PostgreSQL

postgreesqlDiscover system accounts and their permissions

JDBC Connection String

jdbc:postgresql://sql.example.com:5432/postgres?ssl=true

Validate Credentials

SELECT 
    r.rolname as integration_specific_id,
    r.rolname as username,
    COALESCE(r.rolname || '@' || current_database(), r.rolname) as email,
    CASE 
        WHEN NOT r.rolcanlogin THEN 'INACTIVE'
        WHEN r.rolvaliduntil < CURRENT_TIMESTAMP THEN 'DEPROVISIONED'
        ELSE 'ACTIVE' 
    END as user_status,
    CASE 
        WHEN r.rolsuper OR NOT r.rolcanlogin THEN 'SERVICE'
        ELSE 'USER' 
    END as account_type
FROM pg_catalog.pg_roles r 
LIMIT 1;

List Accounts

SELECT 
    r.rolname as integration_specific_id,
    r.rolname as username,
    COALESCE(r.rolname || '@' || current_database(), r.rolname) as email,
    CASE 
        WHEN NOT r.rolcanlogin THEN 'INACTIVE'
        WHEN r.rolvaliduntil < CURRENT_TIMESTAMP THEN 'DEPROVISIONED'
        ELSE 'ACTIVE' 
    END as user_status,
    CASE 
        WHEN r.rolsuper OR NOT r.rolcanlogin THEN 'SERVICE'
        ELSE 'USER' 
    END as account_type
FROM pg_catalog.pg_roles r;

List Entitlements

SELECT 
    'ROLE_' || r.rolname as integration_specific_id,
    current_database() as integration_specific_resource_id,
    'ROLE' as entitlement_type,
    'Role - ' || r.rolname as label,
    true as is_assignable
FROM pg_catalog.pg_roles r;

Find Entitlement Associations

SELECT 
    m.member::regrole::text as account_id,
    'ROLE_' || r.rolname as integration_specific_entitlement_id,
    current_database() as integration_specific_resource_id
FROM pg_catalog.pg_roles r
JOIN pg_catalog.pg_auth_members m ON r.oid = m.roleid;

List Resources

SELECT 
    current_database() as integration_specific_id,
    current_database() as label,
    'DATABASE' as resource_type
FROM pg_database 
WHERE datname = current_database();