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

(integ-tests-alpha): Account ID not redacted in integration test #30831

Closed
jdukewich opened this issue Jul 11, 2024 · 5 comments
Closed

(integ-tests-alpha): Account ID not redacted in integration test #30831

jdukewich opened this issue Jul 11, 2024 · 5 comments
Assignees
Labels
@aws-cdk/integ-tests bug This issue is a bug. effort/small Small work item – less than a day of effort p3

Comments

@jdukewich
Copy link
Contributor

jdukewich commented Jul 11, 2024

Describe the bug

In snapshots from integration tests, you will notice that any account IDs get redacted and replaced with ${AWS::AccountId}. However, if you try to write an integration test that creates a security group, it will not remove the account ID from the *.assets.json or manifest.json files.

Expected Behavior

I expected my AWS Account ID to be replaced by ${AWS::AccountId} in the generated snapshot files.

Current Behavior

My AWS Account ID is not replaced by ${AWS::AccountId} in the generated snapshot files.

Reproduction Steps

  1. Create a new integration test packages/@aws-cdk-testing/framework-integ/test/aws-ec2/test/integ.security-group.ts
  2. Make sure your AWS credentials are configured
  3. Copy the following code into the test file
import * as cdk from 'aws-cdk-lib';
import * as ec2 from 'aws-cdk-lib/aws-ec2';

import { EC2_RESTRICT_DEFAULT_SECURITY_GROUP } from 'aws-cdk-lib/cx-api';
import { IntegTest } from '@aws-cdk/integ-tests-alpha';

const app = new cdk.App();

const env = {
  account: process.env.CDK_INTEG_ACCOUNT || process.env.CDK_DEFAULT_ACCOUNT,
  region: process.env.CDK_INTEG_REGION || process.env.CDK_DEFAULT_REGION,
};

class SgLookupStack extends cdk.Stack {
  constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
    super(scope, id, props);
    this.node.setContext(EC2_RESTRICT_DEFAULT_SECURITY_GROUP, false);

    const testVpc = new ec2.Vpc(this, 'MyVpc', {
      vpcName: 'my-vpc-name',
      ipAddresses: ec2.IpAddresses.cidr('10.0.0.0/16'),
      subnetConfiguration: [],
      natGateways: 0,
    });
    new ec2.SecurityGroup(this, 'MySgA', { vpc: testVpc, securityGroupName: 'my-sg' });
  }
}

const stack = new SgLookupStack(app, 'StackWithSg', { env });
new IntegTest(app, 'SgLookupTest', {
  testCases: [stack],
});

app.synth();
  1. Run the test yarn build && yarn integ --update-on-failed aws-ec2/test/integ.security-group
  2. Inspect the snapshot files (specifically *.assets.json and manifest.json) and observe that your AWS account ID is not redacted and replaced by the placeholder.

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.148.1

Framework Version

No response

Node.js Version

v20.11.1

OS

Ubuntu via WSL2

Language

TypeScript

Language Version

No response

Other information

No response

@jdukewich jdukewich added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 11, 2024
@github-actions github-actions bot added the @aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud label Jul 11, 2024
@ashishdhingra ashishdhingra added @aws-cdk/integ-tests and removed @aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud labels Jul 12, 2024
@ashishdhingra ashishdhingra self-assigned this Jul 12, 2024
@ashishdhingra ashishdhingra added needs-reproduction This issue needs reproduction. and removed needs-triage This issue or PR still needs to be triaged. labels Jul 12, 2024
@ashishdhingra ashishdhingra added effort/small Small work item – less than a day of effort p3 labels Jul 17, 2024
@ashishdhingra
Copy link
Contributor

@jdukewich Good afternoon. Please execute the following steps to re-generate the correct snapshots:

  • Do not define and use env variable. In other words, modify your code to the one below:
import * as cdk from 'aws-cdk-lib';
import * as ec2 from 'aws-cdk-lib/aws-ec2';

import { EC2_RESTRICT_DEFAULT_SECURITY_GROUP } from 'aws-cdk-lib/cx-api';
import { IntegTest } from '@aws-cdk/integ-tests-alpha';

const app = new cdk.App();

class SgLookupStack extends cdk.Stack {
  constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
    super(scope, id, props);
    this.node.setContext(EC2_RESTRICT_DEFAULT_SECURITY_GROUP, false);

    const testVpc = new ec2.Vpc(this, 'MyVpc', {
      vpcName: 'my-vpc-name',
      ipAddresses: ec2.IpAddresses.cidr('10.0.0.0/16'),
      subnetConfiguration: [],
      natGateways: 0,
    });
    new ec2.SecurityGroup(this, 'MySgA', { vpc: testVpc, securityGroupName: 'my-sg' });
  }
}

const stack = new SgLookupStack(app, 'StackWithSg');
new IntegTest(app, 'SgLookupTest', {
  testCases: [stack],
});

app.synth();
  • Delete your old snapshot directory integ.security-group.js.snapshot.
  • Make sure the .ts file is transpiled to .js file (this could be easily done by using yarn watch in a separate terminal window)
  • Re-run yarn integ --update-on-failed test/aws-ec2/test/integ.security-group.js from /projects/aws-cdk/packages/@aws-cdk-testing/framework-integ.

Thanks,
Ashish

@ashishdhingra ashishdhingra added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed needs-reproduction This issue needs reproduction. labels Jul 17, 2024
@TheRealAmazonKendra
Copy link
Contributor

After you have updated the snapshot, if you run the build again from root, your build should fail. We have a tool git-secrets-scan that specifically checks for account numbers added to code. I assume you are not running the entire build locally after updating integ tests, but we do upon submission of the PR and it cannot merge if there are account numbers or other secrets present.

@jdukewich
Copy link
Contributor Author

Looks good removing env, thank you

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Jul 18, 2024
@ashishdhingra ashishdhingra closed this as not planned Won't fix, can't repro, duplicate, stale Jul 18, 2024
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@aws-cdk-automation
Copy link
Collaborator

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.

@aws aws locked as resolved and limited conversation to collaborators Jul 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
@aws-cdk/integ-tests bug This issue is a bug. effort/small Small work item – less than a day of effort p3
Projects
None yet
Development

No branches or pull requests

4 participants