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(core): enable additional metadata collection (under feature flag) #32827

Merged

Conversation

GavinZZ
Copy link
Contributor

@GavinZZ GavinZZ commented Jan 10, 2025

Issue # (if applicable)

Closes #.

Reason for this change

Expand the scope of usage data collected by the AWS CDK to better inform CDK development and improve communication for security concerns and emerging issues. Currently, for those that opt in, the CDK collects usage data on your CDK version and which L2 constructs you use. For more information on current CDK behavior, see Version Reporting.

This proposal expands the scope of usage data collection to include the following from L2 constructs in CDK applications:

  • Property keys - Collect which property keys you use from the L2 constructs in your app. This includes property keys nested in dictionary objects.
  • Property values of Boolean and enum types - Collect property key values of only Boolean and enum types. All other types, such as string values or construct references will be redacted.
  • Method name, keys, and property values of Boolean and ENUM types - When you use an L2 construct method, we will collect the method name, property keys, and property values of of Boolean and enum types

Description of changes

Update CDK synthesis code to additionally handle resource metadata.

On feature flag set to true, synthesis will not only inject Metadata usage like version and construct name, it will additionally look for any construct/method/feature flag metadata injected during resource creation.

Note that this PR is only part one so we will have follow up PRs to add metadata injection during resource creation.

On feature flag set to false, it should be the same as before.

Describe any new or updated permissions being added

N/A

Description of how you validated changes

New unit tests added.
New integration tests added.

Checklist


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

AWS CDK Team and others added 5 commits January 9, 2025 19:52
This PR does not currently change CLI functionality. The function
`convertToCliArgs` is not used in the CLI yet which is why this PR is
not fixing a regression. It will eventually be used to strongly-type cli
arguments.

Previously, aliased commands, like `cdk ack` instead of `cdk
acknowledge` would fall through the cracks of the generated convert
function. The switch statement was only switching on command names so we
would not store any options associated with an aliased command.
Specifically, `cdk synth --exclusively` would _not_ store the
`exclusively` flag in the ensuing `CliArguments` object because `synth`
is an alias.

Now we do. This is an additional step forward to being able to use
`CliArguments` in `cli.ts`

----

*By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache-2.0 license*
This PR does not change the functionality of the CLI (yet)

It does however articulate a schema for what `cdk.json` should look like
in the future. I'm aware that we honor a slightly different set of rules
in `cdk.json` that _is not documented anywhere_, and we will have to
honor those rules ad-hoc. However, this will hopefully move us towards a
strongly-typed future where `cdk.json` contents mirror CLI argument
options.

- global options are specified at the base level of `cdk.json`
- command specific options will be prefixed by their command name. NOTE:
some options are honored at the base level today. I will have to, in a
separate PR, find each of these instances and take care of them but
ensuring we still map them to the correct place in `CliArguments`.

```json
{
  "app": "npx ts-node -P tsconfig.json --prefer-ts-exts src/main.ts",
  "output": "cdk.out",
  "build": "npx projen bundle",
  "watch": {
      "exclude": [
        "README.md",
        "cdk*.json",
        "**/*.d.ts",
        "**/*.js",
        "tsconfig.json",
        "package*.json",
        "yarn.lock",
        "node_modules"
    ]
}
```

This will turn into the following `CliArgument` object:

```ts
{
  globalOptions: {
    app:  'npx ts-node -P tsconfig.json --prefer-ts-exts src/main.ts',
    output: 'cdk.out',
    build: 'npx projen bundle',
    watch: {
      exclude: [
          "README.md",
          "cdk*.json",
          "**/*.d.ts",
          "**/*.js",
          "tsconfig.json",
          "package*.json",
          "yarn.lock",
          "node_modules",
      ],
   },
};
```

----

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

---------

Co-authored-by: Momo Kornher <[email protected]>
### Issue # (if applicable)

None

### Reason for this change

AWS AppConfig environment supports [deletion protection](https://docs.aws.amazon.com/appconfig/latest/userguide/deletion-protection.html) and this feature is not configurable from AWS CDK.

### Description of changes

- Add `DeletionProtectionCheck` enum
- Add `deletionProtectionCheck` prop to `EnvironmentOption`

There are two entities, `EnvironmentOptions` and `EnvironmentProps`, where `EnvironmentProps` is designed as an extension of `EnvironmentOptions` with the addition of an `application` prop.

```ts
export interface EnvironmentProps extends EnvironmentOptions {
  /**
   * The application to be associated with the environment.
   */
  readonly application: IApplication;
}

abstract class ApplicationBase extends cdk.Resource implements IApplication, IExtensible {
  public addEnvironment(id: string, options: EnvironmentOptions = {}): IEnvironment {
    return new Environment(this, id, {
      application: this,
      ...options,
    });
  }
```
Therefore, the current argument addition has also been made to `EnvironmentOptions`.

### Describe any new or updated permissions being added

None

### Description of how you validated changes

Add both unit and integ test.

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@GavinZZ GavinZZ requested a review from a team as a code owner January 10, 2025 00:29
@github-actions github-actions bot added the p2 label Jan 10, 2025
@aws-cdk-automation aws-cdk-automation requested a review from a team January 10, 2025 00:29
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Jan 10, 2025
@GavinZZ GavinZZ changed the base branch from yuanhaoz/feat/metadata-collection to main January 10, 2025 00:49
@GavinZZ GavinZZ added the pr/do-not-merge This PR should not be merged at this time. label Jan 10, 2025
@GavinZZ
Copy link
Contributor Author

GavinZZ commented Jan 10, 2025

Temporarily change the target branch to main to trigger integration tests.

Note that adding import statements and this.node.addMetadata(...) statement to Resources' constructor will be in separate PR.
Currently, this will redact ENUM values as well. We do want to keep ENUM values un-redacted, but this will come as a future change.

mergify bot and others added 10 commits January 10, 2025 01:11
… does not allow IPv6 inbound traffic (under feature flag) (#32765)

### Issue # (if applicable)

Closes #32197 .

### Reason for this change

Default generated security group ingress rules for open, dual-stack-without-public-ipv4 ALB does not allow IPv6 traffic. Only a rule for IPv4 ingress traffic is added to the security group rules currently.

### Description of changes

Introduced a new feature flag which is enabled by default so that default generated security group ingress rules now have an additional rule that allows IPv6 ingress from anywhere. 


### Describe any new or updated permissions being added

No new IAM permissions. Added IPv6 security group ingress rules for open, internet-facing ALBs if IP address type  is `dual-stack-without-public-ipv4` and feature flag is set to `true` (default).


### Description of how you validated changes

Added unit test which checks the security group rules for both cases where feature flag is enabled/disabled. Updated integration test snapshot.

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

Co-authored-by: Clare Liguori <[email protected]>

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
This PR does not change CLI functionality because we are not using `CliArguments` yet. This PR includes the following related changes:

- `CliArguments` are renamed `UserInput` to reflect what the schema represents -- they are options available to be specified via CLI options or `cdk.json`.
- the tool previously known as `cli-arg-gen` is now named `user-input-gen` to reflect this change.

----

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

As a product we have standardized on `cdk synth`. This change reflects that while not changing behavior of the CDK CLI at all. It will however matter for the behavior of a future feature where we allow defaults specified in a schematic way in `cdk.json`. The payoff is that instead of requiring `synthesize: { ... }` we instead will require `synth: { ... }`.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
This does not change CLI functionality because `UserInput` is not in use yet. Since we have full control over `UserInput`, i.e. we control the input functions from the CLI or `cdk.json`, we can rename properties however we like. `_` is a relic of `yargs`, we do not need to maintain that convention.


----

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

Closes #32210 

### Reason for this change

Incorrect grammar in a SnapStart warning that appears during cdk deployment.

### Description of changes

Corrected the line:

`SnapStart only support published Lambda versions. Ignore if function already have published versions`

to:

`SnapStart only supports published Lambda versions. Ignore if function already has published versions.`

### Describe any new or updated permissions being added

No permissions changes.

### Description of how you validated changes

No testing needed, only changed text in a warning.

### Checklist
- [X] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@GavinZZ GavinZZ force-pushed the yuanhaoz/feat/metadata-collection-1 branch from ae763b0 to f9f14d4 Compare January 10, 2025 17:42
@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Jan 10, 2025
@GavinZZ GavinZZ requested a review from moelasmar January 10, 2025 21:45
@@ -0,0 +1,96 @@
{
Copy link
Contributor

@moelasmar moelasmar Jan 10, 2025

Choose a reason for hiding this comment

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

I could not see the metadata resource in this template, although you enabled the ENABLE_ADDITIONAL_METADATA_COLLECTION FF. Is this expected

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is expected as all of our integration test have analyticsReporting: false to avoid contaminate the actual DB. I enabled to flag to make sure that it does deploy on my local test machine by overriding analyticsReporting to true.

nested: { foo: '*' },
arr: ['*', '*', '*'],
str: '*',
arrOfObjects: [{ foo: { hello: '*' } }, { myFunc: '*' }],
Copy link
Contributor

Choose a reason for hiding this comment

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

add a TODO here to change this test case with your change to only collect data for our types.

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.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@GavinZZ GavinZZ added the pr-linter/exempt-integ-test The PR linter will not require integ test changes label Jan 10, 2025
@GavinZZ
Copy link
Contributor Author

GavinZZ commented Jan 10, 2025

Verified that this build successfully. Going to ask Core team for a review and set the target branch to feature branch to merge in the change (instead of merging to main).

@aws-cdk-automation aws-cdk-automation dismissed their stale review January 10, 2025 22:54

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

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

@GavinZZ GavinZZ changed the base branch from main to yuanhaoz/feat/metadata-collection January 13, 2025 19:12
@GavinZZ GavinZZ merged commit 54167b5 into yuanhaoz/feat/metadata-collection Jan 13, 2025
16 of 20 checks passed
@GavinZZ GavinZZ deleted the yuanhaoz/feat/metadata-collection-1 branch January 13, 2025 19:13
Copy link

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 13, 2025
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.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@aws-cdk-automation
Copy link
Collaborator

The pull request linter fails with the following errors:

❌ CLI code has changed. A maintainer must run the code through the testing pipeline (git fetch origin pull/32827/head && git push -f origin FETCH_HEAD:test-main-pipeline), then add the 'pr-linter/cli-integ-tested' label when the pipeline succeeds.

PRs must pass status checks before we can provide a meaningful review.

If you would like to request an exemption from the status checks or clarification on feedback, please leave a comment on this PR containing Exemption Request and/or Clarification Request.

@GavinZZ GavinZZ restored the yuanhaoz/feat/metadata-collection-1 branch January 13, 2025 19:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
contribution/core This is a PR that came from AWS. p2 pr/do-not-merge This PR should not be merged at this time. pr/needs-maintainer-review This PR needs a review from a Core Team Member pr-linter/exempt-integ-test The PR linter will not require integ test changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants