Proteggere e archiviare i dati sensibili utilizzando il connettore Secret Manager
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Secret Manager è un sistema di archiviazione pratico e sicuro per chiavi API, password, certificati e altri dati sensibili. Secret Manager fornisce un posto centralizzato e un'unica fonte attendibile per gestire, accedere e controllare i secret in Google Cloud.
Puoi utilizzare il
connettore di Workflows per l'API Secret Manager
per accedere a Secret Manager all'interno di un workflow. Ciò semplifica l'integrazione, perché il connettore gestisce la formattazione delle richieste e fornisce metodi e argomenti in modo che tu non debba conoscere i dettagli dell'API Secret Manager. Il connettore ha anche
un comportamento integrato per la gestione dei nuovi tentativi e delle operazioni a lunga esecuzione. Per scoprire
di più sull'utilizzo dei connettori di Workflows, consulta
Informazioni sui connettori.
Concedi al account di servizio di Workflows l'accesso a Secret Manager
Secret Manager utilizza Identity and Access Management (IAM) per il controllo
dell'accesso. Per creare, gestire, elencare o accedere a un secret, è necessario concedere le autorizzazioni IAM appropriate a livello di progetto e a livello di singola risorsa. Per ulteriori informazioni, consulta
Controllo dell'accesso con IAM.
Analogamente all'invocazione di un endpoint HTTP, una chiamata al connettore richiede i campi call e args. Per saperne di più, vedi
Richiamare una chiamata al connettore.
Oltre a utilizzare un passaggio di chiamata, puoi chiamare i metodi helper in un'espressione come questa:
Ad esempio, puoi utilizzare il metodo helper accessString per recuperare i dati secret come stringa. È più semplice rispetto all'utilizzo dell'API access, in quanto i dati secret vengono decodificati automaticamente in un formato stringa.
Puoi anche utilizzare il metodo helper addVersionString per aggiungere un nuovo valore secret
a un secret esistente. È più semplice rispetto all'utilizzo dell'API addVersion, in quanto i dati segreti vengono codificati automaticamente in una stringa Base64, richiesta da addVersion.
Recuperare un secret utilizzando il connettore Secret Manager
Il seguente flusso di lavoro mostra come utilizzare il connettore Secret Manager per recuperare un secret.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-04 UTC."],[],[],null,["# Secure and store sensitive data using the Secret Manager connector\n\nSecret Manager is a secure and convenient storage system for\nAPI keys, passwords, certificates, and other sensitive data. Secret Manager\nprovides a central place and single source of truth to manage, access, and audit\nsecrets across Google Cloud.\n\nYou can use Workflows'\n[connector for the Secret Manager API](https://cloud.google.com/workflows/docs/reference/googleapis/secretmanager/Overview)\nto access Secret Manager within a workflow. This simplifies the\nintegration for you, because the connector handles the formatting of\nrequests, and provides methods and arguments so that you don't need to know\nthe details of the Secret Manager API. The connector also has\nbuilt-in behavior for handling retries and long-running operations. To learn\nmore about using Workflows connectors, see\n[Understand connectors](/workflows/docs/connectors).\n\nGrant the Workflows service account access to Secret Manager\n------------------------------------------------------------\n\nSecret Manager uses Identity and Access Management (IAM) for access\ncontrol. To create, manage, list, or access a secret, the appropriate\nIAM permissions must be granted at the project level and at the\nindividual resource level. For more information, see\n[Access control with IAM](/secret-manager/docs/access-control).\n\nWorkflows uses service accounts to give workflows access to\nGoogle Cloud resources. To\n[access a secret version](/secret-manager/docs/access-secret-version), you must\ngrant the Secret Manager Secret Accessor role\n(`roles/secretmanager.secretAccessor`) on the secret, project, folder, or\norganization to the service account. Learn more about\n[deploying a workflow with a user-managed service account](/workflows/docs/authentication).\n\nEnable the APIs\n---------------\n\nBefore using the Workflows' connector for the\nSecret Manager API, ensure that you enable the\nSecret Manager and Workflows APIs. \n\n### Console\n\n[Enable the APIs](https://console.cloud.google.com/flows/enableapi?apiid=secretmanager.googleapis.com,workflows.googleapis.com)\n\n### gcloud\n\n gcloud services enable secretmanager.googleapis.com workflows.googleapis.com\n\nInvoke a connector call\n-----------------------\n\nSimilar to invoking an HTTP endpoint, a connector call requires `call` and `args`\nfields. For more information, see\n[Invoke a connector call](/workflows/docs/reference/googleapis#invoke_a_connector_call).\n\nIn addition to using a call step, you can call the helper methods in an\nexpression like this: \n\n```genshi\n${googleapis.secretmanager.v1.projects.secrets.versions.accessString(secret_id, version, project_id)}\n```\n\nFor example, you can use the helper method `accessString` to retrieve the secret\ndata as a string. This is simpler than using the `access` API as the secret data\nis automatically decoded to a string format.\n\nYou can also use the helper method `addVersionString` to add a new secret value\nto an existing secret. This is simpler than using the `addVersion` API as the\nsecret data is automatically encoded to a base-64 string, which is required by\n`addVersion`.\n\nRetrieve a secret using the Secret Manager connector\n----------------------------------------------------\n\nThe following workflow demonstrates how to use the Secret Manager\nconnector to retrieve a secret.\n\n### YAML\n\n # This workflow demonstrates how to use the Secret Manager connector:\n # Retrieve a secret using three different methods\n # Expected output: the secret data (thrice)\n - init:\n assign:\n - project_id: ${sys.get_env(\"GOOGLE_CLOUD_PROJECT_ID\")}\n - secret_id: \"test-secret\" # Make sure you have this secret and it has a version of 1.\n - version: \"1\"\n # Add data to an existing secret without base-64 encoding\n - add_version_string:\n call: googleapis.secretmanager.v1.projects.secrets.addVersionString\n args:\n secret_id: ${secret_id}\n project_id: ${project_id}\n data: \"a new secret\"\n # Retrieve the secret in string format without base-64 decoding and assume\n # that the secret data is a valid UTF-8 string; if not, raise an error\n - access_string_secret:\n call: googleapis.secretmanager.v1.projects.secrets.versions.accessString\n args:\n secret_id: ${secret_id}\n version: ${version} # if not set, \"latest\" is used\n project_id: ${project_id}\n result: str_secret\n # Retrieve the secret in string format without base-64 decoding\n - access_secret:\n call: googleapis.secretmanager.v1.projects.secrets.versions.access\n args:\n name: ${\"projects/\" + project_id + \"/secrets/\" + secret_id + \"/versions/\" + version}\n result: base64_encoded_secret\n # Retrieve the secret using positional arguments in an expression\n - expression:\n assign:\n - secret_str_from_exp: ${googleapis.secretmanager.v1.projects.secrets.versions.accessString(secret_id, version, project_id)}\n - the_end:\n return:\n - ${str_secret}\n - ${text.decode(base64.decode(base64_encoded_secret.payload.data))}\n - ${secret_str_from_exp}\n\n### JSON\n\n [\n {\n \"init\": {\n \"assign\": [\n {\n \"project_id\": \"${sys.get_env(\\\"GOOGLE_CLOUD_PROJECT_ID\\\")}\"\n },\n {\n \"secret_id\": \"test-secret\"\n },\n {\n \"version\": \"1\"\n }\n ]\n }\n },\n {\n \"add_version_string\": {\n \"call\": \"googleapis.secretmanager.v1.projects.secrets.addVersionString\",\n \"args\": {\n \"secret_id\": \"${secret_id}\",\n \"project_id\": \"${project_id}\",\n \"data\": \"a new secret\"\n }\n }\n },\n {\n \"access_string_secret\": {\n \"call\": \"googleapis.secretmanager.v1.projects.secrets.versions.accessString\",\n \"args\": {\n \"secret_id\": \"${secret_id}\",\n \"version\": \"${version}\",\n \"project_id\": \"${project_id}\"\n },\n \"result\": \"str_secret\"\n }\n },\n {\n \"access_secret\": {\n \"call\": \"googleapis.secretmanager.v1.projects.secrets.versions.access\",\n \"args\": {\n \"name\": \"${\\\"projects/\\\" + project_id + \\\"/secrets/\\\" + secret_id + \\\"/versions/\\\" + version}\"\n },\n \"result\": \"base64_encoded_secret\"\n }\n },\n {\n \"expression\": {\n \"assign\": [\n {\n \"secret_str_from_exp\": \"${googleapis.secretmanager.v1.projects.secrets.versions.accessString(secret_id, version, project_id)}\"\n }\n ]\n }\n },\n {\n \"the_end\": {\n \"return\": [\n \"${str_secret}\",\n \"${text.decode(base64.decode(base64_encoded_secret.payload.data))}\",\n \"${secret_str_from_exp}\"\n ]\n }\n }\n ]\n\nWhat's next\n-----------\n\n- [Learn more about Secret Manager](/secret-manager/docs/overview)"]]