Ravindra BagaleCourses & study guides मराठी Track your progress

AWS Cloud

S3 Bucket Policy Project 9: Deny Delete, MFA Delete and Object Lock

Immutable evidence store: forensic lead Maya Banerjee in Kolkata must stop casual deletes. Combine a bucket policy Deny on delete without MFA, enable MFA Delete on versioning, and for stronger cases turn on S3 Object Lock (Governance or Compliance). Cleanup must be planned before Compliance mode.

In this chapter

  • Why deny-delete and MFA matter for evidence
  • What MFA condition and Object Lock modes mean
  • How to CLI test delete deny vs MFA allow
  • Governance vs Compliance cleanup reality
  • Interview answers

1. Everyday project story

Delhi cyber cell analyst Rohit Verma and Stockholm SOC manager Erik Lindqvist keep incident disk images in S3. Accidental aws s3 rm must not wipe evidence.

2. Why deny delete + MFA + Lock?

Versioning alone is not enough if someone deletes versions. MFA Delete and Object Lock add deliberate friction and WORM options.

  • Deny s3:DeleteObject* unless aws:MultiFactorAuthPresent
  • Bucket versioning + MFA Delete (root MFA)
  • Object Lock Governance vs Compliance
  • Plan retention before Compliance

3. What is the policy?

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "DenyDeleteWithoutMFA",
      "Effect": "Deny",
      "Principal": "*",
      "Action": [
        "s3:DeleteObject",
        "s3:DeleteObjectVersion",
        "s3:PutLifecycleConfiguration"
      ],
      "Resource": [
        "arn:aws:s3:::rb-evidence-ap-south-1",
        "arn:aws:s3:::rb-evidence-ap-south-1/*"
      ],
      "Condition": {
        "BoolIfExists": { "aws:MultiFactorAuthPresent": "false" }
      }
    }
  ]
}

Line-by-line

  1. Deny DeleteObject and DeleteObjectVersion without MFA.
  2. Also Deny PutLifecycleConfiguration — lifecycle can mass-expire.
  3. BoolIfExists MultiFactorAuthPresent false — no MFA → Deny.
  4. Does not replace Object Lock legal holds.
  5. Root enables MFA Delete on versioning.
  6. Compliance mode retention cannot be shortened by anyone.

4. CLI with output

# This lab enables Object Lock at creation. You can also enable it on an existing general purpose bucket.
# After enabling Object Lock, you cannot disable it or suspend versioning for that bucket.
aws s3api create-bucket --bucket rb-evidence-ap-south-1 --region ap-south-1 \
  --create-bucket-configuration LocationConstraint=ap-south-1 \
  --object-lock-enabled-for-bucket

aws s3api put-bucket-policy --bucket rb-evidence-ap-south-1 --policy file://deny-delete.json

# MFA Delete (example — requires root serial/token; lab carefully)
# aws s3api put-bucket-versioning --bucket rb-evidence-ap-south-1 \
#   --versioning-configuration Status=Enabled,MFADelete=Enabled \
#   --mfa "arn:aws:iam::111122223333:mfa/root-account-mfa-device PASSCODE"

5. Test allow and deny

# DENY — normal session delete
aws s3 rm s3://rb-evidence-ap-south-1/disk.img
# AccessDenied

# ALLOW — session with MFA (STS get-session-token with MFA, then delete)
aws sts get-session-token --serial-number arn:aws:iam::111122223333:mfa/user --token-code 123456
# export temp keys, then:
aws s3 rm s3://rb-evidence-ap-south-1/disk.img
# A successful unversioned delete request may place a delete marker.
# A protected version can still exist underneath it. Inspect object versions before claiming it was removed.

6. Object Lock modes

Decide whether you need recovery, confirmation or retention

Versioning keeps multiple versions. A normal delete can hide a key behind a marker while old versions remain. MFA Delete adds a second-factor check for certain permanent version operations. Object Lock retention protects a specified version for a time, depending on its mode. These solve different parts of the evidence problem.

Sketch a protected version A under a delete marker. The default key can appear missing while A remains protected. Read the exact version state before assuming the evidence was erased. Compliance retention can prevent removal until its date, so use a paper example or the approved governance practice only when learning on disposable data.

ModeWho can overrideUse
GovernanceUsers with special bypass permissionOps flexibility
ComplianceNobody during retention — not even rootRegulated evidence
Legal holdUntil hold removedCase freeze

7. Multi-industry

Forensics (Kolkata — Maya Banerjee), cyber cell (Delhi — Rohit Verma), SOC (Stockholm — Erik Lindqvist), pharma batch records (Vadodara — Dr. Helly Shah).

8. AccessDenied debugging and Policy Simulator

When S3 returns AccessDenied, check in order: (1) Block Public Access, (2) matching bucket policy Deny, (3) missing IAM Allow, (4) KMS key policy, (5) VPC endpoint policy, (6) legacy ACL. IAM Policy Simulator can miss BPA/VPC/KMS — always re-test with real CLI from the real network path.

# 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: deny delete without MFA

Run a reversible delete-marker drill before trying stronger controls

In a fresh versioned lab bucket without permanent retention, upload two safe versions of the same test file. Delete the key without a version ID and use the console’s version view. Expect to see both data versions and a current delete marker. With the approved cleanup identity, remove only the marker and verify that the newest data version can be read again.

If the object remains hidden, check which version is now current. Confirm retention and legal holds before any permanent version removal. Clean up your disposable bucket only after verifying its versions and markers. Keep Compliance mode out of this reversible drill.

Do this in ap-south-1 (Mumbai) unless your org forbids it. Set a budget alert first.

  1. Create Lock-enabled lab bucket (or versioning-only if Lock blocked).
  2. Apply DenyDeleteWithoutMFA; upload a file.
  3. aws s3 rm without MFA → AccessDenied.
  4. Optional: MFA session delete OR Governance retain — document result.

Cleanup (stop billing)

  1. Only delete when retention/hold allows; empty bucket; delete policy/bucket.
  2. Never leave Compliance locks you cannot afford in a personal lab.

10. Common errors and fixes

Each row is a real mistake students and juniors hit. Read the fix before you panic.

Error / symptomFix
AccessDenied but IAM Allow looks fineFind explicit Deny in bucket policy or BPA blocking public.
Policy JSON rejected on putValidate with python3 -m json.tool; no smart quotes; use file://.
Policy Simulator Allow, CLI DenySimulator skips some layers; retest with real CLI/role/network.
Wrong Resource ARN shapeGetObject needs arn:...:bucket/* ; ListBucket needs bare bucket ARN.
Condition key typo or wrong caseKeys like aws:SourceIp are case-sensitive.
Missing Principal on bucket policyResource-based policies require Principal; identity policies must omit it.
Account-level BPA overrides bucketAccount Block Public Access can still block public grants.
Encrypted object / KMS forgottenSSE-KMS needs key policy + kms:Decrypt/GenerateDataKey.
Cannot delete anything everCompliance retention still active — wait or use different lab bucket.
MFA Delete enable failsMust use root credentials + MFA device.

11. Troubleshooting checklist

  1. Confirm region and endpoint hostname for the bucket.
  2. Print get-bucket-policy and get-public-access-block.
  3. Reproduce with a least-privilege lab IAM user.
  4. Binary-search Denies by commenting one Sid at a time in lab.
  5. Read CloudTrail errorCode and additionalEventData.
  6. If KMS involved, test key permissions separately.
  7. From VPC path: route to gateway prefix list + endpoint policy.
  8. Cleanup versioning/Object Lock labs carefully.

12. FAQ

Q. Is a bucket policy the same as an IAM policy?

No. Bucket policy is resource-based on the bucket; IAM is identity-based. For same-account, either can Allow; explicit Deny wins; cross-account needs both.

Q. Do I still need ACLs in 2026?

Prefer Bucket owner enforced (ACLs off) + bucket policy. Some log deliveries still need canned ACL on Put.

Q. What is Block Public Access?

Switches that block public ACLs/policies at account or bucket. Disable only the minimum for a deliberate public design.

Q. How do you debug AccessDenied fast?

BPA → bucket policy → IAM → KMS → VPCe → CloudTrail. Never “fix” with Action *.

Q. MFA Delete vs policy MFA condition?

MFA Delete is a versioning feature (root); policy condition applies to API calls with MFA context.

Q. Object Lock after create?

Must enable at bucket creation.

Q. Lifecycle bypass?

We Deny PutLifecycleConfiguration in the sample.

Q. Governance bypass permission?

s3:BypassGovernanceRetention — grant rarely.

13. Interview Q&A

Q. Stop casual deletes how?

Deny delete without MFA; consider MFA Delete + Object Lock.

Q. Governance vs Compliance?

Governance bypassable with permission; Compliance not during retain.

Q. Why Deny lifecycle changes?

Lifecycle can expire all versions quietly.

Q. Prove deny?

rm without MFA → AccessDenied.

Q. Root and Compliance?

Root also cannot shorten Compliance retention.

Q. When enable Object Lock?

At bucket creation — plan first.

14. Tips in English, Marathi and Hindi

Ravindra Bagale's Tip (EN)

Never enable Compliance mode on a personal credit-card lab without a short retention and a calendar reminder.

Ravindra Bagale's Tip (MR)

Personal lab वर Compliance बिना short retention व reminder नको.

Tip (HI)

Personal lab में Compliance बिना छोटी retention और reminder न लगाएं।

Try at home

  1. Deny delete without MFA; capture AccessDenied.
  2. Write 5 lines comparing Governance vs Compliance.
  3. List who in your org may bypass Governance.

In short

  1. Deny delete unless MFA present.
  2. MFA Delete is a versioning feature.
  3. Object Lock: Governance vs Compliance.
  4. Enable Lock at create time.
  5. Plan cleanup before Compliance.

15. Policy design checklist before you save

  1. Write the business rule in one sentence (who can do what from where).
  2. Choose Allow vs Deny-unless consciously; remember explicit Deny wins.
  3. List every Resource ARN shape you need (bucket vs bucket/*).
  4. Name every Condition key exactly (case-sensitive).
  5. Decide BPA settings before put-bucket-policy.
  6. Plan the allow test and the deny test with expected HTTP/CLI codes.
  7. Plan cleanup (versioning, Object Lock, KMS schedules).
  8. Paste JSON through python3 -m json.tool before apply.

16. Policy Simulator walkthrough

IAM Policy Simulator is great for identity policies and a first pass on resource policies, but it can miss Block Public Access, VPC endpoint policies, and some KMS denials. Use it to catch typos, then always re-test with AWS CLI from the real network path (office IP, VPC, or CloudFront).

  1. Open IAM → Policy simulator → pick the user/role.
  2. Add action s3:GetObject / PutObject and the object ARN.
  3. If you use resource policies, include the bucket policy text where the tool allows.
  4. Note Allow/Deny; then run the matching CLI from the real path.
  5. If Simulator Allow but CLI Deny, check BPA, VPCe, KMS, and explicit Denies next.

17. Copy-paste runbook (print this)

# 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 (reuse the pattern)

Each project above uses one industry story. Use the same policy pattern in these other industries without rewriting the JSON from scratch — only change the bucket name, principal, and Condition values.

  • Healthcare (Priya Nair, Apollo-style clinic): patient PDFs — prefer SSE-KMS + OrgID + MFA delete.
  • Fintech (Arjun Mehta, UPI wallet): statements — office IP + SecureTransport + CloudFront OAC for the customer portal.
  • EdTech (Sofia Alvarez, online course): course videos — CloudFront OAC only; never public ACLs.
  • Logistics (Kenji Watanabe, fleet app): GPS dumps — VPC endpoint only from the private subnet runners.
  • Media (Fatima Khan, newsroom): raw footage — Object Lock COMPLIANCE + deny delete.
  • Retail (Lucas Meyer, D2C brand): product images — public read for /images/* only; deny everything else.
  • SaaS (Ananya Iyer, B2B CRM): tenant exports — ${aws:username} or ${aws:PrincipalTag/tenant} prefixes.
  • Government (Rahul Deshmukh, state portal): RTI archives — OrgID + MFA + Object Lock.

19. AccessDenied debugging flowchart

  1. Read the error code and the request ID. Save both.
  2. Confirm you are calling the right bucket and region.
  3. Check Block Public Access if the principal is * or a service that looks public.
  4. Decode the policy: is there an explicit Deny that matches? Deny wins.
  5. Check Condition keys: SecureTransport, SourceVpce, SourceIp, PrincipalOrgID, encryption headers.
  6. For KMS: does the key policy allow the caller? Bucket policy alone is not enough.
  7. For CloudFront: is OAC present and the distribution id matching?
  8. For VPC: are you really going through the endpoint (no public IP leak)?
  9. Simulate in IAM Policy Simulator, then re-test with CLI from the real path.
  10. Only then open a support case with the request id and a redacted policy.

20. What good looks like in a PR review

  • Policy JSON validates and is indented.
  • Every Statement has Sid, Effect, Action, Resource.
  • No Principal:* with write actions unless BPA and a Deny fence exist.
  • Allow test and Deny test are documented with expected output.
  • Cleanup steps will not strand Object Lock or KMS keys.

Worked example: the file disappeared but the locked version is still there

Imagine a cover sheet that says “withdrawn” on top of a document in a records cupboard. The original stays underneath. The same distinction matters on a versioned bucket.

  1. In a disposable lab, write down one test object's version ID and whether it has retention or a legal hold.
  2. Read the result of an ordinary delete and then inspect the version list. A permitted ordinary delete can place a current delete marker. The object can disappear from ordinary reads while the earlier version and its retention remain.
  3. Review what cleanup will require before selecting a retention mode. Use a short, appropriate lab retention in a disposable bucket. A compliance-retained version cannot be permanently deleted by the account root user before expiry.
Interview question: are versioning, MFA Delete and Object Lock interchangeable?

No. Versioning keeps distinct revisions, MFA Delete adds MFA requirements to specific versioning and permanent-delete operations, and Object Lock applies retention or legal hold to object versions. Check which behavior the task actually needs.

Reference 1 · Reference 2 · Reference 3

Practise this chapter

Interview questions and answers

How would you prove a data version is still protected if its public key appears missing?

Inspect the version list, the current entry and the older version’s retention or hold. Check approved access by version ID. A missing unversioned GET may simply be the delete marker.

How do versioning, MFA Delete and Object Lock answer different requirements?

Versioning preserves history that can be restored. MFA Delete adds verification for sensitive version operations. Object Lock sets retention or a hold on versions. Pick each according to the data’s recovery and evidence requirements.

Check your understanding

Choose an answer, then compare your reasoning with the explanation.

0 of 3 answered correctly
1. A versioned bucket has a current delete marker and an older retained data version. What does this mean?

Answer and explanation

C. The key can look missing while the data version remains stored

Ordinary access follows the current entry. Older versions remain independently addressable if retained.

2. Which distinction matters before using Compliance retention in a practice bucket?

Answer and explanation

A. Protected versions cannot be removed until their retention ends, even by root

Compliance mode is designed to hold a protected version through its retention period. Use an approved disposable scenario or paper exercise.

3. Which action is reversible in the versioning lab when the old data still exists?

Answer and explanation

A. Remove the exact current delete marker

Removing the marker can reveal the previous version. Removing the data version is different.

Practice Tasks

Practice checks run in your browser. They check the answer for this exercise; they do not create resources or connect to your AWS account.

About this scenario

Singapore Freight is a logistics business in Singapore. Wei Ling Tan looks after its IT and cloud work. They count money in SGD and run their AWS resources in the ap-southeast-1 Region. In the tasks below you do real jobs for them using what this lesson teaches. All names, account IDs, IP addresses and numbers are made up for practice.

0 / 16

Easy Get lock policy

Deny delete.

Get bucket policy sgfreight-lock.

  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Easy Get versioning lock bucket

Required.

Get bucket versioning sgfreight-lock.

  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Easy Apply the lesson: scenario 3

A protected object version is in COMPLIANCE mode and its retention date has not passed. Can the account root user shorten that retention? Answer yes or no.

  1. Read the situation and identify what you need to decide.
  2. Work through the relevant concept or calculation.
  3. Enter only the requested term or number.
  4. Check your answer, then read the explanation.

Easy Apply the lesson: scenario 4

Which S3 bucket feature must be enabled for Object Lock: versioning or static website hosting?

  1. Read the situation and identify what you need to decide.
  2. Work through the relevant concept or calculation.
  3. Enter only the requested term or number.
  4. Check your answer, then read the explanation.

Easy List lock bucket

Inventory.

List objects sgfreight-lock.

  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Easy Head lock bucket

Exists.

Head bucket sgfreight-lock.

  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Easy Get BPA lock

BPA.

Get public access block sgfreight-lock.

  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Medium Get Object Lock config

WORM.

Get object lock configuration sgfreight-lock.

  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Medium Put retained object

Write.

Put object evidence.pdf into sgfreight-lock from ./evidence.pdf.

  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Medium Write a conditional MFA allow

Privileged.

In the answer box, write a bucket policy granting the example AWS account 116201995216 only s3:DeleteObjectVersion on sgfreight-lock objects, with the Bool condition aws:MultiFactorAuthPresent = true.

  1. Start with { "Version": "2012-10-17", "Statement": [ ... ] }.
  2. In each statement write Effect, Action and Resource.
  3. Give only what the task needs (least privilege).
  4. Use double quotes and commas correctly. Click Check answer.

Medium Object Lock mode JSON

COMPLIANCE.

JSON ObjectLockEnabled Enabled Mode COMPLIANCE.

  1. Start from the top-level keys the task names.
  2. Indent child keys with 2 spaces (no tabs).
  3. Fill in each property with the value from the task.
  4. Click Check answer. Key order does not matter.

Medium Apply the lesson: scenario 12

Can Object Lock be enabled on a supported existing general purpose bucket, after meeting its prerequisites? Answer yes or no.

  1. Read the situation and identify what you need to decide.
  2. Work through the relevant concept or calculation.
  3. Enter only the requested term or number.
  4. Check your answer, then read the explanation.

Medium Apply the lesson: scenario 13

An object's retention date has passed but an active legal hold remains. Can the protected version be deleted before the hold is removed? Answer yes or no.

  1. Read the situation and identify what you need to decide.
  2. Work through the relevant concept or calculation.
  3. Enter only the requested term or number.
  4. Check your answer, then read the explanation.

Hard Deny DeleteObject

Protect.

Deny s3:DeleteObject for Principal * on sgfreight-lock objects.

  1. Start with { "Version": "2012-10-17", "Statement": [ ... ] }.
  2. In each statement write Effect, Action and Resource.
  3. Give only what the task needs (least privilege).
  4. Use double quotes and commas correctly. Click Check answer.

Hard Match absent or false MFA context

An MFA context key can be absent on some request paths.

For a separate explicit Deny on the lab resource, write only the JSON Condition value. Choose the Boolean operator that matches a false or missing aws:MultiFactorAuthPresent key, with false as the comparison value. Do not include a full policy.

  1. Start from the top-level keys the task names.
  2. Indent child keys with 2 spaces (no tabs).
  3. Fill in each property with the value from the task.
  4. Click Check answer. Key order does not matter.

Hard Delete lock policy

Cleanup.

Delete bucket policy sgfreight-lock.

  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Revision, interview and comparison cards

Revise this lesson in a few minutes. Save the cards on your phone or download them as PNG files. The QR code on each card opens this lesson.

Revision card: Object Lock and WORM. Evidence and invoices must not vanish after a bad script. Enable Object Lock at create; COMPLIANCE/GOVERNANCE retention; Deny DeleteObject in policy; MFA Delete on versioning. Create with lock → put object with retain → delete fails → document legal hold. Priya Nair compliance bucket uses COMPLIANCE 30-day lab retention.
Revision card: Object Lock and WORM · Download PNG · Open card page
Revision card: MFA Delete protection. Version deletes and versioning state changes need an MFA code when MFA Delete is on. aws:MultiFactorAuthPresent for privileged statements; keep day-to-day Deny delete. Delete without MFA → deny; with MFA session → allowed if policy says so. Sofia Alvarez cannot purge versions until she MFA-authenticates.
Revision card: MFA Delete protection · Download PNG · Open card page
Comparison: COMPLIANCE mode vs GOVERNANCE mode. COMPLIANCE mode: Cannot shorten/remove until expiry — even root. GOVERNANCE mode: Privileged users can override with special perms.
Comparison: COMPLIANCE mode vs GOVERNANCE mode · Download PNG · Open card page
Comparison: MFA Delete vs Object Lock retention. MFA Delete: Protects versioning changes and permanent version deletes. Object Lock retention: Time-bound or hold-based undeletable objects.
Comparison: MFA Delete vs Object Lock retention · Download PNG · Open card page
Interview card: COMPLIANCE vs GOVERNANCE?. COMPLIANCE cannot be shortened/removed by root until expiry; GOVERNANCE can with special perms. Pick based on legal requirement. Delete before retain end → fail in COMPLIANCE.
Interview card: COMPLIANCE vs GOVERNANCE? · Download PNG · Open card page
Interview card: What does MFA Delete protect?. Changing versioning state and permanently deleting versions requires MFA. Different from Object Lock but complementary. delete-object without MFA denied when configured.
Interview card: What does MFA Delete protect? · Download PNG · Open card page
Interview card: When enable Object Lock?. Primarily at bucket creation; you cannot casually turn it on later the same way. Plan before create in labs. CreateBucket with ObjectLockEnabledForBucket.
Interview card: When enable Object Lock? · Download PNG · Open card page
Interview card: What is a legal hold?. Independent switch that prevents deletion until removed, separate from retain-until date. Used for investigations. Hold on evidence.pdf blocks delete.
Interview card: What is a legal hold? · Download PNG · Open card page

More cards: Ravi Sir's Cards.