@@ -3,10 +3,32 @@ import cuid from 'cuid'
33import { initRuleEngine } from '../../../utils/test'
44
55import 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'
67import Aws_CIS_140_213 from '../rules/aws-cis-1.4.0-2.1.3'
78import Aws_CIS_140_215 from '../rules/aws-cis-1.4.0-2.1.5'
89import 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+
1032export interface QueryawsRdsDbInstance {
1133 id : string
1234 encrypted : boolean
@@ -17,6 +39,7 @@ export interface EncryptionRule {
1739}
1840export 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