Skip to content
This repository has been archived by the owner on Oct 9, 2020. It is now read-only.

Commit

Permalink
Allow user to customize Roles / ManagedPolicy
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <[email protected]>
  • Loading branch information
ndeloof committed Aug 13, 2020
1 parent 5277509 commit 0b0cba0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
19 changes: 15 additions & 4 deletions pkg/amazon/backend/cloudformation.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,15 +440,26 @@ func createTaskExecutionRole(service types.ServiceConfig, err error, definition
PolicyDocument: policy,
PolicyName: fmt.Sprintf("%sGrantAccessToSecrets", service.Name),
})
}

if roles, ok := service.Extensions[compose.ExtensionRole]; ok {
rolePolicies = append(rolePolicies, iam.Role_Policy{
PolicyDocument: roles,
})
}
managedPolicies := []string{
ECSTaskExecutionPolicy,
ECRReadOnlyPolicy,
}
if v, ok := service.Extensions[compose.ExtensionManagedPolicies]; ok {
for _, s := range v.([]interface{}) {
managedPolicies = append(managedPolicies, s.(string))
}
}
template.Resources[taskExecutionRole] = &iam.Role{
AssumeRolePolicyDocument: assumeRolePolicyDocument,
Policies: rolePolicies,
ManagedPolicyArns: []string{
ECSTaskExecutionPolicy,
ECRReadOnlyPolicy,
},
ManagedPolicyArns: managedPolicies,
}
return taskExecutionRole, nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/amazon/backend/iam.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var assumeRolePolicyDocument = PolicyDocument{
},
}

// could alternatively depend on https://github.com/kubernetes-sigs/cluster-api-provider-aws/blob/master/pkg/cloud/services/iam/types.go#L52
// could alternatively depend on https://github.com/kubernetes-sigs/cluster-api-provider-aws/blob/master/cmd/clusterawsadm/api/iam/v1alpha1/types.go
type PolicyDocument struct {
Version string `json:",omitempty"`
Statement []PolicyStatement `json:",omitempty"`
Expand Down
2 changes: 2 additions & 0 deletions pkg/compose/x.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ const (
ExtensionMinPercent = "x-aws-min_percent"
ExtensionMaxPercent = "x-aws-max_percent"
ExtensionRetention = "x-aws-logs_retention"
ExtensionRole = "x-aws-role"
ExtensionManagedPolicies = "x-aws-policies"
)

0 comments on commit 0b0cba0

Please sign in to comment.