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
- Org Allow.
- Deny outside + service carve.
- Service bool.
- Real org id.
- IAM still.
- 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)
- Org policy.
- Allow/deny.
- Presign myth.
- Write myth bust.
Cleanup (billing थांबवा)
- Cleanup.
- Key hygiene.
10. सामान्य errors आणि fixes
प्रत्येक row = खरी चूक. Panic करण्याआधी fix वाचा.
| Error / लक्षण | Fix |
|---|---|
| IAM Allow + Deny | Bucket Deny / BPA. |
| JSON reject | json.tool + file://. |
| Simulator ≠ CLI | Real CLI. |
| Wrong ARN | /* vs bare. |
| Condition typo | Exact spelling. |
| Principal | Resource policy needs it. |
| Account BPA | Check account switches. |
| KMS layer | Key policy + IAM. |
| Org breaks logs | Service carve-out. |
| Referer auth | Real authZ. |
11. Troubleshooting checklist
- Region + endpoint.
- Policy + BPA.
- Lab user.
- Sid binary search.
- CloudTrail.
- KMS test.
- VPCe path.
- 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 को सुरक्षा न समझें।
घरी करून बघा
- Two profiles.
- Myth demo.
- Carve-out list.
थोडक्यात सांगायचं तर
- PrincipalOrgID.
- IAM still.
- Service carve-out.
- No Referer auth.
- Presign reality.
15. Policy save करण्याआधी checklist
- Business rule एका वाक्यात.
- Allow vs Deny-unless; Deny wins.
- ARN shapes.
- Condition keys.
- BPA first.
- Allow+deny plan.
- Cleanup plan.
- json.tool.
16. Policy Simulator walkthrough
Simulator identity/resource typos साठी चांगला; BPA/VPCe/KMS miss होऊ शकतात. नंतर खऱ्या path वरून CLI.
- Simulator → user/role.
- Action + ARN.
- Include bucket policy.
- CLI confirm.
- 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
- Error code + request id.
- Bucket + region.
- BPA.
- Explicit Deny.
- Conditions.
- KMS key policy.
- OAC id.
- VPCe path.
- Simulator + CLI.
- Support last.
20. PR review checklist
- Valid JSON.
- Required fields.
- No open write.
- Tests.
- Cleanup.
सराव Tasks
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.
- Task वाचा आणि ते कोणत्या AWS service बद्दल आहे ते ठरवा.
- aws लिहा, मग service चं नाव, मग operation (action शब्द).
- प्रत्येक आवश्यक flag (--name) व त्यापुढे task मधली value लिहा.
- Flags कोणत्याही क्रमाने चालतात. Check answer दाबा.
सोपं List
का: In-org.
काय करायचं: thanehousing-org list.
- Task वाचा आणि ते कोणत्या AWS service बद्दल आहे ते ठरवा.
- aws लिहा, मग service चं नाव, मग operation (action शब्द).
- प्रत्येक आवश्यक flag (--name) व त्यापुढे task मधली value लिहा.
- Flags कोणत्याही क्रमाने चालतात. Check answer दाबा.
सोपं Outside
का: Fence.
काय करायचं: Outside तर 1.
- Task मधले numbers लिहून घ्या.
- कागदावर step by step काढा.
- Box मध्ये फक्त final उत्तर लिहा.
- Check answer दाबा.
सोपं Presign
का: Secret.
काय करायचं: Presign तर 1.
- Task मधले numbers लिहून घ्या.
- कागदावर step by step काढा.
- Box मध्ये फक्त final उत्तर लिहा.
- Check answer दाबा.
सोपं Head
का: Exists.
काय करायचं: thanehousing-org head.
- Task वाचा आणि ते कोणत्या AWS service बद्दल आहे ते ठरवा.
- aws लिहा, मग service चं नाव, मग operation (action शब्द).
- प्रत्येक आवश्यक flag (--name) व त्यापुढे task मधली value लिहा.
- Flags कोणत्याही क्रमाने चालतात. Check answer दाबा.
सोपं BPA
का: BPA.
काय करायचं: thanehousing-org BPA.
- Task वाचा आणि ते कोणत्या AWS service बद्दल आहे ते ठरवा.
- aws लिहा, मग service चं नाव, मग operation (action शब्द).
- प्रत्येक आवश्यक flag (--name) व त्यापुढे task मधली value लिहा.
- Flags कोणत्याही क्रमाने चालतात. Check answer दाबा.
मध्यम Get
का: Allow.
काय करायचं: get report.
- Task वाचा आणि ते कोणत्या AWS service बद्दल आहे ते ठरवा.
- aws लिहा, मग service चं नाव, मग operation (action शब्द).
- प्रत्येक आवश्यक flag (--name) व त्यापुढे task मधली value लिहा.
- Flags कोणत्याही क्रमाने चालतात. Check answer दाबा.
मध्यम Put
का: Write.
काय करायचं: put report.
- Task वाचा आणि ते कोणत्या AWS service बद्दल आहे ते ठरवा.
- aws लिहा, मग service चं नाव, मग operation (action शब्द).
- प्रत्येक आवश्यक flag (--name) व त्यापुढे task मधली value लिहा.
- Flags कोणत्याही क्रमाने चालतात. Check answer दाबा.
मध्यम HTTPS
का: TLS.
काय करायचं: deny HTTP.
- { "Version": "2012-10-17", "Statement": [ ... ] } ने सुरू करा.
- प्रत्येक statement मध्ये Effect, Action व Resource लिहा.
- Task ला लागेल तेवढंच द्या (least privilege).
- Double quotes व commas नीट वापरा. Check answer दाबा.
मध्यम OrgID JSON
का: Condition.
काय करायचं: o-xxxxxx.
- Task मधल्या top-level keys पासून सुरू करा.
- Child keys 2 spaces ने indent करा (tabs नकोत).
- प्रत्येक property मध्ये task मधली value भरा.
- Check answer दाबा. Keys चा क्रम महत्त्वाचा नाही.
मध्यम Referer
का: Pitfall.
काय करायचं: Weak तर 1.
- Task मधले numbers लिहून घ्या.
- कागदावर step by step काढा.
- Box मध्ये फक्त final उत्तर लिहा.
- Check answer दाबा.
मध्यम Bind
का: Conditions.
काय करायचं: Still apply तर 1.
- Task मधले numbers लिहून घ्या.
- कागदावर step by step काढा.
- Box मध्ये फक्त final उत्तर लिहा.
- Check answer दाबा.
मध्यम Enc
का: SSE.
काय करायचं: thanehousing-org enc.
- Task वाचा आणि ते कोणत्या AWS service बद्दल आहे ते ठरवा.
- aws लिहा, मग service चं नाव, मग operation (action शब्द).
- प्रत्येक आवश्यक flag (--name) व त्यापुढे task मधली value लिहा.
- Flags कोणत्याही क्रमाने चालतात. Check answer दाबा.
अवघड OrgID
का: Org.
काय करायचं: deny outside org.
- { "Version": "2012-10-17", "Statement": [ ... ] } ने सुरू करा.
- प्रत्येक statement मध्ये Effect, Action व Resource लिहा.
- Task ला लागेल तेवढंच द्या (least privilege).
- Double quotes व commas नीट वापरा. Check answer दाबा.
अवघड Referer
का: Weak.
काय करायचं: referer weak.
- Task मधल्या top-level keys पासून सुरू करा.
- Child keys 2 spaces ने indent करा (tabs नकोत).
- प्रत्येक property मध्ये task मधली value भरा.
- Check answer दाबा. Keys चा क्रम महत्त्वाचा नाही.
अवघड Del
का: Cleanup.
काय करायचं: thanehousing-org del.
- Task वाचा आणि ते कोणत्या AWS service बद्दल आहे ते ठरवा.
- aws लिहा, मग service चं नाव, मग operation (action शब्द).
- प्रत्येक आवश्यक flag (--name) व त्यापुढे task मधली value लिहा.
- Flags कोणत्याही क्रमाने चालतात. Check answer दाबा.
उजळणी, मुलाखत आणि तुलना cards
हा lesson काही मिनिटांत revise करा. Cards phone वर save करा किंवा PNG download करा. प्रत्येक card वरचा QR हा lesson उघडतो.








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