Skip to content

Commit ef163c2

Browse files
authored
Add /etc/ssh/ssh_known_hosts file (#234)
* Add /etc/ssh/ssh_known_hosts file This adds the SSH Host keys for the following services: - Github (github.com) - Gitlab (gitlab.com) - Azure (ssh.dev.azure.com) - Visual Studio (vs-ssh.visualstudio.com) - BitBucket (bitbucket.org) - Google (source.developers.google.com port 2022) This means that git won't complain on first connect when using Projects. Also added note to README.md about creating your own file for private git server * Fix file name
1 parent 02402b7 commit ef163c2

File tree

6 files changed

+181
-0
lines changed

6 files changed

+181
-0
lines changed

.docker/Dockerfile.alpine

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ RUN set -ex && \
3636
# Set work directory
3737
WORKDIR /usr/src/node-red
3838

39+
# Setup SSH known_hosts file
40+
COPY known_hosts.sh .
41+
RUN ./known_hosts.sh /etc/ssh/ssh_known_hosts && rm /usr/src/node-red/known_hosts.sh
42+
3943
# package.json contains Node-RED NPM module and node dependencies
4044
COPY package.json .
4145
COPY flows.json /data

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,3 +587,30 @@ __References:__
587587
https://groups.google.com/forum/#!topic/node-red/ieo5IVFAo2o
588588

589589
<br>
590+
591+
### SSH Known Hosts
592+
593+
The containers are pre-populated with a `/etc/ssh/ssh_known_hosts` file which holds the public SSH fingerprints for the following services:
594+
595+
- Github (github.com)
596+
- Gitlab (gitlab.com)
597+
- Azure (ssh.dev.azure.com)
598+
- Visual Studio (vs-ssh.visualstudio.com)
599+
- BitBucket (bitbucket.org)
600+
- Google (source.developers.google.com port 2022)
601+
602+
This is to allow the Projects feature to work without complaining the first time you try and connect to a git repository hosted on one of
603+
these services. If you are using Projects with your own git server and using SSH URLS then you can mount your own known_hosts file into the
604+
container. e.g.
605+
606+
```
607+
docker run -d -p 1880:1880 -e NODE_RED_ENABLE_PROJECTS=true -v /path/to/known_hosts:/etc/ssh/ssh_known_hosts nodered/node-red
608+
```
609+
610+
You can generate the known_hosts file as follows:
611+
612+
```
613+
ssh-keyscan hostname > known_hosts
614+
```
615+
616+
<br>

docker-custom/Dockerfile.custom

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ RUN set -ex && \
3131
# Set work directory
3232
WORKDIR /usr/src/node-red
3333

34+
# Setup SSH known_hosts file
35+
COPY known_hosts.sh .
36+
RUN ./known_hosts.sh /etc/ssh/ssh_known_hosts && rm /usr/src/node-red/known_hosts.sh
37+
3438
# package.json contains Node-RED NPM module and node dependencies
3539
COPY package.json .
3640
COPY flows.json /data

docker-custom/Dockerfile.debian

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ RUN set -ex && \
3232
# Set work directory
3333
WORKDIR /usr/src/node-red
3434

35+
# Setup SSH known_hosts file
36+
COPY known_hosts.sh .
37+
RUN ./known_hosts.sh /etc/ssh/ssh_known_hosts && rm /usr/src/node-red/known_hosts.sh
38+
3539
# package.json contains Node-RED NPM module and node dependencies
3640
COPY package.json .
3741
COPY flows.json /data

docker-custom/known_hosts.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/bash
2+
3+
# Originally taken from the Flux project (https://github.com/fluxcd/flux/tree/master/docker) where is under an
4+
# Apache-2.0 license
5+
6+
set -eu
7+
8+
known_hosts_file=${1}
9+
known_hosts_file=${known_hosts_file:-/etc/ssh/ssh_known_hosts}
10+
hosts="github.com gitlab.com bitbucket.org ssh.dev.azure.com vs-ssh.visualstudio.com"
11+
hosts_2022="source.developers.google.com"
12+
13+
# The heredoc below was generated by constructing a known_hosts using
14+
#
15+
# ssh-keyscan github.com gitlab.com bitbucket.org ssh.dev.azure.com vs-ssh.visualstudio.com > ./known_hosts
16+
#
17+
# then generating the sorted fingerprints with
18+
#
19+
# ssh-keygen -l -f ./known_hosts | LC_ALL=C sort
20+
#
21+
# then checking against the published fingerprints from:
22+
# - github.com: https://help.github.com/articles/github-s-ssh-key-fingerprints/
23+
# - gitlab.com: https://docs.gitlab.com/ee/user/gitlab_com/#ssh-host-keys-fingerprints
24+
# - bitbucket.org: https://confluence.atlassian.com/bitbucket/ssh-keys-935365775.html
25+
# - ssh.dev.azure.com & vs-ssh.visualstudio.com: sign in, then go to User settings -> SSH Public Keys
26+
# (this is where the public key fingerprint is shown; it's not a setting)
27+
# - source.developers.google.com: https://cloud.google.com/source-repositories/docs/cloning-repositories
28+
29+
fingerprints=$(mktemp -t)
30+
cleanup() {
31+
rm -f "$fingerprints"
32+
}
33+
trap cleanup EXIT
34+
35+
# make sure sorting is in the same locale as the heredoc
36+
export LC_ALL=C
37+
38+
generate() {
39+
ssh-keyscan ${hosts} > ${known_hosts_file}
40+
ssh-keyscan -p 2022 ${hosts_2022} >> ${known_hosts_file}
41+
}
42+
43+
validate() {
44+
ssh-keygen -l -f ${known_hosts_file} | sort > "$fingerprints"
45+
46+
diff - "$fingerprints" <<EOF
47+
2048 SHA256:ROQFvPThGrW4RuWLoL9tq9I9zJ42fK4XywyRtbOz/EQ gitlab.com (RSA)
48+
2048 SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8 github.com (RSA)
49+
2048 SHA256:ohD8VZEXGWo6Ez8GSEJQ9WpafgLFsOfLOtGGQCQo6Og ssh.dev.azure.com (RSA)
50+
2048 SHA256:ohD8VZEXGWo6Ez8GSEJQ9WpafgLFsOfLOtGGQCQo6Og vs-ssh.visualstudio.com (RSA)
51+
2048 SHA256:zzXQOXSRBEiUtuE8AikJYKwbHaxvSc0ojez9YXaGp1A bitbucket.org (RSA)
52+
256 SHA256:AGvEpqYNMqsRNIviwyk4J4HM0lEylomDBKOWZsBn434 [source.developers.google.com]:2022 (ECDSA)
53+
256 SHA256:HbW3g8zUjNSksFbqTiUWPWg2Bq1x8xdGUrliXFzSnUw gitlab.com (ECDSA)
54+
256 SHA256:eUXGGm1YGsMAS7vkcx6JOJdOGHPem5gQp4taiCfCLB8 gitlab.com (ED25519)
55+
EOF
56+
57+
}
58+
59+
retries=10
60+
count=0
61+
ok=false
62+
wait=2
63+
until ${ok}; do
64+
generate && validate && ok=true || ok=false
65+
count=$(($count + 1))
66+
if [[ ${count} -eq ${retries} ]]; then
67+
echo "ssh-keyscan failed, no more retries left"
68+
exit 1
69+
fi
70+
sleep ${wait}
71+
done

known_hosts.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/bash
2+
3+
# Originally taken from the Flux project (https://github.com/fluxcd/flux/tree/master/docker) where is under an
4+
# Apache-2.0 license
5+
6+
set -eu
7+
8+
known_hosts_file=${1}
9+
known_hosts_file=${known_hosts_file:-/etc/ssh/ssh_known_hosts}
10+
hosts="github.com gitlab.com bitbucket.org ssh.dev.azure.com vs-ssh.visualstudio.com"
11+
hosts_2022="source.developers.google.com"
12+
13+
# The heredoc below was generated by constructing a known_hosts using
14+
#
15+
# ssh-keyscan github.com gitlab.com bitbucket.org ssh.dev.azure.com vs-ssh.visualstudio.com > ./known_hosts
16+
#
17+
# then generating the sorted fingerprints with
18+
#
19+
# ssh-keygen -l -f ./known_hosts | LC_ALL=C sort
20+
#
21+
# then checking against the published fingerprints from:
22+
# - github.com: https://help.github.com/articles/github-s-ssh-key-fingerprints/
23+
# - gitlab.com: https://docs.gitlab.com/ee/user/gitlab_com/#ssh-host-keys-fingerprints
24+
# - bitbucket.org: https://confluence.atlassian.com/bitbucket/ssh-keys-935365775.html
25+
# - ssh.dev.azure.com & vs-ssh.visualstudio.com: sign in, then go to User settings -> SSH Public Keys
26+
# (this is where the public key fingerprint is shown; it's not a setting)
27+
# - source.developers.google.com: https://cloud.google.com/source-repositories/docs/cloning-repositories
28+
29+
fingerprints=$(mktemp -t)
30+
cleanup() {
31+
rm -f "$fingerprints"
32+
}
33+
trap cleanup EXIT
34+
35+
# make sure sorting is in the same locale as the heredoc
36+
export LC_ALL=C
37+
38+
generate() {
39+
ssh-keyscan ${hosts} > ${known_hosts_file}
40+
ssh-keyscan -p 2022 ${hosts_2022} >> ${known_hosts_file}
41+
}
42+
43+
validate() {
44+
ssh-keygen -l -f ${known_hosts_file} | sort > "$fingerprints"
45+
46+
diff - "$fingerprints" <<EOF
47+
2048 SHA256:ROQFvPThGrW4RuWLoL9tq9I9zJ42fK4XywyRtbOz/EQ gitlab.com (RSA)
48+
2048 SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8 github.com (RSA)
49+
2048 SHA256:ohD8VZEXGWo6Ez8GSEJQ9WpafgLFsOfLOtGGQCQo6Og ssh.dev.azure.com (RSA)
50+
2048 SHA256:ohD8VZEXGWo6Ez8GSEJQ9WpafgLFsOfLOtGGQCQo6Og vs-ssh.visualstudio.com (RSA)
51+
2048 SHA256:zzXQOXSRBEiUtuE8AikJYKwbHaxvSc0ojez9YXaGp1A bitbucket.org (RSA)
52+
256 SHA256:AGvEpqYNMqsRNIviwyk4J4HM0lEylomDBKOWZsBn434 [source.developers.google.com]:2022 (ECDSA)
53+
256 SHA256:HbW3g8zUjNSksFbqTiUWPWg2Bq1x8xdGUrliXFzSnUw gitlab.com (ECDSA)
54+
256 SHA256:eUXGGm1YGsMAS7vkcx6JOJdOGHPem5gQp4taiCfCLB8 gitlab.com (ED25519)
55+
EOF
56+
57+
}
58+
59+
retries=10
60+
count=0
61+
ok=false
62+
wait=2
63+
until ${ok}; do
64+
generate && validate && ok=true || ok=false
65+
count=$(($count + 1))
66+
if [[ ${count} -eq ${retries} ]]; then
67+
echo "ssh-keyscan failed, no more retries left"
68+
exit 1
69+
fi
70+
sleep ${wait}
71+
done

0 commit comments

Comments
 (0)