Documentation
¶
Overview ¶
Package httpserver provides HTTP API handlers for HTCondor operations.
Package httpserver provides HTTP API handlers for HTCondor operations.
Index ¶
- func ConfigureSecurityForToken(token string) (*security.SecurityConfig, error)
- func ConfigureSecurityForTokenWithCache(token string, sessionCache *security.SessionCache) (*security.SecurityConfig, error)
- func DefaultOpenIDConnectSession(username string) *openid.DefaultSession
- func GenerateSigningKey() ([]byte, error)
- func GetScheddWithToken(ctx context.Context, schedd *htcondor.Schedd) (*htcondor.Schedd, error)
- func GetSecurityConfigFromToken(ctx context.Context) (*security.SecurityConfig, error)
- func GetTokenFromContext(ctx context.Context) (string, bool)
- func WithToken(ctx context.Context, token string) context.Context
- type CollectorAdsResponse
- type Config
- type ErrorResponse
- type JobActionFunc
- type JobListResponse
- type JobSubmitRequest
- type JobSubmitResponse
- type OAuth2Provider
- type OAuth2StateEntry
- type OAuth2StateStore
- type OAuth2Storage
- func (s *OAuth2Storage) ClientAssertionJWTValid(ctx context.Context, jti string) error
- func (s *OAuth2Storage) Close() error
- func (s *OAuth2Storage) CreateAccessTokenSession(ctx context.Context, signature string, request fosite.Requester) error
- func (s *OAuth2Storage) CreateAuthorizeCodeSession(ctx context.Context, signature string, request fosite.Requester) error
- func (s *OAuth2Storage) CreateClient(ctx context.Context, client *fosite.DefaultClient) error
- func (s *OAuth2Storage) CreateOpenIDConnectSession(ctx context.Context, signature string, requester fosite.Requester) error
- func (s *OAuth2Storage) CreateRefreshTokenSession(ctx context.Context, signature string, request fosite.Requester) error
- func (s *OAuth2Storage) DeleteAccessTokenSession(ctx context.Context, signature string) error
- func (s *OAuth2Storage) DeleteOpenIDConnectSession(ctx context.Context, signature string) error
- func (s *OAuth2Storage) DeleteRefreshTokenSession(ctx context.Context, signature string) error
- func (s *OAuth2Storage) GetAccessTokenSession(ctx context.Context, signature string, session fosite.Session) (fosite.Requester, error)
- func (s *OAuth2Storage) GetAuthorizeCodeSession(ctx context.Context, signature string, session fosite.Session) (fosite.Requester, error)
- func (s *OAuth2Storage) GetClient(ctx context.Context, clientID string) (fosite.Client, error)
- func (s *OAuth2Storage) GetOpenIDConnectSession(ctx context.Context, signature string, requester fosite.Requester) (fosite.Requester, error)
- func (s *OAuth2Storage) GetRefreshTokenSession(ctx context.Context, signature string, session fosite.Session) (fosite.Requester, error)
- func (s *OAuth2Storage) InvalidateAuthorizeCodeSession(ctx context.Context, signature string) error
- func (s *OAuth2Storage) LoadHMACSecret(ctx context.Context) ([]byte, error)
- func (s *OAuth2Storage) LoadRSAKey(ctx context.Context) (string, error)
- func (s *OAuth2Storage) RevokeAccessToken(ctx context.Context, requestID string) error
- func (s *OAuth2Storage) RevokeRefreshToken(ctx context.Context, requestID string) error
- func (s *OAuth2Storage) RevokeRefreshTokenMaybeGracePeriod(ctx context.Context, requestID string, _ string) error
- func (s *OAuth2Storage) SaveHMACSecret(ctx context.Context, secret []byte) error
- func (s *OAuth2Storage) SaveRSAKey(ctx context.Context, privateKeyPEM string) error
- func (s *OAuth2Storage) SetClientAssertionJWT(ctx context.Context, jti string, exp time.Time) error
- type Server
- type TokenCache
- type TokenCacheEntry
- type UserInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConfigureSecurityForToken ¶
func ConfigureSecurityForToken(token string) (*security.SecurityConfig, error)
ConfigureSecurityForToken configures security settings to use the provided token This is a helper function to set up cedar's security configuration for TOKEN authentication
func ConfigureSecurityForTokenWithCache ¶ added in v0.0.3
func ConfigureSecurityForTokenWithCache(token string, sessionCache *security.SessionCache) (*security.SecurityConfig, error)
ConfigureSecurityForTokenWithCache configures security settings with an optional session cache If sessionCache is nil, the global cache will be used
func DefaultOpenIDConnectSession ¶ added in v0.0.3
func DefaultOpenIDConnectSession(username string) *openid.DefaultSession
DefaultOpenIDConnectSession creates a default OpenID Connect session
func GenerateSigningKey ¶
GenerateSigningKey generates a new signing key for token generation Returns the key content as bytes
func GetScheddWithToken ¶
GetScheddWithToken creates a schedd connection configured with token authentication This wraps the schedd to use token authentication from context
func GetSecurityConfigFromToken ¶
func GetSecurityConfigFromToken(ctx context.Context) (*security.SecurityConfig, error)
GetSecurityConfigFromToken retrieves the token from context and creates a SecurityConfig This is a convenience function for HTTP handlers to convert context token to SecurityConfig
func GetTokenFromContext ¶
GetTokenFromContext retrieves the token from the context
Types ¶
type CollectorAdsResponse ¶ added in v0.0.3
CollectorAdsResponse represents collector ads listing response
type Config ¶
type Config struct {
ListenAddr string // Address to listen on (e.g., ":8080")
ScheddName string // Schedd name
ScheddAddr string // Schedd address (e.g., "127.0.0.1:9618"). If empty, discovered from collector.
UserHeader string // HTTP header to extract username from (optional)
SigningKeyPath string // Path to token signing key (optional, for token generation)
TrustDomain string // Trust domain for token issuer (optional; only used if UserHeader is set)
UIDDomain string // UID domain for generated token username (optional; only used if UserHeader is set)
TLSCertFile string // Path to TLS certificate file (optional, enables HTTPS)
TLSKeyFile string // Path to TLS key file (optional, enables HTTPS)
ReadTimeout time.Duration // HTTP read timeout (default: 30s)
WriteTimeout time.Duration // HTTP write timeout (default: 30s)
IdleTimeout time.Duration // HTTP idle timeout (default: 120s)
Collector *htcondor.Collector // Collector for metrics (optional)
EnableMetrics bool // Enable /metrics endpoint (default: true if Collector is set)
MetricsCacheTTL time.Duration // Metrics cache TTL (default: 10s)
Logger *logging.Logger // Logger instance (optional, creates default if nil)
EnableMCP bool // Enable MCP endpoints with OAuth2 (default: false)
OAuth2DBPath string // Path to OAuth2 SQLite database (default: "oauth2.db")
OAuth2Issuer string // OAuth2 issuer URL (default: listen address)
OAuth2ClientID string // OAuth2 client ID for SSO (optional)
OAuth2ClientSecret string // OAuth2 client secret for SSO (optional)
OAuth2AuthURL string // OAuth2 authorization URL for SSO (optional)
OAuth2TokenURL string // OAuth2 token URL for SSO (optional)
OAuth2RedirectURL string // OAuth2 redirect URL for SSO (optional)
OAuth2UserInfoURL string // OAuth2 user info endpoint for SSO (optional)
OAuth2UsernameClaim string // Claim name for username in token (default: "sub")
OAuth2GroupsClaim string // Claim name for groups in user info (default: "groups")
MCPAccessGroup string // Group required for any MCP access (empty = all authenticated)
MCPReadGroup string // Group required for read operations (empty = all have read)
MCPWriteGroup string // Group required for write operations (empty = all have write)
}
Config holds server configuration
type ErrorResponse ¶
type ErrorResponse struct {
Error string `json:"error"`
Message string `json:"message,omitempty"`
Code int `json:"code"`
}
ErrorResponse represents an error response
type JobActionFunc ¶ added in v0.0.3
type JobActionFunc func(ctx context.Context, constraint, reason string) (*htcondor.JobActionResults, error)
JobActionFunc is a function that performs a job action (hold, release, etc.)
type JobListResponse ¶
JobListResponse represents a job listing response
type JobSubmitRequest ¶
type JobSubmitRequest struct {
SubmitFile string `json:"submit_file"` // Submit file content
}
JobSubmitRequest represents a job submission request
type JobSubmitResponse ¶
type JobSubmitResponse struct {
ClusterID int `json:"cluster_id"`
JobIDs []string `json:"job_ids"` // Array of "cluster.proc" strings
}
JobSubmitResponse represents a job submission response
type OAuth2Provider ¶ added in v0.0.3
type OAuth2Provider struct {
// contains filtered or unexported fields
}
OAuth2Provider manages OAuth2 operations
func NewOAuth2Provider ¶ added in v0.0.3
func NewOAuth2Provider(dbPath string, issuer string) (*OAuth2Provider, error)
NewOAuth2Provider creates a new OAuth2 provider with SQLite storage
func (*OAuth2Provider) Close ¶ added in v0.0.3
func (p *OAuth2Provider) Close() error
Close closes the OAuth2 provider and its storage
func (*OAuth2Provider) GetProvider ¶ added in v0.0.3
func (p *OAuth2Provider) GetProvider() fosite.OAuth2Provider
GetProvider returns the underlying fosite OAuth2Provider
func (*OAuth2Provider) GetStorage ¶ added in v0.0.3
func (p *OAuth2Provider) GetStorage() *OAuth2Storage
GetStorage returns the OAuth2 storage
type OAuth2StateEntry ¶ added in v0.0.3
type OAuth2StateEntry struct {
AuthorizeRequest fosite.AuthorizeRequester
Timestamp time.Time
}
OAuth2StateEntry represents a stored OAuth2 authorization state
type OAuth2StateStore ¶ added in v0.0.3
type OAuth2StateStore struct {
// contains filtered or unexported fields
}
OAuth2StateStore manages OAuth2 state parameters for the authorization flow
func NewOAuth2StateStore ¶ added in v0.0.3
func NewOAuth2StateStore() *OAuth2StateStore
NewOAuth2StateStore creates a new OAuth2 state store
func (*OAuth2StateStore) GenerateState ¶ added in v0.0.3
func (s *OAuth2StateStore) GenerateState() (string, error)
GenerateState generates a secure random state parameter
func (*OAuth2StateStore) Get ¶ added in v0.0.3
func (s *OAuth2StateStore) Get(state string) (fosite.AuthorizeRequester, bool)
Get retrieves and removes an authorize request for the given state
func (*OAuth2StateStore) Store ¶ added in v0.0.3
func (s *OAuth2StateStore) Store(state string, ar fosite.AuthorizeRequester)
Store stores an authorize request with the given state
type OAuth2Storage ¶ added in v0.0.3
type OAuth2Storage struct {
// contains filtered or unexported fields
}
OAuth2Storage implements fosite storage interfaces using SQLite
func NewOAuth2Storage ¶ added in v0.0.3
func NewOAuth2Storage(dbPath string) (*OAuth2Storage, error)
NewOAuth2Storage creates a new OAuth2 storage backed by SQLite
func (*OAuth2Storage) ClientAssertionJWTValid ¶ added in v0.0.3
func (s *OAuth2Storage) ClientAssertionJWTValid(ctx context.Context, jti string) error
ClientAssertionJWTValid implements fosite.ClientAssertionJWTValid interface This checks if a JWT ID (JTI) has already been used to prevent replay attacks
func (*OAuth2Storage) Close ¶ added in v0.0.3
func (s *OAuth2Storage) Close() error
Close closes the database connection
func (*OAuth2Storage) CreateAccessTokenSession ¶ added in v0.0.3
func (s *OAuth2Storage) CreateAccessTokenSession(ctx context.Context, signature string, request fosite.Requester) error
CreateAccessTokenSession stores an access token session
func (*OAuth2Storage) CreateAuthorizeCodeSession ¶ added in v0.0.3
func (s *OAuth2Storage) CreateAuthorizeCodeSession(ctx context.Context, signature string, request fosite.Requester) error
CreateAuthorizeCodeSession stores an authorization code session
func (*OAuth2Storage) CreateClient ¶ added in v0.0.3
func (s *OAuth2Storage) CreateClient(ctx context.Context, client *fosite.DefaultClient) error
CreateClient creates a new OAuth2 client
func (*OAuth2Storage) CreateOpenIDConnectSession ¶ added in v0.0.3
func (s *OAuth2Storage) CreateOpenIDConnectSession(ctx context.Context, signature string, requester fosite.Requester) error
CreateOpenIDConnectSession implements openid.OpenIDConnectRequestStorage interface
func (*OAuth2Storage) CreateRefreshTokenSession ¶ added in v0.0.3
func (s *OAuth2Storage) CreateRefreshTokenSession(ctx context.Context, signature string, request fosite.Requester) error
CreateRefreshTokenSession stores a refresh token session
func (*OAuth2Storage) DeleteAccessTokenSession ¶ added in v0.0.3
func (s *OAuth2Storage) DeleteAccessTokenSession(ctx context.Context, signature string) error
DeleteAccessTokenSession deletes an access token session
func (*OAuth2Storage) DeleteOpenIDConnectSession ¶ added in v0.0.3
func (s *OAuth2Storage) DeleteOpenIDConnectSession(ctx context.Context, signature string) error
DeleteOpenIDConnectSession implements openid.OpenIDConnectRequestStorage interface
func (*OAuth2Storage) DeleteRefreshTokenSession ¶ added in v0.0.3
func (s *OAuth2Storage) DeleteRefreshTokenSession(ctx context.Context, signature string) error
DeleteRefreshTokenSession deletes a refresh token session
func (*OAuth2Storage) GetAccessTokenSession ¶ added in v0.0.3
func (s *OAuth2Storage) GetAccessTokenSession(ctx context.Context, signature string, session fosite.Session) (fosite.Requester, error)
GetAccessTokenSession retrieves an access token session
func (*OAuth2Storage) GetAuthorizeCodeSession ¶ added in v0.0.3
func (s *OAuth2Storage) GetAuthorizeCodeSession(ctx context.Context, signature string, session fosite.Session) (fosite.Requester, error)
GetAuthorizeCodeSession retrieves an authorization code session
func (*OAuth2Storage) GetOpenIDConnectSession ¶ added in v0.0.3
func (s *OAuth2Storage) GetOpenIDConnectSession(ctx context.Context, signature string, requester fosite.Requester) (fosite.Requester, error)
GetOpenIDConnectSession implements openid.OpenIDConnectRequestStorage interface
func (*OAuth2Storage) GetRefreshTokenSession ¶ added in v0.0.3
func (s *OAuth2Storage) GetRefreshTokenSession(ctx context.Context, signature string, session fosite.Session) (fosite.Requester, error)
GetRefreshTokenSession retrieves a refresh token session
func (*OAuth2Storage) InvalidateAuthorizeCodeSession ¶ added in v0.0.3
func (s *OAuth2Storage) InvalidateAuthorizeCodeSession(ctx context.Context, signature string) error
InvalidateAuthorizeCodeSession invalidates an authorization code
func (*OAuth2Storage) LoadHMACSecret ¶ added in v0.0.3
func (s *OAuth2Storage) LoadHMACSecret(ctx context.Context) ([]byte, error)
LoadHMACSecret loads the HMAC secret
func (*OAuth2Storage) LoadRSAKey ¶ added in v0.0.3
func (s *OAuth2Storage) LoadRSAKey(ctx context.Context) (string, error)
LoadRSAKey loads the RSA private key in PEM format
func (*OAuth2Storage) RevokeAccessToken ¶ added in v0.0.3
func (s *OAuth2Storage) RevokeAccessToken(ctx context.Context, requestID string) error
RevokeAccessToken revokes an access token
func (*OAuth2Storage) RevokeRefreshToken ¶ added in v0.0.3
func (s *OAuth2Storage) RevokeRefreshToken(ctx context.Context, requestID string) error
RevokeRefreshToken revokes a refresh token
func (*OAuth2Storage) RevokeRefreshTokenMaybeGracePeriod ¶ added in v0.0.3
func (s *OAuth2Storage) RevokeRefreshTokenMaybeGracePeriod(ctx context.Context, requestID string, _ string) error
RevokeRefreshTokenMaybeGracePeriod implements fosite.TokenRevocationStorage interface This handles refresh token revocation. The signature parameter allows for grace period implementation but for simplicity we immediately revoke the token by request ID
func (*OAuth2Storage) SaveHMACSecret ¶ added in v0.0.3
func (s *OAuth2Storage) SaveHMACSecret(ctx context.Context, secret []byte) error
SaveHMACSecret stores the HMAC secret
func (*OAuth2Storage) SaveRSAKey ¶ added in v0.0.3
func (s *OAuth2Storage) SaveRSAKey(ctx context.Context, privateKeyPEM string) error
SaveRSAKey stores the RSA private key in PEM format
func (*OAuth2Storage) SetClientAssertionJWT ¶ added in v0.0.3
SetClientAssertionJWT implements fosite.SetClientAssertionJWT interface This stores the JTI (JWT ID) with expiration to prevent replay attacks
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server represents the HTTP API server
func (*Server) GetAddr ¶ added in v0.0.3
GetAddr returns the actual listening address of the server. Returns empty string if the server hasn't started yet.
func (*Server) GetOAuth2Provider ¶ added in v0.0.3
func (s *Server) GetOAuth2Provider() *OAuth2Provider
GetOAuth2Provider returns the OAuth2 provider (for testing)
func (*Server) UpdateOAuth2RedirectURL ¶ added in v0.0.3
UpdateOAuth2RedirectURL updates the OAuth2 redirect URL for SSO integration. This is useful when the server is started with a dynamic port (e.g., "127.0.0.1:0") and you need to update the redirect URL after the server has started.
type TokenCache ¶ added in v0.0.3
type TokenCache struct {
// contains filtered or unexported fields
}
TokenCache manages validated tokens and their associated session caches
func NewTokenCache ¶ added in v0.0.3
func NewTokenCache() *TokenCache
NewTokenCache creates a new token cache
func (*TokenCache) Add ¶ added in v0.0.3
func (tc *TokenCache) Add(token string) (*TokenCacheEntry, error)
Add adds a validated token to the cache with a session cache If the token is already in the cache, returns the existing entry Automatically schedules cleanup when the token expires
func (*TokenCache) Get ¶ added in v0.0.3
func (tc *TokenCache) Get(token string) (*TokenCacheEntry, bool)
Get retrieves a token cache entry if it exists and is not expired
func (*TokenCache) Remove ¶ added in v0.0.3
func (tc *TokenCache) Remove(token string)
Remove removes a token from the cache and cancels its cleanup timer
func (*TokenCache) Size ¶ added in v0.0.3
func (tc *TokenCache) Size() int
Size returns the number of cached tokens
type TokenCacheEntry ¶ added in v0.0.3
type TokenCacheEntry struct {
Token string
Username string // Username extracted from JWT (for rate limiting)
Expiration time.Time
SessionCache *security.SessionCache
// contains filtered or unexported fields
}
TokenCacheEntry represents a cached token with its expiration and associated session cache
type UserInfo ¶ added in v0.0.3
type UserInfo struct {
Subject string `json:"sub"`
Email string `json:"email"`
Name string `json:"name"`
Groups interface{} `json:"groups"` // Can be []string or string
Claims map[string]interface{} // Additional claims
}
UserInfo represents user information from the IDP