pomerium/authorize/evaluator/config.go
Kenneth Jenkins de68e37bc3
config: add new mTLS enforcement setting (#4443)
Add an "enforcement" option to the new downstream mTLS configuration
settings group.

When not set, or when set to "policy_default_deny", keep the current
behavior of adding an invalid_client_certificate rule to all policies.

When the enforcement mode is set to just "policy", remove the default
invalid_client_certificate rule that would be normally added.

When the enforcement mode is set to "reject_connection", configure the
Envoy listener with the require_client_certificate setting and remove
the ACCEPT_UNTRUSTED option.

Add a corresponding field to the Settings proto.
2023-08-09 07:53:11 -07:00

85 lines
2.5 KiB
Go

package evaluator
import (
"github.com/pomerium/pomerium/config"
)
type evaluatorConfig struct {
policies []config.Policy
clientCA []byte
clientCRL []byte
addDefaultClientCertificateRule bool
signingKey []byte
authenticateURL string
googleCloudServerlessAuthenticationServiceAccount string
jwtClaimsHeaders config.JWTClaimHeaders
}
// An Option customizes the evaluator config.
type Option func(*evaluatorConfig)
func getConfig(options ...Option) *evaluatorConfig {
cfg := new(evaluatorConfig)
for _, o := range options {
o(cfg)
}
return cfg
}
// WithPolicies sets the policies in the config.
func WithPolicies(policies []config.Policy) Option {
return func(cfg *evaluatorConfig) {
cfg.policies = policies
}
}
// WithClientCA sets the client CA in the config.
func WithClientCA(clientCA []byte) Option {
return func(cfg *evaluatorConfig) {
cfg.clientCA = clientCA
}
}
// WithClientCRL sets the client CRL in the config.
func WithClientCRL(clientCRL []byte) Option {
return func(cfg *evaluatorConfig) {
cfg.clientCRL = clientCRL
}
}
// WithAddDefaultClientCertificateRule sets whether to add a default
// invalid_client_certificate deny rule to all policies.
func WithAddDefaultClientCertificateRule(addDefaultClientCertificateRule bool) Option {
return func(cfg *evaluatorConfig) {
cfg.addDefaultClientCertificateRule = addDefaultClientCertificateRule
}
}
// WithSigningKey sets the signing key and algorithm in the config.
func WithSigningKey(signingKey []byte) Option {
return func(cfg *evaluatorConfig) {
cfg.signingKey = signingKey
}
}
// WithAuthenticateURL sets the authenticate URL in the config.
func WithAuthenticateURL(authenticateURL string) Option {
return func(cfg *evaluatorConfig) {
cfg.authenticateURL = authenticateURL
}
}
// WithGoogleCloudServerlessAuthenticationServiceAccount sets the google cloud serverless authentication service
// account in the config.
func WithGoogleCloudServerlessAuthenticationServiceAccount(serviceAccount string) Option {
return func(cfg *evaluatorConfig) {
cfg.googleCloudServerlessAuthenticationServiceAccount = serviceAccount
}
}
// WithJWTClaimsHeaders sets the JWT claims headers in the config.
func WithJWTClaimsHeaders(headers config.JWTClaimHeaders) Option {
return func(cfg *evaluatorConfig) {
cfg.jwtClaimsHeaders = headers
}
}