You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For feature proposals:
The use case is the same as for SSM Parameter Store.
Storing secrets like database connection parameters / api keys etc.
Would be nice to choose between SSM Parameters Store and the AWS Secrets Manager for storing configs and secrets.
Reacted by Sergio Arcos, Aaron Scherer, Kurt McAlpine, Hunter Haydel, Charles Lanahan, Bethany Berkowitz, Jakub Holý, Jarred Riggall, mconigliaro, Jack Davis and 14 more
Yes, this please! 💯
If nobody else will, I can probably make a PR for this. It would be nice to get some feedback from serverless maintainers whether or not that would be wasted time, or if this feature would be welcome :)
This might not be as trivial as mirroring the SSM syntax.
Secrets manager stores multiple key values in the secrets as text. Commonly key values are stored in text as JSON, but this is not necessarily the only way they are stored. Users can use any serialisation that they want.
If we ignored the alternative ways of storing the key values, and assume secrets are always key/value JSON, then we could use the syntax {secret:name_of_secret.key}.
But given users are charged each time a key is decrypted we would also probably need to cache the secret so that {secret:name_of_secret.foo} and {secret:name_of_secret.bar} don't make two requests unnecessarily.
Excellent points. To be honest, I've kinda changed strategies here. Pulling in secrets and storing them locally in a cloud formation file sort of goes against keeping these secrets really secret in the first place. I'm going to change my strategy.
The question is how secure or risky it is to implement this solution.
My Assumption:
As far as I understand a cloudfornationfile will be transmitted and uploaded having the secrets already injected, when you do serverless deploy.
The package itself will be immediately created in .serverless folder and destroyed after successful upload.
This upload is hopefully encrypted right ? at least with ssl.
That would be ok for my solutions.
If someone accesses these files on my laptop I have a bigger issue.
I would not use this solution for a cashcow service where I make millions.
But in my eyes then you would have a different setup (k8s, fargate, docker) even because of costs.
So yes I still would like to have it :)
Key:Value Pair Style...
I haven't tried this yet, but it looks like you can now access secrets from the Secrets Manager via the SSM Parameter Store, so this may be supported with no code changes.
@BethanyBerkowitz that almost works but this new feature requires a WithDecryption flag to be set when pulling secrets via SSM, which the serverless SSM integration does not do, so you end up seeing this error: WithDecryption flag must be True for retrieving a Secret Manager secret.
EDIT: this actually works if you add the additional flag to decrypt a key. Here is an example: ${ssm:/aws/reference/secretsmanager/my/key~true}. This is also described here
Reacted by Matt Fulgo, mconigliaro and Daniel Kelleher
Reacted by Bethany Berkowitz, Hendrik Jander and Alex
@agonbina${ssm:/aws/reference/secretsmanager/my/key~true} doesn't work for me, ${ssm:/aws/reference/secretsmanager/my~true} does work, but gives back the whole secret as a json serialized thing. I need to get usernames and passwords out of the json to individual parameters.
Can this be done in serverless.yml?
Did the above work for anyone? It did not work for me, could someone please share a complete example of the yml file they used to get it work? I keep getting A valid file to satisfy the declaration 'self:custom.secrets.db_root_username' could not be found.
Thanks!
@rakeshsehgal1 I think that it is weird that the error message mentions A valid file. There might be a typo in your settings, so serverless is looking for a file instead of accessing ssm.
I've seen errors in relation to SSM such as A valid service attribute to satisfy the declaration 'self:custom.settings.ssm.test' could not be found. or A valid SSM parameter to satisfy the declaration 'ssm:/aws/reference/secretsmanager/my-secrets~true' could not be found.
I don't have a full yml to share (I split most into several parts) but if you share yours I could help you.
The my_check_secrets is in AWS Secret manager as a json. And then in my code trying to access process.env.myCreds to get the json or the value. The error that I got was (just for ref again): A valid service attribute to satisfy the declaration 'self:custom.secrets' could not be found.
@rakeshsehgal1 the problem is the indentation. Your custom section ended up inside the provider section. I guess this should work (haven't tested it though)
Thanks @jmsg1990 this works, that was the only indentation I had not tried :) .
Just to make it easier for someone else, in the final yml I directly used my key from the secret:
when the AWS secret is stored as:
{
"key1": "value1",
"key2": "value2"
}
and then in your code directly access process.env.envKey1. Not sure if it's possible to use the entire custom object or not.
Reacted by robertvorthman, Juan Manuel Silva Garretón, Robin Cher, symbiotech, bhupender rawat, nakhodkin, 300LiterPropofol and Lucas Possani
Thanks @jmsg1990 this works, that was the only indentation I had not tried :) .
Just to make it easier for someone else, in the final yml I directly used my key from the secret:
when the AWS secret is stored as:
{
"key1": "value1",
"key2": "value2"
}
and then in your code directly access process.env.envKey1. Not sure if it's possible to use the entire custom object or not.
It is really kind of you for sharing this!! Really helps me. Thank you a lot @raakasf
Activity
e-e-e commentedon Jul 11, 2018
Is there any progress on this proposal? I am currently working on a project which would benefit from a simple interface to AWS secrets manager.
ronkorving commentedon Jul 30, 2018
Yes, this please! 💯
If nobody else will, I can probably make a PR for this. It would be nice to get some feedback from serverless maintainers whether or not that would be wasted time, or if this feature would be welcome :)
eahefnawy commentedon Jul 30, 2018
@ronkorving thanks for pitching in. Could you explain how you intend to implement this? and what the experience would be like for using this feature?
pharindoko commentedon Jul 30, 2018
Same behaviour and implementation as for the Parameter Store (SSM).
Just the option to choose between one or the other....
eahefnawy commentedon Jul 30, 2018
@pharindoko I like that. We'd def appreciate a PR! 😊
e-e-e commentedon Jul 31, 2018
This might not be as trivial as mirroring the SSM syntax.
Secrets manager stores multiple key values in the secrets as text. Commonly key values are stored in text as JSON, but this is not necessarily the only way they are stored. Users can use any serialisation that they want.
If we ignored the alternative ways of storing the key values, and assume secrets are always key/value JSON, then we could use the syntax
{secret:name_of_secret.key}.But given users are charged each time a key is decrypted we would also probably need to cache the secret so that
{secret:name_of_secret.foo}and{secret:name_of_secret.bar}don't make two requests unnecessarily.Just some quick thoughts.
ronkorving commentedon Aug 1, 2018
Excellent points. To be honest, I've kinda changed strategies here. Pulling in secrets and storing them locally in a cloud formation file sort of goes against keeping these secrets really secret in the first place. I'm going to change my strategy.
e-e-e commentedon Aug 1, 2018
@ronkorving I really agree - really SSM shouldn't be used for encrypted values either for the reasons you mentioned.
We ended up storing env vars that point to the secret key, and then in our lambda's we fetch and cache them before executing the hander.
ronkorving commentedon Aug 1, 2018
@e-e-e I was thinking of doing exactly that
pharindoko commentedon Aug 12, 2018
I used both methods:
The question is how secure or risky it is to implement this solution.
My Assumption:
As far as I understand a cloudfornationfile will be transmitted and uploaded having the secrets already injected, when you do serverless deploy.
The package itself will be immediately created in .serverless folder and destroyed after successful upload.
This upload is hopefully encrypted right ? at least with ssl.
That would be ok for my solutions.
If someone accesses these files on my laptop I have a bigger issue.
I would not use this solution for a cashcow service where I make millions.
But in my eyes then you would have a different setup (k8s, fargate, docker) even because of costs.
So yes I still would like to have it :)
Key:Value Pair Style...
BethanyBerkowitz commentedon Sep 11, 2018
I haven't tried this yet, but it looks like you can now access secrets from the Secrets Manager via the SSM Parameter Store, so this may be supported with no code changes.
https://aws.amazon.com/about-aws/whats-new/2018/07/aws-systems-manager-parameter-store-integrates-with-aws-secrets-manager-and-adds-parameter-version-labeling/
https://docs.aws.amazon.com/systems-manager/latest/userguide/integration-ps-secretsmanager.html
agonbina commentedon Sep 13, 2018
@BethanyBerkowitz that almost works but this new feature requires a
WithDecryptionflag to be set when pulling secrets via SSM, which the serverless SSM integration does not do, so you end up seeing this error:WithDecryption flag must be True for retrieving a Secret Manager secret.EDIT: this actually works if you add the additional flag to decrypt a key. Here is an example:
${ssm:/aws/reference/secretsmanager/my/key~true}. This is also described hereImran99 commentedon Sep 14, 2018
+1. Secrets manager also supports key rotation via a custom lambda, not sure if SSM can do that.
q42jaap commentedon Sep 24, 2018
@agonbina
${ssm:/aws/reference/secretsmanager/my/key~true}doesn't work for me,${ssm:/aws/reference/secretsmanager/my~true}does work, but gives back the whole secret as a json serialized thing. I need to get usernames and passwords out of the json to individual parameters.Can this be done in serverless.yml?
5 remaining items
Document how to use Secrets Manager
bradennapier commentedon Jul 27, 2019
This should actually be added to support the case you want ot read many files to stop reading the secret many times (you pay per decrypt).
It should parse it once and re-use the secret any time requested during a deployment.
jmsg1990 commentedon Jul 31, 2019
You can do this by adding a secrets section to your serverless.yml like this:
Then, you can reference your secrets stored in ssm anywhere in you yml using:
${self:custom.secrets.db_root_username}The names
secrets,my-secretsanddb_root_usernameare used here just as an example.Also, I like naming the secret store using variables:
raakasf commentedon Dec 18, 2019
Did the above work for anyone? It did not work for me, could someone please share a complete example of the yml file they used to get it work? I keep getting
A valid file to satisfy the declaration 'self:custom.secrets.db_root_username' could not be found.Thanks!
jmsg1990 commentedon Dec 18, 2019
@rakeshsehgal1 I think that it is weird that the error message mentions
A valid file. There might be a typo in your settings, so serverless is looking for a file instead of accessing ssm.I've seen errors in relation to SSM such as
A valid service attribute to satisfy the declaration 'self:custom.settings.ssm.test' could not be found.orA valid SSM parameter to satisfy the declaration 'ssm:/aws/reference/secretsmanager/my-secrets~true' could not be found.I don't have a full yml to share (I split most into several parts) but if you share yours I could help you.
raakasf commentedon Dec 19, 2019
Thanks @jmsg1990, here is my yml:
The my_check_secrets is in AWS Secret manager as a json. And then in my code trying to access process.env.myCreds to get the json or the value. The error that I got was (just for ref again):
A valid service attribute to satisfy the declaration 'self:custom.secrets' could not be found.Thanks for helping out!
jmsg1990 commentedon Dec 19, 2019
@rakeshsehgal1 the problem is the indentation. Your
customsection ended up inside theprovidersection. I guess this should work (haven't tested it though)I hope it helps!
raakasf commentedon Dec 19, 2019
Thanks @jmsg1990 this works, that was the only indentation I had not tried :) .
Just to make it easier for someone else, in the final yml I directly used my key from the secret:
when the AWS secret is stored as:
{
"key1": "value1",
"key2": "value2"
}
and then in your code directly access
process.env.envKey1. Not sure if it's possible to use the entire custom object or not.300LiterPropofol commentedon Nov 20, 2020
gazal-k commentedon Dec 18, 2020
we have a secret with JSON value like
{ "encrypt.key": "123", "encrypt.initVector": "456" }Referencing it in serverless like:
In the generated
serverless-state.json, I can see that the JSON value is retreived correctlyI've tried a few different ways to read that into the environment variables of our lambda fns
results in the following in the state file
Also tried:
but that produces
Any suggestions on how we can extract the secret values?
gazal-k commentedon Dec 21, 2020
I think I figured it out. I used a js file (https://www.serverless.com/framework/docs/providers/aws/guide/variables/#reference-variables-in-javascript-files) to transform the secret.
transformSecretsManagerResponse.jsand in
serverless.yaml