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

Unable to run gcloud commands with non-root container user #48

Open
hinewin opened this issue Mar 19, 2024 · 7 comments
Open

Unable to run gcloud commands with non-root container user #48

hinewin opened this issue Mar 19, 2024 · 7 comments

Comments

@hinewin
Copy link

hinewin commented Mar 19, 2024

I'm experiencing an issue while attempting to execute gcloud commands with a non root container user. The issue appears to stem from restricted access to /var/run/secrets/sts.googleapis.com/serviceaccount/..data/token. This particular path needs to be accessible for gcloud commands to function properly. The problem persists even when I include the annotation cloud.google.com/gcloud-run-as-user in the service account.

@ordovicia
Copy link
Contributor

Cloud you please share the details of your gcp-workload-identity-federation-webhook deployment (version, args, etc.) and ServiceAccounts and pods with which you are experiencing the issue, so that we can try to reproduce it?

@hinewin
Copy link
Author

hinewin commented Mar 26, 2024

Webhook's version: 0.4.1
I've verified the workload identity pool and provider are working properly and was able to access resources with a container that runs as root.
Using the same working pool, provider and GSA, I've created a new KSA to support running a pod with a non-root container user and verified the correct ID for the non-root user.

Below is the KSA & Pod manifest file

# GSA has access to bucket `foo-gcs` and can read the secret file
# gcloud storage cat gs://foo-gcs/secret
# KSA Manifest
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: sa-foo
  namespace: default
  labels:
    app: wif-bar
  annotations:
    cloud.google.com/workload-identity-provider: "correct-identity-provider"
    cloud.google.com/service-account-email: "[email protected]"
    cloud.google.com/audience: "correct-audience"
    cloud.google.com/injection-mode: "gcloud"
    cloud.google.com/gcloud-run-as-user: "1001"


# Pod Manifest
---
apiVersion: v1
kind: Pod
metadata:
  name: sa-foo
  namespace: default
  labels:
    app: wif-bar
spec:
  serviceAccountName: sa-foo
  containers:
  - name: gcloud-kubectl
    image: foobar-image-with-non-root-user
    command: ["/bin/sh"]
    args: ["-c", "gcloud storage cat gs://foo-gcs/secret && while true; do echo 'keep alive'; sleep 10; done"]

logs from the following container return:

ERROR: gcloud crashed (PermissionError):   [Errno 13]  Permission denied: '/var/run/secrets/sts.googleapis.com/serviceacount/token'

@hinewin
Copy link
Author

hinewin commented Apr 8, 2024

Hi, I would like to check in on this issue. I am currently still unable to run non-root containers using this webhook.

@ordovicia
Copy link
Contributor

Sorry for late response.

logs from the following container return:

ERROR: gcloud crashed (PermissionError):   [Errno 13]  Permission denied: '/var/run/secrets/sts.googleapis.com/serviceacount/token'

What is the container's UID?
I guess setting cloud.google.com/gcloud-run-as-user annotation value to the UID might work.

@hinewin
Copy link
Author

hinewin commented Apr 9, 2024

Thanks for your respond @ordovicia , I've already included the correct UID for the container in the above manifest cloud.google.com/gcloud-run-as-user: "1001" but the issue persists ):
Are you able to reproduce?

@hinewin
Copy link
Author

hinewin commented Apr 18, 2024

Hello, just a friendly nudge on this topic. Are you able to find any further details regarding this problem?

@hinewin
Copy link
Author

hinewin commented May 28, 2024

Just checking in to see if theres any update on this?

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

2 participants