Add MaxPermission constant (62) to make the valid bit range explicit in the API. Document in PermissionProvider that audit logging belongs in the application layer. API committed as stable: Identity, PermissionMask, context helpers, and PermissionProvider interface are unchanged from v0.9.0.
3.4 KiB
3.4 KiB
Changelog
All notable changes to this module will be documented in this file.
The format is based on Keep a Changelog, and this module adheres to Semantic Versioning.
1.0.0 — 2026-05-08
Added
MaxPermission Permission = 62— exported constant that makes the valid bit range explicit in the API; applications can use it in validation code and it is referenced in thePermissiontype godoc
Changed
Permissiontype godoc updated to referenceMaxPermissionand document that values outside[0, MaxPermission]are silently ignoredPermissionProvidergodoc updated to document that audit logging of permission checks is out of scope for this package — log denials and grants inside PermissionProvider implementations or in the middleware layer
Unchanged
Identity, PermissionMask (Has, Grant), context helpers (SetInContext, FromContext), and the PermissionProvider interface are API-compatible with v0.9.0.
0.9.0 - 2026-03-18
Added
Permission—int64type representing a named bit position (0–62) for a single capability; applications define their own constants using this typePermissionMask—int64type representing a resolved bit-set of capabilities for a user on a resourcePermissionMask.Has(p Permission) bool— O(1) check whether a permission bit is set; returns false for out-of-range values (p < 0 or p >= 63)PermissionMask.Grant(p Permission) PermissionMask— returns a new mask with the given bit set without mutating the receiver; silently ignores out-of-range valuesIdentity— value type (not a pointer) carryingUID,TenantID,DisplayName, andEmailfor an authenticated principalNewIdentity(uid, displayName, email string) Identity— constructs an Identity from token authentication data;TenantIDis intentionally left empty for later enrichmentIdentity.WithTenant(id string) Identity— returns a copy of the Identity withTenantIDset; does not mutate the receiver, safe for concurrent middleware useSetInContext(ctx context.Context, id Identity) context.Context— stores an Identity in a context using a private unexported key type to prevent collisionsFromContext(ctx context.Context) (Identity, bool)— retrieves the Identity stored bySetInContext; returns the zero-value Identity and false if no identity is presentPermissionProviderinterface —ResolveMask(ctx context.Context, uid, resource string) (PermissionMask, error)for DB-backed or in-memory permission resolution
Design Notes
Identityis a value type throughout — every enrichment call (e.g.WithTenant) returns a new copy, eliminating nil-pointer bugs and preventing accidental mutation of a shared context value across concurrent middleware.- Permissions are bit positions (0–62) packed into an
int64mask; applications define their own namedPermissionconstants — none are prescribed by this package — keeping the bit-set model flat and free of role-hierarchy complexity. - This package owns the context key for
Identityvia an unexportedauthContextKey{}struct, so any module that needs to carry an authenticated identity imports onlyrbac; zero micro-lib dependencies (stdlib only).