Skip to content

feat: add --cert* options #6

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 2 commits into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/code-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ VS Code in the browser
| Options Id | Description | Type | Default Value |
|-----|-----|-----|-----|
| auth | The type of authentication to use. When 'password' is selected, code-server will auto-generate a password. 'none' disables authentication entirely. | string | password |
| cert | Path to certificate. A self signed certificate is generated if none is provided. | string | - |
| certHost | hostname to use when generating a self signed certificate. | string | - |
| certKey | path to certificate key when using non-generated cert. | string | - |
| disableFileDownloads | Disable file downloads from Code. When enabled, users will not be able to download files from the editor. | boolean | false |
| disableFileUploads | Disable file uploads to Code. When enabled, users will not be able to upload files to the editor. | boolean | false |
| disableGettingStartedOverride | Disable the coder/coder override in the Help: Getting Started page. | boolean | false |
Expand Down
15 changes: 15 additions & 0 deletions src/code-server/devcontainer-feature.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@
"default": "password",
"description": "The type of authentication to use. When 'password' is selected, code-server will auto-generate a password. 'none' disables authentication entirely."
},
"cert": {
"type": "string",
"default": "",
"description": "Path to certificate. A self signed certificate is generated if none is provided."
},
"certHost": {
"type": "string",
"default": "",
"description": "hostname to use when generating a self signed certificate."
},
"certKey": {
"type": "string",
"default": "",
"description": "path to certificate key when using non-generated cert."
},
"disableFileDownloads": {
"type": "boolean",
"default": false,
Expand Down
17 changes: 16 additions & 1 deletion src/code-server/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,29 @@ if [[ "$DISABLEWORKSPACETRUST" == "true" ]]; then
DISABLE_FLAGS+=(--disable-workspace-trust)
fi

CERT_FLAGS=()

if [[ -n "$CERT" ]]; then
CERT_FLAGS+=(--cert "$CERT")
fi

if [[ -n "$CERTHOST" ]]; then
CERT_FLAGS+=(--cert-host "$CERTHOST")
fi

if [[ -n "$CERTKEY" ]]; then
CERT_FLAGS+=(--cert-key "$CERTKEY")
fi

cat > /usr/local/bin/code-server-entrypoint \
<< EOF
#!/usr/bin/env bash
set -e

$(declare -p DISABLE_FLAGS)
$(declare -p CERT_FLAGS)

su $_REMOTE_USER -c 'code-server --auth "$AUTH" --bind-addr "$HOST:$PORT" "\${DISABLE_FLAGS[@]}" "$CODE_SERVER_WORKSPACE"'
su $_REMOTE_USER -c 'code-server --auth "$AUTH" --bind-addr "$HOST:$PORT" "\${DISABLE_FLAGS[@]}" "\${CERT_FLAGS[@]}" "$CODE_SERVER_WORKSPACE"'
EOF

chmod +x /usr/local/bin/code-server-entrypoint
15 changes: 15 additions & 0 deletions test/code-server/code-server-cert-host.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
set -e

# Optional: Import test library bundled with the devcontainer CLI
source dev-container-features-test-lib

# Feature-specific tests
check "code-server version" code-server --version
check "code-server running" pgrep -f 'code-server/lib/node.*/code-server'
check "code-server listening" lsof -i "@127.0.0.1:8080"

check "code-server cert-host" grep '"--cert-host".*"coder.com"' < /usr/local/bin/code-server-entrypoint

# Report results
reportResults
18 changes: 18 additions & 0 deletions test/code-server/code-server-cert.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
set -e

# Optional: Import test library bundled with the devcontainer CLI
source dev-container-features-test-lib

cat /usr/local/bin/code-server-entrypoint

# Feature-specific tests
check "code-server version" code-server --version
check "code-server running" pgrep -f 'code-server/lib/node.*/code-server'
check "code-server listening" lsof -i "@127.0.0.1:8080"

check "code-server cert" grep '"--cert".*"/path/to/cert.pem"' < /usr/local/bin/code-server-entrypoint
check "code-server cert-key" grep '"--cert-key".*"/path/to/key.pem"' < /usr/local/bin/code-server-entrypoint

# Report results
reportResults
17 changes: 17 additions & 0 deletions test/code-server/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,22 @@
"disableWorkspaceTrust": true
}
}
},
"code-server-cert": {
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"features": {
"code-server": {
"cert": "/path/to/cert.pem",
"certKey": "/path/to/key.pem"
}
}
},
"code-server-cert-host": {
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"features": {
"code-server": {
"certHost": "coder.com"
}
}
}
}