In the rapidly evolving landscape of cloud-native architecture, security cannot be an afterthought; it must be embedded into the foundational configuration of your infrastructure. For organizations running applications on Amazon Elastic Kubernetes Service (EKS), adhering to Kubernetes Pod Security Standards (PSS) is not just a best practice—it is often a compliance requirement. This guide provides a practical, step-by-step approach to configuring restricted profiles on EKS, moving beyond theoretical concepts to actionable implementation strategies suitable for IT students and junior engineers looking to master container security.
Understanding the Shift from Privileged to Restricted Profiles
Historically, Kubernetes clusters operated with a “least privilege” mindset that was often ignored in favor of convenience. Containers were frequently run as root, allowed unrestricted access to the host filesystem, and permitted privileged mode execution. This approach created a massive attack surface. The introduction of Pod Security Standards changed this paradigm by categorizing policies into three levels: privileged, baseline, and restricted.
The goal of this guide is to help you configure the restricted profile. Unlike the baseline profile, which allows many dangerous capabilities (like mounting host paths or running as root), the restricted profile disables these features entirely. It enforces strict network policies, requires containers to run as non-root users, and prohibits privileged containers. While this might seem limiting, it is the industry standard for production workloads where data integrity and security are paramount.
The EKS Admission Controller: Policy Enforcement
On AWS EKS, enforcing these standards is most effectively done using an admission controller. Without one, you could still deploy insecure pods if a developer bypassed your checks. The recommended solution is to deploy the Open Policy Agent (OPA) Gatekeeper or the native AWS Pod Security Admission (PSA) add-on. For this guide, we will focus on the concept of PSA as it is tightly integrated with EKS control planes, though OPA Gatekeeper offers similar functionality for multi-cloud scenarios.
Before applying policies, you must understand that EKS uses a mechanism called default-enforcement-action. By default, if a policy is not explicitly defined, the cluster may allow insecure configurations. To secure your cluster, you must define the desired state and set the enforcement action to Enforce or Audit during the upgrade process.
Step 1: Preparing Your Environment and Prerequisites
Before modifying cluster settings, ensure your local development environment mirrors production constraints. This is crucial for IT students practicing in lab environments. You will need:
- An EKS cluster with access to the AWS Console or CLI.
kubectlinstalled and configured with appropriate credentials.- A sample application deployment manifest (YAML) that you intend to secure.
- Note: Always test these configurations in a sandbox cluster first. Never apply restrictive policies to a production cluster without a rollback strategy, as legitimate applications might require temporary exceptions during migration.
Step 2: Enabling the Pod Security Admission Add-on
The most straightforward method to enable restricted profiles on EKS is via the AWS Console or CLI using the aws eks update-kubeconfig and specific add-on commands. However, the modern approach involves upgrading the control plane version which triggers a prompt for setting the default enforcement action.
If you are managing the cluster manually or using Terraform, you might apply a ConfigMap to define the PSA settings:
apiVersion: v1
kind: ConfigMap
metadata:
name: pod-security-admission-config
namespace: kube-system
data:
default-enforcement-action: Enforce
restricted-default-enforcement-action: Enforce
baseline-default-enforcement-action: Audit
Apply this configuration using kubectl apply -f <configmap-file>.yaml. This tells the cluster to reject any new pods that do not comply with the restricted profile immediately.
Step 3: Verifying Policy Application and Expected Results
Once the ConfigMap is applied, you must verify that the admission controller is active. Attempt to deploy a standard insecure pod, such as one running as root or in privileged mode.
Expected Result:
When you run kubectl apply -f insecure-pod.yaml, you should see an error message indicating that the pod violates the restricted profile. The output will typically look like this:
Error from server (Forbidden): admission webhook "validation.webhook.k8s.aws" denied the request: validation failed: [containers[0].securityContext.runAsNonRoot is false, containers[0].securityContext.privileged is true]
This confirms that the cluster is now blocking insecure configurations. If you attempt to deploy a compliant pod (running as a non-root user with no host path mounts), the deployment should succeed without errors.
Common Mistakes and Troubleshooting in Lab Environments
When configuring restricted profiles, several common pitfalls can derail your implementation. One frequent mistake among junior engineers is failing to update existing deployments. If you enable Enforce mode on an existing cluster, new pods will be blocked, but old pods might continue running with insecure configurations until they are restarted or deleted.
Fix: Always schedule a maintenance window to restart all workloads after enabling restricted policies. Ensure your CI/CD pipelines (like those using Jenkins, GitLab CI, or GitHub Actions) have been updated to generate compliant manifests. If your pipeline tries to push an image that runs as root by default, the deployment will fail at the admission layer.
Another common error involves legacy applications that require specific Linux capabilities. Instead of disabling the policy and reverting to baseline, investigate if the application can be refactored to run without those capabilities. If not, you may need to define a custom Exemption in your PSA configuration to allow specific namespaces or labels to bypass restrictions temporarily.
Industry Application: Cost Controls and Security Compliance
Implementing restricted profiles is not just about security; it also aids in cost control and compliance. Insecure containers often require larger resource allocations due to the overhead of running as root or accessing unnecessary host resources. By enforcing strict isolation, you can optimize resource usage. Furthermore, many regulatory frameworks (such as PCI-DSS or HIPAA) mandate container hardening.
A realistic industry scenario involves a financial services firm migrating its legacy on-premise applications to EKS. The security team mandates that all new pods must adhere to the restricted profile. By automating this via admission controllers, the team ensures that no developer can accidentally deploy an insecure workload, reducing the risk of data breaches and avoiding costly compliance audits.
Student Practice Task: Securing a Sample Deployment
To solidify your understanding, try the following exercise in your local lab environment:
- Create a
Deploymentmanifest for a simple web server (e.g., Nginx). - Modify the manifest to explicitly set
securityContext.runAsNonRoot: trueand specify a non-root user ID (e.g., 1000). - Remove any
hostPathvolume mounts. - Apply the configuration to your EKS test cluster.
- Observe the logs of the admission webhook to see it validate your request before allowing the pod to schedule.
By completing this task, you gain hands-on experience with the nuances of Kubernetes security policies, preparing you for real-world infrastructure roles where safety and compliance are non-negotiable.
Educational-use notice: This tutorial is for learning and controlled lab use only. Test carefully, use backups, and obtain authorization before making changes. Do not run unfamiliar commands on production systems. We accept no responsibility for misuse, damage, data loss, or production issues.

