Proposed way to use iam access and secretKey in cdk
See original GitHub issue❓ General Issue
There are a lot of application out there that still require an access/secretKey pair and do not work with roles. What’s the ideal/secure way to use those in cdk without creating resources manually beforehand.
The Question
There is the parameter store (SSM) and the secrets manager (SM) available. In SSM I can only create “normal” strings from cdk/cloudformation - not secure strings. In SM I can only get a new secret but not store my own one.
So the only option currently seems to be this:
const user = new iam.User(this, 'User', {
userName: this.getConfig('bucketName'),
})
const accessKey = new iam.CfnAccessKey(this, 'AccessKey', {
userName: user.userName,
})
const ssmSecretKey = new ssm.StringParameter(this, 'SsmSecretKey', {
parameterName: '/' + [this.account, this.stackName, 'secretKey'].join('/'),
stringValue: accessKey.attrSecretAccessKey,
})
const bucket = new s3.Bucket(this, 'Bucket', {
bucketName: this.getConfig('bucketName'),
versioned: false,
removalPolicy: RemovalPolicy.RETAIN,
publicReadAccess: false,
blockPublicAccess: BlockPublicAccess.BLOCK_ALL,
})
bucket.grantReadWrite(user)
and then of course using it later in my case in ecs:
const loadBalancedEcsService = new ecsPatterns.ApplicationLoadBalancedEc2Service(this, 'Service', {
cluster: cluster,
memoryLimitMiB: 1024,
taskImageOptions: {
image: ecs.ContainerImage.fromEcrRepository(asset.repository),
environment: {
AWS_ACCESS_KEY_ID: accessKey.ref,
AWS_DEFAULT_REGION: this.region,
},
secrets: {
AWS_SECRET_ACCESS_KEY: ecs.Secret.fromSsmParameter(ssmSecretKey),
},
containerPort: 4873,
},
desiredCount: 1,
domainName: this.getConfig('domainName'),
protocol: ApplicationProtocol.HTTPS,
domainZone: domainZone,
healthCheckGracePeriod: cdk.Duration.seconds(60),
})
Other information
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:17 (11 by maintainers)
Top Results From Across the Web
class AccessKey (construct) · AWS CDK
Creates a new IAM user, access and secret keys, and stores the secret access key in a Secret. const user = new iam.User(this,...
Read more >Create AWS access key and secret access key for an IAM user
Create long-term AWS IAM credentials for your CI/CD system or a legacy microservice, or anything that doesn't support IAM Roles and STS credentials....
Read more >AWS CDK - How to pass Access Key Secret and Secret Key Id ...
My issue is I cannot get aws secret key and id and then, pass as Env variable to my container. See below: First,...
Read more >Managing AWS S3 Bucket And Write IAM User Access Key ...
A simple way of accessing a user's access key Id and the secret is to created AWS CloudFormation outputs for it. ... To...
Read more >AWS Account and User | AWS CDK Workshop
Open a terminal window and use aws configure to set up your environment. Type the access key ID and secret key and choose...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Here is an example using awsCustomResource to store accessKeyId and secretAccessKey in
But custom resource lambda logs will contains your secret for 24h (might have a way to force delete the logStream though)
Ideally when creating a user, you would be able to just specify a key and it would populate that key in your secrets manager on your behalf… Then you’d never need to actually see the key in the first place and it would programatically be available to your app.