Authorization
Roles, permissions and the optional adapters that back them.
Signet provides the authorization vocabulary; your application owns the state through optional adapters. Nothing here is required unless you enable it.
type Authorizer interface {
Roles(context.Context, string) []string
Authorize(ctx context.Context, userID, resource, action string) bool
}
type RoleWriter interface {
SetRoles(context.Context, string, []string) error
}
type AuthorizeIn interface {
AuthorizeIn(ctx context.Context, userID, orgID, resource, action string) bool
}Register them on Config. With no Authorizer, every check denies. Client.Authorize is the
public read-only check; Client.SetRoles writes global roles through the RoleWriter. The optional
AuthorizeIn extension supports organization-scoped checks; supply it via cfg.AuthorizeIn and
read it with Client.AuthorizeIn. It does not change the base Authorizer contract.
Built-in in-memory authorizer
For applications whose roles are simple strings, NewMemoryAuthorizer builds a read-only
Authorizer from RoleStatements and a callback that supplies a User's roles:
authz := signet.NewMemoryAuthorizer(
signet.RoleStatements{
"admin": {signet.PermissionUsersBan, signet.PermissionUsersSetRole},
},
func(ctx context.Context, userID string) []string {
return myStore.RolesFor(ctx, userID)
},
)
cfg.Authorizer = authzStatements are exact grants — a permission is allowed only if a role explicitly lists it. No
wildcard expansion is performed. For dynamic or database-backed rules, implement Authorizer
yourself instead.
A Permission is an exact resource:action string. Signet publishes the strings it checks:
PermissionUsersBan (users:ban), PermissionUsersSetRole (users:set-role),
PermissionUsersImpersonate (users:impersonate), PermissionSessionsRevoke (sessions:revoke),
PermissionAPIKeysCreate (api-keys:create), PermissionAPIKeysRevoke (api-keys:revoke),
PermissionOrgsCreate (organizations:create), PermissionOrgsMemberAdd (organizations:member-add),
PermissionOrgsMemberRemove (organizations:member-remove) and PermissionOrgsMemberRole
(organizations:member-role). No wildcard expansion is performed. Denials return ErrForbidden
with wire code forbidden (403), and guarded actions emit an Audit event with outcome: denied.
Read-only listing requires a valid Session plus a grant, but no separate "list" permission is
published: listings reuse the related write permission (organizations:create to list
Organizations, organizations:member-add to list Members, users:ban to list Users and
sessions:revoke to list Sessions). Applications never invent permission strings.