Pulse/internal/config/registration.go
Pulse Monitor decce4f39f feat: implement secure registration token system with fixes
- Add registration token system for secure node auto-registration
- Implement token generation, validation, and revocation APIs
- Add frontend UI for managing registration tokens
- Fix polling interval hot-reload to work without restart
- Fix environment variable persistence for system settings
- Optimize monitor reload to avoid 'no nodes configured' message
- Fix goroutine leak in token manager cleanup
- Fix context propagation in reload logic
- Fix AUTO_UPDATE_ENABLED persistence bug
- Add proper error handling and security validation
- Ensure all resources properly cleaned up with defer statements
2025-08-09 11:54:26 +00:00

52 lines
No EOL
1.4 KiB
Go

package config
import (
"os"
"strconv"
"time"
)
// RegistrationConfig holds registration token configuration
type RegistrationConfig struct {
RequireToken bool
DefaultValidity time.Duration
DefaultMaxUses int
AllowUnprotected bool
}
// GetRegistrationConfig returns the registration configuration from environment
func GetRegistrationConfig() RegistrationConfig {
config := RegistrationConfig{
RequireToken: false,
DefaultValidity: 15 * time.Minute,
DefaultMaxUses: 1,
AllowUnprotected: true,
}
// Check if registration tokens are required
if os.Getenv("REQUIRE_REGISTRATION_TOKEN") == "true" {
config.RequireToken = true
config.AllowUnprotected = false
}
// Allow explicitly disabling protection for homelab use
if os.Getenv("ALLOW_UNPROTECTED_AUTO_REGISTER") == "true" {
config.AllowUnprotected = true
}
// Set default validity from environment
if validityStr := os.Getenv("REGISTRATION_TOKEN_DEFAULT_VALIDITY"); validityStr != "" {
if validitySec, err := strconv.Atoi(validityStr); err == nil {
config.DefaultValidity = time.Duration(validitySec) * time.Second
}
}
// Set default max uses from environment
if maxUsesStr := os.Getenv("REGISTRATION_TOKEN_DEFAULT_MAX_USES"); maxUsesStr != "" {
if maxUses, err := strconv.Atoi(maxUsesStr); err == nil {
config.DefaultMaxUses = maxUses
}
}
return config
}