2022-09-30 15:16:31 +02:00
|
|
|
include::../description.adoc[]
|
|
|
|
|
|
|
|
include::../ask-yourself.adoc[]
|
|
|
|
|
|
|
|
include::../recommended.adoc[]
|
|
|
|
|
|
|
|
== Sensitive Code Example
|
|
|
|
|
|
|
|
This policy allows all users, including anonymous ones, to access an S3 bucket:
|
|
|
|
|
|
|
|
[source,python]
|
|
|
|
----
|
|
|
|
from aws_cdk.aws_iam import PolicyStatement, AnyPrincipal, Effect
|
|
|
|
from aws_cdk.aws_s3 import Bucket
|
|
|
|
|
|
|
|
bucket = Bucket(self, "ExampleBucket")
|
|
|
|
|
|
|
|
bucket.add_to_resource_policy(PolicyStatement(
|
|
|
|
effect=Effect.ALLOW,
|
|
|
|
actions=["s3:*"],
|
|
|
|
resources=[bucket.arn_for_objects("*")],
|
2022-10-11 10:28:07 +02:00
|
|
|
principals=[AnyPrincipal()] # Sensitive
|
2022-09-30 15:16:31 +02:00
|
|
|
))
|
|
|
|
----
|
|
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
|
|
|
|
This policy allows only the authorized users:
|
|
|
|
|
|
|
|
[source,python]
|
|
|
|
----
|
|
|
|
from aws_cdk.aws_iam import PolicyStatement, AccountRootPrincipal, Effect
|
|
|
|
from aws_cdk.aws_s3 import Bucket
|
|
|
|
|
|
|
|
bucket = Bucket(self, "ExampleBucket")
|
|
|
|
|
|
|
|
bucket.add_to_resource_policy(PolicyStatement(
|
|
|
|
effect=Effect.ALLOW,
|
|
|
|
actions=["s3:*"],
|
|
|
|
resources=[bucket.arn_for_objects("*")],
|
|
|
|
principals=[AccountRootPrincipal()]
|
|
|
|
))
|
|
|
|
----
|
|
|
|
|
|
|
|
include::../see.adoc[]
|
2023-06-22 10:38:01 +02:00
|
|
|
|
2022-09-30 15:16:31 +02:00
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
|
|
|
|
'''
|
|
|
|
== Implementation Specification
|
|
|
|
(visible only on this page)
|
|
|
|
|
|
|
|
include::../message.adoc[]
|
|
|
|
|
2022-10-11 10:28:07 +02:00
|
|
|
include::../highlighting.adoc[]
|
2022-09-30 15:16:31 +02:00
|
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|