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: TaskDefinition Container Secret property #3326

Closed
1 of 5 tasks
nmussy opened this issue Jul 17, 2019 · 3 comments
Closed
1 of 5 tasks

ECS: TaskDefinition Container Secret property #3326

nmussy opened this issue Jul 17, 2019 · 3 comments
Labels
needs-triage This issue or PR still needs to be triaged.

Comments

@nmussy
Copy link
Contributor

nmussy commented Jul 17, 2019

Note: for support questions, please first reference our documentation, then use Stackoverflow. This repository's issues are intended for feature requests and bug reports.

  • I'm submitting a ...

    • 🪲 bug report
    • 🚀 feature request
    • 📚 construct library gap
    • ☎️ security issue or vulnerability => Please see policy
    • ❓ support request => Please see note at the top of this template.
  • What is the current behavior?
    If the current behavior is a 🪲bug🪲: Please provide the steps to reproduce
    There is currently no practical way to securely pass SSM parameters or Secrets Manager secrets to an ECS task definition, due to the missing AWS::ECS::TaskDefinition ClontainerDefinition Secret property.

  • What is the expected behavior (or behavior of feature suggested)?
    Add a secrets property or addSecrets method, to provide parameters and secrets to ECS tasks. Ideally, the secrets given would also be added to the container role policy.

  • What is the motivation / use case for changing the behavior or adding this feature?
    Securely and easily pass parameters and secrets to containers

  • Please tell us about your environment:

    • CDK CLI Version: 1.0.0
    • Module Version: 1.0.0
    • OS: all
    • Language: all
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. associated pull-request, stackoverflow, gitter, etc)

@nmussy nmussy added the needs-triage This issue or PR still needs to be triaged. label Jul 17, 2019
@nmussy nmussy changed the title ECS: TaskDefinition Secret property ECS: TaskDefinition Container Secret property Jul 17, 2019
@nmussy
Copy link
Contributor Author

nmussy commented Jul 17, 2019

Here is a working override in the meantime, using an RDS instance secret as an example:

const database = new DatabaseInstance(this, 'rds', {
    vpc,
    engine: DatabaseInstanceEngine.MYSQL,
    instanceClass: InstanceType.of(InstanceClass.BURSTABLE2, InstanceSize.MICRO),
    databaseName: DATABASE_NAME,
    masterUsername: DATABASE_ADMIN,
});
database.connections.allowDefaultPortFromAnyIpv4();

const taskDefinition = new TaskDefinition(this, 'task', {
    compatibility: Compatibility.EC2,
});

const container = taskDefinition.addContainer('container', {
    image: ContainerImage.fromEcrRepository(new Repository(this, 'ecr', {}), 'latest'),
});

{
    database.secret && database.secret.grantRead(taskDefinition.obtainExecutionRole());

    const taskDefinitionResource = taskDefinition.node.findChild('Resource') as unknown as CfnTaskDefinition;
    taskDefinitionResource.addPropertyOverride('ContainerDefinitions.0.Secrets', [{
        Name: 'RDS_SECRET',
        ValueFrom: database.secret && database.secret.secretArn
    }]);
}

@CShigaki
Copy link

CShigaki commented Jul 18, 2019

You can also use Secrets like this

const taskDef = new cdk.CfnResource(this, 'TaskDef', {
  type: 'AWS::ECS::TaskDefinition',
  properties: {
    ...
    ContainerDefinitions : [
      {
        ...
        Secrets: {
          Name: '',
          ValueFrom: 'secret-arn',
        }
        ...
      },
    ],
    ...
  },
});

@nmussy
Copy link
Contributor Author

nmussy commented Jul 19, 2019

Duplicate of #1478

@nmussy nmussy closed this as completed Jul 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants