Hi,
I hope someone can help but it is a use-case that may not have come up before and specific to me and mine. Some context: all of the application and infrastructure secrets I need are stored in GCP Secret Manager. To access them I have a service account (.json) that is used when creating the client for interacting with the secret manager api. Because I want to run dagger in Gitlab I can only supply the serviceaccount.json file through an environment variable because I cannot push the secret file to the repository. A sample of the code for accessing secret manager is shown below:
def get_secret(project_id: str, secret_name: str, sa_json_from_env: str) -> str:
sa_json = json.loads(sa_json_from_env)
client = secretmanager.SecretManagerServiceClient().from_service_account_info(info=sa_json)
name = f"projects/{project_id}/secrets/{secret_name}/versions/latest"
response = client.access_secret_version(name=name)
return response.payload.data.decode("UTF-8")
This code works when I run it outside of the dagger pipeline. If I export the service_account.json to the environment variable SA_JSON invoke it like secret = get_secret("my_project", "my_secret", os.environ.get("SA_JSON")) it reads the variable from the environment and creates the client with service account and then returns the secret.
When I run it inside the dagger pipeline something I do not understand happens...