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

feat(secretsmanager/rds): support credential rotation #2052

Merged
merged 18 commits into from
Mar 20, 2019

Conversation

jogold
Copy link
Contributor

@jogold jogold commented Mar 19, 2019

Add construct for rotation schedule, secret target attachment and RDS rotation single user.

This is needed in order to implement something like cluster.addRotationSingleUser(...) in aws-rds which will allow to create a cluster (or instance, no construct yet) with a secrets manager generated master password and add rotation to it (PR to follow if this one is accepted).

Question: where does the construct RdsRotationSingleUser fit? Here in aws-secretsmanager or in aws-rds?


Pull Request Checklist

  • Testing
    • Unit test added (prefer not to modify an existing test, otherwise, it's probably a breaking change)
    • CLI change?: coordinate update of integration tests with team
    • cdk-init template change?: coordinated update of integration tests with team
  • Docs
    • jsdocs: All public APIs documented
    • README: README and/or documentation topic updated
  • Title and Description
    • Change type: title prefixed with fix, feat will appear in changelog
    • Title: use lower-case and doesn't end with a period
    • Breaking?: last paragraph: "BREAKING CHANGE: <describe what changed + link for details>"
    • Issues: Indicate issues fixed via: "Fixes #xxx" or "Closes #xxx"
  • Sensitive Modules (requires 2 PR approvers)
    • IAM Policy Document (in @aws-cdk/aws-iam)
    • EC2 Security Groups and ACLs (in @aws-cdk/aws-ec2)
    • Grant APIs (only if not based on official documentation with a reference)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license.

Add construct for rotation schedule, secret target attachment and RDS rotation
single user.
@jogold jogold requested a review from a team as a code owner March 19, 2019 12:01
Copy link
Contributor

@rix0rrr rix0rrr left a comment

Choose a reason for hiding this comment

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

Please also describe these classes in the README. A section should be something like "how to set up credential rotation"

/**
* The connections object of the RDS database instance or cluster.
*/
connections: ec2.Connections;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I'd rather you pass an IConnectable here. Any reason that wouldn't work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, this should have been an IConnectable.

/**
* Options to add a secret attachement to a secret.
*/
export interface SecretTargetAttachmentOptions {
Copy link
Contributor

Choose a reason for hiding this comment

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

Feel like this should be an interface like:

export interface ISecretAttachmentTarget {
  asSecretAttachmentTarget(): SecretAttachmentTargetProps;
}

export interface SecretAttachmentTargetProps {
   targetId: string;
   targetType: AttachmentTargetType;
}

export interface SecretTargetAttachmentOptions {
  target: ISecretAttachmentTarget;
}

And then have the DBInstance and DBCluster classes implement ISecretAttachmentTarget.

// This allows to reference the secret after attachment (dependency). When
// creating a secret for a RDS cluster or instance this is the secret that
// will be used as the input for the rotation.
this.secret = Secret.import(this, 'Secret', {
Copy link
Contributor

Choose a reason for hiding this comment

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

It feels like this is something that users might forget, especially since these docs are in implementation notes.

Another idea (not necessarily saying you must do this), how about changing this into:

class AttachedSecret implements ISecret {
  ...
}

So that an AttachedSecret can be used anywhere a secret can be used? And if not that, then at least put these notes in a public comment somewhere, seems very relevant to this construct's usage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like this idea of the AttachedSecret

@@ -0,0 +1,204 @@
import ec2 = require('@aws-cdk/aws-ec2');
Copy link
Contributor

Choose a reason for hiding this comment

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

Feels like this whole file should live in the aws-rds package.

Copy link
Contributor Author

@jogold jogold Mar 19, 2019

Choose a reason for hiding this comment

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

OK to move the RDS rotation, in the same PR then? It breaks the conventional commit + squash convention here...

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure what you mean. The only thing it might break is the scope, if the scope were a single package.

I would feel comfortable with a feat(secretsmanager/rds): support credential rotation.

@jogold jogold changed the title feat(secretsmanager): add construct for RDS rotation single user feat(secretsmanager/rds): support credential rotation Mar 19, 2019
@jogold
Copy link
Contributor Author

jogold commented Mar 19, 2019

Since there's already a breaking change for aws-rds coming from #2025, can we add here the switch from kmsKeyArn: string to kmsKey: kms.IEncryptionKey in the DatabaseClusterProps?

Copy link
Contributor

@rix0rrr rix0rrr left a comment

Choose a reason for hiding this comment

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

Jonathan, I think this is just fantastic. Thank you!

@@ -53,3 +53,28 @@ attributes:
```ts
const writeAddress = cluster.clusterEndpoint.socketAddress; // "HOSTNAME:PORT"
```

### Rotating master password
When the master password is generated and stored in AWS Secrets Manager, it can be rotated automatically: [example of setting up master password rotation](test/integ.cluster-rotation.lit.ts)
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to be on a line by itself.

*/
export class DatabaseCluster extends cdk.Construct implements IDatabaseCluster {
export abstract class DatabaseClusterBase extends cdk.Construct implements IDatabaseCluster {
Copy link
Contributor

Choose a reason for hiding this comment

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

<3

* Parameter or the SSM Parameter Store instead.
* Do not put passwords in your CDK code directly.
*
* @default a Secrets Manager generated password
Copy link
Contributor

Choose a reason for hiding this comment

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

<3

@rix0rrr
Copy link
Contributor

rix0rrr commented Mar 20, 2019

Will merge after current release process is over. You just missed the cut, sorry, it will be in the next release.

@jogold
Copy link
Contributor Author

jogold commented Mar 20, 2019

No prob, have you seen this?

Since there's already a breaking change for aws-rds coming from #2025, can we add here the switch from kmsKeyArn: string to kmsKey: kms.IEncryptionKey in the DatabaseClusterProps?

@rix0rrr
Copy link
Contributor

rix0rrr commented Mar 20, 2019

Oh totally. Though can you create a new PR for that please?

@rix0rrr rix0rrr merged commit bf79c82 into aws:master Mar 20, 2019
@jogold jogold deleted the secret-rotation branch March 20, 2019 18:19
@jogold
Copy link
Contributor Author

jogold commented Mar 20, 2019

Oh totally. Though can you create a new PR for that please?

See #2063

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants