Luke Granger-Brown
7592e76a31
tokend is responsible for issuing service-scoped tokens based on the token held and generated by the Vault Agent. It can also generate "server-user" scoped tokens, which exist for convenience's sake: they are not a strong attestation of the user on the machine, and have limited privileges compared to a Vault token issued using e.g. `vault login -method=oidc`.
32 lines
1.2 KiB
Bash
Executable file
32 lines
1.2 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
set -euo pipefail
|
|
|
|
CERTIFICATE_JSON="$(@curl@/bin/curl \
|
|
-H "X-Vault-Request: true" \
|
|
-X PUT \
|
|
-d "{\"common_name\": \"${CERTIFICATE_DOMAIN}\"}" \
|
|
--unix-socket "/run/tokend/sock" \
|
|
"http://localhost:8200/v1/acme/certs/${CERTIFICATE_ROLE}")"
|
|
|
|
if [[ "$(@jq@/bin/jq .errors <(echo "$CERTIFICATE_JSON") 2>/dev/null)" != "null" ]]; then
|
|
@jq@/bin/jq .errors <(echo "$CERTIFICATE_JSON") >&2
|
|
exit 1
|
|
fi
|
|
|
|
temp_dir=$(mktemp -d)
|
|
trap "rm -rf $temp_dir" INT TERM HUP EXIT
|
|
|
|
@jq@/bin/jq -r .data.cert <(echo "$CERTIFICATE_JSON") > "$temp_dir/cert.pem"
|
|
@jq@/bin/jq -r .data.private_key <(echo "$CERTIFICATE_JSON") > "$temp_dir/pkey.pem"
|
|
|
|
@curl@/bin/curl -k \
|
|
--user "${RARITAN_USERNAME}:${RARITAN_PASSWORD}" \
|
|
-F cert_file=@"$temp_dir/cert.pem" \
|
|
-F key_file=@"$temp_dir/pkey.pem" \
|
|
"https://${RARITAN_IP}/cgi-bin/server_ssl_cert_upload.cgi"
|
|
@curl@/bin/curl -k \
|
|
--user "${RARITAN_USERNAME}:${RARITAN_PASSWORD}" \
|
|
"https://${RARITAN_IP}/bulk" \
|
|
-H 'Content-Type: application/json; charset=UTF-8' \
|
|
--data-binary '{"jsonrpc":"2.0","method":"performBulk","params":{"requests":[{"rid":"/server_ssl_cert","json":{"jsonrpc":"2.0","method":"installPendingKeyPair","params":null,"id":1}}]},"id":2}'
|