Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we run kong with non root privileges? #4102

Closed
smartaquarius10 opened this issue May 29, 2023 · 1 comment
Closed

Can we run kong with non root privileges? #4102

smartaquarius10 opened this issue May 29, 2023 · 1 comment
Milestone

Comments

@smartaquarius10
Copy link

Hello,

We ran dry run of pod security admission(pod-security.kubernetes.io/enforce=restricted) on kong and received this warning

Warning: allowPrivilegeEscalation != false, unrestricted capabilities, runAsNonRoot != true, seccompProfile

Is it mandatory to keep it as is or we can run it with non root privileges. Does this impact the kong behavior.

@rainest
Copy link
Contributor

rainest commented Oct 10, 2023

Running as non-root is fine. All official images use a kong user that isn't root.

The chart has the ability to set Pod and container security contexts, but currently only does so for read-only root filesystems. In general, applying the context required for restricted to containers (it doesn't appear we need anything for Pods) is fine:

diff --git a/charts/kong/values.yaml b/charts/kong/values.yaml
index 676df7f..115c73b 100644
--- a/charts/kong/values.yaml
+++ b/charts/kong/values.yaml
@@ -948,6 +948,14 @@ securityContext: {}
 # securityContext for containers.
 containerSecurityContext:
   readOnlyRootFilesystem: true
+  allowPrivilegeEscalation: false
+  runAsUser: 1000
+  runAsNonRoot: true
+  seccompProfile:
+    type: RuntimeDefault
+  capabilities:
+    drop:
+    - ALL

Although not exhaustively tested, the default configuration comes online with these restrictions, and I don't have reason to expect other configurations would break with those restrictions.

The runAsUser: 1000 bit is necessary and a bit of a problem. Kubernetes has no means if determining if a named user is not UID 0 and requires a numeric UID. AFAIK we use the same user creation script for all distribution packages, and the lack of a UID there means the actual UID isn't guaranteed. It will vary depending on the distribution's configuration for new the starting UID for non-stock users.

There's some gateway scaffolding code that suggests we do enforce a consistent UID, but I'm not familiar enough with the gateway image build process to confirm that is definitely the case.

This security context is also applied across all our containers equally. The controller does not use UID 1000 (although it appears it sometimes did in the past? git blame isn't helping me figure out the history, but some iterations of the Dockerfile use 1000) although this does not appear to be an issue, as it doesn't interact with any files other than the single, world-executable (AFAIK) binary.

As a side note, this is not the case for our Kuma mesh by default (it requires root to do some iptables manipulation), but that can be sequestered in a dedicated iptables management deployment in a special namespace so that the sidecars do not need it in other namespaces.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants