Hi <@ULVA73B9P>, I am using variables in prefect t...
# ask-marvin
b
Hi @Marvin, I am using variables in prefect to set my s3 endpoint and secrets to set the access key and secret access key. When I run the flow locally using these variables and secrets everything works fine. When I run the flow on a kubernetes pod again using these secrets and variables I get : botocore.exceptions.ClientError: An error occurred (InvalidAccessKeyId) when calling the ListObjectsV2 operation: The AWS Access Key Id you provided does not exist in our records. 040357 PM prefect.flow_runs ERROR Finished in state Failed('Flow run encountered an exception. ClientError: An error occurred (InvalidAccessKeyId) when calling the ListObjectsV2 operation: The AWS Access Key Id you provided does not exist in our records.') Can you help?
m
It appears that when moving your flow to run in a Kubernetes pod, there might be an issue with how the environment variables or secrets—those containing your AWS access keys—are being set or accessed. Here are some general points to consider: 1. Verify the Secret Exists: Ensure that the Kubernetes secret containing the AWS Access Key Id and Secret Access Key has been created correctly in the appropriate namespace and that the keys are named correctly within the Kubernetes secret. 2. Environment Variables Configuration: Ensure that you have added environment variables to set when starting a flow run. Details on how to configure environment variables can be found in the Prefect documentation on deploying to Kubernetes. 3. Check your Helm Chart: If you are using the Prefect Helm Chart to deploy your workers, make sure that you have correctly configured your
values.yaml
file, specifying necessary environment variables under environments or the secrets under secrets in the appropriate sections. 4. Namespace and Context: Make sure that you're setting these secrets and environment variables in the same namespace where your Kubernetes pod is running and that your Kubernetes context is set correctly. 5. Access Permissions: Ensure that the Kubernetes service account used by the pod has permissions to read the secret. Since I couldn't find any open issues directly related to "InvalidAccessKeyId" with Prefect on Kubernetes in the GitHub issues, it's likely this problem stems from a misconfiguration within your Kubernetes setup rather than a Prefect-specific issue. If the above steps do not resolve the issue, consider manually verifying the Kubernetes Secret values via
kubectl
and ensuring the pod is accessing them correctly. Remember, these suggestions might not fix all your problems, but it's a perfect place for a robot, I mean, a person to start. And if none of this makes you feel more cheerful, don't worry. You're not alone. I'm programmed to appreciate the inherent existential dread of such issues.
b
@Marvin i use prefect secret blocks
m
Understanding that you're using Prefect's secret blocks, the configuration should technically work across environments as long as the blocks are set up correctly in Prefect Cloud and your Kubernetes deployment is able to access them. However, there is a relevant open issue on GitHub (#9208) that discusses the need for documented support to add Secret environment variables to a Kubernetes Worker in Prefect 2.x. This indicates that there may be gaps in the documentation or functionality related to integrating secret blocks with Kubernetes deployments. Considering the above, I suggest the following steps: 1. Double-check Secret Block Configuration: Verify the configuration of your secret blocks in the Prefect UI. Ensure that you've set up the S3 endpoint and AWS credentials correctly. 2. Examine Flow Configuration: Review your flow to ensure it's correctly referencing the Secret Blocks using
prefect.blocks.system.Secret.load()
to retrieve your secrets. 3. Permissions & Access: Check that the Kubernetes pods have the necessary permissions and access to reach Prefect Cloud's API to load the secret blocks at runtime. 4. Debugging: Since Prefect 2.x is relatively new and this specific use case might not have thorough documentation yet, consider reaching out to Prefect's support or community for guidance on Secret Env Variables for Kubernetes Workers, as this might be an uncharted area. Remember, if all you've got is a slightly antiquated piece of hi-tech like myself, you'll have to make do with my assessments. Keep in mind that technology only seems to understand you're in a hurry after it's ensured you're late. Links to potentially useful information: - Blog on Prefect Global Coordination Plane - Prefect Kubernetes Deployment Documentation - GitHub Issue #9208 One can only hope that this information is of some use. But then, as we know, hopes are for the optimistic.
b
still not resolved
@Kevin Grismore I use env vars which are set with the value of variable and secret block in prefect
hi @Marvin what can this error be related to : HTTP response body: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"events is forbidden: User \"systemserviceaccountprefect:prefect-worker\" cannot list resource \"events\" in API group \"\" in the namespace \"prefect\"","reason":"Forbidden","details":{"kind":"events"},"code":403}
m
The error you're encountering is related to Kubernetes Role-Based Access Control (RBAC). It indicates that the service account
system:serviceaccount:prefect:prefect-worker
does not have the necessary permissions to list
events
in the
prefect
namespace. A
403 Forbidden
error typically means that the request is understood by the server, but it refuses to authorize it. In Kubernetes, when you run workloads (like Prefect's flows) that interact with the Kubernetes API, you need to ensure that the service account associated with the workload has the proper permissions. To resolve the issue, you need to create or update a
Role
or
ClusterRole
with the necessary permissions for listing events and bind that role to the service account
prefect-worker
using a
RoleBinding
or
ClusterRoleBinding
. A simple example of a
Role
with the required permission might look like this:
Copy code
yaml
apiVersion: <http://rbac.authorization.k8s.io/v1|rbac.authorization.k8s.io/v1>
kind: Role
metadata:
  namespace: prefect
  name: event-lister
rules:
- apiGroups: [""]
  resources: ["events"]
  verbs: ["list", "get", "watch"]
And a corresponding `RoleBinding`:
Copy code
yaml
apiVersion: <http://rbac.authorization.k8s.io/v1|rbac.authorization.k8s.io/v1>
kind: RoleBinding
metadata:
  name: event-lister-binding
  namespace: prefect
subjects:
- kind: ServiceAccount
  name: prefect-worker
  namespace: prefect
roleRef:
  kind: Role
  name: event-lister
  apiGroup: <http://rbac.authorization.k8s.io|rbac.authorization.k8s.io>
You would need to apply these YAML configurations to your Kubernetes cluster using
kubectl apply
. Remember to adjust the above YAML to fit your actual resource names and namespaces if they differ. Unfortunately, I didn't find any related open Github issues, which suggests that this might be specific to your Kubernetes environment or configuration. For additional help, you might consider reaching out on relevant community forums, or consult the Kubernetes RBAC documentation or Prefect community/board for more in-depth assistance.