From 11b6693f945079d83e80c7baef69568dfa3fdb6e Mon Sep 17 00:00:00 2001 From: hopleus Date: Sat, 5 Oct 2024 11:23:10 +0300 Subject: [PATCH] Added the ability to configure endpoints availability (Platform Configs and Swagger) --- .goreleaser.yml | 88 +++++++++++++++++++-------------------- CHANGELOG.md | 5 +++ README.md | 7 ++++ config-example.yaml | 7 ++++ hscontrol/app.go | 23 ++++++---- hscontrol/types/config.go | 15 +++++++ 6 files changed, 92 insertions(+), 53 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index ddf829ade5..ed74983d0b 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -110,28 +110,28 @@ kos: - '{{ trimprefix .Tag "v" }}' - "sha-{{ .ShortCommit }}" - - id: dockerhub - build: headscale - base_image: gcr.io/distroless/base-debian12 - repository: hopleus/headscale - bare: true - platforms: - - linux/amd64 - - linux/386 - - linux/arm64 - - linux/arm/v7 - tags: - - "{{ if not .Prerelease }}latest{{ end }}" - - "{{ if not .Prerelease }}{{ .Major }}.{{ .Minor }}.{{ .Patch }}{{ end }}" - - "{{ if not .Prerelease }}{{ .Major }}.{{ .Minor }}{{ end }}" - - "{{ if not .Prerelease }}{{ .Major }}{{ end }}" - - "{{ if not .Prerelease }}v{{ .Major }}.{{ .Minor }}.{{ .Patch }}{{ end }}" - - "{{ if not .Prerelease }}v{{ .Major }}.{{ .Minor }}{{ end }}" - - "{{ if not .Prerelease }}v{{ .Major }}{{ end }}" - - "{{ if not .Prerelease }}stable{{ else }}unstable{{ end }}" - - "{{ .Tag }}" - - '{{ trimprefix .Tag "v" }}' - - "sha-{{ .ShortCommit }}" +# - id: dockerhub +# build: headscale +# base_image: gcr.io/distroless/base-debian12 +# repository: hopleus/headscale +# bare: true +# platforms: +# - linux/amd64 +# - linux/386 +# - linux/arm64 +# - linux/arm/v7 +# tags: +# - "{{ if not .Prerelease }}latest{{ end }}" +# - "{{ if not .Prerelease }}{{ .Major }}.{{ .Minor }}.{{ .Patch }}{{ end }}" +# - "{{ if not .Prerelease }}{{ .Major }}.{{ .Minor }}{{ end }}" +# - "{{ if not .Prerelease }}{{ .Major }}{{ end }}" +# - "{{ if not .Prerelease }}v{{ .Major }}.{{ .Minor }}.{{ .Patch }}{{ end }}" +# - "{{ if not .Prerelease }}v{{ .Major }}.{{ .Minor }}{{ end }}" +# - "{{ if not .Prerelease }}v{{ .Major }}{{ end }}" +# - "{{ if not .Prerelease }}stable{{ else }}unstable{{ end }}" +# - "{{ .Tag }}" +# - '{{ trimprefix .Tag "v" }}' +# - "sha-{{ .ShortCommit }}" - id: ghcr-debug repository: ghcr.io/hopleus/headscale @@ -159,28 +159,28 @@ kos: - '{{ trimprefix .Tag "v" }}-debug' - "sha-{{ .ShortCommit }}-debug" - - id: dockerhub-debug - build: headscale - base_image: gcr.io/distroless/base-debian12:debug - repository: hopleus/headscale - bare: true - platforms: - - linux/amd64 - - linux/386 - - linux/arm64 - - linux/arm/v7 - tags: - - "{{ if not .Prerelease }}latest-debug{{ end }}" - - "{{ if not .Prerelease }}{{ .Major }}.{{ .Minor }}.{{ .Patch }}-debug{{ end }}" - - "{{ if not .Prerelease }}{{ .Major }}.{{ .Minor }}-debug{{ end }}" - - "{{ if not .Prerelease }}{{ .Major }}-debug{{ end }}" - - "{{ if not .Prerelease }}v{{ .Major }}.{{ .Minor }}.{{ .Patch }}-debug{{ end }}" - - "{{ if not .Prerelease }}v{{ .Major }}.{{ .Minor }}-debug{{ end }}" - - "{{ if not .Prerelease }}v{{ .Major }}-debug{{ end }}" - - "{{ if not .Prerelease }}stable{{ else }}unstable-debug{{ end }}" - - "{{ .Tag }}-debug" - - '{{ trimprefix .Tag "v" }}-debug' - - "sha-{{ .ShortCommit }}-debug" +# - id: dockerhub-debug +# build: headscale +# base_image: gcr.io/distroless/base-debian12:debug +# repository: hopleus/headscale +# bare: true +# platforms: +# - linux/amd64 +# - linux/386 +# - linux/arm64 +# - linux/arm/v7 +# tags: +# - "{{ if not .Prerelease }}latest-debug{{ end }}" +# - "{{ if not .Prerelease }}{{ .Major }}.{{ .Minor }}.{{ .Patch }}-debug{{ end }}" +# - "{{ if not .Prerelease }}{{ .Major }}.{{ .Minor }}-debug{{ end }}" +# - "{{ if not .Prerelease }}{{ .Major }}-debug{{ end }}" +# - "{{ if not .Prerelease }}v{{ .Major }}.{{ .Minor }}.{{ .Patch }}-debug{{ end }}" +# - "{{ if not .Prerelease }}v{{ .Major }}.{{ .Minor }}-debug{{ end }}" +# - "{{ if not .Prerelease }}v{{ .Major }}-debug{{ end }}" +# - "{{ if not .Prerelease }}stable{{ else }}unstable-debug{{ end }}" +# - "{{ .Tag }}-debug" +# - '{{ trimprefix .Tag "v" }}-debug' +# - "sha-{{ .ShortCommit }}-debug" checksum: name_template: "checksums.txt" diff --git a/CHANGELOG.md b/CHANGELOG.md index d09e1d2274..3fa7f7ed34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,11 @@ - Improved compatibilty of built-in DERP server with clients connecting over WebSocket. - Allow nodes to use SSH agent forwarding [#2145](https://github.com/juanfont/headscale/pull/2145) +## [FORK] 0.23.0-1 (2024-10-04) +### Changes + +- Add HostInfo to Node response +- Added the ability to configure endpoints availability (Platform Configs and Swagger) ## 0.23.0 (2024-09-18) diff --git a/README.md b/README.md index ff44e8e466..9f2706f05b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,10 @@ +# Differences from the original HeadScale assembly + +- [x] Add HostInfo to Node response +- [x] Added the ability to configure endpoints availability (Platform Configs and Swagger) + +# HeadScale + ![headscale logo](./docs/logo/headscale3_header_stacked_left.png) ![ci](https://github.com/juanfont/headscale/actions/workflows/test.yml/badge.svg) diff --git a/config-example.yaml b/config-example.yaml index 5b757bc959..3a35cdba7d 100644 --- a/config-example.yaml +++ b/config-example.yaml @@ -384,3 +384,10 @@ logtail: # default static port 41641. This option is intended as a workaround for some buggy # firewall devices. See https://tailscale.com/kb/1181/firewalls/ for more information. randomize_client_port: false + +# Configuration routes +routes: + # Disabling routes to download configuration for windows and apple + platformConfig: false + # Disabling routes for Swagger + swagger: false diff --git a/hscontrol/app.go b/hscontrol/app.go index 5c85b0641d..d8acefa4c6 100644 --- a/hscontrol/app.go +++ b/hscontrol/app.go @@ -447,15 +447,20 @@ func (h *Headscale) createRouter(grpcMux *grpcRuntime.ServeMux) *mux.Router { if provider, ok := h.authProvider.(*AuthProviderOIDC); ok { router.HandleFunc("/oidc/callback", provider.OIDCCallbackHandler).Methods(http.MethodGet) } - router.HandleFunc("/apple", h.AppleConfigMessage).Methods(http.MethodGet) - router.HandleFunc("/apple/{platform}", h.ApplePlatformConfig). - Methods(http.MethodGet) - router.HandleFunc("/windows", h.WindowsConfigMessage).Methods(http.MethodGet) - - // TODO(kristoffer): move swagger into a package - router.HandleFunc("/swagger", headscale.SwaggerUI).Methods(http.MethodGet) - router.HandleFunc("/swagger/v1/openapiv2.json", headscale.SwaggerAPIv1). - Methods(http.MethodGet) + + if h.cfg.Routes.PlatformConfig { + router.HandleFunc("/apple", h.AppleConfigMessage).Methods(http.MethodGet) + router.HandleFunc("/apple/{platform}", h.ApplePlatformConfig). + Methods(http.MethodGet) + router.HandleFunc("/windows", h.WindowsConfigMessage).Methods(http.MethodGet) + } + + if h.cfg.Routes.Swagger { + // TODO(kristoffer): move swagger into a package + router.HandleFunc("/swagger", headscale.SwaggerUI).Methods(http.MethodGet) + router.HandleFunc("/swagger/v1/openapiv2.json", headscale.SwaggerAPIv1). + Methods(http.MethodGet) + } if h.cfg.DERP.ServerEnabled { router.HandleFunc("/derp", h.DERPServer.DERPHandler) diff --git a/hscontrol/types/config.go b/hscontrol/types/config.go index f02b9758bb..ec2d860dc6 100644 --- a/hscontrol/types/config.go +++ b/hscontrol/types/config.go @@ -86,6 +86,8 @@ type Config struct { Policy PolicyConfig Tuning Tuning + + Routes RoutesConfig } type DNSConfig struct { @@ -203,6 +205,11 @@ type LogConfig struct { Level zerolog.Level } +type RoutesConfig struct { + PlatformConfig bool + Swagger bool +} + type Tuning struct { NotifierSendTimeout time.Duration BatchChangeDelay time.Duration @@ -284,6 +291,9 @@ func LoadConfig(path string, isFile bool) error { viper.SetDefault("tuning.batch_change_delay", "800ms") viper.SetDefault("tuning.node_mapsession_buffered_chan_size", 30) + viper.SetDefault("routes.platformConfig", true) + viper.SetDefault("routes.swagger", true) + viper.SetDefault("prefixes.allocation", string(IPAllocationStrategySequential)) if err := viper.ReadInConfig(); err != nil { @@ -920,6 +930,11 @@ func LoadServerConfig() (*Config, error) { "tuning.node_mapsession_buffered_chan_size", ), }, + + Routes: RoutesConfig{ + PlatformConfig: viper.GetBool("routes.platformConfig"), + Swagger: viper.GetBool("routes.swagger"), + }, }, nil }