-
Notifications
You must be signed in to change notification settings - Fork 10
/
docker-compose.yml
208 lines (186 loc) · 5.27 KB
/
docker-compose.yml
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
version: "3.7"
x-container-common: &container-common
image: consensys/quorum-hashicorp-vault-plugin:latest
networks:
- vault
services:
vault:
<<: *container-common
tty: true
restart: "no"
cap_add:
- IPC_LOCK
environment:
ROOT_TOKEN_PATH: /vault/token/.root
VAULT_ADDR: http://vault:8200
PLUGIN_MOUNT_PATH: quorum
KVV2_MOUNT_PATH: secret
VAULT_IS_READY: /vault/token/.ready
ports:
- 8200:8200
volumes:
- token:/vault/token
- ./scripts/vault-init.sh:/usr/local/bin/init.sh
entrypoint:
- sh
- -c
- |
cat <<EOF > /vault/config.hcl
backend "file" {
path = "/vault/file"
}
listener "tcp" {
address = "vault:8200"
tls_disable = true
}
default_lease_ttl = "15m"
max_lease_ttl = "30m"
api_addr = "http://vault:8200"
plugin_directory = "/vault/plugins"
log_level = "Debug"
EOF
( sleep 2 ; init.sh && cat > $${VAULT_IS_READY}) &
vault server -config=/vault/config.hcl
healthcheck:
test: [ "CMD", "wget", "--spider", "--proxy", "off", "http://localhost:8200/v1/sys/health?standbyok=true" ]
interval: 10s
timeout: 3s
retries: 10
start_period: 5s
vault-ssl:
<<: *container-common
tty: true
container_name: vault
restart: "no"
cap_add:
- IPC_LOCK
ports:
- 8200:8200
depends_on:
- generate-certs
volumes:
- token:/vault/token
- tls:/vault/tls
- ./scripts/vault-init.sh:/usr/local/bin/init.sh
environment:
ROOT_TOKEN_PATH: /vault/token/.root
VAULT_ADDR: https://vault:8200
PLUGIN_MOUNT_PATH: quorum
VAULT_IS_READY: /vault/token/.ready
VAULT_CACERT: ${VAULT_CACERT-/vault/tls/ca.crt}
VAULT_CLIENT_CERT: ${VAULT_CLIENT_CERT-/vault/tls/client.crt}
VAULT_CLIENT_KEY: ${VAULT_CLIENT_KEY-/vault/tls/client.key}
VAULT_SERVER_CERT: ${VAULT_SERVER_CERT-/vault/tls/tls.crt}
VAULT_SERVER_KEY: ${VAULT_SERVER_KEY-/vault/tls/tls.key}
entrypoint:
- sh
- -c
- |
cat <<EOF > /vault/config.hcl
backend "file" {
path = "/vault/file"
}
listener "tcp" {
address = "vault:8200"
tls_disable = false
tls_client_ca_file = "$${VAULT_CACERT}"
tls_cert_file = "$${VAULT_SERVER_CERT}"
tls_key_file = "$${VAULT_SERVER_KEY}"
}
default_lease_ttl = "15m"
max_lease_ttl = "30m"
api_addr = "https://vault:8200"
plugin_directory = "/vault/plugins"
log_level = "Debug"
EOF
until [ -f $${VAULT_SERVER_CERT} ]; do
echo "[INIT] waiting for $${VAULT_SERVER_CERT} to be ready..."
sleep 1
done
( sleep 2 ; init.sh && cat > $${VAULT_IS_READY}) &
vault server -config=/vault/config.hcl
healthcheck:
test: [ "CMD", "wget", "--spider", "--proxy", "off", "https://localhost:8200/v1/sys/health?standbyok=true" ]
interval: 10s
timeout: 3s
retries: 10
start_period: 5s
generate-certs:
image: golang:1.16
tty: true
restart: "no"
volumes:
- tls:/vault/tls
- ./deps/cfssl:/config
- ./scripts/generate-pki.sh:/usr/local/bin/init.sh
environment:
CONF_DIR: /config
DEST_CERT_PATH: /vault/tls/
entrypoint:
- sh
- -c
- |
go get github.com/cloudflare/cfssl/cmd/cfssl
go get github.com/cloudflare/cfssl/cmd/cfssljson
init.sh
agent:
<<: *container-common
tty: true
depends_on:
- vault
cap_add:
- IPC_LOCK
environment:
PLUGIN_MOUNT_PATH: quorum
ROOT_TOKEN_PATH: /vault/token/.root
VAULT_ADDR: http://vault:8200
SECRET_FILE_PATH: /vault/token/secret
ROLE_FILE_PATH: /vault/token/role
VAULT_IS_READY: /vault/token/.ready
CAPABILITIES: '[\"create\", \"read\", \"update\", \"delete\", \"list\"]'
APP_ROLE_ID: key-manager
APP_ROLE_POLICIES: '["allow_keys", "allow_secrets"]'
POLICY_ID: allow_keys
KVV2_MOUNT_PATH: secret
KVV2_POLICY_ID: allow_secrets
volumes:
- token:/vault/token
- ./scripts/vault-agent-init.sh:/usr/local/bin/init.sh
entrypoint:
- sh
- -c
- |
cat <<EOF > /vault/config.hcl
exit_after_auth = false
vault {
address = "http://vault:8200"
}
auto_auth {
method "approle" {
config = {
role_id_file_path = "/vault/token/role"
secret_id_file_path = "/vault/token/secret"
remove_secret_id_file_after_reading = false
}
}
sink "file" {
config = {
path = "/vault/token/.vault-token"
}
}
}
EOF
until [ -f $${VAULT_IS_READY} ]; do
echo "[AGENT] waiting for vault to be ready..."
sleep 1
done
init.sh
vault agent -config=/vault/config.hcl
networks:
vault:
driver: bridge
volumes:
token:
driver: local
tls:
driver: local