I am trying to run a Python script to access Secrets Manager in GCP, but I keep running into the error above: "403 Request had insufficient authentication scopes".
I have been following these instructions in the GCP docs. I can successfully access a secret version with the command line using
gcloud secrets versions access {{ version-id }} --secret={{ "secret-id" }}
but cannot access a secret version using the Python function from the docs
def access_secret_version(project_id, secret_id, version_id):
"""
Access the payload for the given secret version if one exists. The version
can be a version number as a string (e.g. "5") or an alias (e.g. "latest").
"""
# Import the Secret Manager client library.
from google.cloud import secretmanager
# Create the Secret Manager client.
client = secretmanager.SecretManagerServiceClient()
# Build the resource name of the secret version.
name = f"projects/{project_id}/secrets/{secret_id}/versions/{version_id}"
# Access the secret version.
response = client.access_secret_version(request={"name": name})
# Print the secret payload.
# snippet is showing how to access the secret material.
payload = response.payload.data.decode("UTF-8")
return payload
What am I missing here?
The IAM permissions for my account contain "Secrets Manager Secret Accessor." I don't think that is the issue since I can access a secret version from the command line. But the Python script keeps failing.
Any ideas what the issue might be?