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

14. Amazon S3: Buckets, Objects, Policies and Presigned URLs

Chala mitrano, aata aapan EC2 chya baher padtoy! Aattaparyant sagle files – HTML, images, uploads – server chya disk var thevlya. Pan server band padla, disk bharli, kiwa ekach video lakho lokanni baghitla tar kay? Tyasathi AWS ne dila aahe S3 – Simple Storage Service. Aaj aapan bucket, object, Block Public Access, bucket policy, static website hosting, versioning aani presigned URLs – sagla step by step karu. Aani ek goshta aadhich sangto: cyber security madhe "leaky S3 bucket" he shabd tumhi khup vela aikal. Chukicha ek checkbox aani company cha sagla data internet var! Mhanun ha chapter lakshpurvak vacha, dhyan rakho.

What you will learn in this chapter

  • What S3 is: buckets, objects, keys, regions and storage classes
  • Creating a bucket and uploading objects with the console and the AWS CLI
  • Block Public Access, bucket policies and who can read what
  • Hosting a static website on S3
  • Versioning and lifecycle rules to survive mistakes
  • Presigned URLs for temporary, private access
  • Encryption, logging, IAM roles and an S3 security checklist

Concepts in this chapter

  1. 14.1What S3 Is: Buckets, Objects and Keys
  2. 14.2Creating a Bucket and Uploading Objects
  3. 14.3Block Public Access and Bucket Policies
  4. 14.4Hosting a Static Website on S3
  5. 14.5Versioning and Lifecycle Rules
  6. 14.6Presigned URLs: Temporary Private Access
  7. 14.7Encryption, Logging, IAM Roles and the S3 Security Checklist

The chapter recap is at the end of the last concept page.

Chapter 14: Amazon S3 — practice tasks

Open chapter lessons · Full guided lab: s3 private bucket presigned url (not repeated here)

14.1 Find public objects in a bucket policy (paper)

EasyHealthcare

Why: Public S3 buckets leak patient files every year.

What: Read the policy in the data file and say what is public.

Data file: policy.txt

FieldValue
EffectAllow
Principal*
Actions3:GetObject
Resourcearn:aws:s3:::clinic-mumbai/reports/*

About this file: A made-up bucket policy shown as a table. Each row is one field of one statement. Columns: Field = policy key; Value = its setting.

How:

  1. Look for Principal "*".
  2. Check Action and Resource.

Expected output: Anyone can GetObject on reports/*.

Hint

Principal * = whole internet.

Answer / how to check
  1. Fix: remove the statement; use presigned URLs.

14.2 Practise S3 locally with MinIO

MediumIT

Why: You can learn S3 without an AWS bill.

What: Run MinIO in Docker, create a private bucket, upload a file.

How:

  1. docker run -d --rm -p 127.0.0.1:9000:9000 --name minio minio/minio server /data
  2. Use boto3 with endpoint http://127.0.0.1:9000 and keys minioadmin.
  3. Create bucket invoices, upload a.txt.
  4. curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:9000/invoices/a.txt

Expected output: 403 without credentials.

Hint

Buckets are private by default.

Answer / how to check
  1. Status 403 = private.

14.3 Make a presigned URL that expires

MediumRetail

Why: Share one file for a short time, not the whole bucket.

What: Generate a 60-second URL in MinIO.

How:

  1. Call generate_presigned_url('get_object', Params={'Bucket':'invoices','Key':'a.txt'}, ExpiresIn=60).
  2. curl it now, then after 70 s.

Expected output: 200 first, 403 after expiry.

Hint

Clock must be correct.

Answer / how to check
  1. Second curl is 403.

Extended teaching notes

Why this lesson matters

Use this lesson to strengthen systems you own: understand the risk, practise safely in a lab, then write and apply the fix.

Apply the fix across stacks

Same class of bug, same idea in every language.

Java / Spring Boot

Parameterise queries, encode output, CSRF tokens, limited Actuator, dependency scanning.

ASP.NET Core

EF Core / parameterised SQL, Razor encoding, HTTPS, Data Protection.

Node.js / Express

helmet, parameterised SQL, npm audit, avoid eval and shell concat.

Python / Django / Flask / FastAPI

ORM, autoescape, pip-audit, Bandit; never shell=True with user input.

PHP / Laravel

PDO/Eloquent, Blade escaping, composer audit.

Go / Ruby

database/sql placeholders / ActiveRecord; html/template / ERB escaping; govulncheck / Brakeman.

nginx / Apache / Tomcat

Hide versions, TLS, security headers, least-open ports.

MySQL / PostgreSQL / MongoDB / Redis

Private networks, auth on, least-privilege users, no 0.0.0.0/0.

AWS / Azure / GCP

Roles not long-lived keys, private data stores, cloud audit logs on.

Mini case study

Suppose we are on a purple-team exercise for an Indian mid-size company (sample data). Red notes a technique from this lesson against a lab clone. Blue must show the control that stops it, the log that would have fired, and the ticket that hardens production. That is the standard this course trains you for.

Defender's worksheet (do this today)

  1. Write the lesson title, date and the exact lab target you are allowed to use.
  2. List three owned systems (VMs, apps, or cloud accounts) where this lesson applies.
  3. Run one safe check from the lesson on a lab system only. Paste the command and output.
  4. Write a two-sentence fix you would give a teammate.
  5. Name one related public advisory (CERT-In, CISA, NVD, or a vendor bulletin) with its date.

Indian workplace (sample data)

Suppose we are a junior analyst at Infosys, TCS, Wipro or a fintech SOC in Bengaluru/Pune. Turn this lesson into one checklist item with an owner, a due date and a place to store evidence (ticket + screenshot).

Global practice

Compare your notes with OWASP, CIS Benchmarks, NIST CSF/IR guidance or a cloud Well-Architected security question. Write five lines on what overlaps.

Everyday analogy

Explain the risk and the fix to a family member without jargon. If they can repeat the warning, you understand it well enough to teach juniors.

Key terms

  • Control: a safeguard (patch, config, process, detection).
  • Finding: a weakness backed by evidence.
  • Remediation: the fix plus how you verified it.
  • Scope: systems you have written permission to touch.
  • Least privilege: only the access the task needs.
  • Defence in depth: several layers so one failure does not end the story.

Common mistakes

  • Skipping written permission "just for a quick scan".
  • Practising on hostel, office or public targets without authorisation.
  • Collecting tool output without writing the fix.
  • Copying attack steps onto production to "verify". Defenders verify with versions, configs and patches.
  • Publishing screenshots that contain secrets, cookies or internal hostnames.

Recap

  • Evidence, fix, owner, date.
  • Own lab only.
  • Fix > spectacle.