Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
Acme.Sh
Commits
de692d3d
Unverified
Commit
de692d3d
authored
Aug 18, 2020
by
Sergey Pashinin
Browse files
Vault deploy hook
parent
21fd46d6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Dockerfile
View file @
de692d3d
...
...
@@ -7,6 +7,7 @@ RUN apk update -f \
coreutils
\
bind-tools
\
curl
\
sed
\
socat
\
tzdata
\
oath-toolkit-oathtool
\
...
...
deploy/vault.sh
0 → 100644
View file @
de692d3d
#!/usr/bin/env sh
# Here is a script to deploy cert to hashicorp vault using curl
# (https://www.vaultproject.io/)
#
# it requires following environment variables:
#
# VAULT_PREFIX - this contains the prefix path in vault
# VAULT_ADDR - vault requires this to find your vault server
#
# additionally, you need to ensure that VAULT_TOKEN is avialable
# to access the vault server
#returns 0 means success, otherwise error.
######## Public functions #####################
#domain keyfile certfile cafile fullchain
vault_deploy
()
{
_cdomain
=
"
$1
"
_ckey
=
"
$2
"
_ccert
=
"
$3
"
_cca
=
"
$4
"
_cfullchain
=
"
$5
"
_debug _cdomain
"
$_cdomain
"
_debug _ckey
"
$_ckey
"
_debug _ccert
"
$_ccert
"
_debug _cca
"
$_cca
"
_debug _cfullchain
"
$_cfullchain
"
# validate required env vars
if
[
-z
"
$VAULT_PREFIX
"
]
;
then
_err
"VAULT_PREFIX needs to be defined (contains prefix path in vault)"
return
1
fi
if
[
-z
"
$VAULT_ADDR
"
]
;
then
_err
"VAULT_ADDR needs to be defined (contains vault connection address)"
return
1
fi
# JSON does not allow multiline strings.
# So replacing new-lines with "\n" here
_ckey
=
$(
sed
-z
's/\n/\\n/g'
<
"
$2
"
)
_ccert
=
$(
sed
-z
's/\n/\\n/g'
<
"
$3
"
)
_cca
=
$(
sed
-z
's/\n/\\n/g'
<
"
$4
"
)
_cfullchain
=
$(
sed
-z
's/\n/\\n/g'
<
"
$5
"
)
URL
=
"
$VAULT_ADDR
/v1/
$VAULT_PREFIX
/
$_cdomain
"
if
[
-n
"
$FABIO
"
]
;
then
curl
--silent
-H
"X-Vault-Token:
$VAULT_TOKEN
"
--request
POST
--data
"{
\"
cert
\"
:
\"
$_cfullchain
\"
,
\"
key
\"
:
\"
$_ckey
\"
}"
"
$URL
"
||
return
1
else
curl
--silent
-H
"X-Vault-Token:
$VAULT_TOKEN
"
--request
POST
--data
"{
\"
value
\"
:
\"
$_ccert
\"
}"
"
$URL
/cert.pem"
||
return
1
curl
--silent
-H
"X-Vault-Token:
$VAULT_TOKEN
"
--request
POST
--data
"{
\"
value
\"
:
\"
$_ckey
\"
}"
"
$URL
/cert.key"
||
return
1
curl
--silent
-H
"X-Vault-Token:
$VAULT_TOKEN
"
--request
POST
--data
"{
\"
value
\"
:
\"
$_cca
\"
}"
"
$URL
/chain.pem"
||
return
1
curl
--silent
-H
"X-Vault-Token:
$VAULT_TOKEN
"
--request
POST
--data
"{
\"
value
\"
:
\"
$_cfullchain
\"
}"
"
$URL
/fullchain.pem"
||
return
1
fi
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment