Skip to content

Commit ca6fffd

Browse files
committed
Add HTTP Proxy support for SSH
Signed-off-by: Alexandros Skaliotis <[email protected]>
1 parent e9fa707 commit ca6fffd

File tree

19 files changed

+633
-2
lines changed

19 files changed

+633
-2
lines changed

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ filed named `.gitkeep`. Finally, create individual locks by making an empty file
7272
retrying to acquire a lock or release a lock. The default is 10 seconds.
7373
Valid values: `60s`, `90m`, `1h`.
7474
75+
* `https_tunnel`: *Optional.* Information about an HTTPS proxy that will be used to tunnel SSH-based git commands over.
76+
Has the following sub-properties:
77+
* `proxy_host`: *Required.* The host name or IP of the proxy server
78+
* `proxy_port`: *Required.* The proxy server's listening port
79+
* `proxy_user`: *Optional.* If the proxy requires authentication, use this username
80+
* `proxy_password`: *Optional.* If the proxy requires authentication, use this password
81+
7582
### Example
7683
7784
Fetching a repo with only 100 commits of history:
@@ -234,6 +241,29 @@ example:
234241
params: {release: specific-aws-env}
235242
```
236243

244+
### Configuring resource to proxy SSH commands through an HTTP proxy
245+
246+
```
247+
resources:
248+
- name: aws-environments
249+
type: pool
250+
source:
251+
uri: [email protected]:concourse/locks.git
252+
branch: master
253+
pool: aws
254+
private_key: |
255+
-----BEGIN RSA PRIVATE KEY-----
256+
MIIEowIBAAKCAQEAtCS10/f7W7lkQaSgD/mVeaSOvSF9ql4hf/zfMwfVGgHWjj+W
257+
<Lots more text>
258+
DWiJL+OFeg9kawcUL6hQ8JeXPhlImG6RTUffma9+iGQyyBMCGd1l
259+
-----END RSA PRIVATE KEY-----
260+
https_tunnel:
261+
proxy_host: proxy-server.mycorp.com
262+
proxy_port: 3128
263+
proxy_user: myuser
264+
proxy_password: myverysecurepassword
265+
```
266+
237267
## Development
238268

239269
### Prerequisites
@@ -258,6 +288,29 @@ docker build -t pool-resource --target tests -f dockerfiles/alpine/Dockerfile .
258288
docker build -t pool-resource --target tests -f dockerfiles/ubuntu/Dockerfile .
259289
```
260290

291+
#### Note about the integration tests
292+
293+
If you want to run the integration tests, a bit more work is required. You will require
294+
an actual git repo to which you can push and pull, configured for SSH access. To do this,
295+
add two files to `integration-tests/ssh` (note that names **are** important):
296+
* `test_key`: This is the private key used to authenticate against your repo.
297+
* `test_repo`: This file contains one line of the form `test_repo_url[#test_branch]`.
298+
If the branch is not specified, it defaults to `main`. For example,
299+
`[email protected]:concourse-git-tester/git-resource-integration-tests.git` or
300+
`[email protected]:concourse-git-tester/git-resource-integration-tests.git#testing`
301+
302+
To set up or reset the contents of the repo, use the `integration-tests/ssh/init-repo.sh` script.
303+
The script clones the configured repository, (re-)creates the relevant directories,
304+
commits and pushes the changes. If you'd rather execute the commands yourself, view the script
305+
contents to understand the directory structure expected by the integration tests.
306+
307+
Then run the tests for both `alpine` and `ubuntu` images:
308+
309+
```sh
310+
docker build -t pool-resource --target integrationtests -f dockerfiles/alpine/Dockerfile .
311+
docker build -t pool-resource --build-arg base_image=concourse/golang-builder --target integrationtests -f dockerfiles/ubuntu/Dockerfile .
312+
```
313+
261314
### Contributing
262315

263316
Please make all pull requests to the `master` branch and ensure tests pass

assets/check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ payload=$TMPDIR/git-resource-request
1616
cat > $payload <&0
1717

1818
load_pubkey $payload
19+
configure_https_tunnel $payload
1920
configure_credentials $payload
2021

2122
uri=$(jq -r '.source.uri // ""' < $payload)

assets/common.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,31 @@ EOF
2222
fi
2323
}
2424

25+
configure_https_tunnel() {
26+
tunnel=$(jq -r '.source.https_tunnel // empty' < $1)
27+
28+
if [ ! -z "$tunnel" ]; then
29+
host=$(echo "$tunnel" | jq -r '.proxy_host // empty')
30+
port=$(echo "$tunnel" | jq -r '.proxy_port // empty')
31+
user=$(echo "$tunnel" | jq -r '.proxy_user // empty')
32+
password=$(echo "$tunnel" | jq -r '.proxy_password // empty')
33+
34+
pass_file=""
35+
if [ ! -z "$user" ]; then
36+
cat > ~/.ssh/tunnel_config <<EOF
37+
proxy_user = $user
38+
proxy_passwd = $password
39+
EOF
40+
chmod 0600 ~/.ssh/tunnel_config
41+
pass_file="-F ~/.ssh/tunnel_config"
42+
fi
43+
44+
if [ -n "$host" ] && [ -n "$port" ]; then
45+
echo "ProxyCommand /usr/bin/proxytunnel $pass_file -p $host:$port -d %h:%p" >> ~/.ssh/config
46+
fi
47+
fi
48+
}
49+
2550
configure_credentials() {
2651
local username=$(jq -r '.source.username // ""' < $1)
2752
local password=$(jq -r '.source.password // ""' < $1)

assets/in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ payload=$(mktemp $TMPDIR/pool-resource-request.XXXXXX)
3333
cat > $payload <&0
3434

3535
load_pubkey $payload
36+
configure_https_tunnel $payload
3637
configure_credentials $payload
3738

3839
uri=$(jq -r '.source.uri // ""' < $payload)

assets/out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ exec 1>&2 # redirect all output to stderr for logging
1010
payload=$(mktemp $TMPDIR/pool-resource-request.XXXXXX)
1111
cat > $payload <&0
1212
load_pubkey $payload
13+
configure_https_tunnel $payload
1314
configure_credentials $payload
1415

1516
/opt/go/out $1 >&3 < $payload

dockerfiles/alpine/Dockerfile

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,23 @@ RUN set -e; for pkg in $(go list ./...); do \
1111
done
1212

1313
FROM ${base_image} AS resource
14-
RUN apk add --no-cache bash jq git git-daemon openssh
14+
RUN apk add --no-cache bash jq git git-daemon openssh make g++ libressl-dev
1515
RUN git config --global user.email "git@localhost"
1616
RUN git config --global user.name "git"
17+
1718
ADD assets/ /opt/resource/
1819
RUN chmod +x /opt/resource/*
1920
COPY --from=builder /assets /opt/go
2021
RUN chmod +x /opt/go/out
2122

23+
WORKDIR /root
24+
RUN git clone https://github.com/proxytunnel/proxytunnel.git && \
25+
cd proxytunnel && \
26+
make -j4 && \
27+
install -c proxytunnel /usr/bin/proxytunnel && \
28+
cd .. && \
29+
rm -rf proxytunnel
30+
2231
FROM resource AS tests
2332
COPY --from=builder /tests /go/resource-tests/
2433
RUN set -e; for test in /go/resource-tests/*.test; do \
@@ -27,4 +36,10 @@ RUN set -e; for test in /go/resource-tests/*.test; do \
2736
ADD test/ /opt/resource-tests
2837
RUN /opt/resource-tests/all.sh
2938

39+
FROM resource AS integrationtests
40+
RUN apk --no-cache add squid
41+
ADD test/ /opt/resource-tests/test
42+
ADD integration-tests /opt/resource-tests/integration-tests
43+
RUN /opt/resource-tests/integration-tests/integration.sh
44+
3045
FROM resource

dockerfiles/ubuntu/Dockerfile

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ RUN set -e; for pkg in $(go list ./...); do \
1111
done
1212

1313
FROM ${base_image} AS resource
14-
RUN apt-get update && apt-get install -y jq git
14+
RUN apt-get update && apt-get install -y jq git make g++ libssl-dev openssh-client
1515
RUN git config --global user.email "git@localhost"
1616
RUN git config --global user.name "git"
1717

@@ -20,6 +20,14 @@ RUN chmod +x /opt/resource/*
2020
COPY --from=builder /assets /opt/go
2121
RUN chmod +x /opt/go/out
2222

23+
WORKDIR /root
24+
RUN git clone https://github.com/proxytunnel/proxytunnel.git && \
25+
cd proxytunnel && \
26+
make -j4 && \
27+
install -c proxytunnel /usr/bin/proxytunnel && \
28+
cd .. && \
29+
rm -rf proxytunnel
30+
2331
FROM resource AS tests
2432
COPY --from=builder /tests /go/resource-tests/
2533
RUN set -e; for test in /go/resource-tests/*.test; do \
@@ -28,4 +36,10 @@ RUN set -e; for test in /go/resource-tests/*.test; do \
2836
ADD test/ /opt/resource-tests
2937
RUN /opt/resource-tests/all.sh
3038

39+
FROM resource AS integrationtests
40+
RUN apt-get update && apt-get install -y squid net-tools
41+
ADD test/ /opt/resource-tests/test
42+
ADD integration-tests /opt/resource-tests/integration-tests
43+
RUN /opt/resource-tests/integration-tests/integration.sh
44+
3145
FROM resource

0 commit comments

Comments
 (0)