DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Kubernetes Security: 10 Best Practices From the Industry and Community

Kubernetes Security: 10 Best Practices From the Industry and Community

One of the best ways to tighten your Kubernetes security is by implementing ten tactics that have become industry standard.

Olesia Pozdniakova user avatar by
Olesia Pozdniakova
·
Oct. 04, 22 · Opinion
Like (1)
Save
Tweet
Share
3.34K Views

Join the DZone community and get the full member experience.

Join For Free

Kubernetes requires extensive configuration, and keeping container security at the right level is always challenging. One of the best ways to tighten your clusters’ security is by implementing tactics that have become industry standard. Here are the 10 most important ones.

10 Best Practices for Kubernetes Security

1. Don’t Keep Secrets in an Environment Variable

It’s a good practice to have your objects use a secret in an environment variable since other parts of your system can access environment variables. That’s why it’s best to use secrets as files or take advantage of a secretKeyRef to minimize potential attacks.

2. Use Strong Kubernetes Authentication and Authorization

Integrating Kubernetes with a third-party authentication provider is smart, as it delivers extra security features like multi-factor authentication. Avoid managing users at the API server level to make access to the control plane more secure. Use Identity and Access Management (IAM) solution from the cloud service provider if you’re running a managed Kubernetes service like EKS, GKE, AKS, or similar. Go for OpenID Connect (OIDC) alongside an SSO provider you got used to if CSP IAM isn’t an option.  

3. Disable the NET_RAW Capability

If your K8s containers don’t drop the NET_RAW capability, you risk enabling a wide range of networking exploits from within the cluster. It’s best to use Policy Enforcement solutions like Open Policy Agents, Kyverno, or Kubernetes Pod Security admission controller to ensure you are following best practices. Use drop for ALL or NET_RAW capabilities in the pod’s securityContext definition to ensure that the NET_RAW capability is disabled.

4. Avoid Sharing the Host’s IPC or Network Namespace 

Check if your pods are sharing the host’s IPC or network namespace. Sharing namespaces for pod and host interprocess communication may lead to opening access to shared information. Pods should not be allowed access to the host namespaces. 

And sharing pod and host network namespaces enables network access to the host network from the pod, which breaks network isolation. That’s why you better set the hostNetwork parameter to false in PodSecurityPolicy.

5. Use Kubernetes Role-Based Access Control (RBAC)

RBAC helps to define who has access to the Kubernetes API and on what permissions. In Kubernetes 1.6 and higher, RBAC is usually enabled by default. Since Kubernetes combines authorization controllers, make sure to disable the legacy Attribute Based Access Control (ABAC) when enabling RBAC.

Pick namespace-specific permissions over cluster-wide permissions. Even when debugging, don’t grant cluster administrator privileges. Otherwise, your container security may be compromised.

6. Avoid Usage of Root File System for Container Security

Are your containers running without a read-only root file system? Using a read-only file system prevents malicious binaries from writing to a system or a system takeover by attackers. You can ensure that containers use only the read-only file system by setting readOnlyRootFilesystem to true in Pod securityContext definition. 

7. Isolate Your Kubernetes Nodes

Kubernetes nodes should never be exposed directly to public networks. Ideally, these nodes are located on a separate network and – if possible – without any direct connections to the general corporate network. 

You can achieve this by keeping Kubernetes control and data traffic isolated. Otherwise, they both flow through the same pipe. Open access to the data plane means that access is open to the control plane as well. Configure nodes with an ingress controller and set it to only allow connections from the master node via the specified port through the network access control list (ACL).

8. Avoid Running Containers in Privileged Mode

Does your deployment have containers running in privileged (root) mode? This allows the container to gain access to critical resources of the host. Avoid running containers in privileged mode or enable the podSecurityPolicy with the privileged parameter set to false. This will ensure that containers can’t run processes that require root privileges on the host.

9. Check for Unsafe /Proc Mount

Deployments with unsafe /proc mount (procMount=Unmasked) will allow bypassing the default masking behavior of the container runtime. Setting a container with an Unmasked /proc mount type can potentially expose the host information to the container and, as a result, cause a potential information leakage or container escape. Set procMount=Default to ensure the container doesn’t unsafely expose any parts of /proc.

10. Have a Rolling Update Strategy

Another smart move is developing a rolling update strategy. Rolling updates allow deployment updates to minimize your application downtime by incrementally updating pod instances with new ones. See this page in the Kubernetes docs for more details.

Achieving Kubernetes Security Is Challenging

The Kubernetes ecosystem is constantly changing – and so are its security and configuration parts. Keeping up with these changes takes time and effort, stealing away engineers from other tasks and screaming for their attention.

Another challenge teams experience around Kubernetes security is the prioritization of security issues – depending on the application’s size, prioritizing issues may become time-consuming.

But automation is here to change that. 

Kubernetes security

Published at DZone with permission of Olesia Pozdniakova. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • 5 Steps for Getting Started in Deep Learning
  • OpenVPN With Radius and Multi-Factor Authentication
  • Apache Kafka Is NOT Real Real-Time Data Streaming!
  • Public Key and Private Key Pairs: Know the Technical Difference

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: