Skip to content

Commit a1c99dd

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 <[email protected]>
1 parent 1489c0e commit a1c99dd

File tree

10 files changed

+192
-153
lines changed

10 files changed

+192
-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: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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 mkdir -p /home/user/ssh
50+
RUN ssh-keygen -q -N "" -t ed25519 -f /opt/ssh/ssh_client_ed25519_key
51+
RUN chmod 644 /opt/ssh/ssh_client_*
52+
53+
# Add script to start and stop the service
54+
COPY --chown=0:0 /build/scripts/sshd.start /
55+
56+
RUN mkdir /opt/www
57+
COPY /build/scripts/server.js /opt/www/
58+
59+
ENV USER_NAME=dev
60+
61+
EXPOSE 2022 3400
62+
63+
USER 10001

build/scripts/server.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
const http = require('http');
2+
const fs = require('fs');
3+
const hostname = '127.0.0.1';
4+
const port = 3400;
5+
6+
const server = http.createServer((req, res) => {
7+
// Set the response header
8+
res.statusCode = 200;
9+
res.setHeader('Content-Type', 'text/html'); // Specify HTML content
10+
11+
let keyContent = "PRIVATE KEY NOT FOUND";
12+
try {
13+
keyContent = fs.readFileSync('/opt/ssh/ssh_client_ed25519_key', 'utf8');
14+
} catch (err) {
15+
// continue
16+
}
17+
// Send the HTML content
18+
res.end(`
19+
<!DOCTYPE html>
20+
<html>
21+
<head>
22+
<title>${process.env["DEVWORKSPACE_NAME"]}</title>
23+
</head>
24+
<body>
25+
<h1>Workspace ${process.env["DEVWORKSPACE_NAME"]} is running</h1>
26+
<div class="border">
27+
<ol>
28+
<li>Make sure your local oc client is logged in to your OpenShift cluster</li>
29+
<li><p class="center">Run <code>oc port-forward ${process.env["HOSTNAME"]} 2022:2022</code></p></li>
30+
<li>
31+
<p>In VS Code, connect to <code>localhost</code> on port <code>2022</code> with user <code>${process.env["USER_NAME"]}</code> and the following identity file :</p>
32+
<p>
33+
<pre>
34+
${keyContent}
35+
</pre>
36+
</p>
37+
<p>
38+
This can also be configured locally in <code>$HOME/.ssh/config</code> with the following :
39+
</p>
40+
<p>
41+
<pre>
42+
Host localhost
43+
HostName 127.0.0.1
44+
User dev
45+
Port 2022
46+
IdentityFile /path/to/the/ssh_client_ed25519_key
47+
</pre>
48+
</p>
49+
</li>
50+
</ol>
51+
</div>
52+
</body>
53+
</html>
54+
`);
55+
});
56+
57+
server.listen(port, hostname, () => {
58+
console.log(`Server running at http://${hostname}:${port}/`);
59+
});

build/scripts/sshd.start

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
rm -rf /home/user/ssh
4+
mkdir -p /home/user/ssh
5+
cp /opt/ssh/ssh_client_ed25519_key.pub /home/user/ssh/authorized_keys
6+
7+
# start
8+
/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: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
attributes:
58+
app.kubernetes.io/component: che-code-sshd
59+
app.kubernetes.io/part-of: che-code-server.eclipse.org

devfile.pr-327.yaml

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

devfile.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
schemaVersion: 2.2.2
1111
metadata:
1212
name: che-code
13-
1413
components:
1514

1615
- name: dev

0 commit comments

Comments
 (0)