Documentation
¶
Index ¶
- func BuildControllerDialTLSConfig(secureMode bool, configuredPath string, customCerts []*x509.Certificate, ...) *tls.Config
- func CertPoolFromCertificates(certs []*x509.Certificate) *x509.CertPool
- func ConstantTimeCompare(a, b []byte) bool
- func ConstantTimeEqual(a, b string) bool
- func CreateControllerTLSConfig(controllerCert *x509.Certificate) (*tls.Config, error)
- func CreateInsecureTLSConfig() *tls.Config
- func CreateRouterTLSConfig(routerCert *x509.Certificate) (*tls.Config, error)
- func CreateTLSConfigWithClientCerts(caCert *x509.Certificate, tlsCert []byte, tlsKey []byte) (*tls.Config, error)
- func CreateWebSocketTLSConfig(webSocketCert *x509.Certificate) (*tls.Config, error)
- func EdgeGuardHashFromJWT(tokenString string) (string, error)
- func EdgeletAPIAuthMiddleware(next http.Handler) http.Handler
- func EdgeletAPIPKIPaths() (caPath, certPath, keyPath string)
- func EnsureEdgeletAPIPKI() (string, string, string, error)
- func EnsureEdgeletAPITokenForCurrentState() error
- func GenerateBootstrapEdgeletAPIJWT(ttl time.Duration) (string, error)
- func GenerateSecureRandomBytes(size int) ([]byte, error)
- func GenerateSecureRandomString(size int) (string, error)
- func GenerateToken() (string, error)
- func GetProvisionedPublicKey() string
- func LoadCertificateFromBase64(base64Data string) (*x509.Certificate, error)
- func LoadCertificateFromPEM(pemData []byte) (*x509.Certificate, error)
- func LoadCertificatesFromDirectory(dirPath string) ([]*x509.Certificate, error)
- func LoadCertificatesFromFile(filePath string) ([]*x509.Certificate, error)
- func LoadCertificatesFromPEM(pemData []byte) ([]*x509.Certificate, error)
- func LoadControllerCertFromConfig(value string) (*x509.Certificate, error)
- func LoadControllerCertsFromConfig(value string) ([]*x509.Certificate, error)
- func LoadControllerTrustForTLS(configuredPath string) ([]*x509.Certificate, error)
- func ProvisionedPublicJWKJSON() ([]byte, error)
- func ReadEdgeletAPICACertPEM() ([]byte, error)
- func SecureHash(data []byte) ([]byte, error)
- func ShouldRotateByLifetime(iat, exp int64, now time.Time) bool
- func ShouldRotateEdgeletAPIToken(tokenString string, now time.Time) (bool, error)
- func TokenSHA256(token string) string
- func ValidateAccessToken(token string) bool
- func ValidateCertificateChain(certs []*x509.Certificate, trustStore *TrustStore) error
- type CombinedTrustManager
- type ControllerTrustLoadError
- type EdgeGuardLink
- type JWK
- type JWTManager
- func (j *JWTManager) GenerateControllerJWT(controllerAudience string, ttl time.Duration) (string, string, int64, int64, error)
- func (j *JWTManager) GenerateEdgeGuardJWT(hash string, links []EdgeGuardLink, ttl time.Duration) (string, string, int64, int64, error)
- func (j *JWTManager) GenerateEdgeletAPITokenJWT(subject string, ttl time.Duration, extraClaims map[string]any) (string, string, int64, int64, error)
- func (j *JWTManager) GenerateJWT() (string, error)
- func (j *JWTManager) GenerateServiceAccountJWT(subject string, ttl time.Duration, extraClaims map[string]any) (string, string, int64, int64, error)
- func (j *JWTManager) Reset()
- func (j *JWTManager) ValidateJWT(tokenString string) (*jwt.Token, error)
- type LocalJWTValidationResult
- type LocalTokenManager
- type TrustStore
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 ¶
ConstantTimeCompare performs a constant-time comparison of two byte slices This prevents timing attacks when comparing sensitive data like tokens or keys
func ConstantTimeEqual ¶
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 ¶
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 ¶
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 ¶
EdgeletAPIAuthMiddleware creates middleware for validating local API tokens
func EdgeletAPIPKIPaths ¶
func EdgeletAPIPKIPaths() (caPath, certPath, keyPath string)
func EnsureEdgeletAPITokenForCurrentState ¶
func EnsureEdgeletAPITokenForCurrentState() error
EnsureEdgeletAPITokenForCurrentState reconciles /etc/edgelet/edgelet-api token contents. - Unprovisioned: unsigned bootstrap JWT - Provisioned: signed Ed25519 JWT
func GenerateBootstrapEdgeletAPIJWT ¶
GenerateBootstrapEdgeletAPIJWT creates an unsigned JWT for unprovisioned bootstrap mode.
func GenerateSecureRandomBytes ¶
GenerateSecureRandomBytes generates cryptographically secure random bytes
func GenerateSecureRandomString ¶
GenerateSecureRandomString generates a cryptographically secure random string
func GenerateToken ¶
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 ProvisionedPublicJWKJSON ¶ added in v1.1.0
ProvisionedPublicJWKJSON returns the compact public-only signing JWK for projected workload verification (no private key material).
func ReadEdgeletAPICACertPEM ¶
func SecureHash ¶
SecureHash generates a secure hash of data (placeholder for future implementation) This can be extended to use specific hash functions if needed
func ShouldRotateByLifetime ¶
ShouldRotateByLifetime applies token rotation trigger policy: rotate when remaining lifetime is <=20% of TTL, capped by a max lead window.
func ShouldRotateEdgeletAPIToken ¶
ShouldRotateEdgeletAPIToken returns true when token should be rotated according to token lifetime policy.
func TokenSHA256 ¶
TokenSHA256 computes the stable hash used for persisted token metadata.
func ValidateAccessToken ¶
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 ¶
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 EdgeGuardLink ¶
type EdgeGuardLink struct {
Name string `json:"name"`
MAC string `json:"mac"`
LinkState string `json:"linkState"`
}
EdgeGuardLink is the locked link state of one NIC stored in the Edge Guard JWT. The identity hash does not include link state. This claim is the baseline used to tell a dark port becoming up from a locked-up port losing carrier.
func EdgeGuardLinksFromJWT ¶
func EdgeGuardLinksFromJWT(tokenString string) (links []EdgeGuardLink, present bool, err error)
EdgeGuardLinksFromJWT returns the locked NIC link states from a stored Edge Guard JWT. present is false when the token has no links claim, which is the pre-lock baseline.
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, links []EdgeGuardLink, ttl time.Duration) (string, string, int64, int64, error)
GenerateEdgeGuardJWT creates a dedicated JWT for edgeguard attestation payloads. A nil links slice omits the claim. A non-nil slice, including empty, stores the link lock.
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 ¶
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 (*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