Documentation
¶
Index ¶
- Constants
- func Authenticate(doc *UsersFile, principal, token string) error
- func FindDefaultRemote(cfg *remoteapi.AuthConfig) (*remoteapi.RemoteConfig, bool)
- func FreshAccessToken(ctx context.Context, remote remoteapi.RemoteConfig) (string, error)
- func GenerateKey() (string, error)
- func GenerateToken() (string, error)
- func HashToken(token string) string
- func LoadAuthConfig(path string) (*remoteapi.AuthConfig, error)
- func LoadKey(path string) ([]byte, error)
- func LoginOIDC(ctx context.Context, req OIDCLoginRequest) (remoteapi.RemoteConfig, error)
- func OpenBrowser(url string) error
- func SaveAuthConfig(path string, cfg *remoteapi.AuthConfig) error
- func SaveUsers(path string, doc *UsersFile) error
- func UpsertRemote(cfg *remoteapi.AuthConfig, remote remoteapi.RemoteConfig)
- func UpsertUser(doc *UsersFile, user User)
- func VerifyToken(token, hash string) bool
- type Discovery
- type DispatchVerifier
- type Identity
- type Issuer
- type OIDCConfig
- type OIDCLoginRequest
- type OIDCVerifier
- type StoreVerifier
- type User
- type UsersFile
- type Verifier
Constants ¶
const ( // ProvisionAuto inserts a user principal the first time a valid token is seen. ProvisionAuto = "auto" // ProvisionAllowlist rejects principals that were not created ahead of time. ProvisionAllowlist = "allowlist" )
const HashPrefix = "sha256:"
Variables ¶
This section is empty.
Functions ¶
func Authenticate ¶
func FindDefaultRemote ¶
func FindDefaultRemote(cfg *remoteapi.AuthConfig) (*remoteapi.RemoteConfig, bool)
func FreshAccessToken ¶ added in v1.1.0
FreshAccessToken returns the stored bearer, refreshing an OIDC access token that expires within a minute. The refresh token is not included in the result.
func GenerateKey ¶
GenerateKey returns a 32-byte random HMAC key as hex.
func GenerateToken ¶
func LoadAuthConfig ¶
func LoadAuthConfig(path string) (*remoteapi.AuthConfig, error)
func LoginOIDC ¶ added in v1.1.0
func LoginOIDC(ctx context.Context, req OIDCLoginRequest) (remoteapi.RemoteConfig, error)
LoginOIDC performs the loopback PKCE flow and stores the remote. The refresh token is written to disk and is never returned to the server.
func OpenBrowser ¶ added in v1.1.0
OpenBrowser starts the OS URL handler. Failure is not fatal; the URL is also printed.
func SaveAuthConfig ¶
func SaveAuthConfig(path string, cfg *remoteapi.AuthConfig) error
func UpsertRemote ¶
func UpsertRemote(cfg *remoteapi.AuthConfig, remote remoteapi.RemoteConfig)
func UpsertUser ¶
func VerifyToken ¶
Types ¶
type Discovery ¶ added in v1.1.0
type Discovery struct {
Issuer string `json:"issuer"`
AuthorizationEndpoint string `json:"authorization_endpoint"`
TokenEndpoint string `json:"token_endpoint"`
JWKSURI string `json:"jwks_uri"`
}
Discovery is the subset of an OpenID provider metadata document the CLI and the server both need.
type DispatchVerifier ¶ added in v1.1.0
type DispatchVerifier struct {
Invite *StoreVerifier
OIDC *OIDCVerifier
}
DispatchVerifier routes HS256 invite tokens and RS256/ES256 OIDC tokens. The HMAC key is never used on an OIDC token.
type Identity ¶
Identity is the verified actor. Invite tokens take the principal from sub. OIDC tokens take it from the configured principal claim.
type OIDCConfig ¶ added in v1.1.0
type OIDCConfig struct {
Issuer string
Audience string
JWKSURL string
PrincipalClaim string
AllowClaim string
AllowValue string
RoleClaim string
OrgValue string
Provision string
}
OIDCConfig is generic OIDC access-token verification. It does not name a vendor.
func (*OIDCConfig) Prepare ¶ added in v1.1.0
func (c *OIDCConfig) Prepare() error
Prepare applies defaults and rejects a configuration that would admit every account at the issuer. A claim gate or an allowlist is required.
type OIDCLoginRequest ¶ added in v1.1.0
type OIDCLoginRequest struct {
Issuer string
ClientID string
Server string
Name string
DataDir string
PrincipalClaim string
CAFile string
ServerName string
MakeDefault bool
// Scopes are requested in addition to openid and profile. Blank entries and
// duplicates are dropped. offline_access is not included unless listed here.
Scopes []string
// OpenBrowser is called with the authorization URL. Nil prints the URL and
// tries the OS opener. Tests can complete the redirect themselves.
OpenBrowser func(url string) error
Timeout time.Duration
HTTP *http.Client
}
OIDCLoginRequest is a public-client authorization-code login with PKCE.
type OIDCVerifier ¶ added in v1.1.0
type OIDCVerifier struct {
DB *store.DB
Config OIDCConfig
HTTP *http.Client
// contains filtered or unexported fields
}
OIDCVerifier checks RS256/ES256 access tokens against an IdP JWKS.
func NewOIDCVerifier ¶ added in v1.1.0
func NewOIDCVerifier(db *store.DB, cfg OIDCConfig) (*OIDCVerifier, error)
NewOIDCVerifier validates cfg and returns a verifier. JWKS is fetched on first use.
type StoreVerifier ¶
StoreVerifier checks signature, expiry, principal, and jti revocation against the DB.
type Verifier ¶
Verifier validates a bearer token. StoreVerifier checks invite JWTs. OIDCVerifier checks IdP access tokens. DispatchVerifier accepts both.
func NewVerifier ¶ added in v1.1.0
NewVerifier builds the invite verifier, the OIDC verifier, or both. jwtKeyFile may be empty only when cfg.Issuer is set.