Documentation
¶
Overview ¶
Package graphlock serializes the transactions that remove relationships from the authorization graph with the graph reconciler's repairs.
A revocation removes the relationship from the graph inside the transaction that changes the database, after the database change and before the commit, holding the lock of every principal and organization whose relationships it removes. The reconciler (authz/mode) writes a missing relationship back only in a transaction holding the same locks, after reading the rows again. Whichever runs second sees the other's result: the reconciler cannot restore a relationship a revocation is removing, and a revocation cannot be undone by a repair already under way.
The locks are PostgreSQL transaction-scoped advisory locks, released when the transaction ends. SQLite has no advisory locks; Lock does nothing there, so the guarantee needs PostgreSQL.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Grant ¶
func Grant(ctx context.Context, client *ent.Client, keys []string, write func(ctx context.Context, c *ent.Client) error) (err error)
Grant writes to the graph the access a committed change granted, without undoing a revocation that committed since. It runs write in a transaction holding the locks named by keys; write reads the rows again through c, the transaction's client, and writes only the relationships they still call for (package identity/graphstate). A revocation holding one of the locks finishes first, so write sees its result; one that starts later waits for write, and removes what it wrote.
The transaction only reads and is rolled back when write returns. Grant returns write's error, joined with a failure to end the transaction. Lock it with the same keys as the reconciler's repair of the relationship: the organization and the principal for a relationship on an organization, its facet or a resource in it, the principal alone for platform administration, and both principals for a manager relation.
func Lock ¶
Lock takes the transaction-scoped locks named by keys, in sorted order so that two transactions locking overlapping sets cannot deadlock. The locks are held until tx commits or rolls back. On SQLite it does nothing.
func Organization ¶
Organization is the lock key of an organization's relationships.
Types ¶
This section is empty.