forked from dokku-alt/dokku-alt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvars
More file actions
46 lines (37 loc) · 1.48 KB
/
Copy pathvars
File metadata and controls
46 lines (37 loc) · 1.48 KB
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
#!/bin/bash
source "$(dirname $0)/../dokku_common"
AUTHORIZED_KEYS="$DOKKU_ROOT/.ssh/authorized_keys"
DEPLOY_ALLOWED="DEPLOY_ALLOWED"
add_ssh_key() {
KEY_FILE=$(mktemp)
KEY=$(tee "$KEY_FILE")
NAME="$1"
VERIFY_NAME="$2"
delete_key_file() {
rm -f "$KEY_FILE"
}
trap delete_key_file INT EXIT
FINGERPRINT=$(ssh-keygen -lf "$KEY_FILE" | awk '{print $2}')
[[ -z "$FINGERPRINT" ]] && fail "Invalid ssh public key"
[[ -n "$VERIFY_NAME" ]] && grep -q "FINGERPRINT=$FINGERPRINT " "$AUTHORIZED_KEYS" && \
! grep -q "FINGERPRINT=$FINGERPRINT NAME=$VERIFY_NAME" "$AUTHORIZED_KEYS" && \
fail "$FINGERPRINT is already added with different permission. You have to manually edit authorized_keys and remove the entry."
KEY_PREFIX="command=\"FINGERPRINT=$FINGERPRINT NAME=$NAME \`cat $DOKKU_ROOT/.sshcommand\` \$SSH_ORIGINAL_COMMAND\",no-agent-forwarding,no-user-rc,no-X11-forwarding,no-port-forwarding"
sed --in-place "/FINGERPRINT=$FINGERPRINT /d" "$AUTHORIZED_KEYS" # remove old key
echo "$KEY_PREFIX $KEY" >> "$AUTHORIZED_KEYS"
}
remove_fingerprint() {
sed --in-place "/FINGERPRINT=$1 /d" "$AUTHORIZED_KEYS"
}
verify_fingerprint() {
FINGERPRINT="$1"
[[ "$FINGERPRINT" =~ ^[0-9a-fA-F:]+$ ]] || fail "$FINGERPRINT: this is not fingerprint!"
}
is_fingerprint_allowed() {
if [[ -f "$DOKKU_ROOT/$APP/$DEPLOY_ALLOWED" ]] && grep -q "^$1\$" "$DOKKU_ROOT/$APP/$DEPLOY_ALLOWED"
then
return 0
else
return 1
fi
}