Skip to content

Commit 67e47a4

Browse files
committed
Adds ssh port and proper arguments parsing
1 parent bb2f187 commit 67e47a4

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

cmd/cli/add_to_known_hosts.sh

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,37 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

3-
# Usage: ./add_to_known_hosts.sh <http proxy> <host ip> >> ~/.ssh/known_hosts
4-
# Makes sure the pubkey returned from proxy matches ssh-keyscan of the host, and formats in a way that can be appended to known_hosts
3+
# For help run with -h
54

6-
if [ $1 = "-h" ]; then
7-
echo "Usage: ./add_to_known_hosts.sh <http proxy> <host ip> >> ~/.ssh/known_hosts (or append manually)"
8-
exit 0;
5+
usage() {
6+
echo -e "Makes sure the pubkey returned from proxy matches ssh-keyscan of the host, and formats in a way that can be appended to known_hosts.\nUsage:\t./add_to_known_hosts.sh [--proxy=http://127.0.0.1:8080] --ssh-host=<hosts ip> [--ssh-port=22] >> ~/.ssh/known_hosts\n\tMake sure your cvm-reverse-proxy client is running."
7+
}
8+
9+
PORT=22
10+
PROXY="http://127.0.0.1:8080"
11+
12+
for i in "$@"
13+
do
14+
case $i in
15+
--proxy=*)
16+
PROXY="${i#*=}"
17+
;;
18+
--ssh-host=*)
19+
HOST="${i#*=}"
20+
;;
21+
--ssh-port=*)
22+
PORT="${i#*=}"
23+
;;
24+
-h|--help|*)
25+
usage
26+
exit 0
27+
;;
28+
esac
29+
done
30+
31+
if [[ -z "$HOST" ]]; then
32+
usage
33+
exit 1
934
fi
1035

11-
pubkey=`curl -s $1/pubkey`
12-
ssh-keyscan -H "$2" 2>/dev/null | grep "${pubkey}"
36+
pubkey=`curl -s $PROXY/pubkey`
37+
ssh-keyscan -p "$PORT" -H "$HOST" 2>/dev/null | grep "${pubkey}"

cmd/httpserver/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var flags []cli.Flag = []cli.Flag{
2626
},
2727
&cli.StringFlag{
2828
Name: "metrics-addr",
29-
Value: "127.0.0.1:8090",
29+
Value: "",
3030
Usage: "address to listen on for Prometheus metrics",
3131
},
3232
&cli.BoolFlag{
@@ -46,7 +46,7 @@ var flags []cli.Flag = []cli.Flag{
4646
},
4747
&cli.StringFlag{
4848
Name: "log-service",
49-
Value: "your-project",
49+
Value: "ssh-pubkey-server",
5050
Usage: "add 'service' tag to logs",
5151
},
5252
&cli.BoolFlag{

0 commit comments

Comments
 (0)