Skip to content

Commit 2d50710

Browse files
JimNasbyGEgurjeet
authored andcommitted
Add push script; improve docs
* Add random-route option to manifest * Add push script * Add script to clean up temporary stuff * Start client after push * Split tunnel stuff into a separate script * Emphasize need to have modified .ssh/config * Add sanity check for URL * Fix for changed version of cf * Allow configuration of port numbers
1 parent 086289e commit 2d50710

File tree

6 files changed

+151
-2
lines changed

6 files changed

+151
-2
lines changed

.default.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CHISEL_LOCAL_PORT=${CHISEL_LOCAL_PORT:-5022}
2+
CHISEL_REMOTE_PORT=${CHISEL_REMOTE_PORT:-2022}

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Ignore client
2+
chisel
3+
4+
# Ignore things that are done on a per-instance basis
5+
id_rsa.pub
6+
ssh_host_rsa_key
7+
ssh_host_rsa_key.pub

README.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,24 @@
5454
(2022 in this case) is fixed. You can run multiple chisel clients simultaneously
5555
by choosing a different local port (5022 in this case).
5656

57-
7. Use SSH to login in the container
57+
7. Add entry to ~/.ssh/config (optional)
58+
59+
You can add an entry to your ssh config to make ssh'ing to chisel easier.
60+
NOTE: the config file is position sensitive, so if you have a `Host *`
61+
entry in your file you need to add this before the `Host *` entry.
62+
63+
```
64+
Host chisel
65+
ForwardAgent yes
66+
HostName localhost
67+
Port 5022
68+
User vcap
69+
Compression yes
70+
```
71+
72+
This entry will allow you to simply `ssh chisel` to connect.
73+
74+
8. Use SSH to login in the container
5875
5976
Use standard SSH applications to connect to the SSH daemon in the container.
6077
The user name to connect as is `vcap`. The SSH utiliites will use your private
@@ -64,18 +81,34 @@
6481
`-i` switch. You must have uploaded the corresponding public key in step 3
6582
above, for this to work.
6683
84+
If you added an entry to ~/.ssh/config:
85+
86+
```
87+
ssh chisel
88+
```
89+
90+
otherwise:
91+
6792
```
6893
ssh vcap@localhost -p 5022
6994
```
7095
71-
8. Perform local port forwarding
96+
9. Perform local port forwarding
7297
7398
You can also use SSH to perform local port forwarding.
7499
75100
For example, you can use this command to create a local port 6632 that
76101
forwards all TCP traffic to your Postgres database (port 5432) instance
77102
that is only accessible from Cloud Foundry applications.
78103
104+
If you added an entry to ~/.ssh/config:
105+
106+
```
107+
ssh -L 6632:myapp-db.example.com:5432 chisel
108+
```
109+
110+
otherwise:
111+
79112
```
80113
ssh -L 6632:myapp-db.example.com:5432 vcap@localhost -p 5022
81114
```

clean.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
cd `dirname $0`
6+
7+
for f in `egrep -v '^#' .gitignore`; do
8+
if echo $f | egrep -q '^/|\.\.'; then
9+
echo "Ignoring dangerous .gitignore entry $f"
10+
else
11+
echo Removing $f
12+
rm -f $f
13+
fi
14+
done

push.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/sh
2+
3+
set -e # exit on error
4+
5+
cd `dirname $0`
6+
source .default.sh
7+
8+
appname="cf-ssh-chisel-$USER"
9+
10+
# Generate a key to identify the server (if one doesn't already exist)
11+
# TODO: put all generated files (this and id_rsa.pub) into a single directory
12+
if [ ! -r ssh_host_rsa_key ]; then
13+
ssh-keygen -t rsa -f ssh_host_rsa_key -N '' -C "chisel-ssh identity for $appname"
14+
echo '[localhost]:$CHISEL_LOCAL_PORT' `cat ssh_host_rsa_key.pub` >> ~/.ssh/known_hosts
15+
fi
16+
17+
if [ ! -r id_rsa.pub ]; then
18+
cp ~/.ssh/id_rsa.pub .
19+
fi
20+
21+
if ! grep -q 'Host chisel' ~/.ssh/config; then
22+
cat <<_EOF_
23+
24+
You might want to add this entry to ~/.ssh/config. Note that the config file is
25+
position-sensitive, so this needs to be added before the 'Host *' entry if you
26+
have one.
27+
28+
Host chisel
29+
ForwardAgent yes
30+
HostName localhost
31+
Port $CHISEL_LOCAL_PORT
32+
User vcap
33+
Compression yes
34+
_EOF_
35+
fi
36+
37+
cf push -t 180 $appname & # -t: maximum number of seconds to wait for app to start
38+
39+
export GOPATH=$(echo ${PWD%src/github.com/jpillora/chisel})
40+
go build
41+
42+
wait
43+
44+
./tunnel
45+
46+
# vi: expandtab sw=2 ts=2

tunnel

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/sh
2+
3+
set -e # exit on error
4+
5+
cd `dirname $0`
6+
7+
appname="cf-ssh-chisel-$USER"
8+
echo "Starting $appname forwarding local port ${CHISEL_LOCAL_PORT:=5022} to remote port ${CHISEL_REMOTE_PORT:=2022}"
9+
10+
echo "Checking if $appname is running"
11+
cf app $appname > /dev/null # Make sure app is there
12+
13+
if ! cf app $appname | grep -q running; then
14+
echo "ERROR: $appname is not running"
15+
exit 1
16+
fi
17+
18+
echo "Obtaining url for $appname"
19+
url=`cf app $appname | egrep 'routes|urls' | awk '{print $2}'`
20+
21+
# Sanity-check the URL. This is kinda important because the chisel client
22+
# doesn't complain if it can't connect. :(
23+
echo "$url" | grep "$appname" | grep -q predix.io || { echo "URL doesn't look sane: $url"; exit 2; }
24+
25+
# If there's an existing client running, kill it
26+
client_pids=`ps auxww | grep ./chisel | grep ${CHISEL_LOCAL_PORT}:${CHISEL_REMOTE_PORT} | grep -v grep | awk '{print $2}'`
27+
if [ -n "$client_pids" ]; then
28+
kill $client_pids
29+
fi
30+
31+
echo "Starting client, connecting to $url"
32+
cmd="./chisel client --keepalive 10s https://$url ${CHISEL_LOCAL_PORT}:${CHISEL_REMOTE_PORT}"
33+
echo "Running in background: $cmd"
34+
$cmd > /dev/null &
35+
36+
cat <<_EOF_
37+
You can now connect via
38+
39+
ssh vcap@localhost -p ${CHISEL_LOCAL_PORT}
40+
41+
or **IF** you added an entry to ~/.ssh/config:
42+
43+
ssh chisel
44+
45+
_EOF_
46+
47+
# vi: expandtab sw=2 ts=2

0 commit comments

Comments
 (0)