Skip to content
Tutorials Center
My learning

Topics

Lesson 30 of 53 ยท Network, Wireless and Cloud Security

Cloud and Container Security Testing

Learn the shared responsibility model, common IAM and storage misconfigurations, secrets in images and Kubernetes basics, with Python policy-audit stand-ins.

When a company moves to the cloud, the servers do not disappear; someone else owns the data center and the hypervisor, while the customer still owns almost everything that can be misconfigured. Most real cloud breaches are not clever exploits against the provider. They are an overly generous permission, a storage bucket left public, or a secret that ended up where anyone could read it.

This lesson explains who is responsible for what, the usual mistakes, and how containers and Kubernetes add their own risks. Cloud consoles, provider command-line tools and clusters cannot run on this site, so their settings appear as read-only snippets. Testing a cloud account is only allowed with the owner's written authorization, and many providers have their own rules for security testing, so read them before you start. The runnable parts are Python stand-ins that audit a made-up policy and a made-up Dockerfile.

Shared responsibility

Provider Data centers, hardware, hypervisor.
Customer Identities, data, configuration.
Shared Patching and settings depend on the service type.

The more managed the service, the more the provider handles. Configuration is always yours.

1 / 2

The shared responsibility model

Every provider publishes a version of the same idea. The provider secures the cloud itself: facilities, hardware, the virtualization layer and the managed services' internals. You secure what you put in the cloud: who can log in, what each identity may do, how data is encrypted, which networks can reach what, and how your own software is patched.

What changes with the service type:

  • Infrastructure as a service (virtual machines): you patch the operating system and everything above it.
  • Platform services (managed databases, app platforms): the provider patches the engine; you still control access, network exposure and backups.
  • Software as a service: the provider runs nearly everything, but you still manage users, sharing settings and MFA.

A security test therefore concentrates on configuration and identity, because that is where the customer's mistakes are.

IAM: identity and access management

IAM decides who (users, roles, services) may perform which actions on which resources. It is the center of cloud security: with a powerful enough identity, an attacker needs nothing else. Typical problems:

  • Wildcards: policies that allow every action ("Action": "*") on every resource ("Resource": "*").
  • Everyone is an admin: it was easier at the time, and nobody went back.
  • Long-lived access keys that never rotate, sit in code repositories or are shared between people.
  • No MFA on the accounts that can change everything, especially the root or owner account.
  • Over-trusting roles: a role that any account, or any workload, may assume.
  • Privilege escalation paths: an identity allowed to edit policies or attach roles can give itself more power, even if it looks harmless.

The principle that answers all of them is least privilege: grant exactly the actions and resources needed, nothing more, and review regularly. Prefer short-lived credentials from roles over permanent keys, and put MFA on every human account.

A policy in the common JSON style used by several providers looks like this. It is a read-only example; the exact schema differs per provider.

JSON
{
  "Statement": [
    { "Effect": "Allow", "Action": "storage:GetObject", "Resource": "reports-bucket/*" }
  ]
}

It allows one action on one bucket: narrow and easy to review.

Exposed storage and data

Object storage (buckets, blobs) is cheap, durable and easy to expose by accident. A bucket that is publicly listable or readable has caused many disclosures of customer files, backups and logs. What to check, with permission, on your own accounts:

  • Is public access blocked at the account level, not only bucket by bucket?
  • Do bucket policies and access lists grant access to "everyone" or "any authenticated user" (which can mean anyone with any account on that provider)?
  • Is data encrypted at rest, and are keys managed sensibly?
  • Are snapshots, backups and logs protected as strongly as the original data?

Never browse or download other people's exposed data to "prove" a point. If you find one while researching, stop, record nothing sensitive, and report it through the owner's disclosure channel. See Law, Scope and Rules of Engagement.

Secrets in code, images and environments

A secret is any credential: API keys, passwords, tokens, private keys. Secrets leak in predictable places:

  • Source code and commit history (removing a file does not remove it from history).
  • Container images: every layer is kept, so a secret copied in one step and deleted in the next is still in the image for anyone who pulls it.
  • Build logs, CI variables printed by mistake, and configuration files shared in chat.
  • Instance metadata and environment variables, read by code that should not have that access.

Defenses: use a secrets manager, inject secrets at run time, grant each workload its own narrowly scoped identity, rotate regularly, and scan repositories and images for secrets before they ship (Secure Coding and DevSecOps goes deeper). If a secret leaks, rotate it immediately; deleting it from the repository is not enough.

Containers and Kubernetes basics

A container packages an application with its libraries and runs it isolated from other processes on the same host kernel. Containers are lighter than virtual machines, but they share the host kernel, so a weak configuration can reach the host. See the Docker tutorial for how images and containers work, for example Docker introduction.

Common container weaknesses:

  • Running as root inside the container when a normal user would do.
  • Privileged containers or mounting the Docker socket, which hands out control of the host.
  • Large base images full of unneeded tools and known vulnerabilities; prefer small, maintained base images and rebuild often.
  • Images pulled with moving tags from untrusted registries; pin versions and verify where images come from.
  • Secrets baked into layers (see above).

Kubernetes schedules containers across machines. The key ideas for security testing:

  • Pods run containers; namespaces group resources; service accounts give pods an identity to call the cluster API.
  • RBAC controls who may do what in the cluster. The same least-privilege rules apply, and a role that can read secrets or create pods is powerful.
  • Secrets objects are only base64-encoded by default, which is encoding and not encryption. Enable encryption at rest and restrict who can read them.
  • Network policies limit pod-to-pod traffic; with none, every pod can usually reach every other pod.
  • The API server and the kubelet must never be reachable from the internet without strong authentication.
  • Pod security settings should forbid privileged pods, host networking and running as root.

A read-only fragment showing safer container settings in a Kubernetes manifest:

YAML
securityContext:
  runAsNonRoot: true
  allowPrivilegeEscalation: false
  readOnlyRootFilesystem: true
  capabilities:
    drop: ["ALL"]

Stand-in: audit a sample policy document

This Python program reads a made-up policy (as a JSON string) and reports risky statements. A real scanner works over the provider's API and understands conditions, resource policies and role trust; this one just applies four easy-to-read rules.

Python Stand-in: IAM policy auditor

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 first statement passes because it is narrow. Fix the others by naming exact actions and resources, removing the public principal, and putting permission-editing rights in a separate, heavily protected role.

Stand-in: find secrets in a Dockerfile

Layers keep what you copy in, so a secret in any step ends up in the image. This stand-in scans a made-up Dockerfile for risky lines using simple patterns.

Python Stand-in: Dockerfile checker

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 real fix is to pass secrets at run time from a secrets manager, pin a base image version, add a non-root USER, and expose only the ports the application needs.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Under the shared responsibility model, which item is always the customer's job?

    The provider secures the underlying cloud; configuration, identity and data are yours regardless of the service type.
  2. 2. A developer deletes a password file in a later Docker build step. Is the secret gone from the image?

    Image layers are cumulative. Anything copied in an earlier layer can be extracted. Rotate the secret and rebuild without it.
  3. 3. Why is a policy with Action '' and Resource '' dangerous?

    Compromising that identity compromises the whole account. Least privilege names exact actions and resources.
  4. 4. What is true of Kubernetes Secrets by default?

    Base64 is just encoding. Enable encryption at rest and limit RBAC access to Secrets.

Summary

  • The provider secures the cloud; you secure your identities, data and configuration.
  • IAM is the center: apply least privilege, avoid wildcards, use MFA and short-lived credentials.
  • Public storage and unprotected backups cause many breaches; block public access at account level.
  • Secrets leak through code, history and image layers; use a secrets manager and rotate after any leak.
  • Containers share the host kernel, so run as non-root, avoid privileged mode and keep images small and pinned.
  • Kubernetes needs RBAC, encrypted Secrets, network policies and a protected API server.
  • Only test cloud accounts you are authorized to test, and follow the provider's testing rules.

Next: Privilege Escalation Concepts and OS Hardening.