[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-04 (世界標準時間)。"],[[["\u003cp\u003eCloud Code's Secret Manager integration allows users to manage secrets directly within their IDE, avoiding the need to store them in the codebase.\u003c/p\u003e\n"],["\u003cp\u003eUsers can create new secrets, define their project, name, value, region, and labels through the Secret Manager explorer or directly from the editor.\u003c/p\u003e\n"],["\u003cp\u003eNew versions of existing secrets can be created, including the option to disable past versions, either via the Secret Manager explorer or from the editor.\u003c/p\u003e\n"],["\u003cp\u003eSecrets can be accessed from applications by installing the Secret Manager client library and including relevant code snippets, with authentication setups available for local or remote development.\u003c/p\u003e\n"],["\u003cp\u003eKubernetes secrets can be managed by adding them as environment variables or mounting them as volumes within deployments.\u003c/p\u003e\n"]]],[],null,["# Manage secrets with Secret Manager in Cloud Code for VS Code\n\nWith Cloud Code's [Secret Manager](/secret-manager)\nintegration, you can create, view, update, and use secrets in your IDE and\nwithout storing them in your codebase.\n\nThis page describes how to access Secret Manager in your IDE and how\nyou can get started creating and managing secrets.\n\nEnable Secret Manager API\n-------------------------\n\nWhen managing secrets with Cloud Code, secrets are securely stored\nin Secret Manager and can be programmatically fetched when you need\nthem. All you need is the Secret Manager API enabled and the right\npermissions to manage secrets:\n\n1. Make sure that you're working in the project where your application code\n resides. Your secret must be in the same project as your application code.\n\n2. Click **Cloud Code** and then expand the\n **Secret Manager** explorer.\n\n3. If you haven't enabled the Secret Manager API, click\n **Enable Secret Manager API** in the Secret Manager explorer.\n\nCreate secrets\n--------------\n\nTo create a secret using the Secret Manager explorer, follow these\nsteps:\n\n1. In your IDE, click **Cloud Code** and then expand the\n **Secret Manager** explorer.\n\n2. Click add **Create Secret** in the\n **Secret Manager** explorer.\n\n In the **Create Secret** dialog, set your secret's project, name, value, and\n region, and specify labels to organize your secrets.\n\nAlternatively, you can create a secret using the editor:\n\n1. Open a file containing text that you want to store as a secret in the editor.\n2. Highlight the text to store as a secret, right-click, and then click **Create Secret in Secret Manager**.\n3. In the **Create Secret** dialog, customize the secret's project, name, value, region, and labels.\n\nCreate new versions of secrets\n------------------------------\n\nTo create a new version of a secret using Secret Manager, follow\nthese steps:\n\n1. Right-click an existing secret and then choose **Create Secret Version**.\n\n2. In the **Create Version** dialog, set the new value of your existing secret\n using the **Secret value** field or by importing a file.\n\n3. To remove all previous versions of your secret and keep just the new version\n you're creating, choose **Disable all past versions**.\n\n4. Click **Create Version** . Your version is added and you can see the\n latest secret version and previous versions listed under the **Versions**\n dropdowns.\n\nAlternatively, you can create a new version of a secret in the editor:\n\n1. In the editor, open a file and highlight the text to store as a secret.\n\n2. Right-click the highlighted text and then choose **Add Version to Secret in\n Secret Manager**.\n\n### Manage secret versions\n\nTo enable, disable, or destroy a version of a secret, right-click the secret\nand then select the command for the action you want to perform. For enabled\nversions of secrets, you can also view the version's value.\n\nView secrets\n------------\n\nTo view secrets, in the **Secret Manager** explorer, select a secret\nfrom the list. Details of the secret such as name, replication policy, creation\ntimestamp, and resource ID are listed below the secret name.\n\n### View secrets in Google Cloud console\n\nAlternatively, you can view secrets in Google Cloud console by right-clicking\nthe secret in the **Secret Manager** explorer and clicking **Open in\nCloud console**.\n\n\n### View secrets in Kubernetes explorer\n\nTo view secrets in the **Kubernetes** explorer, follow these steps:\n\n1. Click **Cloud Code** and then expand the **Kubernetes** explorer.\n2. Expand your cluster and then expand **Secrets**.\n3. Expand the secret to view its details.\n\nAccess secrets from your application\n------------------------------------\n\nAfter your secret is created, you can include it in your code and set up\nauthentication.\n\nTo access a secret from your application:\n\n1. Install the Secret Manager client library.\n\n 1. Click **Cloud Code** and then expand the\n **Cloud APIs** explorer.\n\n 2. Expand **Cloud Security** \\\u003e **Secret Manager API** and then follow the\n instructions in the Install Client Library section for the language\n you're using.\n\n2. Customize and include the\n [relevant code snippet](/secret-manager/docs/access-secret-version)\n in your application's code.\n\n To obtain your secret's version name to use in your code, select the secret\n in the Secret Manager panel, right-click, and then choose\n **Copy Resource ID**.\n3. To complete your authentication setup, follow the Client libraries\n authentication guide:\n\n - **Local development** : If you're developing on a local cluster (like minikube or Docker Desktop) or a local emulator, you should complete the steps illustrated in the [Local development section](/code/docs/vscode/client-libraries#local_development) relevant to your workflow.\n - **Remote development** : If you're using a GKE cluster or a Cloud Run service in your application, you should complete the steps illustrated in the [Remote development section](/code/docs/vscode/client-libraries#remote_development) relevant to your workflow, including the Secret Manager-specific instructions for setting up the required roles on your service account.\n\nAdd a secret as an environment variable\n---------------------------------------\n\nTo add an existing [Kubernetes secret](https://kubernetes.io/docs/concepts/configuration/secret/)\nto the deployment as an environment variable, follow these steps:\n\n1. Click **Cloud Code** and then expand the **Kubernetes** explorer.\n2. Expand your minikube cluster and then expand **Secrets**.\n3. Right-click a secret that represents a deployment object and then click **Add Secret as Environment Variable**.\n\nMount a secret as a volume\n--------------------------\n\nTo mount an existing [Kubernetes secret](https://kubernetes.io/docs/concepts/configuration/secret/)\nas a volume in the deployment's container, follow these steps:\n\n1. Click **Cloud Code** and then expand the **Kubernetes** explorer.\n2. Expand your minikube cluster and then expand **Secrets**.\n3. Right-click a secret that represents a deployment object and then click **Mount Secret as Volume**.\n\nDelete secrets\n--------------\n\n| **Note:** Deleting a secret requires the Secret Admin role (`roles/secretmanager.admin`) on the secret, project, folder, or organization. IAM roles can't be granted on a secret version.\n\nTo delete a secret using the Secret Manager in\nCloud Code, follow these steps:\n\n1. Click **Cloud Code** and then expand the\n **Secret Manager** explorer.\n\n2. Right-click an existing secret and select **Open in Cloud Console**.\n\n3. On the **Secret details** page, click **DELETE** and follow the prompts to\n delete the secret.\n\nGet Support\n-----------\n\nTo send feedback, report issues on [GitHub](https://github.com/GoogleCloudPlatform/cloud-code-vscode/issues), or ask a question on [Stack Overflow](https://stackoverflow.com/questions/ask?tags=cloud-code-vscode)."]]