-
Notifications
You must be signed in to change notification settings - Fork 26
/
bastion
87 lines (74 loc) · 2.47 KB
/
bastion
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
#!/usr/bin/env sh
HOST_KEYS_PATH_PREFIX="${HOST_KEYS_PATH_PREFIX:='/'}"
HOST_KEYS_PATH="${HOST_KEYS_PATH:='/etc/ssh'}"
if [ "$PUBKEY_AUTHENTICATION" == "false" ]; then
CONFIG_PUBKEY_AUTHENTICATION="-o PubkeyAuthentication=no"
else
CONFIG_PUBKEY_AUTHENTICATION="-o PubkeyAuthentication=yes"
fi
if [ -n "$AUTHORIZED_KEYS" ]; then
CONFIG_AUTHORIZED_KEYS="-o AuthorizedKeysFile=$AUTHORIZED_KEYS"
else
CONFIG_AUTHORIZED_KEYS="-o AuthorizedKeysFile=authorized_keys"
fi
if [ -n "$TRUSTED_USER_CA_KEYS" ]; then
CONFIG_TRUSTED_USER_CA_KEYS="-o TrustedUserCAKeys=$TRUSTED_USER_CA_KEYS"
CONFIG_AUTHORIZED_PRINCIPALS_FILE="-o AuthorizedPrincipalsFile=/etc/ssh/auth_principals/%u"
fi
if [ "$GATEWAY_PORTS" == "true" ]; then
CONFIG_GATEWAY_PORTS="-o GatewayPorts=yes"
else
CONFIG_GATEWAY_PORTS="-o GatewayPorts=no"
fi
if [ "$PERMIT_TUNNEL" == "true" ]; then
CONFIG_PERMIT_TUNNEL="-o PermitTunnel=yes"
else
CONFIG_PERMIT_TUNNEL="-o PermitTunnel=no"
fi
if [ "$X11_FORWARDING" == "true" ]; then
CONFIG_X11_FORWARDING="-o X11Forwarding=yes"
else
CONFIG_X11_FORWARDING="-o X11Forwarding=no"
fi
if [ "$TCP_FORWARDING" == "false" ]; then
CONFIG_TCP_FORWARDING="-o AllowTcpForwarding=no"
else
CONFIG_TCP_FORWARDING="-o AllowTcpForwarding=yes"
fi
if [ "$AGENT_FORWARDING" == "false" ]; then
CONFIG_AGENT_FORWARDING="-o AllowAgentForwarding=no"
else
CONFIG_AGENT_FORWARDING="-o AllowAgentForwarding=yes"
fi
if [ ! -f "$HOST_KEYS_PATH/ssh_host_rsa_key" ]; then
/usr/bin/ssh-keygen -A -f "$HOST_KEYS_PATH_PREFIX"
fi
if [ -n "$LISTEN_ADDRESS" ]; then
CONFIG_LISTEN_ADDRESS="-o ListenAddress=$LISTEN_ADDRESS"
else
CONFIG_LISTEN_ADDRESS="-o ListenAddress=0.0.0.0"
fi
if [ -n "$LISTEN_PORT" ]; then
CONFIG_LISTEN_PORT="-o Port=$LISTEN_PORT"
else
CONFIG_LISTEN_PORT="-o Port=22"
fi
/usr/sbin/sshd -D -e -4 \
-o "HostKey=$HOST_KEYS_PATH/ssh_host_rsa_key" \
-o "HostKey=$HOST_KEYS_PATH/ssh_host_dsa_key" \
-o "HostKey=$HOST_KEYS_PATH/ssh_host_ecdsa_key" \
-o "HostKey=$HOST_KEYS_PATH/ssh_host_ed25519_key" \
-o "PasswordAuthentication=no" \
-o "PermitEmptyPasswords=no" \
-o "PermitRootLogin=no" \
$CONFIG_PUBKEY_AUTHENTICATION \
$CONFIG_AUTHORIZED_KEYS \
$CONFIG_GATEWAY_PORTS \
$CONFIG_PERMIT_TUNNEL \
$CONFIG_X11_FORWARDING \
$CONFIG_AGENT_FORWARDING \
$CONFIG_TCP_FORWARDING \
$CONFIG_TRUSTED_USER_CA_KEYS \
$CONFIG_AUTHORIZED_PRINCIPALS_FILE \
$CONFIG_LISTEN_ADDRESS \
$CONFIG_LISTEN_PORT