Skip to content

Commit

Permalink
feat(HIPAA Security): EMR check (#358)
Browse files Browse the repository at this point in the history
Closes #259 

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
dontirun authored Sep 22, 2021
1 parent 2dc2adb commit ed0ab3b
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 44 deletions.
73 changes: 37 additions & 36 deletions RULES.md

Large diffs are not rendered by default.

29 changes: 22 additions & 7 deletions src/HIPAA-Security/hipaa-security.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import {
hipaaSecurityELBTlsHttpsListenersOnly,
hipaaSecurityELBv2ACMCertificateRequired,
} from './rules/elb';
import { hipaaSecurityEMRKerberosEnabled } from './rules/emr';
import {
hipaaSecurityOpenSearchEncryptedAtRest,
hipaaSecurityOpenSearchInVPCOnly,
Expand Down Expand Up @@ -78,7 +79,7 @@ export class HIPAASecurityChecks extends NagPack {
this.checkElastiCache(node, ignores);
this.checkElasticBeanstalk(node, ignores);
this.checkELB(node, ignores);
// this.checkEMR(node, ignores);
this.checkEMR(node, ignores);
// this.checkIAM(node, ignores);
// this.checkLambda(node, ignores);
this.checkOpenSearch(node, ignores);
Expand Down Expand Up @@ -632,12 +633,26 @@ export class HIPAASecurityChecks extends NagPack {
}
}

// /**
// * Check EMR Resources
// * @param node the IConstruct to evaluate
// * @param ignores list of ignores for the resource
// */
// private checkEMR(node: CfnResource, ignores: any): void {}
/**
* Check EMR Resources
* @param node the IConstruct to evaluate
* @param ignores list of ignores for the resource
*/
private checkEMR(node: CfnResource, ignores: any) {
if (
!this.ignoreRule(ignores, 'HIPAA.Security-EMRKerberosEnabled') &&
!hipaaSecurityEMRKerberosEnabled(node)
) {
const ruleId = 'HIPAA.Security-EMRKerberosEnabled';
const info =
'The EMR cluster does not have Kerberos enabled - (Control IDs: 164.308(a)(3)(i), 164.308(a)(3)(ii)(A), 164.308(a)(3)(ii)(B), 164.308(a)(4)(i), 164.308(a)(4)(ii)(A), 164.308(a)(4)(ii)(B), 164.308(a)(4)(ii)(C), 164.312(a)(1)).';
const explanation =
'The access permissions and authorizations can be managed and incorporated with the principles of least privilege and separation of duties, by enabling Kerberos for Amazon EMR clusters.';
Annotations.of(node).addError(
this.createMessage(ruleId, info, explanation)
);
}
}

// /**
// * Check IAM Resources
Expand Down
20 changes: 20 additions & 0 deletions src/HIPAA-Security/rules/emr/hipaaSecurityEMRKerberosEnabled.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
import { CfnCluster } from '@aws-cdk/aws-emr';
import { IConstruct, Stack } from '@aws-cdk/core';

/**
* EMR clusters have Kerberos enabled - (Control IDs: 164.308(a)(3)(i), 164.308(a)(3)(ii)(A), 164.308(a)(3)(ii)(B), 164.308(a)(4)(i), 164.308(a)(4)(ii)(A), 164.308(a)(4)(ii)(B), 164.308(a)(4)(ii)(C), 164.312(a)(1))
* @param node the CfnResource to check
*/
export default function (node: IConstruct): boolean {
if (node instanceof CfnCluster) {
const kerberosAttributes = Stack.of(node).resolve(node.kerberosAttributes);
if (kerberosAttributes == undefined) {
return false;
}
}
return true;
}
1 change: 1 addition & 0 deletions src/HIPAA-Security/rules/emr/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
export { default as hipaaSecurityEMRKerberosEnabled } from './hipaaSecurityEMRKerberosEnabled';
2 changes: 1 addition & 1 deletion src/NIST-800-53/rules/emr/nist80053EMRKerberosEnabled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { CfnCluster } from '@aws-cdk/aws-emr';
import { IConstruct, Stack } from '@aws-cdk/core';

/**
* EMR clusters have Kerberos enabled - (Control IDs: AC-2(j), AC-3, AC-5c, and AC-6)
* EMR clusters have Kerberos enabled - (Control IDs: AC-2(j), AC-3, AC-5c, AC-6)
* @param node the CfnResource to check
*/
export default function (node: IConstruct): boolean {
Expand Down
50 changes: 50 additions & 0 deletions test/HIPAA-Security/HIPAA-Security-EMR.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
import { SynthUtils } from '@aws-cdk/assert';
import { CfnCluster } from '@aws-cdk/aws-emr';
import { Aspects, Stack } from '@aws-cdk/core';
import { HIPAASecurityChecks } from '../../src';

describe('Amazon EMR', () => {
test('HIPAA.Security-EMRKerberosEnabled: - EMR clusters have Kerberos enabled - (Control IDs: 164.308(a)(3)(i), 164.308(a)(3)(ii)(A), 164.308(a)(3)(ii)(B), 164.308(a)(4)(i), 164.308(a)(4)(ii)(A), 164.308(a)(4)(ii)(B), 164.308(a)(4)(ii)(C), 164.312(a)(1)', () => {
const nonCompliant = new Stack();
Aspects.of(nonCompliant).add(new HIPAASecurityChecks());
new CfnCluster(nonCompliant, 'rEmrCluster', {
instances: {},
jobFlowRole: ' EMR_EC2_DefaultRole',
name: 'foo',
serviceRole: 'bar',
});
const messages = SynthUtils.synthesize(nonCompliant).messages;
expect(messages).toContainEqual(
expect.objectContaining({
entry: expect.objectContaining({
data: expect.stringContaining('HIPAA.Security-EMRKerberosEnabled:'),
}),
})
);

const compliant = new Stack();
Aspects.of(compliant).add(new HIPAASecurityChecks());
new CfnCluster(compliant, 'rEmrCluster', {
instances: {},
jobFlowRole: ' EMR_EC2_DefaultRole',
name: 'foo',
serviceRole: 'bar',
kerberosAttributes: {
kdcAdminPassword: 'baz',
realm: 'qux',
},
});
const messages2 = SynthUtils.synthesize(compliant).messages;
expect(messages2).not.toContainEqual(
expect.objectContaining({
entry: expect.objectContaining({
data: expect.stringContaining('HIPAA.Security-EMRKerberosEnabled:'),
}),
})
);
});
});

0 comments on commit ed0ab3b

Please sign in to comment.