-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen-secrets.sh
executable file
·62 lines (48 loc) · 1.12 KB
/
gen-secrets.sh
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
#!/bin/bash
set -euo pipefail
function make_cert () {
# Note: we just issue all certs to localhost, since we want to be flexible
# about DNS.
description="$1"
cert_path="$2"
key_path="$3"
config="$(mktemp)"
cat > "${config}" <<-EOF
[req]
prompt = no
distinguished_name = dn
[dn]
C=US
ST=California
L=Berkeley
O=Kelda Inc
OU=Kelda Blimp ${description}
CN=localhost
[ext]
subjectAltName = @alt_names
[alt_names]
DNS.1 = localhost
EOF
openssl req \
-x509 \
-newkey rsa:4096 \
-keyout "${key_path}" \
-out "${cert_path}" \
-days 365 \
-nodes \
-extensions ext \
-config "${config}"
rm "${config}"
}
function gen_token () {
length="$1"
# Restrict the token the alphanumerical characters to avoid any encoding
# issues.
# tr on Mac expects UTF-8 input by default so we have to set the locale:
# https://unix.stackexchange.com/questions/45404/why-cant-tr-read-from-dev-urandom-on-osx/217276
LC_ALL=C tr -dc a-zA-Z0-9 < /dev/urandom | head -c "${length}"
}
cd "$(dirname "$0")"
mkdir -p secrets
make_cert "Manager" secrets/manager.crt.pem secrets/manager.key.pem
gen_token 32 > secrets/cluster-auth-token