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

Add AWS+MySQL Rotator Agent #2

Merged
merged 5 commits into from Aug 8, 2022
Merged

Add AWS+MySQL Rotator Agent #2

merged 5 commits into from Aug 8, 2022

Conversation

nmanoogian
Copy link
Member

@nmanoogian nmanoogian commented Jul 13, 2022

This PR adds an agent for rotating MySQL database credentials using an AWS Lambda.

Note that we're fetching our keyset from S3, see the security review doc for more details.

Closes ENG-4294

This allows consumers of this lib to import without `--experimental-specifier-resolution=node`
Now that all relative imports have extensions, this isn't required.
});
}

export async function fetchS3KeySet(bucket = "doppler-keys") {
Copy link
Member Author

Choose a reason for hiding this comment

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

This bucket doesn't exist yet. We're in the process of getting a security review on the S3 keyset fetch approach and I'll post updates here

@nmanoogian nmanoogian force-pushed the nic/aws-mysql branch 2 times, most recently from fb1e96c to f297131 Compare July 13, 2022 22:08
# Remove node_modules to be reinstalled later
RUN rm -r node_modules

FROM public.ecr.aws/lambda/nodejs:16
Copy link
Member Author

Choose a reason for hiding this comment

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

Note that this Dockerfile is still meant to build a deployable image. We're currently considering switching to S3-based code bundle deployments. If we go that route, not much will change other than this file and some additional deploy scripts.

@linear
Copy link

linear bot commented Jul 13, 2022

ENG-4295 Implement secret engine for rotation agent + AWS Postgres

Implement an engine to use in the generic rotation controller.

Comment on lines 13 to 15
export async function fetchS3KeySet(bucket = "doppler-keys") {
const s3Client = new S3({ forcePathStyle: true });
const keyFile = await s3Client.getObject({ Bucket: bucket, Key: "secret-agents-jwks.json" });
Copy link
Contributor

Choose a reason for hiding this comment

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

These can change later but I want to align on bucket/file naming. Ideally we follow the same pattern as our keys repo (i.e. $repo/secret-agents/jwks.json)

Copy link
Member Author

Choose a reason for hiding this comment

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

I like that 👍 I'll change it preemptively

@@ -0,0 +1,20 @@
{
"name": "aws-utils",
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we going to publish this? If not, probably best to add private: true

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. We won't publish these immediately but in the future (6mo-1y), we'll probably be publishing these. Should we make them private: true for now and change them later? Or leave it as-is for now?

Regardless, we should definitely make sure that our licenses and other package metadata are all accurate

COPY ./apps/aws-mysql-rotator/package*.json ./apps/aws-mysql-rotator/
RUN npm install --workspace apps/aws-mysql-rotator

RUN ls -l node_modules
Copy link
Contributor

Choose a reason for hiding this comment

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

For debugging?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, my bad -- missed this!

COPY --from=build /usr/src/app .

# Only install production dependencies
RUN npm install --production
Copy link
Contributor

Choose a reason for hiding this comment

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

We probably want npm clean-install --production (I think it supports --production)

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good! Because we're doing this from a brand new image, I don't think this is strictly necessary but it's probably a good practice. I verified that clean-install does support the --production flag

if (process.env.OVERRIDE_KEY_SET) {
keySetOption = { type: "local", keySet: JSON.parse(process.env.OVERRIDE_KEY_SET) };
} else {
keySetOption = { type: "local", keySet: await fetchS3KeySet(process.env.OVERRIDE_KEY_SET_S3_BUCKET ?? undefined) };
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: is the ?? undefined needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, I was just trying to indicate that it was indeed optional. If you think that's clear already (given "override" in the name) then I'll drop it

@@ -0,0 +1,134 @@
import mysql, { QueryError } from "mysql2/promise";
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a more "official" mysql package we can use?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good callout. I hunted around for mysql libs and found a few options and this is what I turned up:

@nmanoogian
Copy link
Member Author

Force push addresses review feedback

@linear
Copy link

linear bot commented Jul 14, 2022

ENG-4294 Implement MySQL + AWS rotation agent v1

  • Perform request authentication and validation
  • Implement status check
  • Implement all interface functions

@nmanoogian nmanoogian merged commit 2c89904 into main Aug 8, 2022
@nmanoogian nmanoogian deleted the nic/aws-mysql branch August 8, 2022 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants