Skip to content

Commit 8772e2b

Browse files
feat: add passwordFile, hashedPasswordFile, githubAuthTokenFile and absProxyBasePath options (#10)
Adds the final four options - `passwordFile` - `hashedPasswordFile` - `githubAuthTokenFile` - `absProxyBasePath` The decision to pass credentials via a file instead of embedding them directly in the devcontainer.json is to allow people the ability to not commit the password to source control.
1 parent f999968 commit 8772e2b

File tree

11 files changed

+150
-0
lines changed

11 files changed

+150
-0
lines changed

src/code-server/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ VS Code in the browser
1515

1616
| Options Id | Description | Type | Default Value |
1717
|-----|-----|-----|-----|
18+
| absProxyBasePath | The base path to prefix to all absproxy requests | string | - |
1819
| appName | The name to use in branding. Will be shown in titlebar and welcome message. | string | - |
1920
| auth | The type of authentication to use. When 'password' is selected, code-server will auto-generate a password. 'none' disables authentication entirely. | string | password |
2021
| cert | Path to certificate. A self signed certificate is generated if none is provided. | string | - |
@@ -29,9 +30,12 @@ VS Code in the browser
2930
| disableWorkspaceTrust | Disable Workspace Trust feature. This only affects the current session. | boolean | false |
3031
| enableProposedAPI | Comma-separated list of VS Code extension IDs to enable proposed API features for. | string | - |
3132
| extensions | Comma-separated list of VS Code extensions to install. Format: 'publisher.extension[@version]' (e.g., 'ms-python.python,ms-azuretools.vscode-docker'). | string | - |
33+
| githubAuthTokenFile | Path to a file containing your GitHub auth token. | string | - |
34+
| hashedPasswordFile | Path to a file containing the hashed password used for authentication. The password should be hashed with argon2 and be in the encoded form. This takes priority over `passwordFile`. | string | - |
3235
| host | The address to bind to for the code-server. Use '0.0.0.0' to listen on all interfaces. | string | 127.0.0.1 |
3336
| locale | Set VS Code display language and language shown on the login page. Format should be an IETF language tag (e.g., 'en', 'fr', 'zh-CN'). | string | - |
3437
| logFile | Path to a file to send stdout and stderr logs to from code-server. | string | /tmp/code-server.log |
38+
| passwordFile | Path to a file containing the password used for authentication. | string | - |
3539
| port | The port to bind to for the code-server. | string | 8080 |
3640
| proxyDomain | Domain used for proxying ports. | string | - |
3741
| socket | Path to a socket. When specified, host and port will be ignored. | string | - |

src/code-server/devcontainer-feature.json

+20
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
"version": "1.0.0",
55
"description": "VS Code in the browser",
66
"options": {
7+
"absProxyBasePath": {
8+
"type": "string",
9+
"default": "",
10+
"description": "The base path to prefix to all absproxy requests"
11+
},
712
"appName": {
813
"type": "string",
914
"default": "",
@@ -75,6 +80,16 @@
7580
"default": "",
7681
"description": "Comma-separated list of VS Code extensions to install. Format: 'publisher.extension[@version]' (e.g., 'ms-python.python,ms-azuretools.vscode-docker')."
7782
},
83+
"githubAuthTokenFile": {
84+
"type": "string",
85+
"default": "",
86+
"description": "Path to a file containing your GitHub auth token."
87+
},
88+
"hashedPasswordFile": {
89+
"type": "string",
90+
"default": "",
91+
"description": "Path to a file containing the hashed password used for authentication. The password should be hashed with argon2 and be in the encoded form. This takes priority over `passwordFile`."
92+
},
7893
"host": {
7994
"type": "string",
8095
"default": "127.0.0.1",
@@ -90,6 +105,11 @@
90105
"default": "/tmp/code-server.log",
91106
"description": "Path to a file to send stdout and stderr logs to from code-server."
92107
},
108+
"passwordFile": {
109+
"type": "string",
110+
"default": "",
111+
"description": "Path to a file containing the password used for authentication."
112+
},
93113
"port": {
94114
"type": "string",
95115
"default": "8080",

src/code-server/install.sh

+16
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ if [[ "$PROXYDOMAIN" ]]; then
106106
FLAGS+=(--proxy-domain "$PROXYDOMAIN")
107107
fi
108108

109+
if [[ "$ABSPROXYBASEPATH" ]]; then
110+
FLAGS+=(--abs-proxy-base-path "$ABSPROXYBASEPATH")
111+
fi
112+
109113
cat > /usr/local/bin/code-server-entrypoint <<EOF
110114
#!/usr/bin/env bash
111115
set -e
@@ -116,6 +120,18 @@ fi
116120
117121
$(declare -p FLAGS)
118122
123+
if [[ -f "$PASSWORDFILE" ]]; then
124+
export PASSWORD="\$(<"$PASSWORDFILE")"
125+
fi
126+
127+
if [[ -f "$HASHEDPASSWORDFILE" ]]; then
128+
export HASHED_PASSWORD="\$(<"$HASHEDPASSWORDFILE")"
129+
fi
130+
131+
if [[ -f "$GITHUBAUTHTOKENFILE" ]]; then
132+
export GITHUB_TOKEN="\$(<"$GITHUBAUTHTOKENFILE")"
133+
fi
134+
119135
code-server "\${FLAGS[@]}" "$CODE_SERVER_WORKSPACE" >"$LOGFILE" 2>&1
120136
EOF
121137

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 locale" grep '"--abs-proxy-base-path".*"/user/123/workspace"' < /usr/local/bin/code-server-entrypoint
13+
14+
# Report results
15+
reportResults
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
cat /tmp/code-server.log
13+
check "code-server github-auth-token-file" grep 'export GITHUB_TOKEN="$(<"/tmp/code-server-github-auth-token")"' < /usr/local/bin/code-server-entrypoint
14+
15+
# Report results
16+
reportResults
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM mcr.microsoft.com/devcontainers/base:ubuntu
2+
3+
RUN su vscode -c 'echo "github auth token" > /tmp/code-server-github-auth-token'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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 hashed-password-file" grep 'export HASHED_PASSWORD="$(<"/tmp/code-server-hashed-password")"' < /usr/local/bin/code-server-entrypoint
13+
check "code-server hashed-password" grep 'Using password from $HASHED_PASSWORD' < /tmp/code-server.log
14+
15+
# Report results
16+
reportResults
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM mcr.microsoft.com/devcontainers/base:ubuntu
2+
3+
RUN su vscode -c 'echo "\$argon2id\$v=19\$m=16,t=2,p=1\$c2FtcGxlc2FsdA\$YBn10Qizrh/i2jf/rPOCCA" > /tmp/code-server-hashed-password'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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 password-file" grep $'export PASSWORD="$(<"/tmp/code-server-password")"' < /usr/local/bin/code-server-entrypoint
13+
check "code-server password" grep 'Using password from $PASSWORD' < /tmp/code-server.log
14+
15+
# Report results
16+
reportResults
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM mcr.microsoft.com/devcontainers/base:ubuntu
2+
3+
RUN su vscode -c "echo 'some sample password' > /tmp/code-server-password"

test/code-server/scenarios.json

+38
Original file line numberDiff line numberDiff line change
@@ -227,5 +227,43 @@
227227
"proxyDomain": "dev.coder.com"
228228
}
229229
}
230+
},
231+
"code-server-password-file": {
232+
"build": {
233+
"dockerfile": "Dockerfile"
234+
},
235+
"features": {
236+
"code-server": {
237+
"passwordFile": "/tmp/code-server-password"
238+
}
239+
}
240+
},
241+
"code-server-hashed-password-file": {
242+
"build": {
243+
"dockerfile": "Dockerfile"
244+
},
245+
"features": {
246+
"code-server": {
247+
"hashedPasswordFile": "/tmp/code-server-hashed-password"
248+
}
249+
}
250+
},
251+
"code-server-github-auth-token-file": {
252+
"build": {
253+
"dockerfile": "Dockerfile"
254+
},
255+
"features": {
256+
"code-server": {
257+
"githubAuthTokenFile": "/tmp/code-server-github-auth-token"
258+
}
259+
}
260+
},
261+
"code-server-abs-proxy-base-path": {
262+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
263+
"features": {
264+
"code-server": {
265+
"absProxyBasePath": "/user/123/workspace"
266+
}
267+
}
230268
}
231269
}

0 commit comments

Comments
 (0)