From 81f91f03b41e3c2e3bd875f7a480337cb5109b7f Mon Sep 17 00:00:00 2001 From: Jiang Zhu Date: Sun, 21 Aug 2022 16:22:15 +0800 Subject: [PATCH 1/4] add env var to specify config location --- cmd/headscale/cli/root.go | 3 ++ integration_cli_test.go | 38 +++++++++++++++ .../etc/alt-env-config.dump.gold.yaml | 47 +++++++++++++++++++ integration_test/etc/alt-env-config.yaml | 25 ++++++++++ 4 files changed, 113 insertions(+) create mode 100644 integration_test/etc/alt-env-config.dump.gold.yaml create mode 100644 integration_test/etc/alt-env-config.yaml diff --git a/cmd/headscale/cli/root.go b/cmd/headscale/cli/root.go index 2c28c584..459a99fd 100644 --- a/cmd/headscale/cli/root.go +++ b/cmd/headscale/cli/root.go @@ -25,6 +25,9 @@ func init() { } func initConfig() { + if cfgFile == "" { + cfgFile = os.Getenv("HEADSCALE_CONFIG") + } if cfgFile != "" { err := headscale.LoadConfig(cfgFile, true) if err != nil { diff --git a/integration_cli_test.go b/integration_cli_test.go index f2066021..d2e28bee 100644 --- a/integration_cli_test.go +++ b/integration_cli_test.go @@ -1739,6 +1739,8 @@ func (s *IntegrationCLITestSuite) TestLoadConfigFromCommand() { assert.Nil(s.T(), err) altConfig, err := os.ReadFile("integration_test/etc/alt-config.dump.gold.yaml") assert.Nil(s.T(), err) + altEnvConfig, err := os.ReadFile("integration_test/etc/alt-env-config.dump.gold.yaml") + assert.Nil(s.T(), err) _, err = ExecuteCommand( &s.headscale, @@ -1771,4 +1773,40 @@ func (s *IntegrationCLITestSuite) TestLoadConfigFromCommand() { assert.Nil(s.T(), err) assert.YAMLEq(s.T(), string(altConfig), string(altDumpConfig)) + + _, err = ExecuteCommand( + &s.headscale, + []string{ + "headscale", + "dumpConfig", + }, + []string{ + "HEADSCALE_CONFIG=/etc/headscale/alt-env-config.yaml", + }, + ) + assert.Nil(s.T(), err) + + altEnvDumpConfig, err := os.ReadFile("integration_test/etc/config.dump.yaml") + assert.Nil(s.T(), err) + + assert.YAMLEq(s.T(), string(altEnvConfig), string(altEnvDumpConfig)) + + _, err = ExecuteCommand( + &s.headscale, + []string{ + "headscale", + "-c", + "/etc/headscale/alt-config.yaml", + "dumpConfig", + }, + []string{ + "HEADSCALE_CONFIG=/etc/headscale/alt-env-config.yaml", + }, + ) + assert.Nil(s.T(), err) + + altDumpConfig, err = os.ReadFile("integration_test/etc/config.dump.yaml") + assert.Nil(s.T(), err) + + assert.YAMLEq(s.T(), string(altConfig), string(altDumpConfig)) } diff --git a/integration_test/etc/alt-env-config.dump.gold.yaml b/integration_test/etc/alt-env-config.dump.gold.yaml new file mode 100644 index 00000000..2c10db93 --- /dev/null +++ b/integration_test/etc/alt-env-config.dump.gold.yaml @@ -0,0 +1,47 @@ +acl_policy_path: "" +cli: + insecure: false + timeout: 5s +db_path: /tmp/integration_test_db.sqlite3 +db_type: sqlite3 +derp: + auto_update_enabled: false + server: + enabled: false + stun: + enabled: true + update_frequency: 1m + urls: + - https://controlplane.tailscale.com/derpmap/default +dns_config: + base_domain: headscale.net + domains: [] + magic_dns: true + nameservers: + - 1.1.1.1 +ephemeral_node_inactivity_timeout: 30m +node_update_check_interval: 100s +grpc_allow_insecure: false +grpc_listen_addr: :50443 +ip_prefixes: + - fd7a:115c:a1e0::/48 + - 100.64.0.0/10 +listen_addr: 0.0.0.0:18080 +log_level: disabled +logtail: + enabled: false +metrics_listen_addr: 127.0.0.1:19090 +oidc: + scope: + - openid + - profile + - email + strip_email_domain: true +private_key_path: private.key +server_url: http://headscale:18080 +tls_client_auth_mode: relaxed +tls_letsencrypt_cache_dir: /var/www/.cache +tls_letsencrypt_challenge_type: HTTP-01 +unix_socket: /var/run/headscale.sock +unix_socket_permission: "0o770" +randomize_client_port: false diff --git a/integration_test/etc/alt-env-config.yaml b/integration_test/etc/alt-env-config.yaml new file mode 100644 index 00000000..2dc3024f --- /dev/null +++ b/integration_test/etc/alt-env-config.yaml @@ -0,0 +1,25 @@ +log_level: trace +acl_policy_path: "" +db_type: sqlite3 +ephemeral_node_inactivity_timeout: 30m +node_update_check_interval: 100s +ip_prefixes: + - fd7a:115c:a1e0::/48 + - 100.64.0.0/10 +dns_config: + base_domain: headscale.net + magic_dns: true + domains: [] + nameservers: + - 1.1.1.1 +db_path: /tmp/integration_test_db.sqlite3 +private_key_path: private.key +listen_addr: 0.0.0.0:18080 +metrics_listen_addr: 127.0.0.1:19090 +server_url: http://headscale:18080 + +derp: + urls: + - https://controlplane.tailscale.com/derpmap/default + auto_update_enabled: false + update_frequency: 1m From 35dd9209b98b47e7a4326803d48f2d62e20c253a Mon Sep 17 00:00:00 2001 From: Jiang Zhu Date: Sun, 21 Aug 2022 16:26:06 +0800 Subject: [PATCH 2/4] update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f2fd517..b598ea1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - Add ability to connect to PostgreSQL over TLS/SSL [#745](https://github.com/juanfont/headscale/pull/745) - Fix CLI registration of expired machines [#754](https://github.com/juanfont/headscale/pull/754) +- Add ability to specify config location via env var `HEADSCALE_CONFIG` [#674](https://github.com/juanfont/headscale/issues/674) ## 0.16.3 (2022-08-17) From ce4a1cf4473f7cb5c1e0e83633a7332ead1c14db Mon Sep 17 00:00:00 2001 From: Jiang Zhu Date: Sun, 21 Aug 2022 23:53:07 +0800 Subject: [PATCH 3/4] 1. add noise key to config file 2. lower node check interval --- integration_test/etc/alt-env-config.dump.gold.yaml | 4 +++- integration_test/etc/alt-env-config.yaml | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/integration_test/etc/alt-env-config.dump.gold.yaml b/integration_test/etc/alt-env-config.dump.gold.yaml index 2c10db93..f3ebd080 100644 --- a/integration_test/etc/alt-env-config.dump.gold.yaml +++ b/integration_test/etc/alt-env-config.dump.gold.yaml @@ -20,7 +20,7 @@ dns_config: nameservers: - 1.1.1.1 ephemeral_node_inactivity_timeout: 30m -node_update_check_interval: 100s +node_update_check_interval: 30s grpc_allow_insecure: false grpc_listen_addr: :50443 ip_prefixes: @@ -38,6 +38,8 @@ oidc: - email strip_email_domain: true private_key_path: private.key +noise: + private_key_path: noise_private.key server_url: http://headscale:18080 tls_client_auth_mode: relaxed tls_letsencrypt_cache_dir: /var/www/.cache diff --git a/integration_test/etc/alt-env-config.yaml b/integration_test/etc/alt-env-config.yaml index 2dc3024f..4f195265 100644 --- a/integration_test/etc/alt-env-config.yaml +++ b/integration_test/etc/alt-env-config.yaml @@ -2,7 +2,7 @@ log_level: trace acl_policy_path: "" db_type: sqlite3 ephemeral_node_inactivity_timeout: 30m -node_update_check_interval: 100s +node_update_check_interval: 30s ip_prefixes: - fd7a:115c:a1e0::/48 - 100.64.0.0/10 @@ -14,6 +14,8 @@ dns_config: - 1.1.1.1 db_path: /tmp/integration_test_db.sqlite3 private_key_path: private.key +noise: + private_key_path: noise_private.key listen_addr: 0.0.0.0:18080 metrics_listen_addr: 127.0.0.1:19090 server_url: http://headscale:18080 From a81a4d274f787f7da6ce5973d6e01de0cb0f25e5 Mon Sep 17 00:00:00 2001 From: Jiang Zhu <5499746+huskyii@users.noreply.github.com> Date: Mon, 22 Aug 2022 20:20:20 +0800 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b598ea1b..1b66931c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 0.17.0 (2022-XX-XX) - Added support for Tailscale TS2021 protocol [#738](https://github.com/juanfont/headscale/pull/738) +- Add ability to specify config location via env var `HEADSCALE_CONFIG` [#674](https://github.com/juanfont/headscale/issues/674) ## 0.16.4 (2022-08-21) @@ -10,7 +11,6 @@ - Add ability to connect to PostgreSQL over TLS/SSL [#745](https://github.com/juanfont/headscale/pull/745) - Fix CLI registration of expired machines [#754](https://github.com/juanfont/headscale/pull/754) -- Add ability to specify config location via env var `HEADSCALE_CONFIG` [#674](https://github.com/juanfont/headscale/issues/674) ## 0.16.3 (2022-08-17)