Skip to content

Commit 6a694d0

Browse files
hc-github-team-secure-vault-coremaxcoulombemickael-hc
authored
Backport of Docs/vault 23837/sync doc update into release/1.16.x (#26058)
* Docs/vault 23837/sync doc update (#25433) * + documented the new sync API options * * cherry-pick * address review comments * move statuses into a table for consistency * fix merge conflicts --------- Co-authored-by: Max Coulombe <[email protected]> Co-authored-by: mickael-hc <[email protected]> Co-authored-by: maxcoulombe <[email protected]>
1 parent 84bc41c commit 6a694d0

File tree

3 files changed

+475
-19
lines changed

3 files changed

+475
-19
lines changed

website/content/api-docs/system/secrets-sync.mdx

+134-1
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,16 @@ This endpoint creates a destination to synchronize action secrets with a GitHub
424424

425425
- `name` `(string: <required>)` - Specifies the name for this destination. This is specified as part of the URL.
426426

427-
- `access_token` `(string: <required>)` - Fine-grained or personal access token.
427+
- `access_token` `(string: <optional>)` - Fine-grained or personal access token.
428+
Use `access_token` as an alternative to authenticating with a GitHub app.
429+
430+
- `app_name` `(string: <optional>)` - The name of a GitHub App configured in Vault to use for
431+
authentication. Use `app_name` and `installation_id` as an alternative to
432+
authenticating with an access token.
433+
434+
- `installation_id` `(string: <optional>)` - The installation ID of the GitHub
435+
app to use for authentication. Required when using `app_name` for
436+
authentication.
428437

429438
- `repository_owner` `(string: <required>)` - GitHub organization or username that owns the repository. For example, if a repository is located at https://github.com/hashicorp/vault.git the owner is hashicorp.
430439

@@ -826,3 +835,127 @@ $ curl \
826835
"auth": null
827836
}
828837
```
838+
839+
## Configure a custom GitHub app
840+
841+
Use the `POST` operation with `sys/sync/github-apps` endpoint to configure a
842+
custom GitHub application for syncing secrets with GitHub repositories.
843+
844+
845+
| Method | Path |
846+
|:-------|:-----------------------------|
847+
| `POST` | `sys/sync/github-apps/:name` |
848+
849+
850+
### Parameters
851+
852+
- `name` `(string: <required>)` - Specifies a custom name for the GitHub
853+
application that is used when configuring the destination. Although this can be any name, we recommend using the same app name configured in GitHub.
854+
855+
- `app_id` `(string: <required>)` - Specifies the GitHub application ID, provided by GitHub.
856+
857+
- `private_key` `(string: <required>)` - Specifies the private key used to authenticate with the GitHub application.
858+
859+
### Sample payload
860+
```json
861+
{
862+
"app_id": "true",
863+
"private_key": "<PRIVATE KEY PEM>"
864+
}
865+
```
866+
867+
### Sample requests
868+
869+
```shell-session
870+
$ curl \
871+
--header "X-Vault-Token: ..." \
872+
--request POST \
873+
--data @payload.json
874+
http://127.0.0.1:8200/v1/sys/sync/github-apps/my-custom-app
875+
```
876+
877+
878+
### Sample response
879+
880+
```json
881+
{
882+
"request_id": "uuid",
883+
"data": {
884+
"app_id": 123456,
885+
"fingerprint": "<fingerprint>",
886+
"name": "my-custom-app",
887+
"private_key": "*****"
888+
},
889+
"mount_type": "system"
890+
}
891+
```
892+
893+
## Read custom GitHub app
894+
895+
Use the `GET` operation with `sys/sync/github-apps` to view details about the
896+
configured GitHub application.
897+
898+
899+
| Method | Path |
900+
|:-------|:-----------------------------|
901+
| `GET` | `sys/sync/github-apps/:name` |
902+
903+
904+
### Parameters
905+
906+
- `name` `(string: <required>)` - Specifies a custom name for the GitHub application.
907+
908+
909+
### Sample requests
910+
911+
```shell-session
912+
$ curl \
913+
--header "X-Vault-Token: ..." \
914+
--request GET \
915+
http://127.0.0.1:8200/v1/sys/sync/github-apps/my-custom-app
916+
```
917+
918+
919+
### Sample response
920+
921+
```json
922+
{
923+
"request_id": "uuid",
924+
"data": {
925+
"app_id": 123456,
926+
"fingerprint": "<fingerprint>",
927+
"name": "my-custom-app",
928+
"private_key": "*****"
929+
},
930+
"mount_type": "system"
931+
}
932+
```
933+
934+
## Delete custom GitHub app
935+
936+
Use the `DELETE` operation with `sys/sync/github-apps` to delete a configured
937+
GitHub application.
938+
939+
You cannot delete applications with active authentication destination
940+
references. Deleting an application configuration **does not** delete the GitHub
941+
application from GitHub.
942+
943+
944+
| Method | Path |
945+
|:---------|:-----------------------------|
946+
| `DELETE` | `sys/sync/github-apps/:name` |
947+
948+
949+
### Parameters
950+
951+
- `name` `(string: <required>)` - Specifies a custom name for the GitHub application.
952+
953+
954+
### Sample requests
955+
956+
```shell-session
957+
$ curl \
958+
--header "X-Vault-Token: ..." \
959+
--request DELETE \
960+
http://127.0.0.1:8200/v1/sys/sync/github-apps/my-custom-app
961+
```

website/content/docs/sync/github.mdx

+98-6
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,23 @@ to connect directly with Vault. This guide walks you through the configuration p
1212

1313
Prerequisites:
1414
* Ability to read or create KVv2 secrets
15-
* Ability to create GitHub fine-grained or personal tokens with access to modify repository secrets
15+
* Ability to create GitHub fine-grained or personal tokens (or a GitHub application) with access to modify repository secrets
1616
* Ability to create sync destinations and associations on your Vault server
1717

1818
## Setup
1919

20-
1. To get started with syncing Vault secrets to your GitHub repository, you will need an
20+
1. To get started with syncing Vault secrets to your GitHub repository, you will need a configured [GitHub application](#github-application) or an
2121
[access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens)
2222
which has access to the repository you want to manage secrets for and write permissions on the repository's actions secrets.
2323
In the list of GitHub permissions, this is simply called "Secrets". Choosing this will automatically include read-only Metadata.
2424

25-
1. Configure a sync destination with the access token created in the previous step.
25+
<Warning title="Pitfalls of using an access token">
26+
Access tokens are tied to a user account and can be revoked at any time, causing disruptions to the sync process.
27+
GitHub applications are long-lived and do not expire. Using a GitHub application for authentication is preferred over using a personal access token.
28+
</Warning>
29+
30+
31+
If you decide to go with an access token, here's how you can configure a sync destination:
2632

2733
```shell-session
2834
$ vault write sys/sync/destinations/gh/my-dest \
@@ -122,12 +128,13 @@ or the association in Vault will delete the secret in GitHub as well.
122128
<Note>
123129

124130
GitHub only supports single value secrets, so KVv2 secrets from Vault will be stored as a JSON string.
125-
In the example above, the value for secret "my-secret" will be synced to GitHub as the JSON string `{"foo":"bar"}`.
131+
In the example above, the value for secret "my-secret" will be synced to GitHub as the JSON string `{"foo":"bar"}` if the
132+
destination is configured to use the `secret-path` [granularity level](/vault/docs/sync#granularity).
126133

127134
</Note>
128135

129-
It is strongly advised to mask individual values for each sub-key to prevent the unintended disclosure of secrets
130-
in any GitHub Action outputs. The following snippet illustrates how to mask each secret values:
136+
If using the secret-path granularity, it is strongly advised to mask individual values for each sub-key to prevent the
137+
unintended disclosure of secrets in any GitHub Action outputs. The following snippet illustrates how to mask each secret values:
131138

132139
```yaml
133140
name: Mask synced secret values
@@ -146,6 +153,91 @@ in any GitHub Action outputs. The following snippet illustrates how to mask each
146153
done
147154
```
148155
156+
If the GitHub destination uses the default `secret-key` granularity, the values are masked by GitHub automatically.
157+
158+
## GitHub application
159+
160+
Instead of authenticating with a personal access token, you can choose to
161+
authenticate with a
162+
[custom GitHub application](https://docs.github.com/en/apps/creating-github-apps/registering-a-github-app/registering-a-github-app).
163+
164+
Start by following the GitHub instructions for
165+
[installing a GitHub app](https://docs.github.com/en/apps/using-github-apps/installing-your-own-github-app).
166+
to install your GitHub application on a specified repository and note the
167+
assigned installation ID.
168+
169+
<Tip title="Your installation ID is in the app URL">
170+
171+
You can find your assigned installation ID in the URL path parameter:
172+
`https://github.com/settings/installations/<INSTALLATION_ID>`
173+
174+
</Tip>
175+
176+
Then add your GitHub application to your Vault instance.
177+
178+
To use your GitHub application with Vault:
179+
180+
- the application must have permission to read and write secrets.
181+
- you must generate a private key for the application on GitHub.
182+
- the application must be installed on the repository you want to sync secrets with.
183+
- you must know the application ID assigned by GitHub.
184+
- you must know the installation ID assigned by GitHub.
185+
186+
Callback, redirect URLs, and webhooks are not required at this time.
187+
188+
To configure the application in Vault, use `vault write` with the
189+
`sys/sync/github-apps` endpoint to assign a unique name and set the relevant
190+
information:
191+
192+
<CodeBlockConfig hideClipboard>
193+
194+
```shell-session
195+
$ vault write sys/sync/github-apps/<APP_NAME> \
196+
app_id=<APP_ID> \
197+
private_key=<PATH_TO_PRIVATE_KEY>
198+
199+
Key Value
200+
--- -----
201+
app_id <app-id>
202+
fingerprint <fingerprint>
203+
name <app-name>
204+
private_key *****
205+
```
206+
</CodeBlockConfig>
207+
208+
<Tip title="Fingerprint verification">
209+
210+
Vault returns the fingerprint of the private_key provided to ensure that the
211+
correct private key was configured and that it was not tampered with along the way.
212+
You can compare the fingerprint to the one provided by GitHub.
213+
For more information, see [Verifying private keys](https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/managing-private-keys-for-github-apps#verifying-private-keys).
214+
215+
</Tip>
216+
217+
218+
Next, use `vault write` with the `sys/sync/destinations/gh` endpoint to
219+
configure a GitHub destination that references your new GitHub application:
220+
221+
<CodeBlockConfig hideClipboard>
222+
223+
```shell-session
224+
$ vault write sys/sync/destinations/gh/<DESTINATION_NAME> \
225+
installation_id=<INSTALLATION_ID> \
226+
repository_owner=<GITHUB_USER> \
227+
repository_name=<MY_REPO_NAME> \
228+
app_name=<APP_NAME>
229+
230+
Key Value
231+
--- -----
232+
connection_details map[app_config:map[app_name:<app-name>] installation_id:<installation-id> repository_name:<repo-name> repository_owner:<repo-owner>]
233+
name my-dest
234+
options map[custom_tags:map[] granularity_level:secret-key secret_name_template:VAULT_{{ .MountAccessor | uppercase }}_{{ .SecretPath | uppercase }}_{{ .SecretKey | uppercase }}]
235+
type gh
236+
```
237+
</CodeBlockConfig>
238+
239+
You can now [use your GitHub application to sync secrets with your GitHub repository](#usage).
240+
149241
## API
150242

151243
Please see the [secrets sync API](/vault/api-docs/system/secrets-sync) for more details.

0 commit comments

Comments
 (0)