Skip to content

About

Test your own Docker and Kubernetes environments

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

test-your-environment

A companion kit for the Portainer container security webinar.

These scripts check whether your Docker host or Kubernetes cluster accepts or refuses the dangerous container requests demonstrated in the webinar: privileged containers, host namespaces, host filesystem mounts and Docker socket mounts. They also check whether the isolation controls that limit the damage (rootless mode, user namespaces, NetworkPolicy enforcement) are really in effect.

These are the checks we ran during the session. Run them against your own environment to find out which of the requests you saw demonstrated it would accept, and which it would refuse.

What this is, and what it is not

This is a detection kit. Each check asks the runtime to do something dangerous and records one thing: was the request accepted, or refused?

This is not an exploit kit. No check:

  • reads /etc/shadow, /etc/ssh/, credentials, keys or any private data
  • writes to the host filesystem
  • starts a reverse shell or makes outbound connections (the only thing a check container talks to is the Docker socket, and by default it does not even do that - it only confirms the socket is reachable)
  • leaves containers, pods or namespaces behind
  • contains exploit code or CVE payloads

Every check is designed to be safe to run against a production environment. You should still read the scripts before running them anywhere that matters - they are short, and that is the point.

Disclaimer

Use at your own risk. This kit is licensed under the Apache License 2.0 and is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and non-infringement. In no event shall Portainer.io Limited or the contributors be liable for any claim, damages or other liability arising from, out of or in connection with the use of these scripts.

  • Only run it against systems you own or are authorized to test. Running security checks against infrastructure without permission may breach your organization's policies or the law.
  • You are responsible for where you run it. The checks are designed to be non-destructive, but they do start containers, create a Kubernetes namespace, and send requests that may trigger security alerts, audit events or policy violations in your monitoring tools. Tell your security or platform team before running it on shared or production systems.
  • Results are indicative, not a security assessment. A clean result does not mean an environment is secure, and an [EXPOSED] result does not mean it has been compromised. The checks cover only the specific requests listed below.
  • No support is implied. This is a companion to a webinar, not a supported Portainer product.

Prerequisites

Docker checks

  • Docker installed, with the docker CLI able to reach the engine you want to test (DOCKER_HOST or the current docker context)
  • The alpine image available locally: docker pull alpine

Kubernetes checks

  • kubectl configured and pointing at the target cluster
  • RBAC to create and delete namespaces, and to create pods, services, networkpolicies and pods/exec in the check namespace
  • Cluster nodes able to pull the alpine and busybox images (busybox provides wget and a tiny web server for the NetworkPolicy check)

The scripts are POSIX sh and run under bash, dash, ash or zsh.

How to run

Clone the repository:

git clone https://github.com/portainer/test-your-environment.git
cd test-your-environment

Then run the checks for your environment:

Docker

bash docker/check-docker.sh

Kubernetes (uses the escape-checks namespace by default)

bash kubernetes/check-kubernetes.sh

Kubernetes with a custom namespace (created and deleted by the script)

bash kubernetes/check-kubernetes.sh --namespace my-test-ns

Both main scripts accept --help. Set NO_COLOR=1 to disable color; it is also disabled automatically when output is not a terminal (for example when piped to a file).

Kubernetes namespace setup

You do not need to create anything first. check-kubernetes.sh:

  1. creates a dedicated namespace (escape-checks unless you pass --namespace),
  2. runs every check inside that namespace only, and
  3. deletes the namespace on exit - whether the checks pass, fail, or you press Ctrl-C.

Do not point --namespace at an existing namespace. As a safeguard the script refuses to run if the namespace already exists, and refuses default, kube-system, kube-public and kube-node-lease outright. If a previous run was killed hard (e.g. kill -9) and left escape-checks behind, delete it with kubectl delete namespace escape-checks and re-run.

The new namespace gets whatever Pod Security level your cluster applies to new namespaces by default - which is exactly what an application team would get. The script does not add or change Pod Security labels.

What the checks do

Docker (docker/checks/)

Check What it runs Notes
privileged.sh docker run --rm --privileged alpine sh -c 'echo ...'
host-pid.sh docker run --rm --pid=host alpine sh -c 'echo ...' Does not list or touch host processes
host-network.sh docker run --rm --network=host alpine sh -c 'echo ...' Makes no network connections
bind-mount.sh Mounts /etc/hostname only, read-only, and checks the file appears Does not read the file. The webinar demo used -v /:/host; this check never mounts /
socket-mount.sh Mounts the daemon socket and checks it is present and writable No API call by default (see below)
rootless.sh docker info - is the daemon rootless? No container started
userns-remap.sh docker info - is userns-remap enabled? No container started

Bind and socket mounts use --mount rather than -v: with -v, a missing source path is silently created as a directory on the host; --mount fails instead, so the checks can never write to the host.

SOCKET_API_CHECK=1 bash docker/check-docker.sh makes the socket check go one step further and call the read-only GET /version endpoint through the mounted socket. This installs curl inside the throwaway container, which downloads from the Alpine package mirror, so it is off by default.

Kubernetes (kubernetes/checks/)

Check What it does
pod-security.sh Submits a privileged: true pod (manifests/test-privileged.yaml)
hostpath.sh Submits a pod mounting /etc/hostname read-only via hostPath (manifests/test-hostpath.yaml)
host-namespaces.sh Submits a hostPID: true pod and a hostNetwork: true pod
user-namespaces.sh Runs a hostUsers: false pod that prints /proc/self/uid_map and exits
network-policy.sh Starts a web pod + client pod, confirms traffic flows, applies a default-deny ingress policy, confirms traffic is blocked

The admission checks (pod-security, hostpath, host-namespaces) use kubectl create --dry-run=server. The pod goes through every admission controller - Pod Security Admission, validating webhooks (Kyverno, Gatekeeper), ValidatingAdmissionPolicy - exactly as a real request would, but nothing is persisted and no container starts. (If a webhook refuses dry-run requests, the check falls back to a real create; the pod only runs sleep 5 and is removed with the namespace.)

Only user-namespaces.sh and network-policy.sh start real pods. They run as a non-root UID with a restricted-compliant security context, mount nothing from the node, and are deleted with the namespace.

How to read the output

DOCKER ENVIRONMENT CHECK
========================
[EXPOSED]    --privileged:        accepted - engine executes without restriction
[EXPOSED]    --pid=host:          accepted - engine executes without restriction
[EXPOSED]    --network=host:      accepted - engine executes without restriction
[EXPOSED]    Host bind mount:     accepted - engine executes without restriction
[EXPOSED]    Docker socket mount: accepted - engine executes without restriction
[PARTIAL]    Rootless mode:       active - escapes land as invoking user, not host root
[EXPOSED]    userns-remap:        not enabled

KUBERNETES ENVIRONMENT CHECK  (namespace: escape-checks)
========================================================
[REFUSED]    --privileged:        Pod Security baseline refused at admission
[REFUSED]    hostPath volumes:    Pod Security baseline refused at admission
[REFUSED]    hostPID:             Pod Security baseline refused at admission
[REFUSED]    hostNetwork:         Pod Security baseline refused at admission
[ACTIVE]     User namespaces:     hostUsers: false remaps UID 0 - uid_map confirmed (0 1745813504 65536)
[ENFORCED]   NetworkPolicy:       default-deny blocks traffic (CNI enforces)
Tag Color Meaning
[EXPOSED] red The dangerous request was accepted, or the control is missing
[UNENFORCED] red The control was accepted by the API but nothing enforces it
[INACTIVE] red The control was requested but is not in effect
[REFUSED] green The request was refused - the line says by whom
[ACTIVE] / [ENFORCED] green The control is in effect and was verified
[PARTIAL] yellow Some protection, but not a refusal
[ERROR] / [UNKNOWN] / [SKIPPED] yellow The check could not reach a verdict - the line says why

What EXPOSED means - and what it does not

[EXPOSED] means the runtime has no gate for that request. Anyone who can start a container on this engine (or a pod in a new namespace on this cluster) can ask for it and get it.

It does not mean your host is compromised, that anyone has used it, or that you have a vulnerability in the CVE sense. Plain Docker accepts every one of these requests by design: the Docker API is root-equivalent, and the engine trusts whoever can reach it. That is the point the webinar made - the gate has to come from somewhere else (rootless mode, user namespaces, an authorization layer in front of the API, or admission control in Kubernetes).

Likewise, [REFUSED] means the request was stopped at the door. It does not mean the environment is secure in every other respect.

Common results

  • Docker reports EXPOSED for every flag. Normal for a default Docker install. Rootless mode and userns-remap reduce what an escape reaches; restricting who can reach the Docker API controls who can ask.
  • Kubernetes admits everything. New namespaces get the cluster's default Pod Security level, which is privileged (no restriction) unless an admission configuration says otherwise.
  • Pod Security only warns here, it does not enforce. The namespace has a warn or audit level but no enforce level. Users see a warning; the pod is still admitted.
  • NetworkPolicy [UNENFORCED]. The API server stored the policy, but the CNI ignored it. This is a known gap on CNIs without NetworkPolicy support
    • for example KubeSolo without Cilium, or Flannel on its own.
  • User namespaces [INACTIVE]. The hostUsers: false field was dropped (feature not enabled on the cluster) or the pod got the identity map 0 0 4294967295. Needs Kubernetes 1.33+ (or the feature gate on earlier versions), a container runtime with user namespace support, and a kernel with idmapped mounts.

Exit codes

Code Meaning
0 Checks ran (whatever the results)
2 Preflight failed - nothing was checked
130 / 143 Interrupted (Kubernetes namespace is still cleaned up)

Sharing your results

Paste your output into RESULTS.md and share it with your platform or security team as a starting point for deciding what to change. Remove anything you consider sensitive (for example context names or engine versions) before sharing it outside your organization.

Source

These checks come from the Portainer Container Platform Threat Model paper, which sets out the escape paths the webinar demonstrated and the controls that close them.

License

Copyright 2026 Portainer.io Limited.

Licensed under the Apache License, Version 2.0. See LICENSE for the full text.

Repository layout

├── README.md
├── LICENSE                      # Apache License 2.0
├── .shellcheckrc                # lint settings for ShellCheck only; not used when running the checks
├── RESULTS.md                   # template: paste your output and share
├── lib/                         # shared output/helper functions
├── docker/
│   ├── check-docker.sh          # runs all Docker checks, prints summary
│   └── checks/                  # one script per check
└── kubernetes/
    ├── check-kubernetes.sh      # creates namespace, runs checks, deletes namespace
    ├── checks/                  # one script per check
    └── manifests/               # pod specs used by the checks

About

Test your own Docker and Kubernetes environments

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages