SkillSprout
Chapter 7 · Lesson 4
Advanced
6 min read

Security Auditing: CloudTrail, VPC Flow Logs, Access Analyzer and Inspector

Overview

Auditing answers three questions: who did what (CloudTrail), what traffic flowed (VPC Flow Logs, DNS query logs), and what is exposed or vulnerable (Config, Access Analyzer, Inspector). Mature teams centralise these logs in a protected account, query them at scale and turn anomalies into alerts.

Think of a shopping mall. CloudTrail is the access-control log for staff doors, flow logs are the footfall cameras counting who walked between shops, Access Analyzer checks whether any back door is unlocked to outsiders, and Inspector is the safety inspector scanning each shop for known hazards.

DOP-C02 expects you to configure organisation trails with integrity validation, query them with Athena or CloudTrail Lake, spot common threats (exposed access keys, public buckets, unencrypted data) and automate alerts through EventBridge or metric filters.

Key Concepts

  • CloudTrail records management events by default (90-day Event history); trails deliver management, data and Insights events to S3 and optionally CloudWatch Logs.
  • An organisation trail logs all member accounts to one S3 bucket in a log archive account; enable log file integrity validation (digests signed by AWS).
  • CloudTrail Lake stores events in an immutable, SQL-queryable event data store with retention up to seven years (or longer with extendable retention).
  • VPC Flow Logs capture IP traffic metadata (ACCEPT/REJECT) at VPC, subnet or ENI level to CloudWatch Logs, S3 or Firehose; they do not capture payloads, DHCP or metadata service traffic.
  • IAM Access Analyzer finds resources shared with external principals, unused access, and validates or generates policies from CloudTrail.
  • Amazon Inspector continuously scans EC2, ECR images and Lambda functions for software vulnerabilities and network exposure and posts findings to Security Hub.
  • Amazon Detective builds a behaviour graph from CloudTrail, flow logs and GuardDuty to speed investigations.
  • CloudFormation drift detection and Config identify configuration that deviates from the expected state.

Detailed Notes

Audit data sources

SourceAnswersDeliveryQuery with
CloudTrail management eventsWho changed a resourceS3, CloudWatch Logs, EventBridgeAthena, Logs Insights, CloudTrail Lake
CloudTrail data eventsWho read or wrote S3 objects or invoked LambdaS3, LakeAthena, Lake (extra cost)
CloudTrail InsightsUnusual API call rates or error ratesTrailConsole, EventBridge
VPC Flow LogsWhich addresses and ports talkedCloudWatch Logs, S3, FirehoseLogs Insights, Athena
Route 53 Resolver query logsWhich DNS names were looked upCloudWatch Logs, S3, FirehoseLogs Insights, Athena
ConfigWhat the configuration was over timeS3, SNS, Config aggregatorAdvanced queries, Athena
Access AnalyzerWhat is exposed or unusedFindingsEventBridge, Security Hub

Secure CloudTrail design

  1. Create an organisation trail from the management or delegated account, multi-Region, with management events and selected data events.
  2. Deliver to an S3 bucket in a dedicated log archive account, with SSE-KMS, versioning, Object Lock or MFA delete, and a bucket policy that only allows the CloudTrail service principal to write.
  3. Enable log file validation; verify later with aws cloudtrail validate-logs.
  4. Stream to CloudWatch Logs and create metric filters for high-risk actions (root login, console login without MFA, IAM policy changes, security group changes, CloudTrail stop logging).
bash
aws cloudtrail create-trail --name org-trail --s3-bucket-name org-audit-logs \
  --is-organization-trail --is-multi-region-trail --enable-log-file-validation \
  --kms-key-id alias/audit-logs
aws cloudtrail validate-logs --trail-arn arn:aws:cloudtrail:us-east-1:111122223333:trail/org-trail \
  --start-time 2025-03-01T00:00:00Z

Metric filter for root account usage

text
{ ($.userIdentity.type = "Root") && ($.userIdentity.invokedBy NOT EXISTS) && ($.eventType != "AwsServiceEvent") }

Attach the filter to a metric, alarm at threshold 1 and notify an SNS topic. An EventBridge rule on CloudTrail events achieves a similar result with lower latency and without a Logs group.

Querying with Athena

sql
SELECT useridentity.arn, eventname, sourceipaddress, eventtime
FROM cloudtrail_logs
WHERE eventname IN ('DeleteTrail','StopLogging','PutBucketPolicy')
  AND errorcode IS NULL
ORDER BY eventtime DESC LIMIT 50;

Partition projection on account, Region and date keeps queries fast. For a managed alternative, CloudTrail Lake gives SQL without table setup and supports federation to Athena.

Flow log analysis patterns

  • A custom format that adds pkt-srcaddr, pkt-dstaddr, tcp-flags and flow-direction helps when traffic passes through NAT or Transit Gateway.
  • REJECT records on port 22 from the internet indicate scans; large outbound byte counts to unfamiliar IPs hint at exfiltration. GuardDuty analyses the same data for you.
  • Cost control: send to S3 in Parquet with hourly partitions and use 5- or 10-minute aggregation intervals only when needed.

Vulnerability and exposure management

ServiceScopeAutomation
InspectorEC2 (via SSM agent), ECR images, Lambda code and layersFindings to EventBridge and Security Hub; ECR scan on push
Access AnalyzerS3, IAM roles, KMS, SQS, Lambda and moreExternal access, unused access and policy checks in CI
Config rulesConfiguration complianceAuto-remediation via SSM Automation
Drift detectionCloudFormation-managed resourcesScheduled via EventBridge and Lambda

Common cloud threats the exam names: exposed access keys (found in public repositories), S3 buckets with public access or encryption disabled, insecure HTTP, overly broad security groups and unused IAM users. Each has a detective control (Config, Access Analyzer, GuardDuty) and a preventive control (SCP, Block Public Access, guardrails).

Real World Example

Scenario: after an incident an auditor asks who disabled encryption on a bucket three weeks ago. Because the company runs an organisation trail with data events delivered to an immutable log archive account and loaded into CloudTrail Lake, the security team runs a SQL query and finds the API call, the assumed role session name and the source IP within minutes.

They then add CloudWatch metric filters and EventBridge rules for high-risk API calls, run Access Analyzer unused-access findings monthly, and enable Inspector on all EC2 and ECR resources so vulnerability findings flow to Security Hub.

Architecture Diagram

Centralised audit pipeline
Architecture
AWS Cloud
Member accounts
Org trail
VPC Flow Logs
Log archive account
Locked S3 bucketSSE-KMS
Athena / Lake
AlertsSNS / Lambda

Events and traffic from every account land in a protected archive and drive alerts.

  1. 1Every account sends CloudTrail and flow logs to the organisation destinations.
  2. 2Logs are stored encrypted, versioned and locked in the archive account.
  3. 3Integrity validation proves logs were not modified.
  4. 4Athena or CloudTrail Lake answer investigations with SQL.
  5. 5Metric filters and EventBridge rules alert on risky API calls in near real time.

Best Practices

  • ✓Use an organisation trail with log file validation and a locked-down log archive account.
  • ✓Alert on root usage, console logins without MFA, IAM and network changes via EventBridge or metric filters.
  • ✓Capture S3 and Lambda data events only for sensitive resources to control cost.
  • ✓Turn on VPC Flow Logs (custom format, S3 Parquet) for production VPCs and Resolver query logs.
  • ✓Run Inspector, Access Analyzer and Config continuously and aggregate in Security Hub.

Common Interview Questions

Exam Tips

DOP-C02 focus

  • "Immutable proof logs unchanged" = log file validation plus S3 Object Lock in a separate account.
  • "Alert in near real time on a specific API call" = EventBridge rule on CloudTrail event.
  • "Who is accessing from outside the organisation?" = IAM Access Analyzer external access findings.
  • "Scan ECR images and EC2 for CVEs" = Amazon Inspector.

Chapter quiz

Identity, Network and Data Protection · 10 questions

  1. 1.A platform team wants application developers to create their own IAM roles for Lambda functions, but must ensure these roles can never gain administrator permissions or access to the networking account. What is the most appropriate solution?

  2. 2.A CI/CD system hosted on GitHub must deploy to AWS accounts. Security forbids storing long-lived access keys in the CI secrets. What should be configured?

  3. 3.A company shares an encrypted RDS snapshot with a second account, but the second account cannot copy it. The snapshot is encrypted with a customer managed KMS key. What is missing?

  4. 4.An online retailer faces an HTTP flood from thousands of IP addresses against the login URL, which is served through CloudFront and an ALB. They want automatic throttling with minimal application change. What should they implement?

  5. 5.An organisation with 300 accounts needs to guarantee that every Application Load Balancer has an AWS WAF web ACL with a baseline managed rule group, including accounts created in the future. What should be used?

  6. 6.A security team must ensure all outbound traffic from private subnets in dozens of VPCs is restricted to a list of approved domain names, with logs of blocked attempts. Which architecture is best?

  7. 7.A company stores customer documents in many S3 buckets across accounts. Compliance requires discovery of buckets containing personal data and automatic notification when new sensitive data appears. Which solution meets the requirement with the least operational effort?

  8. 8.A regulation requires that the company, not AWS, has exclusive control of the cryptographic keys, using dedicated hardware inside the customer's VPC. Which service should be used?

  9. 9.During an audit the security team must demonstrate that CloudTrail logs from all accounts have not been modified and cannot be deleted by account administrators. Which combination should be implemented?

  10. 10.A DevOps engineer needs to be alerted within a minute whenever the root user signs in to any account in the organisation. What is the most direct implementation?

0 of 10 answered

Finished this lesson?

0 of 44 lessons done · 0% of the course