How It Works
PostgreSQL access in Infisical PAM uses an Infisical Gateway to securely proxy connections to your PostgreSQL server. When a user requests access, Infisical establishes a secure tunnel through the Gateway, enabling secure access without exposing your PostgreSQL instance directly.Key Concepts
- Gateway: An Infisical Gateway deployed in your network that can reach the PostgreSQL server. The Gateway handles secure communication between users and your PostgreSQL instance.
- Authentication: Credentials (username/password) are stored securely in Infisical and used by the Gateway to authenticate with PostgreSQL on behalf of the user.
- Local Proxy: The Infisical CLI starts a local proxy on your machine that intercepts PostgreSQL connections and routes them securely through the Gateway to your PostgreSQL instance.
- Session Tracking: All access sessions are logged, including when the session was created, who accessed the PostgreSQL instance, session duration, and when it ended.
Session Tracking
Infisical tracks:- When the session was created
- Who accessed which PostgreSQL instance
- Session duration
- When the session ended
Session Logs: After ending a session (by stopping the proxy), you can view
detailed session logs in the Sessions page.
Prerequisites
Before configuring PostgreSQL access in Infisical PAM, you need:- Infisical Gateway - A Gateway deployed in your network with access to the PostgreSQL server
- PostgreSQL Credentials - Username and password for the PostgreSQL instance
- Infisical CLI - The Infisical CLI installed on user machines
Create the PAM Resource
The PAM Resource represents the connection between Infisical and your PostgreSQL instance.Ensure Gateway is Running
Before creating the resource, ensure you have an Infisical Gateway running and registered with your Infisical instance. The Gateway must have network access to your PostgreSQL server.
Create the Resource in Infisical
- Navigate to your PAM project and go to the Resources tab
- Click Add Resource and select PostgreSQL
-
Enter a Name for the resource (e.g.,
production-postgres,staging-db) - Select the Gateway that has access to this PostgreSQL instance
-
Enter the Host - the hostname or IP address of your PostgreSQL server (e.g.,
postgres.example.comor192.168.1.100) - Enter the Database Name - the database to connect to
-
Enter the Port - the PostgreSQL port (default:
5432) -
Configure SSL/TLS options:
- Enable SSL: Toggle to enable TLS/SSL connections (enabled by default)
- Reject Unauthorized: Toggle to verify SSL certificates (enabled by default, recommended for production)
- Trusted CA SSL Certificate: Optional CA certificate for custom certificate authorities
- Optionally configure a Rotation Account by providing a username and password. This is required if you want to enable automated credential rotation for accounts on this resource.
SSL Configuration: SSL is enabled by default. For self-signed certificates, you may need to provide the CA certificate or disable certificate validation (not recommended for production).
Create PAM Accounts
Once you have configured the PAM resource, you’ll need to configure a PAM account for your PostgreSQL resource. A PAM Account represents a specific set of credentials that users can request access to. You can create multiple accounts per resource, each with different permission levels.Navigate to Resource
Go to the Resources tab in your PAM project and open the PostgreSQL resource you created.
Fill in Account Details
Fill in the account details:If the resource has rotation account credentials configured, you can also enable Credential Rotation for this account and select a rotation interval (1 day, 3 days, 7 days, or 30 days).
A friendly name for this account (e.g.,
readonly-user, admin-access)An optional description for this account.
The PostgreSQL username.
The PostgreSQL password.
When enabled, users must complete a multi-factor authentication (MFA) challenge before accessing this account. The MFA method used is determined by the organization’s enforced method, the user’s configured method, or email as a fallback.
Access PostgreSQL Account
There are two ways to access a PostgreSQL account: through the browser via Web Access, or locally via the CLI.Web Access
PostgreSQL resources can be accessed directly from the browser using Infisical’s web-based SQL console. This provides a convenient way to run queries without installing any local tools. For details, see PostgreSQL Web Access.CLI Access
The Infisical CLI starts a local proxy that allows you to connect with any PostgreSQL client (psql, pgAdmin, DBeaver, etc.) and supports multiple concurrent connections per session.Get the Access Command
- Navigate to the Resources tab in your PAM project and open the PostgreSQL resource
- In the resource’s accounts section, find the account you want to access
- Click the Access button for that account
- Copy the provided CLI command
Run the Access Command
Run the copied command in your terminal.The CLI will:
- Authenticate with Infisical
- Establish a secure connection through the Gateway
- Start a local proxy on your machine
- Display a local connection URL you can use to connect
Connect to PostgreSQL
Once the proxy is running, connect to PostgreSQL using the connection URL displayed by the CLI. You can use any PostgreSQL client — no password is needed, as the Gateway injects the real credentials on your behalf.Using psql:Using other clients:You can also use GUI clients such as pgAdmin, DBeaver, DataGrip, or TablePlus. Point them to
localhost on the port shown in the CLI output with the username and database from the connection URL. Leave the password field empty.