Conventions for separating gcloud and ADC authentication per repo. Apply them after understanding the reasons. Enabling GCP APIs is in kstack-gcp-service-usage, and how to write tasks is in kstack-mise-tasks .
Separate the location of authentication per repo, and point both CLOUDSDK_CONFIG and GOOGLE_APPLICATION_CREDENTIALS to it
For repos that use gcloud (in a monorepo, the directory that handles GCP), point mise.toml の [env] で、CLOUDSDK_CONFIG to a repo-dedicated directory, and pointGOOGLE_APPLICATION_CREDENTIALS to the application_default_credentials.json of that directory. Place the directory outside the repo (~/.config/gcloud-<名前>), and do not put credentials in the working tree.
# Bad: CLOUDSDK_CONFIG だけを分ける(Terraform の google provider は共有の ~/.config/gcloud の ADC を読む)
[env]
CLOUDSDK_CONFIG = "{{env.HOME}}/.config/gcloud-acme"
# Good
[env]
CLOUDSDK_CONFIG = "{{env.HOME}}/.config/gcloud-acme"
GOOGLE_APPLICATION_CREDENTIALS = "{{env.HOME}}/.config/gcloud-acme/application_default_credentials.json"
Why: The default ~/.config/gcloud is one per machine, so logging in on one repo overwrites the authentication of sessions in other repos running with a different account. Some ADC readers do not look at CLOUDSDK_CONFIG (Terraform's google provider and the Go and Node client libraries search in the order of GOOGLE_APPLICATION_CREDENTIALS, the default ~/.config/gcloud, and the metadata server), so also pointGOOGLE_APPLICATION_CREDENTIALS so that every reader reads the same file.
Run login as a mise task, and obtain both the gcloud CLI and ADC
login は [env] Run it as a task that receives env from the same settings as gcloud auth login・gcloud auth application-default login , and do not type kstack-mise-tasks in a bare shell. gcloud CLI authentication and ADC are different things, so obtain both in the task. The task location and invocation method follow .config/mise/tasks/ (for a repo root, place it in mise run loginand run [env] ; for a monorepo config root, place it in the same mise.toml and run it from the repo root with mise run //<path>:login)。
# Good: infra/gcp/mise.toml
[tasks.login]
description = "Log in gcloud CLI and ADC for this repo"
interactive = true
run = [
"gcloud auth login",
"gcloud auth application-default login",
]
Bad: env が効いていない shell で gcloud auth application-default login を実行する / 上書きした ADC を mv して戻そうとする
Good: mise run //infra/gcp:login を実行し、gcloud auth list と ADC のアカウントを確かめてから apply する
Why: Running it in a place where env is not in effect writes to the shared ~/.config/gcloud and breaks the authentication of other repos. A mise task receives the [env] of its config root no matter which directory it is invoked from.gcloud services enable use CLI authentication, while providers and client libraries use ADC, so doing only one of them will fail partway through.