Skip to content

Commit

Permalink
fix(redshift): Fix Redshift User Secret Multi-User Rotation
Browse files Browse the repository at this point in the history
Fixes Redshift User Secret Multi-User Rotation for new Users
by including `masterarn` in the Secret's Serialized JSON Object Text.

Note: This doesn't affect existing users (nor fixes roation for them)
since the secret string template is only used when the secret is
first created. For those existing secrets, the secret text will need
to be updated to include `masterarn` using the GetSecretValue and
UpdateSecret SecretManager APIs.

closes #28852

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
pennia committed Jan 25, 2024
1 parent b1e3dfd commit 4ac9db6
Show file tree
Hide file tree
Showing 25 changed files with 4,169 additions and 3 deletions.
14 changes: 12 additions & 2 deletions packages/@aws-cdk/aws-redshift-alpha/lib/database-secret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ export interface DatabaseSecretProps {
* @default default master key
*/
readonly encryptionKey?: kms.IKey;

/**
* The master secret which will be used to rotate this secret.
*
* @default - no master secret information will be included
*/
readonly masterSecret?: secretsmanager.ISecret;
}

/**
Expand All @@ -30,10 +37,13 @@ export class DatabaseSecret extends secretsmanager.Secret {
encryptionKey: props.encryptionKey,
generateSecretString: {
passwordLength: 30, // Redshift password could be up to 64 characters
secretStringTemplate: JSON.stringify({ username: props.username }),
secretStringTemplate: JSON.stringify({
username: props.username,
masterarn: props.masterSecret?.secretArn,
}),
generateStringKey: 'password',
excludeCharacters: '"@/\\\ \'',
},
});
}
}
}
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-redshift-alpha/lib/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export class User extends UserBase {
const secret = new DatabaseSecret(this, 'Secret', {
username,
encryptionKey: props.encryptionKey,
masterSecret: props.adminUser,
});
const attachedSecret = secret.attach(props.cluster);
this.password = attachedSecret.secretValueFromJson('password');
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4ac9db6

Please sign in to comment.