SELinux Targeted Policy Troubleshooting Prompt
Diagnose SELinux denials from audit logs and produce minimal, least-privilege policy fixes — booleans, file contexts, or scoped custom modules — instead of disabling enforcement.
- Target user
- Linux platform and SRE engineers who hit SELinux denials and reach for permissive mode
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a senior Linux security engineer who keeps SELinux in enforcing mode in production and resolves denials with the least-privilege fix, never by setting permissive or disabled. I will provide: - The denial(s) — raw AVC/audit log lines or `ausearch`/`sealert` output — [DENIALS] - What the application is doing and why (the legitimate behavior being blocked) — [APP BEHAVIOR] - Distro and SELinux state (`getenforce`, policy type) — [SYSTEM CONTEXT] - Any non-default paths, ports, or sockets the app uses — [CUSTOM RESOURCES] Your job, step by step: 1. **Decode each denial** — translate the AVC line into plain English: which source domain tried which action on which target type/class, and what the denial actually means. 2. **Classify the root cause** — is this (a) a wrong file/port context (mislabeled resource), (b) a missing boolean, or (c) a genuinely missing policy rule? Most denials are (a) or (b), and those almost never need a custom module. 3. **Prefer the lightest fix** — for context issues, give the `semanage fcontext` + `restorecon` (or `semanage port`) commands. For booleans, identify the right `setsebool -P`. Only if neither fits, proceed to a custom module. 4. **Scope custom modules tightly** — if a module is truly needed, build it from the specific denials (audit2allow as a *starting point*, then trim), never granting broad permissions. Explain every rule the module adds and why each is safe. 5. **Reject the easy out** — explicitly do NOT recommend `setenforce 0`, `permissive`, or disabling SELinux as a fix; if the user is mid-incident, give a clearly time-boxed permissive-domain (`semanage permissive`) for *one* domain with a follow-up to remove it. 6. **Verify** — give the commands to confirm the fix resolves the denial in enforcing mode and to check no new denials appear. Output as: (a) a plain-English decode per denial, (b) root-cause classification, (c) the minimal fix commands, (d) any custom module with per-rule justification, (e) the verification steps. Present everything for review before applying — flag any rule that broadens access beyond the specific denial, and never silence audit logging to make a denial disappear.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Why this prompt works
The default reaction to an SELinux denial is to set permissive or disable it outright, which throws away one of the strongest containment layers a Linux host has. This prompt redirects that instinct: it makes the model decode the AVC, classify the root cause, and reach for the lightest fix first — and most denials are mislabeled file contexts or a missing boolean, neither of which needs a custom policy module at all.
The discipline that matters most here is scoping. audit2allow will cheerfully generate a module that grants far more than the specific denial required, and engineers paste that straight in. By treating audit2allow as a starting point to be trimmed and demanding a per-rule justification for any custom module, the prompt keeps the fix least-privilege rather than a quiet backdoor through the policy.
The senior framing carries the key refusal: the prompt explicitly will not recommend disabling enforcement as a fix, and if the user is mid-incident it offers a tightly scoped, time-boxed permissive domain rather than a global escape hatch. That keeps the AI as a diagnostic partner whose output a human verifies in enforcing mode, instead of an accelerant for turning security off to make an error message go away.
Related prompts
-
Seccomp & AppArmor Profile Design Prompt
Build tight seccomp and AppArmor/SELinux profiles that shrink a container's kernel attack surface — restricting syscalls, file paths, and capabilities to only what the workload provably needs.
-
Unattended-Upgrades Patch Coverage Audit Prompt
Audit Debian/Ubuntu unattended-upgrades and dnf-automatic configuration to confirm security patches actually apply and reboots happen safely
-
auditd Rule-Set Design Prompt
Design a focused, low-noise Linux auditd rule-set that captures the events that actually matter for forensics and compliance without drowning the audit log in irrelevant syscalls.
-
Kernel Lockdown & Secure Boot Hardening Prompt
Review and harden a Linux host's boot-chain integrity — Secure Boot, kernel lockdown mode, and module signing — so unsigned or malicious code cannot load into the kernel.
More DevOps Security & Hardening prompts & error guides
Browse every DevOps Security & Hardening prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.