Setting up authentication for Docker | Artifact Registry Documentation suggests that gcloud
is more secure than using a JSON file with credentials. I disagree. In fact I'll argue the exact opposite is true. What am I misunderstanding?
Setting up authentication for Docker | Artifact Registry Documentation says:
gcloud
as credential helper (Recommended)Configure your Artifact Registry credentials for use with Docker directly in gcloud. Use this method when possible for secure, short-lived access to your project resources. This option only supports Docker versions 18.03 or above.
followed by:
JSON key file
A user-managed key-pair that you can use as a credential for a service account. Because the credential is long-lived, it is the least secure option of all the available authentication methods
The JSON key file contains a private key and other goodies giving a hacker long-lived access. The keys to the kingdom. But only to the Artifact Repository in this instance, because the service account that the JSON file is for only has specifically those rights.
Now gcloud
has two auth options:
gcloud auth activate-service-account ACCOUNT --key-file=KEYFILE
gcloud auth login
Lets start with gcloud
and a service account: Here it stores KEYFILE
in unencrypted in ~/.config/gcloud/credentials.db
. Using the JSON file directly boils down docker login -u _json_key --password-stdin https://some.server < KEYFILE
which stores the KEYFILE
contents in ~/.docker/config.json
. So using gcloud
with a service account or just using the JSON file directly should be equivalent, security wise. They both store the same KEYFILE
unencrypted in a file.
gcloud auth login
requires login with a browser where I give consent to giving gcloud
access to my user account in its entirety. It is not limited to the Artifact Repository like the service account is. Looking with sqlite3 ~/.config/gcloud/credentials.db .dump
I can see that it stores an access_token
but also a refresh_token
. If the hacker has access to ~/.config/gcloud/credentials.db
with access and refresh tokens, doesn't he own the system just as much as if he had access to the JSON file? Actually, this is worse because my user account is not limited to just accessing the Artifact Registry - now the user has access to everything my user has access to.
So all in all: gcloud auth login
is at best security-wise equivalent to using the JSON file. But because the access is not limited to the Artifact Registry, it is in fact worse.
Do you disagree?