Docs
Live demo

Quick start

Connect an identity provider, add a test PostgreSQL server, apply a read-only group rule and check the result in Principal and psql. Plan about 30 minutes.

On this page

You need:

  • The Admin role in a Principal organization.
  • Read-only credentials for GitLab, GitHub, Google Workspace or LDAP.
  • Superuser (or master user) access on a test PostgreSQL server, plus psql.

1. Sign in#

Enroll a second factor during sign-in if prompted: creating a connector and revealing another person’s credentials require one.

  1. Open your Principal address and click Continue with SSO.
  2. Sign in with your identity provider.
  3. Confirm your second factor with Verify code or Use security key, or click Use an authenticator app to enroll one.

You land on the dashboard with the action queue, Quick actions and Infrastructure. If you land on Your access, an administrator must change your role from User to Admin under Organizations.

2. Import your people#

  1. Open Connectors, click Create in the top bar and choose Create connector.
  2. Enter a Name such as Corporate GitLab and pick GitLab, GitHub, Google Workspace or LDAP.
  3. Open Connection and enter the address and credentials, for GitLab Base URL and Token (Supported providers).
  4. Open Test & discover and click Test connection & discover groups.
  5. Under Group filters (Groups for Google Workspace, Filters for LDAP), select one test group such as acme/analytics.
  6. Click Test connection & discover groups again.
  7. Click Create and confirm your second factor if prompted.
  8. Click Run first sync.

When sync finishes, Sync reports Sync completed with user and group counts. Open People → Groups to confirm your group appears with mode Managed. See Connectors for schedules and duplicates.

3. Add a target#

On your test PostgreSQL server, connect as a superuser (or master user) and create Principal’s role. Replace PASSWORD (from openssl rand -hex 24), APP_DB and the owner role APP_OWNER:

sql
CREATE ROLE principal LOGIN PASSWORD 'PASSWORD' CREATEROLE;
GRANT pg_signal_backend TO principal;
GRANT CONNECT ON DATABASE APP_DB TO principal WITH GRANT OPTION;
GRANT APP_OWNER TO principal;

Allow Principal to connect in pg_hba.conf or your firewall. See Prepare a target for other engines.

  1. Open Resources, click Create and choose Create target.
  2. Under Basics, enter a Display name such as warehouse-staging, pick PostgreSQL and leave Managed by Principal on.
  3. Open Connection, paste postgres://principal:<password>@db.example.com:5432/app?sslmode=require into Connection string and click Apply.
  4. Click Run test and wait for the checks to pass.
  5. Click Create target.

Discovery runs automatically. When it finishes, the header shows Scanned just now · Up to date, Databases lists your schemas and tables, and existing roles appear as Unmanaged in Roles. See Add a target and Target details.

4. Grant access#

Create a template for warehouse-staging:

  1. Open Rules & templates, click Create and choose Create template.
  2. Enter Name warehouse-read-only.
  3. Choose One server and pick warehouse-staging in Server.
  4. Open Databases, choose Select and tick your test database, for example app.
  5. Open Permissions and pick Read-only.
  6. Click Create.

Attach the template to your group:

  1. On the warehouse-read-only page, click Give access.
  2. Under People, tick your test group, for example analytics.
  3. Confirm Permissions and Targets are pre-filled.
  4. Click Create and apply.

Principal applies the rule in the background, creating a login role and grants for each member:

sql
CREATE ROLE "anna_lee" WITH LOGIN PASSWORD '<generated>';
GRANT CONNECT ON DATABASE "app" TO "anna_lee";
GRANT USAGE ON SCHEMA "public" TO "anna_lee";
GRANT SELECT ON ALL TABLES IN SCHEMA "public" TO "anna_lee";
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA "public" TO "anna_lee";

When apply finishes, the rule shows Applied and History lists the change count. If it shows Failed, check Needs attention and Apply a rule.

5. Verify the result#

  1. Open Resources → warehouse-staging and check Roles for each group member with Ownership set to Principal-created.
  2. Ask a group member to open Your access and click Reveal, or click Credentials on their row under Roles and click Reveal.
  3. Connect with psql using the revealed role and password:
    bash
    psql "postgres://[email protected]:5432/app?sslmode=require"
  4. Run a SELECT on a table in public to confirm read access.
  5. Run an INSERT or DELETE on that table and confirm PostgreSQL returns permission denied.
  6. Open Drift and click Check all targets.

Out of sync has no rows for your rule, or shows Everyone has exactly what the rules give. Connector syncs add roles for new members and remove them when members leave. To test out-of-band changes, see Drift.

Next steps#

↑ ↓ to moveEnter to openEsc to close