Skip to content

Commit 5b226f5

Browse files
authored
Merge pull request #90421 from zr-msft/ds-k8s-secret-build
[Dev Spaces] added section for doing build time secrets
2 parents c64ea52 + 8f0b15f commit 5b226f5

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

articles/dev-spaces/how-to/manage-secrets.md

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "How to manage secrets when working with an Azure Dev Space"
33
services: azure-dev-spaces
4-
ms.date: "05/11/2018"
4+
ms.date: "12/03/2019"
55
ms.topic: "conceptual"
66
description: "Rapid Kubernetes development with containers and microservices on Azure"
77
keywords: "Docker, Kubernetes, Azure, AKS, Azure Container Service, containers"
@@ -10,7 +10,7 @@ keywords: "Docker, Kubernetes, Azure, AKS, Azure Container Service, containers"
1010

1111
Your services might require certain passwords, connection strings, and other secrets, such as for databases or other secure Azure services. By setting the values of these secrets in configuration files, you can make them available in your code as environment variables. These must be handled with care to avoid compromising the security of the secrets.
1212

13-
Azure Dev Spaces provides two recommended, streamlined options for storing secrets in Helm charts generated by the Azure Dev Spaces client tooling: in the values.dev.yaml file, and inline directly in azds.yaml. It's not recommended to store secrets in values.yaml. Outside of the two approaches for Helm charts generated by the client tooling defined in this article, if you create your own Helm chart, you can use the Helm chart directly to manage and store secrets.
13+
Azure Dev Spaces provides two recommended, streamlined options for storing secrets in Helm charts generated by the Azure Dev Spaces client tooling: in the `values.dev.yaml` file, and inline directly in `azds.yaml`. It's not recommended to store secrets in `values.yaml`. Outside of the two approaches for Helm charts generated by the client tooling defined in this article, if you create your own Helm chart, you can use the Helm chart directly to manage and store secrets.
1414

1515
## Method 1: values.dev.yaml
1616
1. Open VS Code with your project that is enabled for Azure Dev Spaces.
@@ -56,7 +56,7 @@ Azure Dev Spaces provides two recommended, streamlined options for storing secre
5656
7. Make sure that you add _values.dev.yaml_ to the _.gitignore_ file to avoid committing secrets in source control.
5757

5858

59-
## Method 2: Inline directly in azds.yaml
59+
## Method 2: azds.yaml
6060
1. In _azds.yaml_, set secrets under the yaml section configurations/develop/install. Although you can enter secret values directly there, it's not recommended because _azds.yaml_ is checked into source control. Instead, add placeholders using the "$PLACEHOLDER" syntax.
6161

6262
```yaml
@@ -99,6 +99,44 @@ Azure Dev Spaces provides two recommended, streamlined options for storing secre
9999
kubectl get secret --namespace default -o yaml
100100
```
101101

102+
## Passing secrets as build arguments
103+
104+
The previous sections showed how to pass secrets to use at container run time. You can also pass a secret at container build time, such as a password for a private NuGet, using `azds.yaml`.
105+
106+
In `azds.yaml`, set the build time secrets in *configurations.develop.build.args* using the `<variable name>: ${secret.<secret name>.<secret key>}` syntax. For example:
107+
108+
```yaml
109+
configurations:
110+
develop:
111+
build:
112+
dockerfile: Dockerfile.develop
113+
useGitIgnore: true
114+
args:
115+
BUILD_CONFIGURATION: ${BUILD_CONFIGURATION:-Debug}
116+
MYTOKEN: ${secret.mynugetsecret.pattoken}
117+
```
118+
119+
In the above example, *mynugetsecret* is an existing secret and *pattoken* is an existing key.
120+
121+
>[!NOTE]
122+
> Secret names and keys may contain the `.` character. Use `\` to escape `.` when passing secrets as build arguments. For example, to pass a secret named *foo.bar* with the key of *token*: `MYTOKEN: ${secret.foo\.bar.token}`. In addition, secrets can be evaluated with prefix and postfix text. For example, `MYURL: eus-${secret.foo\.bar.token}-version1`. Also, secrets available in parent and grandparent spaces can be passed as build arguments.
123+
124+
In your Dockerfile, use the *ARG* directive to consume the secret, then use that same variable later in the Dockerfile. For example:
125+
126+
```dockerfile
127+
...
128+
ARG MYTOKEN
129+
...
130+
ARG NUGET_EXTERNAL_FEED_ENDPOINTS="{'endpointCredentials': [{'endpoint':'PRIVATE_NUGET_ENDPOINT', 'password':'${MYTOKEN}'}]}"
131+
...
132+
```
133+
134+
Update the services running in your cluster with these changes. On the command line, run the command:
135+
136+
```
137+
azds up
138+
```
139+
102140
## Next steps
103141

104142
With these methods, you can now securely connect to a database, an Azure Cache for Redis, or access secure Azure services.

0 commit comments

Comments
 (0)