-
Notifications
You must be signed in to change notification settings - Fork 9
/
Makefile
193 lines (151 loc) · 5.73 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# Metadata about this makefile and position
MKFILE_PATH := $(lastword $(MAKEFILE_LIST))
CURRENT_DIR := $(patsubst %/,%,$(dir $(realpath $(MKFILE_PATH))))
# List of tests to run
TEST ?= $$(go list ./... | grep -v /vendor/ | grep -v /e2e)
TEST_TIMEOUT?=20m
GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor)
#Plugin information
PLUGIN_NAME := venafi-pki-monitor
PLUGIN_DIR := pkg/bin
PLUGIN_PATH := $(PLUGIN_DIR)/$(PLUGIN_NAME)
DIST_DIR := pkg/dist
VERSION=`git describe --abbrev=0 --tags`
ifdef BUILD_NUMBER
VERSION:=$(VERSION)+$(BUILD_NUMBER)
endif
ifdef RELEASE_VERSION
ifneq ($(RELEASE_VERSION),none)
VERSION=$(RELEASE_VERSION)
endif
endif
#test demo vars
IMPORT_DOMAIN := import.example.com
IMPORT_ROLE := import
MOUNT := pki
RANDOM_SITE_EXP := $$(head /dev/urandom | docker run --rm -i busybox tr -dc a-z0-9 | head -c 5 ; echo '')
ROLE_OPTIONS := generate_lease=true ttl=1h max_ttl=1h
SHA256 := $$(shasum -a 256 "$(PLUGIN_PATH)" | cut -d' ' -f1)
TRUST_BUNDLE := /opt/venafi/bundle.pem
#Docker vars
VAULT_CONT := $$(docker-compose ps |grep Up|grep vault_1|awk '{print $$1}')
DOCKER_CMD := docker exec -it $(VAULT_CONT)
VAULT_CMD := $(DOCKER_CMD) vault
SHA256_DOCKER_CMD := sha256sum "/vault_plugin/$(PLUGIN_NAME)" | cut -d' ' -f1
### Exporting variables for demo and tests
.EXPORT_ALL_VARIABLES:
VAULT_ADDR = http://127.0.0.1:8200
#Must be set,otherwise cloud certificates will timeout
VAULT_CLIENT_TIMEOUT = 180s
test: linter
VAULT_ACC=1 \
go get gotest.tools/gotestsum
gotestsum --junitfile junit.xml -- -timeout $(TEST_TIMEOUT) ./...
policy_test:
go test github.com/Venafi/vault-pki-monitor-venafi/plugin/pki -run ^TestBackend_VenafiPolicy*$
fmt:
gofmt -w $(GOFMT_FILES)
fmtcheck:
@sh -c "'$(CURDIR)/scripts/gofmtcheck.sh'"
#Need to unset VAULT_TOKEN when running vault with dev parameter.
unset:
unset VAULT_TOKEN
#Developement server tasks
dev_server: unset
pkill vault || echo "Vault server is not running"
vault server -log-level=debug -dev -config=vault-config.hcl
dev: dev_build mount_dev
import: ca import_config_write import_config_read import_cert_write
ca:
vault write $(MOUNT)/root/generate/internal \
common_name=my-website.com \
ttl=8760h
#Build
clean:
rm -rf $(PLUGIN_DIR)
rm -rf $(DIST_DIR)
rm -rf artifacts
build: build_strict build_optional
build_strict:
scripts/build.sh $(PLUGIN_NAME) $(PLUGIN_DIR) $(DIST_DIR) strict $(VERSION)
build_optional:
scripts/build.sh $(PLUGIN_NAME) $(PLUGIN_DIR) $(DIST_DIR) optional $(VERSION)
dev_build:
sed -i 's/const venafiPolicyDenyAll =.*/const venafiPolicyDenyAll = true/' plugin/pki/vcert.go
env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags '$(LDFLAGS_STRICT)' -a -o $(PLUGIN_DIR)/$(PLUGIN_NAME) || exit 1
mount_dev: unset
vault write sys/plugins/catalog/$(PLUGIN_NAME) sha_256="$(SHA256)" command="$(PLUGIN_NAME)"
vault secrets disable $(MOUNT) || echo "Secrets already disabled"
vault secrets enable -path=$(MOUNT) -plugin-name=$(PLUGIN_NAME) plugin
import_config_write:
vault write $(MOUNT)/roles/$(IMPORT_ROLE) \
venafi_import="true" \
tpp_url=$(TPP_URL) \
tpp_user=$(TPP_USER) \
tpp_password=$(TPP_PASSWORD) \
zone="$(TPP_ZONE)" \
$(ROLE_OPTIONS) \
allowed_domains=$(IMPORT_DOMAIN) \
allow_subdomains=true \
trust_bundle_file=$(TRUST_BUNDLE) \
import_timeout=15 \
import_workers=5
import_config_read:
vault read $(MOUNT)/roles/$(IMPORT_ROLE)
import_cert_write:
$(eval RANDOM_SITE := $(shell echo $(RANDOM_SITE_EXP)))
@echo "Issuing import-$(RANDOM_SITE).$(IMPORT_DOMAIN)"
vault write $(MOUNT)/issue/$(IMPORT_ROLE) common_name="import-$(RANDOM_SITE).$(IMPORT_DOMAIN)" alt_names="alt-$(RANDOM_SITE).$(IMPORT_DOMAIN),alt2-$(RANDOM_SITE).$(IMPORT_DOMAIN)"
collect_artifacts:
rm -rf artifacts
mkdir -p artifacts
cp -rv $(DIST_DIR)/*.zip artifacts
release:
echo '```' > release.txt
cd artifacts; sha256sum * >> ../release.txt
echo '```' >> release.txt
go get -u github.com/tcnksm/ghr
ghr -prerelease -n $$RELEASE_VERSION -body="$$(cat ./release.txt)" $$RELEASE_VERSION artifacts/
#Docker server with consul
docker_server_prepare:
@echo "Using vault client version $(VAULT_VERSION)"
ifeq ($(VAULT_VERSION),v0.10.3)
@echo "Vault version v0.10.3 have bug which prevents plugin to work properly. Please update your vault client"
@exit 1
endif
docker_server_up:
docker-compose up -d --build
@echo "Run: docker-compose logs"
@echo "to see the logs"
@echo "Run: docker exec -it cault_vault_1 sh"
@echo "to login into vault container"
@echo "Waiting until server start"
sleep 10
docker_server_init:
$(VAULT_CMD) operator init -key-shares=1 -key-threshold=1
@echo "To unseal the vault run:"
@echo "$(VAULT_CMD) operator unseal UNSEAL_KEY"
docker_server_unseal:
@echo Enter unseal key:
$(VAULT_CMD) operator unseal
docker_server_login:
@echo Enter root token:
$(VAULT_CMD) login
docker_server_down:
docker-compose down --remove-orphans
docker_server_logs:
docker-compose logs -f
docker_server_sh:
$(DOCKER_CMD) sh
docker_server: docker_server_prepare docker_server_down docker_server_up docker_server_init docker_server_unseal docker_server_login mount_docker
@echo "Vault started. To run make command export VAULT_TOKEN variable and run make with -e flag, for example:"
@echo "export VAULT_TOKEN=enter-root-token-here"
@echo "make cloud -e"
mount_docker:
$(eval SHA256 := $(shell echo $$($(DOCKER_CMD) $(SHA256_DOCKER_CMD))))
$(VAULT_CMD) write sys/plugins/catalog/$(PLUGIN_NAME) sha_256="$$SHA256" command="$(PLUGIN_NAME)"
$(VAULT_CMD) secrets disable $(MOUNT) || echo "Secrets already disabled"
$(VAULT_CMD) secrets enable -path=$(MOUNT) -plugin-name=$(PLUGIN_NAME) plugin
linter:
@golangci-lint --version || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b /go/bin
golangci-lint run --timeout 3m0s