Reference existing secret manager secrets
Topic to explain how to reference existing secret manager secrets.
If you already have secrets created in a secret manager such as HashiCorp Vault or AWS Secrets Manager, you do not need to re-create the existing secrets in Harness.
Harness does not query the secret manager for existing secrets, but you can create a secret in Harness that references an existing secret in HashiCorp Vault or AWS Secrets Manager. No new secret is created in those providers. If you delete the secret in Harness, it does not delete the secret in the provider.
Before you begin
Go to AWS KMS Secret Manager
Go to AWS Secrets Manager
Option: Vault secrets
You can create a Harness secret that refers to the existing Vault secret using a path and key, such as /path/secret_key#my_key.

In the above example, /path is the pre-existing path, secret_key is the secret name, and my_key is the key used to lookup the secret value.
This Harness secret is simply a reference pointing to an existing Vault secret. Deleting this Harness secret will not delete the Vault secret referred to by this secret.
You can reference pre-existing Vault secrets in the Harness YAML editor.
Option: HashiCorp Vault Secrets
For HashiCorp Vault, you can also use expressions to reference pre-existing secrets in Vault using a fully-qualified path, such as hashicorpvault://LocalVault/foo/bar/mysecret#mykey.
With this type of referencing, you don't need to pre-create secrets.
The scheme hashicorpvault:// is needed to distinguish a Vault secret from other secret references. It is followed by the identifier of the Vault secret manager.
For example, if you have a HashiCorp Vault connector with the identifier myVault in the Account scope and a secret with the name example present in the vault path /harness/testpath with the following values:
You can reference the value of key1 for the secret example using the following expression:
For a HashiCorp Vault connector at the Org scope, use the following expression:
For a HashiCorp Vault connector at the Project scope, use the following expression:
Option: AWS Secrets Manager secrets
You can create a Harness secret that refers to an existing secret in AWS Secrets Manager using the name of the secret, and a prefix if needed. For example, mySecret.

Referencing secret keys
In AWS Secrets Manager, your secrets are specified as key-value pairs, using a JSON collection:

To reference a specific key in your Harness secret, add the key name following the secret name, like secret_name#key_name. In the above example, the secret is named example4docs. To reference the example1 key, you would enter example4docs#example1.
Referencing pre-existing secrets
For AWS secret manager, you can also use expressions to reference pre-existing secrets using a fully-qualified path, such as awssecretsmanager://<connector_identifier>/<secret>.
With this type of reference, you don't need to pre-create secrets.
The scheme awssecretsmanager:// is needed to distinguish an AWS secret manager secret from other secret references. The identifier of the secret manager follows this.
For example, if you have an AWS secret manager connector with the identifier exampleAWS in the Account scope and a secret with the name example present in it.
You can reference the secret example using the following expression:
For an AWS secret manager connector at the Org scope, use the following expression:
For an AWS secret manager connector at the Project scope, use the following expression:
Option: Azure Key Vault secrets
You can create a Harness secret that refers to an existing secret in Azure Key Vault, using that secret's name (for example: azureSecret). You can also specify the secret's version (for example: azureSecret/05).
Referencing pre-existing secrets
For Azure Key Vault secret manager, you can also use expressions to reference pre-existing secrets using a fully-qualified path, such as azurevault://My_AzureVault/mySecret.
With this type of reference, you don't need to pre-create secrets.
The scheme azurevault:// is needed to distinguish an Azure Key Vault secret from other secret references. The identifier of the secret manager follows this.
For example, if you have an Azure Key Vault connector with the identifier exampleAzureKeyVault in the Account scope and a secret with the name example present in it.
You can reference the secret example using the following expression:
For an Azure Key Vault secret manager connector at the Org scope, use the following expression:
For an Azure Key Vault secret manager at the Project scope, use the following expression:
Option: GCP Secret Manager
For GCP secret manager, you can also use expressions to reference pre-existing secrets using a fully-qualified path, such as gcpsecretsmanager://My_GoogleSM/mySecret.
With this type of reference, you don't need to pre-create secrets.
The scheme gcpsecretsmanager:// is needed to distinguish a GCP secret manager secret from other secret references. The identifier of the secret manager follows this.
Supported reference formats
What you add after the connector identifier depends on which secret you want, and on whether that secret lives in the connector default project or in another GCP project.
The latest version of a secret in the connector default project
secretName
gcpsecretsmanager://exampleGCP/example
A specific version of a secret in the connector default project
secretName/version
gcpsecretsmanager://exampleGCP/example/7
A secret in a different GCP project that the connector can access
gcpProject/secretName/version
gcpsecretsmanager://exampleGCP/my-gcp-project/example/latest
For version, enter a version number such as 1 or 7, or enter latest to resolve the most recent version at runtime.
The following examples use a GCP secret manager connector with the identifier exampleGCP and a secret named example.
Reference the latest version of a secret in the connector default project:
Reference a specific version of a secret in the connector default project:
Reference a secret in another GCP project:
When you name a GCP project, always include the version as well. Harness reads gcpsecretsmanager://exampleGCP/my-gcp-project/example as the secret my-gcp-project at version example, not as the secret example in the project my-gcp-project. Harness accepts the expression, and GCP fails later, when the secret is fetched.
Connector scope prefixes
Prefix the scheme with the scope of the connector when the connector is not in the same project as the pipeline. The Harness scope prefix sits in front of the scheme, and does not change the path that follows the connector identifier. Project, org, and account scope connectors all support every format above, including references to another GCP project.
For a connector at the Account scope, use the following expression:
For a connector at the Org scope, use the following expression:
For a connector at the Project scope, use no prefix:
Scope prefixes combine with a cross-project reference. For example, to reference the latest version of the secret example in the GCP project my-gcp-project, use one of the following expressions, depending on the scope of the connector:
Option: Reference JSON secrets
Harness supports the ability to reference JSON secrets for the following secret managers.
AWS KMS Secret Manager
AWS Secret Manager
Azure Key Vault Secret Manager
HashiCorp Vault Secret Manager
Harness allows you to manage the lifecycle of your secrets independently by referencing JSON secrets in the vault.
For example, you can store a secret in vault with the following JSON.
Here are sample outputs for the respective JSONPath from the above JSON file:
test-secret (without any # key)
test-secret#key1
test-secret#key2
test-secret#key3
test-secret#key3.key31
test-secret#key3.key31.key311
Harness does not recommend using keys that include dots and might deprecate support in future releases.
Last updated
Was this helpful?