api/v2: refuse expirySeconds outside 0 to 90 days

Matches SaaS status and text.
This commit is contained in:
Kristoffer Dalby committed 2026-11-05 12:41:50 +01:00
1 parent f1382e4322
commit f32fc9f14a
2 files changed
+13 -4

No files matched your search

+1
View File
@@ -239,6 +239,7 @@ the ACME DNS-01 challenge through a built-in DNS provider: `acmedns`,
- With MagicDNS on, stop sending reverse DNS routes for `prefixes` inside 100.64.0.0/10 and fd7a:115c:a1e0::/48, as on Tailscale SaaS; clients add them. A `prefixes.v4` subset such as 100.64.0.0/24 sent 256, which overflowed systemd-resolved's domain limit and dropped reverse DNS. An octet-aligned prefix outside the ranges gets one route instead of 256 [#3482](https://github.com/juanfont/headscale/pull/3482)
- The v1 API stores an API key or pre-auth key created without `expiration` as one that never expires, and reports its expiration as `null`. It was stored as already expired and rejected on first use. The CLI always sends an expiration and was not affected. Keys created this way before stay expired; create new ones [#3254](https://github.com/juanfont/headscale/pull/3254)
- The v2 API accepts an auth key create that leaves out `tags`, as Tailscale does [#3254](https://github.com/juanfont/headscale/pull/3254)
- The v2 API refuses an auth key `expirySeconds` below 0 or above 90 days, as Tailscale does; a negative value used to mean 90 days [#3254](https://github.com/juanfont/headscale/pull/3254)
## 0.29.7 (2026-10-30)
+12 -4
View File
@@ -16,8 +16,8 @@ func init() {
registrations = append(registrations, registerKeys)
}
// defaultExpiry is the auth-key lifetime when the request omits expirySeconds:
// 90 days, matching Tailscale and the Terraform provider default.
// defaultExpiry is the auth-key lifetime when the request omits expirySeconds,
// and the longest it may ask for: 90 days, as Tailscale.
const defaultExpiry = 90 * 24 * time.Hour
const (
@@ -68,8 +68,8 @@ type CreateKeyRequest struct {
// but an OAuth client (keyType:"client") has none and the Tailscale clients
// omit the field entirely, so it must not be required.
Capabilities *KeyCapabilities `json:"capabilities,omitempty"`
ExpirySeconds int64 `doc:"Lifetime in seconds; defaults to 90 days. Auth keys only." json:"expirySeconds,omitempty"`
Description string `json:"description,omitempty" maxLength:"50"`
ExpirySeconds int64 `doc:"Lifetime in seconds, 0 to 90 days; 0 or omitted means 90 days. Auth keys only." json:"expirySeconds,omitempty"`
Description string `json:"description,omitempty" maxLength:"50"`
// Scopes and Tags are top-level and apply only to keyType "client" (an OAuth
// client). Auth-key tags live under Capabilities.Devices.Create.Tags.
Scopes []string `doc:"OAuth scopes granted to the client. keyType=client only." json:"scopes,omitempty"`
@@ -373,6 +373,14 @@ func createAuthKey(ctx context.Context, b Backend, body CreateKeyRequest) (*keyO
return nil, err
}
switch {
case body.ExpirySeconds < 0:
return nil, huma.Error400BadRequest("expirySeconds must be greater than or equal to 0")
case body.ExpirySeconds > int64(defaultExpiry/time.Second):
return nil, huma.Error400BadRequest("expirySeconds must be less than or equal to " +
strconv.FormatInt(int64(defaultExpiry/time.Second), 10))
}
var create KeyDeviceCreateCapabilities
if body.Capabilities != nil {
create = body.Capabilities.Devices.Create