Skip to content

Commit 1486a04

Browse files
committed
New: Initial commit
0 parents  commit 1486a04

File tree

18 files changed

+1664
-0
lines changed

18 files changed

+1664
-0
lines changed

.github/workflows/release.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: CI/CD
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
workflow_dispatch:
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
name: Run tests
14+
steps:
15+
- uses: actions/checkout@v2
16+
- uses: actions/setup-go@v2
17+
with:
18+
go-version: '^1.15.0'
19+
- run: go version
20+
- run: make test
21+
22+
release:
23+
needs: test
24+
if: ${{ github.event_name == 'workflow_dispatch' }}
25+
runs-on: ubuntu-latest
26+
name: Release a new version
27+
env:
28+
CLI_DIST_BRANCH: ${GITHUB_REF#refs/heads/}
29+
steps:
30+
- uses: actions/checkout@v2
31+
- uses: actions/setup-go@v2
32+
with:
33+
go-version: '^1.15.0'
34+
- uses: actions/setup-node@v1
35+
with:
36+
node-version: '15'
37+
- run: npm install
38+
- run: npx semantic-release
39+
env:
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/artifacts/
2+
/bin/
3+
/node_modules/

.releaserc.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
plugins:
2+
-
3+
- '@semantic-release/commit-analyzer'
4+
- preset: eslint
5+
-
6+
- '@semantic-release/release-notes-generator'
7+
- preset: eslint
8+
-
9+
- '@semantic-release/changelog'
10+
- changelogFile: CHANGELOG.md
11+
-
12+
- '@semantic-release/exec'
13+
- prepareCmd: >
14+
make CLI_DIST_VERSION=${nextRelease.gitTag} dist
15+
-
16+
- '@semantic-release/git'
17+
- assets:
18+
- CHANGELOG.md
19+
message: >
20+
Chore: Release ${nextRelease.version}
21+
22+
${nextRelease.notes}
23+
-
24+
- '@semantic-release/github'
25+
- assets:
26+
- 'artifacts/*'
27+
successComment: false
28+
failComment: false
29+
releasedLabels: false

LICENSE

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Copyright (c) 2020 EvenNode
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is furnished
8+
to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
17+
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Makefile

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#
2+
# Commands
3+
#
4+
5+
export GIT ?= git
6+
export GO ?= go
7+
export MKDIR_P ?= mkdir -p
8+
export RM ?= rm -f
9+
export SHA256SUM ?= shasum -a 256
10+
export TAR ?= tar
11+
export ZIP_M ?= zip -m
12+
13+
#
14+
# Variables
15+
#
16+
17+
GOFLAGS ?=
18+
19+
CLI_DIST_TARGETS ?= $(addprefix dist-bin-,darwin-amd64 windows-amd64 windows-386 linux-amd64 linux-386 linux-arm64 linux-arm freebsd-amd64 freebsd-386 freebsd-arm netbsd-amd64 netbsd-386 openbsd-amd64 openbsd-386 solaris-amd64)
20+
21+
#
22+
#
23+
#
24+
25+
export CLI_DIST_NAME := vault-plugin-secrets-oauth-client-credentials
26+
export CLI_DIST_VERSION ?= $(shell $(GIT) describe --tags --always --dirty)
27+
28+
export ARTIFACTS_DIR := artifacts
29+
export BIN_DIR := bin
30+
31+
#
32+
# Targets
33+
#
34+
35+
.PHONY: all
36+
all: build
37+
38+
$(ARTIFACTS_DIR) $(BIN_DIR):
39+
$(MKDIR_P) $@
40+
41+
.PHONY: generate
42+
generate:
43+
$(GO) generate ./...
44+
45+
.PHONY: build
46+
build: generate $(BIN_DIR)
47+
$(GO) build $(GOFLAGS) -o $(BIN_DIR)/$(CLI_DIST_NAME) ./cmd/oauth
48+
49+
.PHONY: test
50+
test: generate
51+
$(GO) test $(GOFLAGS) ./...
52+
53+
.PHONY: dist
54+
dist: $(CLI_DIST_TARGETS)
55+
56+
.PHONY: clean
57+
clean:
58+
$(RM) -r $(ARTIFACTS_DIR)/
59+
$(RM) -r $(BIN_DIR)/
60+
61+
.PHONY: $(CLI_DIST_TARGETS)
62+
$(CLI_DIST_TARGETS): export CGO_ENABLED = 0
63+
$(CLI_DIST_TARGETS): export GOFLAGS += -a
64+
$(CLI_DIST_TARGETS): export GOOS = $(word 1,$(subst -, ,$*))
65+
$(CLI_DIST_TARGETS): export GOARCH = $(subst $(CLI_EXT_$(GOOS)),,$(word 2,$(subst -, ,$*)))
66+
$(CLI_DIST_TARGETS): export LDFLAGS += -extldflags "-static"
67+
$(CLI_DIST_TARGETS): dist-bin-%: $(ARTIFACTS_DIR)
68+
@scripts/dist

README.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# vault-plugin-secrets-oauth-client-credentials
2+
3+
This is a standalone secrets engine plugin for use with [Hashicorp
4+
Vault](https://www.github.com/hashicorp/vault).
5+
6+
This plugin provides a secure wrapper around OAuth 2 authorization client credentials grant, also know as 2-legged OAuth which does not require authorization.
7+
Client credentials grant is used by clients to obtain an access token outside of the context of a user. This is typically used by clients to access resources about themselves rather than to access a user's resources.
8+
9+
## Usage
10+
11+
Download plugin's binary and [register the plugin with Vault](https://www.vaultproject.io/docs/internals/plugins.html#plugin-registration). We will assume it is registered under the name
12+
`oauthapp`.
13+
14+
Mount the plugin at the path of your choosing:
15+
16+
```console
17+
$ vault secrets enable -path=oauth2/my-provider oauthapp
18+
Success! Enabled the oauthapp secrets engine at: oauth2/my-provider/
19+
```
20+
21+
Configure it with the necessary information to exchange tokens. Token URL shall point to an endpoint for obtaining tokens from your provider (it usually ends with `/token`).
22+
23+
```console
24+
$ vault write oauth2/my-provider/config \
25+
client_id=hOEvqqbHVlSNpuvY \
26+
client_secret=6q2xrjZOJ1R9MfUvUxJzFAk \
27+
token_url=https://example.com/token \
28+
scopes=read.user,read.org
29+
Success! Data written to: oauth2/my-provider/config
30+
```
31+
32+
Once the client secret has been written, it will never be exposed again.
33+
34+
To retrieve a token, read from the `/creds/:name` endpoint. The `name` identifier can be any arbitrary string.
35+
36+
```console
37+
$ vault read oauth2/my-provider/creds/my-user
38+
Key Value
39+
--- -----
40+
access_token RRcJk5r2BBUKsIquXaoVJfnSUX6uTkVReSaEthrgJmd8p9xlWPD0d0ADFgW5p6Glki5UNGEBGr6hWCEu
41+
expires 2020-10-25T13:43:56.6282713+01:00
42+
```
43+
44+
You can override default scopes by specifying `scopes` parameter. This returns a new token with a new scope.
45+
```console
46+
$ vault read oauth2/my-provider/creds/my-user scopes=write.user,write.org
47+
Key Value
48+
--- -----
49+
access_token vy7f9quvazKypM4FJ4WQMLCHkUEcDb2Z3ZifSWMi94Ur40Z3xf13dOj6Cydkp7vdoNRLQD2eOMFy0r2L
50+
expires 2020-10-25T13:44:07.1123581+01:00
51+
```
52+
53+
The client secret is never exposed to Vault clients.
54+
55+
56+
## Endpoints
57+
58+
### `config`
59+
60+
#### `GET` (`read`)
61+
62+
Retrieve the current configuration settings (except the client secret).
63+
64+
#### `PUT` (`write`)
65+
66+
Write new configuration settings. This endpoint completely replaces the existing
67+
configuration.
68+
69+
| Name | Description | Type | Default | Required |
70+
|------|-------------|------|---------|----------|
71+
| `client_id` | The OAuth 2.0 client ID. | String | None | Yes |
72+
| `client_secret` | The OAuth 2.0 client secret. | String | None | Yes |
73+
| `token_url` | URL to obtain access tokens. | String | None | Yes |
74+
| `scopes` | Comma separated list of default explicit scopes. | List of String | None | No |
75+
76+
#### `DELETE` (`delete`)
77+
78+
Remove the current configuration. This does not invalidate any existing access
79+
tokens.
80+
81+
### `creds/:name`
82+
83+
#### `GET` (`read`)
84+
85+
Retrieve a current access token for the given credential.
86+
87+
| Name | Description | Type | Default | Required |
88+
|------|-------------|------|---------|----------|
89+
| `scopes` | A comma separated list of explicit scopes to override default scopes from config. If not specified, default `scopes` from config are used. | List of String | None | No |
90+
91+
#### `DELETE` (`delete`)
92+
93+
Remove the credential information from storage. This removes all scopes identified by the credential's `name`.

cmd/oauth/main.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package main
2+
3+
import (
4+
"os"
5+
6+
"github.com/evennode/vault-plugin-secrets-oauth-client-credentials/pkg/backend"
7+
"github.com/hashicorp/go-hclog"
8+
"github.com/hashicorp/vault/api"
9+
"github.com/hashicorp/vault/sdk/plugin"
10+
)
11+
12+
func main() {
13+
meta := &api.PluginAPIClientMeta{}
14+
15+
flags := meta.FlagSet()
16+
flags.Parse(os.Args[1:])
17+
18+
err := plugin.Serve(&plugin.ServeOpts{
19+
BackendFactoryFunc: backend.Factory,
20+
TLSProviderFunc: api.VaultPluginTLSProvider(meta.GetTLSConfig()),
21+
})
22+
if err != nil {
23+
logger := hclog.New(&hclog.LoggerOptions{})
24+
25+
logger.Error("plugin shutting down", "error", err)
26+
os.Exit(1)
27+
}
28+
}

go.mod

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module github.com/evennode/vault-plugin-secrets-oauth-client-credentials
2+
3+
go 1.15
4+
5+
require (
6+
github.com/hashicorp/go-hclog v0.14.1
7+
github.com/hashicorp/vault/api v1.0.4
8+
github.com/hashicorp/vault/sdk v0.1.14-0.20190909201848-e0fbf9b652e2
9+
github.com/stretchr/testify v1.6.1
10+
golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43
11+
)

0 commit comments

Comments
 (0)