Skip to content

Commit 9949f41

Browse files
authored
Merge pull request #126 from cloudgraphdev/fix/CG-1327-aws-140-212
fix(CG-1327): fix AWS CIS 1.40 2.1.2 rule
2 parents ac8230a + 51a22e1 commit 9949f41

2 files changed

Lines changed: 188 additions & 0 deletions

File tree

src/aws/cis-1.4.0/rules/aws-cis-1.4.0-2.1.2.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,73 @@ export default {
116116
],
117117

118118
severity: 'medium',
119+
gql: `{
120+
queryawsS3 {
121+
id
122+
arn
123+
accountId
124+
__typename
125+
policy {
126+
statement {
127+
effect
128+
action
129+
principal {
130+
key
131+
value
132+
}
133+
condition {
134+
key
135+
operator
136+
value
137+
}
138+
}
139+
}
140+
}
141+
}`,
142+
resource: 'queryawsS3[*]',
143+
conditions: {
144+
path: '@.policy.statement',
145+
array_any: {
146+
and: [
147+
{
148+
path: '[*].effect',
149+
equal: 'Deny',
150+
},
151+
{
152+
path: '[*].principal',
153+
array_any: {
154+
and: [
155+
{
156+
path: '[*].key',
157+
in: ['', 'AWS'],
158+
},
159+
{
160+
path: '[*].value',
161+
contains: '*',
162+
},
163+
],
164+
},
165+
},
166+
{
167+
path: '[*].action',
168+
contains: 's3:*',
169+
},
170+
{
171+
path: '[*].condition',
172+
array_any: {
173+
and: [
174+
{
175+
path: '[*].key',
176+
equal: 'aws:SecureTransport',
177+
},
178+
{
179+
path: '[*].value',
180+
contains: 'false',
181+
},
182+
],
183+
},
184+
},
185+
],
186+
},
187+
},
119188
}

src/aws/cis-1.4.0/tests/aws-cis-1.4.0-2.x.test.ts

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,32 @@ import cuid from 'cuid'
33
import { initRuleEngine } from '../../../utils/test'
44

55
import Aws_CIS_140_211 from '../rules/aws-cis-1.4.0-2.1.1'
6+
import Aws_CIS_140_212 from '../rules/aws-cis-1.4.0-2.1.2'
67
import Aws_CIS_140_213 from '../rules/aws-cis-1.4.0-2.1.3'
78
import Aws_CIS_140_215 from '../rules/aws-cis-1.4.0-2.1.5'
89
import Aws_CIS_140_231 from '../rules/aws-cis-1.4.0-2.3.1'
910

11+
export interface Condition {
12+
key: string
13+
value: string[]
14+
}
15+
16+
export interface Principal {
17+
key: string
18+
value: string[]
19+
}
20+
21+
export interface Statement {
22+
effect: string
23+
action: string[]
24+
principal: Principal[]
25+
condition: Condition[]
26+
}
27+
28+
export interface Policy {
29+
statement: Statement[]
30+
}
31+
1032
export interface QueryawsRdsDbInstance {
1133
id: string
1234
encrypted: boolean
@@ -17,6 +39,7 @@ export interface EncryptionRule {
1739
}
1840
export interface QueryawsS3 {
1941
id: string
42+
policy?: Policy
2043
versioning?: string
2144
mfa?: string
2245
blockPublicAcls?: string
@@ -88,6 +111,102 @@ describe('CIS Amazon Web Services Foundations: 1.4.0', () => {
88111
})
89112
})
90113

114+
describe('AWS CIS 2.1.2 Ensure S3 Bucket Policy allows HTTPS requests', () => {
115+
const getTestRuleFixture = (
116+
effect: string,
117+
action: string,
118+
principal: Principal,
119+
condition: Condition
120+
): CIS2xQueryResponse => {
121+
return {
122+
queryawsS3: [
123+
{
124+
id: cuid(),
125+
policy: {
126+
statement: [
127+
{
128+
effect,
129+
action: [action],
130+
principal: [principal],
131+
condition: [condition],
132+
},
133+
],
134+
},
135+
},
136+
],
137+
}
138+
}
139+
140+
// Act
141+
const testRule = async (
142+
data: CIS2xQueryResponse,
143+
expectedResult: Result
144+
): Promise<void> => {
145+
// Act
146+
const [processedRule] = await rulesEngine.processRule(
147+
Aws_CIS_140_212 as Rule,
148+
{ ...data }
149+
)
150+
151+
// Asserts
152+
expect(processedRule.result).toBe(expectedResult)
153+
}
154+
155+
test('No Security Issue when S3 bucket policies only allow requests that use HTTPS', async () => {
156+
const principal: Principal = {
157+
key: 'AWS',
158+
value: ['*'],
159+
}
160+
const condition: Condition = {
161+
key: 'aws:SecureTransport',
162+
value: ['false'],
163+
}
164+
const data: CIS2xQueryResponse = getTestRuleFixture(
165+
'Deny',
166+
's3:*',
167+
principal,
168+
condition
169+
)
170+
171+
await testRule(data, Result.PASS)
172+
})
173+
174+
test('Security Issue when S3 bucket policy does not have SecureTransport enabled', async () => {
175+
const principal: Principal = {
176+
key: 'AWS',
177+
value: ['arn:aws:iam::111122223333:root'],
178+
}
179+
const condition: Condition = {
180+
key: 'aws:SecureTransport',
181+
value: ['false'],
182+
}
183+
const data: CIS2xQueryResponse = getTestRuleFixture(
184+
'Allow',
185+
's3:*',
186+
principal,
187+
condition
188+
)
189+
190+
await testRule(data, Result.FAIL)
191+
})
192+
193+
test('Security Issue when S3 bucket policy have SecureTransport enabled but grants permission to any public anonymous users', async () => {
194+
const principal: Principal = { key: '', value: ['*'] }
195+
const condition: Condition = {
196+
key: 'aws:SecureTransport',
197+
value: ['true'],
198+
}
199+
const data: CIS2xQueryResponse = getTestRuleFixture(
200+
'Allow',
201+
's3:*',
202+
principal,
203+
condition
204+
)
205+
206+
await testRule(data, Result.FAIL)
207+
})
208+
})
209+
91210
describe('AWS CIS 2.1.3 Ensure MFA Delete is enable on S3 buckets', () => {
92211
const getTestRuleFixture = (
93212
versioning: string,

0 commit comments

Comments
 (0)