Skip to content
Tutorials Center
My learning

Topics

Lesson 65 of 80 ยท Privacy, Cloud and Secure Design

Cloud and Container Security

Learn the shared responsibility model, least-privilege IAM, how storage gets exposed, and how to harden containers, with Python linters you can run.

Moving to the cloud does not move the security problem to someone else. It changes who does what. The provider secures the buildings, the hardware and the virtualization layer. You still decide who can log in, which data is public, how your applications are configured and what runs inside your containers. Most cloud breaches in the news are not clever attacks on the provider; they are a storage bucket left open, an access key with far too many permissions, or a container running as root.

This lesson covers the four ideas that prevent most of those incidents: the shared responsibility model, least-privilege identity and access management (IAM), safe storage configuration, and container hardening. You will also build three small Python linters, because the best cloud controls are the ones a machine checks on every change. It builds on Authorization and Access Control Models and Endpoint Protection and System Hardening.

The shared responsibility model

Every cloud service splits duties between the provider and the customer. The split moves depending on how much the provider manages for you.

flowchart TB
    subgraph CUST["Always the customer"]
        D["Data and its classification"]
        I["Identities, keys and permissions"]
        C["Configuration of every service you use"]
    end
    subgraph MIX["Depends on the service model"]
        R["Guest OS, runtime, patching, network rules"]
    end
    subgraph PROV["Always the provider"]
        H["Hardware, data centers, hypervisor, global network"]
    end
    D --> I --> C --> R --> H

The more managed the service, the less you patch, but data, identities and configuration always stay yours.

Model You manage Provider manages
IaaS (virtual machines) OS, patches, firewall rules, apps, data Hardware, hypervisor
PaaS (managed runtimes and databases) App code, configuration, data, access OS, runtime patching, platform
SaaS (hosted applications) Users, permissions, data sharing settings Almost everything else

A practical consequence: for a managed database you no longer patch the database engine, but you are still responsible for who can connect, whether traffic is encrypted and whether the backup is exposed. When something goes wrong, ask "which side of the line was this on?" first. Misconfiguration is on your side of the line almost every time.

IAM and least privilege

In the cloud almost everything is an API call, and an identity decides which calls succeed. Identities include human users, roles assumed by services and machines, and long-lived access keys. Permissions are written as policies: JSON documents that say which actions an identity may perform on which resources, optionally under conditions.

The rule you already know from The CIA Triad and Core Principles is least privilege: grant only the actions needed, on only the resources needed, for only as long as needed. In policy terms:

  • Avoid the wildcard * for actions and resources. s3:GetObject on one bucket path is a different universe from s3:* on everything.
  • Prefer roles with short-lived credentials over long-lived access keys. A key that never expires will eventually leak into a repository or a laptop backup.
  • Require MFA for humans, and never use the root or owner account for daily work; lock it away.
  • Separate duties: the pipeline that deploys should not be able to read production customer data, and the people who read logs should not be able to delete them.
  • Watch for privilege escalation actions, such as the ability to attach policies, create access keys or pass a powerful role to a service. An identity that can edit its own permissions effectively has all permissions.
  • Review regularly and remove what is unused. Permissions only ever creep upward unless someone cleans them.

The cloud providers differ in syntax, but the shape is the same, so a linter can catch the worst patterns. The example below uses an AWS-style policy format on invented accounts and buckets.

Python A policy linter for risky wildcards

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Notice the last policy. Public read access to a web assets bucket can be legitimate, and the linter still flags it. That is the right behavior: a human should confirm that bucket really holds only public files, and record the decision. A linter's job is to make risky choices visible and deliberate.

Misconfigured storage

Object storage (buckets and blobs) is the classic cloud leak. The pattern repeats: someone makes a bucket public to share one file or to debug an integration, then forgets. Search engines for exposed buckets exist, and attackers scan for them continuously. The data inside is often backups, exports and logs, exactly the files nobody thought of as "published".

Defenses, in order of importance:

  1. Block public access at the account level, so a single mistake on one bucket cannot expose it. Allow exceptions only on purpose-built, separate buckets.
  2. Encrypt at rest with provider-managed or customer-managed keys, and require TLS in transit.
  3. Turn on versioning and access logging, so you can recover overwritten data and answer "who read this?" See Backups, Resilience and Business Continuity.
  4. Use short-lived, signed URLs to share a private object instead of making it public.
  5. Scan continuously. Cloud security posture management (CSPM) tools do exactly what the next demo does, at scale.
Python Auditing storage settings

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The database dump bucket tops the list because it combines open access, no encryption and a purpose that should never be public. Adding context (what the data is) to configuration checks is what separates useful findings from noise.

Container security

Containers package an application with its dependencies and run it on a shared kernel. That is efficient, and it also means a weak container setup can expose the host. Hardening happens at three moments: when you build the image, when you ship it and when you run it.

Build time

  • Start from a small, trusted base image (a slim or "distroless" variant). Fewer packages means fewer vulnerabilities and fewer tools for an attacker to use.
  • Pin versions with a specific tag or, better, a digest; avoid latest, which changes without notice.
  • Create a non-root user and switch to it with USER. Running as root inside a container is a common starting point for escapes.
  • Never put secrets in the image: not in ENV, ARG, copied files or layers. Layers are permanent and anyone with the image can read them. Pass secrets at runtime from a secret store (see Randomness, Key Management and Secrets).
  • Use multi-stage builds so compilers and build tools never reach the final image.

Ship time

  • Scan images for known vulnerabilities and for secrets before they reach a registry, and again on a schedule, because new CVEs appear for old images (see Dependency and Supply Chain Security).
  • Sign images and only deploy signed ones from a private registry you control.

Run time

  • Do not run privileged containers, and do not mount the container runtime socket or the host filesystem into one.
  • Drop Linux capabilities you do not need and add back only what is required; set no-new-privileges.
  • Use a read-only root filesystem with small writable temp mounts, and set CPU and memory limits so one container cannot starve the host.
  • Apply network policies so containers can talk only to the services they need. In orchestrators such as Kubernetes, also enforce pod security standards and keep the API server and dashboards off the public internet.

A hardened runtime configuration looks like this (read-only, shown in Compose syntax):

YAML
services:
  api:
    image: registry.example.com/acme/api:1.8.2
    user: "10001:10001"
    read_only: true
    tmpfs: ["/tmp"]
    cap_drop: ["ALL"]
    security_opt: ["no-new-privileges:true"]
    mem_limit: 256m
    pids_limit: 200

The Dockerfile itself can be linted before it is ever built. This demo checks a few of the most common mistakes.

Python A tiny Dockerfile linter

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Real tools (Hadolint for Dockerfiles, Trivy or Grype for images, kube-linter or policy engines for Kubernetes manifests) apply hundreds of such rules. The principle is the same: encode the rule once, run it on every pull request.

A cloud security checklist

  • Turn on audit logging for every account and send the logs to a separate, locked-down account (see Logging, Log Analysis and SIEM).
  • Use infrastructure as code and review changes like application code, so configuration is versioned and lintable.
  • Separate environments (development, staging, production) into separate accounts or projects.
  • Encrypt everything, manage keys centrally, and rotate them.
  • Monitor for the classic signals: new access keys, permission changes, public storage, logins from unusual places, large data transfers out.
  • Practice recovery. A cloud account is not a backup of itself.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. A company runs its application on managed platform services. Who is responsible for deciding which users can read the stored customer data?

    Data, identities and access configuration are always the customer's job under the shared responsibility model, whatever the service type.
  2. 2. Which IAM change best follows least privilege for a CI pipeline that only uploads build files to one bucket path?

    Grant the single action needed on the single resource needed. Wildcards and administrator roles turn a pipeline compromise into an account compromise.
  3. 3. Why is an unpinned base image such as python:latest risky?

    A moving tag means today's build and tomorrow's build can differ. Pin a version or digest so you know what you are shipping and can update deliberately.
  4. 4. What is the most effective single control against accidental public storage buckets?

    An account-wide block means one mistaken setting on one bucket cannot expose data. Names and annual checks do not stop a misconfiguration.
  5. 5. Which runtime setting reduces the damage of a compromised container the most?

    A non-root user, minimal capabilities and a read-only filesystem limit what an attacker can change or reach even after getting code execution inside the container.

Summary

  • The provider secures the infrastructure; you secure your data, identities and configuration, and misconfiguration is the usual cause of cloud breaches.
  • Apply least privilege in IAM: no wildcards, short-lived role credentials, MFA for people, separation of duties and regular cleanup.
  • Block public storage access account-wide, encrypt, enable versioning and logging, and share private files with signed, expiring links.
  • Harden containers at build, ship and run time: small pinned images, non-root users, no baked-in secrets, scanning, dropped capabilities and read-only filesystems.
  • Encode rules as linters and run them on every change, with human review for deliberate exceptions.

Next: Backups, Resilience and Business Continuity, where you will plan for the day a control fails and data must be recovered.