auth

package
v2.2.14 Latest Latest
Warning

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

Go to latest
Published: May 22, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

SPDX-FileCopyrightText: (C) 2025 Intel Corporation SPDX-License-Identifier: Apache-2.0

SPDX-FileCopyrightText: (C) 2025 Intel Corporation SPDX-License-Identifier: Apache-2.0

Index

Constants

View Source
const (
	OidcUrlEnvVar     = "OIDC_SERVER_URL"
	KeycloakUrlEnvVar = "KEYCLOAK_URL"
	OpaEnabledEnvVar  = "OPA_ENABLED"
	OpaPortEnvVar     = "OPA_PORT"
)
View Source
const (
	AuthorizationHeaderKey   = "Authorization"
	ActiveProjectIdHeaderKey = "Activeprojectid"
	BearerPrefix             = "Bearer "
)
View Source
const (
	VaultServer    = "http://vault.orch-platform.svc.cluster.local:8200"
	ServiceAccount = "cluster-manager"
)

Variables

View Source
var NewVaultAuthFunc = NewVaultAuth

NewVaultAuthFunc allows tests to inject a mock VaultAuth implementation

Functions

func ClearClientAccessTokenTTL

func ClearClientAccessTokenTTL(ctx context.Context, oidcURL string, realm string, clientID string, adminToken string) bool

ClearClientAccessTokenTTL removes per-client token lifespan override to inherit realm default. Returns true if override absent or successfully cleared; false on failure.

func EnforceClientAccessTokenTTL

func EnforceClientAccessTokenTTL(ctx context.Context, oidcURL string, realm string, clientID string, desired time.Duration, adminToken string) bool

EnforceClientAccessTokenTTL sets the client's access token lifespan if different from desired value. Returns true on success (including already correct), false on failure.

func EnsureM2MCredentials

func EnsureM2MCredentials(forceRefresh bool) error

EnsureM2MCredentials loads M2M credentials from Vault if not yet cached (force refresh if forceRefresh) Exposed so other packages (e.g. rest) can guarantee the client ID prior to admin enforcement operations

func ExtractClaims

func ExtractClaims(tokenString string) (string, string, time.Time, error)

ExtractClaims extracts claims from a JWT token

func ExtractUserRoles

func ExtractUserRoles(claims jwt.MapClaims) ([]string, error)

ExtractUserRoles extracts user roles from JWT token claims

func GetAccessToken

func GetAccessToken(authHeader string) string

GetAccessToken returns the access token from the Authorization header

func GetM2MClientID

func GetM2MClientID() string

GetM2MClientID returns the currently cached M2M client ID (empty if not yet loaded)

func JwtTokenWithM2M

func JwtTokenWithM2M(ctx context.Context, ttl *time.Duration) (string, error)

JwtTokenWithM2M retrieves a new token from Keycloak using M2M authentication with configurable TTL

func NewNoopAuthenticator

func NewNoopAuthenticator() *noopAuthenticator

NewNoopAuthenticator returns a new no-op Authenticator

func NewOidcAuthenticator

func NewOidcAuthenticator(provider provider, opa opa.ClientWithResponsesInterface) (*oidcAuthenticator, error)

NewOidcAuthenticator returns a new OIDC Authenticator

func NewOidcProvider

func NewOidcProvider(endpoint string) (*oidcProvider, error)

NewOidcProvider creates a new OIDC provider using it's well-known configuration

func NewOpaClient

func NewOpaClient(port int) (opa.ClientWithResponsesInterface, error)

NewOpaClient returns a new OPA client

func SetCachedM2MCredentials

func SetCachedM2MCredentials(id, secret string)

SetCachedM2MCredentials allows the main package (or tests) to preload client credentials so that JwtTokenWithM2M does not need to contact Vault on each invocation. Safe for concurrent reads after set

Types

type TokenResponse

type TokenResponse struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
}

type VaultAuth

type VaultAuth interface {
	GetClientCredentials(ctx context.Context) (string, string, error)
}

func NewVaultAuth

func NewVaultAuth(vaultServer string, serviceAccount string) (VaultAuth, error)

Jump to

Keyboard shortcuts

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