Search code examples
dockersecuritygoogle-cloud-platformgoogle-compute-enginegoogle-cloud-run

When you assign service account to a Cloud Run service, what does exactly happen?


I am trying to understand what does assigning service account to a Cloud Run service actually do in order to improve the security of the containers. I have multiple processes running within a Cloud Run service and not all of them do need to access the project resources.

A more specific question I have in mind is: Would I be able to create multiple users and run some processes as a user that does not have access to the service account or does every user have access to the service account?

I run a small experiment on a VM instance (I guess this will be a similar case as with Cloud Run) where I created a new user and after creation, it wasn't authorized to use the service account of the instance. However, I am not sure is there a way to authorize it which would make my method insecure.

Thank you.

EDIT

To perform the test I created a new os user and used "gcloud auth list" from the new user account. However, I should have made a curl request and I would have been able to retrieve credentials as pointed out by an answer below.


Solution

  • Your question is not very clear to me but I will try to provide you several inputs.

    When you run a service on Cloud Run, you have 2 choices for defining its identity

    • Either it's the compute engine service account which is used (by default, is you specify nothing)
    • Or it's the service account that you specify at the deployment

    This service account is valid for the Cloud Run service (you can have up to 1000 different services per project).

    Now, when you run your container, the service account is not really loaded into the container (it's the same thing with compute engine), but there is an API available for requesting the authentication data of this service account. It's name metadata server

    It's not restricted to users (I don't know how you perform your test on Compute Engine!), a simple curl is enough for getting the data.

    This metadata server is used when you use your libraries, for example, and you use the "default credentials". gcloud SDK also uses it.

    I hope you have a better view now. If not, add details in your question or in the comments.