-
-
Notifications
You must be signed in to change notification settings - Fork 591
Add external secret extension implementation #6252
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
Show all changes
21 commits
Select commit
Hold shift + click to select a range
a4e4b28
add initial secret extension implementation
mofr93 ff0a90f
format
mofr93 cf46132
Merge branch 'main' into feature/secret-extension
mofr93 d5b183e
fixes. streamline with registry extension. add docs
mofr93 6e276a6
[pre-commit.ci] auto fixes from pre-commit.com hooks [CI SKIP]
pre-commit-ci[bot] 780ad39
fix docs, response and tests
mofr93 40c23e3
add WOODPECKER_SECRET_SERVICE_NETRC flag. add repo-level option too a…
mofr93 1b8b76e
make global and per-repo separate
mofr93 019b3eb
Merge branch 'main' into feature/secret-extension
qwerty287 3c2beb7
fixes
mofr93 600bf91
fix var
mofr93 25ab129
Update docs/docs/20-usage/72-extensions/55-secret-extension.md
mofr93 3081872
Update server/services/secret/combined_test.go
mofr93 3d582d6
fix reviews
qwerty287 bb159f1
fix format
qwerty287 aa3302e
format
qwerty287 78df804
Merge branch 'main' into feature/secret-extension
mofr93 07acba6
Update 10-server.md
qwerty287 d0278e3
Update combined.go
qwerty287 81090ab
Update http.go
qwerty287 59224d4
Fix merge
qwerty287 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
166 changes: 166 additions & 0 deletions
166
docs/docs/20-usage/72-extensions/55-secret-extension.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,166 @@ | ||
| # Secret extension | ||
|
|
||
| Woodpecker uses the secret extension to get secrets from an external service. You can configure an HTTP endpoint in the repository settings in the extensions tab. | ||
|
|
||
| Using such an extension can be useful if you want to: | ||
|
|
||
| - Centralize secret management (e.g. HashiCorp Vault, AWS Secrets Manager) | ||
| - Dynamically generate secrets per pipeline | ||
|
|
||
| ## Security | ||
|
|
||
| :::warning | ||
| As Woodpecker will pass private information like tokens and will execute the returned configuration, it is extremely important to secure the external extension. Therefore Woodpecker signs every request. Read more about it in the security section. | ||
| ::: | ||
|
|
||
| ## Global configuration | ||
|
|
||
| In addition to the ability to configure the extension per repository, you can also configure a global endpoint in the Woodpecker server configuration. This can be useful if you want to use the extension for all repositories. Be careful if | ||
| you share your Woodpecker server with others as they will also use your secret extension. | ||
|
|
||
| If both the global and the repo-level extension return a secret with the same name, it will use the secret from the repo extension. | ||
|
|
||
| ```ini title="Server" | ||
| WOODPECKER_SECRET_EXTENSION_ENDPOINT=https://example.com/secrets | ||
| WOODPECKER_SECRET_EXTENSION_NETRC=false | ||
| ``` | ||
|
|
||
| ## How it works | ||
|
|
||
| When a pipeline is triggered, Woodpecker will fetch secrets from your service. The extension secrets are merged with the secrets configured directly in Woodpecker, with extension secrets taking priority by name. If the extension is unavailable, Woodpecker falls back to the locally configured secrets. | ||
|
|
||
| ### Request | ||
|
|
||
| The extension receives an HTTP POST request with the following JSON payload: | ||
|
|
||
| :::info | ||
| The `netrc` field is only included in the request when the global `WOODPECKER_SECRET_EXTENSION_NETRC` is set to `true` (default: `false`) or the per-repo "Send netrc credentials" is checked. | ||
| ::: | ||
|
|
||
| ```ts | ||
| class Request { | ||
| repo: Repo; | ||
| pipeline: Pipeline; | ||
| netrc?: Netrc; // only included when netrc sending is enabled (see above) | ||
| } | ||
| ``` | ||
|
|
||
| Checkout the following models for more information: | ||
|
|
||
| - [repo model](https://github.com/woodpecker-ci/woodpecker/blob/main/server/model/repo.go) | ||
| - [pipeline model](https://github.com/woodpecker-ci/woodpecker/blob/main/server/model/pipeline.go) | ||
| - [netrc model](https://github.com/woodpecker-ci/woodpecker/blob/main/server/model/netrc.go) | ||
|
|
||
| :::tip | ||
| The `netrc` data is pretty powerful as it contains credentials to access the repository. You can use this to clone the repository or even use the forge (Github or Gitlab, ...) API to get more information about the repository. | ||
| ::: | ||
|
|
||
| Example request: | ||
|
|
||
| ```json | ||
| // Please check the latest structure in the models mentioned above. | ||
| // This example is likely outdated. | ||
|
|
||
| { | ||
| "repo": { | ||
| "id": 100, | ||
| "uid": "", | ||
| "user_id": 0, | ||
| "namespace": "", | ||
| "name": "woodpecker-test-pipeline", | ||
| "slug": "", | ||
| "scm": "git", | ||
| "git_http_url": "", | ||
| "git_ssh_url": "", | ||
| "link": "", | ||
| "default_branch": "", | ||
| "private": true, | ||
| "visibility": "private", | ||
| "active": true, | ||
| "config": "", | ||
| "trusted": false, | ||
| "protected": false, | ||
| "ignore_forks": false, | ||
| "ignore_pulls": false, | ||
| "cancel_pulls": false, | ||
| "timeout": 60, | ||
| "counter": 0, | ||
| "synced": 0, | ||
| "created": 0, | ||
| "updated": 0, | ||
| "version": 0 | ||
| }, | ||
| "pipeline": { | ||
| "author": "myUser", | ||
| "author_avatar": "https://myforge.com/avatars/d6b3f7787a685fcdf2a44e2c685c7e03", | ||
| "author_email": "my@email.com", | ||
| "branch": "main", | ||
| "changed_files": ["some-filename.txt"], | ||
| "commit": "2fff90f8d288a4640e90f05049fe30e61a14fd50", | ||
| "created_at": 0, | ||
| "deploy_to": "", | ||
| "enqueued_at": 0, | ||
| "error": "", | ||
| "event": "push", | ||
| "finished_at": 0, | ||
| "id": 0, | ||
| "link_url": "https://myforge.com/myUser/woodpecker-testpipe/commit/2fff90f8d288a4640e90f05049fe30e61a14fd50", | ||
| "message": "test old config\n", | ||
| "number": 0, | ||
| "parent": 0, | ||
| "ref": "refs/heads/main", | ||
| "refspec": "", | ||
| "clone_url": "", | ||
| "reviewed_at": 0, | ||
| "reviewed_by": "", | ||
| "sender": "myUser", | ||
| "signed": false, | ||
| "started_at": 0, | ||
| "status": "", | ||
| "timestamp": 1645962783, | ||
| "title": "", | ||
| "updated_at": 0, | ||
| "verified": false | ||
| }, | ||
| "netrc": { | ||
| "machine": "myforge.com", | ||
| "login": "myUser", | ||
| "password": "forge-access-token" | ||
| } | ||
| } | ||
| // Note: the "netrc" field is omitted when netrc sending is not enabled. | ||
| ``` | ||
|
|
||
| ### Response | ||
|
|
||
| The extension should respond with a JSON object containing a `secrets` array. | ||
| If the extension wants to keep the existing secrets without adding any, it can respond with HTTP status `204 No Content`. | ||
|
|
||
| ```ts | ||
| class Response { | ||
| secrets: { | ||
| name: string; // the secret name, matched by from_secret in pipeline config | ||
| value: string; // the secret value | ||
| images?: string[]; // optional: restrict to specific plugins | ||
| events?: string[]; // optional: restrict to specific pipeline events | ||
| }[]; | ||
| } | ||
| ``` | ||
|
|
||
| Example response: | ||
|
|
||
| ```json | ||
| { | ||
| "secrets": [ | ||
| { | ||
| "name": "docker_password", | ||
| "value": "your-secret-password-123" | ||
| }, | ||
| { | ||
| "name": "deploy_token", | ||
| "value": "super-secret-token", | ||
| "events": ["push", "tag"] | ||
| } | ||
| ] | ||
| } | ||
| ``` | ||
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.
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.