|
| 1 | += Permission Rules for Operations |
| 2 | + |
| 3 | + |
| 4 | +## Overview |
| 5 | + |
| 6 | +In Oxla, superusers can perform almost any operation, while object owners have broad privileges over their own objects. |
| 7 | +This document explains the logic behind operation permissions and the factors considered when determining whether a specific |
| 8 | +operation is allowed. |
| 9 | + |
| 10 | +## Classification of operations |
| 11 | + |
| 12 | +All operations that an Oxla client can perform fall into one of the following categories: |
| 13 | + |
| 14 | +* **Unavailable regardless of permissions**: operations that are never allowed |
| 15 | +* **Superusers-only**: operations restricted to superusers |
| 16 | +* **Owner-only**: operations allowed only for the object's owner |
| 17 | +* **Privilege-based:**: operations allowed for users with a specific privilege (P1) on an object (O1) |
| 18 | +* **Conditional**: operations are allowed only when all conditions are met. Each condition must belong to either category 3 or category 4 |
| 19 | +* **Available to all users**: operations that anyone can perform |
| 20 | +
|
| 21 | +## Implicitly Allowed Operations |
| 22 | + |
| 23 | +For operations in categories 3 and 4, two key rules apply: |
| 24 | + |
| 25 | +1. **Superuser Inheritance**: if an operation is allowed for the owner of object O1, it is also allowed for all superusers, |
| 26 | +regardless of ownership |
| 27 | +
|
| 28 | +2. **Owner Inheritance**: if an operation requires privilege P1 on object O1, the owner of O1 can perform it, |
| 29 | +even without having privilage (P1). Referring to rule 1, all superusers can also perform such operations |
| 30 | +
|
| 31 | +These rules mean that privileges granted to a superuser are irrelevant while they retain superuser status. |
| 32 | +If a user loses superuser status, their explicit privileges become relevant again, |
| 33 | +including any changes made while they were a superuser. |
| 34 | + |
| 35 | +[NOTE] |
| 36 | +==== |
| 37 | +Role attributes, privileges, and ownership are managed independently. |
| 38 | +Modifying one does not affect the others. This separation, combined with the implicit rules, |
| 39 | +makes the privilege system straightforward and adaptable |
| 40 | +==== |
| 41 | + |
| 42 | + |
| 43 | +## Operation Categories: Examples |
| 44 | + |
| 45 | +For clarity, reviewing examples of operations from each category can be highly beneficial. |
| 46 | + |
| 47 | +### Unavailable Regardless of Permissions |
| 48 | + |
| 49 | +Some operations are always forbidden because they would violate built-in constraints. |
| 50 | +For example, deleting the default `public` schema or dropping a role that still owns objects is not allowed: |
| 51 | + |
| 52 | +[source,sql] |
| 53 | +---- |
| 54 | +DROP ROLE john; |
| 55 | +---- |
| 56 | + |
| 57 | +Even superusers cannot drop a role if it owns objects: |
| 58 | + |
| 59 | +[source] |
| 60 | +---- |
| 61 | +ERROR: role "john" cannot be dropped because some objects depend on it: |
| 62 | +... here is the list of dependent objects ... |
| 63 | +---- |
| 64 | + |
| 65 | + |
| 66 | +[NOTE] |
| 67 | +==== |
| 68 | +You can drop a role only after removing all its dependencies. |
| 69 | +==== |
| 70 | + |
| 71 | + |
| 72 | +### Superuser-Only Operations |
| 73 | + |
| 74 | +Certain operations require superuser privileges. For example, creating a new role: |
| 75 | + |
| 76 | +[source,sql] |
| 77 | +---- |
| 78 | +CREATE ROLE username PASSWORD 'your_secure_password'; |
| 79 | +---- |
| 80 | + |
| 81 | +Only superusers can execute this command. |
| 82 | + |
| 83 | +### Owner-Only Operations |
| 84 | + |
| 85 | +Some operations are restricted to object owners, even if other users have all possible privileges on the object. |
| 86 | +For example, only the owner of schema `s1` can drop it: |
| 87 | + |
| 88 | +[source,sql] |
| 89 | +---- |
| 90 | +DROP SCHEMA s1; |
| 91 | +---- |
| 92 | + |
| 93 | +This operation is not permitted for non-owners, regardless of their privileges. |
| 94 | + |
| 95 | +### Privilege-Based Operations |
| 96 | + |
| 97 | +Many operations require specific privileges. For example, creating a table in schema `s1` requires the CREATE privilege on that schema: |
| 98 | + |
| 99 | +[source,sql] |
| 100 | +---- |
| 101 | +CREATE TABLE s1.t1(a integer); |
| 102 | +---- |
| 103 | + |
| 104 | + |
| 105 | +### Conditional Operations |
| 106 | + |
| 107 | +Some operations require multiple privileges or ownerships such as privileges of category 3 or 4. |
| 108 | +If the user is a superuser, all such conditions are considered met. |
| 109 | +If not, each condition must be checked individually, and all must be satisfied (either explicitly or implicitly). |
| 110 | + |
| 111 | +For example, to execute: |
| 112 | + |
| 113 | +[source,sql] |
| 114 | +---- |
| 115 | +SELECT * FROM s1.t1; |
| 116 | +---- |
| 117 | + |
| 118 | + |
| 119 | +The user must have: |
| 120 | +1. `USAGE` privilege on schema `s1` |
| 121 | +2. `SELECT` privilege on table `s1.t1` |
| 122 | + |
| 123 | +If a user owns the schema `s1` but not the table `s1.t1` and lacks `SELECT` privilege on `s1.t1`, the operation is forbidden. |
| 124 | +Similarly, the operation will be forbidden if owning the table `s1.t1` without `USAGE` privilege on schema `s1`. |
| 125 | + |
| 126 | +### Operations Available to All Users |
| 127 | + |
| 128 | +Some operations are always available, assuming the user is connected to Oxla database. For example: |
| 129 | + |
| 130 | +[source,sql] |
| 131 | +---- |
| 132 | +SELECT sqrt(15); |
| 133 | +---- |
| 134 | + |
| 135 | + |
| 136 | +This query succeeds for any connected user, even if their `CONNECT` privilege was revoked after connecting. |
0 commit comments