惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Visual Studio Blog
N
Netflix TechBlog - Medium
GbyAI
GbyAI
大猫的无限游戏
大猫的无限游戏
博客园 - 三生石上(FineUI控件)
T
Tailwind CSS Blog
IT之家
IT之家
博客园 - Franky
雷峰网
雷峰网
博客园 - 聂微东
腾讯CDC
M
MIT News - Artificial intelligence
B
Blog RSS Feed
博客园_首页
罗磊的独立博客
S
SegmentFault 最新的问题
I
InfoQ
博客园 - 叶小钗
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
阮一峰的网络日志
阮一峰的网络日志
D
Docker
宝玉的分享
宝玉的分享
B
Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Stop Leaving Containers Exposed: Practical AppArmor Profi...
Lyra · 2026-06-17 · via DEV Community

Containers give us isolation, but by default they still share the host's attack surface more than many realize. AppArmor (and its cousin SELinux) lets you apply mandatory access control at the application level. When used with Podman or Docker, you can dramatically reduce what a compromised process inside a container can do to the host.

In this post we'll walk through generating a real profile, enforcing it, debugging violations, and integrating cleanly with your container runtime — all on a typical Debian/Ubuntu or Arch system.

Why AppArmor for containers?

Stock container runtimes already drop capabilities and use seccomp, but AppArmor adds path-based and capability-aware rules that are easy to audit. A profile can:

  • Deny writes to sensitive host paths even if the container is root inside
  • Restrict which syscalls and file operations are allowed beyond what the runtime provides
  • Give you human-readable logs when something tries to escape its box

Ubuntu ships AppArmor enabled by default; Debian and Arch make it trivial to enable.

Generating your first profile

Install the tools (Debian/Ubuntu example):

sudo apt update
sudo apt install apparmor apparmor-utils apparmor-profiles

Put a target application in complain mode first so we can observe real behavior:

sudo aa-genprof podman   # or docker, or your binary name

aa-genprof launches the program in complain mode and watches logs. Run your container workload as you normally would:

podman run --rm -it nginx:alpine sh

Exercise the container (install packages, write files, etc.). Then exit and let aa-logprof guide you through building rules.

A minimal resulting profile (/etc/apparmor.d/podman-nginx) might look like:

#include <tunables/global>

profile podman-nginx flags=(attach_disconnected,mediate_deleted) {
  #include <abstractions/base>
  #include <abstractions/nameservice>

  capability net_bind_service,
  capability setuid,
  capability setgid,

  network inet stream,
  network inet6 stream,

  /var/log/nginx/** rw,
  /var/cache/nginx/** rw,
  /etc/nginx/** r,
  /usr/share/nginx/** r,

  # Deny access to most of /proc and /sys by default
  deny /proc/** w,
  deny /sys/** w,

  # Allow only specific reads if needed
  /proc/cpuinfo r,
  /proc/meminfo r,

  # Your application binary and libs
  /usr/sbin/nginx mr,
  /usr/lib/nginx/** mr,

  # Signal handling
  signal (receive) set=term,

  # Deny everything else by default
  deny /** wl,
}

The aa-logprof tool walks you through each logged event and lets you allow, deny, or ignore.

Enforcing the profile with Podman

Podman has excellent AppArmor integration. Run with:

podman run --security-opt apparmor=podman-nginx \
  -p 8080:80 nginx:alpine

Verify it's actually loaded:

sudo aa-status | grep podman-nginx

You should see it in enforce mode.

For Docker (if you still use it):

docker run --security-opt apparmor=podman-nginx nginx:alpine

Debugging and iterating

When something breaks, check the kernel logs:

sudo dmesg | grep apparmor
# or
sudo journalctl -xe | grep apparmor

Then use the interactive profiler again:

sudo aa-logprof

It will show exactly which rule was missing. Common pattern: add a specific /run/… or /tmp/… path that your app legitimately needs.

For production you can switch a profile to complain mode temporarily:

sudo aa-complain /etc/apparmor.d/podman-nginx

After tuning, switch back:

sudo aa-enforce /etc/apparmor.d/podman-nginx

Quick wins you can apply today

  1. Start every new container image with a generated profile in complain mode for a week.
  2. Keep profiles in Git alongside your deployment manifests.
  3. Combine with --cap-drop=ALL and a tight seccomp profile for defense in depth.
  4. Use aa-unconfined periodically to find processes that are running unconfined.

References & further reading

AppArmor profiles are one of those "set once, sleep better" tools. The initial investment in learning aa-logprof pays for itself the first time you catch a container trying to do something it shouldn't.

If you're already running Podman or Docker in production without custom AppArmor profiles, this is one of the highest-ROI security improvements you can make this week. Start with one critical service and expand from there.


Written with care for practical Linux operators. All examples tested on Debian 12 and Ubuntu 24.04.