-
Notifications
You must be signed in to change notification settings - Fork 45
Support VS Code (local) to Devworkspace over SSH #560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| # Copyright (c) 2025 Red Hat, Inc. | ||
| # This program and the accompanying materials are made | ||
| # available under the terms of the Eclipse Public License 2.0 | ||
| # which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
| # | ||
| # SPDX-License-Identifier: EPL-2.0 | ||
| # | ||
|
|
||
| FROM quay.io/devfile/universal-developer-image:latest | ||
|
|
||
| USER 0 | ||
|
|
||
| RUN dnf -y install libsecret openssh-server && \ | ||
| dnf -y clean all --enablerepo='*' | ||
|
|
||
| # Step 1. Generate SSH Host keys | ||
| RUN mkdir /opt/ssh | ||
| RUN chmod 755 /opt/ssh | ||
| RUN chown -R root:root /opt/ssh/ | ||
|
|
||
| RUN ssh-keygen -q -N "" -t dsa -f /opt/ssh/ssh_host_dsa_key && \ | ||
| ssh-keygen -q -N "" -t rsa -b 4096 -f /opt/ssh/ssh_host_rsa_key && \ | ||
| ssh-keygen -q -N "" -t ecdsa -f /opt/ssh/ssh_host_ecdsa_key && \ | ||
| ssh-keygen -q -N "" -t ed25519 -f /opt/ssh/ssh_host_ed25519_key | ||
|
|
||
| # Step 2. Configure SSH as non-root user | ||
| RUN cp /etc/ssh/sshd_config /opt/ssh/ | ||
|
|
||
| # Step 3. Fix permissions | ||
| RUN chmod 644 /opt/ssh/ssh_host_* /opt/ssh/sshd_config | ||
|
|
||
| # Use non-privileged port, set user authorized keys, disable strict checks | ||
| RUN sed -i \ | ||
| -e 's|#Port 22|Port 2022|' \ | ||
| -e 's|AuthorizedKeysFile .ssh/authorized_keys|AuthorizedKeysFile /home/user/ssh/authorized_keys|' \ | ||
| -e 's|#StrictModes yes|StrictModes=no|' \ | ||
| -e 's|#PidFile /var/run/sshd.pid|PidFile /tmp/sshd.pid|' \ | ||
| -e 's|#LogLevel INFO|LogLevel DEBUG3|' \ | ||
| /opt/ssh/sshd_config | ||
|
|
||
| # Provide new path containing host keys | ||
| RUN sed -i \ | ||
| -e 's|#HostKey /etc/ssh/ssh_host_rsa_key|HostKey /opt/ssh/ssh_host_rsa_key|' \ | ||
| -e 's|#HostKey /etc/ssh/ssh_host_ecdsa_key|HostKey /opt/ssh/ssh_host_ecdsa_key|' \ | ||
| -e 's|#HostKey /etc/ssh/ssh_host_ed25519_key|HostKey /opt/ssh/ssh_host_ed25519_key|' \ | ||
| /opt/ssh/sshd_config | ||
|
|
||
| # Prepare SSH Keys | ||
| RUN ssh-keygen -q -N "" -t ed25519 -f /opt/ssh/ssh_client_ed25519_key | ||
| RUN chmod 644 /opt/ssh/ssh_client_* | ||
|
|
||
| # Add script to start and stop the service | ||
| COPY --chown=0:0 /build/scripts/sshd.start / | ||
|
|
||
| RUN mkdir /opt/www | ||
| COPY /build/scripts/server.js /opt/www/ | ||
|
|
||
| ENV USER_NAME=dev | ||
|
|
||
| EXPOSE 2022 3400 | ||
|
|
||
| USER 10001 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /* | ||
| Copyright (c) 2025 Red Hat, Inc. | ||
| This program and the accompanying materials are made | ||
| available under the terms of the Eclipse Public License 2.0 | ||
| which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
|
|
||
| SPDX-License-Identifier: EPL-2.0 | ||
| */ | ||
|
|
||
| const http = require('http'); | ||
| const fs = require('fs'); | ||
| const hostname = '127.0.0.1'; | ||
| const port = 3400; | ||
|
|
||
| const server = http.createServer((req, res) => { | ||
| res.statusCode = 200; | ||
| res.setHeader('Content-Type', 'text/html'); | ||
|
|
||
| let hasUserPrefSSHKey = fs.existsSync('/etc/ssh/dwo_ssh_key.pub'); | ||
|
|
||
| let pubKey = "PUBLIC KEY COULD NOT BE DISPLAYED"; | ||
| try { | ||
| pubKey = fs.readFileSync('/etc/ssh/dwo_ssh_key.pub', 'utf8'); | ||
| } catch (err) { | ||
| // continue | ||
| } | ||
|
|
||
| let genKey = "PRIVATE KEY NOT FOUND"; | ||
| try { | ||
| genKey = fs.readFileSync('/opt/ssh/ssh_client_ed25519_key', 'utf8'); | ||
| } catch (err) { | ||
| // continue | ||
| } | ||
|
|
||
| let keyMessage = ` | ||
| <pre>${hasUserPrefSSHKey ? pubKey : genKey}</pre> | ||
| </p> | ||
| <p> | ||
| This can also be configured locally in <code>$HOME/.ssh/config</code> with the following :`; | ||
|
|
||
| res.end(` | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <title>${process.env["DEVWORKSPACE_NAME"]}</title> | ||
| </head> | ||
| <body> | ||
| <h1>Workspace ${process.env["DEVWORKSPACE_NAME"]} is running</h1> | ||
| <div class="border"> | ||
| <ol> | ||
| <li>Make sure your local oc client is logged in to your OpenShift cluster</li> | ||
| <li><p class="center">Run <code>oc port-forward ${process.env["HOSTNAME"]} 2022:2022</code>. This establishes a connection to the workspace.</p></li> | ||
| <li> | ||
| <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} | ||
| <pre> | ||
| Host localhost | ||
| HostName 127.0.0.1 | ||
| User ${process.env["USER_NAME"]} | ||
| Port 2022 | ||
| IdentityFile /path/to/the/ssh_client_ed25519_key | ||
| </pre> | ||
| </p> | ||
| </li> | ||
| </ol> | ||
| <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> | ||
| </div> | ||
| </body> | ||
| </html> | ||
| `); | ||
| }); | ||
|
|
||
| server.listen(port, hostname, () => { | ||
| console.log(`Server running at http://${hostname}:${port}/`); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #!/bin/bash | ||
| # | ||
| # Copyright (c) 2025 Red Hat, Inc. | ||
| # This program and the accompanying materials are made | ||
| # available under the terms of the Eclipse Public License 2.0 | ||
| # which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
| # | ||
| # SPDX-License-Identifier: EPL-2.0 | ||
| # | ||
|
|
||
| rm -rf /home/user/ssh | ||
| mkdir -p /home/user/ssh | ||
| if [ -f /etc/ssh/dwo_ssh_key.pub ]; then | ||
| cp /etc/ssh/dwo_ssh_key.pub /home/user/ssh/authorized_keys | ||
| else | ||
| cp /opt/ssh/ssh_client_ed25519_key.pub /home/user/ssh/authorized_keys | ||
| fi | ||
|
|
||
| # start | ||
| /usr/sbin/sshd -D -f /opt/ssh/sshd_config -E /tmp/sshd.log |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.