John Lee
09/23/2021, 10:12 AMfrom pathlib import Path
import tempfile
import os
import google.auth
creds = Path(tempfile.NamedTemporaryFile().name)
creds.write_text(os.environ["GOOGLE_APPLICATION_CREDENTIALS"])
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = str(creds)
google.auth.default()
Kevin Kho
Kevin Kho
Kevin Kho
GCP_CREDENTIALS
. It would only default to GOOGLE_APPLICATION_CREDENTIALS
is this is missing (lines 32-33 here). So if you provide the secret, I don’t think it should hit that, unless you use another client inside your script or maybe use your own GCP task?Kevin Kho
GCP_CREDENTIALS
and the GOOGLE_APPLICATION_CREDENTIALS
as a file, it does seem weird and I would honestly just go the GOOGLE_APPLICATION_CREDENTIALS
cuz all the Prefect code in the task library just uses the Google Client
anyway which will fall back to that. No sense to use both for sure.Vinicius Cerutti
09/23/2021, 9:14 PMPREFECT__CONTEXT__SECRETS__GCP_CREDENTIALS
variable is set in the helm chart for the kubernetes agent, does it need to be directly set in the agent start arg as well? (e.g prefect agent kubernets start -e PREFE...GCP_CREDENTIALS=$...
) or it will be directly recognized as a secret?Kevin Kho
--env PREFECT__CONTEXT__SECRETS__GCP_CREDENTIALS=….
?Vinicius Cerutti
09/23/2021, 9:15 PMVinicius Cerutti
09/23/2021, 9:20 PMcredentials = prefect.context.get("secrets", {}).get("GCP_CREDENTIALS")
inside the flow podKevin Kho
PREFECT___CONTEXT___…
are loaded into the context and the Secret will be held in the context. In general though, not all env variables are copied cover. Also, environment variables are not copied over to Dask workers, but the prefect context is. So if it is already in prefect.context.secrets
, I think it will make it to the Dask worker.Vinicius Cerutti
09/23/2021, 9:23 PMKevin Kho
"PREFECT__CLOUD__USE_LOCAL_SECRETS" = "true"
and see if that helps? Secret.get() will look locally. Also, I think the syntax would be Secret("GCP_CREDENTIALS").get()
if you want it to pull the environment variable?Vinicius Cerutti
09/23/2021, 9:28 PMAmazing, this seems very reasonable too. I will try that out. Uhm, I will try using Secrets as well. thanksand see if that helps?"PREFECT__CLOUD__USE_LOCAL_SECRETS" = "true"
Kevin Kho
Kevin Kho
Vinicius Cerutti
09/23/2021, 9:31 PMVinicius Cerutti
09/23/2021, 9:31 PMJohn Lee
09/24/2021, 12:46 PM--env
option.Vinicius Cerutti
09/28/2021, 4:49 PMKevin Kho
Vinicius Cerutti
09/28/2021, 5:19 PMVinicius Cerutti
09/28/2021, 5:20 PMMost of the tasks do use GCP_CREDENTIALSThat's one of my doubts, do we need to use the GCP task in order to access the GCP secret for the run? or just running a simple task will be enough?
Vinicius Cerutti
09/28/2021, 5:21 PM-e
arg for the agent start command
• we then succeed in authenticating the flow, using prefect login (it's other credentials file) and send the flow pipeline to prefct.io
• but, the real problem is, for instance, executing a pd.read_csv or using the client in the flow ends up in a error. We were getting anonymous caller insufficient permission to access Google cloud storageVinicius Cerutti
09/28/2021, 5:30 PMKevin Kho
Kevin Kho
Kevin Kho
-e
flag. It gets added to the context and the prefect.context.get("secrets", {}).get("GCP_CREDENTIALS")
will be able to grab it and pass it to the Client
. Otherwise, it falls back to this line, and the default GCP Client falls back to GOOGLE_APPLICATION_CREDENTIALS
. This is my current understanding. John here might know way moreVinicius Cerutti
09/28/2021, 5:43 PMVinicius Cerutti
09/28/2021, 5:44 PMKevin Kho
get_google_client
can take in credentials
and use those instead of the secret. So you might be able to import that function and use it to create a Client by passing credentials directly?Vinicius Cerutti
09/28/2021, 5:49 PMKevin Kho
set_google_application_credentials
phase give you?Vinicius Cerutti
09/28/2021, 5:50 PMKevin Kho
Vinicius Cerutti
09/28/2021, 5:52 PMKevin Kho
Vinicius Cerutti
09/28/2021, 5:54 PM