Audit logs and infrastructure as code

Unit 5 of 5 in Cloud fundamentals and shared responsibility.

You will be able to keep an audit trail of account activity and scan infrastructure code for risky settings before it is built.

Lesson

The audit trail

AWS CloudTrail helps with operational and risk auditing, governance and compliance of an AWS account. Actions taken by a user, a role or an AWS service are recorded as events, including actions in the console, the command line and the software development kits and APIs.

The CloudTrail event history is available automatically when you create an account: a viewable, searchable, downloadable and immutable record of the past 90 days of management events in a Region. For a record beyond 90 days AWS points to trails, which capture events and deliver them to an Amazon S3 bucket, with optional delivery to CloudWatch Logs and EventBridge. A trail can cover one account, or many accounts through AWS Organizations.

That is the cloud version of the logging idea from the Defense track: almost everything in the cloud is an API call, so the API log is the record of who did what, when and from where.

Infrastructure as code, checked before it exists

Terraform files describe cloud resources as text you can version and review. Checkov is a static code analysis tool that scans infrastructure as code for misconfigurations that may lead to security or compliance problems, and it includes more than 750 predefined policies. It scans Terraform, CloudFormation, Azure Resource Manager, Kubernetes and other file types, supports custom policies and checks against common standards such as the CIS and AWS Foundations benchmarks.

The point of scanning code instead of the live account is time: a public bucket caught in a text file is fixed with an edit, not an incident. Fixing it in the code also fixes it every time the infrastructure is rebuilt, which a console click does not.

Triage, not panic

A scanner can produce dozens of findings for a small file. The skill is ranking them: which exposes data to the internet today, which removes a safety net and which is housekeeping. The short drill lab practises exactly this, using findings from a real scanner on a small Terraform snippet.

Key points

Sources

Practice in the labs

Turn on an audit trail and scan infrastructure code for risky settings.

Knowledge check

  1. How long does the CloudTrail event history keep management events? Answer: 90 days. AWS says event history is a record of the past 90 days; trails are used for a longer record.
  2. What does Checkov scan? Answer: Infrastructure as code files for misconfigurations. Checkov is a static analysis tool for infrastructure as code such as Terraform and CloudFormation.
  3. Why fix a finding in the Terraform file rather than in the console? Answer: The fix then applies every time the infrastructure is rebuilt. Code is the source of truth, so a fix in the code stays fixed on rebuild, while a console click fixes one resource once.

Back to the syllabus or see all classes.

Related