Skip to content
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

[ECS] [secrets]: support parameter name from AWS Secrets Manager #385

Closed
ramilexe opened this issue Jun 24, 2019 · 36 comments
Closed

[ECS] [secrets]: support parameter name from AWS Secrets Manager #385

ramilexe opened this issue Jun 24, 2019 · 36 comments
Assignees
Labels
Coming Soon ECS Amazon Elastic Container Service

Comments

@ramilexe
Copy link

Tell us about your request
I want to be able to inject Secret Key item from Secrets Manager to ECS container_definitions.secrets

Which service(s) is this request for?
ECS

Tell us about the problem you're trying to solve. What are you trying to do, and why is it hard?
In task definition I have the following configuration:

"secrets": [
  {
    "valueFrom": "arn:aws:secretsmanager:us-east-1:account:secret:SECRET_NAME",
    "name": "RABBITMQ_DEFAULT_USER"
  }
]

but it gets injected as whole json object with other parameters:

image

Is it possible to get only one value from the secret?
Thank you

@ramilexe ramilexe added the Proposed Community submitted issue label Jun 24, 2019
@coultn coultn added the ECS Amazon Elastic Container Service label Jun 24, 2019
@nsbialek
Copy link

nsbialek commented Aug 8, 2019

This came up in a recent conversation as if the feature already exists. If someone has documentation for how to implement this please drop a note here. It would be much appreciated.

@kadrach
Copy link
Member

kadrach commented Aug 8, 2019

Ran into this issue earlier this week with RDS credentials generated by SecretsManager. The ECS ContainerDefinition.Secrets only support an Arn for ValueFrom.

CloudFormation offers support for "dynamic references" for SecretsManager of the form {{resolve:secretsmanager:secret-id:secret-string:json-key:version-stage:version-id}} (note json-key).

The downside of this approach is that it bakes the secret into the stack on create/update operations, meaning a rotation of the secret would not be picked up by new tasks until the stack is updated.

@hspak
Copy link

hspak commented Sep 4, 2019

I would love this functionality so we can have 1 secret in secrets manager per ECS task instead of 1 per every secret a task requires.

@ramilexe
Copy link
Author

ramilexe commented Sep 9, 2019

Any updates on that @coultn ? Is it on roadmap?

@galindro
Copy link

This is something really nice because it would avoid unnecessary costs.

For example:

Imagine that, to access an API, we should inform username and password. We could simply store them together in one secret:

Secret name: prod/api/trackify
Secret Value:

{
  "username": "myusername",
  "password": "mypassword"
}

With the current limitation, we can store each json property on its own secret, incurring in more costs:

Secret name: prod/api/trackify/username
Secret Value: myusername

Secret name: prod/api/trackify/password
Secret Value: mypassword

@coultn
Copy link

coultn commented Sep 17, 2019

Any updates on that @coultn ? Is it on roadmap?

Apologies for the delay in responding - we are aware of the request and are evaluating the priority. Additional thumbs-up on the issue are always welcome and we do pay attention to that when prioritizing.

@stephen-164
Copy link

Also note that this requirement (one plaintext value per secret) is incompatible with the key rotation mechanisms and secret target attachments (eg RDS attachment, which requires a JSON structure to add the host/engine/port values). This makes the implementation particularly confusing.

@jritsema
Copy link

I agree that this would be a great option to have in ECS/Fargate. Maybe a new setting like injectSecretProperties that would inject each json property key/value as an envvar.

In the mean time, we created a docker shim that can do this.
https://github.com/turnerlabs/sm_entrypoint

We also use parameter store to achieve this but would prefer to standardize on Secrets Manager.

@cervantek
Copy link

Heads up that CodeBuild team just released exactly this with the following format. The ECS team should be talking to the CodeBuild team about these type of things, you guys are solving a lot of the same problems.

secret-id:json-key:version-stage:version-id

https://aws.amazon.com/about-aws/whats-new/2019/11/aws-codebuild-adds-support-for-aws-secrets-manager/

jy19 added a commit to jy19/amazon-ecs-agent that referenced this issue Feb 14, 2020
for roadmap issue aws#385
aws/containers-roadmap#385
this commit adds the ability for customers to add parameters
to the secretsmanager ARN specified in containers. agent will be
able to retrieve secret by version or retrieve part of a secret
by json key.
this commit also fixes a minor issue breaking go vet in an unrelated test.
jy19 added a commit to jy19/amazon-ecs-agent that referenced this issue Feb 14, 2020
for roadmap issue aws#385
aws/containers-roadmap#385
this commit adds the ability for customers to add parameters
to the secretsmanager ARN specified in containers. agent will be
able to retrieve secret by version or retrieve part of a secret
by json key.
this commit also fixes a minor issue breaking go vet in an unrelated test.
jy19 added a commit to jy19/amazon-ecs-agent that referenced this issue Feb 14, 2020
for roadmap issue aws#385
aws/containers-roadmap#385
this commit adds the ability for customers to add parameters
to the secretsmanager ARN specified in containers. agent will be
able to retrieve secret by version or retrieve part of a secret
by json key.
this commit also fixes a minor issue breaking go vet in an unrelated test.
jy19 added a commit to jy19/amazon-ecs-agent that referenced this issue Feb 14, 2020
for roadmap issue aws#385
aws/containers-roadmap#385
this commit adds the ability for customers to add parameters
to the secretsmanager ARN specified in containers. agent will be
able to retrieve secret by version or retrieve part of a secret
by json key.
this commit also fixes a minor issue breaking go vet in an unrelated test.
jy19 added a commit to jy19/amazon-ecs-agent that referenced this issue Feb 17, 2020
for roadmap issue aws#385
aws/containers-roadmap#385
this commit adds the ability for customers to add parameters
to the secretsmanager ARN specified in containers. agent will be
able to retrieve secret by version or retrieve part of a secret
by json key.
this commit also fixes a minor issue breaking go vet in an unrelated test.
jy19 added a commit to jy19/amazon-ecs-agent that referenced this issue Feb 18, 2020
for roadmap issue aws#385
aws/containers-roadmap#385
this commit adds the ability for customers to add parameters
to the secretsmanager ARN specified in containers. agent will be
able to retrieve secret by version or retrieve part of a secret
by json key.
this commit also fixes a minor issue breaking go vet in an unrelated test.
@rich4j
Copy link

rich4j commented Feb 25, 2020

Assuming this release addressed ask here? Open while AWS add support to CloudFormation?

https://aws.amazon.com/about-aws/whats-new/2020/02/amazon-ecs-now-supports-aws-secrets-manager-version-and-json-keys/

@coultn
Copy link

coultn commented Feb 26, 2020

@rich4j This is supported in CloudFormation now. We will keep this issue open while we are adding support for Fargate tasks in ECS.

@coultn coultn added this to We're Working On It in containers-roadmap Feb 26, 2020
@rich4j
Copy link

rich4j commented Feb 26, 2020

@rich4j This is supported in CloudFormation now. We will keep this issue open while we are adding support for Fargate tasks in ECS.

Hi there. Thanks for response. Does this mean that the feature is only available for ECS tasks using EC2 launch type? Don't think that comes across clearly in release and docs.

@coultn
Copy link

coultn commented Feb 27, 2020

@acaire
Copy link

acaire commented Mar 4, 2020

@coultn any prospect of this JSON key functionality trickling through to IAM to allow fine grain write permissions on individual fields, which would allow updating a secret without having access to retrieve it?

@pandayanlu
Copy link

I am blocked as ContainerDefinition:Secret doesn't support json key for ECS Fargate, it would be great appreciate if the support for Fargate can be added ASAP.

@eberkund
Copy link

I am blocked as ContainerDefinition:Secret doesn't support json key for ECS Fargate, it would be great appreciate if the support for Fargate can be added ASAP.

I am using jq

along with

export DB_HOST=$(echo "$DB_SECRET" | jq .host)

to extract the secrets inside my container. Not ideal, but it works.

@ChristophEckerle
Copy link

ChristophEckerle commented May 14, 2020

Hi @srrengar, it is against our system architecture idea and would effect our setup. Is there no workaround available to pass DB secrets into a container definition on Fargate and in the same time to RDS?

In RDS/Aurora Serverless it is not possible to put any ARN for the secrets like in Fargate:
'arn:aws:secretsmanager:eu-central-1:485695650525:secret:dev/mysqlrootpassword-0x0xx'

In Container Definition it is not possible to use resolve, like for Aurora Serverless/RDS:
'MasterUserPassword: !Join ['', ['{{resolve:secretsmanager:', dev/mysqlrootpassword, :SecretString:password}}'
OR
'!Join ['', ['{{resolve:secretsmanager:' , "Fn::ImportValue" : {!Sub '${StackNameDatabase}:${DBMasterPassword}'}, ':SecretString:password}}' ]]'

Every workaround is welcome!

@rrijkse
Copy link

rrijkse commented May 14, 2020

@ChristophEckerle This is my workaround

Pass in an ENV variable without the specific secret (from a taskdefintion.json file)

"secrets": [
        {
          "name": "DB_JSON",
          "valueFrom": "arn:aws:secretsmanager:us-east-1:<account>:secret:<secret name>"
        }

and then parse it in an entrypoint script like start.sh

export DB_HOST=$(echo ${DB_JSON} | jq -r '.endpoint')
/bin/yourapp

The ".endpoint" would be whatever the secret's label is.

@srrengar srrengar moved this from We're Working On It to Coming Soon in containers-roadmap May 20, 2020
@srrengar srrengar self-assigned this May 20, 2020
maiconrocha added a commit to maiconrocha/worksamples that referenced this issue Jun 22, 2020
Unfortunately for tasks that use the Fargate launch type it is only supported to inject the full contents of a secret as an environment variable. Specifying a specific JSON key or version is not supported at this time.

This limitation is being discussed on the link aws/containers-roadmap#385

Due the limitation on Fargate Launch Type, In regards of using ImportValue function on Cloudformation, you can import an value for example:

ValueFrom: !ImportValue "Secretexport" 

*On my case, Secretexport is the Secret ARN

And then you will need to parse the value, for example on the entrypoint:

- "export MyPWD=$(echo ${passwordfromsm} | jq -r '.password')"
@dzmitry-kankalovich
Copy link

dzmitry-kankalovich commented Jul 24, 2020

My case is that we did application services with ECS/EC2 and now we want to run some finite tasks on schedule with ECS/Fargate - and we've bumped into this problem. This is a small but crucial feature, I hope AWS prioritizes implementing it ASAP.

@ophintor
Copy link

I'm on the same boat. We just implemented secret rotation for RDS but now we need to change the way we get those secrets in the app, which is pretty painful.

@memark
Copy link

memark commented Sep 1, 2020

Any update on this? It would be really useful.

@StevePavlin
Copy link

+1, one monolithic secret in SSM injected as specific env vars seems to be the use case that makes sense for us coming off heroku to fargate.

@ophintor
Copy link

ophintor commented Sep 6, 2020

AWS Secret Manager with ECS (Fargate) ---> https://www.youtube.com/watch?v=DPXFknB1up0&t=35s&ab_channel=AWSLinuxWindows

The video is 1h long. Could you please point us to the relevant part of the video? Thanks.

@jwmonroe-outschool
Copy link

I believe would be possible to support JSON keys by reverting this PR. We were using an older version of cdk (1.36.1) and were able to set environment variables for secret keys JSON keys through the ECS agent like such:

secrets: {
    DB_CONNECTION_URI: ecs.Secret.fromSecretsManager(secretStore, "DB_CONNECTION_URI")
}

I believe that a team upstream of CDK (CF? ECS?) must have added support to fix this issue.

We tried upgrading to 1.62.0 and found that CDK was blocking deployments with "Cannot specify secret JSON field for a task using the FARGATE launch" despite the same Fargate task working right before the upgrade.

@memark
Copy link

memark commented Sep 14, 2020

Hi there, Simply Use a policy for Secret Manager in ---> Task Role and Task Execution Role (requires permissions for secret manager)
...

Step 2

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"secretsmanager:GetResourcePolicy",
"secretsmanager:GetSecretValue",
"secretsmanager:DescribeSecret",
"secretsmanager:ListSecretVersionIds"
],
"Resource": [
"arn of the secret created"
]
}
]
}

@quickbooks2018 Just to be clear, are you saying that adding this policy makes parameter names from secrets work again?

That kinda makes me wonder why it was disabled in the first place (in the PR mentioned above). I assumed it was not safe, or not working correctly?

@ophintor
Copy link

Hi there, Simply Use a policy for Secret Manager in ---> Task Role and Task Execution Role (requires permissions for secret manager)
...

Step 2

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"secretsmanager:GetResourcePolicy",
"secretsmanager:GetSecretValue",
"secretsmanager:DescribeSecret",
"secretsmanager:ListSecretVersionIds"
],
"Resource": [
"arn of the secret created"
]
}
]
}

@quickbooks2018 Just to be clear, are you saying that adding this policy makes parameter names from secrets work again?

That kinda makes me wonder why it was disabled in the first place (in the PR mentioned above). I assumed it was not safe, or not working correctly?

I don't think @quickbooks2018's answer relates to the original question. The whole point of this thread is to find a way to pass a value from a secret when the secret is in JSON format, by specifying a key. The example he describes works but it's simply for string secrets rather than secrets stored as part of a JSON structure.

@dzmitry-kankalovich
Copy link

@quickbooks2018 I am still not sure what you are suggesting here. If you are talking about programmatic access to secrets manager from within the application - there are neither doubts nor problems with that, but that's not the problem we discussing here.

Here we are talking about the absence of a declarative way to pass secret values as JSON property via ECS Task definition, e.g.

          Secrets:
            - Name: redshift_db_password
              ValueFrom: !Sub "arn:aws:secretsmanager:${AWS::Region}:${AWS::AccountId}:some-secret-with-json-value:some-json-property::"

UPDATE: I took some time and watched your video. You reference raw value from the secret manager, not the JSON property. Your suggestion is invalid, therefore. Curiously you yourself tell about this problem in your video and even reference this ticket, so not sure why you are confusing people here.

@ngamradt-turner
Copy link

Is there an update as to when this feature will be coming to Fargate?

@jonathan-atom
Copy link

Totally agree that this is a big gap and look forward to a solution... If you can live with Parameter Store, securely injecting single-values as secrets/env in the task definition works just fine.

@ngamradt-turner
Copy link

@jonathan-atom Yes, we are already leveraging workarounds, but we want to get rid of them. Since this works for classic ECS, it needs to get rolled out to Fargate for parity.

@dennisbrouwer91
Copy link

This would indeed really help!

@srrengar
Copy link

srrengar commented Nov 5, 2020

Hi everyone, thank you for your patience. This feature is now available in Fargate as of today.

https://aws.amazon.com/about-aws/whats-new/2020/11/aws-fargate-for-amazon-ecs-launches-features-focused-on-configuration-and-metrics/

@srrengar srrengar closed this as completed Nov 5, 2020
containers-roadmap automation moved this from Coming Soon to Just Shipped Nov 5, 2020
mergify bot pushed a commit to aws/aws-cdk that referenced this issue Nov 13, 2020
Fargate tasks running on platform version 1.4 can now reference a
specific JSON field of a secret stored in Secrets Manager.

Remove the error in `ContainerDefinition` and add a check on the
platform version in `FargateService`.

See https://aws.amazon.com/about-aws/whats-new/2020/11/aws-fargate-for-amazon-ecs-launches-features-focused-on-configuration-and-metrics/

See aws/containers-roadmap#385 (comment)

Closes #11341


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Coming Soon ECS Amazon Elastic Container Service
Projects
Development

No branches or pull requests