-
Notifications
You must be signed in to change notification settings - Fork 10
External secrets #323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
External secrets #323
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3c216d2
Update secrets management docs
IanKWatts c5fc431
External Secrets Operator update
IanKWatts 896b81c
Updates
Pilargit12 e5fbd04
Minor tweaks to external secrets docs
IanKWatts 6c4d12a
Add note about encryption of secrets
IanKWatts File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"cSpell.words": [ | ||
"alertmanager", | ||
"azurekv", | ||
"cicd", | ||
"creds", | ||
"crunchydb", | ||
"Entra", | ||
"externalsecret", | ||
"golddr", | ||
"IDIR", | ||
"imagestreams", | ||
"Kamloops", | ||
"KLAB", | ||
"Kyverno", | ||
"licenseplate", | ||
"linenums", | ||
"myapp", | ||
"nonprod", | ||
"opensource", | ||
"Patroni", | ||
"pids", | ||
"pymdownx", | ||
"rolebinding", | ||
"serviceaccount", | ||
"Sysdig", | ||
"techdocs" | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
src/docs/secrets-management/example_secretstore_azure_key_vault.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
# Example SecretStore - Azure Key Vault | ||
|
||
## Summary | ||
|
||
In order to use Azure Key Vault with the [External Secrets Operator](external-secrets.md), you need to create a Service Principal with the right permissions. You then store the Service Principal’s credentials in a Kubernetes Secret in each namespace where you’ll create `SecretStore` and `ExternalSecret` resources. | ||
|
||
## Requirements | ||
|
||
To complete this setup, you need: | ||
|
||
* Access to your Azure Key Vault | ||
* Access to your OpenShift namespaces | ||
* Docker or Podman, if you're using the Azure CLI | ||
|
||
You can create the Service Principal using either the Azure CLI or the Azure Portal. This guide uses the CLI method. If you prefer the portal, see [Register a Microsoft Entra app and create a service principal](https://learn.microsoft.com/en-us/entra/identity-platform/howto-create-service-principal-portal). | ||
|
||
## Official documentation | ||
|
||
[External Secrets Operator - Azure Key Vault Provider](https://external-secrets.io/latest/provider/azure-key-vault/) | ||
|
||
## Start the Azure CLI Container | ||
|
||
We recommend running the Azure CLI in a Docker or Podman container. Installing the CLI directly on your machine requires many dependencies, which might conflict with other tools or take up unnecessary space if you only need it for this task. | ||
|
||
Make sure you have a running Docker or Podman environment before starting. | ||
|
||
Start the container: | ||
|
||
``` | ||
podman run -it mcr.microsoft.com/azure-cli:cbl-mariner2.0 | ||
``` | ||
|
||
Once it's running and you have a command prompt, run `az` to see version and help information. | ||
|
||
``` | ||
az | ||
``` | ||
|
||
Log in to Azure by running `az login` in the container and following the instructions. | ||
|
||
``` | ||
root [ / ]# az login | ||
To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code ... to authenticate. | ||
``` | ||
|
||
Make a note of the subscription ID in the output of the login command. | ||
|
||
## Create the Service Principal | ||
|
||
To create the Service Principal, make sure you have the following information: | ||
|
||
* Your Azure subscription ID | ||
* The name of your Key Vault | ||
* The resource group of your Key Vault | ||
|
||
You’ll use this information when you run the Azure CLI commands in the next steps: | ||
``` | ||
export SUBSCRIPTION_ID="your-subscription-ID" | ||
export KEY_VAULT_NAME="your-key-vault-name" | ||
export RESOURCE_GROUP="your-key-vaults-resource-group" | ||
export SP_NAME="name-of-service-principal-to-create" | ||
``` | ||
|
||
Run the command to create the service principal: | ||
``` | ||
az ad sp create-for-rbac --name "${SP_NAME}" --role "Key Vault Secrets User" --scopes /subscriptions/${SUBSCRIPTION_ID}/resourceGroups/${RESOURCE_GROUP}/providers/Microsoft.KeyVault/vaults/${KEY_VAULT_NAME} --sdk-auth | ||
``` | ||
|
||
Save a copy of the output from this command - you'll need `clientId`, `clientSecret`, and `tenantId`. Set the client credentials as environment variables if you'd like to copy the command below to create the Secret. | ||
``` | ||
export CLIENT_ID=clientId_from_output | ||
export CLIENT_SECRET=clientSecret_from_output | ||
``` | ||
|
||
## Create the OpenShift Secret | ||
|
||
First, create a Secret in your OpenShift namespace to store your Azure Service Principal credentials. You can use the UI if you like, or use the following command: | ||
``` | ||
oc create secret generic azure-key-vault-creds --from-literal=clientId=${CLIENT_ID} --from-literal=clientSecret=${CLIENT_SECRET} | ||
``` | ||
|
||
## Assign permissions to the Service Principal | ||
|
||
Using the Azure CLI, get a list of Service Principals: | ||
|
||
``` | ||
az ad sp list --show-mine | ||
``` | ||
|
||
If you see more than one, look for the one with the `displayName` that is equal to your new Service Principal. Find its `id` for that entry and assign it to an environment variable. | ||
``` | ||
export OBJECT_ID="the-service-principals-id" | ||
``` | ||
|
||
Or, use `jq` to extract it automatically: | ||
``` | ||
export OBJECT_ID=`az ad sp list --show-mine | jq -r ".[] | select(.displayName == \"${SP_NAME}\") | .id"` | ||
``` | ||
|
||
Now assign the right permissions to your Service Principal so it can access Secrets in Azure Key Vault: | ||
``` | ||
az keyvault set-policy --name ${KEY_VAULT_NAME} --object-id ${OBJECT_ID} --secret-permissions get list | ||
``` | ||
|
||
## Create a SecretStore | ||
Next, create a YAML manifest for the `SecretStore`. Be sure to enter the correct values for the `tenantId` and the name of the Secret that you created above. | ||
``` | ||
apiVersion: external-secrets.io/v1beta1 | ||
kind: SecretStore | ||
metadata: | ||
name: azure-key-vault | ||
namespace: abc123-dev | ||
spec: | ||
provider: | ||
azurekv: | ||
tenantId: "MY_TENANT_ID" | ||
vaultUrl: https://my-key-vault-name.vault.azure.net/ | ||
authSecretRef: | ||
clientId: | ||
name: azure-key-vault-creds | ||
key: clientId | ||
clientSecret: | ||
name: azure-key-vault-creds | ||
key: clientSecret | ||
``` | ||
|
||
After applying the YAML manifest, check the status of the new SecretStore. It should show as ready. | ||
``` | ||
status: | ||
capabilities: ReadWrite | ||
conditions: | ||
- lastTransitionTime: "2025-05-21T17:43:07Z" | ||
message: store validated | ||
reason: Valid | ||
status: "True" | ||
type: Ready | ||
``` | ||
|
||
Once the SecretStore is ready, you can create an [ExternalSecret](external-secrets.md#create-an-externalsecret) to sync your secrets. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
--- | ||
title: External secrets | ||
|
||
slug: external-secrets-operator | ||
|
||
description: The External Secrets Operator can link your OpenShift namespace with an external secrets management service. | ||
|
||
keywords: | ||
|
||
page_purpose: Describes the purpose and use of the External Secrets Operator | ||
|
||
audience: developer, technical lead | ||
|
||
author: Ian Watts | ||
|
||
content_owner: Ian Watts | ||
|
||
sort_order: 3 | ||
--- | ||
|
||
# External Secrets | ||
|
||
The **External Secrets Operator (ESO)** is a Kubernetes operator that connects to external secret management systems like [Azure Key Vault](https://azure.microsoft.com/en-us/products/key-vault/) and [AWS Secrets Manager](https://docs.aws.amazon.com/secretsmanager/latest/userguide/intro.html). The operator reads information from external APIs (systems) and automatically adds them to Kubernetes as Secrets. | ||
|
||
ESO's main purpose to keep your Kubernetes Secrets in sync with external APIs. It uses custom resources `ExternalSecret` and `SecretStore` to provide a user-friendly abstraction for the external API that stores and manages the lifecycle of the secrets for you. | ||
|
||
ESO is available in each cluster. It's **self-serve**, so you can: | ||
|
||
* Choose from many different secret management services | ||
* Use the same service across your hybrid cloud environment | ||
* Add redundancy to your secrets management set up | ||
|
||
For more details, visit the [official External Secrets Operator documentation](https://external-secrets.io/latest/). | ||
|
||
Note that OpenShift Secrets are now encrypted on disk, which resolves what was previously a security concern. | ||
|
||
## How External Secrets Operator works | ||
|
||
To connect to an external secrets management system, you create two resources: | ||
|
||
* A `SecretStore`, which sets up the connection and credentials | ||
* One or more `ExternalSecrets`, which define the specific secrets and keys to copy into OpenShift | ||
|
||
Create both resources in each namespace where you want to replicate secrets. | ||
|
||
## Create a SecretStore | ||
The `SecretStore` resource stores the address and credentials for your secrets management service. The setup depends on which service you're using. | ||
|
||
Check the [provider list](https://external-secrets.io/latest/provider/aws-secrets-manager/) for setup instructions specific to your service. | ||
|
||
If you are using Azure Key Vault, see the [Example SecretStore - Azure Key Vault](example_secretstore_azure_key_vault.md). | ||
|
||
## Create an ExternalSecret | ||
An `ExternalSecret` connects to a `SecretStore` and lists the specific secrets you want to copy from the external service. Each `ExternalSecret` creates one OpenShift secret. | ||
|
||
The key-value pairs or other secret data you define in the `ExternalSecret` are automatically added to the OpenShift secret. | ||
|
||
Here is an example: | ||
``` | ||
apiVersion: external-secrets.io/v1 | ||
kind: ExternalSecret | ||
metadata: | ||
name: my-app-1 | ||
namespace: abc123-dev | ||
spec: | ||
secretStoreRef: | ||
kind: SecretStore | ||
# The name of your SecretStore | ||
name: azure-key-vault | ||
target: | ||
# The name of the Secret in OpenShift. | ||
# It will be created if it does not already exist. | ||
name: my-app-1 | ||
data: | ||
- remoteRef: | ||
# The name of the key in the external secrets system | ||
key: dev-db-user | ||
# The name of the key in the OpenShift secret | ||
secretKey: db-user | ||
- remoteRef: | ||
key: dev-db-pass | ||
secretKey: db-pass | ||
``` | ||
|
||
For more information when creating an ExternalSecret, use the `oc` CLI, such as: | ||
``` | ||
oc explain externalsecret.spec | ||
``` | ||
|
||
``` | ||
oc explain externalsecret.spec.refreshInterval | ||
``` | ||
|
||
or edit it in the YAML view in the OpenShift UI and click on the the 'View sidebar' link. | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe also mention that Openshift secure is now encrypted, so it's okay to use Openshift secret objects