-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(HIPAA Security): IAM Checks (#360)
Closes #193 Closes #195 Closes #196 Closes #198 Closes #200 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Showing
9 changed files
with
657 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
27 changes: 27 additions & 0 deletions
27
src/HIPAA-Security/rules/iam/hipaaSecurityIAMNoInlinePolicy.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
import { CfnRole, CfnUser, CfnGroup, CfnPolicy } from '@aws-cdk/aws-iam'; | ||
import { IConstruct, Stack } from '@aws-cdk/core'; | ||
|
||
/** | ||
* IAM Group, User, and Roles do not contain inline policies - (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 CfnGroup || | ||
node instanceof CfnUser || | ||
node instanceof CfnRole | ||
) { | ||
const inlinePolicies = Stack.of(node).resolve(node.policies); | ||
if (inlinePolicies != undefined) { | ||
return false; | ||
} | ||
} | ||
if (node instanceof CfnPolicy) { | ||
return false; | ||
} | ||
return true; | ||
} |
45 changes: 45 additions & 0 deletions
45
src/HIPAA-Security/rules/iam/hipaaSecurityIAMPolicyNoStatementsWithAdminAccess.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
import { | ||
CfnPolicy, | ||
CfnManagedPolicy, | ||
PolicyDocument, | ||
CfnGroup, | ||
CfnRole, | ||
} from '@aws-cdk/aws-iam'; | ||
import { IConstruct, Stack } from '@aws-cdk/core'; | ||
|
||
/** | ||
* IAM policies do not grant admin access - (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 CfnPolicy || node instanceof CfnManagedPolicy) { | ||
if (checkDocument(node, node.policyDocument)) { | ||
return false; | ||
} | ||
} else if (node instanceof CfnGroup || node instanceof CfnRole) { | ||
if (node.policies != undefined && checkDocument(node, node.policies)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
/** | ||
* Helper function for parsing through the policy document | ||
* @param node the CfnResource to Check | ||
* @param policyDoc the JSON policy document | ||
* @returns boolean | ||
*/ | ||
function checkDocument(node: IConstruct, policyDoc: any): boolean { | ||
const resolvedDoc = Stack.of(node).resolve(policyDoc) as PolicyDocument; | ||
const reg = | ||
/"Action":\[?(.*,)?"\*"(,.*)?\]?,"Effect":"Allow","Resource":\[?(.*,)?"(?:arn(?::.*(?::)?)?)?\*"(,.*)?\]?/gm; | ||
if (JSON.stringify(resolvedDoc).search(reg) != -1) { | ||
return true; | ||
} | ||
return false; | ||
} |
44 changes: 44 additions & 0 deletions
44
src/HIPAA-Security/rules/iam/hipaaSecurityIAMPolicyNoStatementsWithFullAccess.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
import { | ||
CfnPolicy, | ||
CfnManagedPolicy, | ||
PolicyDocument, | ||
CfnGroup, | ||
CfnRole, | ||
} from '@aws-cdk/aws-iam'; | ||
import { IConstruct, Stack } from '@aws-cdk/core'; | ||
|
||
/** | ||
* IAM policies do not grant full access - (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 CfnPolicy || node instanceof CfnManagedPolicy) { | ||
if (checkDocument(node, node.policyDocument)) { | ||
return false; | ||
} | ||
} else if (node instanceof CfnGroup || node instanceof CfnRole) { | ||
if (node.policies != undefined && checkDocument(node, node.policies)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
/** | ||
* Helper function for parsing through the policy document | ||
* @param node the CfnResource to Check | ||
* @param policyDoc the JSON policy document | ||
* @returns boolean | ||
*/ | ||
function checkDocument(node: IConstruct, policyDoc: any): boolean { | ||
const resolvedDoc = Stack.of(node).resolve(policyDoc) as PolicyDocument; | ||
const reg = /"Action":\[?(.*,)?"(?:\w+:)?\*"(,.*)?\]?,"Effect":"Allow"/gm; | ||
if (JSON.stringify(resolvedDoc).search(reg) != -1) { | ||
return true; | ||
} | ||
return false; | ||
} |
20 changes: 20 additions & 0 deletions
20
src/HIPAA-Security/rules/iam/hipaaSecurityIAMUserGroupMembership.ts
This file contains 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
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 { CfnUser } from '@aws-cdk/aws-iam'; | ||
import { IConstruct, Stack } from '@aws-cdk/core'; | ||
|
||
/** | ||
* IAM users are assigned to at least one group - (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 CfnUser) { | ||
const userGroup = Stack.of(node).resolve(node.groups); | ||
if (userGroup == undefined) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} |
25 changes: 25 additions & 0 deletions
25
src/HIPAA-Security/rules/iam/hipaaSecurityIAMUserNoPolicies.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
import { CfnPolicy, CfnManagedPolicy, CfnUser } from '@aws-cdk/aws-iam'; | ||
import { IConstruct, Stack } from '@aws-cdk/core'; | ||
/** | ||
* IAM policies are not attached at the user level - (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 CfnPolicy || node instanceof CfnManagedPolicy) { | ||
const policyUsers = Stack.of(node).resolve(node.users); | ||
if (policyUsers != undefined) { | ||
return false; | ||
} | ||
} else if (node instanceof CfnUser) { | ||
const policies = Stack.of(node).resolve(node.policies); | ||
const managedPolicyArns = Stack.of(node).resolve(node.managedPolicyArns); | ||
if (policies != undefined || managedPolicyArns != undefined) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} |
This file contains 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
Oops, something went wrong.