Skip to content

Commit fed8e9b

Browse files
committed
chore: fixed Makefile to be able to run the plugin locally
1 parent 2a936ef commit fed8e9b

File tree

3 files changed

+82
-9
lines changed

3 files changed

+82
-9
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,6 @@ tmp/
4040
bin/
4141
/coverage.html
4242
/coverage.out
43-
.envrc
43+
.envrc
44+
/build/
45+
/run/

Makefile

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
SHELL := /bin/bash
22

33
GO ?= go
4+
VAULT ?= vault
45

5-
COVER_PROFILE ?= coverage.out
6-
COVER_HTML ?= coverage.html
6+
COVER_PROFILE ?= $(BUILD_DIR)/coverage.out
7+
COVER_HTML ?= $(BUILD_DIR)/coverage.html
78

89
# Default build tags for tests; can be overridden:
910
# make test TAGS="unit,local"
@@ -13,13 +14,54 @@ TAGS ?= unit,local,saas,selfhosted
1314
# make test TEST_ARGS="-run TestFoo -v"
1415
TEST_ARGS ?=
1516

16-
.PHONY: test coverage clean-coverage
17+
BUILD_DIR ?= build
18+
PLUGIN_CMD ?= vault-plugin-secrets-gitlab
19+
PLUGIN_BIN ?= gitlab
20+
21+
VAULT_PLUGIN_DIR ?= ./run/plugins
22+
VAULT_ROOT_TOKEN ?= root-token
23+
VAULT_ADDR ?= http://127.0.0.1:8200
24+
25+
PLUGIN_NAME ?= gitlab
26+
PLUGIN_TYPE ?= secret
27+
28+
.PHONY: test coverage clean clean-coverage build vault-plugin-enable vault-dev check-go check-vault
29+
30+
check-go:
31+
@command -v "$(GO)" >/dev/null 2>&1 || { \
32+
echo "ERROR: required binary '$(GO)' not found in PATH. Install Go or set GO=<path-to-go>."; \
33+
exit 1; \
34+
}
35+
36+
check-vault:
37+
@command -v "$(VAULT)" >/dev/null 2>&1 || { \
38+
echo "ERROR: required binary '$(VAULT)' not found in PATH. Install Vault or set VAULT=<path-to-vault>."; \
39+
exit 1; \
40+
}
41+
42+
clean:
43+
rm -rf $(BUILD_DIR) $(VAULT_PLUGIN_DIR)
1744

1845
test: coverage
1946

20-
coverage:
21-
$(GO) test ./... -coverprofile=$(COVER_PROFILE) -race -tags $(TAGS) -count 1 $(TEST_ARGS)
47+
coverage: check-go clean-coverage
48+
mkdir -p $(BUILD_DIR)
49+
$(GO) test ./... -cover -coverprofile=$(COVER_PROFILE) -race -tags $(TAGS) -count 1 $(TEST_ARGS)
2250
$(GO) tool cover -html=$(COVER_PROFILE) -o $(COVER_HTML)
2351

2452
clean-coverage:
25-
rm -f $(COVER_PROFILE) $(COVER_HTML)
53+
rm -f $(BUILD_DIR)/$(COVER_PROFILE) $(BUILD_DIR)/$(COVER_HTML)
54+
55+
build: check-go
56+
mkdir -p $(BUILD_DIR)
57+
$(GO) build -trimpath -o $(BUILD_DIR)/$(PLUGIN_BIN) ./cmd/$(PLUGIN_CMD)
58+
59+
vault-plugin-enable: check-vault
60+
export VAULT_ADDR=$(VAULT_ADDR)
61+
export VAULT_TOKEN=$(VAULT_ROOT_TOKEN)
62+
$(VAULT) secrets enable -path="$(PLUGIN_NAME)" "$(PLUGIN_NAME)"
63+
64+
vault-dev: check-vault clean build
65+
mkdir -p $(VAULT_PLUGIN_DIR)
66+
cp -f $(BUILD_DIR)/$(PLUGIN_BIN) $(VAULT_PLUGIN_DIR)/$(PLUGIN_BIN)
67+
$(VAULT) server -dev -dev-root-token-id=$(VAULT_ROOT_TOKEN) -dev-plugin-dir=$(shell pwd)/$(VAULT_PLUGIN_DIR)

README.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ you may or may not be able to access certain paths.
7474
Lists existing configs
7575
7676
^flags$
77-
Flags for the plugins.
77+
Flags for the plugin.
7878
7979
^roles/(?P<role_name>\w(([\w-.]+)?\w)?)$
8080
Create a role with parameters that are used to generate a various access tokens.
8181
8282
^roles?/?$
8383
Lists existing roles
8484
85-
^token/(?P<role_name>\w(([\w-.]+)?\w)?)$
85+
^token/(?P<role_name>\w(([\w-.]+)?\w)?)(/(?P<path>.+))?$
8686
Generate an access token based on the specified role
8787
```
8888
## Flags
@@ -425,3 +425,32 @@ $ vault secrets list -detailed -format=json | jq '."gitlab/"'
425425
## Info
426426
427427
Running the logging with `debug` level will show sensitive information in the logs.
428+
429+
## Local development
430+
431+
Start vault with, this should create a dev server on port 8200
432+
433+
```shell
434+
make vault-dev
435+
```
436+
437+
And then enable the plugin by running:
438+
439+
```shell
440+
make vault-plugin-enable
441+
```
442+
443+
To configure the plugin run:
444+
445+
```shell
446+
vault write gitlab/config/default base_url=http://localhost:8080/ token=glpat-wU8yWBGat-nypZcyf1LL auto_rotate_token=false auto_rotate_before=48h type=self-managed
447+
vault write gitlab/roles/pdp name='{{ .role_name }}-{{ .token_type }}-{{ randHexString 4 }}' path='.*' dynamic_path=true scopes="read_api" token_type=personal ttl=48h
448+
```
449+
450+
Then you can request the token for the role you created:
451+
452+
```shell
453+
vault read gitlab/token/pdp/root
454+
vault read gitlab/token/pdp/admin-user
455+
vault read gitlab/token/pdp/normal-user
456+
```

0 commit comments

Comments
 (0)