Skip to content

fix(tree): list databases when the role lacks CONNECT on some cluster databases#105

Open
brains-fatman wants to merge 1 commit into
dev-asterix:mainfrom
brains-fatman:fix/db-tree-permission-denied
Open

fix(tree): list databases when the role lacks CONNECT on some cluster databases#105
brains-fatman wants to merge 1 commit into
dev-asterix:mainfrom
brains-fatman:fix/db-tree-permission-denied

Conversation

@brains-fatman

Copy link
Copy Markdown

Summary

Fixes #104.

src/providers/tree/loaders/ConnectionLoader.ts enumerates every database in the cluster with a single query that calls pg_database_size(datname) for each row. pg_database_size() requires CONNECT on the target database (or membership in pg_read_all_stats). When the connecting role lacks CONNECT on any database in the cluster, the first inaccessible database aborts the whole SELECT, so the tree shows no databases at all — including the ones the role can access. The "Databases" node still reports a non-zero count, but expanding it yields an empty list.

Change

Guard the size computation with has_database_privilege(datname, 'CONNECT') in both affected queries (databases-group and system-databases-group):

SELECT datname,
       CASE WHEN has_database_privilege(datname, 'CONNECT')
            THEN pg_size_pretty(pg_database_size(datname))
       END as size
FROM pg_database
ORDER BY datname

Inaccessible databases now yield a NULL size instead of erroring the whole statement. Behaviour is unchanged for privileged roles — all databases are still listed, with sizes. This is a query-only change; no TypeScript or API changes.

Other occurrences (intentionally not touched)

pg_database_size() is also used in helper.ts (databaseStats, scoped to current_database()) and DashboardData.ts (scoped to a single $1 database). Both operate on a single database the user is connected to, so they aren't affected by this bug. Happy to extend the same guard there if you'd prefer consistency.

Verification

The failing scenario was observed in a real shared/multi-tenant cluster where the connecting role lacks CONNECT on neighbouring databases. The fix relies on has_database_privilege() — a standard catalog function that returns a boolean and does not raise on inaccessible databases — to gate pg_database_size(), so the statement can no longer abort. For privileged roles the result set is identical to before.

…e DBs

pg_database_size() requires CONNECT on the target database (or membership
in pg_read_all_stats). The database tree enumerated the whole cluster in a
single query calling pg_database_size(datname) for every row, so the first
inaccessible database aborted the entire SELECT — leaving the tree empty
even for databases the role can access.

Guard the size computation with has_database_privilege(datname, 'CONNECT')
in both the databases-group and system-databases-group queries, so
inaccessible databases yield a NULL size instead of erroring the whole
statement. Behaviour is unchanged for privileged roles.

Fixes dev-asterix#104

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 22, 2026

Copy link
Copy Markdown

@brains-fatman is attempting to deploy a commit to the asterix-dev Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 A new contributor appears! 🎉
Huge thanks to @brains-fatman for your first PR! We are thrilled to see new faces here.
While you wait for a review, feel free to join our Discord/Slack to introduce yourself. If you have any questions about the build process, just drop a comment below.
Thanks for making this project better!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Database tree lists nothing when the connecting role lacks CONNECT on other databases (pg_database_size -> permission denied)

1 participant