|
| 1 | +# Secrets |
| 2 | + |
| 3 | +Secrets allow centralized management of sensitive values such as API keys and credentials. They are project-scoped, managed by project admins, and can be referenced in run configurations to pass sensitive values to runs in a secure manner. |
| 4 | + |
| 5 | +!!! info "Secrets encryption" |
| 6 | + By default, secrets are stored in plaintext in the DB. |
| 7 | + Configure [server encryption](../guides/server-deployment.md#encryption) to store secrets encrypted. |
| 8 | + |
| 9 | +## Manage secrets |
| 10 | + |
| 11 | +### Set |
| 12 | + |
| 13 | +Use the `dstack secret set` command to create a new secret: |
| 14 | + |
| 15 | +<div class="termy"> |
| 16 | + |
| 17 | +```shell |
| 18 | +$ dstack secret set my_secret some_secret_value |
| 19 | +OK |
| 20 | +``` |
| 21 | + |
| 22 | +</div> |
| 23 | + |
| 24 | +The same command can be used to update an existing secret: |
| 25 | + |
| 26 | +<div class="termy"> |
| 27 | + |
| 28 | +```shell |
| 29 | +$ dstack secret set my_secret another_secret_value |
| 30 | +OK |
| 31 | +``` |
| 32 | + |
| 33 | +</div> |
| 34 | + |
| 35 | +### List |
| 36 | + |
| 37 | +Use the `dstack secret list` command to list all secrets set in a project: |
| 38 | + |
| 39 | +<div class="termy"> |
| 40 | + |
| 41 | +```shell |
| 42 | +$ dstack secret |
| 43 | + NAME VALUE |
| 44 | + hf_token ****** |
| 45 | + my_secret ****** |
| 46 | + |
| 47 | +``` |
| 48 | + |
| 49 | +</div> |
| 50 | + |
| 51 | +### Get |
| 52 | + |
| 53 | +The `dstack secret list` does not show secret values. To see a secret value, use the `dstack secret get` command: |
| 54 | + |
| 55 | +<div class="termy"> |
| 56 | + |
| 57 | +```shell |
| 58 | +$ dstack secret get my_secret |
| 59 | + NAME VALUE |
| 60 | + my_secret some_secret_value |
| 61 | + |
| 62 | +``` |
| 63 | + |
| 64 | +</div> |
| 65 | + |
| 66 | +### Delete |
| 67 | + |
| 68 | +Secrets can be deleted using the `dstack secret delete` command: |
| 69 | + |
| 70 | +<div class="termy"> |
| 71 | + |
| 72 | +```shell |
| 73 | +$ dstack secret delete my_secret |
| 74 | +Delete the secret my_secret? [y/n]: y |
| 75 | +OK |
| 76 | +``` |
| 77 | + |
| 78 | +</div> |
| 79 | + |
| 80 | +## Use secrets |
| 81 | + |
| 82 | +You can use the `${{ secrets.<secret_name> }}` syntax to reference secrets in run configurations. Currently, secrets interpolation is supported in `env` and `registry_auth` properties. |
| 83 | + |
| 84 | +### `env` |
| 85 | + |
| 86 | +Suppose you need to pass a sensitive environment variable to a run such as `HF_TOKEN`. You'd first create a secret holding the environment variable value: |
| 87 | + |
| 88 | +<div class="termy"> |
| 89 | + |
| 90 | +```shell |
| 91 | +$ dstack secret set hf_token {hf_token_value} |
| 92 | +OK |
| 93 | +``` |
| 94 | + |
| 95 | +</div> |
| 96 | + |
| 97 | +and then reference the secret in `env`: |
| 98 | + |
| 99 | +<div editor-title=".dstack.yml"> |
| 100 | + |
| 101 | +```yaml |
| 102 | +type: service |
| 103 | +env: |
| 104 | + - HF_TOKEN=${{ secrets.hf_token }} |
| 105 | +commands: |
| 106 | + ... |
| 107 | +``` |
| 108 | +
|
| 109 | +</div> |
| 110 | +
|
| 111 | +### `registry_auth` |
| 112 | + |
| 113 | +If you need to pull a private Docker image, you can store registry credentials as secrets and reference them in `registry_auth`: |
| 114 | + |
| 115 | +<div editor-title=".dstack.yml"> |
| 116 | + |
| 117 | +```yaml |
| 118 | +type: service |
| 119 | +image: nvcr.io/nim/deepseek-ai/deepseek-r1-distill-llama-8b |
| 120 | +registry_auth: |
| 121 | + username: $oauthtoken |
| 122 | + password: ${{ secrets.ngc_api_key }} |
| 123 | +``` |
| 124 | + |
| 125 | +</div> |
0 commit comments