-
Notifications
You must be signed in to change notification settings - Fork 428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(task): grant task-run execution role access to secrets based on tag #3256
Changes from 3 commits
4de175d
9838d8b
692b9a5
11132ee
94ee963
eb032de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,10 @@ Parameters: | |
Type: String | ||
Arch: | ||
Type: String | ||
App: | ||
Type: String | ||
Env: | ||
Type: String | ||
Conditions: | ||
# NOTE: Image cannot be pushed until the ECR repo is created, at which time ContainerImage would be "". | ||
HasImage: | ||
|
@@ -39,6 +43,13 @@ Conditions: | |
!Not [ !Equals [ !Join [ "", !Ref EntryPoint ], "" ] ] | ||
HasCustomPlatform: | ||
!Not [!Equals [!Ref OS, ""]] | ||
HasApp: | ||
!Not [!Equals [!Ref App, ""]] | ||
HasEnv: | ||
!Not [!Equals [!Ref Env, ""]] | ||
HasAppAndEnv: !And | ||
- !Condition HasApp | ||
- !Condition HasEnv | ||
Resources: | ||
TaskDefinition: | ||
Metadata: | ||
|
@@ -89,6 +100,34 @@ Resources: | |
Action: 'sts:AssumeRole' | ||
ManagedPolicyArns: | ||
- !Sub 'arn:${AWS::Partition}:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy' | ||
{{- if .Secrets}} | ||
Policies: | ||
- !If | ||
- HasAppAndEnv | ||
- PolicyName: 'PullSecrets' | ||
PolicyDocument: | ||
Version: '2012-10-17' | ||
Statement: | ||
- Effect: 'Allow' | ||
Action: | ||
- ssm:GetParameters | ||
Condition: | ||
StringEquals: | ||
"ssm:ResourceTag/copilot-application": !If [ HasAppAndEnv, !Ref App, !Ref "AWS::NoValue" ] | ||
"ssm:ResourceTag/copilot-environment": !If [ HasAppAndEnv, !Ref Env, !Ref "AWS::NoValue" ] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we remove these |
||
Resource: | ||
- !Sub arn:${AWS::Partition}:ssm:${AWS::Region}:${AWS::AccountId}:parameter/* | ||
- Effect: 'Allow' | ||
Action: | ||
- secretsmanager:GetSecretValue | ||
Condition: | ||
StringEquals: | ||
"secretsmanager:ResourceTag/copilot-application": !If [ HasAppAndEnv, !Ref App, !Ref "AWS::NoValue" ] | ||
"secretsmanager:ResourceTag/copilot-environment": !If [ HasAppAndEnv, !Ref Env, !Ref "AWS::NoValue" ] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Samesies! |
||
Resource: | ||
- !Sub arn:${AWS::Partition}:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:* | ||
- !Ref AWS::NoValue | ||
{{- end}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is awesome! |
||
DefaultTaskRole: | ||
Metadata: | ||
'aws:copilot:description': 'An IAM Role for the task to make AWS API calls on your behalf. Policies are required by ECS Exec' | ||
|
@@ -154,4 +193,4 @@ Resources: | |
Outputs: | ||
ECRRepo: | ||
Description: ECR Repo used to store images of task. | ||
Value: !GetAtt ECRRepo.Arn | ||
Value: !GetAtt ECRRepo.Arn |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need hasapp and has env?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually we can remove this and put these conditions directly into
HasAppAndEnv
condition.