Allow user to customize Roles / ManagedPolicy

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2020-08-13 15:43:24 +02:00
parent 8182c98abf
commit f74cc8f0aa
No known key found for this signature in database
GPG Key ID: 9858809D6F8F6E7E
3 changed files with 18 additions and 5 deletions

View File

@ -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
}

View File

@ -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"`

View File

@ -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"
)