Skip to content

Commit fe40ea7

Browse files
committed
Add a feature to the tailscale devcontainer to auto-set the operator
1 parent 4430789 commit fe40ea7

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

src/tailscale/tailscaled-devcontainer-start.sh

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,21 @@
33
# Use of this source code is governed by a BSD-style
44
# license that can be found in the LICENSE file.
55

6+
# if an operator argument has been provided, set the operator to
7+
# the specified value; if the value is the special value "$USER"
8+
# then set the operator to the default user for the devcontainer.
9+
#
10+
# This is done before the sudo switchover so we have the actual
11+
# user persisted.
12+
if [[ -n "$OPERATOR" ]]; then
13+
if [[ "$OPERATOR" == "\$USER" ]]; then
14+
OPERATOR=$(id -un)
15+
fi
16+
export OPERATOR
17+
fi
18+
619
if [[ $(id -u) -ne 0 ]]; then
7-
if ! command -v sudo > /dev/null; then
20+
if ! command -v sudo >/dev/null; then
821
>&2 echo "tailscaled could not start as root."
922
exit 1
1023
fi
@@ -31,7 +44,6 @@ EOF
3144
fi
3245
fi
3346

34-
3547
TAILSCALED_PID=""
3648
TAILSCALED_SOCK=/var/run/tailscale/tailscaled.sock
3749
TAILSCALED_LOG=/var/log/tailscaled.log
@@ -72,6 +84,12 @@ if [[ -n "$auth_key" ]]; then
7284
if [[ -n "${CODESPACE_NAME}" ]]; then
7385
hostnamearg="--hostname=${CODESPACE_NAME}"
7486
fi
75-
/usr/local/bin/tailscale up --accept-routes --authkey="$auth_key" $hostnamearg
87+
88+
operatorarg=""
89+
if [[ -n "${OPERATOR}" ]]; then
90+
operatorarg="--operator=${OPERATOR}"
91+
fi
92+
93+
/usr/local/bin/tailscale up --accept-routes --authkey="$auth_key" $hostnamearg $operatorarg
7694
fi
7795
fi

test/tailscale/scenarios.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,13 @@
2727
"features": {
2828
"tailscale": {}
2929
}
30+
},
31+
"tailscale_operator": {
32+
"image": "ubuntu:latest",
33+
"features": {
34+
"tailscale": {
35+
"operator": "$USER"
36+
}
37+
}
3038
}
31-
}
39+
}

test/tailscale/tailscale_operator.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test.sh

0 commit comments

Comments
 (0)