Skip to main content

Roles & Permissions

GitGazer has two layers of roles:

  • Integration roles (owner, admin, member, viewer) belong to a person in one integration. The API checks them before it runs an operation.
  • Database roles (gitgazer_reader, gitgazer_writer, gitgazer_mcp) belong to a database session. PostgreSQL uses them to decide which tables a query may touch and, through row-level security (RLS), which tenant's rows it sees.

The two meet in the database: every request runs with the caller's integrations, and for the role-aware views also with the caller's integration role per integration.

Integration roles​

Each row in github."user-assignments" gives one user one role in one integration. The roles form a strict hierarchy, and a higher role can do everything a lower role can:

The ranks live in ROLE_RANK (packages/db/src/types/members.ts); hasRole(userRole, requiredRole) compares them. The API and the web app use the same function.

RoleMeant for
ownerEverything, including deleting the integration. The creator starts as owner.
adminManaging the integration: members, invitations, apps, handles, GitHub App.
memberDay-to-day use: notification rules, seeing pending invitations.
viewerRead-only: workflows, dashboards, event log, members, apps and their rules.

A user gets a role by:

  • Creating an integration — the creator becomes owner.
  • Accepting an invitation — the role on the invitation (admin, member or viewer; owner invitations are refused).
  • Organization sync — members of the linked GitHub organization get the integration's org-sync default role (viewer, member or admin).
  • A role change by an admin or owner.

Permission matrix​

The permission table in apps/lambdas/api/src/shared/permissions/table.ts is the source of truth. It maps each route ('<METHOD> <path>') to an operation and each operation to an access level: public, authenticated or a minimum role. The authorize middleware (apps/lambdas/api/src/shared/middleware/authorization.ts) runs after authenticate and originCheck. For a minimum role it reads the path segment at the pattern's :integrationId position, loads the caller's roles if needed, and answers 403 if the caller is not a member (Not a member of this integration) or ranks too low (Insufficient permissions). A route without a table entry also gets 403. Role-gated decisions and refusals for a missing entry are logged as authz entries.

The two Slack callbacks (slackApp.installCallback, slackUser.signInCallback) are marked checkedInHandler: they learn the integration only from the signed state, so their handlers call checkAccess themselves.

MCP tools use the same table. registerTool takes a tool name from it and calls checkAccess on every tool call; a refusal comes back as a tool error in the response, not an HTTP status. The write tools map to the same operations as the matching routes, so each needs the role the route needs in the integration it names: member for the notification rule tools, admin for the handle tools, rename_integration and update_webhook_events, and any signed-in user for the two event log tools, as on the route (RLS limits them to the caller's integrations). list_slack_channels needs admin like its route and, because it only reads, is available in read-only sessions too. The other write tools are registered only for tokens with the scope gitgazer-mcp/write; the role check applies on top of that.

Every operation that is not public must be in exactly one of two places: TOOLS (tool name to operation) or NOT_IN_MCP (operation to the reason it has no tool). Dangerous, irreversible or access-changing operations, such as creating or deleting an integration, rotating the webhook secret, linking an installation, members, invitations, app installation and the Slack OAuth flows, are in NOT_IN_MCP and stay in the web app, as do reads that run_sql covers and session plumbing. table.test.ts fails when a new operation is in neither, so exposing it to MCP is always a decision. See MCP Server for the list.

Routes without an integrationId in the path (apart from the public routes and the two Slack callbacks) are authenticated. They act on all the caller's integrations, and RLS limits them to those. A CI test (table.test.ts) fails if a route or tool has no entry, or an entry has none.

AreaOperationEndpointMinimum role
IntegrationsList your integrations (with your role)GET /api/integrationsany membership
Create an integrationPOST /api/integrationssigned in (becomes owner)
RenamePUT /api/integrations/:integrationIdadmin
DeleteDELETE /api/integrations/:integrationIdowner
Rotate the webhook secretPOST /api/integrations/:integrationId/rotate-secretadmin
Link / unlink a GitHub App installationPOST /api/integrations/:integrationId/github-app, DELETE …/github-app/:installationIdadmin
Change the GitHub App webhook eventsPATCH /api/integrations/:integrationId/github-app/:installationId/eventsadmin
Change the org-sync default rolePATCH /api/integrations/:integrationId/org-sync-settingsadmin
MembersList membersGET /api/integrations/:integrationId/membersviewer
Change a member's rolePATCH /api/integrations/:integrationId/members/:userId/roleadmin
Remove a memberDELETE /api/integrations/:integrationId/members/:userIdadmin
Leave the integrationPOST /api/integrations/:integrationId/leaveviewer, except owners
InvitationsList pending invitationsGET /api/integrations/:integrationId/invitationsmember
Create / resend / revoke an invitationPOST …/invitations, POST …/invitations/:invitationId/resend, DELETE …/invitations/:invitationIdadmin
Accept an invitationPOST /api/invitations/acceptsigned in, with the token
AppsList apps, handles and their settingsGET /api/integrations/:integrationId/appsviewer
Add or remove an appPOST …/apps, DELETE …/apps/:appIdadmin
Install the Slack app, move a workspace, list channelsGET …/apps/slack/install, GET …/apps/slack/move-candidates, POST …/apps/slack/move, GET …/apps/:appId/slack/channelsadmin
Create / edit / delete a notification handlePOST …/apps/:appId/handles, PATCH …/handles/:handleId, DELETE …/handles/:handleIdadmin
Slack linkConnect / disconnect your own Slack userGET /api/integrations/:integrationId/slack/connect, DELETE …/slack/connectionviewer (own account only)
NotificationsList notification rulesGET /api/notificationsany membership
Create / update / delete a notification rulePOST /api/integrations/:integrationId/notifications, PUT …/notifications/:id, DELETE …/notifications/:idmember
MonitoringWorkflows, overview, metricsGET /api/workflows, /api/overview, /api/metrics/*any membership
Event log, mark entries readGET /api/event-log, PATCH /api/event-log/:id/read, POST /api/event-log/mark-all-readany membership
OtherWebSocket tokenGET /api/auth/ws-tokensigned in
MCP data toolsPOST /api/mcpany membership; what is visible depends on the role
MCP notification rule tools (write sessions only)POST /api/mcp: create_, update_, delete_notification_rulemember
MCP handle, integration and event log tools (write sessions only)POST /api/mcp: create_, update_, delete_notification_handle, rename_integration, update_webhook_events, set_event_log_read, mark_all_event_log_readadmin; the event log tools any membership
MCP Slack channel list (both session types)POST /api/mcp: list_slack_channelsadmin

"Any membership" means any role in the integration the data belongs to; a user with no integrations gets empty results. The read flag of an event log entry is stored on the entry, so marking it read marks it for everyone in the integration.

Rules beyond the minimum role​

The members controller (apps/lambdas/api/src/domains/members/members.controller.ts) adds these checks:

  • Nobody can change their own role.
  • Only an owner can give someone the owner role.
  • Only an owner can change the role of an owner or an admin. An admin can change members and viewers, including promoting them to admin.
  • Nobody can remove an owner. Only an owner can remove an admin. Nobody can remove themselves; they leave instead.
  • An owner cannot leave.
  • Invitations carry admin, member or viewer, never owner.

The Slack install callback (/api/slack/oauth/callback) checks for admin itself, because it has no integrationId in the path.

Several owners and ownership transfer​

An integration can have more than one owner: an owner can promote anyone to owner. The API also lets an owner change another owner's role, so a handover is: promote the new owner, the new owner changes the old owner's role, the old owner leaves. The web app does not offer the middle step: its member card has no role menu for owners.

Data that depends on the role​

Below the role in the table, the field is empty (NULL) while the rest of the row stays visible. The API and the MCP read these through the same role-aware views, so they agree.

DataMinimum role
Pending invitationsmember
Invitation email and invite tokenadmin
Email addresses of members, inviters and inviteesadmin
GitHub App webhook secret (secret)admin
Webhook handle URLsadmin
Everything else in the integration (runs, jobs, rules)viewer

In the web app​

The web app hides what the caller's role does not allow, using hasRole with the role that GET /api/integrations returns for each integration (for example IntegrationSettings.vue, IntegrationMembers.vue, UserCard.vue, the app panels). The role dropdown on a member card only offers roles at or below the caller's own. This is convenience only; the API is the authority.

Database roles​

RoleLoginAttributesUsed for
rootyes, IAM auth (rds_iam)cluster master user, rds_superuser memberThe app login of every Lambda (RDS_DB_USER), and the migration user. Owns all schemas, tables, views and functions.
gitgazer_writernoNOINHERIT, no CREATEROLE / CREATEDBWrites, switched to with SET LOCAL ROLE.
gitgazer_readernoNOINHERIT, no CREATEROLE / CREATEDBReads, the default of withRlsTransaction.
gitgazer_mcpyes, IAM auth (rds_iam)NOINHERIT, no CREATEROLE / CREATEDBThe MCP tools (run_sql, list_tables, describe_table) on their own connection pool.

The roles are declared in packages/db/src/schema/app.ts. None of them is a superuser or has BYPASSRLS.

Two roles existed before and are gone: gitgazer_user was renamed to gitgazer_writer (20260310160938_daffy_human_cannonball), and gitgazer_analyst was created for read-only analytics and dropped again (20260721213946_regular_night_nurse).

How a session gets its role​

Every Lambda connects as root and switches role per transaction with withRlsTransaction (packages/db/src/client.ts):

  • Reads use gitgazer_reader (the default). Writes pass userName: gitgazerWriter.name.
  • rls.integration_ids is the caller's integrations. Each ID is checked against a UUID pattern before it goes into the SET LOCAL.
  • root owns every table and no table has FORCE ROW LEVEL SECURITY, so root itself bypasses RLS. The SET LOCAL ROLE is what makes RLS apply, and code that queries db directly runs across all tenants.
  • The MCP tools do not switch from root: they use a second pool that logs in as gitgazer_mcp (mcpDb), because a session logged in as the table owner could switch back to it. That pool exists only in rds-proxy connection mode; in data-api mode the MCP tools refuse to run.

Code that runs as root without a role switch, on purpose, because it works across tenants or on global tables:

WhereWhat
apps/lambdas/api/src/shared/middleware/authentication.tsUpserts the signed-in user in gitgazer.users, resolves pending_org_sync.
apps/lambdas/api/src/domains/integrations/Loads the caller's roles, creates an integration and its owner assignment.
apps/lambdas/websocket/src/index.tsStores and removes gitgazer.ws_connections rows.
packages/backend-services/src/org-member-resolver.tsReads github.github_org_members.
packages/backend-services/src/slack/, Slack connect / installgitgazer.slack_workspaces and gitgazer.slack_user_links.
GitHub App webhook handlingLooks up github.github_app_installations before the integration is known.

Tenant isolation with RLS​

Every tenant table has ROW LEVEL SECURITY enabled and a permissive policy per role (packages/db/src/schema/github/misc.ts):

PolicyRoleCommandsRows
tenant separation writergitgazer_writerALLintegration_id in rls.integration_ids
tenant separation readergitgazer_readerSELECTintegration_id in rls.integration_ids
tenant separation mcpgitgazer_mcpSELECTintegration_id in github.integration_ids(), the verified rls.signed_context

Without rls.integration_ids the reader and writer see no rows. rls.integration_ids is a plain setting: it is trusted because only the app sets it, and gitgazer_reader and gitgazer_writer cannot log in. The MCP runs arbitrary SQL, so its context is signed instead; see Role-aware views.

Tables without RLS:

TableWho can read it
gitgazer.usersroot, reader and writer (global; the API reads members through gitgazer.users_view)
gitgazer.mcp_query_usageroot, reader and writer (per-user MCP budget)
github.github_org_membersroot, reader and writer
gitgazer.slack_workspaces, gitgazer.slack_user_linksroot only; shared across tenants
gitgazer_internal.context_keyroot only; the signing key

Role-aware views​

The views apply the integration role in the database. They read rls.signed_context, which holds <integration-uuid>:<role> pairs and an HMAC signature bound to the backend PID and the transaction start. github.signed_context() verifies it and github.integration_ids(min_role) returns the integrations where the caller has at least min_role; an invalid context yields none. Only root can sign (gitgazer_internal.sign_context).

Each view is security_barrier, filters rows itself (it runs as its owner, so base-table RLS does not apply), and returns NULL for columns below their role. The views are defined in packages/db/src/schema/views.ts; the row and column rules are listed in MCP Server: Queryable data, and the signing in MCP Server: Security model.

The API uses them for members, invitations and apps by passing integrationRoles to withRlsTransaction, with the caller's role in the requested integration.

Privileges​

All objects live in three schemas. gitgazer_internal holds only the signing key and the sign function, and no role but root has USAGE on it.

Schemareaderwritermcp
gitgazerUSAGEUSAGEUSAGE
githubUSAGEUSAGEUSAGE
gitgazer_internal———

Tables (S = SELECT, I = INSERT, U = UPDATE, D = DELETE):

TableRLSreaderwritermcp
github.workflow_runs, workflow_jobs, workflow_run_pull_requests, pull_requests, pull_request_reviewsyesSSIUDS
github.repositories, organizations, enterprises, "user"yesSSIUDS
github.github_app_installationsyesSSIUDS
github."user-assignments", events, github_app_webhooks, pending_org_syncyesSSIUD—
github.github_org_membersnoSSIUD—
gitgazer.integrationsyesSSIUDS on integration_id, label, created_at
gitgazer.integration_apps, integration_app_github_settings, integration_app_slack_settingsyesSSIUD—
gitgazer.notification_handles, webhook_handle_details, slack_handle_detailsyesSSIUD—
gitgazer.notification_rules, notification_rule_destinations, integration_invitations, event_log_entries, ws_connectionsyesSSIUD—
gitgazer.users, mcp_query_usagenoSSIUD—
gitgazer.slack_workspaces, slack_user_linksno———
gitgazer_internal.context_keyno———

Views (SELECT only; the writer has none):

Viewreadermcp
gitgazer.users_view, github.user_assignments_view, gitgazer.integration_invitations_viewSS
gitgazer.integration_apps_view, integration_app_github_settings_view, integration_app_slack_settings_view, slack_workspaces_viewSS
gitgazer.notification_handles_view, webhook_handle_details_view, slack_handle_details_view, notification_rule_destinations_viewSS
gitgazer.notification_rules_view, event_log_entries_view—S

Functions:

FunctionSecurity definerreaderwritermcp
github.signed_context()yesEXECUTE—EXECUTE
github.integration_ids(text)noEXECUTE—EXECUTE
gitgazer_internal.sign_context(text, int, bigint)yes———

Defaults for new objects​

ALTER DEFAULT PRIVILEGES in gitgazer and github gives every new table and view created by root SELECT for gitgazer_reader and SELECT, INSERT, UPDATE, DELETE for gitgazer_writer. gitgazer_mcp gets nothing by default. So when you add:

  • A tenant table — enable RLS and attach writerTenantSeparationPolicy() and readerTenantSeparationPolicy(); add mcpTenantSeparationPolicy() and an explicit GRANT SELECT … TO gitgazer_mcp only if the MCP should read it.
  • A global table or a secret — REVOKE the default grants from the reader and writer (as for the Slack tables).
  • A view — REVOKE the default grants, then grant SELECT to the roles that need it. A view runs as its owner, so it must filter tenants itself.

The db-migration skill (.github/skills/db-migration/SKILL.md) walks through the migration.

Checking the live state​

The tables above reflect the database at the time of writing. These catalog queries show the current grants and policies:

-- Policies
SELECT schemaname, tablename, policyname, roles, cmd
FROM pg_policies
ORDER BY 1, 2, 3;

-- Table and view privileges per role
SELECT n.nspname, c.relname, c.relkind, c.relrowsecurity,
has_table_privilege('gitgazer_reader', c.oid, 'SELECT') AS reader_select,
has_table_privilege('gitgazer_writer', c.oid, 'INSERT') AS writer_insert,
has_table_privilege('gitgazer_mcp', c.oid, 'SELECT') AS mcp_select
FROM pg_class c
JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE n.nspname IN ('gitgazer', 'github', 'gitgazer_internal') AND c.relkind IN ('r', 'v')
ORDER BY 1, 3, 2;