Skip to content

Add a feature to the tailscale devcontainer to auto-set the operator #58

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

offbyone
Copy link

@offbyone offbyone commented Aug 7, 2025

I think this works?

I'd like to have my codespace user automatically set as a tailscale operator.

@raggi raggi requested review from raggi and Copilot August 7, 2025 21:29
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

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)

@@ -0,0 +1 @@
test.sh
Copy link
Preview

Copilot AI Aug 7, 2025

Choose a reason for hiding this comment

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

The test file contains only 'test.sh' which appears to be a placeholder. This should contain actual test logic for the operator functionality.

Suggested change
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

Copilot uses AI. Check for mistakes.

# This is done before the sudo switchover so we have the actual
# user persisted.
if [[ -n "$OPERATOR" ]]; then
if [[ "$OPERATOR" == "\$USER" ]]; then
Copy link
Preview

Copilot AI Aug 7, 2025

Choose a reason for hiding this comment

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

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.

Suggested change
if [[ "$OPERATOR" == "\$USER" ]]; then
if [[ "$OPERATOR" == '$USER' ]]; then

Copilot uses AI. Check for mistakes.

operatorarg="--operator=${OPERATOR}"
fi

/usr/local/bin/tailscale up --accept-routes --authkey="$auth_key" $hostnamearg $operatorarg
Copy link
Preview

Copilot AI Aug 7, 2025

Choose a reason for hiding this comment

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

The variables $hostnamearg and $operatorarg should be quoted to prevent word splitting and glob expansion issues if they contain spaces or special characters.

Suggested change
/usr/local/bin/tailscale up --accept-routes --authkey="$auth_key" $hostnamearg $operatorarg
/usr/local/bin/tailscale up --accept-routes --authkey="$auth_key" "$hostnamearg" "$operatorarg"

Copilot uses AI. Check for mistakes.

@raggi raggi force-pushed the ts-operator branch 7 times, most recently from f95bc2e to ee705c6 Compare August 8, 2025 00:39
@raggi
Copy link
Member

raggi commented Aug 8, 2025

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

@offbyone
Copy link
Author

offbyone commented Aug 8, 2025

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.

@bradfitz
Copy link
Member

bradfitz commented Aug 8, 2025

Is codespace always a single-user environment? Maybe we can just change this in tailscaled so setting --operator isn't even required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants