Documentation
¶
Index ¶
- func DefaultExpiration() string
- func DefaultExtensions() map[string]string
- func Forbidden(message string) error
- func NewHandler(config Config) (http.Handler, error)
- func ValidateDuration(d string) error
- type Config
- type OIDCConfig
- type PolicyConfig
- type PolicyEvaluator
- type PolicyRulesConfig
- type Rules
- type ServerConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultExpiration ¶ added in v0.1.8
func DefaultExpiration() string
DefaultExpiration returns the default certificate expiration duration
func DefaultExtensions ¶ added in v0.1.8
DefaultExtensions returns the default SSH certificate extensions
func NewHandler ¶
NewHandler creates an HTTP handler for the policy server. The handler supports:
GET / — returns discovery data (auth config for the OIDC bootstrap) POST / — evaluates a cert request (token + connection)
Every request must carry a valid CA-minted request token (pkg/serviceauth); CAPublicKey is therefore required.
func ValidateDuration ¶ added in v0.1.8
ValidateDuration checks if a duration string is valid
Types ¶
type Config ¶
type Config struct {
// CAPublicKey is the CA's SSH public key, used to verify the request-bound
// JWT (pkg/serviceauth) on every request. Required.
CAPublicKey sshcert.RawPublicKey
// Validator validates tokens and extracts identity (authentication).
Validator *oidc.Validator
// Evaluator makes authorization decisions based on identity.
Evaluator PolicyEvaluator
// Discovery is the configuration returned on GET / requests.
// The CA fetches this to serve discovery data to clients.
Discovery *wire.Discovery
}
Config configures the policy server HTTP handler.
type OIDCConfig ¶ added in v0.1.8
type OIDCConfig struct {
Issuer string `yaml:"issuer" json:"issuer"`
ClientID string `yaml:"client_id" json:"client_id"`
ClientSecret string `yaml:"client_secret,omitempty" json:"client_secret,omitempty"` // Optional, for confidential clients
}
OIDCConfig represents OIDC configuration for token validation
type PolicyConfig ¶ added in v0.8.0
type PolicyConfig struct {
Users map[string][]string `yaml:"users" json:"users"` // user identity → tags
Defaults *Rules `yaml:"defaults,omitempty" json:"defaults,omitempty"`
Hosts map[string]*Rules `yaml:"hosts,omitempty" json:"hosts,omitempty"` // hostname → host rules
}
PolicyConfig contains the policy rules the evaluator applies: users, host patterns, and defaults. It is read once at startup from config; reload is a process restart (dynamic reload via URL was removed, see task 8b).
type PolicyEvaluator ¶
type PolicyEvaluator interface {
// Evaluate makes an authorization decision for the given identity and connection.
// The identity has already been extracted from a validated token.
// tokenExpiry is the auth token's expiry, used to clamp the issued
// certificate's validity so it can never outlive the auth session that
// requested it.
// Returns:
// - *wire.PolicyResponse: Certificate parameters and policy if authorized
// - error: If authorization denied
//
// Error handling:
// - Return policyserver.Forbidden (403) if access denied by policy
// - Return other errors (500) for internal errors
Evaluate(ctx context.Context, identity string, tokenExpiry time.Time, conn policy.Connection) (*wire.PolicyResponse, error)
}
PolicyEvaluator makes authorization decisions based on identity and connection details. The token has already been validated and identity extracted by the handler. Implementations must: - Make authorization decision (allow/deny) based on identity - Return certificate parameters (principals, expiration, extensions) for the matching host pattern - Return appropriate errors for different failure modes
type PolicyRulesConfig ¶ added in v0.1.8
type PolicyRulesConfig struct {
CAPublicKey string `yaml:"ca_pubkey" json:"ca_pubkey"`
OIDC OIDCConfig `yaml:"oidc" json:"oidc"`
Users map[string][]string `yaml:"users" json:"users"` // user identity → tags
Defaults *Rules `yaml:"defaults,omitempty" json:"defaults,omitempty"`
Hosts map[string]*Rules `yaml:"hosts,omitempty" json:"hosts,omitempty"` // hostname → host rules
}
PolicyRulesConfig represents the policy server rules configuration. This defines users, hosts, and access policies - not CLI flags. It bundles what ServerConfig and PolicyConfig hold separately, for the inline single-file config case; ExtractServerConfig/ExtractPolicyConfig split it into those two for the evaluator.
func (*PolicyRulesConfig) ExtractPolicyConfig ¶ added in v0.8.0
func (c *PolicyRulesConfig) ExtractPolicyConfig() *PolicyConfig
ExtractPolicyConfig extracts the policy-rules portion (users/hosts/defaults) from PolicyRulesConfig, for passing to evaluator.New/NewForTesting.
func (*PolicyRulesConfig) ExtractServerConfig ¶ added in v0.8.0
func (c *PolicyRulesConfig) ExtractServerConfig() *ServerConfig
ExtractServerConfig extracts the static server portion from PolicyRulesConfig. Used for backwards compatibility when all config is in one file.
func (*PolicyRulesConfig) Validate ¶ added in v0.1.8
func (c *PolicyRulesConfig) Validate() error
Validate checks that the PolicyRulesConfig is valid
type Rules ¶ added in v0.18.0
type Rules struct {
Allow map[string][]string `yaml:"allow,omitempty" json:"allow,omitempty"` // principal → allowed tags
Expiration string `yaml:"expiration,omitempty" json:"expiration,omitempty"` // Cert expiration (e.g., "5m")
Extensions map[string]string `yaml:"extensions,omitempty" json:"extensions,omitempty"` // Cert extensions
}
Rules defines a set of policy rules: which principals are allowed, cert expiration, and cert extensions. It is used both as the global default (PolicyConfig.Defaults) and as a per-host override (PolicyConfig.Hosts), since the two were structurally identical and only differed by name.
type ServerConfig ¶ added in v0.8.0
type ServerConfig struct {
CAPublicKey string `yaml:"ca_pubkey" json:"ca_pubkey"`
OIDC OIDCConfig `yaml:"oidc" json:"oidc"`
}
ServerConfig contains static server configuration loaded at startup. These settings cannot be changed without restarting the server.
func (*ServerConfig) BootstrapAuth ¶ added in v0.8.0
func (c *ServerConfig) BootstrapAuth() wire.AuthConfig
BootstrapAuth returns the auth configuration for the bootstrap endpoint.
func (*ServerConfig) Validate ¶ added in v0.8.0
func (c *ServerConfig) Validate() error
Validate checks that the ServerConfig is valid.