Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow setting node registration expiration via config #2280

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"),
Comment on lines +944 to +945
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these should be "nestable" in yaml, so

Suggested change
NodeRegistrationCacheExpiration: viper.GetDuration("tuning.node_registration_cache_expiration"),
NodeRegistrationCacheCleanup: viper.GetDuration("tuning.node_registration_cache_cleanup"),
NodeRegistrationCacheExpiration: viper.GetDuration("tuning.node_registration_cache.expiration"),
NodeRegistrationCacheCleanup: viper.GetDuration("tuning.node_registration_cache.cleanup"),

but its fine to keep them as fields in go.

},
}, nil
}
Expand Down
Loading