mirror of
https://github.com/netbirdio/netbird.git
synced 2026-09-12 17:59:06 +02:00
Prevent unvalidated registrations from reserving domain names indefinitely. Give pending registrations a 48-hour validation window and clean up expired entries at startup and every 60 minutes. Emit CustomDomainValidationExpired for each deletion and preserve registrations referenced by services. Reject validation after expiry and prevent concurrent validation from recreating deleted registrations. Normalize domain names with the shared parser before registration. Migrate existing pending registrations to receive a fresh 48-hour validation window.
57 lines
1.8 KiB
Go
57 lines
1.8 KiB
Go
package domain
|
|
|
|
import "time"
|
|
|
|
// ValidationTTL is the time available to validate a custom domain registration.
|
|
const ValidationTTL = 48 * time.Hour
|
|
|
|
// ID identifies a custom domain registration.
|
|
type ID string
|
|
|
|
type Type string
|
|
|
|
const (
|
|
TypeFree Type = "free"
|
|
TypeCustom Type = "custom"
|
|
)
|
|
|
|
type Domain struct {
|
|
ID string `gorm:"unique;primaryKey;autoIncrement"`
|
|
Domain string `gorm:"unique"` // Domain records must be unique, this avoids domain reuse across accounts.
|
|
AccountID string `gorm:"index"`
|
|
TargetCluster string // The proxy cluster this domain should be validated against
|
|
Type Type `gorm:"-"`
|
|
Validated bool
|
|
ValidationExpiresAt *time.Time `gorm:"index"`
|
|
// SupportsCustomPorts is populated at query time for free domains from the
|
|
// proxy cluster capabilities. Not persisted.
|
|
SupportsCustomPorts *bool `gorm:"-"`
|
|
// RequireSubdomain is populated at query time. When true, the domain
|
|
// cannot be used bare and a subdomain label must be prepended. Not persisted.
|
|
RequireSubdomain *bool `gorm:"-"`
|
|
// SupportsCrowdSec is populated at query time from proxy cluster capabilities.
|
|
// Not persisted.
|
|
SupportsCrowdSec *bool `gorm:"-"`
|
|
// SupportsPrivate is populated at query time from proxy cluster capabilities. Not persisted.
|
|
SupportsPrivate *bool `gorm:"-"`
|
|
}
|
|
|
|
// EventMeta returns activity event metadata for a domain
|
|
func (d *Domain) EventMeta() map[string]any {
|
|
return map[string]any{
|
|
"domain": d.Domain,
|
|
"target_cluster": d.TargetCluster,
|
|
"validated": d.Validated,
|
|
}
|
|
}
|
|
|
|
// Copy returns a copy with an independent validation deadline.
|
|
func (d *Domain) Copy() *Domain {
|
|
dCopy := *d
|
|
if d.ValidationExpiresAt != nil {
|
|
expiresAt := *d.ValidationExpiresAt
|
|
dCopy.ValidationExpiresAt = &expiresAt
|
|
}
|
|
return &dCopy
|
|
}
|