Package: console
The console package provides helpers useful across the service.
Functions
principalFromRHIdentity(identity:dict | object,domain?:string) :SubjectReferenceBuilds a principal SubjectReference from a parsed platform identity object.
This function eliminates the need for consumers to manually inspect identity types, extract user IDs, and construct subject references. It accepts the inner identity dict/object from the
x-rh-identityheader and handles the resolution internally.Supported identity types:
Type Accepted fields Useruser.user_idServiceAccountservice_account.user_idUnsupported types (
System,X509,Associate) raise an error. The resolved user ID is combined with thedomainto produce a resource ID of the form{domain}/{userId}(e.g.redhat/7393748), which is passed to principalSubject.Example:
from kessel.console import principalFromRHIdentity # User identity (e.g. from request.auth in Django, or Identity object) identity = { "type": "User", "org_id": "12345", "user": {"user_id": "7393748", "username": "jdoe"} } subject = principalFromRHIdentity(identity) # ServiceAccount identity sa_identity = { "type": "ServiceAccount", "org_id": "456", "service_account": { "user_id": "2647318", "username": "service-account-2647318" } } subject = principalFromRHIdentity(sa_identity)identity:dict | objectThe inner identity dict/object from the
x-rh-identityheader (e.g.{"type": "User", "org_id": "...", "user": {...}}). This is the parsed identity — not the full{"identity": {...}}envelope and not the raw base64 string. Use principalFromRHIdentityHeader if you have the raw header.domain?:stringThe domain or organization the user belongs to. Defaults to
"redhat".
principalFromRHIdentityHeader(header:string,domain?:string) :SubjectReferenceBuilds a principal SubjectReference from a raw base64-encoded
x-rh-identityheader.Example:
from kessel.console import principalFromRHIdentityHeader # Directly from the HTTP header header = request.headers["x-rh-identity"] subject = principalFromRHIdentityHeader(header) # Use in a permission check checkResponse = checkClient.check( resource=workspaceResource(workspaceId), permission="workspace_view", subject=subject, )header:stringThe base64-encoded
x-rh-identityheader value.domain?:stringThe domain or organization the user belongs to. Defaults to
"redhat".