Repository navigation
fix(db): grant regengine SELECT (status) on tenants (v139 / SEL-616) #3741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7691dd7
fix(db): grant regengine SELECT (status) on tenants (v139 / SEL-616)
PetrefiedThunder 3ef0ce8
Merge branch 'main' into grok/sel616-tenants-status-grant
PetrefiedThunder 17c40b3
Merge branch 'main' into grok/sel616-tenants-status-grant
PetrefiedThunder a3978a6
fix(sel-616): allowlist v139 revision hex in secrets scan
PetrefiedThunder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
alembic/versions/20261028_e7a1c9d2f4b0_v139_tenants_status_select_grant.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| """Grant regengine column-level SELECT on tenants.status (v139 / SEL-616). | ||
|
|
||
| Prod auth for the Compliance Dashboard readiness path fails because | ||
| ``shared.api_key_store`` runs ``SELECT status FROM tenants WHERE id = ...`` | ||
| and v111 only granted ``SELECT (id)`` to ``regengine``. This revision adds | ||
| the missing column privilege only — never a table-level SELECT — and the | ||
| matching v111 ``REGENGINE_COLUMN_GRANTS`` inventory entry keeps the grant | ||
| across ``apply_runtime_role_cutover``. | ||
|
|
||
| Mirrors ``supabase/migrations/20261028120000_v139_tenants_status_select_grant.sql``. | ||
| Do not apply to prod without C.Lee's approval via DevOps. Pairs with the | ||
| UI degrade in #3740; this PR is the DB half of SEL-616. | ||
|
|
||
| Revision ID: e7a1c9d2f4b0 | ||
| Revises: a3f7ce361b0e | ||
| Create Date: 2026-10-28 | ||
| """ | ||
|
|
||
| from typing import Sequence, Union | ||
|
|
||
| from alembic import op | ||
|
|
||
| revision: str = "e7a1c9d2f4b0" # pragma: allowlist secret | ||
| down_revision: Union[str, Sequence[str], None] = "a3f7ce361b0e" # pragma: allowlist secret | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| op.execute( | ||
| """ | ||
| DO $grant$ | ||
| BEGIN | ||
| IF to_regclass('public.tenants') IS NOT NULL | ||
| AND EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'regengine') THEN | ||
| -- Column-level only. Do not GRANT SELECT ON public.tenants | ||
| -- (table-level); names/settings stay control-plane. | ||
| GRANT SELECT (status) ON TABLE public.tenants TO regengine; | ||
| END IF; | ||
| END | ||
| $grant$; | ||
| """ | ||
| ) | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| op.execute( | ||
| """ | ||
| DO $revoke$ | ||
| BEGIN | ||
| IF to_regclass('public.tenants') IS NOT NULL | ||
| AND EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'regengine') THEN | ||
| REVOKE SELECT (status) ON TABLE public.tenants FROM regengine; | ||
| END IF; | ||
| END | ||
| $revoke$; | ||
| """ | ||
| ) |
30 changes: 30 additions & 0 deletions
30
supabase/migrations/20261028120000_v139_tenants_status_select_grant.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| -- v139 / SEL-616: column-level SELECT on public.tenants(status) for regengine. | ||
| -- | ||
| -- Mirrors alembic/versions/20261028_e7a1c9d2f4b0_v139_tenants_status_select_grant.py. | ||
| -- Auth (api_key_store.get_tenant_status) needs status to fail closed on | ||
| -- suspended tenants. v111 only granted SELECT (id). Do NOT grant table-level | ||
| -- SELECT — names, settings, and webhook config stay control-plane. | ||
| -- | ||
| -- Idempotent. Do not apply to prod without C.Lee's approval via DevOps. | ||
| -- Pairs with the Compliance Dashboard degrade in #3740. | ||
|
|
||
| DO $grant$ | ||
| BEGIN | ||
| IF to_regclass('public.tenants') IS NOT NULL | ||
| AND EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'regengine') THEN | ||
| -- Column-level only. Never GRANT SELECT ON public.tenants (table-level). | ||
| GRANT SELECT (status) ON TABLE public.tenants TO regengine; | ||
| END IF; | ||
| END | ||
| $grant$; | ||
|
|
||
| -- Downgrade (run by hand only): | ||
| -- | ||
| -- DO $revoke$ | ||
| -- BEGIN | ||
| -- IF to_regclass('public.tenants') IS NOT NULL | ||
| -- AND EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'regengine') THEN | ||
| -- REVOKE SELECT (status) ON TABLE public.tenants FROM regengine; | ||
| -- END IF; | ||
| -- END | ||
| -- $revoke$; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: regengine/RegEngine
Length of output: 27259
Security Misconfiguration
Reachability: Internal
Exploitability: Difficult
CWE: CWE-732 — Incorrect Permission Assignment for Critical Resource
View Security blast radius
Prevent the cutover inventory from re-granting
statusafter downgrade.The v139 downgrade revokes
SELECT(status), but rerunningscripts/apply_runtime_role_cutover.pyreapplies the v111 inventory and restores that grant. Make the inventory version-aware, or apply the grant only while v139 is installed. Add a regression test that downgrades v139, reruns the cutover, and asserts thatstatusremains revoked.Source: Path instructions