Skip to Content
Mengty Learns
Platform tools

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).

referenceintermediateTested with ansible-core 2.22 (docs), kubernetes 1.35.10 (docs), kyverno 1.20.0 (docs)Updated Nov 27, 2026

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 with rule, reason, and expires, and fail the playbook if expires <= today.
  • SSH & Mandatory Access Control: Disable root login and password auth, validate sshd_config with sshd -t -f %s before reload, and assert SELinux == enforcing in production.
  • Default-deny firewall: Set firewalld default zone to drop (or nftables default-drop) and open only the exact ports each host role requires.
  • Audit & file integrity: Forward auditd privileged-command logs to the SIEM and run scheduled AIDE integrity checks.

2. Cluster & namespace baseline (Kubernetes)

  • Pod Security Admission (restricted): Label every application namespace with pod-security.kubernetes.io/enforce: restricted so 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 :latest tags, require resources.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: Applying default-deny-all with Egress enabled breaks service discovery immediately unless you add an explicit egress rule to kube-dns on port 53.
  • Permissive SELinux left on in prod: Setting SELinux to permissive "temporarily" hides policy denials instead of fixing file contexts; use assert in Ansible to block permissive mode in production.
  • Unbounded waivers: Inline # nosec comments 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: restricted and default-deny-all NetworkPolicy.
  • Kyverno blocks :latest tags, unsigned images, and Pods without resource limits.
  • etcd encryption 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