Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 19 additions & 1 deletion src/code-server/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,32 @@ if [[ "$DISABLEWORKSPACETRUST" == "true" ]]; then
DISABLE_FLAGS+=(--disable-workspace-trust)
fi

CERT_FLAGS=()

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Alternative way:

Suggested change
CERT_FLAGS+=(--cert)
CERT_FLAGS+=("$CERT")
CERT_FLAGS+=(--cert "$CERT")

fi

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

if [[ -n "$CERTKEY" ]]; then
CERT_FLAGS+=(--cert-key)
CERT_FLAGS+=("$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"
}
}
}
}