config

package
v1.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EnvServerBaseURL is the base URL for the API server (used for OAuth metadata)
	EnvServerBaseURL = "SERVER_BASE_URL"

	// EnvAuthServerBaseURL is the base URL for Asgardeo Thunder (authorization server)
	EnvAuthServerBaseURL = "AUTH_SERVER_BASE_URL"

	// EnvJWKSURL is the JWKS URL for JWT validation
	EnvJWKSURL = "JWKS_URL"

	// EnvJWTIssuer is the expected JWT issuer
	EnvJWTIssuer = "JWT_ISSUER"

	// EnvJWTAudience is the expected JWT audience (optional)
	EnvJWTAudience = "JWT_AUDIENCE"

	// EnvMCPToolsets is the comma-separated list of enabled MCP toolsets
	EnvMCPToolsets = "MCP_TOOLSETS"

	// EnvJWTDisabled is the flag to disable JWT authentication
	EnvJWTDisabled = "JWT_DISABLED"

	// EnvJWKSURLTLSInsecureSkipVerify is the flag to skip TLS verification when fetching JWKS
	EnvJWKSURLTLSInsecureSkipVerify = "JWKS_URL_TLS_INSECURE_SKIP_VERIFY"

	// EnvLogLevel is the log level for the API server (debug, info, warn, error)
	EnvLogLevel = "LOG_LEVEL"

	// EnvOIDCAuthorizationURL is the OIDC authorization endpoint URL
	EnvOIDCAuthorizationURL = "OIDC_AUTHORIZATION_URL"

	// EnvOIDCTokenURL is the OIDC token endpoint URL
	EnvOIDCTokenURL = "OIDC_TOKEN_URL" // #nosec G101 -- This is an environment variable name, not a credential
)

Environment variable names for OpenChoreo API configuration

View Source
const (
	DefaultServerBaseURL  = "http://api.openchoreo.localhost"
	DefaultThunderBaseURL = "http://sts.openchoreo.localhost"
)

Default values for configuration

Variables

This section is empty.

Functions

func NewLoader added in v0.13.0

func NewLoader(configPath string, flags *pflag.FlagSet) (*coreconfig.Loader, error)

NewLoader creates a configuration loader with all sources loaded. Loading priority (highest to lowest):

  1. CLI flags (only if explicitly set)
  2. Environment variables (OC_API__SERVER__PORT -> server.port)
  3. Config file (YAML)
  4. Struct defaults

If configPath is empty, no config file is loaded. If flags is nil, no flag overrides are applied.

Types

type AuthenticationConfig added in v0.13.0

type AuthenticationConfig struct {
	// JWT defines JWT authentication settings.
	JWT JWTConfig `koanf:"jwt"`
}

AuthenticationConfig defines authentication settings.

func AuthenticationDefaults added in v0.13.0

func AuthenticationDefaults() AuthenticationConfig

AuthenticationDefaults returns the default authentication configuration.

func (*AuthenticationConfig) Validate added in v0.13.0

Validate validates the authentication configuration.

type AuthorizationConfig added in v0.13.0

type AuthorizationConfig struct {
	// Enabled enables authorization enforcement.
	Enabled bool `koanf:"enabled"`
	// Cache defines caching settings for authorization decisions.
	Cache AuthzCacheConfig `koanf:"cache"`
	// ResyncInterval is the interval for informer cache resync.
	// This triggers re-listing of CRDs and OnUpdate callbacks for reconciliation.
	// Set to 0 to disable periodic resync (watch events still work).
	ResyncInterval time.Duration `koanf:"resync_interval"`
}

AuthorizationConfig defines authorization (Casbin) settings. Policies are loaded from ClusterAuthzRole, AuthzRole, ClusterAuthzRoleBinding, and AuthzRoleBinding CRDs.

func AuthorizationDefaults added in v0.13.0

func AuthorizationDefaults() AuthorizationConfig

AuthorizationDefaults returns the default authorization configuration.

func (*AuthorizationConfig) ToAuthzConfig added in v0.13.0

func (c *AuthorizationConfig) ToAuthzConfig(securityEnabled bool) authz.Config

ToAuthzConfig converts to the authz library config. The securityEnabled parameter propagates the top-level security.enabled flag.

func (*AuthorizationConfig) Validate added in v0.13.0

Validate validates the authorization configuration.

type AuthzCacheConfig added in v0.13.0

type AuthzCacheConfig struct {
	// Enabled enables the Casbin enforcer cache.
	Enabled bool `koanf:"enabled"`
	// TTL is the cache time-to-live duration.
	TTL time.Duration `koanf:"ttl"`
}

AuthzCacheConfig defines caching settings for authorization.

func AuthzCacheDefaults added in v0.13.0

func AuthzCacheDefaults() AuthzCacheConfig

AuthzCacheDefaults returns the default cache configuration.

func (*AuthzCacheConfig) Validate added in v0.13.0

func (c *AuthzCacheConfig) Validate(path *config.Path) config.ValidationErrors

Validate validates the cache configuration.

type ClientConfig added in v0.13.0

type ClientConfig struct {
	// ClientID is the OAuth client identifier.
	ClientID string `koanf:"client_id"`
	// Scopes is the list of OAuth scopes to request.
	Scopes []string `koanf:"scopes"`
}

ClientConfig defines an OAuth client configuration for external integrations.

func (*ClientConfig) Validate added in v0.13.0

func (c *ClientConfig) Validate(path *config.Path) config.ValidationErrors

Validate validates the client configuration.

type ClusterGatewayConfig added in v0.14.0

type ClusterGatewayConfig struct {
	// Enabled controls whether cluster gateway integration is enabled.
	Enabled bool `koanf:"enabled"`
	// URL is the cluster gateway service URL.
	URL string `koanf:"url"`
	// TLS defines TLS settings for the connection.
	TLS ClusterGatewayTLSConfig `koanf:"tls"`
}

ClusterGatewayConfig defines cluster gateway connection settings for communicating with workflow planes and data planes through the cluster gateway proxy.

func ClusterGatewayDefaults added in v0.14.0

func ClusterGatewayDefaults() ClusterGatewayConfig

ClusterGatewayDefaults returns the default cluster gateway configuration.

func (*ClusterGatewayConfig) Validate added in v0.14.0

Validate validates the cluster gateway configuration.

type ClusterGatewayTLSConfig added in v0.14.0

type ClusterGatewayTLSConfig struct {
	// CACertPath is the path to the CA certificate file for verifying the cluster gateway server.
	CACertPath string `koanf:"ca_cert_path"`
	// ClientCertPath is the path to the client certificate file for mTLS authentication.
	ClientCertPath string `koanf:"client_cert_path"`
	// ClientKeyPath is the path to the client private key file for mTLS authentication.
	ClientKeyPath string `koanf:"client_key_path"`
	// Insecure disables TLS verification for the cluster gateway connection.
	// For local development only.
	Insecure bool `koanf:"insecure"`
}

ClusterGatewayTLSConfig defines TLS settings for cluster gateway connections.

type Config added in v0.8.0

type Config struct {
	// Server defines HTTP server settings.
	Server ServerConfig `koanf:"server"`
	// Security defines authentication and authorization settings.
	Security SecurityConfig `koanf:"security"`
	// Identity defines identity provider settings.
	Identity IdentityConfig `koanf:"identity"`
	// MCP defines Model Context Protocol server settings.
	MCP MCPConfig `koanf:"mcp"`
	// SecretManagement toggles the Secret management API endpoints.
	SecretManagement SecretManagementConfig `koanf:"secret_management"`
	// Logging defines logging settings.
	Logging LoggingConfig `koanf:"logging"`
	// ClusterGateway defines cluster gateway connection settings.
	ClusterGateway ClusterGatewayConfig `koanf:"cluster_gateway"`
}

Config is the top-level configuration for openchoreo-api.

func Defaults added in v0.13.0

func Defaults() Config

Defaults returns the default configuration.

func (*Config) Validate added in v0.13.0

func (c *Config) Validate() error

Validate validates the configuration.

type EntitlementConfig added in v0.13.0

type EntitlementConfig struct {
	// Claim is the claim name for entitlement extraction.
	Claim string `koanf:"claim"`
	// DisplayName is the human-readable name for the claim.
	DisplayName string `koanf:"display_name"`
}

EntitlementConfig defines how to extract entitlement claims from tokens.

func (*EntitlementConfig) Validate added in v0.13.0

Validate validates the entitlement configuration.

type IdentityConfig added in v0.13.0

type IdentityConfig struct {
	// OIDC defines OpenID Connect provider settings.
	OIDC OIDCConfig `koanf:"oidc"`
	// Clients defines OAuth client configurations for external integrations.
	// Keys are client identifiers (e.g., "cli", "ci").
	Clients map[string]ClientConfig `koanf:"clients"`
}

IdentityConfig defines identity provider settings.

func IdentityDefaults added in v0.13.0

func IdentityDefaults() IdentityConfig

IdentityDefaults returns the default identity configuration.

func (*IdentityConfig) Validate added in v0.13.0

func (c *IdentityConfig) Validate(path *config.Path) config.ValidationErrors

Validate validates the identity configuration.

type JWKSConfig added in v0.13.0

type JWKSConfig struct {
	// RefreshInterval is how often to refresh keys from the JWKS URL.
	RefreshInterval time.Duration `koanf:"refresh_interval"`
	// SkipTLSVerify skips TLS certificate verification for JWKS URL.
	// WARNING: Only use for development/testing.
	SkipTLSVerify bool `koanf:"skip_tls_verify"`
}

JWKSConfig defines JWKS (JSON Web Key Set) operational settings. Note: The JWKS URL comes from identity.oidc.jwks_url.

func JWKSDefaults added in v0.13.0

func JWKSDefaults() JWKSConfig

JWKSDefaults returns the default JWKS configuration.

func (*JWKSConfig) Validate added in v0.13.0

func (c *JWKSConfig) Validate(path *config.Path) config.ValidationErrors

Validate validates the JWKS configuration.

type JWTConfig added in v0.13.0

type JWTConfig struct {
	// Audiences is the list of acceptable token audiences (aud claim).
	// Token must contain at least one of these audiences. Optional.
	Audiences []string `koanf:"audiences"`
	// ClockSkew is the allowed clock skew for token validation.
	ClockSkew time.Duration `koanf:"clock_skew"`
	// JWKS defines JSON Web Key Set operational settings.
	JWKS JWKSConfig `koanf:"jwks"`
}

JWTConfig defines JWT authentication settings.

func JWTDefaults added in v0.13.0

func JWTDefaults() JWTConfig

JWTDefaults returns the default JWT configuration.

func (*JWTConfig) ToJWTMiddlewareConfig added in v0.13.0

func (c *JWTConfig) ToJWTMiddlewareConfig(oidc *OIDCConfig, logger *slog.Logger, resolver *jwt.Resolver, securityEnabled bool) jwt.Config

ToJWTMiddlewareConfig converts to the JWT middleware library config. The oidc parameter provides issuer and JWKS URL from identity configuration. The securityEnabled parameter propagates the top-level security.enabled flag.

func (*JWTConfig) Validate added in v0.13.0

func (c *JWTConfig) Validate(path *config.Path) config.ValidationErrors

Validate validates the JWT configuration.

type LoggingConfig added in v0.13.0

type LoggingConfig struct {
	// Level is the minimum log level (debug, info, warn, error).
	Level string `koanf:"level"`
	// Format is the log output format (json, text).
	Format string `koanf:"format"`
	// AddSource includes source file and line number in log entries.
	AddSource bool `koanf:"add_source"`
}

LoggingConfig defines logging settings.

func LoggingDefaults added in v0.13.0

func LoggingDefaults() LoggingConfig

LoggingDefaults returns the default logging configuration.

func (*LoggingConfig) ToLoggingConfig added in v0.13.0

func (c *LoggingConfig) ToLoggingConfig() logging.Config

ToLoggingConfig converts to the logging library config.

func (*LoggingConfig) Validate added in v0.13.0

func (c *LoggingConfig) Validate(path *config.Path) config.ValidationErrors

Validate validates the logging configuration.

type MCPConfig added in v0.13.0

type MCPConfig struct {
	// Enabled enables the MCP server endpoint.
	Enabled bool `koanf:"enabled"`
	// Toolsets is the list of enabled MCP toolsets.
	Toolsets []string `koanf:"toolsets"`
}

MCPConfig defines Model Context Protocol server settings.

func MCPDefaults added in v0.13.0

func MCPDefaults() MCPConfig

MCPDefaults returns the default MCP configuration.

func (*MCPConfig) ParseToolsets added in v0.13.0

func (c *MCPConfig) ParseToolsets() map[tools.ToolsetType]bool

ParseToolsets converts the toolset strings to a map of ToolsetType for lookup.

func (*MCPConfig) ValidateMCPConfig added in v0.17.0

func (c *MCPConfig) ValidateMCPConfig(path *config.Path) config.ValidationErrors

ValidateMCPConfig validates the MCP configuration.

type MechanismConfig added in v0.13.0

type MechanismConfig struct {
	// Entitlement defines how to extract entitlement claims.
	Entitlement EntitlementConfig `koanf:"entitlement"`
}

MechanismConfig defines an authentication mechanism for a subject type.

func (*MechanismConfig) Validate added in v0.13.0

func (c *MechanismConfig) Validate(path *config.Path) config.ValidationErrors

Validate validates the mechanism configuration.

type MiddlewareConfig added in v0.13.0

type MiddlewareConfig struct {
}

MiddlewareConfig defines server middleware configurations. Placeholder for future middleware settings (e.g., request_id).

func MiddlewareDefaults added in v0.13.0

func MiddlewareDefaults() MiddlewareConfig

MiddlewareDefaults returns the default middleware configuration.

func (*MiddlewareConfig) Validate added in v0.13.0

func (c *MiddlewareConfig) Validate(path *config.Path) config.ValidationErrors

Validate validates the middleware configuration.

type OIDCConfig added in v0.13.0

type OIDCConfig struct {
	// Issuer is the OIDC provider issuer URL.
	// Used for token validation and as the base for OAuth metadata.
	Issuer string `koanf:"issuer"`
	// JWKSURL is the URL to fetch JSON Web Key Set for token verification.
	JWKSURL string `koanf:"jwks_url"`
	// AuthorizationEndpoint is the OAuth authorization endpoint URL.
	AuthorizationEndpoint string `koanf:"authorization_endpoint"`
	// TokenEndpoint is the OAuth token endpoint URL.
	TokenEndpoint string `koanf:"token_endpoint"`
}

OIDCConfig defines OpenID Connect provider settings.

func OIDCDefaults added in v0.13.0

func OIDCDefaults() OIDCConfig

OIDCDefaults returns the default OIDC configuration.

func (*OIDCConfig) Validate added in v0.13.0

func (c *OIDCConfig) Validate(_ *config.Path) config.ValidationErrors

Validate validates the OIDC configuration. No validation required - defaults are provided, and incorrect values will fail at runtime when the features are used.

type SecretManagementConfig added in v1.1.0

type SecretManagementConfig struct {
	// Enabled toggles the Secret management API (POST/PUT/GET/LIST/DELETE under
	// /api/v1alpha1/namespaces/{ns}/secrets). When false, all five
	// endpoints return 501 Not Implemented.
	Enabled bool `koanf:"enabled"`
}

SecretManagementConfig defines settings for the Secret management API endpoints.

func SecretManagementDefaults added in v1.1.0

func SecretManagementDefaults() SecretManagementConfig

SecretManagementDefaults returns the default Secret management configuration.

type SecurityConfig added in v0.9.0

type SecurityConfig struct {
	// Enabled enables all security checks (authentication and authorization).
	// When false, authentication and authorization enforcement is skipped and
	// requests are processed as anonymous without any access restrictions.
	Enabled bool `koanf:"enabled"`
	// Authentication defines authentication settings.
	Authentication AuthenticationConfig `koanf:"authentication"`
	// Subjects defines subject types for identity classification.
	// Keys are subject type identifiers (e.g., "user", "service_account").
	Subjects map[string]SubjectConfig `koanf:"subjects"`
	// Authorization defines authorization (Casbin) settings.
	Authorization AuthorizationConfig `koanf:"authorization"`
}

SecurityConfig defines all security-related settings.

func SecurityDefaults added in v0.13.0

func SecurityDefaults() SecurityConfig

SecurityDefaults returns the default security configuration.

func (*SecurityConfig) ToSubjectUserTypeConfigs added in v0.13.0

func (c *SecurityConfig) ToSubjectUserTypeConfigs() []subject.UserTypeConfig

ToSubjectUserTypeConfigs converts the map-based subjects config to the subject library's slice format.

func (*SecurityConfig) Validate added in v0.13.0

func (c *SecurityConfig) Validate(path *config.Path) config.ValidationErrors

Validate validates the security configuration.

type ServerConfig added in v0.13.0

type ServerConfig struct {
	// BindAddress is the address to bind the HTTP server to.
	BindAddress string `koanf:"bind_address"`
	// Port is the HTTP server port.
	Port int `koanf:"port"`
	// PublicURL is the externally accessible URL of this server.
	// Used for OAuth resource metadata and self-referential links.
	PublicURL string `koanf:"public_url"`
	// Timeouts defines HTTP server timeout settings.
	Timeouts TimeoutsConfig `koanf:"timeouts"`
	// TLS defines TLS/HTTPS settings.
	TLS TLSConfig `koanf:"tls"`
	// Middleware defines middleware configurations.
	Middleware MiddlewareConfig `koanf:"middleware"`
}

ServerConfig defines HTTP server settings.

func ServerDefaults added in v0.13.0

func ServerDefaults() ServerConfig

ServerDefaults returns the default server configuration.

func (*ServerConfig) ToServerConfig added in v0.13.0

func (c *ServerConfig) ToServerConfig() server.Config

ToServerConfig converts to the server library config.

func (*ServerConfig) Validate added in v0.13.0

func (c *ServerConfig) Validate(path *config.Path) config.ValidationErrors

Validate validates the server configuration.

type SubjectConfig added in v0.13.0

type SubjectConfig struct {
	// DisplayName is the human-readable name for this subject type.
	DisplayName string `koanf:"display_name"`
	// Priority determines check order (lower = higher priority).
	Priority int `koanf:"priority"`
	// Mechanisms defines authentication mechanisms and their entitlement extraction.
	// Keys are mechanism types (e.g., "jwt").
	Mechanisms map[string]MechanismConfig `koanf:"mechanisms"`
}

SubjectConfig defines a subject type for identity classification.

func (*SubjectConfig) Validate added in v0.13.0

func (c *SubjectConfig) Validate(path *config.Path) config.ValidationErrors

Validate validates the subject configuration.

type TLSConfig added in v0.13.0

type TLSConfig struct {
	// Enabled enables TLS for the HTTP server.
	Enabled bool `koanf:"enabled"`
	// CertFile is the path to the TLS certificate file.
	CertFile string `koanf:"cert_file"`
	// KeyFile is the path to the TLS private key file.
	KeyFile string `koanf:"key_file"`
}

TLSConfig defines TLS/HTTPS settings.

func TLSDefaults added in v0.13.0

func TLSDefaults() TLSConfig

TLSDefaults returns the default TLS configuration.

func (*TLSConfig) Validate added in v0.13.0

func (c *TLSConfig) Validate(path *config.Path) config.ValidationErrors

Validate validates the TLS configuration.

type TimeoutsConfig added in v0.13.0

type TimeoutsConfig struct {
	// Read is the maximum duration for reading the entire request.
	Read time.Duration `koanf:"read"`
	// Write is the maximum duration before timing out writes of the response.
	Write time.Duration `koanf:"write"`
	// Idle is the maximum duration to wait for the next request.
	Idle time.Duration `koanf:"idle"`
	// Shutdown is the maximum duration to wait for active connections to close.
	Shutdown time.Duration `koanf:"shutdown"`
}

TimeoutsConfig defines HTTP server timeout settings.

func TimeoutsDefaults added in v0.13.0

func TimeoutsDefaults() TimeoutsConfig

TimeoutsDefaults returns the default timeout configuration.

func (*TimeoutsConfig) Validate added in v0.13.0

func (c *TimeoutsConfig) Validate(path *config.Path) config.ValidationErrors

Validate validates the timeout configuration.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL