Skip to main content
skill CX Codex

container-hardening — Claude Code skill: what it does, how to install

Hardens Docker images and runtime environments with non-root users, read-only filesystems, and Kubernetes security contexts.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add BagelHole/DevOps-Security-Agent-Skills --skill container-hardening -a claude-code
Open on GitHub

What container-hardening does

This skill provides templates and rules to lock down container images and deployment manifests. It outlines Dockerfile patterns using dedicated non-root users with UID 1001, minimal base images like Alpine or distroless, and explicit ownership via --chown.

For execution, it includes hardened docker run flags such as --cap-drop=ALL, --security-opt=no-new-privileges:true, and --read-only. It also covers Kubernetes Pod manifests with strict securityContext configurations and image scanning rules via Trivy.

Applications that require arbitrary writes across the filesystem will fail under these restrictions. You will need to declare explicit writable paths, such as --tmpfs /tmp, before deploying.

What it helps with

  • switch Dockerfile builds to an unprivileged user
  • drop unnecessary Linux capabilities on container startup
  • configure securityContext for Kubernetes pods
  • scan container images for high-severity vulnerabilities with Trivy

Example prompts for the agent

  • Harden this Dockerfile by creating a non-root user and stripping build tools.
  • Generate a Kubernetes pod manifest with read-only root filesystem and dropped capabilities.
  • Show a secure docker run command that blocks privilege escalation.

How to install container-hardening

1Skills CLI (Vercel)

npx skills add BagelHole/DevOps-Security-Agent-Skills --skill container-hardening -a claude-code

2Manually: put the files in place

~/.claude/skills/container-hardening/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/container-hardening/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about container-hardening

How do I install container-hardening in Claude Code?

Run npx skills add BagelHole/DevOps-Security-Agent-Skills --skill container-hardening -a claude-code in your terminal.

What does container-hardening do?

It guides the assistant in securing Dockerfiles, locking down container runtime options, and applying Kubernetes security contexts.

Which image scanner is featured in the skill templates?

It includes scanning examples using Trivy configured for HIGH and CRITICAL vulnerability severities.

Source text

SKILL.md · MIT
---
name: container-hardening
description: Secure Docker images and container runtime configurations. Implement non-root users, read-only filesystems, and security contexts. Use when building secure container images or hardening container deployments.
license: MIT
metadata:
  author: devops-skills
  version: "1.0"
---

# Container Hardening

Secure container images and runtime configurations.

## When to Use This Skill

Use this skill when:
- Building secure container images
- Hardening container deployments
- Meeting container security requirements
- Implementing defense in depth

## Dockerfile Security

```dockerfile
# Use minimal base image
FROM alpine:3.18

# Don't run as root
RUN addgroup -g 1001 -S appgroup && \
    adduser -u 1001 -S appuser -G appgroup

# Copy with specific ownership
COPY --chown=appuser:appgroup . /app

# Remove unnecessary packages
RUN apk del --purge build-dependencies && \
    rm -rf /var/cache/apk/*

# Use non-root user
USER appuser

# Read-only filesystem support
WORKDIR /app
```

## Runtime Security

```bash
# Run with security options
docker run -d \
  --read-only \
  --tmpfs /tmp \
  --security-opt=no-new-privileges:true \
  --cap-drop=ALL \
  --cap-add=NET_BIND_SERVICE \
  --user 1001:1001 \
  myapp:latest
```

## Kubernetes Security Context

```yaml
apiVersion: v1
kind: Pod
spec:
  securityContext:
    runAsNonRoot: true
    runAsUser: 1001
    fsGroup: 1001
  containers:
  - name: app
    securityContext:
      allowPrivilegeEscalation: false
      readOnlyRootFilesystem: true
      capabilities:
        drop: ["ALL"]
```

## Image Scanning

```bash
# Scan with Trivy
trivy image --severity HIGH,CRITICAL myapp:latest

# Use distroless images
FROM gcr.io/distroless/static-debian11
```

## Best Practices

- Use minimal base images
- Run as non-root user
- Enable read-only filesystem
- Drop all capabilities
- Scan images regularly
- Sign and verify images
- Use secrets management

## Related Skills

- [container-scanning](../../scanning/container-scanning/) - Vulnerability scanning
- [kubernetes-hardening](../kubernetes-hardening/) - K8s security

© devops-skills · MIT · BagelHole/DevOps-Security-Agent-Skills

Similar skills

Everything for Security →

From the same set127

firewall-config A skill that writes and reviews firewall rules: iptables, nftables, UFW and AWS security groups. Useful when you lock down a server perimeter or split a network into zones. CX Codex +1 458installs ssh-configuration Configures OpenSSH clients and servers, handles Ed25519 keys, port forwarding, and bastion jumps for secure Linux server access. CX Codex +1 451installs prometheus-grafana This skill gives your agent templates for Prometheus scraping, PromQL queries and Grafana panels. Handy when a project needs monitoring added. CX Codex +1 449installs windows-server A skill for Windows Server administration: roles and features, IIS sites, Active Directory users, updates. Useful when the agent touches Windows infrastructure. CX Codex +1 449installs vulnerability-scanning A skill for finding and prioritizing CVEs across systems and dependencies with Nessus, OpenVAS, Qualys and Nuclei. Useful for audits and compliance work. CX Codex +1 424installs postgresql Guides PostgreSQL database administration, streaming replication, backups, and performance tuning. Useful when deploying or optimizing database instances. CX Codex +1 419installs ssl-tls-management A skill for SSL/TLS work: issuing Let's Encrypt certificates, automating renewal, running cert-manager in Kubernetes and checking cipher suites. Useful when you set up HTTPS or fix an expired cert. CX Codex +1 420installs hashicorp-vault A skill that walks your agent through HashiCorp Vault: secret engines, auth methods, policies and certificate issuance, without guessing CLI syntax. CX Codex +1 413installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor