Skip to content

feat(pipelines): confirm IAM changes before starting the deployment#15441

Merged
mergify[bot] merged 24 commits intomasterfrom
bryanpan342/security-only-option
Jul 16, 2021
Merged

feat(pipelines): confirm IAM changes before starting the deployment#15441
mergify[bot] merged 24 commits intomasterfrom
bryanpan342/security-only-option

Conversation

@BryanPan342
Copy link
Copy Markdown
Contributor

@BryanPan342 BryanPan342 commented Jul 7, 2021

Add an option under addApplication for a given stage to create a CodeBuild that checks if there are any security changes within the stage's assembly.

  • If the changes exist: manual approval is required
  • else: a lambda function will automatically approve the manual approval action

Adding a security check to an application creates two actions that precede the prepare
and deploy actions of an application:

  1. A CodeBuild Project that runs a security diff on the stage
  2. A Manual Approval Action that can be approved via a shared Lambda function.
Pipeline
├── Stage: Build
│   └── ...
├── Stage: Synth
│   └── ...
├── Stage: UpdatePipeline
│   └── ...
├── Stage: MyApplicationStage
│   └── Actions
│       ├── MyApplicationSecurityCheck       // Security Diff Action
│       ├── MyApplicationManualApproval      // Manual Approval Action
│       ├── Stack.Prepare
│       └── Stack.Deploy
└── ...
Example Usage You can enable the security check in one of two ways:
  1. Enable security check across the entire CdkStage

    const pipeline = new CdkPipeline(app, 'Pipeline', {
      // ...source and build information here (see above)
    });
    const stage = pipeline.addApplicationStage(new MyApplication(this, 'Testing'), {
      securityCheck: true,
    });
    // The 'PreProd' application is also run against a security diff because we configured
    // the stage to enable security checks
    stage.addApplication(new MyApplication(this, 'PreProd'));
  2. Enable security check for a single application

    const pipeline = new CdkPipeline(app, 'Pipeline', {
      // ...source and build information here (see above)
    });
    const stage = pipeline.addApplicationStage(new MyApplication(this, 'NoCheck'));
    stage.addApplication(new MyApplication(this, 'RunSecurityDiff'), {
      securityCheck: true,
    });

Fixes: #12748


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
Copy Markdown

gitpod-io bot commented Jul 7, 2021

@BryanPan342 BryanPan342 marked this pull request as draft July 7, 2021 02:19
@BryanPan342 BryanPan342 self-assigned this Jul 7, 2021
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Jul 7, 2021
Copy link
Copy Markdown
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.

This is looking great! Amazing you've been able to get this to work so quickly

fix test

docs + notifications
@BryanPan342 BryanPan342 force-pushed the bryanpan342/security-only-option branch from e9ac203 to c87f688 Compare July 10, 2021 00:52
@BryanPan342 BryanPan342 changed the title feat: implement security check during pipelines application stage feat(pipelines): implement security check during pipelines application stage Jul 12, 2021
@BryanPan342 BryanPan342 requested a review from rix0rrr July 13, 2021 02:55
@BryanPan342 BryanPan342 marked this pull request as ready for review July 13, 2021 02:55
@BryanPan342 BryanPan342 added @aws-cdk/pipelines CDK Pipelines library feature/enhancement A new API to make things easier or more intuitive. A catch-all for general feature requests. labels Jul 13, 2021
@BryanPan342 BryanPan342 added this to the [GA] CDK Pipelines milestone Jul 13, 2021

### Security Check

CDK Pipelines offers a security check option for the applications you deploy. The
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Try to put yourself in the shoes of the customer when reading this section.

Do you care more about how it's implemented, or do you care more about what it does for YOU, the customer, and why/when you should be using it?

This rule of thumb will also help you to think about what to include. If this was someone else's product that you were just using, at what point would you be satisfied? I know you are trying to be thorough but for my money there's too much detail in the section below, eating up attention and space for other topics.

// ...source and build information here (see above)
});
const stage = pipeline.addApplicationStage(new MyApplication(this, 'Testing'), {
securityCheck: true,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm thinking this term is a little vague.

How about we call it confirmPermissionsWidening ? Broadening ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

how about checkBroadeningPermissions?

Copy link
Copy Markdown
Contributor

@rix0rrr rix0rrr Jul 14, 2021

Choose a reason for hiding this comment

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

I think confirm is a better verb to use, as it also implies what's going to happen ("check" leaves the door open too much... so you checked it. Now what?)

confirmPermissionsBroadening then?

runOrder: this.nextSequentialRunOrder(),
additionalInformation: `#{${appStageName}SecurityCheck.MESSAGE}`,
// Boot strap cicd2 us-west-1 --trust
externalEntityLink: `https://#{${appStageName}SecurityCheck.LINK}`,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I saw you saying in the other thing the https was added by the manual approval action, but I didn't know WE were the ones making that choice. Is this necessary?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

LMAO that's embarrassing... i guess this was a change i made early on that i just forgot about.. I think it's better if we remove it and keep it to the script itself

project: cdkDiffProject,
variablesNamespace: `${appStageName}SecurityCheck`,
environmentVariables: {
STACK_NAME: {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm noticing we have STACK_NAME here -- what if there are more than one stacks in the stage we're deploying?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah so this is the pipeline stack name..not like a stack within the stage

@rix0rrr rix0rrr changed the title feat(pipelines): implement security check during pipelines application stage feat(pipelines): confirm IAM changes before starting the deployment Jul 16, 2021
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Jul 16, 2021

Thank you for contributing! Your pull request will be updated from master 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 ebba618 into master Jul 16, 2021
@mergify mergify bot deleted the bryanpan342/security-only-option branch July 16, 2021 13:56
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Jul 16, 2021

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

@aws-cdk-automation
Copy link
Copy Markdown
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: faa5847
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

// Run invoke only if cdk diff passes (returns exit code 0)
// 0 -> true, 1 -> false
ifElse({
condition: 'cdk diff -a . --security-only --fail $STAGE_PATH/\\*',
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This will not work because $STAGE_PATH is the pipeline stack name

We need to target the assembly for the stage itself:
assembly-PipelineStackName-StageName

@mrpackethead
Copy link
Copy Markdown

THis is a very interesting and exciting peice of work to add to the project. Looking forward to seeing it soon.

The question now begs, what other things can we check in a a similar fashion

@BryanPan342
Copy link
Copy Markdown
Contributor Author

The question now begs, what other things can we check in a a similar fashion

Stay tuned :D

TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this pull request Aug 3, 2021
…ws#15441)

Add an option under `addApplication` for a given stage to create a CodeBuild that checks if there are any security changes within the stage's assembly. 

* If the changes exist: **manual approval is required**
* else: a lambda function will automatically approve the manual approval action

Adding a security check to an application creates two actions that precede the prepare
and deploy actions of an application:
1. A CodeBuild Project that runs a security diff on the stage
2. A Manual Approval Action that can be approved via a shared Lambda function.

```txt
Pipeline
├── Stage: Build
│   └── ...
├── Stage: Synth
│   └── ...
├── Stage: UpdatePipeline
│   └── ...
├── Stage: MyApplicationStage
│   └── Actions
│       ├── MyApplicationSecurityCheck       // Security Diff Action
│       ├── MyApplicationManualApproval      // Manual Approval Action
│       ├── Stack.Prepare
│       └── Stack.Deploy
└── ...
```

<details>
<summary>Example Usage</summary>
You can enable the security check in one of two ways:

1. Enable security check across the entire `CdkStage`

    ```ts
    const pipeline = new CdkPipeline(app, 'Pipeline', {
      // ...source and build information here (see above)
    });
    const stage = pipeline.addApplicationStage(new MyApplication(this, 'Testing'), {
      securityCheck: true,
    });
    // The 'PreProd' application is also run against a security diff because we configured
    // the stage to enable security checks
    stage.addApplication(new MyApplication(this, 'PreProd'));
    ```

2. Enable security check for a single application

    ```ts
    const pipeline = new CdkPipeline(app, 'Pipeline', {
      // ...source and build information here (see above)
    });
    const stage = pipeline.addApplicationStage(new MyApplication(this, 'NoCheck'));
    stage.addApplication(new MyApplication(this, 'RunSecurityDiff'), {
      securityCheck: true,
    });
    ```

</details>

Fixes: aws#12748

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
hollanddd pushed a commit to hollanddd/aws-cdk that referenced this pull request Aug 26, 2021
…ws#15441)

Add an option under `addApplication` for a given stage to create a CodeBuild that checks if there are any security changes within the stage's assembly. 

* If the changes exist: **manual approval is required**
* else: a lambda function will automatically approve the manual approval action

Adding a security check to an application creates two actions that precede the prepare
and deploy actions of an application:
1. A CodeBuild Project that runs a security diff on the stage
2. A Manual Approval Action that can be approved via a shared Lambda function.

```txt
Pipeline
├── Stage: Build
│   └── ...
├── Stage: Synth
│   └── ...
├── Stage: UpdatePipeline
│   └── ...
├── Stage: MyApplicationStage
│   └── Actions
│       ├── MyApplicationSecurityCheck       // Security Diff Action
│       ├── MyApplicationManualApproval      // Manual Approval Action
│       ├── Stack.Prepare
│       └── Stack.Deploy
└── ...
```

<details>
<summary>Example Usage</summary>
You can enable the security check in one of two ways:

1. Enable security check across the entire `CdkStage`

    ```ts
    const pipeline = new CdkPipeline(app, 'Pipeline', {
      // ...source and build information here (see above)
    });
    const stage = pipeline.addApplicationStage(new MyApplication(this, 'Testing'), {
      securityCheck: true,
    });
    // The 'PreProd' application is also run against a security diff because we configured
    // the stage to enable security checks
    stage.addApplication(new MyApplication(this, 'PreProd'));
    ```

2. Enable security check for a single application

    ```ts
    const pipeline = new CdkPipeline(app, 'Pipeline', {
      // ...source and build information here (see above)
    });
    const stage = pipeline.addApplicationStage(new MyApplication(this, 'NoCheck'));
    stage.addApplication(new MyApplication(this, 'RunSecurityDiff'), {
      securityCheck: true,
    });
    ```

</details>

Fixes: aws#12748

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

@aws-cdk/pipelines CDK Pipelines library contribution/core This is a PR that came from AWS. feature/enhancement A new API to make things easier or more intuitive. A catch-all for general feature requests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(pipelines): security-impacting change approval

4 participants