Connections
Exact hosts and an auth template, owned by an admin. The gateway applies it to every request a linked workflow sends to those hosts.
Create and link
An admin creates the connection. A developer links it to workflows. The workflow code then calls the host without credentials.
# Create or replace a connection (admin key).
# Answers the connection with its version.
curl -X PUT https://api.shiftlabs.org/v1/connections/stripe \
-H "authorization: Bearer $SHIFTLABS_API_KEY" \
-H "content-type: application/json" \
-d '{
"hosts": ["api.stripe.com"],
"template": {
"headers": {"Authorization": "Bearer {{ secret.STRIPE_KEY }}"}
}
}'
# Link it (developer key).
# The list replaces the workflow's links; [] removes them all.
curl -X PUT https://api.shiftlabs.org/v1/workflows/refund-check/connections \
-H "authorization: Bearer $SHIFTLABS_API_KEY" \
-H "content-type: application/json" \
-d '{"connections": ["stripe"]}'
import { workflow } from "shiftlabs";
export default workflow<{ id: string }>(async ({ payload, step }) => {
// No Authorization header: the stripe connection sets it.
const charge = await step.run("fetch charge", () =>
fetch(`https://api.stripe.com/v1/charges/${payload.id}`)
.then((r) => r.json()),
);
return charge.status;
});
from workers import fetch
from shiftlabs import workflow
@workflow
async def refund_check(ctx):
# No Authorization header: the stripe connection sets it.
async def fetch_charge():
r = await fetch(
f"https://api.stripe.com/v1/charges/{ctx.payload['id']}"
)
return await r.json()
charge = await ctx.step.run("fetch charge", fetch_charge)
return charge["status"]
- Name
1 to 63 lowercase letters, digits and hyphens, starting with a letter or digit. Workflows link it by this name.
- Saving
PUTreplaces the whole connection and raises its version. Every secret the template names must already exist. - Linking
A workflow uses only the connections linked to it. Linking an unknown name is refused. You can link before the first deploy.
- Deleting
Deleting a connection unlinks it everywhere and moves it to the trash for 7 days, with its links. An admin can restore it until then. Its name stays taken while it's there: a
PUTreturns409. You can't delete a secret a connection uses. The API returns409withusedBy.
- Admins create, change and delete connections. Developers link them to workflows. Everyone in the workspace, viewers included, can read connections and their templates. Templates contain expressions, not secret values.
- A workspace holds 10 connections on the free tier. Creating one more returns
403 {"error": "quota exceeded", "limit": "connections", "max": 10}. - If an SDK requires an API key, pass a placeholder. The template replaces it. To set credentials in your code yourself, use secret stand-ins.
Hosts
A connection applies only to the hostnames it lists, matched exactly.
- Exact names
1 to 20 hostnames. No wildcards, ports or IP addresses:
api.stripe.comdoes not coverfiles.stripe.com. Names are trimmed, lowercased and de-duplicated. - Shape
At most 253 characters and at least two labels. Each label is 1 to 63 letters, digits or hyphens, not starting or ending with a hyphen, and the last one contains a letter.
- https only
A connection's credentials are only sent over https. A plain
http://request to a covered host is refused. - Overlaps
When two connections linked to one workflow cover the same host, each request must pick one with
x-shiftlabs-connection, or it is refused. The gateway strips the header before forwarding.
await fetch("https://api.stripe.com/v1/transfers", {
method: "POST",
headers: {
"content-type": "application/x-www-form-urlencoded",
"x-shiftlabs-connection": "stripe-connect",
},
body: new URLSearchParams({ amount: "500", currency: "usd" }),
});
await fetch("https://api.stripe.com/v1/transfers", method="POST",
headers={"content-type": "application/x-www-form-urlencoded",
"x-shiftlabs-connection": "stripe-connect"},
body="amount=500¤cy=usd")
The header must name a connection linked to this workflow whose hosts include this host. If only one connection covers the host, you don't need the header.
Requests to hosts that no linked connection covers go out as your code sent them, with any stand-ins replaced.
The template
A JSON object with up to four parts. Every value is a template string: literal text with {{ expressions }} in it.
| Part | Keys | What the gateway does |
|---|---|---|
headers | Header names, up to 128 characters. | Sets each header, replacing any value the code sent. |
query | Parameter names, 1 to 128 characters. | Sets each query parameter, replacing any the code sent. |
path | One template, starting with /. | Replaces the whole path. Expression output is percent-encoded. The literal text around it is kept. |
body.json | JSON pointers, starting with /. | Sets a string at each pointer, creating objects on the way. The request must send content-type: application/json and a JSON object. |
body.form | Form fields, 1 to 128 characters. | Sets each field. The request must send content-type: application/x-www-form-urlencoded. |
// Bearer token
{ "headers": { "Authorization": "Bearer {{ secret.STRIPE_KEY }}" } }
// Basic auth from two secrets
{ "headers": {
"Authorization": "{{ basic(secret.TWILIO_SID, secret.TWILIO_TOKEN) }}" } }
// Key in the query string, account in the path
{ "query": { "key": "{{ secret.MAPS_KEY }}" },
"path": "/v2/accounts/{{ var.ACCOUNT_ID }}/geocode" }
// Token in a JSON body field
{ "body": { "json": { "/auth/token": "{{ secret.PAGER_TOKEN }}" } } }
// Signed request: timestamp and HMAC of the final body
{ "headers": {
"X-Timestamp": "{{ now() }}",
"X-Signature": "{{ hmac_sha256(secret.SIGNING_KEY, now() ~ '.' ~ request.body) | base64 }}"
} }
- At least one entry and at most 32, counted across all parts. Any other top-level key is refused.
bodypatchesjsonorform, not both. - Each template string is at most 2,048 characters, renders to at most 16 KiB, and nests expressions at most 32 deep.
- Reserved headers cannot be set:
Host,Content-Length,Transfer-Encoding,Connection,x-shiftlabs-connection,X-Shiftlabs-TenantandX-Abuse-Contact. - Secrets the template names must exist when you save it. Vars are looked up on each request. If a var is not set, the request is refused.
- The gateway patches the body, then the path, then the query, and renders headers last. Header templates see the final request. Only header templates can read
request.body. - A path template replaces the path the code sent on every request to these hosts.
Expressions
Inside {{ }}: references, quoted text, functions, ~ to join and | to pipe.
| Expression | Gives |
|---|---|
secret.NAME | The secret's value. Only the gateway sees it. |
var.NAME | The calling workflow's var: its own value, or the workspace value. See Vars. |
request.method · request.host | The outgoing request's method and hostname. |
request.path · request.query | Its path, and its query string without the ?. |
request.body | Its body as text, up to 1 MiB. Header templates only. |
oauth.access_token | An OAuth 2.0 connection's access token. Only the gateway sees it. |
'text' · "text" | Literal text, with \n and \t escapes. Use single quotes inside a JSON template to avoid escaping. |
a ~ b | The two joined. |
x | f | The same as f(x). |
x | f(y) | The same as f(x, y). |
( … ) | Grouping. |
| Function | Gives |
|---|---|
base64(x) · base64url(x) · hex(x) | The text or bytes encoded. |
urlencode(x) | The text percent-encoded. |
json(x) | The text as a JSON string, quotes included. |
lower(x) · upper(x) · trim(x) | The text lowercased, uppercased or trimmed. |
sha256(x) | The SHA-256 digest, as bytes. |
hmac_sha256(key, data) · hmac_sha512(key, data) | The HMAC of data under key, as bytes. |
basic(user, password) | Basic and the base64 of user:password: a whole Authorization value. |
now() · now_ms() | The time in Unix seconds or milliseconds, the same for every template in one request. |
uuid() | A random UUID. |
Bytes from sha256 and the HMACs come out as lowercase hex unless you pipe them to base64, base64url or hex. Functions that take text, and ~, don't accept bytes. Encode them first. Functions with no arguments still need their parentheses.
If a template fails at request time, the request is refused with 403 and the reason.
At the gateway
Every fetch your code makes goes through the egress gateway. It handles each request in this order. TCP connections your code opens go through the same gateway, under the rules in TCP.
- Destination
Refuses IP addresses, ports other than 80 and 443, and any
*.shiftlabs.orghost. Allows a set number of requests a minute to one host: 30 on Free, 600 on Pro, and up to 6,000 on Enterprise. Applies to all requests, with or without a connection. - Quota
Counts the request against the workspace's outbound requests: 3,000 per 24 hours on the free tier, then
429. Requests refused by connection rules count too. - Choose
Finds the linked connections whose hosts include this host, or the one named in
x-shiftlabs-connection. Without a match, the request goes out as sent. - Apply
Loads the secrets and vars the template names, patches the request and overwrites what the code set. Each use is audited as
inject, with the connection, host and secret names. - Send
Every request carries
X-Shiftlabs-TenantandX-Abuse-Contact. A request a connection applied to is sent over https only and does not follow redirects. Your code gets the3xx. If it re-issues the request, the rules apply again. - Scrub
If the response to that request echoes a secret, as it was sent (a query parameter or form field percent-encoded, with
+for a space) or in a reversible encoding such as base64, hex or Basic auth, in a header or a text body, your code sees[redacted]. Signatures fromsha256and the HMACs stay visible. Binary bodies pass through unchanged.
Outbound requests · refund-check
4 · 600 a minute to one host · 1 rate limited| Request | Status | Time |
|---|---|---|
| GET api.stripe.comvia connection stripe | 200 | 182 ms |
| GET api.stripe.comno connection | blockedconnection billing is not declared for workflow refund-check | 3 ms |
| POST hooks.slack.comno connection | 200 | 95 ms |
| GET api.stripe.comvia connection stripe | 429 rate limitedrate limited: over 600 requests/min to api.stripe.com | 0 ms |
| Reason | Status | When |
|---|---|---|
connections stripe, stripe-connect all cover api.stripe.com; pick one with the x-shiftlabs-connection header | 403 | Two linked connections cover the host and the request names neither. |
connection billing is not declared for workflow refund-check | 403 | x-shiftlabs-connection names a connection this workflow has not linked. |
connection billing does not cover api.stripe.com | 403 | It names one whose hosts do not include this host. |
credentials are only sent over https | 403 | The request to a covered host is plain http. |
connection stripe patches the body; GET has none | 403 | A body.json or body.form template meets a GET or HEAD. |
connection patches a JSON body; send content-type: application/json | 403 | The content type does not match the body part. The form part needs application/x-www-form-urlencoded. A JSON body that is not an object is refused as well. |
request body too large for a connection that reads or patches it (1 MiB) | 403 | The template patches the body or reads request.body, and the body is over 1 MiB. |
var ACCOUNT_ID used by connection maps is not set | 403 | The template names a var with no value for this workflow. |
connection google isn't connected; an admin must connect it | 403 | An OAuth 2.0 connection no admin has connected yet. |
connection google's OAuth sign-in was revoked or expired; an admin must reconnect it | 403 | The provider refused the connection's refresh token. |
connection google's token couldn't be refreshed: the token endpoint answered 503 | 403 | The access token expired while refreshes kept failing. The reason says why. |
header X-Signature template produced a control character | 403 | A rendered header holds a line break or a NUL. |
quota exceeded: egressPerDay=3000 | 429 | The workspace's outbound requests for the last 24 hours are used up (3,000 on the free tier). |
rate limited: over 30 requests/min to api.stripe.com | 429 | One host got more requests from the workspace in a minute than its plan allows: 30 on Free, 600 on Pro. The count starts again within a minute. |
Every refusal shows in the run's outbound requests with its reason. The heading there also shows the workspace's limit for one host, and how many requests it refused, each marked 429 rate limited. Refusals about which connection applies, or a missing var, are also written to the audit log as blocked.
OAuth 2.0
An OAuth 2.0 connection signs in to an API, such as Google's, with your own OAuth client. An admin connects it once in the dashboard. The vault keeps the access and refresh tokens and refreshes the access token before it expires. The template sends it as {{ oauth.access_token }}, and workflow code never receives either token.
Create one in the dashboard or with the API. In New connection, choose HTTP, then oauth2 under Credentials, and enter your OAuth client's authorize, token and optional revoke URLs, client ID, client secret, scopes and extra authorize parameters. The form shows the redirect URI to register, and the template starts as {"headers": {"Authorization": "Bearer {{ oauth.access_token }}"}}. With the API:
# The OAuth client's secret is a secret like any other (admin key).
curl -X PUT https://api.shiftlabs.org/v1/secrets/GOOGLE_CLIENT_SECRET \
-H "authorization: Bearer $SHIFTLABS_API_KEY" \
-H "content-type: application/json" \
-d '{"value": "GOCSPX-…"}'
# Create the connection. Without a template, requests get
# Authorization: Bearer {{ oauth.access_token }}.
curl -X PUT https://api.shiftlabs.org/v1/connections/google \
-H "authorization: Bearer $SHIFTLABS_API_KEY" \
-H "content-type: application/json" \
-d '{
"hosts": ["www.googleapis.com"],
"oauth2": {
"authorizeUrl": "https://accounts.google.com/o/oauth2/v2/auth",
"tokenUrl": "https://oauth2.googleapis.com/token",
"revokeUrl": "https://oauth2.googleapis.com/revoke",
"clientId": "1234-abcd.apps.googleusercontent.com",
"clientSecret": "{{ secret.GOOGLE_CLIENT_SECRET }}",
"scopes": ["https://www.googleapis.com/auth/drive.readonly"],
"extraAuthorizeParams": {"access_type": "offline", "prompt": "consent"}
}
}'
- Your OAuth client
Add
https://app.shiftlabs.org/oauth/callbackto your OAuth client's redirect URIs. The client and its consent screen are yours. - Connect
An admin opens the connection on the Connections screen and chooses Connect. The provider asks them to consent, then sends them back to the dashboard, and the connection shows Connected. Workflows link it like any connection.
- Refresh
The vault refreshes the access token when 2 minutes or less are left. While the token endpoint fails, it tries again at most every 30 seconds.
- Disconnect
Disconnect revokes the token at
revokeUrl, if you set one, and forgets both tokens. Requests through the connection are refused until an admin connects it again.
authorizeUrl,tokenUrlandrevokeUrlare https URLs on port 443 with a public hostname.clientSecretis a template that uses secrets only. Up to 50scopes, and up to 16extraAuthorizeParams, which can't setresponse_type,client_id,redirect_uri,scope,state,code_challengeorcode_challenge_method.- The template must use
{{ oauth.access_token }}, and only an OAuth 2.0 connection's template can. - Google returns a refresh token only with
access_type=offlineandprompt=consent. Without one, the connection stays Not connected and says why. - The admin who chooses Connect must finish in the same session within 10 minutes.
- Saving the connection with the same client and scopes keeps its tokens. A change to
authorizeUrl,tokenUrl,revokeUrl,clientId,clientSecretorscopesforgets them, and an admin connects it again. Deleting it, or saving it withoutoauth2, forgets them too. Each of these also revokes the old tokens at the oldrevokeUrl, if one was set. In the dashboard, Edit asks before a save that would forget a connected connection's tokens, with Save and forget tokens. - Reconnect replaces the stored sign-in without revoking it. Some providers, Google included, end the app's whole access to the account on any revoke, which would end the new sign-in too. Disconnect first to revoke the old sign-in, for example before connecting a different account. A reconnect that gets no refresh token does revoke the one it replaced.
- Each change of status is audited. A change a refresh makes goes to the workspace's alert emails and webhook as
connections.status.
| Status | Means | Requests through it |
|---|---|---|
Not connected (pending) | No admin has connected it, or the provider sent no refresh token. | Refused |
Connected (connected) | The vault holds a token and refreshes it. | Get the access token |
Refresh failed (refresh_failed) | The token endpoint failed or couldn't be reached. lastError says why. | Get the current token until it expires, then refused |
Revoked (revoked) | The provider refused the refresh token, such as after someone removed the app's access. | Refused until an admin connects it again |
TCP
A TCP connection lists exact host:port targets, such as a Postgres, MySQL or Redis server. Workflow code that links it can open TCP connections to those targets, and to nothing else. For Postgres and Redis, the connection can also hold a login: the gateway logs in with a secret, and your code never holds the password. Pro and Enterprise workspaces have TCP connections. Free workspaces don't.
# Create or replace a TCP connection (admin key).
# Answers the connection with its version.
# The gateway logs in to Postgres as report, with the secret PG_PASSWORD.
curl -X PUT https://api.shiftlabs.org/v1/connections/prod-db \
-H "authorization: Bearer $SHIFTLABS_API_KEY" \
-H "content-type: application/json" \
-d '{
"protocol": "tcp",
"targets": ["db.example.com:5432"],
"tls": "postgres",
"auth": {
"postgres": {"user": "report", "password": "{{ secret.PG_PASSWORD }}"}
}
}'
# Link it like any connection (developer key).
curl -X PUT https://api.shiftlabs.org/v1/workflows/nightly-report/connections \
-H "authorization: Bearer $SHIFTLABS_API_KEY" \
-H "content-type: application/json" \
-d '{"connections": ["prod-db"]}'
import postgres from "postgres";
import { workflow } from "shiftlabs";
export default workflow(async ({ step }) => {
return step.run("count orders", async () => {
// TLS off and any password: the prod-db connection adds TLS, and the
// gateway logs in.
const sql = postgres({
host: "db.example.com",
port: 5432,
database: "shop",
username: "report",
ssl: false,
password: "x",
});
try {
const [row] = await sql`select count(*)::int as n from orders`;
return row.n;
} finally {
await sql.end();
}
});
});
# /// script
# dependencies = ["asyncpg"]
# ///
import asyncpg
from shiftlabs import workflow
@workflow
async def nightly_report(ctx):
# TLS off and any password: the prod-db connection adds TLS, and the
# gateway logs in.
async def count_orders():
conn = await asyncpg.connect(
host="db.example.com",
port=5432,
database="shop",
user="report",
ssl=False,
password="x",
)
try:
return await conn.fetchval("select count(*) from orders")
finally:
await conn.close()
return await ctx.step.run("count orders", count_orders)
- Targets
1 to 20
host:portentries. The host follows the rules for hosts: an exact name, no wildcards, never an IP address, and nevershiftlabs.orgor a subdomain. The port is 1 to 65535. Targets are lowercased, de-duplicated and sorted. - Exact address
Code connects to a target exactly as listed.
db.example.com:5432does not coverdb.example.com:5433. - Its own kind
A TCP connection takes
targets,tlsandauth, nothostsortemplate. To reuse an HTTP connection's name for a TCP one, or the reverse, delete it, then delete it for good from the trash. - One per target
A workflow can link only one TCP connection that covers a target.
import { connect } from "cloudflare:sockets";
// The address must be a target of a TCP connection linked to this workflow.
const socket = connect("db.example.com:5432");
const writer = socket.writable.getWriter();
const reader = socket.readable.getReader();
import asyncio
# The address must be a target of a TCP connection linked to this workflow.
reader, writer = await asyncio.open_connection("db.example.com", 5432)
TypeScript code can use cloudflare:sockets, node:net or a driver built on them. Python code can use socket, asyncio or a driver such as asyncpg.
| Ports | Used for |
|---|---|
| 23 | Telnet |
| 25, 465, 587, 2525 | SMTP (sending mail) |
| 135, 137-139, 445 | Windows RPC and SMB |
| 1900, 5353 | Discovery |
| 6660-6669, 6697 | IRC |
- Special-use names are never targets: names under
.local,.localhost,.internal,.home.arpa,.test,.invalidand.oniondon't name a public server.
tls | What the gateway does |
|---|---|
off | Sends plain text to the server. Use it only on a network you trust. |
on | Speaks TLS from the first byte, as rediss:// does. |
postgres | Sends Postgres' SSLRequest, then upgrades to TLS. Use it for every Postgres server: Postgres 17's direct TLS needs a TLS option the gateway can't send. |
mysql | Reads the MySQL server's greeting, then upgrades to TLS inside MySQL's handshake. Use it for MySQL and MariaDB servers. |
- Connect with TLS off in your code:
ssl: false,ssl=Falseorsslmode=disable. The gateway adds TLS astlssays. Code that asks for TLS itself, withsecureTransport: "on"or"starttls", ornode:tls, fails. A driver that sends an SSLRequest anyway gets "no" whentlsispostgres. Withtlsmysql, your driver is shown a server without TLS, and a driver that asks for TLS anyway is refused. - With
tlsmysql, MySQL 8'scaching_sha2_passwordasks for the password itself on a user's first login after the server starts. Your driver sees no TLS, so it asks for the server's RSA key: the gateway answers with a key of its own, then sends the password to the server over TLS.mysql2does this by default. - The gateway checks the server's certificate against public certificate authorities only. Managed databases that use a private CA, such as Amazon RDS, Google Cloud SQL, Supabase, DigitalOcean and Aiven, fail verification. Neon and Azure use public CAs.
- The TLS the gateway adds can't present a client certificate or trust a private CA. Reach a server that needs either from your own runner: see Client certificates and private CAs.
- With
tlsoff, your code chooses every byte the target gets. A target that is a proxy (HTTP CONNECT, SOCKS), or a front that routes by TLS server name, reaches whatever it forwards to. Declare one only if the workflow may reach all of that.
- Targets per workspace
tcpTargets, counted across all TCP connections: none on Free, 20 on Pro, and as agreed on Enterprise.GET /v1/usagereturnstcpTargets, andlimits.tcpTargetsis the most you can declare. - Connections
TCP and HTTP connections count together toward the workspace's connections.
- Rate
10 new connections a minute to one target from the workspace.
- Length
A connection lasts at most 15 minutes and carries at most 1 GiB each way. It also ends when the workflow step's invocation ends.
- Outbound requests
Each connection that passes the address, port and rate checks counts as one outbound request toward the workspace's quota, including one that no TCP connection covers.
- On Free, saving a TCP connection returns
403 {"error": "TCP connections need the Pro plan", "limit": "tcpTargets", "max": 0}. - Saving more targets than
tcpTargetsallows returns403 {"error": "quota exceeded", "limit": "tcpTargets", "max": 20}.
# The gateway logs in as the ACL user worker, with the secret REDIS_PASSWORD.
curl -X PUT https://api.shiftlabs.org/v1/connections/cache \
-H "authorization: Bearer $SHIFTLABS_API_KEY" \
-H "content-type: application/json" \
-d '{
"protocol": "tcp",
"targets": ["cache.example.com:6380"],
"tls": "on",
"auth": {
"redis": {"user": "worker", "password": "{{ secret.REDIS_PASSWORD }}"}
}
}'
authOptional: a gateway login for Postgres or Redis. It holds one of
postgresorredis, with auserand apassword. The password is a template string, with the same{{ secret.NAME }},{{ var.NAME }}and pipes. It must use at least one secret, and it can't userequestvalues.- The secret
It needs neither hosts nor
readable. The gateway uses it, and your code never receives it. While a connection'sauthuses a secret, the secret can't be deleted. Restoring a connection from the trash whose login's secret is gone returns409with the secret inmissing. - Postgres
useris required. Your code connects with TLS off, and any user and password, or none. The gateway puts the connection'suserin place of your code's, and keeps the database and the other settings. Withtlsonorpostgres, it logs in with SCRAM-SHA-256, MD5 or a cleartext password. Withtlsoff, it logs in only with SCRAM-SHA-256 of at least 4,096 iterations, so nobody on the path can crack the password offline. It checks the server's SCRAM-SHA-256 proof. Then it tells your code the login succeeded. A driver's cancel requests pass to the server unchanged. A Postgres login withtlsmysqlis refused with400 {"error": "auth.postgres needs tls off, on or postgres"}. - Redis
tlsmust beon:AUTHcarries the password as written, so a Redis login withoff,postgresormysqlis refused with400 {"error": "auth.redis needs tls on"}.useris optional. Without it, the gateway logs in as Redis' default user. The gateway sendsAUTHbefore any of your code's commands. Your code's ownAUTHgets+OKfrom the gateway, with any password. AHELLOloses itsAUTHpart. Other commands go to the server as sent. - Without
authYour code logs in itself, with a readable secret. See Passwords over TCP below.
Redis' default user
- Log in as an ACL user without admin commands, for example one with
-@admin. - Redis' default user, with
requirepass, can runCONFIG GET requirepass. That returns the password to whoever is logged in, your workflow code included.
Postgres users
- Any Postgres user can change its own password with
ALTER ROLE CURRENT_USER PASSWORD '…', workflow code included. With the new password, code could log in to the server directly. - Give the connection's user only the privileges the workflow needs.
- Alert on
ALTER ROLEin the server's logs, and on failed gateway logins: each is anerrorin the workspace's outbound traffic.
Passwords over TCP
- Postgres and Redis: use a gateway login with
auth. The secret needs neither hosts norreadable, and your code never receives it. - SSH, MySQL and other servers: a secret an admin marks
readable. Your code reads it withreveal("NAME"), orctx.reveal("NAME")in Python. - A readable secret is the weaker model: the value reaches your code. Every load is audited, and the value is replaced by
[redacted]in logs, in the run's output and in errors. - Apart from a login, and MySQL's handshake with
tlsmysql, the gateway never reads inside a TCP stream. HTTP templates don't apply there, and a stand-in stays literal text.
A refusal reaches your code in the protocol it speaks, and the connection closes. A Postgres client gets a FATAL error (SQLSTATE 08004) whose message starts shiftlabs: . A Redis client gets -ERR shiftlabs: <reason>. Once a target with tls mysql is allowed, a MySQL client gets a server error whose message starts shiftlabs: . Anything else gets one text line, shiftlabs: <reason>. When a Postgres server refuses the gateway's login, or a MySQL server refuses the connection, your code gets the server's own error instead.
| Reason | When |
|---|---|
TCP connections need the Pro plan | The workspace has no TCP targets. |
port 25 is never allowed | The port is one of the ports never allowed. |
TCP targets must be hostnames, not IP addresses | The code connected to an IP address. |
connections to shiftlabs.org are not allowed from workflows | The host is shiftlabs.org or a subdomain. |
.local names are not allowed | The host is a special-use name. |
no TCP connection linked to workflow nightly-report covers db.example.com:5433 | No TCP connection the workflow links lists this host:port. |
rate limited: over 10 connections/min to db.example.com:5432 | More than 10 new connections to one target in a minute. |
quota exceeded: egressPerDay=1000000 | The workspace's outbound requests for the last 24 hours are used up. |
could not connect to db.example.com:5432: <detail> | The server could not be reached. The detail says why. |
db.example.com:5432 does not offer TLS | tls is on, postgres or mysql, and the server didn't start TLS, or its MySQL greeting doesn't offer it. |
db.example.com:3306 did not send a MySQL greeting | tls is mysql, and the server's first packet isn't a MySQL greeting. |
db.example.com:3306 sent no MySQL greeting within 10 s | tls is mysql, and the server sent no greeting within 10 seconds. |
db.example.com:3306 sent more than its greeting before TLS | tls is mysql, and the server sent more bytes after its greeting, before TLS started. |
db.example.com:3306 refused the connection: <error> | tls is mysql, and the server sent an error instead of a greeting, such as for a host it doesn't allow. Your code gets the server's own error, as the server sent it. |
the code asked for TLS; connect with TLS off, and tls mysql adds it | tls is mysql, and your code's driver asked for TLS itself. |
the code did not answer the MySQL greeting | tls is mysql, and your code sent no handshake response within 10 seconds. |
the code's MySQL handshake response is malformed | tls is mysql, and your code's handshake response isn't one MySQL 4.1 or later sends. |
the address is not a valid host:port | The address the code connected to isn't a hostname and a port, such as a number or a URL. The reason never repeats the address. |
password authentication failed for user "report" | Postgres refused the gateway's login. Your code gets the server's own error, as the server sent it. |
the server refused the login: WRONGPASS invalid username-password pair or user is disabled. | Redis refused the gateway's login. The reason ends with the server's error line. |
the server asks for a cleartext password, which the gateway sends only over TLS; set tls to on or postgres | Postgres asked for a cleartext password, and tls is off. |
the server asks for an MD5 password, which the gateway sends only over TLS; set tls to on or postgres | Postgres asked for an MD5 password, and tls is off. |
the server offers <mechanisms>; the gateway logs in with SCRAM-SHA-256 | Postgres offered a SASL login without SCRAM-SHA-256. |
the server asks for a login the gateway doesn't support (authentication method <n>) | Postgres asked for a login other than SCRAM-SHA-256, MD5 or a cleartext password. |
the server could not prove it knows the password | The server's SCRAM-SHA-256 proof was wrong or missing. |
the server sent an unexpected message during the login | The server's login messages came out of order. |
the server asks for <n> SCRAM iterations; the gateway allows 1 to 100,000 | The server's SCRAM-SHA-256 login asks for too many iterations. With tls off, the gateway allows 4,096 to 100,000. |
the server did not finish the login within 10 s | The whole login took longer than 10 seconds. |
the server refused the login with an error that isn't shown, since it may echo the password | Redis answered the gateway's AUTH with an error other than WRONGPASS or NOAUTH. |
connection prod-db changed since its login was saved; save it again | An older version of shiftlabs changed the connection without its login. Save it again with its auth. |
the code did not open a Postgres connection | The connection has a Postgres login, and your code didn't start a Postgres connection. |
secret PG_PASSWORD used by connection prod-db no longer exists | A secret the login uses was deleted. |
var DB_SUFFIX used by connection prod-db is not set | A var the login uses is not set. |
- Firewalls
The addresses TCP connections come from are not published, so a database that allow-lists IP addresses can't allow-list shiftlabs yet.
- Unreachable targets
Connections can't reach Cloudflare's own addresses or private addresses. A target hosted behind Cloudflare, or a name that resolves to a private address, gets
could not connect to <host:port>: <detail>. - SSH
Workflows have no SSH client.
- Agents
Agents reach a database only through a workflow. Their code tools have no network.
- Audit
Each connection the gateway allows is audited as
socket, with the connection name, thehost:port, itstlsmode, its login inauth(postgres,redisornull) and thesecretsthe login uses. A connection to a target that no linked TCP connection covers, or whose login's secret or var is gone, is audited asblocked. - Outbound traffic
Each attempt is recorded with its target, port, outcome, bytes each way and duration. A failed login is recorded as an
error, with its reason. TCP traffic carries no run, so it isn't listed under a run's outbound requests.
Client certificates and private CAs
Workflow code can't present a client certificate (mTLS) or trust a private certificate authority. Reach such a server from a runner in your network instead, with step.exec or a registered activity. The certificate, its key and the CA stay in files on the runner's host.
import { workflow } from "shiftlabs";
export default workflow(async ({ step }) => {
// The files are on the runner's host, mounted into its container.
const r = await step.exec("ledger balance", {
command: [
"curl", "-fsS",
"--cert", "/etc/ledger-tls/client.crt",
"--key", "/etc/ledger-tls/client.key",
"--cacert", "/etc/ledger-tls/ca.crt",
"https://ledger.corp.example.com/v1/balance",
],
});
return r.stdout;
});
from shiftlabs import workflow
@workflow
async def ledger_balance(ctx):
# The files are on the runner's host, mounted into its container.
r = await ctx.step.exec(
"ledger balance",
command=[
"curl", "-fsS",
"--cert", "/etc/ledger-tls/client.crt",
"--key", "/etc/ledger-tls/client.key",
"--cacert", "/etc/ledger-tls/ca.crt",
"https://ledger.corp.example.com/v1/balance",
],
)
return r["stdout"]
- Mount the folder into the runner's container read-only, such as
-v /srv/ledger-tls:/etc/ledger-tls:rowith Docker. The files must be readable by uid 1000. - Don't store the key, the certificate or the CA as a shiftlabs secret. Left on the runner's host, they never reach shiftlabs.
- For a server with a private CA that asks for no client certificate,
--cacertalone is enough. Any client on the runner works the same way, such as Python'sssl. - A command's requests leave from the runner's host, not through the gateway, so connections don't apply to them.
- The gateway's own
fetchsends no client certificate and checks servers against public certificate authorities only, as its TCP TLS does.
Dashboard and API
Manage connections in the dashboard or with the /v1 API. Roles are the same in both.
- Connections screen
Every connection with its hosts, the secrets and vars its template uses, its version, and an OAuth 2.0 connection's status, last refresh and who connected it. Admins create one with a name, hosts one per line and the template in a JSON editor, and for an OAuth 2.0 connection, oauth2 under Credentials with its client's URLs, client ID, client secret, scopes and extra authorize parameters. They edit or delete it from its panel, where they also connect or disconnect an OAuth 2.0 connection. Edit asks before a save that changes a connected OAuth 2.0 client and so forgets its tokens.
- Workflows screen
Open a workflow and find its Connections section. Developers and admins choose Edit links, tick the connections the workflow uses and save.
- Audit
connection_put,connection_delete,connection_restore,connection_purge,workflow_link,inject,socket,blocked, and for OAuth 2.0oauth_connect,oauth_refresh,oauth_refresh_failed,oauth_revokedandoauth_disconnect, for admins on the Audit screen and at/v1/audit.
| Route | Method | Minimum role |
|---|---|---|
/v1/connections [{name, hosts, template, secrets, vars, version, updatedAt}]; TCP connections add protocol, targets, tls and auth, and their secrets and vars are the ones auth's password uses; OAuth 2.0 connections add oauth2 and oauth: {status, lastError, refreshedAt, consentedBy, consentedAt} | GET | viewer |
/v1/connections/:name {"hosts", "template"}, {"hosts", "oauth2", "template"?} for OAuth 2.0, or {"protocol": "tcp", "targets", "tls", "auth"?} for TCP; returns the connection | PUT | admin |
/v1/connections/:name {"deleted": name, "purgeAt"}; moves it to the trash for 7 days, and its name stays taken while it's there (409); or 404 | DELETE | admin |
/v1/connections/:name/oauth/start {url}, the provider's consent page; from the dashboard only | POST | admin |
/v1/connections/oauth/callback {"code", "state"} from the provider's redirect; returns the connection; from the dashboard only | POST | admin |
/v1/connections/:name/oauth revokes and forgets the tokens; returns the connection | DELETE | admin |
/v1/workflows/:workflow/connections the linked names | GET | viewer |
/v1/workflows/:workflow/connections {"connections": [...]}; returns the linked names | PUT | developer |