Skip to content

feat: add opt-in Tailscale SSH support to devcontainer (#208) - #211

Merged
c-vigo merged 9 commits into
feature/70-remote-devc-orchestrationfrom
feature/208-tailscale-ssh-support
Mar 7, 2026
Merged

c-vigo merged 9 commits into
feature/70-remote-devc-orchestrationfrom
feature/208-tailscale-ssh-support

Conversation

@gerchowl

@gerchowl gerchowl commented Feb 26, 2026 •

Copy link
Copy Markdown
Contributor

Description

Add opt-in Tailscale SSH support to the devcontainer workspace template. When TAILSCALE_AUTHKEY is set via docker-compose.local.yaml, Tailscale is installed at container creation and started on every container start, enabling direct SSH access over the tailnet. When unset, all hooks are silent no-ops — zero impact on existing users.

This enables tools like Cur*or GUI to execute shell commands inside the container via SSH remote, working around the known devcontainer protocol limitation.

Type of Change

  • feat -- New feature
  • fix -- Bug fix
  • docs -- Documentation only
  • chore -- Maintenance task (deps, config, etc.)
  • refactor -- Code restructuring (no behavior change)
  • test -- Adding or updating tests
  • ci -- CI/CD pipeline changes
  • build -- Build system or dependency changes
  • revert -- Reverts a previous commit
  • style -- Code style (formatting, whitespace)

Modifiers

  • Breaking change (!) -- This change breaks backward compatibility

Changes Made

  • assets/workspace/.devcontainer/scripts/setup-tailscale.sh (new) — Single script with install and start subcommands. Uses userspace networking (--tun=userspace-networking), Tailscale SSH (--ssh), and auto-generates hostname from devcontainer.json name field.
  • assets/workspace/.devcontainer/scripts/post-create.sh — Added hook to setup-tailscale.sh install after dependency sync.
  • assets/workspace/.devcontainer/scripts/post-start.sh — Added SCRIPT_DIR resolution and hook to setup-tailscale.sh start after dependency sync.
  • assets/workspace/.devcontainer/docker-compose.local.yaml — Added commented example for TAILSCALE_AUTHKEY and TAILSCALE_HOSTNAME env vars.
  • assets/workspace/.devcontainer/README.md — Added "Tailscale SSH" section with prerequisites, setup, ACL configuration, and how-it-works documentation.
  • tests/bats/setup-tailscale.bats (new) — 9 BATS tests covering script structure, opt-in gate (no-op when authkey unset/empty), and invalid subcommand handling.
  • CHANGELOG.md — Added entry under ## Unreleased → ### Added.

Changelog Entry

Added

  • Opt-in Tailscale SSH support for devcontainer (#208)
    • New setup-tailscale.sh script with install and start subcommands
    • Hooks into post-create.sh (install) and post-start.sh (start)
    • Silent no-op when TAILSCALE_AUTHKEY is unset — zero impact on existing users
    • Commented example in docker-compose.local.yaml for quick setup
    • Documentation in .devcontainer/README.md with quick-start and ACL instructions

Testing

  • Tests pass locally (just test)
  • Manual testing performed (describe below)

Manual Testing Details

N/A — Live Tailscale testing requires network access and a valid authkey. BATS tests cover the opt-in gate logic (the critical behavior).

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation accordingly (edit docs/templates/, then run just docs)
  • I have updated CHANGELOG.md in the [Unreleased] section (and pasted the entry above)
  • My changes generate no new warnings or errors
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

Additional Notes

Refs: #208

@c-vigo

c-vigo commented Mar 3, 2026

Copy link
Copy Markdown
Contributor

Would it make sense to install tailscale in the image instead of at the host, and only enable if the env variable is set?

@gerchowl

gerchowl commented Mar 3, 2026

Copy link
Copy Markdown
Contributor Author

it is doing it in the image. that was the idea, also in this way it does not persist, i.e. you can set ephemeral auth in tailscale so it will die eventually.
even though i hit issues every now and then still...
potentially this could also help with the CI issues if dagger doesnt? :-D
just wiring up the ssh between them via tailscale, you could even check what the gh runners are doing with the test containers ;-)

@c-vigo

c-vigo commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

@gerchowl Somehow for me the tailscaled service was dying after the postAttach command. Can you verify that with the latest change it still works for you, and merge?

Architecture decisions, lifecycle hook placement, programmatic key
generation via OAuth API, git signing gap, and future considerations.
Ported from fd5 prototype and extended with OAuth key generation flow.

Refs: #208
@c-vigo
c-vigo merged commit 3d8c002 into feature/70-remote-devc-orchestration Mar 7, 2026
1 check passed
@c-vigo
c-vigo deleted the feature/208-tailscale-ssh-support branch March 7, 2026 06:22
gerchowl added a commit that referenced this pull request Mar 7, 2026
## Summary

- Add `--open <ide>|none` flag to decouple IDE from infra (`--open none`
for headless/scripted use)
- Add `--yes` flag for non-interactive mode
- Add `inject_tailscale_key()` — generates ephemeral Tailscale auth keys
via OAuth API and injects into remote `docker-compose.local.yaml`
- Key injection is fully opt-in: silent no-op when
`TS_CLIENT_ID`/`TS_CLIENT_SECRET` are absent

## How it works

```
Local: TS_CLIENT_ID + TS_CLIENT_SECRET
  → OAuth token from api.tailscale.com
  → Ephemeral auth key (tag:devcontainer)
  → SSH inject into remote docker-compose.local.yaml
  → compose up → container joins tailnet
```

## Test plan

- [x] BATS: `--open none` skips editor detection
- [x] BATS: `--open code` fails when code not in PATH
- [x] BATS: `--open invalid` rejected
- [x] BATS: `--yes` accepted
- [x] BATS: `inject_tailscale_key` skips when OAuth creds unset
- [x] BATS: function defined and called in main
- [x] All 34 existing + new tests pass
- [ ] Manual: test with real Tailscale OAuth creds on remote host

## Part of

Epic: #232
Closes: #230
Depends on: #208 (Tailscale SSH in workspace template)

## References

- Design doc: `docs/designs/tailscale-ssh.md` (added in PR #211)
- [Tailscale OAuth API](https://tailscale.com/kb/1215/oauth-clients)
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.

2 participants