Pod Security Policies got nuked in Kubernetes 1.25. Pod Security Admission is the replacement that actually works... most of the time.
PSA enforces security standards at the namespace level using simple labels. Unlike PSPs, which required you to have a fucking PhD in RBAC to understand what was happening, PSA runs as a built-in admission controller. This means PSA doesn't rely on those godawful webhooks that would randomly decide to take a shit during your Friday deployments.
PSA has been enabled by default since Kubernetes 1.23... or was it 1.22? Fuck it, I'm not looking it up right now - point is, if you upgraded past 1.20 something, it's probably there. Whether it's actually doing anything useful or just lurking in the background waiting to ruin your Friday deployment is anyone's guess.
Pod Security Standards Levels
PSA implements three security levels with increasing restrictions:
Privileged: No restrictions whatsoever. Your pods can do whatever the hell they want - mount the host, run as root, execute random binaries. Use this for system workloads and those ancient legacy apps that were built back when security wasn't even a thought.
Baseline: Blocks the really obvious security disasters like privileged containers and host networking. Most semi-modern apps can probably run under baseline without you wanting to throw your laptop out the window.
Restricted: Full paranoid mode. Pods must run as non-root with read-only filesystems and basically zero capabilities. Good luck getting anything from before 2021 to work with this - you'll be debugging security contexts until the heat death of the universe.
PSA Enforcement Modes
PSA supports three enforcement modes that can be applied independently to each namespace, which sounds flexible until you realize it's just three different ways for things to break:
- enforce: Actually rejects pods that violate the security standard. Failed deployments supposedly return "clear" error messages (spoiler: they don't, you'll still be scratching your head wondering wtf went wrong).
- audit: Lets pods run but creates logs that nobody reads. Great for compliance checkboxes.
- warn: Shows warnings to users who will promptly ignore them and deploy anyway.
You're supposed to start with audit and warn modes first to see what breaks, then enable enforcement once you've "fixed the obvious violations." Ha. What actually happens is you enable audit mode, get flooded with about 847 violations, realize your entire infrastructure was built on the assumption that everything runs as root, and then quietly go back to privileged mode.
Most teams enable audit mode at their target security level, spend about 3 days trying to make sense of the thousands of violations, give up, and just exempt everything. I may or may not have done this myself... multiple times.
Why Pod Security Policies Were Garbage
PSPs had so many fucking design issues that even the Kubernetes maintainers eventually said "fuck it, we're starting over":
- The RBAC relationships were so convoluted that figuring out which policy applied to which pod was like solving a Rubik's cube blindfolded
- Policy selection logic was about as transparent as a brick wall - pods would randomly get different policies and nobody knew why
- Every single policy needed its own special YAML file and a matching RBAC binding, because apparently complexity is a feature
- Error messages were written by someone who clearly hated users and wanted them to suffer
PSA fixes this clusterfuck by using explicit namespace labels - no more guessing games about which policy applies. But here's the catch: PSA trades PSP's fine-grained per-pod control for simpler namespace-level policies. Works fine for most people, but if you need different security settings for each pod in the same namespace, well... you're basically fucked.
PSA is easier to configure than PSPs, but that doesn't mean it's easy to implement. The namespace-level enforcement completely fucks over applications that need mixed security requirements in the same namespace, which is basically every real-world application.
How PSA Plays with Other Kubernetes Security
PSA works with other Kubernetes security stuff like security contexts, network policies, and RBAC. It validates pods early in the admission process, so you get immediate feedback when shit breaks instead of finding out later when your app mysteriously crashes.
PSA error messages are supposedly clearer than PSPs. When a pod gets rejected, the error is supposed to tell you what security control failed. "Supposed to" being the key phrase here - sometimes the errors are still cryptic as hell and about as helpful as a chocolate teapot.
I spent 6 fucking hours debugging why Prometheus node-exporter wouldn't start only to discover it needed to mount /proc
from the host. The error message? "violates PodSecurity restricted:v1.29" - thanks for nothing, Kubernetes. Real helpful. I could have gotten more useful information from a Magic 8-Ball.
Here's some free advice: start with privileged mode everywhere and gradually tighten restrictions. Don't be like me and jump straight to restricted mode thinking you're some kind of security hero. I made that mistake once and spent the entire next Monday fixing 47 different apps that suddenly couldn't write to temp directories anymore. My coffee got cold about 15 times that day.