auth

package
v1.0.3-rc.1 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: EPL-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildControllerDialTLSConfig

func BuildControllerDialTLSConfig(secureMode bool, configuredPath string, customCerts []*x509.Certificate, loadErr error) *tls.Config

BuildControllerDialTLSConfig builds TLS settings for controller HTTPS/WSS dials.

Trust policy:

  • secureMode off: skip verification (controllerCert ignored)
  • secureMode on, empty configuredPath: OS trust store (RootCAs nil)
  • secureMode on, path set, loadErr != nil: OS trust store (missing/unreadable file)
  • secureMode on, path set, certs loaded: exclusive trust in those PEMs only

func CertPoolFromCertificates

func CertPoolFromCertificates(certs []*x509.Certificate) *x509.CertPool

CertPoolFromCertificates builds a root pool from the given certificates.

func ConstantTimeCompare

func ConstantTimeCompare(a, b []byte) bool

ConstantTimeCompare performs a constant-time comparison of two byte slices This prevents timing attacks when comparing sensitive data like tokens or keys

func ConstantTimeEqual

func ConstantTimeEqual(a, b string) bool

ConstantTimeEqual performs a constant-time comparison of two strings

func CreateControllerTLSConfig

func CreateControllerTLSConfig(controllerCert *x509.Certificate) (*tls.Config, error)

CreateControllerTLSConfig creates a TLS config for controller connections

func CreateInsecureTLSConfig

func CreateInsecureTLSConfig() *tls.Config

CreateInsecureTLSConfig creates a TLS config that skips certificate verification This is used when we need to make an insecure connection to get a new certificate

func CreateRouterTLSConfig

func CreateRouterTLSConfig(routerCert *x509.Certificate) (*tls.Config, error)

CreateRouterTLSConfig creates a TLS config for router connections

func CreateTLSConfigWithClientCerts

func CreateTLSConfigWithClientCerts(caCert *x509.Certificate, tlsCert []byte, tlsKey []byte) (*tls.Config, error)

CreateTLSConfigWithClientCerts creates a TLS config with client certificates

func CreateWebSocketTLSConfig

func CreateWebSocketTLSConfig(webSocketCert *x509.Certificate) (*tls.Config, error)

CreateWebSocketTLSConfig creates a TLS config for websocket connections

func EdgeGuardHashFromJWT

func EdgeGuardHashFromJWT(tokenString string) (string, error)

EdgeGuardHashFromJWT returns the hardware fingerprint hash claim from a stored Edge Guard JWT. Comparison must use this stable hash, not the full JWT string (iat/exp/jti change every signing).

func EdgeletAPIAuthMiddleware

func EdgeletAPIAuthMiddleware(next http.Handler) http.Handler

EdgeletAPIAuthMiddleware creates middleware for validating local API tokens

func EdgeletAPIPKIPaths

func EdgeletAPIPKIPaths() (caPath, certPath, keyPath string)

func EnsureEdgeletAPIPKI

func EnsureEdgeletAPIPKI() (string, string, string, error)

func EnsureEdgeletAPITokenForCurrentState

func EnsureEdgeletAPITokenForCurrentState() error

EnsureEdgeletAPITokenForCurrentState reconciles /etc/edgelet/edgelet-api token contents. - Unprovisioned: unsigned bootstrap JWT - Provisioned: signed Ed25519 JWT

func GenerateBootstrapEdgeletAPIJWT

func GenerateBootstrapEdgeletAPIJWT(ttl time.Duration) (string, error)

GenerateBootstrapEdgeletAPIJWT creates an unsigned JWT for unprovisioned bootstrap mode.

func GenerateSecureRandomBytes

func GenerateSecureRandomBytes(size int) ([]byte, error)

GenerateSecureRandomBytes generates cryptographically secure random bytes

func GenerateSecureRandomString

func GenerateSecureRandomString(size int) (string, error)

GenerateSecureRandomString generates a cryptographically secure random string

func GenerateToken

func GenerateToken() (string, error)

GenerateToken generates a secure random token

func GetProvisionedPublicKey

func GetProvisionedPublicKey() string

GetProvisionedPublicKey returns the base64url public key from provisioned JWK.

func LoadCertificateFromBase64

func LoadCertificateFromBase64(base64Data string) (*x509.Certificate, error)

LoadCertificateFromBase64 loads a certificate from base64-encoded PEM data

func LoadCertificateFromPEM

func LoadCertificateFromPEM(pemData []byte) (*x509.Certificate, error)

LoadCertificateFromPEM loads a certificate from PEM-encoded data

func LoadCertificatesFromDirectory

func LoadCertificatesFromDirectory(dirPath string) ([]*x509.Certificate, error)

LoadCertificatesFromDirectory loads all certificates from a directory

func LoadCertificatesFromFile

func LoadCertificatesFromFile(filePath string) ([]*x509.Certificate, error)

LoadCertificatesFromFile loads certificates from a file

func LoadCertificatesFromPEM

func LoadCertificatesFromPEM(pemData []byte) ([]*x509.Certificate, error)

LoadCertificatesFromPEM loads multiple certificates from PEM-encoded data

func LoadControllerCertFromConfig

func LoadControllerCertFromConfig(value string) (*x509.Certificate, error)

LoadControllerCertFromConfig loads the first controller trust certificate from a config value. Prefer LoadControllerCertsFromConfig for TLS trust pools.

func LoadControllerCertsFromConfig

func LoadControllerCertsFromConfig(value string) ([]*x509.Certificate, error)

LoadControllerCertsFromConfig loads all controller trust anchors from a config value that may be a file path, base64-encoded PEM bundle, or inline PEM.

func LoadControllerTrustForTLS

func LoadControllerTrustForTLS(configuredPath string) ([]*x509.Certificate, error)

LoadControllerTrustForTLS loads controller trust material for BuildControllerDialTLSConfig. When configuredPath is empty, no error is returned. When the path is set but loading fails, a *ControllerTrustLoadError is returned (caller may fall back to OS trust).

func ReadEdgeletAPICACertPEM

func ReadEdgeletAPICACertPEM() ([]byte, error)

func SecureHash

func SecureHash(data []byte) ([]byte, error)

SecureHash generates a secure hash of data (placeholder for future implementation) This can be extended to use specific hash functions if needed

func ShouldRotateByLifetime

func ShouldRotateByLifetime(iat, exp int64, now time.Time) bool

ShouldRotateByLifetime applies token rotation trigger policy: rotate when remaining lifetime is <=20% of TTL, capped by a max lead window.

func ShouldRotateEdgeletAPIToken

func ShouldRotateEdgeletAPIToken(tokenString string, now time.Time) (bool, error)

ShouldRotateEdgeletAPIToken returns true when token should be rotated according to token lifetime policy.

func TokenSHA256

func TokenSHA256(token string) string

TokenSHA256 computes the stable hash used for persisted token metadata.

func ValidateAccessToken

func ValidateAccessToken(token string) bool

ValidateAccessToken is a helper function to validate access tokens

func ValidateCertificateChain

func ValidateCertificateChain(certs []*x509.Certificate, trustStore *TrustStore) error

ValidateCertificateChain validates a certificate chain against a trust store

Types

type CombinedTrustManager

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

CombinedTrustManager implements a custom X509TrustManager that validates against both system and custom certificates

func (*CombinedTrustManager) VerifyPeerCertificate

func (ctm *CombinedTrustManager) VerifyPeerCertificate(rawCerts [][]byte, _ [][]*x509.Certificate) error

VerifyPeerCertificate validates a certificate chain

type ControllerTrustLoadError

type ControllerTrustLoadError struct {
	Path string
	Err  error
}

ControllerTrustLoadError indicates configured controllerCert could not be loaded.

func (*ControllerTrustLoadError) Error

func (e *ControllerTrustLoadError) Error() string

func (*ControllerTrustLoadError) Unwrap

func (e *ControllerTrustLoadError) Unwrap() error

type JWK

type JWK struct {
	Kty string `json:"kty"` // Key type (must be "OKP")
	Crv string `json:"crv"` // Curve (must be "Ed25519")
	Kid string `json:"kid"` // Key ID (optional)
	D   string `json:"d"`   // Private key (base64url encoded)
	X   string `json:"x"`   // Public key (base64url encoded, optional for private key)
}

JWK represents a JSON Web Key structure

type JWTManager

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

JWTManager handles JWT token generation and validation

func GetJWTManager

func GetJWTManager() *JWTManager

GetInstance returns the singleton JWT manager instance

func (*JWTManager) GenerateControllerJWT

func (j *JWTManager) GenerateControllerJWT(controllerAudience string, ttl time.Duration) (string, string, int64, int64, error)

GenerateControllerJWT creates a signed JWT for controller communication.

func (*JWTManager) GenerateEdgeGuardJWT

func (j *JWTManager) GenerateEdgeGuardJWT(hash string, ttl time.Duration) (string, string, int64, int64, error)

GenerateEdgeGuardJWT creates a dedicated JWT for edgeguard attestation payloads.

func (*JWTManager) GenerateEdgeletAPITokenJWT

func (j *JWTManager) GenerateEdgeletAPITokenJWT(subject string, ttl time.Duration, extraClaims map[string]any) (string, string, int64, int64, error)

GenerateEdgeletAPITokenJWT creates a provisioned local admin token.

func (*JWTManager) GenerateJWT

func (j *JWTManager) GenerateJWT() (string, error)

GenerateJWT generates a controller-auth JWT token with the configured private key. Kept as compatibility wrapper for existing controller paths.

func (*JWTManager) GenerateServiceAccountJWT

func (j *JWTManager) GenerateServiceAccountJWT(subject string, ttl time.Duration, extraClaims map[string]any) (string, string, int64, int64, error)

GenerateServiceAccountJWT creates a signed JWT for a managed microservice service-account identity.

func (*JWTManager) Reset

func (j *JWTManager) Reset()

Reset resets the JWT Manager state to allow re-initialization with new credentials

func (*JWTManager) ValidateJWT

func (j *JWTManager) ValidateJWT(tokenString string) (*jwt.Token, error)

ValidateJWT validates a JWT token using the public key derived from the private key

type LocalJWTValidationResult

type LocalJWTValidationResult struct {
	Claims jwt.MapClaims
	Alg    string
}

LocalJWTValidationResult captures parsed/validated token metadata.

func ValidateEdgeletAPIJWT

func ValidateEdgeletAPIJWT(tokenString string) (*LocalJWTValidationResult, error)

ValidateEdgeletAPIJWT validates EdgeletAPI JWTs according to agent state: - unprovisioned: unsigned bootstrap JWTs are accepted - provisioned: unsigned JWTs are rejected and signed JWT is required

type LocalTokenManager

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

LocalTokenManager manages local API tokens

func GetLocalTokenManager

func GetLocalTokenManager() *LocalTokenManager

GetLocalTokenManager returns the singleton local token manager instance

func (*LocalTokenManager) GenerateAndSaveToken

func (ltm *LocalTokenManager) GenerateAndSaveToken() (string, error)

GenerateAndSaveToken generates a new token and saves it to the file

func (*LocalTokenManager) LoadToken

func (ltm *LocalTokenManager) LoadToken() (string, error)

LoadToken loads the token from the file

func (*LocalTokenManager) Reset

func (ltm *LocalTokenManager) Reset()

Reset clears the cached token (forces reload from file)

func (*LocalTokenManager) SaveToken

func (ltm *LocalTokenManager) SaveToken(token string) error

SaveToken saves a token to the file

func (*LocalTokenManager) ValidateToken

func (ltm *LocalTokenManager) ValidateToken(providedToken string) bool

ValidateToken validates a token against the stored token using constant-time comparison

type TrustStore

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

TrustStore manages certificate trust stores

func NewTrustStore

func NewTrustStore() *TrustStore

NewTrustStore creates a new trust store

func (*TrustStore) AddCertificate

func (ts *TrustStore) AddCertificate(cert *x509.Certificate)

AddCertificate adds a certificate to the trust store

func (*TrustStore) CreateCombinedTrustManager

func (ts *TrustStore) CreateCombinedTrustManager() *CombinedTrustManager

CreateCombinedTrustManager creates a combined trust manager that validates against both system certificates and custom certificates

Jump to

Keyboard shortcuts

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