Free — no signup required

Golden Images and Hardening

3 min read

The "Master Recipe"

A Golden Image (also called a "base image," "baked image," or "machine image") is a pre-configured, pre-approved OS image that your organization uses as the starting point for all server deployments. Rather than launching a raw Ubuntu image and waiting for it to configure itself at boot time, you launch your Golden Image and it is immediately ready — all software installed, all security settings applied, all agents running.

The contrast with the alternative is stark. The traditional approach uses User Data scripts (AWS) or startup scripts (GCP) that run at boot time to install software. This means every server spends 5–15 minutes configuring itself on first boot, and if the package repository is unavailable or a script has a bug, your server never becomes healthy. With a Golden Image, boot time is the same as a raw OS — typically under 60 seconds — because there is nothing to install.

Security Hardening with CIS Benchmarks

Golden Images are the ideal place to apply security hardening — the process of reducing a system's attack surface by disabling unnecessary features and enforcing security policies. The most widely used standard is the CIS Benchmark (published by the Center for Internet Security), which provides specific, prescriptive configuration recommendations for every major OS.

A CIS-hardened Golden Image built with Packer might include provisioner steps that:

  • Disable unused network services (telnet, rsh, rlogin).
  • Configure sshd to disallow root login and password authentication (keys only).
  • Set umask to 027 to restrict default file permissions.
  • Enable auditd for system call auditing.
  • Configure fail2ban or ufw firewall rules.
  • Install and configure a security monitoring agent (e.g., AWS Inspector agent, Datadog agent, Falco).
  • Remove compilers (gcc, make) that attackers could use to compile exploit code.

By baking this into the image, you achieve compliance by default. Every server launched from the Golden Image is compliant from its first second of existence. You do not need to run a compliance scanner and then remediate — the image is the remediation.

The Image Hierarchy

In practice, most organizations build images in layers:

Base OS Image (Ubuntu 22.04 from Canonical)
    └── Hardened Base Image (CIS benchmark applied, monitoring agents installed)
            ├── Web Server Image (Nginx added)
            │       └── App Image v1.4.2 (your application code added)
            ├── Database Image (PostgreSQL added)
            └── Worker Image (job processing dependencies added)

Each layer is built with Packer, using the previous layer's image as its source_ami_filter. This means the CIS hardening only needs to be applied once (in the Hardened Base Image build), and all downstream images inherit it automatically.

Interview Tip

Interviewers at security-conscious companies often ask: "How do you ensure all your servers meet your security baseline?" A junior answer mentions running a scanner periodically. A senior answer describes the Golden Image pipeline: security hardening is applied once in a Packer build, the resulting image is tested against the CIS benchmark using a tool like inspec or oscap as a Packer post-processor, and only images that pass are tagged as approved for production. All Terraform code is constrained to use only approved images via tag filters. Drift is impossible because servers are never modified after launch.

Key Point: Golden Images shift security and compliance left — from a runtime concern (scanning running servers) to a build-time concern (testing images before they are ever deployed). A server that fails a security check never reaches production because the image build fails first, not because a scanner catches it after the fact.

This is one of 18 chapters

Every chapter is free — Kubernetes, Terraform, SRE, distributed systems, and more — with fast daily review built in.

Sign up free