Skip to content

Commit 2570d97

Browse files
authored
Merge pull request #4224 from Skarlso/fix-malformed-s3-policy
fix: malformed s3 arn due to incorrect string formatting
2 parents fa7a8f6 + 81e5212 commit 2570d97

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

pkg/cloud/services/s3/s3.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ func (s *Service) bucketPolicy(bucketName string) (string, error) {
244244
Sid: "control-plane",
245245
Effect: iam.EffectAllow,
246246
Principal: map[iam.PrincipalType]iam.PrincipalID{
247-
iam.PrincipalAWS: []string{fmt.Sprintf("arn:%s:iam::%s:role/%s", s.scope, *accountID.Account, bucket.ControlPlaneIAMInstanceProfile)},
247+
iam.PrincipalAWS: []string{fmt.Sprintf("arn:%s:iam::%s:role/%s", partition, *accountID.Account, bucket.ControlPlaneIAMInstanceProfile)},
248248
},
249249
Action: []string{"s3:GetObject"},
250250
Resource: []string{fmt.Sprintf("arn:%s:s3:::%s/control-plane/*", partition, bucketName)},

pkg/cloud/services/s3/s3_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ func TestReconcileBucket(t *testing.T) {
172172
if !strings.Contains(policy, fmt.Sprintf("%s/node/*", bucketName)) {
173173
t.Errorf("At least one policy should apply for all objects with %q prefix, got: %v", "node", policy)
174174
}
175+
176+
if !strings.Contains(policy, "arn:aws:iam::foo:role/control-plane.cluster-api-provider-aws.sigs.k8s.io") {
177+
t.Errorf("Expected arn to contain the right principal; got: %v", policy)
178+
}
175179
}).Return(nil, nil).Times(1)
176180

177181
if err := svc.ReconcileBucket(); err != nil {

0 commit comments

Comments
 (0)