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(logs): support DataProtectionPolicy in LogGroup construct #23402

Merged
merged 22 commits into from
May 8, 2023

Conversation

kchg
Copy link
Contributor

@kchg kchg commented Dec 20, 2022

Sensitive data protection for CloudWatch Logs was launched at re:Invent 2022. This feature will enable that property under DataProtectionPolicy as a JSON object in the LogGroup construct.

Use case: A data protection policy can help safeguard sensitive data that's ingested by the log group by auditing and masking the sensitive log data. When a user who does not have permission to view masked data views a log event that includes masked data, the sensitive data is replaced by asterisks.

closes #23399


All Submissions:

Adding new Construct Runtime Dependencies:

  • This PR adds new construct runtime dependencies following the process described here

New Features

  • Have you added the new feature to an integration test?
    • Did you use yarn integ to deploy the infrastructure and generate the snapshot (i.e. yarn integ without --dry-run)?

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

@gitpod-io
Copy link

gitpod-io bot commented Dec 20, 2022

@github-actions github-actions bot added the beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK label Dec 20, 2022
@aws-cdk-automation aws-cdk-automation requested a review from a team December 20, 2022 01:01
@github-actions github-actions bot added feature-request A feature should be added or improved. p2 labels Dec 20, 2022
Copy link
Contributor

@peterwoodworth peterwoodworth left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @kchg!

As it is now, this PR doesn't introduce any functionality that isn't already easily achievable through escape hatches. So, instead of asking our users to fully understand how to build a data protection policy and supply that directly as an object, it would be great to abstract this such that the dataProtectionPolicy prop takes in a class with a name like DataProtectionPolicy that can contain one or more configurable DataPolicyStatements. See our Policy and PolicyStatement classes in our IAM module for reference on what this might look like 🙂 These classes contain methods to modify existing statements, and ways to add statements to an existing policy. I think these methods would be useful in this case as well. Open to thoughts/suggestions!

@kchg
Copy link
Contributor Author

kchg commented Jan 5, 2023

Thanks for the feedback @peterwoodworth! I'll make some changes here to abstract away the details of creating a data protection policy, so that users can just provide a list of data identifiers and any audit destinations.

@aws-cdk-automation
Copy link
Collaborator

This PR has been in the CHANGES REQUESTED state for 3 weeks, and looks abandoned. To keep this PR from being closed, please continue work on it. If not, it will automatically be closed in a week.

@kchg kchg force-pushed the LogGroup-DataProtectionPolicy branch from d820ef6 to 232799b Compare January 11, 2023 21:19
@mergify mergify bot dismissed peterwoodworth’s stale review January 11, 2023 21:20

Pull request has been modified.

@kchg kchg force-pushed the LogGroup-DataProtectionPolicy branch from 9edc82e to 9e531b9 Compare January 11, 2023 22:23
@github-actions github-actions bot added the effort/medium Medium work item – several days of effort label Jan 11, 2023
@kchg
Copy link
Contributor Author

kchg commented Jan 13, 2023

Hi @peterwoodworth, this PR should allow users to add a data protection policy to a log group without knowing the actual structure of the policy. Could you please review this? Thanks.

Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

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

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

@kchg kchg changed the title feat(aws-logs): support DataProtectionPolicy in LogGroup construct feat(logs): support DataProtectionPolicy in LogGroup construct Jan 18, 2023
@aws-cdk-automation aws-cdk-automation dismissed their stale review January 18, 2023 00:16

✅ Updated pull request passes all PRLinter validations. Dissmissing previous PRLinter review.

@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

1 similar comment
@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

@kchg kchg removed the request for review from peterwoodworth January 23, 2023 17:19
@kchg
Copy link
Contributor Author

kchg commented May 2, 2023

Hi @corymhall, thank you for the review, I've made changes or addressed each comment from your review, please let me know what you think.

@kchg kchg requested a review from corymhall May 2, 2023 01:58
@mergify mergify bot dismissed corymhall’s stale review May 2, 2023 15:39

Pull request has been modified.

@kchg kchg requested a review from corymhall May 2, 2023 15:41
Copy link
Contributor

@corymhall corymhall left a comment

Choose a reason for hiding this comment

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

Looking good! Just a couple more suggestions.

/**
* Represents a data protection policy in a log group.
*/
export class DataProtectionPolicy {
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah on second look I was thinking about extending construct because the constructor took a scope argument. I think we should modify this API a bit to be something like.

class DataProtectionPolicy {
  constructor(props: DataProtectionPolicyProps) {
    ...
  }
  public bind(scope: Construct): DataProtectionPolicyConfig {
    ...
  }
}

and then

new CfnLogGroup(this, 'Resource', {
  ...,
  dataProtectionPolicy: props.dataProtectionPolicy.bind(this),

/**
* Data Protection Policy for this log group.
*
* @default null
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
* @default null
* @default - no data protection policy

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

- Add bind method to remove need for scope from constructor
- Made DataIdentifier required and add check for length
@mergify mergify bot dismissed corymhall’s stale review May 4, 2023 17:12

Pull request has been modified.

@kchg kchg requested a review from corymhall May 4, 2023 17:40
Copy link
Contributor

@corymhall corymhall left a comment

Choose a reason for hiding this comment

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

Looking good! Just a couple of minor things

* @param scope the Construct scope
* @returns the data protection policy
*/
public bind(scope: Construct): DataProtectionPolicyConfig {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is a public API, we should allow for non-breaking changes that we might need to
make in the future. We can either make this an internal API by adding
@internal and changing the name to _bind() or we can add a second optional
props argument that is empty for now. public bind(scope: Construct, props: DataProtectionPolicyBindProps = {})

If you don't think there is any use case for using this outside of the internal
library usage then I would recommend going with @internal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to _bind()

@@ -0,0 +1,28 @@
"use strict";
Copy link
Contributor

Choose a reason for hiding this comment

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

This file should not have been git ignored. Can you check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like the .gitignore was updated since the commit adding these files, I've removed this file from the PR.

@@ -0,0 +1 @@
export {};
Copy link
Contributor

Choose a reason for hiding this comment

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

This file should have been git ignored, can you check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed this file.

- Made the bind() method internal with _bind()
- Removed gitignored files
@mergify mergify bot dismissed corymhall’s stale review May 5, 2023 21:30

Pull request has been modified.

@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label May 5, 2023
@kchg kchg requested a review from corymhall May 5, 2023 22:00
corymhall
corymhall previously approved these changes May 8, 2023
@mergify
Copy link
Contributor

mergify bot commented May 8, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot dismissed corymhall’s stale review May 8, 2023 10:33

Pull request has been modified.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: a4be031
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify
Copy link
Contributor

mergify bot commented May 8, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit ed3962a into aws:main May 8, 2023
7 checks passed
@renatoargh
Copy link

Hey, thanks for the great PR!

A question: this PR introduces the ability to associate a DataProtectionPolicy to a LogGroup when you create it via the new LogGroup({ ... }) constructor. However, I would like to associate a DataProtectionPolicy with an existing LogGroup to use the data protection feature with an existing lambda. I know I can retrieve an existing LogGroup like this:

const existingLogGroup = LogGroup.fromLogGroupName(
    scope,
    'ExistingLambdaLogGroup',
    '/aws/lambda/my-existing-function-name'
);

But then I am unable to do something like existingLogGroup.addDataProtectionPolicy(new DataProtectionPolicy({ ... })).

Are there any plans to support it or Is there any way to make it work that I cannot see?

I tried creating a logGroup from scratch and associating when creating the lambda but it doesn't seem possible to make lambda use a different log group than the default /aws/lambda/${functionName}.

Again, thanks a lot!

@kevincifuentes-eb
Copy link

@renatoargh Did you find any workaround for that use case? Thanks!

@kevincifuentes-eb
Copy link

Any idea if this is possible somehow? I'm also using CDK for our infrastructure and don't see a way to set a custom log group or simply modify the existing one on the lambda to add that DataProtectionPolicy.
Thanks for your help!

@kevincifuentes-eb
Copy link

If just someone gets to the same PR here, I finally was able to implement it using AWSCustomResource executing a AWSSDKCall when the CloudFormation is created (onCreate)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aws-logs: support DataProtectionPolicy in LogGroup construct
8 participants