Skip to content

Commit 737e964

Browse files
committed
More changes to support VS Code (local) to Devworkspace over SSH.
- Custom image based on UDI that contains the non-root SSH daemon, basic web server to show webpage on startup to guide the user - che-code-sshd.yaml file as entrypoint to configure the custom image Signed-off-by: Roland Grunberg <rgrunber@redhat.com>
1 parent 1489c0e commit 737e964

File tree

10 files changed

+223
-153
lines changed

10 files changed

+223
-153
lines changed

.github/workflows/pr-check-build-che-code-image.yaml

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
name: Pull Request Check
1414

1515
# Trigger the workflow on pull request
16-
on: [pull_request]
16+
on: [workflow_dispatch]
1717

1818
jobs:
1919
# build:
@@ -124,32 +124,17 @@ jobs:
124124

125125
- name: Build Che-Code Docker image
126126
run: |
127-
PR_NUMBER="${{ github.event.number }}"
128-
echo "Pull request $PR_NUMBER"
129-
130-
DEV_IMAGE_NAME="quay.io/che-incubator-pull-requests/che-code-dev:pr-$PR_NUMBER-dev-amd64"
127+
DEV_IMAGE_NAME="quay.io/rgrunber/che-code-sshd:latest"
131128
echo "Dev image $DEV_IMAGE_NAME"
132129
echo "_DEV_IMAGE_NAME=${DEV_IMAGE_NAME}" >> $GITHUB_ENV
133130
134131
docker buildx build \
135132
--platform linux/amd64 \
136133
--progress=plain \
137134
--push \
138-
-f build/dockerfiles/dev.ssh.Dockerfile \
135+
-f build/dockerfiles/dev.sshd.Dockerfile \
139136
-t ${DEV_IMAGE_NAME} .
140137
141138
- name: Display docker images
142139
run: |
143140
docker images
144-
145-
- name: 'Comment PR'
146-
uses: actions/github-script@v6
147-
with:
148-
script: |
149-
const { repo: { owner, repo } } = context;
150-
await github.rest.issues.createComment({
151-
issue_number: context.issue.number,
152-
owner: context.repo.owner,
153-
repo: context.repo.repo,
154-
body: `Pull Request Dev image published:\n👉 [${process.env._DEV_IMAGE_NAME}](https://${process.env._DEV_IMAGE_NAME})`
155-
})

build/dockerfiles/dev.ssh.Dockerfile

Lines changed: 0 additions & 70 deletions
This file was deleted.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Copyright (c) 2025 Red Hat, Inc.
2+
# This program and the accompanying materials are made
3+
# available under the terms of the Eclipse Public License 2.0
4+
# which is available at https://www.eclipse.org/legal/epl-2.0/
5+
#
6+
# SPDX-License-Identifier: EPL-2.0
7+
#
8+
9+
FROM quay.io/devfile/universal-developer-image:latest
10+
11+
USER 0
12+
13+
RUN dnf -y install libsecret openssh-server && \
14+
dnf -y clean all --enablerepo='*'
15+
16+
# Step 1. Generate SSH Host keys
17+
RUN mkdir /opt/ssh
18+
RUN chmod 755 /opt/ssh
19+
RUN chown -R root:root /opt/ssh/
20+
21+
RUN ssh-keygen -q -N "" -t dsa -f /opt/ssh/ssh_host_dsa_key && \
22+
ssh-keygen -q -N "" -t rsa -b 4096 -f /opt/ssh/ssh_host_rsa_key && \
23+
ssh-keygen -q -N "" -t ecdsa -f /opt/ssh/ssh_host_ecdsa_key && \
24+
ssh-keygen -q -N "" -t ed25519 -f /opt/ssh/ssh_host_ed25519_key
25+
26+
# Step 2. Configure SSH as non-root user
27+
RUN cp /etc/ssh/sshd_config /opt/ssh/
28+
29+
# Step 3. Fix permissions
30+
RUN chmod 644 /opt/ssh/ssh_host_* /opt/ssh/sshd_config
31+
32+
# Use non-privileged port, set user authorized keys, disable strict checks
33+
RUN sed -i \
34+
-e 's|#Port 22|Port 2022|' \
35+
-e 's|AuthorizedKeysFile .ssh/authorized_keys|AuthorizedKeysFile /home/user/ssh/authorized_keys|' \
36+
-e 's|#StrictModes yes|StrictModes=no|' \
37+
-e 's|#PidFile /var/run/sshd.pid|PidFile /tmp/sshd.pid|' \
38+
-e 's|#LogLevel INFO|LogLevel DEBUG3|' \
39+
/opt/ssh/sshd_config
40+
41+
# Provide new path containing host keys
42+
RUN sed -i \
43+
-e 's|#HostKey /etc/ssh/ssh_host_rsa_key|HostKey /opt/ssh/ssh_host_rsa_key|' \
44+
-e 's|#HostKey /etc/ssh/ssh_host_ecdsa_key|HostKey /opt/ssh/ssh_host_ecdsa_key|' \
45+
-e 's|#HostKey /etc/ssh/ssh_host_ed25519_key|HostKey /opt/ssh/ssh_host_ed25519_key|' \
46+
/opt/ssh/sshd_config
47+
48+
# Prepare SSH Keys
49+
RUN ssh-keygen -q -N "" -t ed25519 -f /opt/ssh/ssh_client_ed25519_key
50+
RUN chmod 644 /opt/ssh/ssh_client_*
51+
52+
# Add script to start and stop the service
53+
COPY --chown=0:0 /build/scripts/sshd.start /
54+
55+
RUN mkdir /opt/www
56+
COPY /build/scripts/server.js /opt/www/
57+
58+
#ENV USER_NAME=dev
59+
60+
EXPOSE 2022 3400
61+
62+
USER 10001

build/scripts/server.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
Copyright (c) 2025 Red Hat, Inc.
3+
This program and the accompanying materials are made
4+
available under the terms of the Eclipse Public License 2.0
5+
which is available at https://www.eclipse.org/legal/epl-2.0/
6+
7+
SPDX-License-Identifier: EPL-2.0
8+
*/
9+
10+
const http = require('http');
11+
const fs = require('fs');
12+
const hostname = '127.0.0.1';
13+
const port = 3400;
14+
15+
const server = http.createServer((req, res) => {
16+
res.statusCode = 200;
17+
res.setHeader('Content-Type', 'text/html');
18+
19+
let hasUserPrefSSHKey = fs.existsSync('/etc/ssh/dwo_ssh_key.pub');
20+
21+
let pubKey = "PUBLIC KEY COULD NOT BE DISPLAYED";
22+
try {
23+
pubKey = fs.readFileSync('/etc/ssh/dwo_ssh_key.pub', 'utf8');
24+
} catch (err) {
25+
// continue
26+
}
27+
28+
let genKey = "PRIVATE KEY NOT FOUND";
29+
try {
30+
genKey = fs.readFileSync('/opt/ssh/ssh_client_ed25519_key', 'utf8');
31+
} catch (err) {
32+
// continue
33+
}
34+
35+
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 :`;
40+
41+
res.end(`
42+
<!DOCTYPE html>
43+
<html>
44+
<head>
45+
<title>${process.env["DEVWORKSPACE_NAME"]}</title>
46+
</head>
47+
<body>
48+
<h1>Workspace ${process.env["DEVWORKSPACE_NAME"]} is running</h1>
49+
<div class="border">
50+
<ol>
51+
<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>
53+
<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>
56+
Host localhost
57+
HostName 127.0.0.1
58+
User ${process.env["USER_NAME"]}
59+
Port 2022
60+
IdentityFile /path/to/the/ssh_client_ed25519_key
61+
</pre>
62+
</p>
63+
</li>
64+
</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>
66+
</div>
67+
</body>
68+
</html>
69+
`);
70+
});
71+
72+
server.listen(port, hostname, () => {
73+
console.log(`Server running at http://${hostname}:${port}/`);
74+
});

build/scripts/sshd.start

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
#
3+
# Copyright (c) 2025 Red Hat, Inc.
4+
# This program and the accompanying materials are made
5+
# available under the terms of the Eclipse Public License 2.0
6+
# which is available at https://www.eclipse.org/legal/epl-2.0/
7+
#
8+
# SPDX-License-Identifier: EPL-2.0
9+
#
10+
11+
rm -rf /home/user/ssh
12+
mkdir -p /home/user/ssh
13+
if [ -f /etc/ssh/dwo_ssh_key.pub ]; then
14+
cp /etc/ssh/dwo_ssh_key.pub /home/user/ssh/authorized_keys
15+
else
16+
cp /opt/ssh/ssh_client_ed25519_key.pub /home/user/ssh/authorized_keys
17+
fi
18+
19+
# start
20+
/usr/sbin/sshd -D -f /opt/ssh/sshd_config -E /tmp/sshd.log

build/sshd.connect

Lines changed: 0 additions & 6 deletions
This file was deleted.

build/sshd.start

Lines changed: 0 additions & 13 deletions
This file was deleted.

che-code-sshd.yaml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#
2+
# Copyright (c) 2025 Red Hat, Inc.
3+
# This program and the accompanying materials are made
4+
# available under the terms of the Eclipse Public License 2.0
5+
# which is available at https://www.eclipse.org/legal/epl-2.0/
6+
#
7+
# SPDX-License-Identifier: EPL-2.0
8+
#
9+
# Contributors:
10+
# Red Hat, Inc. - initial API and implementation
11+
#
12+
13+
schemaVersion: 2.3.0
14+
metadata:
15+
name: che-code-sshd
16+
displayName: Visual Studio Code (desktop) (SSH)
17+
description: Visual Studio Code server for Eclipse Che over SSH - latest
18+
tags:
19+
- ssh
20+
- CLI
21+
- vscode
22+
attributes:
23+
arch:
24+
- x86_64
25+
- arm64
26+
- s390x
27+
- ppc64le
28+
publisher: che-incubator
29+
version: latest
30+
provider: Provided by [Microsoft](https://www.microsoft.com/) under [License](https://code.visualstudio.com/License)
31+
title: Visual Studio Code server for Eclipse Che over SSH - latest
32+
repository: https://github.com/rgrunber/che-code
33+
firstPublicationDate: '2025-08-01'
34+
35+
components:
36+
- name: che-code-sshd
37+
container:
38+
image: quay.io/rgrunber/che-code-sshd:latest
39+
memoryLimit: 1024Mi
40+
memoryRequest: 256Mi
41+
cpuLimit: 500m
42+
cpuRequest: 30m
43+
command:
44+
- sh
45+
- -c
46+
- "nohup /entrypoint.sh & nohup /sshd.start & nohup node /opt/www/server.js & tail -f /dev/null"
47+
endpoints:
48+
- name: che-code-sshd
49+
attributes:
50+
type: main
51+
discoverable: false
52+
urlRewriteSupported: true
53+
targetPort: 3400
54+
exposure: public
55+
secure: true
56+
protocol: https
57+
volumeMounts:
58+
- name: m2
59+
path: /home/user/.m2
60+
attributes:
61+
app.kubernetes.io/component: che-code-sshd
62+
app.kubernetes.io/part-of: che-code-server.eclipse.org
63+
- name: m2
64+
volume: {}

0 commit comments

Comments
 (0)