aster.cloud aster.cloud
  • /
  • Platforms
    • Public Cloud
    • On-Premise
    • Hybrid Cloud
    • Data
  • Architecture
    • Design
    • Solutions
    • Enterprise
  • Engineering
    • Automation
    • Software Engineering
    • Project Management
    • DevOps
  • Programming
    • Learning
  • Tools
  • About
  • /
  • Platforms
    • Public Cloud
    • On-Premise
    • Hybrid Cloud
    • Data
  • Architecture
    • Design
    • Solutions
    • Enterprise
  • Engineering
    • Automation
    • Software Engineering
    • Project Management
    • DevOps
  • Programming
    • Learning
  • Tools
  • About
aster.cloud aster.cloud
  • /
  • Platforms
    • Public Cloud
    • On-Premise
    • Hybrid Cloud
    • Data
  • Architecture
    • Design
    • Solutions
    • Enterprise
  • Engineering
    • Automation
    • Software Engineering
    • Project Management
    • DevOps
  • Programming
    • Learning
  • Tools
  • About
  • Programming

How To Secure Kubernetes Pods Post-PSPs Deprecation

  • aster.cloud
  • July 1, 2022
  • 6 minute read

Kubernetes pods are the basic building blocks of Kubernetes. It’s managing one or more tightly coupled application containers allowing them to share resources and networks. Pods are hosted on nodes, which are either physical or virtual machines.

When defining a Pod we need to think not only about how much CPU or memory we want to assign to it but also about what would be the interaction between it and the underlying infrastructure. For example, we can allow a Pod to access all devices on the host, which might be a potential threat if someone gets inside of it.


Partner with aster.cloud
for your next big idea.
Let us know here.



From our partners:

CITI.IO :: Business. Institutions. Society. Global Political Economy.
CYBERPOGO.COM :: For the Arts, Sciences, and Technology.
DADAHACKS.COM :: Parenting For The Rest Of Us.
ZEDISTA.COM :: Entertainment. Sports. Culture. Escape.
TAKUMAKU.COM :: For The Hearth And Home.
ASTER.CLOUD :: From The Cloud And Beyond.
LIWAIWAI.COM :: Intelligence, Inside and Outside.
GLOBALCLOUDPLATFORMS.COM :: For The World's Computing Needs.
FIREGULAMAN.COM :: For The Fire In The Belly Of The Coder.
ASTERCASTER.COM :: Supra Astra. Beyond The Stars.
BARTDAY.COM :: Prosperity For Everyone.

That’s why it’s very important to secure pods to prevent that from happening.

In this blog, we will review ways to secure Pods, especially in light of the decision to deprecate PSPs in V1.25

Kubernetes Security

By default, nothing is protected in Kubernetes. This means we can create workloads capable of accessing the underlying infrastructure, posing a potential threat. There are several takes on this problem. We can limit access to clusters by introducing RBAC. When creating Pods, we can specify what capabilities they will have by setting permissions with a Pod security context. But this doesn’t cover everything.

Cluster admins want to enforce developers to create workloads with the lowest privileges possible. If developers happen to be aware that running a container in a Pod as root is a bad idea, those admins have an easy job. But this is often not the case. Many times, they either don’t know all the potential threats or forget about a proper security configuration. People make mistakes—this is normal.

Pod Security Policies

To prevent issues from happening, the Kubernetes community introduced a built-in mechanism called a Pod Security Policy (PSP). On a cluster level, we can create a list of rules that new Pods need to meet to be accepted

Here is a simple example of PSP definition:

<span class="token literal-property property">apiVersion</span><span class="token operator">:</span> policy<span class="token operator">/</span>v1beta1
<span class="token literal-property property">kind</span><span class="token operator">:</span> PodSecurityPolicy
<span class="token literal-property property">metadata</span><span class="token operator">:</span>
  <span class="token literal-property property">name</span><span class="token operator">:</span> simple<span class="token operator">-</span>policy
<span class="token literal-property property">spec</span><span class="token operator">:</span>
  <span class="token literal-property property">privileged</span><span class="token operator">:</span> <span class="token boolean">false</span>
  <span class="token literal-property property">runAsUser</span><span class="token operator">:</span>
    <span class="token literal-property property">rule</span><span class="token operator">:</span> MustRunAsNonRoot
  <span class="token literal-property property">readOnlyRootFilesystem</span><span class="token operator">:</span> <span class="token boolean">true</span>

With that, three rules are being enforced:

  • Disallow a container to run in a privileged mode
  • Disallow processes to run in a container as a root user
  • Disable making writes to a container file system.
Read More  Strengthening Supply Chain Security With Zero Trust Architecture

These are not the only policies that we can choose from. There are plenty of them! All of them are listed in the official Kubernetes documentation.

Unfortunately, there are issues with PSPs themselves. The main problem is that they’re not intuitive to use. All policies need to be bonded both to the users (who create pods directly) and service accounts (like ReplicaSet). This needs to be remembered all the time, but it’s easy to forget. Moreover, a PSP is applied to pods only. It can’t be applied to a deployment, which means that nothing will prevent it from creating it. The resulting Pod may still not be created, but it could be hard to audit why it failed.

Finally, introducing a PSP to an already-running cluster is very challenging. All policies need to be created before enforcing a validation; and, in a huge system, it can be very tricky to figure out which permissions are required by all workloads. Even more of a headache is that PSPs do not apply to already-running pods, so you might only find a potential misconfiguration later on.

All of these things made the Kubernetes team decide to deprecate PSPs and remove them starting from v1.25 That’s why you need to use other ways and tools to reach the same goal.

Pod Security Standards

After deprecating PSP, Kubernetes developers decided to take a different approach to security. Instead of plenty of fine-grained policies that can be combined, there are three standards from which we can choose: privileged, baseline, and restricted.

Privileged

This is an unrestricted policy without any rules. Users or service accounts can create any pod with special privileges. This is a good option when there is no need to be concerned about security at all (e.g., for local development). Also, you can use it for special applications that require modifying something on a host. You should limit the use of these policies to an absolute minimum—only when there is no other way—and treat them with extra caution.

Baseline

This provides a basic set of rules, as it prevents you from sharing a host namespace or running harmful Linux capabilities. It’s a middle ground between the previous and next, highly secured, policy. It should be applied when you are concerned about potential threats, but not yet ready for full protection. You can use these, for example, for less exposed environments (like test environments). A list of permissions that this policy includes can be found in the official documentation.

Read More  Kubernetes Resource Usage: Estimate Workload Cost With Goldilocks Open Source

Restricted

This contains all rules from the previous policy and adds, even more, to provide for best practices in pod hardening, for example, restricting you from running applications as a root. It’s targeted to be applied to all critical applications that are running in production systems. Similar to the previous policy, all details about it can be found in the official documentation.

These are the only options we have to choose from, but they cover most real-life scenarios.

Pod Security Admission

Whenever a modifying kubectl command is run, a Kubernetes API server first needs to validate if it can be applied. This mechanism is called an admission controller, and it’s checked after successful authorization. By default, each Kubernetes cluster has a couple of them turned on. They fulfill tasks such as removing all workloads in the case of a namespace deletion.

The one used to enforce policies defined in the PSS is called Pod Security Admission (PSA).

Enabling it is very easy. The only thing you need to do is add the pod-security.kubernetes.io/<mode>=<standard> label to a namespace. The<mode> defines what action will be applied if a policy is violated:

  • Enforce – A pod will not be created if it violates a policy.
  • Audit – A pod will be created, but an entry will be added to an audit log.
  • Warn – A pod will be created, but a warning will be printed in the console.

The best way to start working with PSA is not to use the restricted policy with the enforce label at the beginning. Probably many already-existing pods would violate this standard, so it’s better to start with only logging and warning users. This allows time for you to transition to more secure workload definitions.

Let’s assume there is already a production namespace we want to apply:kubectl label –overwrite ns production \ pod-security.kubernetes.io/enforce=baseline \ pod-security.kubernetes.io/warn=restricted \ pod-security.kubernetes.io/audit=restricted

For the privileged policy, we would use the privileged value.

Now, if we try to install any application that violates the restricted policy (here, it’s installed with the popular tool Helm):

helm install postgres bitnami<span class="token operator">/</span>postgresql <span class="token operator">-</span>n production <span class="token operator">--</span>version <span class="token number">11.1</span><span class="token number">.28</span> <span class="token operator">--</span>wait

The output we get is:

<span class="token constant">W0509</span> <span class="token number">06</span><span class="token operator">:</span><span class="token number">53</span><span class="token operator">:</span><span class="token number">32.784714</span>    <span class="token number">5472</span> warnings<span class="token punctuation">.</span>go<span class="token operator">:</span><span class="token number">70</span><span class="token punctuation">]</span> would violate PodSecurity <span class="token string">"restricted:latest"</span><span class="token operator">:</span> allowPrivilegeEscalation <span class="token operator">!=</span> <span class="token boolean">false</span> <span class="token punctuation">(</span>container <span class="token string">"postgresql"</span> must <span class="token keyword">set</span> securityContext<span class="token punctuation">.</span>allowPrivilegeEscalation<span class="token operator">=</span><span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">,</span> unrestricted <span class="token function">capabilities</span> <span class="token punctuation">(</span>container <span class="token string">"postgresql"</span> must <span class="token keyword">set</span> securityContext<span class="token punctuation">.</span>capabilities<span class="token punctuation">.</span>drop<span class="token operator">=</span><span class="token punctuation">[</span><span class="token string">"ALL"</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">,</span> runAsNonRoot <span class="token operator">!=</span> <span class="token boolean">true</span> <span class="token punctuation">(</span>pod or container <span class="token string">"postgresql"</span> must <span class="token keyword">set</span> securityContext<span class="token punctuation">.</span>runAsNonRoot<span class="token operator">=</span><span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token function">seccompProfile</span> <span class="token punctuation">(</span>pod or container <span class="token string">"postgresql"</span> must <span class="token keyword">set</span> securityContext<span class="token punctuation">.</span>seccompProfile<span class="token punctuation">.</span>type to <span class="token string">"RuntimeDefault"</span> or <span class="token string">"Localhost"</span><span class="token punctuation">)</span>

This is the first downside of using PSA. It’s still not a widespread mechanism, since it’s a beta, and even popular Helm Charts don’t yet comply with it out of the box.

Read More  Google Cloud Next 2019 | Target's Application Platform (TAP)

There is yet another problem, this time inherited from PSP. Standards are applied only for pods, and if we create them via deployment (which is done in most cases), PSA won’t prevent it from happening. Pods won’t be created, but there will be no immediate feedback.

Finally, PSP does not allow for the creation of custom policies. In some cases, it’s OK to use the restricted standard, apart from maybe two or three rules. In such a situation, there is no real alternative in PSA, apart from changing a standard to being less restrictive.

Alternatives

Pod Security Admission is a Kubernetes built-in response to PSP deprecation. There are, however, other options. Some solutions, like Open Policy Agent (OPA) and Keyverno, allow for writing policies and enforcing them via custom admission controllers.

OPA’s greatest strength is its flexibility, but this is also its greatest weakness. Using Rego language, we can declare any policy we want. However, it requires learning a new language or maintaining policies, and this complexity might not be desirable in some cases.

A middle-ground solution would be to use a scanning solution, which added to a CI/CD pipeline would quickly find potential security vulnerabilities. One of them is Kubescape.

 

 

Guest post originally published on the ARMO blog by Amir Kaushansky
By Amir Kaushansky
Source CNCF


For enquiries, product placements, sponsorships, and collaborations, connect with us at [email protected]. We'd love to hear from you!

Our humans need coffee too! Your support is highly appreciated, thank you!

aster.cloud

Related Topics
  • CNCF
  • CNF
  • Kubernetes
  • Kubernetes Pods
  • Kubescape
You May Also Like
View Post
  • Architecture
  • Data
  • Engineering
  • People
  • Programming
  • Software Engineering
  • Technology
  • Work & Jobs

Predictions: Top 25 Careers Likely In High Demand In The Future

  • June 6, 2023
View Post
  • Programming
  • Software Engineering
  • Technology

Build a Python App to Alert You When Asteroids Are Close to Earth

  • May 22, 2023
View Post
  • Programming

Illuminating Interactions: Visual State In Jetpack Compose

  • May 20, 2023
View Post
  • Computing
  • Data
  • Programming
  • Software
  • Software Engineering

The Top 10 Data Interchange Or Data Exchange Format Used Today

  • May 11, 2023
View Post
  • Architecture
  • Programming
  • Public Cloud

From Receipts To Riches: Save Money W/ Google Cloud & Supermarket Bills – Part 1

  • May 8, 2023
View Post
  • Programming
  • Public Cloud

3 New Ways To Authorize Users To Your Private Workloads On Cloud Run

  • May 4, 2023
View Post
  • Programming
  • Public Cloud

Buffer HTTP Requests With Cloud Tasks

  • May 4, 2023
View Post
  • Programming
  • Public Cloud
  • Software
  • Software Engineering

Learn About Google Cloud’s Updated Renderer For The Maps SDK For Android

  • May 4, 2023

Stay Connected!
LATEST
  • 1
    Advanced audio dialog and generation with Gemini 2.5
    • June 15, 2025
  • 2
    A Father’s Day Gift for Every Pop and Papa
    • June 13, 2025
  • 3
    Global cloud spending might be booming, but AWS is trailing Microsoft and Google
    • June 13, 2025
  • Google Cloud, Cloudflare struck by widespread outages
    • June 12, 2025
  • What is PC as a service (PCaaS)?
    • June 12, 2025
  • 6
    Apple services deliver powerful features and intelligent updates to users this autumn
    • June 11, 2025
  • By the numbers: Use AI to fill the IT skills gap
    • June 11, 2025
  • 8
    Crayon targets mid-market gains with expanded Google Cloud partnership
    • June 10, 2025
  • Apple-WWDC25-Apple-Intelligence-hero-250609 9
    Apple Intelligence gets even more powerful with new capabilities across Apple devices
    • June 9, 2025
  • Apple-WWDC25-Liquid-Glass-hero-250609_big.jpg.large_2x 10
    Apple introduces a delightful and elegant new software design
    • June 9, 2025
about
Hello World!

We are aster.cloud. We’re created by programmers for programmers.

Our site aims to provide guides, programming tips, reviews, and interesting materials for tech people and those who want to learn in general.

We would like to hear from you.

If you have any feedback, enquiries, or sponsorship request, kindly reach out to us at:

[email protected]
Most Popular
  • 1
    Apple supercharges its tools and technologies for developers to foster creativity, innovation, and design
    • June 9, 2025
  • Robot giving light bulb to businessman. Man sitting with laptop on money coins flat vector illustration. Finance, help of artificial intelligence concept for banner, website design or landing web page 2
    FinOps X 2025: IT cost management evolves for AI, cloud
    • June 9, 2025
  • 3
    AI security and compliance concerns are driving a private cloud boom
    • June 9, 2025
  • 4
    It’s time to stop debating whether AI is genuinely intelligent and focus on making it work for society
    • June 8, 2025
  • person-working-html-computer 5
    8 benefits of AI as a service
    • June 6, 2025
  • /
  • Technology
  • Tools
  • About
  • Contact Us

Input your search keywords and press Enter.