-
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
Conversation
"ssm:ResourceTag/copilot-application": !If [ HasAppAndEnv, !Ref App, !Ref "AWS::NoValue" ] | ||
"ssm:ResourceTag/copilot-environment": !If [ HasAppAndEnv, !Ref Env, !Ref "AWS::NoValue" ] | ||
"ssm:ResourceTag/copilot-task": !If [ HasAppAndEnv, !Ref "AWS::NoValue", !Ref TaskName ] |
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.
I really like the changes with allowing access to the copilot-application
and copilot-environment
tags -- makes total sense to me. I am not sure though how obvious it's going to be when not using a copilot managed cluster, requiring the copilot-task
tag for a one-time job seems a bit cumbersome.
What if we had an experience like this?
$ copilot task run --default --secrets hello=/hello,world=arn:aws:secretsmanager:us-west-2:111122223333:secret:aes128-1a2b3c
Looks like you're requesting ssm:GetParameters to the following SSM parameters:
* /hello
and secretsmanager:GetSecretValue to the following Secrets Manager secrets:
* arn:aws:secretsmanager:us-west-2:111122223333:secret:aes128-1a2b3c
Do you grant permission to the ECS/Fargate agent for these secrets? (y/N)
Or if they'd like to skip the prompt they can pass a flag similar to what the CDK does with --require-approval never
$ copilot task run --default --secrets hello=/hello --require-approval never
Then we will augment the Task Execution role such that only the input resources are granted access.
Let me know what you think!
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 you grant permission to the ECS/Fargate agent for these secrets? (y/N)
If they choose "N", do we just error out saying they can't use these secrets without granting access? And what are available options for --require-approval
?
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.
If they choose "N", do we just error out saying they can't use these secrets without granting access?
I assume we'll abort then, but we can look to what the CDK does as well.
And what are available options for --require-approval?
hmm good point for us none, maybe we can flip the flag --acknowledge-iam
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.
Looks good to me! Just to validate we tested it with both secrets (ssm and secretsmanager) and it works right? 😂
Similarly, can we test as well with a secret that's not tagged to make sure it still cannot access it
Both the secrets (ssm and secretsmanager) and scenarios you mentioned are tested ✅ |
HasApp: | ||
!Not [!Equals [!Ref App, ""]] | ||
HasEnv: | ||
!Not [!Equals [!Ref 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.
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.
Condition: | ||
StringEquals: | ||
"ssm:ResourceTag/copilot-application": !If [ HasAppAndEnv, !Ref App, !Ref "AWS::NoValue" ] | ||
"ssm:ResourceTag/copilot-environment": !If [ HasAppAndEnv, !Ref Env, !Ref "AWS::NoValue" ] | ||
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" ] | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome!
"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 comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove these !If
conditionals now that we have line 101-102?
"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 comment
The reason will be displayed to describe this comment to others. Learn more.
Samesies!
This PR fixes the issue #2641
Fixed the issue by adding policies to the execution role when
--secrets
are provided.Tests -
Following manual tests have been taken into consideration
--app
and--env
flags incopilot task run
command then secrets are accessible only whencopilot-application
andcopilot-environment
tags are present with the correct values on the secret--app
and--env
flags incopilot task run
command then secrets are inaccessible only whencopilot-application
andcopilot-environment
tags are NOT present on the secret or they have incorrect values