From 889223e35f90203f364a05e96f774d3549be12ed Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Thu, 3 Nov 2022 17:48:27 +0100 Subject: [PATCH 1/5] Add experimental kradalby gh runner Remove old v2 runner in favour of self-hosted Signed-off-by: Kristoffer Dalby --- .../workflows/test-integration-v2-general.yml | 35 ------------------- .../test-integration-v2-kradalby.yml | 27 ++++++++++++++ 2 files changed, 27 insertions(+), 35 deletions(-) delete mode 100644 .github/workflows/test-integration-v2-general.yml create mode 100644 .github/workflows/test-integration-v2-kradalby.yml diff --git a/.github/workflows/test-integration-v2-general.yml b/.github/workflows/test-integration-v2-general.yml deleted file mode 100644 index f841422d..00000000 --- a/.github/workflows/test-integration-v2-general.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: Integration Test v2 - -on: [pull_request] - -jobs: - integration-test-v2: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 2 - - - name: Set Swap Space - uses: pierotofy/set-swap-space@master - with: - swap-size-gb: 10 - - - name: Get changed files - id: changed-files - uses: tj-actions/changed-files@v14.1 - with: - files: | - *.nix - go.* - **/*.go - integration_test/ - config-example.yaml - - - uses: cachix/install-nix-action@v16 - if: steps.changed-files.outputs.any_changed == 'true' - - - name: Run general integration tests - if: steps.changed-files.outputs.any_changed == 'true' - run: nix develop --command -- make test_integration_v2_general diff --git a/.github/workflows/test-integration-v2-kradalby.yml b/.github/workflows/test-integration-v2-kradalby.yml new file mode 100644 index 00000000..4416a7d4 --- /dev/null +++ b/.github/workflows/test-integration-v2-kradalby.yml @@ -0,0 +1,27 @@ +name: Integration Test v2 - kradalby + +on: [pull_request] + +jobs: + integration-test-v2-kradalby: + runs-on: [self-hosted, linux, x64, nixos, docker] + + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 2 + + # - name: Get changed files + # id: changed-files + # uses: tj-actions/changed-files@v14.1 + # with: + # files: | + # *.nix + # go.* + # **/*.go + # integration_test/ + # config-example.yaml + + - name: Run general integration tests + # if: steps.changed-files.outputs.any_changed == 'true' + run: nix develop --command -- make test_integration_v2_general From b2c0e37122b3ebe3d9efab97416892eea669cfdf Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Fri, 4 Nov 2022 10:32:57 +0100 Subject: [PATCH 2/5] Run on correct change Signed-off-by: Kristoffer Dalby --- .../test-integration-v2-kradalby.yml | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/test-integration-v2-kradalby.yml b/.github/workflows/test-integration-v2-kradalby.yml index 4416a7d4..c76c7896 100644 --- a/.github/workflows/test-integration-v2-kradalby.yml +++ b/.github/workflows/test-integration-v2-kradalby.yml @@ -11,17 +11,17 @@ jobs: with: fetch-depth: 2 - # - name: Get changed files - # id: changed-files - # uses: tj-actions/changed-files@v14.1 - # with: - # files: | - # *.nix - # go.* - # **/*.go - # integration_test/ - # config-example.yaml + - name: Get changed files + id: changed-files + uses: tj-actions/changed-files@v14.1 + with: + files: | + *.nix + go.* + **/*.go + integration_test/ + config-example.yaml - name: Run general integration tests - # if: steps.changed-files.outputs.any_changed == 'true' + if: steps.changed-files.outputs.any_changed == 'true' run: nix develop --command -- make test_integration_v2_general From c31328a54a42ca2e4b117572561e72b1bf93fb2c Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Fri, 4 Nov 2022 10:40:39 +0100 Subject: [PATCH 3/5] Fix bitrotted versions in gh ci Signed-off-by: Kristoffer Dalby --- .github/workflows/build.yml | 4 ++-- .github/workflows/contributors.yml | 2 +- .github/workflows/lint.yml | 4 ++-- .github/workflows/release.yml | 10 +++++----- .github/workflows/renovatebot.yml | 2 +- .github/workflows/test-integration-cli.yml | 4 ++-- .github/workflows/test-integration-derp.yml | 4 ++-- .github/workflows/test-integration-oidc.yml | 4 ++-- .github/workflows/test-integration-v2-kradalby.yml | 2 +- .github/workflows/test.yml | 4 ++-- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c42429d9..cab5e048 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,13 +13,13 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 2 - name: Get changed files id: changed-files - uses: tj-actions/changed-files@v14.1 + uses: tj-actions/changed-files@v34 with: files: | *.nix diff --git a/.github/workflows/contributors.yml b/.github/workflows/contributors.yml index aa0d9264..4b05ffd2 100644 --- a/.github/workflows/contributors.yml +++ b/.github/workflows/contributors.yml @@ -9,7 +9,7 @@ jobs: add-contributors: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Delete upstream contributor branch # Allow continue on failure to account for when the # upstream branch is deleted or does not exist. diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 6e208119..9c080d72 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -7,13 +7,13 @@ jobs: golangci-lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 2 - name: Get changed files id: changed-files - uses: tj-actions/changed-files@v14.1 + uses: tj-actions/changed-files@v34 with: files: | *.nix diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 41a2ee6e..a21a3b53 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,11 +12,11 @@ jobs: runs-on: ubuntu-18.04 # due to CGO we need to user an older version steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: fetch-depth: 0 - name: Set up Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v3 with: go-version: 1.19.0 @@ -37,7 +37,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: fetch-depth: 0 - name: Set up Docker Buildx @@ -100,7 +100,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: fetch-depth: 0 - name: Set up Docker Buildx @@ -166,7 +166,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: fetch-depth: 0 - name: Set up Docker Buildx diff --git a/.github/workflows/renovatebot.yml b/.github/workflows/renovatebot.yml index 53b976ca..b4f3ef0b 100644 --- a/.github/workflows/renovatebot.yml +++ b/.github/workflows/renovatebot.yml @@ -16,7 +16,7 @@ jobs: APP_ID: ${{ secrets.RENOVATEBOT_APP_ID }} - name: Checkout - uses: actions/checkout@v2.0.0 + uses: actions/checkout@v3 - name: Self-hosted Renovate uses: renovatebot/github-action@v31.81.3 diff --git a/.github/workflows/test-integration-cli.yml b/.github/workflows/test-integration-cli.yml index c97c5d5e..72cf31aa 100644 --- a/.github/workflows/test-integration-cli.yml +++ b/.github/workflows/test-integration-cli.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 2 @@ -18,7 +18,7 @@ jobs: - name: Get changed files id: changed-files - uses: tj-actions/changed-files@v14.1 + uses: tj-actions/changed-files@v34 with: files: | *.nix diff --git a/.github/workflows/test-integration-derp.yml b/.github/workflows/test-integration-derp.yml index 8610dd26..8945c887 100644 --- a/.github/workflows/test-integration-derp.yml +++ b/.github/workflows/test-integration-derp.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 2 @@ -18,7 +18,7 @@ jobs: - name: Get changed files id: changed-files - uses: tj-actions/changed-files@v14.1 + uses: tj-actions/changed-files@v34 with: files: | *.nix diff --git a/.github/workflows/test-integration-oidc.yml b/.github/workflows/test-integration-oidc.yml index edd1ab24..7a1718d5 100644 --- a/.github/workflows/test-integration-oidc.yml +++ b/.github/workflows/test-integration-oidc.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 2 @@ -18,7 +18,7 @@ jobs: - name: Get changed files id: changed-files - uses: tj-actions/changed-files@v14.1 + uses: tj-actions/changed-files@v34 with: files: | *.nix diff --git a/.github/workflows/test-integration-v2-kradalby.yml b/.github/workflows/test-integration-v2-kradalby.yml index c76c7896..a6ccea13 100644 --- a/.github/workflows/test-integration-v2-kradalby.yml +++ b/.github/workflows/test-integration-v2-kradalby.yml @@ -13,7 +13,7 @@ jobs: - name: Get changed files id: changed-files - uses: tj-actions/changed-files@v14.1 + uses: tj-actions/changed-files@v34 with: files: | *.nix diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 906ea590..774dfdd6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,13 +7,13 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 2 - name: Get changed files id: changed-files - uses: tj-actions/changed-files@v14.1 + uses: tj-actions/changed-files@v34 with: files: | *.nix From 527b580f5e87599d6564850481d8def727602a96 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Fri, 4 Nov 2022 11:26:33 +0100 Subject: [PATCH 4/5] Add build flag to enable TS2019 (#928) --- .goreleaser.yml | 8 ++++++++ CHANGELOG.md | 1 + Dockerfile | 2 +- Dockerfile.debug | 2 +- Makefile | 14 ++++++++------ app.go | 5 ++--- flake.nix | 4 +++- handler_legacy.go | 15 +++++++++++++++ handler_placeholder.go | 8 ++++++++ protocol_legacy.go | 2 ++ protocol_legacy_poll.go | 2 ++ 11 files changed, 51 insertions(+), 12 deletions(-) create mode 100644 handler_legacy.go create mode 100644 handler_placeholder.go diff --git a/.goreleaser.yml b/.goreleaser.yml index e776b5a7..d4c12c88 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -20,6 +20,8 @@ builds: - -mod=readonly ldflags: - -s -w -X github.com/juanfont/headscale/cmd/headscale/cli.Version=v{{.Version}} + tags: + - ts2019 - id: darwin-arm64 main: ./cmd/headscale/headscale.go @@ -34,6 +36,8 @@ builds: - -mod=readonly ldflags: - -s -w -X github.com/juanfont/headscale/cmd/headscale/cli.Version=v{{.Version}} + tags: + - ts2019 - id: linux-amd64 mod_timestamp: "{{ .CommitTimestamp }}" @@ -46,6 +50,8 @@ builds: main: ./cmd/headscale/headscale.go ldflags: - -s -w -X github.com/juanfont/headscale/cmd/headscale/cli.Version=v{{.Version}} + tags: + - ts2019 - id: linux-arm64 mod_timestamp: "{{ .CommitTimestamp }}" @@ -58,6 +64,8 @@ builds: main: ./cmd/headscale/headscale.go ldflags: - -s -w -X github.com/juanfont/headscale/cmd/headscale/cli.Version=v{{.Version}} + tags: + - ts2019 archives: - id: golang-cross diff --git a/CHANGELOG.md b/CHANGELOG.md index d6836bf0..8eafa7f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ - Remove `ip_prefix` configuration option and warning [#899](https://github.com/juanfont/headscale/pull/899) - Add `dns_config.override_local_dns` option [#905](https://github.com/juanfont/headscale/pull/905) - Fix some DNS config issues [#660](https://github.com/juanfont/headscale/issues/660) +- Make it possible to disable TS2019 with build flag [#928](https://github.com/juanfont/headscale/pull/928) ## 0.16.4 (2022-08-21) diff --git a/Dockerfile b/Dockerfile index 4a83c462..da2d07e0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,7 @@ RUN go mod download COPY . . -RUN CGO_ENABLED=0 GOOS=linux go install -ldflags="-s -w -X github.com/juanfont/headscale/cmd/headscale/cli.Version=$VERSION" -a ./cmd/headscale +RUN CGO_ENABLED=0 GOOS=linux go install -tags ts2019 -ldflags="-s -w -X github.com/juanfont/headscale/cmd/headscale/cli.Version=$VERSION" -a ./cmd/headscale RUN strip /go/bin/headscale RUN test -e /go/bin/headscale diff --git a/Dockerfile.debug b/Dockerfile.debug index a6003c64..7fbaef61 100644 --- a/Dockerfile.debug +++ b/Dockerfile.debug @@ -9,7 +9,7 @@ RUN go mod download COPY . . -RUN CGO_ENABLED=0 GOOS=linux go install -ldflags="-s -w -X github.com/juanfont/headscale/cmd/headscale/cli.Version=$VERSION" -a ./cmd/headscale +RUN CGO_ENABLED=0 GOOS=linux go install -tags ts2019 -ldflags="-s -w -X github.com/juanfont/headscale/cmd/headscale/cli.Version=$VERSION" -a ./cmd/headscale RUN test -e /go/bin/headscale # Debug image diff --git a/Makefile b/Makefile index df9f3140..45538942 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,8 @@ ifeq ($(filter $(GOOS), openbsd netbsd soloaris plan9), ) else endif +TAGS = -tags ts2019 + # GO_SOURCES = $(wildcard *.go) # PROTO_SOURCES = $(wildcard **/*.proto) GO_SOURCES = $(call rwildcard,,*.go) @@ -17,12 +19,12 @@ PROTO_SOURCES = $(call rwildcard,,*.proto) build: - GOOS=$(GOOS) CGO_ENABLED=0 go build -trimpath $(pieflags) -mod=readonly -ldflags "-s -w -X github.com/juanfont/headscale/cmd/headscale/cli.Version=$(version)" cmd/headscale/headscale.go + nix build dev: lint test build test: - @go test -short -coverprofile=coverage.out ./... + @go test $(TAGS) -short -coverprofile=coverage.out ./... test_integration: test_integration_cli test_integration_derp test_integration_oidc test_integration_v2_general @@ -34,7 +36,7 @@ test_integration_cli: -v ~/.cache/hs-integration-go:/go \ -v $$PWD:$$PWD -w $$PWD \ -v /var/run/docker.sock:/var/run/docker.sock golang:1 \ - go test -failfast -timeout 30m -count=1 -run IntegrationCLI ./... + go test $(TAGS) -failfast -timeout 30m -count=1 -run IntegrationCLI ./... test_integration_derp: docker network rm $$(docker network ls --filter name=headscale --quiet) || true @@ -44,7 +46,7 @@ test_integration_derp: -v ~/.cache/hs-integration-go:/go \ -v $$PWD:$$PWD -w $$PWD \ -v /var/run/docker.sock:/var/run/docker.sock golang:1 \ - go test -failfast -timeout 30m -count=1 -run IntegrationDERP ./... + go test $(TAGS) -failfast -timeout 30m -count=1 -run IntegrationDERP ./... test_integration_oidc: docker network rm $$(docker network ls --filter name=headscale --quiet) || true @@ -54,7 +56,7 @@ test_integration_oidc: -v ~/.cache/hs-integration-go:/go \ -v $$PWD:$$PWD -w $$PWD \ -v /var/run/docker.sock:/var/run/docker.sock golang:1 \ - go test -failfast -timeout 30m -count=1 -run IntegrationOIDC ./... + go test $(TAGS) -failfast -timeout 30m -count=1 -run IntegrationOIDC ./... test_integration_v2_general: docker run \ @@ -64,7 +66,7 @@ test_integration_v2_general: -v $$PWD:$$PWD -w $$PWD/integration \ -v /var/run/docker.sock:/var/run/docker.sock \ golang:1 \ - go test ./... -timeout 60m -parallel 6 + go test $(TAGS) -failfast ./... -timeout 60m -parallel 6 coverprofile_func: go tool cover -func=coverage.out diff --git a/app.go b/app.go index 38807c72..7a67e4a3 100644 --- a/app.go +++ b/app.go @@ -454,9 +454,8 @@ func (h *Headscale) createRouter(grpcMux *runtime.ServeMux) *mux.Router { router.HandleFunc("/health", h.HealthHandler).Methods(http.MethodGet) router.HandleFunc("/key", h.KeyHandler).Methods(http.MethodGet) router.HandleFunc("/register/{nkey}", h.RegisterWebAPI).Methods(http.MethodGet) - router.HandleFunc("/machine/{mkey}/map", h.PollNetMapHandler). - Methods(http.MethodPost) - router.HandleFunc("/machine/{mkey}", h.RegistrationHandler).Methods(http.MethodPost) + h.addLegacyHandlers(router) + router.HandleFunc("/oidc/register/{nkey}", h.RegisterOIDC).Methods(http.MethodGet) router.HandleFunc("/oidc/callback", h.OIDCCallback).Methods(http.MethodGet) router.HandleFunc("/apple", h.AppleConfigMessage).Methods(http.MethodGet) diff --git a/flake.nix b/flake.nix index 7b6c7866..595c8dc6 100644 --- a/flake.nix +++ b/flake.nix @@ -26,6 +26,8 @@ version = headscaleVersion; src = pkgs.lib.cleanSource self; + tags = ["ts2019"]; + # Only run unit tests when testing a build checkFlags = ["-short"]; @@ -135,7 +137,7 @@ buildInputs = devDeps; shellHook = '' - export GOFLAGS=-tags="integration,integration_general,integration_oidc,integration_cli,integration_derp" + export GOFLAGS=-tags="ts2019" ''; }; diff --git a/handler_legacy.go b/handler_legacy.go new file mode 100644 index 00000000..8911d430 --- /dev/null +++ b/handler_legacy.go @@ -0,0 +1,15 @@ +//go:build ts2019 + +package headscale + +import ( + "net/http" + + "github.com/gorilla/mux" +) + +func (h *Headscale) addLegacyHandlers(router *mux.Router) { + router.HandleFunc("/machine/{mkey}/map", h.PollNetMapHandler). + Methods(http.MethodPost) + router.HandleFunc("/machine/{mkey}", h.RegistrationHandler).Methods(http.MethodPost) +} diff --git a/handler_placeholder.go b/handler_placeholder.go new file mode 100644 index 00000000..25fe9c65 --- /dev/null +++ b/handler_placeholder.go @@ -0,0 +1,8 @@ +//go:build !ts2019 + +package headscale + +import "github.com/gorilla/mux" + +func (h *Headscale) addLegacyHandlers(router *mux.Router) { +} diff --git a/protocol_legacy.go b/protocol_legacy.go index 4e75d127..f636c175 100644 --- a/protocol_legacy.go +++ b/protocol_legacy.go @@ -1,3 +1,5 @@ +//go:build ts2019 + package headscale import ( diff --git a/protocol_legacy_poll.go b/protocol_legacy_poll.go index f27ee4e3..a8d9343a 100644 --- a/protocol_legacy_poll.go +++ b/protocol_legacy_poll.go @@ -1,3 +1,5 @@ +//go:build ts2019 + package headscale import ( From bf87b33292128856182da396107c4c0b58d0fc4f Mon Sep 17 00:00:00 2001 From: LiuHanCheng Date: Fri, 4 Nov 2022 19:27:23 +0800 Subject: [PATCH 5/5] feat: add information to the `/apple` page for the macOS standalone client user (#915) Co-authored-by: Kristoffer Dalby --- platform_config.go | 157 +++++++++++++---------------------------- templates/apple.html | 102 ++++++++++++++++++++++++++ templates/windows.html | 64 +++++++++++++++++ utils.go | 2 +- 4 files changed, 218 insertions(+), 107 deletions(-) create mode 100644 templates/apple.html create mode 100644 templates/windows.html diff --git a/platform_config.go b/platform_config.go index 7bceb0c9..eb11084f 100644 --- a/platform_config.go +++ b/platform_config.go @@ -2,6 +2,7 @@ package headscale import ( "bytes" + _ "embed" "html/template" "net/http" textTemplate "text/template" @@ -11,51 +12,18 @@ import ( "github.com/rs/zerolog/log" ) +//go:embed templates/apple.html +var appleTemplate string + +//go:embed templates/windows.html +var windowsTemplate string + // WindowsConfigMessage shows a simple message in the browser for how to configure the Windows Tailscale client. func (h *Headscale) WindowsConfigMessage( writer http.ResponseWriter, req *http.Request, ) { - winTemplate := template.Must(template.New("windows").Parse(` - - -

headscale

-

Windows registry configuration

-

- This page provides Windows registry information for the official Windows Tailscale client. -

-

- The registry file will configure Tailscale to use {{.URL}} as its control server. -

-

Caution

-

You should always download and inspect the registry file before installing it:

-
curl {{.URL}}/windows/tailscale.reg
- -

Installation

-

Headscale can be set to the default server by running the registry file:

- -

- Windows registry file -

- -
    -
  1. Download the registry file, then run it
  2. -
  3. Follow the prompts
  4. -
  5. Install and run the official windows Tailscale client
  6. -
  7. When the installation has finished, start Tailscale, and log in by clicking the icon in the system tray
  8. -
-

Or

-

Open command prompt with Administrator rights. Issue the following commands to add the required registry entries:

-
-REG ADD "HKLM\Software\Tailscale IPN" /v UnattendedMode /t REG_SZ /d always
-REG ADD "HKLM\Software\Tailscale IPN" /v LoginURL /t REG_SZ /d "{{.URL}}"
-

- Restart Tailscale and log in. -

- - -`)) - + winTemplate := template.Must(template.New("windows").Parse(windowsTemplate)) config := map[string]interface{}{ "URL": h.cfg.ServerURL, } @@ -136,55 +104,7 @@ func (h *Headscale) AppleConfigMessage( writer http.ResponseWriter, req *http.Request, ) { - appleTemplate := template.Must(template.New("apple").Parse(` - - -

headscale

-

Apple configuration profiles

-

- This page provides configuration profiles for the official Tailscale clients for iOS and macOS. -

-

- The profiles will configure Tailscale.app to use {{.URL}} as its control server. -

- -

Caution

-

You should always download and inspect the profile before installing it:

- -
curl {{.URL}}/apple/macos
- -

Profiles

- - - -

macOS

-

Headscale can be set to the default server by installing a Headscale configuration profile:

-

- macOS profile -

- -
    -
  1. Download the profile, then open it. When it has been opened, there should be a notification that a profile can be installed
  2. -
  3. Open System Preferences and go to "Profiles"
  4. -
  5. Find and install the Headscale profile
  6. -
  7. Restart Tailscale.app and log in
  8. -
- -

Or

-

Use your terminal to configure the default setting for Tailscale by issuing:

- defaults write io.tailscale.ipn.macos ControlURL {{.URL}} - -

Restart Tailscale.app and log in.

- - -`)) + appleTemplate := template.Must(template.New("apple").Parse(appleTemplate)) config := map[string]interface{}{ "URL": h.cfg.ServerURL, @@ -282,24 +202,33 @@ func (h *Headscale) ApplePlatformConfig( } var payload bytes.Buffer + handleMacError := func(ierr error) { + log.Error(). + Str("handler", "ApplePlatformConfig"). + Err(ierr). + Msg("Could not render Apple macOS template") + + writer.Header().Set("Content-Type", "text/plain; charset=utf-8") + writer.WriteHeader(http.StatusInternalServerError) + _, err := writer.Write([]byte("Could not render Apple macOS template")) + if err != nil { + log.Error(). + Caller(). + Err(err). + Msg("Failed to write response") + } + } switch platform { - case "macos": - if err := macosTemplate.Execute(&payload, platformConfig); err != nil { - log.Error(). - Str("handler", "ApplePlatformConfig"). - Err(err). - Msg("Could not render Apple macOS template") + case "macos-standlone": + if err := macosStandloneTemplate.Execute(&payload, platformConfig); err != nil { + handleMacError(err) - writer.Header().Set("Content-Type", "text/plain; charset=utf-8") - writer.WriteHeader(http.StatusInternalServerError) - _, err := writer.Write([]byte("Could not render Apple macOS template")) - if err != nil { - log.Error(). - Caller(). - Err(err). - Msg("Failed to write response") - } + return + } + case "macos-app-store": + if err := macosAppStoreTemplate.Execute(&payload, platformConfig); err != nil { + handleMacError(err) return } @@ -444,7 +373,7 @@ var iosTemplate = textTemplate.Must(textTemplate.New("iosTemplate").Parse(` `)) -var macosTemplate = template.Must(template.New("macosTemplate").Parse(` +var macosAppStoreTemplate = template.Must(template.New("macosTemplate").Parse(` PayloadType io.tailscale.ipn.macos @@ -456,7 +385,23 @@ var macosTemplate = template.Must(template.New("macosTemplate").Parse(` 1 PayloadEnabled - + ControlURL + {{.URL}} + +`)) + +var macosStandloneTemplate = template.Must(template.New("macosStandloneTemplate").Parse(` + + PayloadType + io.tailscale.ipn.macsys + PayloadUUID + {{.UUID}} + PayloadIdentifier + com.github.juanfont.headscale + PayloadVersion + 1 + PayloadEnabled + ControlURL {{.URL}} diff --git a/templates/apple.html b/templates/apple.html new file mode 100644 index 00000000..d21ff276 --- /dev/null +++ b/templates/apple.html @@ -0,0 +1,102 @@ + + + + + + + Document + + + +

headscale

+

Apple configuration profiles

+

+ This page provides + + configuration profiles + + for the official Tailscale clients for +

+ +

+ The profiles will configure Tailscale.app to use {{.URL}} as + its control server. +

+ +

Caution

+

+ You should always download and inspect the profile before installing it: +

+ +
curl {{.URL}}/apple/macos
+ +

Profiles

+ + + +

macOS

+

+ Headscale can be set to the default server by installing a Headscale + configuration profile: +

+

+ macOS AppStore profile + macOS Standalone profile +

+ +
    +
  1. + Download the profile, then open it. When it has been opened, there + should be a notification that a profile can be installed +
  2. +
  3. Open System Preferences and go to "Profiles"
  4. +
  5. Find and install the Headscale profile
  6. +
  7. Restart Tailscale.app and log in
  8. +
+ +

Or

+

+ Use your terminal to configure the default setting for Tailscale by + issuing: +

+
    +
  • + for app store client: + defaults write io.tailscale.ipn.macos ControlURL {{.URL}} +
  • +
  • + for standlone client: + defaults write io.tailscale.ipn.macsys ControlURL {{.URL}} +
  • +
+ +

Restart Tailscale.app and log in.

+ + diff --git a/templates/windows.html b/templates/windows.html new file mode 100644 index 00000000..5e13a72c --- /dev/null +++ b/templates/windows.html @@ -0,0 +1,64 @@ + + + + + + + Document + + + +

headscale

+

Windows registry configuration

+

+ This page provides Windows registry information for the official Windows + Tailscale client. +

+ +

+

+ The registry file will configure Tailscale to use {{.URL}} as + its control server. +

+ +

+

Caution

+

+ You should always download and inspect the registry file before installing + it: +

+
curl {{.URL}}/windows/tailscale.reg
+ +

Installation

+

+ Headscale can be set to the default server by running the registry file: +

+ +

+ Windows registry file +

+ +
    +
  1. Download the registry file, then run it
  2. +
  3. Follow the prompts
  4. +
  5. Install and run the official windows Tailscale client
  6. +
  7. + When the installation has finished, start Tailscale, and log in by + clicking the icon in the system tray +
  8. +
+

Or

+

+ Open command prompt with Administrator rights. Issue the following + commands to add the required registry entries: +

+
+REG ADD "HKLM\Software\Tailscale IPN" /v UnattendedMode /t REG_SZ /d always
+REG ADD "HKLM\Software\Tailscale IPN" /v LoginURL /t REG_SZ /d "{{.URL}}"
+

Restart Tailscale and log in.

+ +

+ + diff --git a/utils.go b/utils.go index fc1fafa2..c0599c99 100644 --- a/utils.go +++ b/utils.go @@ -347,7 +347,7 @@ func IsStringInSlice(slice []string, str string) bool { } func AbsolutePathFromConfigPath(path string) string { - // If a relative path is provided, prefix it with the the directory where + // If a relative path is provided, prefix it with the directory where // the config file was found. if (path != "") && !strings.HasPrefix(path, string(os.PathSeparator)) { dir, _ := filepath.Split(viper.ConfigFileUsed())