-
Notifications
You must be signed in to change notification settings - Fork 187
Add secrets manager integration for credential retrieval #897
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
Changes from all commits
Commits
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
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,125 @@ | ||
| # Secrets Manager | ||
|
|
||
| Perceval supports retrieving credentials from a secrets manager instead of | ||
| passing them directly on the command line. This is useful for automated | ||
| pipelines and environments where storing credentials in plain text is not | ||
| acceptable. | ||
|
|
||
| The following backends support secrets manager authentication: `bugzilla`, | ||
| `bugzillarest`, `confluence`, `discourse`, `gerrit`, `git`, `github`, | ||
| `gitlab`, `gitter`, `googlehits`, `groupsio`, `jenkins`, `rocketchat`, | ||
| `stackexchange`. | ||
|
|
||
| ## Installation | ||
|
|
||
| To use **HashiCorp Vault**, install Perceval with the `hashicorp-manager` group: | ||
|
|
||
| ``` | ||
| $ poetry install --with hashicorp-manager | ||
| ``` | ||
|
|
||
| **Bitwarden** does not require any extra Python package, but the | ||
| [Bitwarden CLI](https://bitwarden.com/help/cli/) (`bw`) must be installed | ||
| and available on your `PATH`. | ||
|
|
||
| ## Common arguments | ||
|
|
||
| All secrets manager providers share the following arguments: | ||
|
|
||
| - `--secrets-manager` — Provider to use: `bitwarden` or `hashicorp` | ||
| - `--secret-name` — Name of the secret entry in the secrets manager | ||
|
|
||
| Credentials must be stored in the vault using the same field names that | ||
| Perceval expects: `user`, `password`, `api_token`, `email`, `access_token`, | ||
| `user_id`. Perceval automatically looks up all of these fields and uses | ||
| whichever ones are present. | ||
|
|
||
| ## Expected field names | ||
|
|
||
| Store your credentials in the vault using these exact names: | ||
|
|
||
| - `api_token` — used by `github`, `gitlab`, `bugzillarest`, `stackexchange`, `gitter` | ||
| - `user` — used by `bugzilla`, `confluence`, `discourse`, `gerrit`, `jenkins` | ||
| - `password` — used by `bugzilla`, `confluence`, `discourse`, `gerrit`, `jenkins` | ||
| - `email` — used by `groupsio` | ||
| - `access_token` — used by `groupsio` | ||
| - `user_id` — used by `rocketchat` | ||
|
|
||
| Only the fields present in the vault are used; the rest are silently ignored. | ||
|
|
||
| ## Bitwarden | ||
|
|
||
| Store your credentials in a Bitwarden item using Perceval's expected field | ||
| names. Fields can be stored as login fields or as custom fields. | ||
|
|
||
| For example, to store a GitHub API token, create a Bitwarden item named | ||
| `GitHub` with a custom field named `api_token` containing the token value. | ||
|
|
||
| Bitwarden-specific arguments: | ||
|
|
||
| - `--bw-client-id` — Bitwarden API client ID | ||
| - `--bw-client-secret` — Bitwarden API client secret | ||
| - `--bw-master-password` — Bitwarden master password | ||
|
|
||
| ### Example | ||
| ``` | ||
| $ perceval github \ | ||
| --secrets-manager bitwarden \ | ||
| --secret-name 'GitHub' \ | ||
| --bw-client-id $BW_CLIENT_ID \ | ||
| --bw-client-secret $BW_CLIENT_SECRET \ | ||
| --bw-master-password $BW_MASTER_PASSWORD \ | ||
| --from-date '2020-01-01' --no-archive \ | ||
| chaoss grimoirelab-perceval | ||
| ``` | ||
|
|
||
| ## HashiCorp Vault | ||
|
|
||
| Store your credentials as key-value pairs in a HashiCorp Vault KV secret | ||
| using Perceval's expected field names. | ||
|
|
||
| For example, to store a GitHub API token: | ||
| ``` | ||
| $ vault kv put secret/GitHub api_token=ghp_xxxxxxxxxxxx | ||
| ``` | ||
|
|
||
| HashiCorp-specific arguments: | ||
|
|
||
| - `--vault-url` — HashiCorp Vault server URL | ||
| - `--vault-token` — Vault authentication token | ||
| - `--vault-certificate` — Path to CA certificate for TLS verification (optional) | ||
|
|
||
| ### Example | ||
| ``` | ||
| $ perceval github \ | ||
| --secrets-manager hashicorp \ | ||
| --secret-name 'GitHub' \ | ||
| --vault-url $VAULT_URL \ | ||
| --vault-token $VAULT_TOKEN \ | ||
| --from-date '2020-01-01' --no-archive \ | ||
| chaoss grimoirelab-perceval | ||
| ``` | ||
|
|
||
| ## Programmatic usage | ||
|
|
||
| The credential resolution logic is also available in `grimoirelab-toolkit` | ||
| via the `CredentialManager` base class, so it can be used from any Python | ||
| code without going through the CLI: | ||
|
|
||
| ```python | ||
| from grimoirelab_toolkit.credential_manager import BitwardenManager | ||
| from grimoirelab_toolkit.credential_manager.hc_manager import HashicorpManager | ||
|
|
||
| # Bitwarden example | ||
| bw_manager = BitwardenManager("your-client-id", "your-client-secret", "your-master-password") | ||
| credentials = bw_manager.resolve_credentials("GitHub", ["api_token"]) | ||
| print(credentials) # {'api_token': 'ghp_...'} | ||
|
|
||
| # HashiCorp Vault example | ||
| hc_manager = HashicorpManager("https://vault.example.com", "hvs.your-token") | ||
| credentials = hc_manager.resolve_credentials("secret/GitHub", ["api_token"]) | ||
| print(credentials) # {'api_token': 'ghp_...'} | ||
| ``` | ||
|
|
||
| This is useful for consumers like KingArthur or custom scripts that use | ||
| Perceval's `Backend` class directly without the CLI. |
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.