I hate it when I'm creating a secret store in AWS and it adds a random uid at the end of the ARN.
Example: arn:aws:secretsmanager:us-east-1:xxxxxxxx:secret:secrets-store-development-k8s-klbiCG
This messes up Terraform templates and makes me cringe every time I need to make ENV variables for each environment.
Please, explain why is this being done so that I could be more at ease. I will share my good karma with you in exchange
I don't think this implementation detail is publicly documented, so unless you find somebody working at AWS to answer this, you'll probably only get guesses.
Disclaimer: This is a guess, but I think it makes sense
As the name of the service suggests, Secrets Manager is built to store secrets to which access should probably be tightly controlled and limited. If the ARN is predictable, you'd open yourself up to the following problem:
- Alice creates a secret
demo
with the ARNarn:aws:secretsmanager:(...):secret:demo
- Alice now creates an EC2 instance and adds an instance profile to it, that allows the
GetSecret
action on the demo secret identified by it's ARNarn:aws:secretsmanager:(...):secret:demo
- Now Alice deletes the secret and after the minimum required amount of time (7 days) the secret gets deleted. Alice doesn't update the policy on the EC2 instance, because granting access to a non-existent secret doesn't seem like a big problem or she just forgets it.
- After about a week Bob comes along and creates a secret, which he also decides to call
demo
and as a result of the predictable ARN, the secret's ARN looks like this:arn:aws:secretsmanager:(...):secret:demo
- Unbeknownst to him, the instance Alice had created a week ago now has access to Bob's secret
This isn't ideal for a service that's supposed to keep your secrets protected.
A simple solution is to add a random suffix to the secrets name.
Other examples in the wild
In AWS there is a similar problem with IAM and roles where they chose to implement it in a different way.
If you set create a role you add a trust relationship to it. This trust relationship or assume role policy defines which principal is allowed to assume this role.
Suppose you set up a role Bob and then create a role Eve and allow the ARN of the Bob role to assume the role Eve.
Now you delete the Bob role and recreate it with the same name.
You'll observe that the new Bob role has the same ARN as the old one.
When the new Bob role tries to assume the Eve role they'll get an AccessDenied
error.
Now you scratch your head, because you're confused.
You think it should work, because you added the ARN, which hasn't changed, to the trust policy ...or did you?
You open up the trust policy and in the assume role policy, you'll see a cryptic ID instead of the ARN you had placed there earlier. That's because in assume role documents AWS uses the physical ID of the underlying role and not the ARN. New Bob has a new physical ID, that's why this doesn't work. They do this exactly for the reasons I outlined above.
To fix your scripts and templates, the ARN can be acquired dynamically.
Here's how to do it in Terraform:
// dynamically acquire the opaque ARN based on the secret name
// implicit dependency: assumes that the secret already exists
data "aws_secretsmanager_secret" "mysecret" {
name = "name-of-my-secret"
}
Then you can access the arn as:
data.aws_secretsmanager_secret.mysecret.arn
For someone who need the ARN
Follow this doc, it shows that we can generate the ARN using the wild card character ?
in place of the last 6 random characters like -
arn:aws:secretsmanager:Region:AccountId:secret:another_secret_name-??????
ValueFrom
property from the Secrets
section in a container definition of an ECS task definition requires the exact ARN (reference). –
Branham © 2022 - 2024 — McMap. All rights reserved.