Skip to content

Commit

Permalink
feat: allow setting node registration expiration via config
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswiggins committed Dec 11, 2024
1 parent 757defa commit 7518eba
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
- 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)
- 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)

Expand Down
8 changes: 3 additions & 5 deletions hscontrol/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ const (
updateInterval = 5 * time.Second
privateKeyFileMode = 0o600
headscaleDirPerm = 0o700

registerCacheExpiration = time.Minute * 15
registerCacheCleanup = time.Minute * 20
)

// Headscale represents the base app of the service.
Expand Down Expand Up @@ -122,8 +119,8 @@ func NewHeadscale(cfg *types.Config) (*Headscale, error) {
}

registrationCache := zcache.New[string, types.Node](
registerCacheExpiration,
registerCacheCleanup,
cfg.Tuning.NodeRegistrationCacheExpiration,
cfg.Tuning.NodeRegistrationCacheCleanup,
)

app := Headscale{
Expand Down Expand Up @@ -171,6 +168,7 @@ func NewHeadscale(cfg *types.Config) (*Headscale, error) {
app.nodeNotifier,
app.ipAlloc,
app.polMan,
&cfg.Tuning,
)
if err != nil {
if cfg.OIDC.OnlyStartIfOIDCIsAvailable {
Expand Down
5 changes: 3 additions & 2 deletions hscontrol/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func NewAuthProviderOIDC(
notif *notifier.Notifier,
ipAlloc *db.IPAllocator,
polMan policy.PolicyManager,
tuningCfg *types.Tuning,
) (*AuthProviderOIDC, error) {
var err error
// grab oidc config if it hasn't been already
Expand All @@ -88,8 +89,8 @@ func NewAuthProviderOIDC(
}

registrationCache := zcache.New[string, key.MachinePublic](
registerCacheExpiration,
registerCacheCleanup,
tuningCfg.NodeRegistrationCacheExpiration,
tuningCfg.NodeRegistrationCacheCleanup,
)

return &AuthProviderOIDC{
Expand Down
8 changes: 8 additions & 0 deletions hscontrol/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ type Tuning struct {
NotifierSendTimeout time.Duration
BatchChangeDelay time.Duration
NodeMapSessionBufferedChanSize int

// Node registration cache expiration
NodeRegistrationCacheExpiration time.Duration
NodeRegistrationCacheCleanup time.Duration
}

// LoadConfig prepares and loads the Headscale configuration into Viper.
Expand Down Expand Up @@ -291,6 +295,8 @@ func LoadConfig(path string, isFile bool) error {
viper.SetDefault("tuning.notifier_send_timeout", "800ms")
viper.SetDefault("tuning.batch_change_delay", "800ms")
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))

Expand Down Expand Up @@ -935,6 +941,8 @@ func LoadServerConfig() (*Config, error) {
NodeMapSessionBufferedChanSize: viper.GetInt(
"tuning.node_mapsession_buffered_chan_size",
),
NodeRegistrationCacheExpiration: viper.GetDuration("tuning.node_registration_cache_expiration"),
NodeRegistrationCacheCleanup: viper.GetDuration("tuning.node_registration_cache_cleanup"),
},
}, nil
}
Expand Down

0 comments on commit 7518eba

Please sign in to comment.