Skip to main content

PostgreSQL Data Connectors

· 6 min read

proxiML now supports PostgreSQL data connectors, letting your jobs read and write your own database without copying the data into the platform. Configure the connection once at the region level, attach it to a job, and your code connects to a local proxiML hostname while proxiML handles authentication to your server.

How It Works​

Data connectors are region-scoped CloudBender resources that record where an external service lives and how to authenticate to it. Previously only raw network rules (custom) were available. Now you can point a connector at a PostgreSQL server, and proxiML:

  • Stores the connection's credentials, encrypted at rest, and never returns them through the proxiML API.
  • When a job using the connector starts, runs a private connection proxy between the job and your server and injects the configured authentication.
  • Gives the job a local hostname, http://CONNECTOR_ID.proximl.internal, instead of your server's real address. The job's network egress is fenced to the connector, so it can only reach your database through it.

The result is that your job code contains no credentials and no knowledge of your database's network location, and your server never sees traffic from the platform's network directly.

Supported Authentication​

A PostgreSQL connector supports two auth methods:

Username and Password -- The connector authenticates to your server as the given role using SCRAM authentication.

Certificate -- The connector presents a client certificate over a mutual TLS (mTLS) connection. Your server must use a pg_hba.conf cert rule, and the client certificate's common name (CN) determines the PostgreSQL role the job connects as. This works well for environments where database access is certificate-gated and passwords are not issued.

Both methods support an optional CA Certificate and a Use TLS toggle (on by default). When TLS is enabled, the connector encrypts the connection to your server; provide the CA certificate to also verify your server's certificate against a specific CA. Without a CA certificate, the connection is still encrypted but the server's certificate is not verified. Certificate auth always requires TLS, so the toggle is locked on for it.

Over the next few days we will announce two more connector types -- Redis on Friday and HTTP on Monday -- each with its own set of supported auth methods.

Using the Web Platform​

Select View Region from the action menu of the region your PostgreSQL server is reachable from, then click the Add button on the Data Connectors toolbar.

  • Name -- A unique name for the connector (lowercase letters, digits, and hyphens).
  • Type -- PostgreSQL.
  • Host -- The hostname or IP address of your PostgreSQL server.
  • Port -- The port your server listens on. Defaults to 5432.
  • Use TLS -- Encrypt the connection to your server. On by default and locked on for Certificate auth.
  • CA Certificate -- Optional PEM-encoded CA certificate. Shown when TLS is enabled. Pins the CA to verify your server's certificate against; when left blank the connection is encrypted but the server's certificate is not verified.
  • Database -- The database name your jobs should connect to.
  • Auth Method -- Username and Password (prompts for a username and password) or Certificate (prompts for your client certificate and client private key in PEM format).

The connector is saved when you click Submit. When editing an existing connector, leave a secret field blank to keep its current value, or enter a new value to rotate it. The connector type and auth method cannot be changed after creation.

Using the SDK​

Create a password-authenticated connector:

connector = await proximl.cloudbender.data_connectors.create( provider_uuid="PROVIDER_ID", region_uuid="REGION_ID", name="pg-primary", type="pg", host="db.internal.example.com", port=5432, database="mydb", auth_type="password", username="proxiML", password="PASSWORD", )

Or one that authenticates with a client certificate:

connector = await proximl.cloudbender.data_connectors.create(
provider_uuid="PROVIDER_ID",
region_uuid="REGION_ID",
name="pg-cert",
type="pg",
host="db.internal.example.com",
port=5432,
database="mydb",
auth_type="certificate",
ca_certificate=open("ca.crt").read(),
client_certificate=open("client.crt").read(),
client_private_key=open("client.key").read(),
)

Then enable the connector for your project (from the Data Connectors section of the project page) and attach it to a job by its ID:

job = await proximl.jobs.create(
name="pg-training-job",
type="training",
gpu_type="rtx3090",
gpu_count=1,
data=dict(connectors=[connector.id]),
)

Inside the job, connect to the connector's local hostname instead of your server:

import psycopg2

conn = psycopg2.connect(
host="pg-primary-0123456789abcdef.proximl.internal",
port=5432,
dbname="mydb",
user="postgres",
)
cur = conn.cursor()
cur.execute("SELECT * FROM training_data LIMIT 1")

Use the connector's actual ID (shown in the Data Connectors grid, returned by create, or listed with data_connectors.list) in place of the placeholder above. The username and password here are ignored by the connector -- any value (or none) will do, since the connector performs the real authentication to your server, using the credentials and database configured on the connector.

Using the CLI​

# List connectors in a region (ID, NAME, TYPE, HOST, AUTH_TYPE, PROTOCOL)
trainml cloudbender data_connector list --provider PROVIDER_ID --region REGION_ID

# Create a password-authenticated connector (TLS on by default)
trainml cloudbender data_connector create pg-primary \
--provider PROVIDER_ID --region REGION_ID \
--type pg --host db.internal.example.com --port 5432 --database mydb \
--auth-type password --username proxiML --password "PASSWORD"

# Plaintext upstream: disable TLS with --no-tls
trainml cloudbender data_connector create pg-plaintext \
--provider PROVIDER_ID --region REGION_ID \
--type pg --host db.internal.example.com --port 5432 --database mydb \
--no-tls --auth-type password --username proxiML --password "PASSWORD"

# Create a certificate-authenticated connector (files keep PEM out of shell history)
trainml cloudbender data_connector create pg-cert \
--provider PROVIDER_ID --region REGION_ID \
--type pg --host db.internal.example.com --port 5432 --database mydb \
--auth-type certificate \
--ca-certificate-file ca.crt \
--client-certificate-file client.crt \
--client-private-key-file client.key

# Rotate a password without re-entering the other settings
trainml cloudbender data_connector edit pg-primary \
--provider PROVIDER_ID --region REGION_ID \
--password "NEW_PASSWORD"

# Remove a connector
trainml cloudbender data_connector remove pg-primary \
--provider PROVIDER_ID --region REGION_ID

Security Notes​

  • Credentials are encrypted at rest with the same passphrase scheme proxiML uses for other secrets, and secret fields are never returned by the proxiML API.
  • The job's network egress is restricted to its connectors, so a job can only talk to your database through the authenticated connector.
  • With TLS enabled (the default), the connection to your server is encrypted. Provide the CA certificate to also verify your server's certificate against a specific CA; without it the connection is encrypted but unverified.

See the CloudBender reference for the full data connector field reference, and keep an eye out for the Redis and HTTP connector announcements later this week.