Azpg roles rbac
Skill lestermarch/postgres-ai-experts/skills/azpg-roles-rbac
Composable AI agents and skills for operating Azure Database for PostgreSQL Flexible Server - PostgreSQL can be used for everything.
npx -y skills add lestermarch/postgres-ai-experts --skill azpg-roles-rbacAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
3 things to look at
- 20 days oldThe repository was created 20 days ago. New is not bad, but a brand new repository carrying a familiar-sounding name is the shape a typosquat arrives in, and there has been no time for anyone else to find a problem with it.
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Design and apply least-privilege access control on Azure Database for PostgreSQL Flexible Server — create login and group (NOLOGIN) roles, GRANT/REVOKE table, schema, and sequence privileges, set ALTER DEFAULT PRIVILEGES so future objects inherit grants, and wire up Microsoft Entra ID authentication (passwordless / token-based logins, the Entra server administrator, and Entra-backed roles via pgaadauth_create_principal). Use this skill whenever the task involves database roles, users, permissions, GRANT, REVOKE, least privilege, "who can access what", azure_pg_admin, Microsoft Entra / Azure AD authentication for Postgres, passwordless DB login, managed identity connecting to Postgres, or "lock down my database" on Flexible Server. Server-parameter changes are azpg-config-tuning; provisioning the server is azpg-provision-iac.
SKILL.md
7.6 KB, as published. Nobody here has run it
Access control & Entra auth on Azure Database for PostgreSQL Flexible Server
Flexible Server uses PostgreSQL's native role system, with two Azure-specific
twists: there is no customer superuser (the azure_pg_admin pseudo-superuser
role is the ceiling), and roles can be backed by Microsoft Entra ID for
passwordless, centrally-governed authentication instead of (or alongside) local
passwords.
This skill is read-write and explicit. Listing roles, grants, and memberships
changes nothing and is auto-runnable. CREATE ROLE, GRANT, REVOKE, ALTER DEFAULT PRIVILEGES, and creating Entra principals mutate the security posture —
an over-broad GRANT or a wrong REVOKE can either expose data or lock out an
application — so every write is guarded and deliberate.
Live instance context (dynamic injection)
Ground access decisions in the roles and grants that actually exist:
- Roles and their attributes (login? superuser-ish? can create roles/dbs?):
!
psql "$PGCONN" -tAc "SELECT rolname, rolcanlogin, rolcreaterole, rolcreatedb, rolinherit FROM pg_roles WHERE rolname NOT LIKE 'pg\_%' ORDER BY rolname;" - Who holds the keys — members of the
azure_pg_adminpseudo-superuser role: !psql "$PGCONN" -tAc "SELECT m.rolname FROM pg_auth_members am JOIN pg_roles r ON r.oid=am.roleid JOIN pg_roles m ON m.oid=am.member WHERE r.rolname='azure_pg_admin';" - Is Entra authentication enabled on the server?
!
az postgres flexible-server show --resource-group "$RG" --name "$SERVER" --query "authConfig" -o json
Anyone in azure_pg_admin effectively owns the database — keep that list small.
When to use this skill
- "Create a read-only user for analytics / a read-write user for the app."
- "Set up least privilege — the app shouldn't be able to DROP tables."
- "Let our app connect with its managed identity, no password."
- "Add <person/group> as a database administrator."
- "Audit who can read the
customerstable." - "New tables aren't visible to the app role" →
ALTER DEFAULT PRIVILEGES.
Decision flow
- Inventory current access (read · auto) —
scripts/inspect_roles.sql: roles, attributes, group memberships,azure_pg_adminmembers, and per-schema grants. You can't design least privilege without seeing the baseline. - Design roles as groups, not individuals (read · auto) — a NOLOGIN group
role per access level (
app_readwrite,app_readonly), with login roles / Entra principals made members. Grants attach to the group; people/services come and go without re-granting. - Choose the auth model (read · auto) — local password vs Entra (passwordless). For app identities prefer Entra + managed identity: no secret to leak or rotate.
- Apply grants least-privilege (write · guarded · explicit) —
scripts/create_role.shemits transaction-wrappedCREATE ROLE+ scopedGRANT+ALTER DEFAULT PRIVILEGES,--dry-runby default. GrantUSAGEon schema + the specific privileges needed, neverALL/SUPERUSER, never ownership to an app. - Wire Entra identities (write · guarded · explicit) — add the Entra server
admin with
az … microsoft-entra-admin create, and create Entra-backed roles in-database withpgaadauth_create_principal(...); then add them to the group role. - Verify the boundary (read · auto) — re-run
inspect_roles.sql; ideally confirm the app role is denied what it shouldn't have (e.g. it canSELECTbut aDROPfails).
Role design cheat-sheet
| Goal | Pattern |
|---|---|
| Reusable access tier | CREATE ROLE app_readonly NOLOGIN; then GRANT to it; add members. |
| Read-only analytics | GRANT USAGE ON SCHEMA app TO app_readonly; GRANT SELECT ON ALL TABLES IN SCHEMA app TO app_readonly; + default privileges. |
| App read/write (no DDL) | GRANT SELECT, INSERT, UPDATE, DELETE … — not ALL, so no TRUNCATE/REFERENCES/ownership. |
| Future tables inherited | ALTER DEFAULT PRIVILEGES IN SCHEMA app GRANT SELECT ON TABLES TO app_readonly; |
| Passwordless app login | Entra role via pgaadauth_create_principal + managed identity token. |
| Human/group admin | az … microsoft-entra-admin create (member of azure_pg_admin). |
Safety protocol
- Least privilege by construction. Start from zero and add the specific
privileges an identity needs.
GRANT ALL,SUPERUSER,CREATEROLE, or making an app role a table owner are almost always wrong — an owner/ALLgrantee can drop or truncate your data. create_role.shis dry-run by default and transaction-wrapped. It prints theCREATE ROLE/GRANTSQL insideBEGIN … COMMIT; nothing runs until--apply. A wrong grant set rolls back cleanly.- Group roles over per-person grants. Attaching privileges to individuals creates unauditable sprawl and orphaned access. Grant to a group; manage membership.
REVOKEcan lock out the app. Before revoking, confirm frominspect_roles.sqlthat no live login role depends on the grant. Revoking the wrong grant is an outage.- Guard
azure_pg_adminmembership. It's the pseudo-superuser — the closest thing to root here. Only true administrators belong; never add an application role to it. - Prefer Entra + managed identity for services. A passwordless token-based
login removes a stored secret entirely; it's more secure than a password in a
connection string. See
reference.mdfor the token flow.
Bundled files
reference.md— the no-superuser model andazure_pg_admin; group-role recipes;ALTER DEFAULT PRIVILEGES; the full Entra story (server admin,pgaadauth_*functions, managed-identity token login), password vs Entra.azure-constraints.md— no superuser / noazuresu; whatazure_pg_admincan and can't do; Entra prerequisites; roles Azure manages;pg_signal_backendfor termination rights.scripts/inspect_roles.sql— read-only audit of roles, attributes, memberships,azure_pg_admin, and grants.scripts/create_role.sh— guarded write; emits transaction-wrapped least-privilegeCREATE ROLE/GRANT/default-privileges SQL,--dry-rundefault,--applyto execute.scripts/README.md— script catalog + safety class.examples/app_least_privilege.md— worked "read-only analytics user + read/write app role via Entra managed identity", including verifying the deny boundary.EVALUATION.md— trigger prompts, expected behaviour, conventions self-review.