Blake
04/13/2022, 5:37 AMEnvVarSecret()
and running on Kubernetes, using a Kubernetes Agent.
I'm using a customized agent deployement with the following env vars added (populated via Kube secrets):
- name: PREFECT__CLOUD__USE_LOCAL_SECRETS
value: 'true'
- name: AWS_ACCESS_KEY_ID
valueFrom:
secretKeyRef:
name: aws-access-key
key: aws_access_key
- name: AWS_SECRET_ACCESS_KEY
valueFrom:
secretKeyRef:
name: aws-secret-key
key: aws_secret_key
The keys end up on the agent no problem - I can see them being passed through in the deployment and pod config.
I even started a shell session on the agent pod and I can see the env vars there no problem!
However, when I try to reference them in a flow running on that agent, I get errors like this:
Task 'AWS_SECRET_ACCESS_KEY': Exception encountered during task execution!
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/prefect/engine/task_runner.py", line 884, in get_task_run_state
logger=self.logger,
File "/usr/local/lib/python3.7/site-packages/prefect/utilities/executors.py", line 468, in run_task_with_timeout
return task.run(*args, **kwargs) # type: ignore
File "/usr/local/lib/python3.7/site-packages/prefect/tasks/secrets/env_var.py", line 50, in run
raise ValueError("Environment variable not set: {}".format(name))
ValueError: Environment variable not set: AWS_SECRET_ACCESS_KEY
These flows work locally with the Env Vars in question set, and they work if I set them manually in the "Run" area of the UI's Kubernetes Run Configuration under "Environment Variables".
Shouldn't flows running on an agent pick up the env vars from the agent by default?davzucky
04/13/2022, 7:26 AMAnna Geller
davzucky
04/13/2022, 10:10 AMBlake
04/13/2022, 4:28 PMAnna Geller
Blake
04/13/2022, 4:35 PMaccess_key = EnvVarSecret(name='AWS_ACCESS_KEY_ID', raise_if_missing=True)
secret_access_key = EnvVarSecret(name='AWS_SECRET_ACCESS_KEY', raise_if_missing=True)
My concern with the IAM roles path is that we'd like something that works locally and when deployed on EKS.Anna Geller
Blake
04/13/2022, 4:59 PMAnna Geller
flow.run()
or:
prefect run -p yourflow.py
Blake
04/13/2022, 5:35 PMBlake
04/13/2022, 5:36 PMprefect-server-2022.03.29
Anna Geller
flow.run()
or:
prefect run -p yourflow.py
This way you are using just a local process and the agents don't matter.
And for your production Helm deployment use IAM roles for service accounts. Environment variables are hard because they are many components here and you would need to be careful that they are set everywhere they are needed - I wouldn't go that route, especially given that for local run you really don't need any environment variables whatsoever - just configure your terminal with aws configure
and you are good to go locally, and use eksctl
for server-side IAM roles setup on KubernetesBlake
04/13/2022, 6:36 PMaws configure
do you mean using the AWS CLI to setup the ~/.aws/credentials
file so that the default credentials are set? The issue there is that we need multiple sets of AWS credentials, sometimes to services outside the AWS environment we're running in.Blake
04/13/2022, 6:36 PMAnna Geller
Blake
04/13/2022, 6:47 PMBlake
04/13/2022, 6:47 PMAnna Geller
Blake
04/13/2022, 9:40 PMKubernetesRun
, they actually run as a Kube Job w/ an ephemal Pod spun up. Makes sense now, thanks!Anna Geller
Blake
04/14/2022, 2:56 AMBring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.
Powered by