Ravindra BagaleCourses & study guides English Track your progress

S3 Bucket Policy Project 10: Org-Only आणि Presigned URL Pitfalls

Org-only: aws:PrincipalOrgID. Pitfalls: service carve-out; Referer/presigned = खरं auth नाही.

या chapter मध्ये तुम्ही काय शिकाल

  • OrgID का
  • Org JSON
  • Member vs external
  • Referer pitfall
  • Interview

1. Story

Tara Krishnan (चेन्नई) व Camille Dupont (Paris) — member accounts only.

2. PrincipalOrgID का?

हे का लागतं?

50 account list fragile. PrincipalOrgID = o-xxxx; IAM Allow अजून लागतं.

  • एक condition
  • IAM still
  • Service carve-out
  • No Referer auth

3. Policy

हे काय आहे?

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "AllowOrgPrincipals",
      "Effect": "Allow",
      "Principal": "*",
      "Action": ["s3:GetObject", "s3:ListBucket"],
      "Resource": [
        "arn:aws:s3:::rb-org-shared-ap-south-1",
        "arn:aws:s3:::rb-org-shared-ap-south-1/*"
      ],
      "Condition": {
        "StringEquals": { "aws:PrincipalOrgID": "o-xxxxxxxxxx" }
      }
    },
    {
      "Sid": "DenyOutsideOrg",
      "Effect": "Deny",
      "Principal": "*",
      "Action": "s3:*",
      "Resource": [
        "arn:aws:s3:::rb-org-shared-ap-south-1",
        "arn:aws:s3:::rb-org-shared-ap-south-1/*"
      ],
      "Condition": {
        "StringNotEquals": { "aws:PrincipalOrgID": "o-xxxxxxxxxx" },
        "Bool": { "aws:PrincipalIsAWSService": "false" }
      }
    }
  ]
}

Line-by-line

  1. Org Allow.
  2. Deny outside + service carve.
  3. Service bool.
  4. Real org id.
  5. IAM still.
  6. External deny.

4. Presigned + Referer pitfall

खरं security नाही

aws:Referer = optional header; attacker काहीही पाठवू शकतो. Presigned = SigV4; Referer bind होत नाही. Hotlink ≠ auth.

# BAD idea (do not rely on this)
# Condition StringLike aws:Referer https://myportal.example.com/*
# A curl -H 'Referer: https://myportal.example.com/' bypasses the "protection".

# Presigned URL — still valid if leaked, until expiry, regardless of Referer
aws s3 presign s3://rb-org-shared-ap-south-1/guide.pdf --expires-in 60
# https://rb-org-shared-ap-south-1.s3.amazonaws.com/guide.pdf?X-Amz-Algorithm=...

5. CLI

कसं करायचं (step by step)

ORG=o-xxxxxxxxxx
aws s3api put-bucket-policy --bucket rb-org-shared-ap-south-1 --policy file://org-only.json

# ALLOW — member account role
aws s3 ls s3://rb-org-shared-ap-south-1/ --profile member
# guide.pdf

# DENY — external account
aws s3 ls s3://rb-org-shared-ap-south-1/ --profile external
# AccessDenied

6. Allow/deny

Allow: member. Deny: external. Referer forge ≠ security.

7. Multi-industry

Landing zones, retail org, hospital, gaming.

8. AccessDenied debugging आणि Policy Simulator

AccessDenied क्रम: BPA → bucket Deny → IAM Allow → KMS → VPCe → ACL. Simulator BPA/VPC/KMS miss करू शकतो — खऱ्या CLI ने test.

# Decode
aws s3api get-bucket-policy --bucket BUCKET --query Policy --output text | python3 -m json.tool
aws s3api get-public-access-block --bucket BUCKET
aws iam simulate-principal-policy --policy-source-arn ARN \
  --action-names s3:GetObject --resource-arns arn:aws:s3:::BUCKET/key.txt
aws cloudtrail lookup-events --lookup-attributes AttributeKey=EventName,AttributeValue=GetObject --max-items 5

9. Lab: org-only + referer

Org block नसेल तर ap-south-1 (Mumbai). आधी budget alert.

कसं करायचं (step by step)

  1. Org policy.
  2. Allow/deny.
  3. Presign myth.
  4. Write myth bust.

Cleanup (billing थांबवा)

  1. Cleanup.
  2. Key hygiene.

10. सामान्य errors आणि fixes

प्रत्येक row = खरी चूक. Panic करण्याआधी fix वाचा.

Error / लक्षणFix
IAM Allow + DenyBucket Deny / BPA.
JSON rejectjson.tool + file://.
Simulator ≠ CLIReal CLI.
Wrong ARN/* vs bare.
Condition typoExact spelling.
PrincipalResource policy needs it.
Account BPACheck account switches.
KMS layerKey policy + IAM.
Org breaks logsService carve-out.
Referer authReal authZ.

11. Troubleshooting checklist

  1. Region + endpoint.
  2. Policy + BPA.
  3. Lab user.
  4. Sid binary search.
  5. CloudTrail.
  6. KMS test.
  7. VPCe path.
  8. Lock cleanup.

12. FAQ

प्र. Bucket = IAM?

नाही — resource vs identity; Deny wins; cross-account दोन्ही.

प्र. ACL 2026?

Owner enforced; logs कधी ACL.

प्र. BPA?

Public ACL/policy blocks.

प्र. AccessDenied fast?

Layer checklist; * नको.

प्र. Org id?

describe-organization.

प्र. * + Org?

Common + Deny.

प्र. Presign+Org?

Signer must pass.

प्र. Referer use?

Weak only.

13. Interview Q&A

प्र. Org lock?

PrincipalOrgID.

प्र. List accounts?

Fragile.

प्र. Services fail?

Carve-out.

प्र. Referer auth?

No.

प्र. Presign+Referer?

Not bound.

प्र. Prove?

Member vs external.

14. Tips — English, मराठी आणि हिंदी

Ravindra Bagale's Tip (EN)

PrincipalOrgID for shared org resources; never confuse it with “Referer security theater”.

Ravindra Bagale's Tip (MR)

Org shared = PrincipalOrgID; Referer security theater नव्हे.

Tip (HI)

Org shared संसाधन = PrincipalOrgID; Referer को सुरक्षा न समझें।

घरी करून बघा

  1. Two profiles.
  2. Myth demo.
  3. Carve-out list.

थोडक्यात सांगायचं तर

  1. PrincipalOrgID.
  2. IAM still.
  3. Service carve-out.
  4. No Referer auth.
  5. Presign reality.

15. Policy save करण्याआधी checklist

  1. Business rule एका वाक्यात.
  2. Allow vs Deny-unless; Deny wins.
  3. ARN shapes.
  4. Condition keys.
  5. BPA first.
  6. Allow+deny plan.
  7. Cleanup plan.
  8. json.tool.

16. Policy Simulator walkthrough

Simulator identity/resource typos साठी चांगला; BPA/VPCe/KMS miss होऊ शकतात. नंतर खऱ्या path वरून CLI.

  1. Simulator → user/role.
  2. Action + ARN.
  3. Include bucket policy.
  4. CLI confirm.
  5. Mismatch → layers.

17. Copy-paste runbook

# 0) Region + names
export AWS_REGION=ap-south-1
export BUCKET=rb-lab-$(date +%s)-ap-south-1

# 1) Create + show BPA
aws s3api create-bucket --bucket $BUCKET --region $AWS_REGION \
  --create-bucket-configuration LocationConstraint=$AWS_REGION
aws s3api get-public-access-block --bucket $BUCKET || true

# 2) Validate + apply policy
python3 -m json.tool policy.json >/dev/null
aws s3api put-bucket-policy --bucket $BUCKET --policy file://policy.json
aws s3api get-bucket-policy --bucket $BUCKET --query Policy --output text | python3 -m json.tool | head

# 3) Allow test + Deny test (fill per project)
# ... project-specific curls / aws s3 cp ...

# 4) Cleanup
aws s3 rm s3://$BUCKET --recursive || true
aws s3api delete-bucket-policy --bucket $BUCKET || true
aws s3api delete-bucket --bucket $BUCKET

18. Industry story bank

वरील प्रत्येक project एक industry story वापरतो. इतर industries मध्ये फक्त bucket/principal/Condition बदला.

  • Healthcare: SSE-KMS + OrgID + MFA.
  • Fintech: IP + HTTPS + OAC.
  • EdTech: OAC only.
  • Logistics: VPCe.
  • Media: Object Lock.
  • Retail: prefix public read.
  • SaaS: prefix homes.
  • Gov: OrgID + MFA + Lock.

19. AccessDenied debugging flowchart

  1. Error code + request id.
  2. Bucket + region.
  3. BPA.
  4. Explicit Deny.
  5. Conditions.
  6. KMS key policy.
  7. OAC id.
  8. VPCe path.
  9. Simulator + CLI.
  10. Support last.

20. PR review checklist

  • Valid JSON.
  • Required fields.
  • No open write.
  • Tests.
  • Cleanup.

सराव Tasks

या scenario बद्दल

Thane Housing Society हा ठाणे मधला रिअल इस्टेट व्यवसाय आहे. Mahesh Patwardhan त्यांचं IT व cloud काम पाहतात. त्यांचे पैसे INR मध्ये मोजले जातात आणि AWS resources ap-south-1 Region मध्ये चालतात. खालच्या tasks मध्ये तुम्ही या lesson मध्ये शिकलेलं वापरून त्यांची खरी कामं करता. सगळी नावं, account IDs, IP addresses व numbers सरावासाठी काल्पनिक आहेत.

0 / 16

सोपं Policy

का: Org.

काय करायचं: thanehousing-org policy.

कसं करायचं:
  1. Task वाचा आणि ते कोणत्या AWS service बद्दल आहे ते ठरवा.
  2. aws लिहा, मग service चं नाव, मग operation (action शब्द).
  3. प्रत्येक आवश्यक flag (--name) व त्यापुढे task मधली value लिहा.
  4. Flags कोणत्याही क्रमाने चालतात. Check answer दाबा.

सोपं List

का: In-org.

काय करायचं: thanehousing-org list.

कसं करायचं:
  1. Task वाचा आणि ते कोणत्या AWS service बद्दल आहे ते ठरवा.
  2. aws लिहा, मग service चं नाव, मग operation (action शब्द).
  3. प्रत्येक आवश्यक flag (--name) व त्यापुढे task मधली value लिहा.
  4. Flags कोणत्याही क्रमाने चालतात. Check answer दाबा.

सोपं Outside

का: Fence.

काय करायचं: Outside तर 1.

कसं करायचं:
  1. Task मधले numbers लिहून घ्या.
  2. कागदावर step by step काढा.
  3. Box मध्ये फक्त final उत्तर लिहा.
  4. Check answer दाबा.

सोपं Presign

का: Secret.

काय करायचं: Presign तर 1.

कसं करायचं:
  1. Task मधले numbers लिहून घ्या.
  2. कागदावर step by step काढा.
  3. Box मध्ये फक्त final उत्तर लिहा.
  4. Check answer दाबा.

सोपं Head

का: Exists.

काय करायचं: thanehousing-org head.

कसं करायचं:
  1. Task वाचा आणि ते कोणत्या AWS service बद्दल आहे ते ठरवा.
  2. aws लिहा, मग service चं नाव, मग operation (action शब्द).
  3. प्रत्येक आवश्यक flag (--name) व त्यापुढे task मधली value लिहा.
  4. Flags कोणत्याही क्रमाने चालतात. Check answer दाबा.

सोपं BPA

का: BPA.

काय करायचं: thanehousing-org BPA.

कसं करायचं:
  1. Task वाचा आणि ते कोणत्या AWS service बद्दल आहे ते ठरवा.
  2. aws लिहा, मग service चं नाव, मग operation (action शब्द).
  3. प्रत्येक आवश्यक flag (--name) व त्यापुढे task मधली value लिहा.
  4. Flags कोणत्याही क्रमाने चालतात. Check answer दाबा.

मध्यम Get

का: Allow.

काय करायचं: get report.

कसं करायचं:
  1. Task वाचा आणि ते कोणत्या AWS service बद्दल आहे ते ठरवा.
  2. aws लिहा, मग service चं नाव, मग operation (action शब्द).
  3. प्रत्येक आवश्यक flag (--name) व त्यापुढे task मधली value लिहा.
  4. Flags कोणत्याही क्रमाने चालतात. Check answer दाबा.

मध्यम Put

का: Write.

काय करायचं: put report.

कसं करायचं:
  1. Task वाचा आणि ते कोणत्या AWS service बद्दल आहे ते ठरवा.
  2. aws लिहा, मग service चं नाव, मग operation (action शब्द).
  3. प्रत्येक आवश्यक flag (--name) व त्यापुढे task मधली value लिहा.
  4. Flags कोणत्याही क्रमाने चालतात. Check answer दाबा.

मध्यम HTTPS

का: TLS.

काय करायचं: deny HTTP.

कसं करायचं:
  1. { "Version": "2012-10-17", "Statement": [ ... ] } ने सुरू करा.
  2. प्रत्येक statement मध्ये Effect, Action व Resource लिहा.
  3. Task ला लागेल तेवढंच द्या (least privilege).
  4. Double quotes व commas नीट वापरा. Check answer दाबा.

मध्यम OrgID JSON

का: Condition.

काय करायचं: o-xxxxxx.

कसं करायचं:
  1. Task मधल्या top-level keys पासून सुरू करा.
  2. Child keys 2 spaces ने indent करा (tabs नकोत).
  3. प्रत्येक property मध्ये task मधली value भरा.
  4. Check answer दाबा. Keys चा क्रम महत्त्वाचा नाही.

मध्यम Referer

का: Pitfall.

काय करायचं: Weak तर 1.

कसं करायचं:
  1. Task मधले numbers लिहून घ्या.
  2. कागदावर step by step काढा.
  3. Box मध्ये फक्त final उत्तर लिहा.
  4. Check answer दाबा.

मध्यम Bind

का: Conditions.

काय करायचं: Still apply तर 1.

कसं करायचं:
  1. Task मधले numbers लिहून घ्या.
  2. कागदावर step by step काढा.
  3. Box मध्ये फक्त final उत्तर लिहा.
  4. Check answer दाबा.

मध्यम Enc

का: SSE.

काय करायचं: thanehousing-org enc.

कसं करायचं:
  1. Task वाचा आणि ते कोणत्या AWS service बद्दल आहे ते ठरवा.
  2. aws लिहा, मग service चं नाव, मग operation (action शब्द).
  3. प्रत्येक आवश्यक flag (--name) व त्यापुढे task मधली value लिहा.
  4. Flags कोणत्याही क्रमाने चालतात. Check answer दाबा.

अवघड OrgID

का: Org.

काय करायचं: deny outside org.

कसं करायचं:
  1. { "Version": "2012-10-17", "Statement": [ ... ] } ने सुरू करा.
  2. प्रत्येक statement मध्ये Effect, Action व Resource लिहा.
  3. Task ला लागेल तेवढंच द्या (least privilege).
  4. Double quotes व commas नीट वापरा. Check answer दाबा.

अवघड Referer

का: Weak.

काय करायचं: referer weak.

कसं करायचं:
  1. Task मधल्या top-level keys पासून सुरू करा.
  2. Child keys 2 spaces ने indent करा (tabs नकोत).
  3. प्रत्येक property मध्ये task मधली value भरा.
  4. Check answer दाबा. Keys चा क्रम महत्त्वाचा नाही.

अवघड Del

का: Cleanup.

काय करायचं: thanehousing-org del.

कसं करायचं:
  1. Task वाचा आणि ते कोणत्या AWS service बद्दल आहे ते ठरवा.
  2. aws लिहा, मग service चं नाव, मग operation (action शब्द).
  3. प्रत्येक आवश्यक flag (--name) व त्यापुढे task मधली value लिहा.
  4. Flags कोणत्याही क्रमाने चालतात. Check answer दाबा.

उजळणी, मुलाखत आणि तुलना cards

हा lesson काही मिनिटांत revise करा. Cards phone वर save करा किंवा PNG download करा. प्रत्येक card वरचा QR हा lesson उघडतो.

उजळणी card: PrincipalOrgID fence. Outside org = deny. Condition PrincipalOrgID. Deny-unless → tests. Org-only research.
उजळणी card: PrincipalOrgID fence · PNG download करा · Card page उघडा
उजळणी card: Presign आणि Referer pitfalls. Presign = temp creds. Conditions bind; Referer weak. Short TTL; HTTPS; real auth. http presign fails TLS Deny.
उजळणी card: Presign आणि Referer pitfalls · PNG download करा · Card page उघडा
तुलना: PrincipalOrgID fence vs Explicit account Allow list. PrincipalOrgID fence: Scales with org. Explicit account Allow list: Precise; brittle list.
तुलना: PrincipalOrgID fence vs Explicit account Allow list · PNG download करा · Card page उघडा
तुलना: Presigned URL vs aws:Referer allowlist. Presigned URL: Temp secret URL. aws:Referer allowlist: Spoofable header.
तुलना: Presigned URL vs aws:Referer allowlist · PNG download करा · Card page उघडा
मुलाखत card: PrincipalOrgID काय?. Org id of caller account. Deny-unless outsiders. External deny.
मुलाखत card: PrincipalOrgID काय? · PNG download करा · Card page उघडा
मुलाखत card: Presigned URL share करण्याचा धोका?. URL = temp access. Short TTL + policy. Leak = download.
मुलाखत card: Presigned URL share करण्याचा धोका? · PNG download करा · Card page उघडा
मुलाखत card: Referer pitfall का?. Spoofable / optional. Not primary auth. Easy spoof.
मुलाखत card: Referer pitfall का? · PNG download करा · Card page उघडा
मुलाखत card: Presign वर conditions लागू?. Yes, still evaluate. Design with fences. http presign fail.
मुलाखत card: Presign वर conditions लागू? · PNG download करा · Card page उघडा

अजून cards: Ravi Sir's Cards.