iam

package
v3.17.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	OIDCPathPrefix        = "/oidc"
	SessionCookieName     = "agent-session"
	SessionOAuthTokenName = "agent-oauth-token"
)

Variables

View Source
var (
	ErrPrincipalExtraction = errors.New("could not extract principal from token")
	ErrRoleDenied          = errors.New("user does not have the required role")
)

Functions

func ContextWithIDToken

func ContextWithIDToken(ctx context.Context, idToken *jwt.Token) context.Context

ContextWithIDToken adds the IDToken to the context

func GetIDToken

func GetIDToken(ctx context.Context) (*jwt.Token, error)

GetIDToken retrieves the ID token from the context if there is one or nil

func IsValidPolicy

func IsValidPolicy(policy api.IAMPolicy) (bool, string)

IsValidPolicy checks if the IAM policy is valid. If its not it returns a string with a human readable message about the violations

func NewAuthMiddleware

func NewAuthMiddleware(oidc *OIDC) (func(http.Handler) http.Handler, error)

NewAuthMiddleware creates a middleware that enforces OIDC authentication

func NewAuthMiddlewareForOIDC

func NewAuthMiddlewareForOIDC(oidc *OIDC) (func(http.Handler) http.Handler, error)

NewAuthMiddlewareForOIDC allows our test to inject a mock OIDC

Types

type AllowAllChecker

type AllowAllChecker struct{}

AllowAllChecker is a no auth checker that allows all requests.

func (*AllowAllChecker) Check

func (c *AllowAllChecker) Check(principal string, role string) bool

func (*AllowAllChecker) GetPrincipal

func (c *AllowAllChecker) GetPrincipal(idToken *jwt.Token) (string, error)

GetPrincipal returns empty principal.

type AuthContext

type AuthContext struct {
	OIDC    *OIDC
	Checker Checker
	Role    string
}

todo(sebastian): use everywhere? AuthContext encapsulates the Auth/IAM context for handlers.

func (*AuthContext) AuthorizeBearerToken added in v3.16.6

func (a *AuthContext) AuthorizeBearerToken(ctx context.Context, bearerToken string) (context.Context, error)

func (*AuthContext) AuthorizeRequest

func (a *AuthContext) AuthorizeRequest(ctx context.Context, req *streamv1.WebsocketRequest) error

type Checker

type Checker interface {
	Check(principal string, role string) bool
	GetPrincipal(idToken *jwt.Token) (string, error)
}

type GenericProvider

type GenericProvider struct {
	// contains filtered or unexported fields
}

GenericProvider implements OIDCProvider for generic OIDC providers

func NewGenericProvider

func NewGenericProvider(cfg *config.GenericOIDCConfig) *GenericProvider

func (*GenericProvider) GetDiscoveryURL

func (p *GenericProvider) GetDiscoveryURL() string

func (*GenericProvider) GetOAuth2Config

func (p *GenericProvider) GetOAuth2Config() (*oauth2.Config, error)

func (*GenericProvider) ValidateDomainClaims

func (p *GenericProvider) ValidateDomainClaims(claims jwt.MapClaims, allowedDomains []string) error

type GoogleProvider

type GoogleProvider struct {
	// contains filtered or unexported fields
}

GoogleProvider implements OIDCProvider for Google OAuth2

func NewGoogleProvider

func NewGoogleProvider(cfg *config.GoogleOIDCConfig) *GoogleProvider

func (*GoogleProvider) GetDiscoveryURL

func (p *GoogleProvider) GetDiscoveryURL() string

func (*GoogleProvider) GetOAuth2Config

func (p *GoogleProvider) GetOAuth2Config() (*oauth2.Config, error)

func (*GoogleProvider) ValidateDomainClaims

func (p *GoogleProvider) ValidateDomainClaims(claims jwt.MapClaims, allowedDomains []string) error

type IDTokenKeyType

type IDTokenKeyType string

IDTokenKeyType string is the key used to store the ID token in the context We define a type to avoid collisions with other context keys

const (
	IDTokenKey IDTokenKeyType = "idToken"
)

type OIDC

type OIDC struct {
	// contains filtered or unexported fields
}

OIDC handles OAuth2 authentication setup and management

func NewOIDC

func NewOIDC(cfg *config.OIDCConfig) (*OIDC, error)

NewOIDC creates a new OIDC

func (*OIDC) CallbackHandler

func (o *OIDC) CallbackHandler(w http.ResponseWriter, r *http.Request)

callbackHandler handles the OAuth2 callback

func (*OIDC) DoClientExchange added in v3.15.2

func (o *OIDC) DoClientExchange() bool

DoClientExchange true if the token exchange happens on the client

func (*OIDC) LoginHandler

func (o *OIDC) LoginHandler(w http.ResponseWriter, r *http.Request)

loginHandler handles the OAuth2 login flow

func (*OIDC) LogoutHandler

func (o *OIDC) LogoutHandler(w http.ResponseWriter, r *http.Request)

LogoutHandler handles the OAuth2 logout

type OIDCProvider

type OIDCProvider interface {
	// GetOAuth2Config returns the OAuth2 configuration
	GetOAuth2Config() (*oauth2.Config, error)
	// GetDiscoveryURL returns the OpenID Connect discovery URL
	GetDiscoveryURL() string
}

OIDCProvider defines the interface for OIDC providers

type PolicyChecker

type PolicyChecker struct {
	// contains filtered or unexported fields
}

PolicyChecker enforces IAMPolicies. It checks if a user has the required permissions to perform an action.

func NewChecker

func NewChecker(policy api.IAMPolicy) (*PolicyChecker, error)

NewChecker creates a new IAM policy checker.

func (*PolicyChecker) Check

func (c *PolicyChecker) Check(principal string, role string) bool

Check returns true if and only if the principal has the given role in the IAM policy.

func (*PolicyChecker) GetPrincipal

func (c *PolicyChecker) GetPrincipal(idToken *jwt.Token) (string, error)

GetPrincipal returns the principal from the idToken.

type TestIDP

type TestIDP struct {
	OIDC    *OIDC
	OIDCCfg *config.OIDCConfig
	// contains filtered or unexported fields
}

func NewTestIDP

func NewTestIDP(clientCredentialsFile string) (*TestIDP, error)

func (*TestIDP) GenerateToken

func (idp *TestIDP) GenerateToken(claims jwt.Claims) (string, error)

func (*TestIDP) GenerateTokenWithMethod added in v3.16.6

func (idp *TestIDP) GenerateTokenWithMethod(claims jwt.Claims, method jwt.SigningMethod) (string, error)

Jump to

Keyboard shortcuts

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