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

[Bug] OpenShift OAuth Proxy can't run in default namespace #969

Closed
ebaron opened this issue Nov 5, 2024 · 9 comments
Closed

[Bug] OpenShift OAuth Proxy can't run in default namespace #969

ebaron opened this issue Nov 5, 2024 · 9 comments
Labels
bug Something isn't working

Comments

@ebaron
Copy link
Member

ebaron commented Nov 5, 2024

I believe this happens because the default namespace doesn't use SecurityContextConstraints. A fix would be adding something like USER 1001 to the Containerfile.

  Warning  Failed                  3m30s                  kubelet                  Error: container has runAsNonRoot and image will run as root (pod: "cryostat-sample-6769cdb9c9-m8ldf_default(c975eee4-58e8-4643-b5a6-ae0d2c343270)", container: cryostat-sample-auth-proxy)
@ebaron ebaron added the bug Something isn't working label Nov 5, 2024
@tthvo
Copy link
Member

tthvo commented Nov 5, 2024

I guess after this is resolved, we can also remove the note here about setting runAsUser in default namespace (i.e. The oauth2-proxy container image also has USER set):

https://github.com/cryostatio/cryostat-helm/blob/5bda8443d8a41b8f259aae607e88054edce92992/charts/cryostat/values.yaml#L276

@ebaron
Copy link
Member Author

ebaron commented Nov 6, 2024

I guess after this is resolved, we can also remove the note here about setting runAsUser in default namespace (i.e. The oauth2-proxy container image also has USER set):

https://github.com/cryostatio/cryostat-helm/blob/5bda8443d8a41b8f259aae607e88054edce92992/charts/cryostat/values.yaml#L276

Indeed! I missed that comment initially.

@andrewazores
Copy link
Member

https://github.com/oauth2-proxy/oauth2-proxy/blob/master/Dockerfile

          "User": "",

It looks like the oauth2-proxy does not have USER set. Since we're already maintaining a small fork of the OpenShift OAuth Proxy I think it makes sense that we can set the USER in our downstream Containerfile, but it doesn't look like we are in a position to do the same thing for the oauth2-proxy.

@ebaron
Copy link
Member Author

ebaron commented Nov 6, 2024

https://github.com/oauth2-proxy/oauth2-proxy/blob/master/Dockerfile

          "User": "",

It looks like the oauth2-proxy does not have USER set. Since we're already maintaining a small fork of the OpenShift OAuth Proxy I think it makes sense that we can set the USER in our downstream Containerfile, but it doesn't look like we are in a position to do the same thing for the oauth2-proxy.

I suppose that's okay as we allow users to set a UID in the container's security context through the CRD. I think that's the only way this container will work in Kubernetes in a namespace with the restricted pod security level. It would be ideal if both images had explicit USER directives though so this extra step for users isn't needed.

@tthvo
Copy link
Member

tthvo commented Nov 6, 2024

https://github.com/oauth2-proxy/oauth2-proxy/blob/master/Dockerfile

          "User": "",

It looks like the oauth2-proxy does not have USER set. Since we're already maintaining a small fork of the OpenShift OAuth Proxy I think it makes sense that we can set the USER in our downstream Containerfile, but it doesn't look like we are in a position to do the same thing for the oauth2-proxy.

I wonder if the oauth2-proxy on Quay is built differently than that Dockerfile above? I am inspecting the quay.io/oauth2-proxy/oauth2-proxy:latest and it seems it has set the user to 65532?

podman inspect quay.io/oauth2-proxy/oauth2-proxy | jq .[].User
"65532"

@andrewazores
Copy link
Member

Ah, I was inspecting a different tag: latest-alpine instead of just alpine. So I guess the oauth2-proxy does run as-is in the default namespace, without any customizations to its securityContext?

@tthvo
Copy link
Member

tthvo commented Nov 6, 2024

Oh actually, the USER is set from the base image that they use: gcr.io/distroless/static:nonroot.

@tthvo
Copy link
Member

tthvo commented Nov 6, 2024

Ah, I was inspecting a different tag: latest-alpine instead of just alpine. So I guess the oauth2-proxy does run as-is in the default namespace, without any customizations to its securityContext?

Oh yep, I just did a quick test and it seems to run without issue^^ Probably need a double check :D

@ebaron
Copy link
Member Author

ebaron commented Nov 6, 2024

I suppose one cool way we know this works is our Scorecard tests running in CI. The namespace is labeled as restricted pod security level:

$(CLUSTER_CLIENT) label --overwrite namespace $(SCORECARD_NAMESPACE) pod-security.kubernetes.io/warn=restricted pod-security.kubernetes.io/audit=restricted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

No branches or pull requests

3 participants