Skip to content

Commit d719798

Browse files
feat: add --cert* options (#6)
Add new configuration options for custom SSL certificates: - `cert`: Path to certificate - `certKey`: Path to certificate key - `certHost`: Hostname for self-signed certificate
1 parent 0825e4c commit d719798

File tree

6 files changed

+84
-1
lines changed

6 files changed

+84
-1
lines changed

Diff for: src/code-server/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ VS Code in the browser
1616
| Options Id | Description | Type | Default Value |
1717
|-----|-----|-----|-----|
1818
| auth | The type of authentication to use. When 'password' is selected, code-server will auto-generate a password. 'none' disables authentication entirely. | string | password |
19+
| cert | Path to certificate. A self signed certificate is generated if none is provided. | string | - |
20+
| certHost | hostname to use when generating a self signed certificate. | string | - |
21+
| certKey | path to certificate key when using non-generated cert. | string | - |
1922
| disableFileDownloads | Disable file downloads from Code. When enabled, users will not be able to download files from the editor. | boolean | false |
2023
| disableFileUploads | Disable file uploads to Code. When enabled, users will not be able to upload files to the editor. | boolean | false |
2124
| disableGettingStartedOverride | Disable the coder/coder override in the Help: Getting Started page. | boolean | false |

Diff for: src/code-server/devcontainer-feature.json

+15
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,21 @@
1010
"default": "password",
1111
"description": "The type of authentication to use. When 'password' is selected, code-server will auto-generate a password. 'none' disables authentication entirely."
1212
},
13+
"cert": {
14+
"type": "string",
15+
"default": "",
16+
"description": "Path to certificate. A self signed certificate is generated if none is provided."
17+
},
18+
"certHost": {
19+
"type": "string",
20+
"default": "",
21+
"description": "hostname to use when generating a self signed certificate."
22+
},
23+
"certKey": {
24+
"type": "string",
25+
"default": "",
26+
"description": "path to certificate key when using non-generated cert."
27+
},
1328
"disableFileDownloads": {
1429
"type": "boolean",
1530
"default": false,

Diff for: src/code-server/install.sh

+16-1
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,29 @@ if [[ "$DISABLEWORKSPACETRUST" == "true" ]]; then
5353
DISABLE_FLAGS+=(--disable-workspace-trust)
5454
fi
5555

56+
CERT_FLAGS=()
57+
58+
if [[ -n "$CERT" ]]; then
59+
CERT_FLAGS+=(--cert "$CERT")
60+
fi
61+
62+
if [[ -n "$CERTHOST" ]]; then
63+
CERT_FLAGS+=(--cert-host "$CERTHOST")
64+
fi
65+
66+
if [[ -n "$CERTKEY" ]]; then
67+
CERT_FLAGS+=(--cert-key "$CERTKEY")
68+
fi
69+
5670
cat > /usr/local/bin/code-server-entrypoint \
5771
<< EOF
5872
#!/usr/bin/env bash
5973
set -e
6074
6175
$(declare -p DISABLE_FLAGS)
76+
$(declare -p CERT_FLAGS)
6277
63-
su $_REMOTE_USER -c 'code-server --auth "$AUTH" --bind-addr "$HOST:$PORT" "\${DISABLE_FLAGS[@]}" "$CODE_SERVER_WORKSPACE"'
78+
su $_REMOTE_USER -c 'code-server --auth "$AUTH" --bind-addr "$HOST:$PORT" "\${DISABLE_FLAGS[@]}" "\${CERT_FLAGS[@]}" "$CODE_SERVER_WORKSPACE"'
6479
EOF
6580

6681
chmod +x /usr/local/bin/code-server-entrypoint

Diff for: test/code-server/code-server-cert-host.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Optional: Import test library bundled with the devcontainer CLI
5+
source dev-container-features-test-lib
6+
7+
# Feature-specific tests
8+
check "code-server version" code-server --version
9+
check "code-server running" pgrep -f 'code-server/lib/node.*/code-server'
10+
check "code-server listening" lsof -i "@127.0.0.1:8080"
11+
12+
check "code-server cert-host" grep '"--cert-host".*"coder.com"' < /usr/local/bin/code-server-entrypoint
13+
14+
# Report results
15+
reportResults

Diff for: test/code-server/code-server-cert.sh

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Optional: Import test library bundled with the devcontainer CLI
5+
source dev-container-features-test-lib
6+
7+
cat /usr/local/bin/code-server-entrypoint
8+
9+
# Feature-specific tests
10+
check "code-server version" code-server --version
11+
check "code-server running" pgrep -f 'code-server/lib/node.*/code-server'
12+
check "code-server listening" lsof -i "@127.0.0.1:8080"
13+
14+
check "code-server cert" grep '"--cert".*"/path/to/cert.pem"' < /usr/local/bin/code-server-entrypoint
15+
check "code-server cert-key" grep '"--cert-key".*"/path/to/key.pem"' < /usr/local/bin/code-server-entrypoint
16+
17+
# Report results
18+
reportResults

Diff for: test/code-server/scenarios.json

+17
Original file line numberDiff line numberDiff line change
@@ -124,5 +124,22 @@
124124
"disableWorkspaceTrust": true
125125
}
126126
}
127+
},
128+
"code-server-cert": {
129+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
130+
"features": {
131+
"code-server": {
132+
"cert": "/path/to/cert.pem",
133+
"certKey": "/path/to/key.pem"
134+
}
135+
}
136+
},
137+
"code-server-cert-host": {
138+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
139+
"features": {
140+
"code-server": {
141+
"certHost": "coder.com"
142+
}
143+
}
127144
}
128145
}

0 commit comments

Comments
 (0)