Add a feature to the tailscale devcontainer to auto-set the operator#58
Add a feature to the tailscale devcontainer to auto-set the operator#58offbyone wants to merge 2 commits intotailscale:mainfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds functionality to automatically set a Tailscale operator in devcontainers. The feature allows users to specify an operator value that can be a literal username or the special value "$USER" which resolves to the current devcontainer user.
Key changes:
- Added operator parameter handling with special "$USER" expansion logic
- Enhanced the tailscale up command to include operator argument when specified
- Added test scenario for the new operator functionality
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/tailscale/tailscaled-devcontainer-start.sh | Added operator parameter processing and integrated operator argument into tailscale up command |
| test/tailscale/scenarios.json | Added test scenario for operator functionality using "$USER" value |
| test/tailscale/tailscale_operator.sh | Added test script file (appears to be a placeholder) |
test/tailscale/tailscale_operator.sh
Outdated
| @@ -0,0 +1 @@ | |||
| test.sh No newline at end of file | |||
There was a problem hiding this comment.
The test file contains only 'test.sh' which appears to be a placeholder. This should contain actual test logic for the operator functionality.
| test.sh | |
| #!/bin/bash | |
| # Basic test for Tailscale operator functionality | |
| set -e | |
| # Path to the operator binary (update as needed) | |
| OPERATOR_BIN="./tailscale-operator" | |
| # Check if the operator binary exists | |
| if [ ! -f "$OPERATOR_BIN" ]; then | |
| echo "FAIL: Operator binary not found at $OPERATOR_BIN" | |
| exit 1 | |
| fi | |
| # Check if the operator binary is executable | |
| if [ ! -x "$OPERATOR_BIN" ]; then | |
| echo "FAIL: Operator binary is not executable" | |
| exit 1 | |
| fi | |
| # Run the operator with --version and check output | |
| VERSION_OUTPUT=$("$OPERATOR_BIN" --version 2>&1) | |
| if [[ "$VERSION_OUTPUT" == "" ]]; then | |
| echo "FAIL: Operator did not return a version" | |
| exit 1 | |
| fi | |
| echo "PASS: Operator binary exists, is executable, and returns version:" | |
| echo "$VERSION_OUTPUT" | |
| exit 0 |
| # This is done before the sudo switchover so we have the actual | ||
| # user persisted. | ||
| if [[ -n "$OPERATOR" ]]; then | ||
| if [[ "$OPERATOR" == "\$USER" ]]; then |
There was a problem hiding this comment.
The string comparison uses escaped dollar sign '$USER' but the test scenario uses '$USER' without escaping. This comparison will never match the actual input from scenarios.json.
| if [[ "$OPERATOR" == "\$USER" ]]; then | |
| if [[ "$OPERATOR" == '$USER' ]]; then |
| operatorarg="--operator=${OPERATOR}" | ||
| fi | ||
|
|
||
| /usr/local/bin/tailscale up --accept-routes --authkey="$auth_key" $hostnamearg $operatorarg |
There was a problem hiding this comment.
The variables $hostnamearg and $operatorarg should be quoted to prevent word splitting and glob expansion issues if they contain spaces or special characters.
| /usr/local/bin/tailscale up --accept-routes --authkey="$auth_key" $hostnamearg $operatorarg | |
| /usr/local/bin/tailscale up --accept-routes --authkey="$auth_key" "$hostnamearg" "$operatorarg" |
f95bc2e to
ee705c6
Compare
|
Gah, I remember debugging this awful test framework before, and I'm hitting an issue I experienced then I think, but it's so opaque and has no local execution story |
I feel that! I tried to see if I could run it locally and all but gave up. |
|
Is codespace always a single-user environment? Maybe we can just change this in tailscaled so setting |
|
I think they mostly will be, but I don't know the full range of ways things like devcontainers can be implemented. |
I think this works?
I'd like to have my codespace user automatically set as a tailscale operator.