feat: allow setting node registration expiration via config

This commit is contained in:
Chris Wiggins 2024-12-12 09:37:56 +13:00
parent 757defa2f2
commit 7518eba82e
4 changed files with 15 additions and 7 deletions

View File

@ -95,6 +95,7 @@ This will also affect the way you [reference users in policies](https://github.c
- Fixed missing `stable-debug` container tag [#2232](https://github.com/juanfont/headscale/pr/2232) - Fixed missing `stable-debug` container tag [#2232](https://github.com/juanfont/headscale/pr/2232)
- Loosened up `server_url` and `base_domain` check. It was overly strict in some cases. [#2248](https://github.com/juanfont/headscale/pull/2248) - Loosened up `server_url` and `base_domain` check. It was overly strict in some cases. [#2248](https://github.com/juanfont/headscale/pull/2248)
- CLI for managing users now accepts `--identifier` in addition to `--name`, usage of `--identifier` is recommended [#2261](https://github.com/juanfont/headscale/pull/2261) - CLI for managing users now accepts `--identifier` in addition to `--name`, usage of `--identifier` is recommended [#2261](https://github.com/juanfont/headscale/pull/2261)
- Added option to set Node registration expiration/cleanup options via config [#2280](https://github.com/juanfont/headscale/pull/2280)
## 0.23.0 (2024-09-18) ## 0.23.0 (2024-09-18)

View File

@ -72,9 +72,6 @@ const (
updateInterval = 5 * time.Second updateInterval = 5 * time.Second
privateKeyFileMode = 0o600 privateKeyFileMode = 0o600
headscaleDirPerm = 0o700 headscaleDirPerm = 0o700
registerCacheExpiration = time.Minute * 15
registerCacheCleanup = time.Minute * 20
) )
// Headscale represents the base app of the service. // Headscale represents the base app of the service.
@ -122,8 +119,8 @@ func NewHeadscale(cfg *types.Config) (*Headscale, error) {
} }
registrationCache := zcache.New[string, types.Node]( registrationCache := zcache.New[string, types.Node](
registerCacheExpiration, cfg.Tuning.NodeRegistrationCacheExpiration,
registerCacheCleanup, cfg.Tuning.NodeRegistrationCacheCleanup,
) )
app := Headscale{ app := Headscale{
@ -171,6 +168,7 @@ func NewHeadscale(cfg *types.Config) (*Headscale, error) {
app.nodeNotifier, app.nodeNotifier,
app.ipAlloc, app.ipAlloc,
app.polMan, app.polMan,
&cfg.Tuning,
) )
if err != nil { if err != nil {
if cfg.OIDC.OnlyStartIfOIDCIsAvailable { if cfg.OIDC.OnlyStartIfOIDCIsAvailable {

View File

@ -68,6 +68,7 @@ func NewAuthProviderOIDC(
notif *notifier.Notifier, notif *notifier.Notifier,
ipAlloc *db.IPAllocator, ipAlloc *db.IPAllocator,
polMan policy.PolicyManager, polMan policy.PolicyManager,
tuningCfg *types.Tuning,
) (*AuthProviderOIDC, error) { ) (*AuthProviderOIDC, error) {
var err error var err error
// grab oidc config if it hasn't been already // grab oidc config if it hasn't been already
@ -88,8 +89,8 @@ func NewAuthProviderOIDC(
} }
registrationCache := zcache.New[string, key.MachinePublic]( registrationCache := zcache.New[string, key.MachinePublic](
registerCacheExpiration, tuningCfg.NodeRegistrationCacheExpiration,
registerCacheCleanup, tuningCfg.NodeRegistrationCacheCleanup,
) )
return &AuthProviderOIDC{ return &AuthProviderOIDC{

View File

@ -212,6 +212,10 @@ type Tuning struct {
NotifierSendTimeout time.Duration NotifierSendTimeout time.Duration
BatchChangeDelay time.Duration BatchChangeDelay time.Duration
NodeMapSessionBufferedChanSize int NodeMapSessionBufferedChanSize int
// Node registration cache expiration
NodeRegistrationCacheExpiration time.Duration
NodeRegistrationCacheCleanup time.Duration
} }
// LoadConfig prepares and loads the Headscale configuration into Viper. // LoadConfig prepares and loads the Headscale configuration into Viper.
@ -291,6 +295,8 @@ func LoadConfig(path string, isFile bool) error {
viper.SetDefault("tuning.notifier_send_timeout", "800ms") viper.SetDefault("tuning.notifier_send_timeout", "800ms")
viper.SetDefault("tuning.batch_change_delay", "800ms") viper.SetDefault("tuning.batch_change_delay", "800ms")
viper.SetDefault("tuning.node_mapsession_buffered_chan_size", 30) viper.SetDefault("tuning.node_mapsession_buffered_chan_size", 30)
viper.SetDefault("tuning.node_registration_cache_expiration", "15m")
viper.SetDefault("tuning.node_registration_cache_cleanup", "20m")
viper.SetDefault("prefixes.allocation", string(IPAllocationStrategySequential)) viper.SetDefault("prefixes.allocation", string(IPAllocationStrategySequential))
@ -935,6 +941,8 @@ func LoadServerConfig() (*Config, error) {
NodeMapSessionBufferedChanSize: viper.GetInt( NodeMapSessionBufferedChanSize: viper.GetInt(
"tuning.node_mapsession_buffered_chan_size", "tuning.node_mapsession_buffered_chan_size",
), ),
NodeRegistrationCacheExpiration: viper.GetDuration("tuning.node_registration_cache_expiration"),
NodeRegistrationCacheCleanup: viper.GetDuration("tuning.node_registration_cache_cleanup"),
}, },
}, nil }, nil
} }