I am able to access an item stored in Google Cloud secrets from the command line or python console -
gcloud secrets versions access 1 --secret=sql-db-pass
But if I try to access it from a Django application it throws the following error. I have already set the gcloud project and provided auth-default login as below
gcloud config set project my-test-project
gcloud auth application-default login
CODE:
secret_parent = "projects/my-test-project"
response = secret_client.access_secret_version(request={"name": "sql-db-pass"})
payload = response.payload.data.decode("UTF-8")
print(f"Plaintext: {payload}")
ERROR:
google.api_core.exceptions.PermissionDenied: 403 Permission denied on resource project sql-db-pass. [links {
description: "Google developers console"
url: "https://console.developers.google.com"
}
, reason: "CONSUMER_INVALID"
domain: "googleapis.com"
metadata {
key: "service"
value: "secretmanager.googleapis.com"
}
metadata {
key: "consumer"
value: "projects/sql-db-pass "
}
]
I'm stumped - any suggestions are appreciated
Use the Project ID and not the Project Name.
The key error message is CONSUMER_INVALID
.