Skip to content

Auth Server: Add Operator CRD Types for Redis Storage #3792

Closed

Description

@tgrunnagle

Description

Add Kubernetes CRD types for configuring Redis storage in the embedded authorization server. This covers the type definitions, generated manifests, and validation webhooks — the foundational schema that the controller/runner integration (covered in #3630) will build on.

Note: Split from #3630, which now covers only controller and runner integration.

Context

The Redis storage backend implemented in #3628 and integration tested in #3629 provides horizontal scaling capabilities for the embedded auth server. This task defines the CRD schema that operators will use to declaratively configure Redis-backed storage.

Parent Issue: https://github.com/stacklok/stacklok-epics/issues/197
Dependencies: #3628 (Core Implementation), #3629 (Integration Testing)
Blocks: #3630 (Controller & Runner Integration)
Related: #3790 (Documentation)

Acceptance Criteria

  • CRD types added to mcpexternalauthconfig_types.go:
    • AuthServerStorageConfig
    • RedisStorageConfig
    • RedisSentinelConfig
    • SentinelServiceRef
    • RedisACLUserConfig
  • EmbeddedAuthServerConfig updated with Storage field
  • Generated manifests updated via task operator-generate and task operator-manifests
  • Validation webhooks implemented for Redis configuration:
    • Exactly one of sentinelAddrs or sentinelService must be specified
    • Timeout values are valid Go duration strings
    • deploymentMode is "sentinel" and authType is "aclUser"
  • task lint, task test, and task operator-manifests pass
  • Code reviewed and approved

Technical Approach

Recommended Implementation

Follow existing patterns in mcpexternalauthconfig_types.go for:

  1. SecretKeyRef pattern for referencing Kubernetes Secrets (lines 369-378)
  2. Kubebuilder validation annotations for enum constraints
  3. Optional fields with sensible defaults

Patterns & Frameworks

  • Kubebuilder validation: Use +kubebuilder:validation:Enum for constrained fields like deploymentMode and authType
  • SecretKeyRef: Follow existing pattern from mcpexternalauthconfig_types.go for Secret references

Code Pointers

  • cmd/thv-operator/api/v1alpha1/mcpexternalauthconfig_types.go — Add CRD types following existing patterns (lines 132-176 for EmbeddedAuthServerConfig, lines 369-378 for SecretKeyRef)
  • pkg/authserver/storage/config.go — Reference for storage configuration types
  • docs/proposals/THV-0035-auth-server-redis-storage.md — RFC with complete CRD type definitions

Component Interfaces

CRD Types (add to mcpexternalauthconfig_types.go):

// AuthServerStorageConfig configures the storage backend for the embedded auth server
type AuthServerStorageConfig struct {
    // Type specifies the storage backend type
    // Valid values: "memory" (default), "redis"
    // +kubebuilder:validation:Enum=memory;redis
    // +kubebuilder:default=memory
    Type string `json:"type,omitempty"`

    // Redis configures Redis storage backend
    // Required when type is "redis"
    // +optional
    Redis *RedisStorageConfig `json:"redis,omitempty"`
}

// RedisStorageConfig configures Redis connection for auth server storage
type RedisStorageConfig struct {
    // DeploymentMode specifies the Redis deployment mode
    // Only "sentinel" is supported for high availability
    // +kubebuilder:validation:Enum=sentinel
    // +kubebuilder:default=sentinel
    DeploymentMode string `json:"deploymentMode,omitempty"`

    // SentinelConfig holds Sentinel configuration
    // Required when deploymentMode is "sentinel"
    SentinelConfig *RedisSentinelConfig `json:"sentinelConfig,omitempty"`

    // AuthType specifies the authentication method
    // Only "aclUser" is supported for secure deployments
    // +kubebuilder:validation:Enum=aclUser
    // +kubebuilder:default=aclUser
    AuthType string `json:"authType,omitempty"`

    // ACLUserConfig configures ACL user authentication
    // Required when authType is "aclUser"
    ACLUserConfig *RedisACLUserConfig `json:"aclUserConfig,omitempty"`

    // DialTimeout is the timeout for establishing connections
    // +kubebuilder:default="5s"
    // +optional
    DialTimeout string `json:"dialTimeout,omitempty"`

    // ReadTimeout is the timeout for socket reads
    // +kubebuilder:default="3s"
    // +optional
    ReadTimeout string `json:"readTimeout,omitempty"`

    // WriteTimeout is the timeout for socket writes
    // +kubebuilder:default="3s"
    // +optional
    WriteTimeout string `json:"writeTimeout,omitempty"`
}

// RedisSentinelConfig configures Redis Sentinel connection
type RedisSentinelConfig struct {
    // MasterName is the name of the Redis master monitored by Sentinel
    MasterName string `json:"masterName"`

    // SentinelAddrs is a list of Sentinel host:port addresses
    // Mutually exclusive with SentinelService
    // +optional
    SentinelAddrs []string `json:"sentinelAddrs,omitempty"`

    // SentinelService enables automatic discovery from a Kubernetes Service
    // Mutually exclusive with SentinelAddrs
    // +optional
    SentinelService *SentinelServiceRef `json:"sentinelService,omitempty"`

    // DB is the Redis database number
    // +kubebuilder:default=0
    // +optional
    DB int32 `json:"db,omitempty"`
}

// SentinelServiceRef references a Kubernetes Service for Sentinel discovery
type SentinelServiceRef struct {
    // Name of the Sentinel Service
    Name string `json:"name"`

    // Namespace of the Sentinel Service (defaults to same namespace)
    // +optional
    Namespace string `json:"namespace,omitempty"`

    // Port of the Sentinel service
    // +kubebuilder:default=26379
    // +optional
    Port int32 `json:"port,omitempty"`
}

// RedisACLUserConfig configures Redis ACL user authentication
type RedisACLUserConfig struct {
    // UsernameSecretRef references a Secret containing the Redis ACL username
    UsernameSecretRef *SecretKeyRef `json:"usernameSecretRef"`

    // PasswordSecretRef references a Secret containing the Redis ACL password
    PasswordSecretRef *SecretKeyRef `json:"passwordSecretRef"`
}

Testing Strategy

Unit Tests

  • Test CRD validation webhooks for mutual exclusivity of sentinelAddrs vs sentinelService
  • Test CRD validation for timeout duration format validation

Validation Tests

  • Test that exactly one of sentinelAddrs or sentinelService is required
  • Test that invalid timeout formats are rejected
  • Test that missing required fields are rejected

Out of Scope

References

Activity

  1. self-assigned this
    on Feb 11, 2026
  2. added
    enhancement
    kubernetes
    api
    on Feb 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

apiauthenticationenhancementkubernetesoperator

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions