Skip to content

Commit

Permalink
Merge pull request #4676 from giantswarm/s3-transit-encryption
Browse files Browse the repository at this point in the history
✨ Enable transit encryption to S3 bucket
  • Loading branch information
k8s-ci-robot committed Dec 13, 2023
2 parents 5711479 + 26ac0d3 commit 7be1c77
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/cloud/services/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,20 @@ func (s *Service) bucketPolicy(bucketName string) (string, error) {
Action: []string{"s3:GetObject"},
Resource: []string{fmt.Sprintf("arn:%s:s3:::%s/control-plane/*", partition, bucketName)},
},
{
Sid: "ForceSSLOnlyAccess",
Effect: iam.EffectDeny,
Principal: map[iam.PrincipalType]iam.PrincipalID{
iam.PrincipalAWS: []string{"*"},
},
Action: []string{"s3:*"},
Resource: []string{fmt.Sprintf("arn:%s:s3:::%s/*", partition, bucketName)},
Condition: iam.Conditions{
"Bool": map[string]interface{}{
"aws:SecureTransport": false,
},
},
},
}

for _, iamInstanceProfile := range bucket.NodesIAMInstanceProfiles {
Expand Down
4 changes: 4 additions & 0 deletions pkg/cloud/services/s3/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ func TestReconcileBucket(t *testing.T) {
if !strings.Contains(policy, "arn:aws:iam::foo:role/control-plane.cluster-api-provider-aws.sigs.k8s.io") {
t.Errorf("Expected arn to contain the right principal; got: %v", policy)
}

if !strings.Contains(policy, "SecureTransport") {
t.Errorf("Expected deny when not using SecureTransport; got: %v", policy)
}
}).Return(nil, nil).Times(1)

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

0 comments on commit 7be1c77

Please sign in to comment.