What does adding WITH GRANT OPTION to a privilege change, and what happens to the privileges that grantee handed out when you later revoke theirs?
answer
- grants are edges with a grantor
- grant option = right to add edges
- RESTRICT fails, CASCADE deletes dependants
- you revoke only your own grants
- still has access? check roles, PUBLIC, other grantors, ownership
basics
~20 sWITH GRANT OPTION lets the grantee re-grant the privilege to others, creating a dependency graph of grants. Revoking the grantor's privilege must deal with those dependants: RESTRICT (the standard default) refuses while dependants exist, CASCADE removes them too. Also, you can only revoke grants you yourself made.
solid answer
~50 sA privilege carries a grantor, so grants form a directed graph rather than a flat list. WITH GRANT OPTION gives the grantee the right to extend that graph by re-granting the same privilege to others. That makes revocation non-trivial. If B re-granted to C, revoking B's privilege leaves C's grant with no valid source. The standard behaviour is RESTRICT: the REVOKE fails rather than silently orphaning dependants. CASCADE walks the graph and removes the dependent grants as well, which can withdraw access from accounts you never touched -- so it deserves a check first. Two more semantics matter. You can revoke only the grants you made; if two grantors both granted SELECT to the same role, revoking one path leaves the other intact and the role keeps access. And you can revoke *just* the grant option, leaving the privilege itself in place, which is how you stop further propagation without breaking the grantee.
code
sql · 11 lines-- owner -> analyst_lead (may re-grant) -> analyst
GRANT SELECT ON app.orders TO analyst_lead WITH GRANT OPTION;
-- analyst_lead then runs:
GRANT SELECT ON app.orders TO analyst;
-- owner revoking later:
REVOKE SELECT ON app.orders FROM analyst_lead RESTRICT; -- errors: dependent grant exists
REVOKE SELECT ON app.orders FROM analyst_lead CASCADE; -- also removes analyst's privilege
-- keep the read, stop the propagation:
REVOKE GRANT OPTION FOR SELECT ON app.orders FROM analyst_lead;go deeper
Know that WITH GRANT OPTION lets the grantee pass the privilege on, and that revoking may affect others.
Explain RESTRICT versus CASCADE and that a revoke only removes your own grants.
Handle the incident version: enumerate dependants, know the four reasons access survives a revoke, and avoid grant option for service accounts.
Set policy so the grant graph stays one level deep, define who may hold propagation rights, and make effective-access review part of the platform rather than an ad-hoc query.
## Grants are edges, not flags It is tempting to picture privileges as a checkbox per (role, object, action). The engine actually stores something richer: each privilege records **who granted it**. So the state is a graph whose nodes are roles and whose edges are 'grantor G gave privilege P on object O to grantee E, with or without the right to pass it on'. WITH GRANT OPTION is what makes the graph deeper than one level: it authorises the grantee to create new edges for the same privilege. Without it, the grantee can use the privilege but not spread it. ## Why the graph shape matters on REVOKE Suppose the owner grants SELECT to B with grant option, and B grants SELECT to C. C's privilege exists because B was entitled to give it. Remove B's privilege and C's edge has no valid basis -- an abandoned privilege. SQL gives two behaviours: - **RESTRICT** (the standard default): the REVOKE fails because dependent privileges exist. This is the safe default: it forces you to look at what you are about to break. - **CASCADE**: the engine removes the dependent privileges too, transitively. The revoke succeeds, and roles you never named lose access. The practical implication is that CASCADE on a widely re-granted privilege is a blast-radius event, and you should enumerate the dependants before running it. In an incident this is the right tool; in routine maintenance, RESTRICT plus a deliberate cleanup order is safer. ## Revoking only the grant option Sometimes the goal is 'you may keep reading, but stop giving this to other people'. The standard supports revoking the *grant option* alone: the grantee keeps the privilege and loses the right to propagate it. Note the wrinkle -- privileges the grantee already handed out are still dependants, so if any exist the same RESTRICT/CASCADE choice applies. ## Only your own edges A REVOKE removes edges whose grantor is you (or a role you are acting as). This produces one of the most common real-world surprises: an admin revokes a privilege, the target still has access, and nothing looks wrong. The reasons are almost always one of: - **Another grantor.** Someone else granted the same privilege independently. Two edges existed; you removed one. - **A role path.** The account inherits the privilege through a role it is a member of, so the direct revoke is irrelevant. - **A PUBLIC grant.** The privilege is held by everyone, and an individual revoke does not subtract from a group grant. - **Ownership.** Owners have implicit rights that are not modelled as grants at all, so revoking does nothing to them. A correct answer to 'I revoked it and they still have access' therefore starts by querying *effective* privileges and their sources, not by repeating the revoke. ## Lifecycle hazards - **Dropping a grantor role.** Every privilege that role granted is a dangling edge; engines generally refuse to drop a role that still owns objects or has granted privileges until those are reassigned or dropped. This is why role deletion in a mature system is a multi-step operation. - **Auditability.** Because the graph can be several edges deep, 'who can read this table' is a transitive-closure question. Any access review that reads only direct grants will under-report. - **Design guidance.** Grant option is rarely appropriate for application accounts. Keep propagation rights with owners and a small set of administrative roles, and give services flat, non-propagating grants; this keeps the graph one level deep, which makes both revocation and review tractable. ## Interview framing Strong answers say three things: grants have grantors, so revocation has dependants; RESTRICT versus CASCADE is a choice about whether to fail loudly or delete transitively; and revocation is scoped to your own edges, which is why access can survive a revoke.
- You revoked SELECT from a role and it can still read the table. What are the possible explanations?Another grantor granted the same privilege, so a second edge survives your revoke, which only removes your own grants. Or the account inherits the privilege through role membership, or through a grant to PUBLIC, neither of which an individual revoke subtracts from. Or the role owns the object, in which case its rights are implicit rather than granted. The fix is to query effective privileges and their sources before acting again.
- Why is CASCADE risky in a production revoke, and what would you do before running it?CASCADE removes every dependent privilege transitively, so it can withdraw access from accounts and services that were never mentioned in the statement and are not owned by the person running it. Before using it I would enumerate the dependent grants from the catalog, identify the owning teams, and either notify them or re-grant the legitimate ones from a stable grantor first. In an active incident the blast radius may be acceptable; in routine maintenance it usually is not.
saying these in an interview costs you the question
- Thinking WITH GRANT OPTION means broader access rather than the right to re-grant
- Believing a REVOKE removes privileges granted by other grantors
- Reaching for CASCADE without enumerating dependants
- Assuming revoking the grant option also removes already-propagated grants
- Answering 'who can read this table' from direct grants only, ignoring role chains