Skip to content

Commit ad8836e

Browse files
committed
Adapt to a non-writeable /etc/passwd file in sshd Dockerfile.
The UDI image currently permits writing to /etc/passwd, and sets the default user to have a login shell. Make /etc/passwd non-writable and "disable" /sbin/nologin (by replacing it with /bin/bash) to ensure the user starting the SSHD service may continue to log into the container over SSH. - Small improvements to presentation of landing page with "Troubleshooting" section and emphasis on certain commands - Include 'UserKnownHostsFile /dev/null' in recommended SSH configuration section as this eliminates need to remove entries from known_hosts if/when the Devworkspace's host key changes Signed-off-by: Roland Grunberg <rgrunber@redhat.com>
1 parent f2ded2f commit ad8836e

2 files changed

Lines changed: 21 additions & 11 deletions

File tree

build/dockerfiles/dev.sshd.Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ COPY --chown=0:0 /build/scripts/sshd.start /
5555
RUN mkdir /opt/www
5656
COPY /build/scripts/server.js /opt/www/
5757

58-
ENV USER_NAME=dev
58+
# Lock down /etc/passwd until fixed in UDI
59+
RUN chmod 644 /etc/passwd
60+
61+
# Bypass nologin shell for random generated user
62+
RUN cp /bin/bash /sbin/nologin
5963

6064
EXPOSE 2022 3400
6165

build/scripts/server.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
const http = require('http');
1111
const fs = require('fs');
12+
const os = require('os');
13+
1214
const hostname = '127.0.0.1';
1315
const port = 3400;
1416

@@ -33,10 +35,7 @@ const server = http.createServer((req, res) => {
3335
}
3436

3537
let keyMessage = `
36-
<pre>${hasUserPrefSSHKey ? pubKey : genKey}</pre>
37-
</p>
38-
<p>
39-
This can also be configured locally in <code>$HOME/.ssh/config</code> with the following :`;
38+
<pre>${hasUserPrefSSHKey ? pubKey : genKey}</pre>`;
4039

4140
res.end(`
4241
<!DOCTYPE html>
@@ -49,20 +48,27 @@ const server = http.createServer((req, res) => {
4948
<div class="border">
5049
<ol>
5150
<li>Make sure your local oc client is logged in to your OpenShift cluster</li>
52-
<li><p class="center">Run <code>oc port-forward ${process.env["HOSTNAME"]} 2022:2022</code>. This establishes a connection to the workspace.</p></li>
51+
<li><p class="center">Run <code><b>oc port-forward ${process.env["HOSTNAME"]} 2022:2022</b></code>. This establishes a connection to the workspace.</p></li>
5352
<li>
54-
<p>In your local VS Code, connect to <code>localhost</code> on port <code>2022</code> with user <code>${process.env["USER_NAME"]}</code> ${hasUserPrefSSHKey ? `. The SSH key, corresponding to the following public key, configured in the "SSH Keys" tab of "User Preferences" has been authorized to connect :` : `and the following identity file :`} ${keyMessage}
55-
<pre>
53+
<p>In your local VS Code, connect to <code>localhost</code> on port <code>2022</code> with user <code>${os.userInfo().username}</code> ${hasUserPrefSSHKey ? `. The SSH key, corresponding to the following public key, configured in the "SSH Keys" tab of "User Preferences" has been authorized to connect :` : `and the following identity file :`} ${keyMessage}</p>
54+
<p>
55+
This can also be configured locally in <code>$HOME/.ssh/config</code> with the following :
56+
<pre><b>
5657
Host localhost
5758
HostName 127.0.0.1
58-
User ${process.env["USER_NAME"]}
59+
User ${os.userInfo().username}
5960
Port 2022
6061
IdentityFile /path/to/the/ssh_client_ed25519_key
61-
</pre>
62+
UserKnownHostsFile /dev/null
63+
</b></pre>
6264
</p>
6365
</li>
6466
</ol>
65-
<p>If the connection fails with "<code>WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED</code>", it may be necessary to remove the <code>localhost</code> or <code>127.0.0.1</code> entries from <code>$HOME/.ssh/known_hosts</code>. This is because the SSHD service container (to which <code>oc port-forward</code> is forwarding) may change.</p>
67+
<h3>Troubleshooting</h3>
68+
<p>If the connection fails with "<code>WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED</code>", it may be necessary to remove the <code>localhost</code> or <code>127.0.0.1</code> entries from <code>$HOME/.ssh/known_hosts</code>. This is because the SSHD service container (to which <code>oc port-forward</code> is forwarding) may change. This can be bypassed by setting <code>UserKnownHostsFile /dev/null</code></p>
69+
<p>Please ensure the permissions on the private key used are restricted to allow only the file owner to read/write. The SSH service may fail to correctly authenticate otherwise.</p>
70+
<p>The most common setup is to connect to the workspace using the "Remote - SSH Connection" from the corresponding editor's extension marketplace. If this setup fails to connect to the workspace, consider disabling the setting <code><b>remote.SSH.useExecServer</b></code> (set to false)</p>
71+
<p>For any other issues, relating to the use of a VS Code-based editor and the "Remote - SSH connection", the "Remote - SSH" logs from the "Output" view are very helpful in diagnosing the issue.</p>
6672
</div>
6773
</body>
6874
</html>

0 commit comments

Comments
 (0)