You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This allows to have a single account for caching in multi-account
environments.
Changes:
- Added support to assume role
- Added the ability to specify access policy
- Added the ability to specify lifecycle policy
Initially, I had two approaches to make this work:
1) let other accounts create repos and fill them with images
2) use the role in the target account (this PR)
While 1) would be preferable, unfortunately, it's doesn't look like it's
possible: you can allow other accounts to create repos, but not put any
policies.
Copy file name to clipboardexpand all lines: docs/getting-started.md
+85
Original file line number
Diff line number
Diff line change
@@ -29,6 +29,91 @@ Choose from one of the strategies below or an alternative if needed.
29
29
--from-literal=aws_secret_access_key=<...>
30
30
```
31
31
32
+
#### Using ECR registries cross-account
33
+
34
+
Although ECR allows creating registry policy that allows reposistories creation from different account, there's no way to push anything to these repositories.
35
+
ECR resource-level policy can not be applied during creation, and to apply it afterwards we need ecr:SetRepositoryPolicy permission, which foreign account doesn't have.
36
+
37
+
One way out of this conundrum is to assume the role in target account
38
+
39
+
```yaml
40
+
target:
41
+
type: aws
42
+
aws:
43
+
accountId: 123456789
44
+
region: ap-southeast-2
45
+
role: arn:aws:iam::123456789012:role/roleName
46
+
```
47
+
!!! note
48
+
Make sure that target role has proper trust permissions that allow to assume it cross-account
49
+
50
+
!!! note
51
+
In order te be able to pull images from outside accounts, you will have to apply proper access policy
52
+
53
+
54
+
#### Access policy
55
+
56
+
You can specify the access policy that will be applied to the created repos in config. Policy should be raw json string.
57
+
For example:
58
+
```yaml
59
+
target:
60
+
aws:
61
+
accountId: 123456789
62
+
region: ap-southeast-2
63
+
role: arn:aws:iam::123456789012:role/roleName
64
+
accessPolicy: '{
65
+
"Statement": [
66
+
{
67
+
"Sid": "AllowCrossAccountPull",
68
+
"Effect": "Allow",
69
+
"Principal": {
70
+
"AWS": "*"
71
+
},
72
+
"Action": [
73
+
"ecr:GetDownloadUrlForLayer",
74
+
"ecr:BatchGetImage",
75
+
"ecr:BatchCheckLayerAvailability"
76
+
],
77
+
"Condition": {
78
+
"StringEquals": {
79
+
"aws:PrincipalOrgID": "o-xxxxxxxxxx"
80
+
}
81
+
}
82
+
}
83
+
],
84
+
"Version": "2008-10-17"
85
+
}'
86
+
```
87
+
88
+
#### Lifecycle policy
89
+
90
+
Similarly to access policy, lifecycle policy can be specified, for example:
91
+
92
+
```yaml
93
+
target:
94
+
aws:
95
+
accountId: 123456789
96
+
region: ap-southeast-2
97
+
role: arn:aws:iam::123456789012:role/roleName
98
+
accessPolicy: '{
99
+
"rules": [
100
+
{
101
+
"rulePriority": 1,
102
+
"description": "Rule 1",
103
+
"selection": {
104
+
"tagStatus": "any",
105
+
"countType": "imageCountMoreThan",
106
+
"countNumber": 1000
107
+
},
108
+
"action": {
109
+
"type": "expire"
110
+
}
111
+
}
112
+
]
113
+
}
114
+
'
115
+
```
116
+
32
117
#### Service Account
33
118
34
119
1. Create an Webidentity IAM role (e.g. `k8s-image-swapper`) with the following trust policy, e.g
0 commit comments