@@ -30,7 +30,7 @@ SNS Topic Policy should not allow any principal to access<br>
3030
3131### Code samples
3232#### Code samples with security vulnerabilities
33- ``` yaml title="Positive test num. 1 - yaml file" hl_lines="50 23"
33+ ``` yaml title="Positive test num. 1 - yaml file" hl_lines="52 23"
3434---
3535- name : Create alarm SNS topic community
3636 community.aws.sns_topic :
@@ -58,7 +58,73 @@ SNS Topic Policy should not allow any principal to access<br>
5858 Statement :
5959 - Action : Publish
6060 Effect : Allow
61- Principal : " *"
61+ Principal :
62+ AWS : " *"
63+
64+ - name : Create alarm SNS topic
65+ sns_topic :
66+ name : " alarms"
67+ state : present
68+ display_name : " alarm SNS topic"
69+ delivery_policy :
70+ http :
71+ defaultHealthyRetryPolicy :
72+ minDelayTarget : 2
73+ maxDelayTarget : 4
74+ numRetries : 3
75+ numMaxDelayRetries : 5
76+ backoffFunction : " <linear|arithmetic|geometric|exponential>"
77+ disableSubscriptionOverrides : True
78+ defaultThrottlePolicy :
79+ maxReceivesPerSecond : 10
80+ subscriptions :
81+ 82+ protocol : " email"
83+ - endpoint : " my_mobile_number"
84+ protocol : " sms"
85+ policy :
86+ Version : ' 2022-05-02'
87+ Statement :
88+ - Effect : Allow
89+ Action : Publish
90+ Principal :
91+ AWS : " *"
92+
93+ ```
94+ ``` yaml title="Positive test num. 2 - yaml file" hl_lines="55 23"
95+ ---
96+ - name : Create alarm SNS topic community
97+ community.aws.sns_topic :
98+ name : " alarms"
99+ state : present
100+ display_name : " alarm SNS topic"
101+ delivery_policy :
102+ http :
103+ defaultHealthyRetryPolicy :
104+ minDelayTarget : 2
105+ maxDelayTarget : 4
106+ numRetries : 3
107+ numMaxDelayRetries : 5
108+ backoffFunction : " <linear|arithmetic|geometric|exponential>"
109+ disableSubscriptionOverrides : True
110+ defaultThrottlePolicy :
111+ maxReceivesPerSecond : 10
112+ subscriptions :
113+ 114+ protocol : " email"
115+ - endpoint : " my_mobile_number"
116+ protocol : " sms"
117+ policy :
118+ Version : ' 2022-05-02'
119+ Statement :
120+ - Effect : Allow
121+ Action : Publish
122+ Principal :
123+ AWS : " *"
124+ Condition :
125+ StringEquals :
126+ 127+
62128- name : Create alarm SNS topic
63129 sns_topic :
64130 name : " alarms"
@@ -85,7 +151,11 @@ SNS Topic Policy should not allow any principal to access<br>
85151 Statement :
86152 - Effect : Allow
87153 Action : Publish
88- Principal : ' *'
154+ Principal :
155+ AWS : " *"
156+ Condition :
157+ StringEquals :
158+ 89159
90160```
91161
@@ -113,7 +183,7 @@ SNS Topic Policy should not allow any principal to access<br>
113183 Statement :
114184 - Effect : Allow
115185 Action : Publish
116- Principal : NotAll
186+ Principal : " arn:aws:iam::123456789012:root "
117187
118188- name : Create alarm SNS topic
119189 sns_topic :
@@ -136,7 +206,148 @@ SNS Topic Policy should not allow any principal to access<br>
136206 Statement :
137207 - Effect : Allow
138208 Action : Publish
139- Principal : NotAll
209+ Principal : " arn:aws:iam::123456789012:root"
210+
211+ ```
212+ ``` yaml title="Negative test num. 2 - yaml file"
213+ - name : Create SNS topic with safe policy
214+ community.aws.sns_topic :
215+ name : secure-topic
216+ display_name : " Secure SNS Topic"
217+ state : present
218+ policy :
219+ Id : secure-topic-policy
220+ Version : " 2012-10-17"
221+ Statement :
222+ - Sid : AllowPublishFromSpecificAccount
223+ Effect : Allow
224+ Resource : " arn:aws:sns:*:*:secure-topic"
225+ Principal : " *"
226+ Action : sns:Publish
227+ Condition :
228+ StringEquals :
229+ aws:SourceAccount : " 123456789012"
230+
231+ - name : Create alarm SNS topic
232+ sns_topic :
233+ name : alarms
234+ state : present
235+ display_name : " alarm SNS topic"
236+ delivery_policy :
237+ http :
238+ defaultHealthyRetryPolicy :
239+ minDelayTarget : 2
240+ maxDelayTarget : 4
241+ numRetries : 3
242+ numMaxDelayRetries : 5
243+ backoffFunction : exponential
244+ disableSubscriptionOverrides : true
245+ defaultThrottlePolicy :
246+ maxReceivesPerSecond : 10
247+ policy :
248+ Version : ' 2022-05-02'
249+ Statement :
250+ - Effect : Allow
251+ Action : Publish
252+ Principal : " *"
253+ Condition :
254+ StringEquals :
255+ aws:SourceOwner : " 123456789012"
256+
257+ ```
258+ ``` yaml title="Negative test num. 3 - yaml file"
259+ - name : Create SNS topic with mixed conditions
260+ community.aws.sns_topic :
261+ name : mixed-topic
262+ display_name : " Mixed SNS Topic"
263+ state : present
264+ policy :
265+ Id : mixed-topic-policy
266+ Version : " 2012-10-17"
267+ Statement :
268+ - Sid : AllowAnyPrincipalWithRestrictions
269+ Effect : Allow
270+ Resource : " arn:aws:sns:*:*:mixed-topic"
271+ Principal : " *"
272+ Action : sns:Publish
273+ Condition :
274+ StringEquals :
275+ aws:ResourceAccount : " 123456789012"
276+
277+ - name : Create alarm SNS topic
278+ sns_topic :
279+ name : alarms
280+ state : present
281+ display_name : " alarm SNS topic"
282+ delivery_policy :
283+ http :
284+ defaultHealthyRetryPolicy :
285+ minDelayTarget : 2
286+ maxDelayTarget : 4
287+ numRetries : 3
288+ numMaxDelayRetries : 5
289+ backoffFunction : exponential
290+ disableSubscriptionOverrides : true
291+ defaultThrottlePolicy :
292+ maxReceivesPerSecond : 10
293+ policy :
294+ Version : ' 2022-05-02'
295+ Statement :
296+ - Effect : Allow
297+ Action : Publish
298+ Principal : " *"
299+ Condition :
300+ StringEquals :
301+ aws:PrincipalAccount : " 123456789012"
302+
303+ ```
304+ <details ><summary >Negative test num. 4 - yaml file</summary >
305+
306+ ``` yaml
307+ - name : Create SNS topic with mixed conditions
308+ community.aws.sns_topic :
309+ name : mixed-topic
310+ display_name : " Mixed SNS Topic"
311+ state : present
312+ policy :
313+ Id : mixed-topic-policy
314+ Version : " 2012-10-17"
315+ Statement :
316+ - Sid : AllowAnyPrincipalWithRestrictions
317+ Effect : Allow
318+ Resource : " arn:aws:sns:*:*:mixed-topic"
319+ Principal : " *"
320+ Action : sns:Publish
321+ Condition :
322+ StringEquals :
323+ aws:VpceAccount : " 123456789012"
324+
325+ - name : Create alarm SNS topic
326+ sns_topic :
327+ name : alarms
328+ state : present
329+ display_name : " alarm SNS topic"
330+ delivery_policy :
331+ http :
332+ defaultHealthyRetryPolicy :
333+ minDelayTarget : 2
334+ maxDelayTarget : 4
335+ numRetries : 3
336+ numMaxDelayRetries : 5
337+ backoffFunction : exponential
338+ disableSubscriptionOverrides : true
339+ defaultThrottlePolicy :
340+ maxReceivesPerSecond : 10
341+ policy :
342+ Version : ' 2022-05-02'
343+ Statement :
344+ - Effect : Allow
345+ Action : Publish
346+ Principal : " *"
347+ Condition :
348+ StringEquals :
349+ aws:VpceAccount : " 123456789012"
140350
141351```
352+ </details >
142353
0 commit comments