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

fix(secretsmanager): rotation function name can exceed 64 chars #7896

Merged
merged 22 commits into from
Jun 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/@aws-cdk/aws-secretsmanager/lib/secret-rotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@ export class SecretRotation extends Construct {
throw new Error('The `masterSecret` must be specified for application using the multi user scheme.');
}

const rotationFunctionName = this.node.uniqueId;
// Max length of 64 chars, get the last 64 chars
const uniqueId = this.node.uniqueId;
const rotationFunctionName = uniqueId.substring(Math.max(uniqueId.length - 64, 0), uniqueId.length);
Comment on lines +213 to +215
Copy link
Contributor Author

@jogold jogold May 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if something in @aws-cdk/core wouldn't be useful for such cases:

this.node.uniqueIdOf(50); // Custom length
this.node.uniqueId64; // Last 64 chars

There are several places in the code where an id derived from unique id is truncated.

Or is this in constructs now?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A more general solution would be nice... and this is blocking me today. :(


const securityGroup = props.securityGroup || new ec2.SecurityGroup(this, 'SecurityGroup', {
vpc: props.vpc,
Expand Down
64 changes: 64 additions & 0 deletions packages/@aws-cdk/aws-secretsmanager/test/test.secret-rotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,68 @@ export = {

test.done();
},

'rotation function name does not exceed 64 chars'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'VPC');
const secret = new secretsmanager.Secret(stack, 'Secret');
const target = new ec2.Connections({
defaultPort: ec2.Port.tcp(3306),
securityGroups: [new ec2.SecurityGroup(stack, 'SecurityGroup', { vpc })],
});

// WHEN
const id = 'SecretRotation'.repeat(5);
new secretsmanager.SecretRotation(stack, id, {
application: secretsmanager.SecretRotationApplication.MYSQL_ROTATION_SINGLE_USER,
secret,
target,
vpc,
});

// THEN
expect(stack).to(haveResource('AWS::Serverless::Application', {
Parameters: {
endpoint: {
'Fn::Join': [
'',
[
'https://secretsmanager.',
{
Ref: 'AWS::Region',
},
'.',
{
Ref: 'AWS::URLSuffix',
},
],
],
},
functionName: 'RotationSecretRotationSecretRotationSecretRotationSecretRotation',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
functionName: 'RotationSecretRotationSecretRotationSecretRotationSecretRotation',
functionName: 'VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName',

I know the symmetry is pleasing, but it also makes it unnecessarily difficult to figure out how the name is generated.

vpcSecurityGroupIds: {
'Fn::GetAtt': [
'SecretRotationSecretRotationSecretRotationSecretRotationSecretRotationSecurityGroupBFCB171A',
'GroupId',
],
},
vpcSubnetIds: {
'Fn::Join': [
'',
[
{
Ref: 'VPCPrivateSubnet1Subnet8BCA10E0',
},
',',
{
Ref: 'VPCPrivateSubnet2SubnetCFCDAA7A',
},
],
],
},
},
}));

test.done();
},
};