Skip to main content
20

VPC basics and IAM least privilege

MediumCloudVPCIAM

Explain cloud networking basics (VPC, subnets, security groups) and how you apply least privilege with IAM.

TL;DR

A VPC is your private network in the cloud, with an IP range split into subnets per availability zone. Public subnets route to an internet gateway; private subnets don't, and reach out through a NAT gateway for things like updates. Put only load balancers in public subnets, and keep apps and databases private. Security groups are stateful firewalls on each resource (allow 5432 only from the app's security group); network ACLs are stateless subnet-level rules. IAM least privilege means every person and workload gets only the permissions it needs, through roles with short-lived credentials rather than long-lived access keys.

Key points

  • Typical layout: ALB in public subnets → app in private subnets → database in isolated private subnets, spread across at least two AZs.
  • Reference security groups by other security groups, not IP ranges, where possible.
  • VPC endpoints (PrivateLink) reach cloud services like S3 without going through NAT or the internet (more secure, and cheaper).
  • Connect VPCs with peering or a transit gateway; plan non-overlapping CIDRs early.
  • IAM: roles for workloads (instance profiles, IRSA or Workload Identity), SSO with MFA for humans, no root account use, specific actions on specific resources instead of *.
  • Use separate accounts per environment (AWS Organizations) as a hard boundary, plus guardrails (SCPs).
  • Audit with CloudTrail, and trim unused permissions with IAM Access Analyzer.

Example

json
{
  "Effect": "Allow",
  "Action": ["s3:GetObject", "s3:PutObject"],
  "Resource": "arn:aws:s3:::acme-uploads/*"
}

Instead of "Action": "s3:*", "Resource": "*".

Common follow-ups

  • Security group vs network ACL? Security groups are stateful (return traffic is automatic), allow-only, and attach to resources. NACLs are stateless, support deny rules, and apply to subnets.
  • How does a private instance download packages? Through a NAT gateway, or better, from internal mirrors or VPC endpoints.

What interviewers look for

Tip

Public vs private subnets with a clear reason, security groups referencing each other, and IAM roles with narrowly scoped, short-lived permissions.

  • Red flag: databases in public subnets, 0.0.0.0/0 on SSH, or *:* policies.

Was this helpful?