Documentation
¶
Overview ¶
Package postgres provides a PostgreSQL implementation of the Warden composite store using grove ORM with Go-based migrations.
Index ¶
- Variables
- type Option
- type Store
- func (s *Store) AttachPermission(ctx context.Context, tenantID string, roleID id.RoleID, ref permission.Ref) error
- func (s *Store) CheckDirectRelation(ctx context.Context, tenantID string, namespacePaths []string, ...) (bool, error)
- func (s *Store) Close() error
- func (s *Store) CountAssignments(ctx context.Context, filter *assignment.ListFilter) (int64, error)
- func (s *Store) CountCheckLogs(ctx context.Context, filter *checklog.QueryFilter) (int64, error)
- func (s *Store) CountPermissions(ctx context.Context, filter *permission.ListFilter) (int64, error)
- func (s *Store) CountPolicies(ctx context.Context, filter *policy.ListFilter) (int64, error)
- func (s *Store) CountRelations(ctx context.Context, filter *relation.ListFilter) (int64, error)
- func (s *Store) CountResourceTypes(ctx context.Context, filter *resourcetype.ListFilter) (int64, error)
- func (s *Store) CountRoles(ctx context.Context, filter *role.ListFilter) (int64, error)
- func (s *Store) CreateAssignment(ctx context.Context, a *assignment.Assignment) error
- func (s *Store) CreateCheckLog(ctx context.Context, e *checklog.Entry) error
- func (s *Store) CreatePermission(ctx context.Context, p *permission.Permission) error
- func (s *Store) CreatePolicy(ctx context.Context, p *policy.Policy) error
- func (s *Store) CreateRelation(ctx context.Context, t *relation.Tuple) error
- func (s *Store) CreateResourceType(ctx context.Context, rt *resourcetype.ResourceType) error
- func (s *Store) CreateRole(ctx context.Context, r *role.Role) error
- func (s *Store) DeleteAssignment(ctx context.Context, tenantID string, assID id.AssignmentID) error
- func (s *Store) DeleteAssignmentsByRole(ctx context.Context, tenantID string, roleID id.RoleID) error
- func (s *Store) DeleteAssignmentsBySubject(ctx context.Context, tenantID, subjectKind, subjectID string) error
- func (s *Store) DeleteAssignmentsByTenant(ctx context.Context, tenantID string) error
- func (s *Store) DeleteCheckLogsBySubject(ctx context.Context, tenantID, subjectKind, subjectID string) (int64, error)
- func (s *Store) DeleteCheckLogsByTenant(ctx context.Context, tenantID string) error
- func (s *Store) DeleteExpiredAssignments(ctx context.Context, now time.Time) (int64, error)
- func (s *Store) DeleteExpiredAssignmentsForTenant(ctx context.Context, tenantID string, now time.Time) (int64, error)
- func (s *Store) DeletePermission(ctx context.Context, tenantID string, permID id.PermissionID) error
- func (s *Store) DeletePermissionsByTenant(ctx context.Context, tenantID string) error
- func (s *Store) DeletePoliciesByTenant(ctx context.Context, tenantID string) error
- func (s *Store) DeletePolicy(ctx context.Context, tenantID string, polID id.PolicyID) error
- func (s *Store) DeleteRelation(ctx context.Context, tenantID string, relID id.RelationID) error
- func (s *Store) DeleteRelationTuple(ctx context.Context, ...) error
- func (s *Store) DeleteRelationsByObject(ctx context.Context, tenantID, objectType, objectID string) error
- func (s *Store) DeleteRelationsBySubject(ctx context.Context, tenantID, subjectType, subjectID string) error
- func (s *Store) DeleteRelationsByTenant(ctx context.Context, tenantID string) error
- func (s *Store) DeleteResourceType(ctx context.Context, tenantID string, rtID id.ResourceTypeID) error
- func (s *Store) DeleteResourceTypesByTenant(ctx context.Context, tenantID string) error
- func (s *Store) DeleteRole(ctx context.Context, tenantID string, roleID id.RoleID) error
- func (s *Store) DeleteRolesByTenant(ctx context.Context, tenantID string) error
- func (s *Store) DetachPermission(ctx context.Context, tenantID string, roleID id.RoleID, ref permission.Ref) error
- func (s *Store) GetAssignment(ctx context.Context, tenantID string, assID id.AssignmentID) (*assignment.Assignment, error)
- func (s *Store) GetCheckLog(ctx context.Context, tenantID string, logID id.CheckLogID) (*checklog.Entry, error)
- func (s *Store) GetPermission(ctx context.Context, tenantID string, permID id.PermissionID) (*permission.Permission, error)
- func (s *Store) GetPermissionByName(ctx context.Context, tenantID, namespacePath, name string) (*permission.Permission, error)
- func (s *Store) GetPolicy(ctx context.Context, tenantID string, polID id.PolicyID) (*policy.Policy, error)
- func (s *Store) GetPolicyByName(ctx context.Context, tenantID, namespacePath, name string) (*policy.Policy, error)
- func (s *Store) GetRelation(ctx context.Context, tenantID string, relID id.RelationID) (*relation.Tuple, error)
- func (s *Store) GetResourceType(ctx context.Context, tenantID string, rtID id.ResourceTypeID) (*resourcetype.ResourceType, error)
- func (s *Store) GetResourceTypeByName(ctx context.Context, tenantID, namespacePath, name string) (*resourcetype.ResourceType, error)
- func (s *Store) GetRole(ctx context.Context, tenantID string, roleID id.RoleID) (*role.Role, error)
- func (s *Store) GetRoleBySlug(ctx context.Context, tenantID, namespacePath, slug string) (*role.Role, error)
- func (s *Store) GetRoles(ctx context.Context, tenantID string, roleIDs []id.RoleID) ([]*role.Role, error)
- func (s *Store) ListActivePolicies(ctx context.Context, tenantID string, namespacePaths []string) ([]*policy.Policy, error)
- func (s *Store) ListAssignments(ctx context.Context, filter *assignment.ListFilter) ([]*assignment.Assignment, error)
- func (s *Store) ListCheckLogs(ctx context.Context, filter *checklog.QueryFilter) ([]*checklog.Entry, error)
- func (s *Store) ListChildRoles(ctx context.Context, tenantID, parentSlug string) ([]*role.Role, error)
- func (s *Store) ListExpiringAssignments(ctx context.Context, tenantID string, before time.Time, limit int) ([]*assignment.Assignment, error)
- func (s *Store) ListPermissions(ctx context.Context, filter *permission.ListFilter) ([]*permission.Permission, error)
- func (s *Store) ListPermissionsByRole(ctx context.Context, tenantID string, roleID id.RoleID) ([]*permission.Permission, error)
- func (s *Store) ListPermissionsBySubject(ctx context.Context, tenantID, subjectKind, subjectID string) ([]*permission.Permission, error)
- func (s *Store) ListPolicies(ctx context.Context, filter *policy.ListFilter) ([]*policy.Policy, error)
- func (s *Store) ListRelationObjects(ctx context.Context, ...) ([]*relation.Tuple, error)
- func (s *Store) ListRelationSubjects(ctx context.Context, tenantID string, namespacePaths []string, ...) ([]*relation.Tuple, error)
- func (s *Store) ListRelations(ctx context.Context, filter *relation.ListFilter) ([]*relation.Tuple, error)
- func (s *Store) ListResourceTypes(ctx context.Context, filter *resourcetype.ListFilter) ([]*resourcetype.ResourceType, error)
- func (s *Store) ListRolePermissions(ctx context.Context, tenantID string, roleID id.RoleID) ([]*permission.Permission, error)
- func (s *Store) ListRolePermissionsForRoles(ctx context.Context, tenantID string, roleIDs []id.RoleID) (map[id.RoleID][]*permission.Permission, error)
- func (s *Store) ListRoles(ctx context.Context, filter *role.ListFilter) ([]*role.Role, error)
- func (s *Store) ListRolesForSubject(ctx context.Context, tenantID string, namespacePaths []string, ...) ([]id.RoleID, error)
- func (s *Store) ListRolesForSubjectOnResource(ctx context.Context, tenantID string, namespacePaths []string, ...) ([]id.RoleID, error)
- func (s *Store) ListSubjectsForRole(ctx context.Context, tenantID string, roleID id.RoleID) ([]*assignment.Assignment, error)
- func (s *Store) Migrate(ctx context.Context) error
- func (s *Store) Ping(ctx context.Context) error
- func (s *Store) PurgeCheckLogs(ctx context.Context, before time.Time) (int64, error)
- func (s *Store) PurgeCheckLogsForTenant(ctx context.Context, tenantID string, before time.Time) (int64, error)
- func (s *Store) SetPolicyVersion(ctx context.Context, tenantID string, polID id.PolicyID, version int) error
- func (s *Store) SetRolePermissions(ctx context.Context, tenantID string, roleID id.RoleID, refs []permission.Ref) error
- func (s *Store) UpdatePermission(ctx context.Context, p *permission.Permission) error
- func (s *Store) UpdatePolicy(ctx context.Context, p *policy.Policy) error
- func (s *Store) UpdatePolicyIfVersion(ctx context.Context, p *policy.Policy, expected int) error
- func (s *Store) UpdateResourceType(ctx context.Context, rt *resourcetype.ResourceType) error
- func (s *Store) UpdateRole(ctx context.Context, r *role.Role) error
Constants ¶
This section is empty.
Variables ¶
var Migrations = migrate.NewGroup("warden")
Migrations is the grove migration group for the Warden store. It can be registered with the grove extension for orchestrated migration management (locking, version tracking, rollback support).
Functions ¶
This section is empty.
Types ¶
type Option ¶ added in v1.7.0
type Option func(*storeConfig)
Option configures a Store at construction time.
func WithStatementTimeout ¶ added in v1.7.0
WithStatementTimeout returns an Option that caps how long a single statement may run on Postgres before the server cancels it (statement_timeout), so a runaway query can't hold a connection forever.
Grove's pgdriver (v1.6.3) builds its pgxpool.Config from the DSN and doesn't expose pgxpool's AfterConnect hook through a driver.Option, so there is no way to guarantee every connection the pool ever opens picks this up. Store applies it as a session-level SET on the connection it acquires immediately at construction (best-effort, useful for a single-connection pool, or as a default before traffic arrives). For a setting that reliably reaches every connection the pool opens, prefer the DSN's `options` startup parameter instead, which pgx applies at connect time for every physical connection:
postgres://user:pass@host/db?options=-c%20statement_timeout%3D5000
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a PostgreSQL implementation of the composite Warden store.
func New ¶
New creates a new PostgreSQL store. See WithStatementTimeout for the caveats of setting statement_timeout after the pool already exists.
func (*Store) AttachPermission ¶
func (*Store) CheckDirectRelation ¶
func (*Store) CountAssignments ¶
func (s *Store) CountAssignments(ctx context.Context, filter *assignment.ListFilter) (int64, error)
func (*Store) CountCheckLogs ¶
func (*Store) CountPermissions ¶
func (s *Store) CountPermissions(ctx context.Context, filter *permission.ListFilter) (int64, error)
func (*Store) CountPolicies ¶
func (*Store) CountRelations ¶
func (*Store) CountResourceTypes ¶
func (s *Store) CountResourceTypes(ctx context.Context, filter *resourcetype.ListFilter) (int64, error)
func (*Store) CountRoles ¶
func (*Store) CreateAssignment ¶
func (s *Store) CreateAssignment(ctx context.Context, a *assignment.Assignment) error
func (*Store) CreateCheckLog ¶
func (*Store) CreatePermission ¶
func (s *Store) CreatePermission(ctx context.Context, p *permission.Permission) error
func (*Store) CreatePolicy ¶
func (*Store) CreateRelation ¶
func (*Store) CreateResourceType ¶
func (s *Store) CreateResourceType(ctx context.Context, rt *resourcetype.ResourceType) error
func (*Store) DeleteAssignment ¶
func (*Store) DeleteAssignmentsByRole ¶
func (*Store) DeleteAssignmentsBySubject ¶
func (*Store) DeleteAssignmentsByTenant ¶
func (*Store) DeleteCheckLogsBySubject ¶ added in v1.7.0
func (*Store) DeleteCheckLogsByTenant ¶
func (*Store) DeleteExpiredAssignments ¶
func (*Store) DeleteExpiredAssignmentsForTenant ¶ added in v1.7.0
func (*Store) DeletePermission ¶
func (*Store) DeletePermissionsByTenant ¶
func (*Store) DeletePoliciesByTenant ¶
func (*Store) DeletePolicy ¶
func (*Store) DeleteRelation ¶
func (*Store) DeleteRelationTuple ¶
func (*Store) DeleteRelationsByObject ¶
func (*Store) DeleteRelationsBySubject ¶
func (*Store) DeleteRelationsByTenant ¶
func (*Store) DeleteResourceType ¶
func (*Store) DeleteResourceTypesByTenant ¶
func (*Store) DeleteRole ¶
DeleteRole removes a role. Assignments and grants go with it via the foreign-key cascades in the schema.
func (*Store) DeleteRolesByTenant ¶
func (*Store) DetachPermission ¶
func (*Store) GetAssignment ¶
func (s *Store) GetAssignment(ctx context.Context, tenantID string, assID id.AssignmentID) (*assignment.Assignment, error)
func (*Store) GetCheckLog ¶
func (*Store) GetPermission ¶
func (s *Store) GetPermission(ctx context.Context, tenantID string, permID id.PermissionID) (*permission.Permission, error)
func (*Store) GetPermissionByName ¶
func (s *Store) GetPermissionByName(ctx context.Context, tenantID, namespacePath, name string) (*permission.Permission, error)
func (*Store) GetPolicyByName ¶
func (*Store) GetRelation ¶ added in v1.7.0
func (*Store) GetResourceType ¶
func (s *Store) GetResourceType(ctx context.Context, tenantID string, rtID id.ResourceTypeID) (*resourcetype.ResourceType, error)
func (*Store) GetResourceTypeByName ¶
func (s *Store) GetResourceTypeByName(ctx context.Context, tenantID, namespacePath, name string) (*resourcetype.ResourceType, error)
func (*Store) GetRoleBySlug ¶
func (*Store) ListActivePolicies ¶
func (*Store) ListAssignments ¶
func (s *Store) ListAssignments(ctx context.Context, filter *assignment.ListFilter) ([]*assignment.Assignment, error)
func (*Store) ListCheckLogs ¶
func (*Store) ListChildRoles ¶
func (*Store) ListExpiringAssignments ¶ added in v1.7.0
func (s *Store) ListExpiringAssignments(ctx context.Context, tenantID string, before time.Time, limit int) ([]*assignment.Assignment, error)
func (*Store) ListPermissions ¶
func (s *Store) ListPermissions(ctx context.Context, filter *permission.ListFilter) ([]*permission.Permission, error)
func (*Store) ListPermissionsByRole ¶
func (s *Store) ListPermissionsByRole(ctx context.Context, tenantID string, roleID id.RoleID) ([]*permission.Permission, error)
func (*Store) ListPermissionsBySubject ¶
func (s *Store) ListPermissionsBySubject(ctx context.Context, tenantID, subjectKind, subjectID string) ([]*permission.Permission, error)
func (*Store) ListPolicies ¶
func (*Store) ListRelationObjects ¶
func (*Store) ListRelationSubjects ¶
func (*Store) ListRelations ¶
func (*Store) ListResourceTypes ¶
func (s *Store) ListResourceTypes(ctx context.Context, filter *resourcetype.ListFilter) ([]*resourcetype.ResourceType, error)
func (*Store) ListRolePermissions ¶
func (s *Store) ListRolePermissions(ctx context.Context, tenantID string, roleID id.RoleID) ([]*permission.Permission, error)
func (*Store) ListRolePermissionsForRoles ¶ added in v1.7.0
func (*Store) ListRolesForSubject ¶
func (*Store) ListRolesForSubjectOnResource ¶
func (*Store) ListSubjectsForRole ¶
func (s *Store) ListSubjectsForRole(ctx context.Context, tenantID string, roleID id.RoleID) ([]*assignment.Assignment, error)
func (*Store) PurgeCheckLogs ¶
func (*Store) PurgeCheckLogsForTenant ¶ added in v1.7.0
func (s *Store) PurgeCheckLogsForTenant(ctx context.Context, tenantID string, before time.Time) (int64, error)
PurgeCheckLogsForTenant is a DELETE, which warden_check_logs allows: its append-only trigger refuses UPDATE only.
func (*Store) SetPolicyVersion ¶
func (*Store) SetRolePermissions ¶
func (*Store) UpdatePermission ¶
func (s *Store) UpdatePermission(ctx context.Context, p *permission.Permission) error
func (*Store) UpdatePolicy ¶
func (*Store) UpdatePolicyIfVersion ¶ added in v1.7.0
UpdatePolicyIfVersion writes p as UpdatePolicy does, only if the stored policy is at version expected. The version check is part of the UPDATE's WHERE clause, so the comparison and the write are one statement: under READ COMMITTED a second writer blocks on the row lock, then re-checks the WHERE against the committed row and matches nothing. When no row changes, a read picks the error: not found if the policy is absent from p's tenant, a version conflict otherwise. That read only chooses the error; the refusal itself was atomic.
p.UpdatedAt is set only once the write has happened, so a refused caller's struct does not claim a write that did not happen.
func (*Store) UpdateResourceType ¶
func (s *Store) UpdateResourceType(ctx context.Context, rt *resourcetype.ResourceType) error