Advertisement
Javi

AWS: S3 Policy

Oct 18th, 2017 (edited)
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. # Advanced S3 policy
  2.  
  3. ## Enforcing prefix equal to the name of the user:
  4.  
  5. ```json
  6. {
  7. "Version": "2012-10-17",
  8. "Statement": [
  9. {
  10. "Action": ["s3:ListBucket"],
  11. "Effect": "Allow",
  12. "Resource": ["arn:aws:s3:::gatitos"],
  13. "Condition": {"StringLike": {"s3:prefix": ["${aws:username}/*"]}}
  14. },
  15. {
  16. "Action": [
  17. "s3:GetObject",
  18. "s3:PutObject"
  19. ],
  20. "Effect": "Allow",
  21. "Resource": ["arn:aws:s3:::gatitos/${aws:username}/*"]
  22. }
  23. ]
  24. }
  25. ```
  26.  
  27. ## Grating access from another account
  28.  
  29. ```json
  30. {
  31. "Version":"2012-10-17",
  32. "Statement":[
  33. {
  34. "Sid":"AddCannedAcl",
  35. "Effect":"Allow",
  36. "Principal": {"AWS": ["arn:aws:iam::111122223333:root","arn:aws:iam::444455556666:root"]},
  37. "Action":["s3:PutObject","s3:PutObjectAcl"],
  38. "Resource":"arn:aws:s3:::DOC-EXAMPLE-BUCKET/*",
  39. "Condition":{"StringEquals":{"s3:x-amz-acl":["public-read"]}}
  40. }
  41. ]
  42. }
  43. ```
  44.  
  45. ## Granting public read access (dangerous!)
  46.  
  47. ```json
  48. {
  49. "Version":"2012-10-17",
  50. "Statement":[
  51. {
  52. "Sid":"PublicRead",
  53. "Effect":"Allow",
  54. "Principal": "*",
  55. "Action":["s3:GetObject","s3:GetObjectVersion"],
  56. "Resource":["arn:aws:s3:::DOC-EXAMPLE-BUCKET/*"]
  57. }
  58. ]
  59. }
  60. ```
  61.  
  62. ## Granting access from IP
  63.  
  64. ```json
  65. {
  66. "Version": "2012-10-17",
  67. "Id": "S3PolicyId1",
  68. "Statement": [
  69. {
  70. "Sid": "IPAllow",
  71. "Effect": "Deny",
  72. "Principal": "*",
  73. "Action": "s3:*",
  74. "Resource": [
  75. "arn:aws:s3:::DOC-EXAMPLE-BUCKET;",
  76. "arn:aws:s3:::DOC-EXAMPLE-BUCKET/*"
  77. ],
  78. "Condition": {
  79. "NotIpAddress": {"aws:SourceIp": "54.240.143.0/24"}
  80. }
  81. }
  82. ]
  83. }
  84. ```
  85.  
  86. ## Granting access from Cloudfront
  87.  
  88. ```json
  89. {
  90. "Version": "2012-10-17",
  91. "Id": "PolicyForCloudFrontPrivateContent",
  92. "Statement": [
  93. {
  94. "Effect": "Allow",
  95. "Principal": {
  96. "AWS": "arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity EH1HDMB1FH2TC"
  97. },
  98. "Action": "s3:GetObject",
  99. "Resource": "arn:aws:s3:::DOC-EXAMPLE-BUCKET/*"
  100. }
  101. ]
  102. }
  103. ```
  104.  
  105. ## Enforcing MFA
  106.  
  107. ```json
  108. {
  109. "Version": "2012-10-17",
  110. "Id": "123",
  111. "Statement": [
  112. {
  113. "Sid": "",
  114. "Effect": "Deny",
  115. "Principal": "*",
  116. "Action": "s3:*",
  117. "Resource": "arn:aws:s3:::DOC-EXAMPLE-BUCKET/taxdocuments/*",
  118. "Condition": { "Null": { "aws:MultiFactorAuthAge": true }}
  119. }
  120. ]
  121. }
  122. ```
  123.  
  124. ## More examples
  125.  
  126. https://docs.aws.amazon.com/AmazonS3/latest/dev/example-bucket-policies.html
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement