cdk-nag
Version:
Check CDK v2 applications for best practices using a combination on available rule packs.
40 lines • 5.76 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
/*
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
const path_1 = require("path");
const aws_cdk_lib_1 = require("aws-cdk-lib");
const aws_codebuild_1 = require("aws-cdk-lib/aws-codebuild");
const nag_rules_1 = require("../../nag-rules");
/**
* CodeBuild projects do not store AWS credentials as plaintext environment variables
* @param node the CfnResource to check
*/
exports.default = Object.defineProperty((node) => {
if (node instanceof aws_codebuild_1.CfnProject) {
//Check for the presence of OAUTH
const environment = aws_cdk_lib_1.Stack.of(node).resolve(node.environment);
const environmentVars = aws_cdk_lib_1.Stack.of(node).resolve(environment.environmentVariables);
if (environmentVars != undefined) {
//For each envvar, check if its a sensitive credential being stored
for (const envVar of environmentVars) {
const resolvedEnvVar = aws_cdk_lib_1.Stack.of(node).resolve(envVar);
const name = nag_rules_1.NagRules.resolveIfPrimitive(node, resolvedEnvVar.name);
const type = nag_rules_1.NagRules.resolveIfPrimitive(node, resolvedEnvVar.type);
if (name == 'AWS_ACCESS_KEY_ID' || name == 'AWS_SECRET_ACCESS_KEY') {
//is this credential being stored as plaintext?
if (type == undefined || type == 'PLAINTEXT') {
return nag_rules_1.NagRuleCompliance.NON_COMPLIANT;
}
}
}
}
return nag_rules_1.NagRuleCompliance.COMPLIANT;
}
else {
return nag_rules_1.NagRuleCompliance.NOT_APPLICABLE;
}
}, 'name', { value: path_1.parse(__filename).name });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ29kZUJ1aWxkUHJvamVjdEVudlZhckF3c0NyZWQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvcnVsZXMvY29kZWJ1aWxkL0NvZGVCdWlsZFByb2plY3RFbnZWYXJBd3NDcmVkLnRzIl0sIm5hbWVzIjpbXSwib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