Platform Security Baseline: Hosts, Clusters, and Exceptions
Enforce a practical, auditable security baseline across Linux hosts (CIS, SELinux, firewalld, auditd, AIDE) and Kubernetes namespaces (PodSecurity, NetworkPolicy, Kyverno).
TL;DR
A security baseline only holds if it is codified and enforced automatically. Harden Linux hosts with CIS controls, SELinux enforcing, default-deny firewalld, auditd, and AIDE; harden Kubernetes namespaces with PodSecurity: restricted, default-deny NetworkPolicy, and Kyverno admission policies—and track every waiver with an expiry date.
Why it exists
Manual hardening checklists rot within weeks: a developer disables SELinux to debug a socket error, a Pod ships as root, or a temporary firewall port stays open for years. Encoding the baseline into Ansible roles and Kubernetes admission policies turns security posture into a repeatable, testable artifact.
Mental model
1. Host baseline (Linux VMs)
- CIS Benchmark + time-boxed exceptions: Apply a CIS role (e.g.
rhel9_cis), store approved waivers in a structured list withrule,reason, andexpires, and fail the playbook ifexpires <= today. - SSH & Mandatory Access Control: Disable root login and password auth, validate
sshd_configwithsshd -t -f %sbefore reload, and assertSELinux == enforcingin production. - Default-deny firewall: Set
firewallddefault zone todrop(ornftablesdefault-drop) and open only the exact ports each host role requires. - Audit & file integrity: Forward
auditdprivileged-command logs to the SIEM and run scheduledAIDEintegrity checks.
2. Cluster & namespace baseline (Kubernetes)
- Pod Security Admission (
restricted): Label every application namespace withpod-security.kubernetes.io/enforce: restrictedso the API server rejects root containers,privileged: true, and missing seccomp profiles. - Default-deny
NetworkPolicy: Block all ingress and egress by default, then add explicit allow rules for CoreDNS (53/UDP,53/TCP), ingress controllers, and required data stores. - Policy-as-code (Kyverno): Require signed image digests, disallow
:latesttags, requireresources.limits, and mandate ownership labels (owner,team).
Do it
Enforce restricted Pod Security and default-deny networking on an app namespace:
# Namespace with Pod Security Admission enforced (not run)
apiVersion: v1
kind: Namespace
metadata:
name: app-orders
labels:
pod-security.kubernetes.io/enforce: restricted
pod-security.kubernetes.io/audit: restricted
pod-security.kubernetes.io/warn: restricted
---
# Default-deny all ingress & egress in app-orders (not run)
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny-all
namespace: app-orders
spec:
podSelector: {}
policyTypes: ["Ingress", "Egress"]Assert in Ansible that no CIS exception has expired:
# Fail if a documented CIS waiver has passed its expiry date (not run)
- name: Fail on expired CIS exceptions
ansible.builtin.assert:
that: item.expires > ansible_date_time.date
fail_msg: "CIS exception {{ item.rule }} expired on {{ item.expires }}."
loop: "{{ cis_exceptions }}"Gotchas
- Forgetting DNS egress in
NetworkPolicy: Applyingdefault-deny-allwithEgressenabled breaks service discovery immediately unless you add an explicit egress rule tokube-dnson port 53. - Permissive SELinux left on in prod: Setting SELinux to
permissive"temporarily" hides policy denials instead of fixing file contexts; useassertin Ansible to block permissive mode in production. - Unbounded waivers: Inline
# noseccomments or permanent CIS skips accumulate silently; require an expiry date and ticket reference for every exception.
Production checklist
- Linux hosts run with CIS baseline, SELinux
enforcing, default-deny firewall,auditd, and AIDE. - Every CIS or scanner exception has an owner, ticket, and expiry date checked in CI/Ansible.
- Kubernetes app namespaces enforce
pod-security.kubernetes.io/enforce: restrictedanddefault-deny-allNetworkPolicy. - Kyverno blocks
:latesttags, unsigned images, and Pods without resource limits. -
etcdencryption at rest uses a KMS provider, and API server audit logs ship to a SIEM.
Check yourself
Check Yourself
1. What happens if you apply a default-deny-all NetworkPolicy (covering both Ingress and Egress) to a namespace without adding a DNS rule?
2. Why should sshd_config templates in Ansible include `validate: 'sshd -t -f %s'`?
Sources
Secure Deployment Platform: VM & Kubernetes Tracks
How a regulated deployment platform separates environments, builds immutable artifacts once, and delivers them across parallel VM and Kubernetes tracks.
Ansible Essentials
Agentless host configuration and rolling VM deployments—inventory, variable precedence, idempotency, handlers, and safe rollouts.