feat(core): template validation after synthesis#23951
Merged
mergify[bot] merged 112 commits intomainfrom Mar 27, 2023
Merged
Conversation
aws-cdk-automation
previously requested changes
Feb 1, 2023
Collaborator
aws-cdk-automation
left a comment
There was a problem hiding this comment.
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.
corymhall
reviewed
Feb 14, 2023
packages/@aws-cdk/core/lib/stack-synthesizers/default-synthesizer.ts
Outdated
Show resolved
Hide resolved
…and ValidationViolationResourceAware, respectively
corymhall
reviewed
Feb 21, 2023
Co-authored-by: Eli Polonsky <epolon@amazon.com>
corymhall
reviewed
Mar 27, 2023
corymhall
reviewed
Mar 27, 2023
Co-authored-by: Cory Hall <43035978+corymhall@users.noreply.github.com>
Co-authored-by: Cory Hall <43035978+corymhall@users.noreply.github.com>
Co-authored-by: Cory Hall <43035978+corymhall@users.noreply.github.com>
Co-authored-by: Cory Hall <43035978+corymhall@users.noreply.github.com>
Co-authored-by: Cory Hall <43035978+corymhall@users.noreply.github.com>
iliapolo
approved these changes
Mar 27, 2023
Collaborator
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Contributor
|
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). |
corymhall
added a commit
that referenced
this pull request
Mar 28, 2023
Integrate policy as code tools into CDK synthesis via a plugin mechanism. Immediately after synthesis, the framework invokes all the registered plugins, collect the results and, if there are any violations, show a report to the user.
Application developers register plugins to a `Stage`:
```ts
const app = new App({
validationPlugins: [
new SomePolicyAgentPlugin(),
new AnotherPolicyAgentPugin(),
]
});
```
Plugin authors must implement the `IPolicyValidationPlugin` interface. Hypothetical example of a CloudFormation Guard plugin:
```ts
export class CfnGuardValidator implements IPolicyValidationPlugin {
public readonly name = 'cfn-guard-validator';
constructor() {}
validate(context: IPolicyValidationContext): PolicyValidationPluginReport {
// execute the cfn-guard cli and get the JSON response from the tool
const cliResultJson = executeCfnGuardCli();
// parse the results and return the violations format
// that the framework expects
const violations = parseGuardResults(cliResultJson);
// construct the report and return it to the framework
// this is a vastly over simplified example that is only
// meant to show the structure of the report that is returned
return {
success: false,
violations: [{
ruleName: violations.ruleName,
recommendation: violations.recommendation,
fix: violations.fix,
violatingResources: [{
resourceName: violations.resourceName,
locations: violations.locations,
templatePath: violations.templatePath,
}],
}],
};
}
}
```
Co-authored-by: corymhall <43035978+corymhall@users.noreply.github.com>
corymhall
added a commit
that referenced
this pull request
Mar 28, 2023
Integrate policy as code tools into CDK synthesis via a plugin mechanism. Immediately after synthesis, the framework invokes all the registered plugins, collect the results and, if there are any violations, show a report to the user.
Application developers register plugins to a `Stage`:
```ts
const app = new App({
validationPlugins: [
new SomePolicyAgentPlugin(),
new AnotherPolicyAgentPugin(),
]
});
```
Plugin authors must implement the `IPolicyValidationPlugin` interface. Hypothetical example of a CloudFormation Guard plugin:
```ts
export class CfnGuardValidator implements IPolicyValidationPlugin {
public readonly name = 'cfn-guard-validator';
constructor() {}
validate(context: IPolicyValidationContext): PolicyValidationPluginReport {
// execute the cfn-guard cli and get the JSON response from the tool
const cliResultJson = executeCfnGuardCli();
// parse the results and return the violations format
// that the framework expects
const violations = parseGuardResults(cliResultJson);
// construct the report and return it to the framework
// this is a vastly over simplified example that is only
// meant to show the structure of the report that is returned
return {
success: false,
violations: [{
ruleName: violations.ruleName,
recommendation: violations.recommendation,
fix: violations.fix,
violatingResources: [{
resourceName: violations.resourceName,
locations: violations.locations,
templatePath: violations.templatePath,
}],
}],
};
}
}
```
Co-authored-by: corymhall <43035978+corymhall@users.noreply.github.com>
homakk
pushed a commit
to homakk/aws-cdk
that referenced
this pull request
Mar 28, 2023
Integrate policy as code tools into CDK synthesis via a plugin mechanism. Immediately after synthesis, the framework invokes all the registered plugins, collect the results and, if there are any violations, show a report to the user.
Application developers register plugins to a `Stage`:
```ts
const app = new App({
validationPlugins: [
new SomePolicyAgentPlugin(),
new AnotherPolicyAgentPugin(),
]
});
```
Plugin authors must implement the `IPolicyValidationPlugin` interface. Hypothetical example of a CloudFormation Guard plugin:
```ts
export class CfnGuardValidator implements IPolicyValidationPlugin {
public readonly name = 'cfn-guard-validator';
constructor() {}
validate(context: IPolicyValidationContext): PolicyValidationPluginReport {
// execute the cfn-guard cli and get the JSON response from the tool
const cliResultJson = executeCfnGuardCli();
// parse the results and return the violations format
// that the framework expects
const violations = parseGuardResults(cliResultJson);
// construct the report and return it to the framework
// this is a vastly over simplified example that is only
// meant to show the structure of the report that is returned
return {
success: false,
violations: [{
ruleName: violations.ruleName,
recommendation: violations.recommendation,
fix: violations.fix,
violatingResources: [{
resourceName: violations.resourceName,
locations: violations.locations,
templatePath: violations.templatePath,
}],
}],
};
}
}
```
Co-authored-by: corymhall <43035978+corymhall@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Integrate policy as code tools into CDK synthesis via a plugin mechanism. Immediately after synthesis, the framework invokes all the registered plugins, collect the results and, if there are any violations, show a report to the user.
Application developers register plugins to a
Stage:Plugin authors must implement the
IPolicyValidationPlugininterface. Hypothetical example of a CloudFormation Guard plugin:Co-authored-by: corymhall 43035978+corymhall@users.noreply.github.com