-
Notifications
You must be signed in to change notification settings - Fork 4k
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
(aws-secretsmanager): grant read fails when secret is fetched using fromSecretNamev2 #17792
Comments
Hi @mneirynck , Can you provide some more detail? Does the role actually receive an error when trying to fetch the secret?
Can you clarify this? The ARN as shown in your issue description looks correct to me. It's worth noting that the For example, if you create a secret with a name of Given your reproduction steps, the role I've created can access the secret perfectly fine. Can you clarify, and/or provide updated reproduction steps? |
This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled. |
Original messageThe IAM role grants
ECS task asks for
Simulating the IAM role policy, grants fail for all wildcards:
Only grants when asking for specific
|
@mneirynck there's two roles here. The task role is what the runtime docker code uses (your app code). The execution role is what Fargate uses to fetch the docker image, fetch aws secrets, etc in order to setup the containers. I'd look in CloudTrail. I had the exact same error message and I finally found the answer there. My secret I was referencing actually didn't exist.
|
Hi,
Is it by design we need to manually add it to the FargateService? Before it was done automatically I believe since I have services where I'm doing the same thing actually. EDIT: it is getting added by cdk, so that's not the problem either |
Nevermind, I'm just plain stupid... Since it's a manually created secret I have to add the Policy manually to the secret as well (or via cdk explicitly) EDIT: Cloudtrail event:
Everything works if I use the secret.from_arn thing and fill in the arn of the secret, so there is something different between the two. For good measure, this is the ARN of the secret: So the only thing I see differently is the ErrorMessage states an ARN without the suffix, but the policy has the suffix. But since it's not a secret not found error I assume it finds the correct secret. |
I'll try with another secret name, as I was indeed using SOMETHING-SECRET as the secret name, which happens to be 6 chars after the hyphen. |
I believe this PR is set to fix this issue. |
Nope, still doesn't work on 2.10.0. I still need to try with a different secret name, but I guess that will work since all our other secrets don't have those 6 chars in the name. |
Ok I'm hitting this again too.
In the policy referenced I have it... {
"Action": [
"secretsmanager:GetSecretValue",
"secretsmanager:DescribeSecret"
],
"Resource": "arn:aws:secretsmanager:us-east-2:{}:secret:plaid/sandbox-??????",
"Effect": "Allow"
},
{
"Action": [
"secretsmanager:GetSecretValue",
"secretsmanager:DescribeSecret"
],
"Resource": "arn:aws:secretsmanager:us-east-2:{}:secret:seed-api/apollo-studio-??????",
"Effect": "Allow"
} Above it is another secret that works fine. Surely it couldn't be because the secret ends in a 6 char word.... |
Well I changed the secret name from |
I'll try to reproduce this next week at some point. Thanks for the find @CarsonF |
I just tested it with a different name and it worked as long as it doesn't end with 6 characters. |
We just encountered this issue with aws-cdk 2.20.0 and it was the 6 character problem 🤯
fails
works |
IAM doc is not too clear on permission for secrets, it shows an It is a bit clearer on the Secrets manager permissions doc, maybe the policy is generated by CDK and doesn't contemplate this particularity.
|
@CarsonF note that the generated permission ended in |
That definitely relates to the problem. I think the root cause is any time the secret is required, should attempt to access via full ARN instead of by name due to the IAM policy specification. |
Here's the doc that explains it |
This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled. |
Happy birthday issue :) |
Given the documentation linked above, and based on my previous investigation into this and other related issues, I don't think there's anything CDK can do here. We specifically call out in our docs to use |
|
@peterwoodworth would it be reasonable to print a warning or even throw an exception under the given circumstances, either on import or when trying to use the secret imported this way with the ECS secrets feature? I even had this issue before and still struggled for a bit today after making the foolish mistake of ending my secret name with |
@marcesengel I'd recommend opening up another feature request or pinging another team member, I no longer work with this product 🙂 |
What is the problem?
I have manually created a secret named "SECRET-NAME" in SecretsManager and need to request it in one of my stacks, I'm doing it like so:
When I grant read access to a role like so:
It generates the wrong access:
Reproduction Steps
Create a manual secret without the secretsmanager added suffix and request it from within your code.
What did you expect to happen?
I would have expected my role to have read access to the role
What actually happened?
A non-existing ARN was used as the secret ARN in the policy
CDK CLI Version
2.0.0-rc.33
Framework Version
No response
Node.js Version
14.16.0
OS
Arch Linux
Language
Python
Language Version
Python 3.9.9
Other information
No response
The text was updated successfully, but these errors were encountered: