Labs · Cyber Security
Lab: Security Review of Your Reels App – Find Secrets in Code, Use a Least-Privilege IAM Role and Confirm RDS Is Private
Course: Cyber Security · Chapter 16: Live Project: Building a Reels App with EC2, S3 and RDS
Chapter 16 builds a Reels app on EC2, S3 and RDS; this lab reviews it the way a security team would before go-live.
Chala mitrano! Building the app is half the work. Before go-live, every good company does a security review: are there passwords in the code, does the server have more AWS rights than it needs, is the database private? Today we review our own project with a simple checklist. Swatahchya code la prashna vichara!
चला मित्रांनो! App बनवणं हे अर्धं काम. Go-live आधी प्रत्येक चांगली company security review करते: code मध्ये passwords आहेत का, server कडे गरजेपेक्षा जास्त AWS rights आहेत का, database private आहे का? आज आपण आपल्या project चा साध्या checklist ने review करणार. स्वतःच्या code ला प्रश्न विचारा!
चलो दोस्तों! App बनाना आधा काम है। Go-live से पहले हर अच्छी company security review करती है: code में passwords तो नहीं, server के पास ज़रूरत से ज़्यादा AWS rights तो नहीं, database private है या नहीं? आज हम अपने project का एक simple checklist से review करेंगे। अपने ही code से सवाल पूछो!
Suppose we are…
Suppose our team built a short-video app like Instagram Reels as the Chapter 16 project: the app runs on EC2, videos go to S3 and user data is in RDS. Before the demo to the client, the Tech Mahindra security lead asks three questions: "Any AWS keys or DB passwords in Git? What can the server's IAM role do? Is RDS reachable from the internet?" We answer each one with evidence.
Goal of this lab
By the end you will have:
- Searched your code and its Git history for secrets.
- The app server using an IAM role (temporary credentials given to the server by AWS) that can only read and write one S3 bucket, with no access keys on disk.
- Evidence that RDS is not public and the S3 bucket blocks public access, written as a short review note.
What you need (all free)
- Your own Chapter 16 project folder with Git (any of your own Git projects also works for Part 1).
- Your AWS account, if the project is still deployed. If you deleted it, do Part 1 on the code and read Parts 2–3 as a checklist.
- 45–50 minutes.
Safety and ethics
Review only your own or your team's projects. If you find a real key, do not paste it anywhere: deactivate it in AWS first, then remove it from the code. Removing it from Git alone is not enough, because the old commit still has it.
Part 1: secrets in code and history
-
Open a terminal in your project folder. Search the current code for common secret patterns:
git grep -nE "AKIA[0-9A-Z]{16}|aws_secret_access_key|DB_PASSWORD|password *="What you should see: no lines (good), or the file and line number of each match to review.
-
Search the whole history, because a key deleted last week is still in old commits:
git log -p --all | grep -nE "AKIA[0-9A-Z]{16}|aws_secret_access_key" | head -
Check that secret files are ignored by Git:
cat .gitignore git check-ignore -v .envWhat you should see:
.gitignore:1:.env .env(or similar). If there is no output, add a line.envto.gitignore. -
If you found a real key in step 1 or 2: IAM → Users → the user → Security credentials → Access keys → Actions → Deactivate, then delete it, then fix the code to read secrets from environment variables or AWS Secrets Manager.
Part 2: least-privilege IAM role
-
On the EC2 server, check for stored keys (there should be none when a role is used):
ls -la ~/.aws/ 2>/dev/null; env | grep -i aws_secret aws sts get-caller-identityWhat you should see: no credentials file and no secret in the environment, and an
Arnlikearn:aws:sts::123456789012:assumed-role/reels-app-role/i-0abc....assumed-rolemeans the server uses a role. -
In IAM → Roles →
reels-app-role(or create one: Create role → AWS service → EC2) → Add permissions → Create inline policy → JSON and use a policy that allows only your bucket (replace the name):{ "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Action": ["s3:GetObject", "s3:PutObject"], "Resource": "arn:aws:s3:::reels-videos-yourname/*" }] } -
Remove broad policies such as AmazonS3FullAccess or AdministratorAccess from the role. Attach the role to the server: EC2 → instance → Actions → Security → Modify IAM role.
-
Test from the server:
echo test > t.txt && aws s3 cp t.txt s3://reels-videos-yourname/t.txt aws s3 lsWhat you should see: the upload succeeds, but
aws s3 ls(list all buckets) fails withAccessDenied. The role can do only what the app needs.
Part 3: data stores private
-
In CloudShell, check RDS and S3:
aws rds describe-db-instances --query "DBInstances[].[DBInstanceIdentifier,PubliclyAccessible]" --output table aws s3api get-public-access-block --bucket reels-videos-yournameWhat you should see:
Falsefor your database, and all four Block Public Access settingstrue. -
Write a 6-line review note: secrets in code (yes/no, fixed?), secrets in history,
.envignored, role used and scoped to one bucket, RDS private, S3 public access blocked.
Ravindra Bagale's Tip
Bots scan GitHub for AKIA keys within minutes of a push. If a key was ever pushed, treat it as stolen: deactivate, rotate, then clean the code. Never think "repo is private, so it's fine". Repos become public by mistake too!
Ravindra Bagale's Tip – मराठी
Push केल्यावर काही मिनिटांत bots GitHub वर AKIA keys शोधतात. एखादी key कधीही push झाली असेल, तर ती चोरीला गेली असं समजा: deactivate करा, rotate करा, मग code साफ करा. "Repo private आहे, म्हणून चालेल" असं कधीच समजू नका. Repos पण चुकून public होतात!
Ravindra Bagale's Tip – हिंदी
Push के कुछ ही मिनट में bots GitHub पर AKIA keys ढूँढ लेते हैं। अगर कोई key कभी भी push हुई है, तो उसे चोरी हुई मानो: deactivate करो, rotate करो, फिर code साफ करो। "Repo private है, तो ठीक है" कभी मत सोचो। Repos भी गलती से public हो जाते हैं!
Common mistakes
| Mistake | What happens | Fix |
|---|---|---|
| Deleting the key from the code but not deactivating it | The key in Git history still works | Deactivate and delete the key in IAM first |
Access keys in ~/.aws/credentials on EC2 |
Anyone who gets onto the server gets long-lived keys | Use an IAM role; delete the file |
"Resource": "*" in the role policy |
The server can touch every bucket | Use your bucket's ARN with /* |
.env committed before adding it to .gitignore |
.gitignore does not remove already tracked files |
git rm --cached .env, commit, rotate the secrets |
| RDS public "for the developer" | Database reachable from the internet | Keep it private; use a bastion or SSM |
Self-check checklist
0 of 6 done
Try-at-home challenge
Add a Git pre-commit hook that stops a commit if the staged changes contain AKIA. Test it with a fake line AKIAFAKEFAKEFAKEFAKE.
Check your answer
cat > .git/hooks/pre-commit <<'H'
#!/bin/sh
if git diff --cached | grep -qE "AKIA[0-9A-Z]{16}"; then
echo "Blocked: possible AWS access key in staged changes"; exit 1
fi
H
chmod +x .git/hooks/pre-commit
Add the fake line to a file, git add it and try to commit: you see "Blocked". Remove the line and the commit works. Real teams use tools like gitleaks in the same way.
Clean up to avoid charges
If the Reels app is still deployed and you no longer need it: terminate the EC2 server, delete the RDS database (no final snapshot), empty and delete the S3 bucket, release any Elastic IP, and delete the IAM role.
Samjla ka? No secrets in Git, a role with one bucket, and private data stores, with evidence. Aata pudhe jaauya: Chapter 17 explains why we learnt all this before Kali Linux.