Files
floci/docs/services/dsql.md
T
Alessandro Lattao f2b62fbbec feat(dsql): serve each cluster's database on the DSQL endpoint (#6102)
* feat(dsql): serve each cluster's database on the DSQL endpoint

Each Aurora DSQL cluster gets a PostgreSQL 16 database in a Docker container,
set up as DSQL's (the role admin owning public, repeatable read), and every
cluster is served on one TLS endpoint where the server name picks the cluster.
A connection is admitted as DSQL admits it, measured on AWS: an IAM token for
the endpoint, DbConnectAdmin for admin, 5 seconds of grace past expiry, a
long-term key only in its own account, IAM enforcement with the account's SCPs,
and DSQL's SQLSTATE, text and hint for every refusal. A role other than admin
is refused as an unmapped one, since role mappings come with AWS IAM GRANT in
the next part. The startup is read as DSQL reads it: a dotted parameter is
refused, and of options only -c name=value counts, the first for a name.

The cluster is CREATING until its database answers; a multi-Region peer is
ACTIVE after peering only once its database answers. A start that fails after
the container exists removes it, a deletion Docker cannot finish leaves the
cluster DELETING for the next start, and whether a cluster is wanted and its
route change under one lock, so a deletion racing a start leaves no route.

The data plane was first one PR; it is split by layer at the maintainer's
request: this part (transport and admin), then AWS IAM GRANT and the other
roles, then DSQL's dialect and limits.

* refactor(postgres): speak PostgreSQL's wire protocol through one shared helper

The DSQL endpoint brought a third copy of the startup parsing, message framing
and ErrorResponse building that the RDS proxy's PostgresProtocolHandler and
Redshift's PostgresWireDecoder each carried. They now go through
core.common.PostgresWire: the startup packet and its parameters, reading and
writing a message with its checked length, and the fields of an ErrorResponse
or NoticeResponse. The length refusals keep the RDS proxy's wording, which its
tests assert; Redshift's oversized-message refusal now reads the same way.

Also from the review: the DSQL integration test makes its IAM users with
EnforcementFixtures.createUser, which removes them after the test; the service
test shares one ready-at-once provision stub; and every exception the endpoint
and session swallow is named ignored, with the reason it is safe.
2026-10-21 08:54:07 -04:00

9.5 KiB

Aurora DSQL

Protocol: REST JSON (control plane) + PostgreSQL wire protocol over TLS (clusters)

Endpoint: http://localhost:4566 (control plane), <cluster-id>.dsql.<region>.localhost.floci.io:5432 (clusters)

Floci runs each Aurora DSQL cluster as a real PostgreSQL 16 database in a Docker container, behind one endpoint that admits clients the way DSQL does: TLS and an IAM token as the password. The answers, messages and SQLSTATEs below were measured on AWS.

Supported Actions

Action Description
CreateCluster Creates a cluster, CREATING until its database answers, then ACTIVE, or PENDING_SETUP for a multi-Region one; deletion protection is on unless turned off
ListClusters Lists the Region's clusters, paginated
GetCluster Returns a cluster, its endpoint and encryption details
UpdateCluster Changes deletion protection, the KMS key and the multi-Region properties
DeleteCluster Deletes a cluster and its database, DELETING in the answer or PENDING_DELETE for a multi-Region one; refused while deletion protection is on
GetVpcEndpointServiceName Returns the Region's VPC endpoint service name
PutClusterPolicy Sets the cluster's resource policy once it passes DSQL's checks, with optimistic versioning
GetClusterPolicy Returns the resource policy in DSQL's form, and its version
DeleteClusterPolicy Removes the resource policy, answering the version removed

TagResource, UntagResource and ListTagsForResource work on cluster ARNs. As on AWS, an ARN that is not a well-formed cluster ARN is refused with AccessDeniedException, one of another Region with BadRequestException, and one of no cluster with NotFoundException. Cluster identifiers are 26 characters of lowercase base32, as DSQL's are, and invalid ones are refused with DSQL's messages.

A cluster created with a witness Region is PENDING_SETUP, and lists itself among its clusters. Once it and each peer it is updated with name one another, all of them are ACTIVE, as on AWS, where this takes about two minutes; a cluster whose database has not answered yet is CREATING until it does. Each has a database of its own; nothing is replicated between them. A customer-managed KMS key is recorded and reported; nothing is encrypted with it.

Connecting

A cluster's endpoint is <cluster-id>.dsql.<region>.localhost.floci.io, port 5432. localhost.floci.io resolves to 127.0.0.1 on the host, and to Floci inside the containers Floci starts, so the same endpoint works from both. All clusters share the port: the TLS server name a client sends picks the cluster, as DNS does on AWS.

TLS is mandatory. The certificate covers *.dsql.<region>.localhost.floci.io for every Region and is signed by Floci's local CA (GET /_floci/ca.pem, see TLS), which the containers Floci starts already trust, so sslmode=verify-full works.

The password is an IAM authentication token for the endpoint, generated by the SDKs and the CLI exactly as for AWS:

curl -s http://localhost:4566/_floci/ca.pem -o floci-root-ca.pem
export PGPASSWORD=$(AWS_ACCESS_KEY_ID=test AWS_SECRET_ACCESS_KEY=test \
  aws dsql generate-db-connect-admin-auth-token --region us-east-1 \
  --hostname <cluster-id>.dsql.us-east-1.localhost.floci.io)
psql "host=<cluster-id>.dsql.us-east-1.localhost.floci.io port=5432 user=admin dbname=postgres \
  sslmode=verify-full sslrootcert=floci-root-ca.pem"

When Floci runs in Docker, publish 5432 alongside 4566.

Authentication

  • admin signs in with a DbConnectAdmin token; every other role with a DbConnect token. The wrong action is refused with the hint Wrong user to action mapping. user: <user>, action: <action>.
  • A token is accepted up to 5 seconds past its expiry, as DSQL accepts it; after that the hint is Signature expired: ....
  • Only admin signs in. DSQL lets another role in only for an IAM role that AWS IAM GRANT mapped to it, which Floci does not support yet, so every other role is refused as an unmapped one is.
  • The signature is verified like any other Floci IAM token: the test key, or a key or session Floci issued. With FLOCI_SERVICES_IAM_ENFORCEMENT_ENABLED, the principal also needs dsql:DbConnectAdmin or dsql:DbConnect on the cluster ARN.
  • Refusals are FATAL with DSQL's text and a Session Id detail: 08P01 without TLS, 08006 for a token refused, 28000 for a role the token cannot sign in as, 55000 for any database other than postgres, and 42704 for a custom (dotted) parameter in the startup.
  • options is read as DSQL reads it: only -c name=value counts, the first one for a name wins, and every other word, --name=value included, is ignored.

SQL

The database is PostgreSQL 16 at REPEATABLE READ, as DSQL's is, with the role admin, which owns the public schema and can create roles and databases. A connection closes after an hour, as DSQL closes it.

Differences from AWS

  • DSQL's SQL dialect is not applied: what DSQL adds to PostgreSQL (CREATE INDEX ASYNC, AWS IAM GRANT, the sys functions) is refused as PostgreSQL refuses it, what DSQL refuses works, and DSQL's transaction limits (one DDL statement, 3,000 rows, 300 seconds) do not apply.
  • DSQL is optimistic: conflicting transactions both run and the second to commit fails with 40001. Floci's database is PostgreSQL, so a write that conflicts waits for the other transaction, then fails with PostgreSQL's 40001.
  • DSQL accepts connections while a cluster is still CREATING; Floci's cluster is CREATING only while its database starts, and serves once its database answers.

Cluster policies

PutClusterPolicy, and CreateCluster with a policy, check the document as DSQL does and refuse it with DSQL's messages:

  • JSON that does not parse, and a statement with no Principal or Resource, or with NotPrincipal or NotResource;
  • a document missing or misusing an element: no Statement, a Version other than 2008-10-17 or 2012-10-17, a member of no policy grammar, an Effect other than Allow or Deny, an unknown condition operator (operators are matched as written), and a principal that names no one: an IAM role or user is looked up in its account, and an account is always taken to exist;
  • a service principal;
  • an Allow to everyone ("*" or an AWS "*") that no condition restricts. A condition restricts with one of the trusted keys of DSQL's block public access page, or aws:SourceIp, aws:SourceVpcArn, aws:VpceAccount, aws:VpceOrgID or aws:VpceOrgPaths, which DSQL also accepts: under a string equality, or a pattern without a wildcard (for an ARN, without one in the account), and never with a policy variable; with an aws:SourceIp prefix of at least /8 for IPv4 or /32 for IPv6; or with aws:PrincipalIsAWSService true. IfExists, ForAllValues: and negated operators never restrict;
  • a policy that explicitly denies the caller both dsql:PutClusterPolicy and dsql:DeleteClusterPolicy, unless bypassPolicyLockoutSafetyCheck is true.

The policy is kept and returned in DSQL's form: pretty-printed, its elements in DSQL's order, a list of one value written as that value, condition values as text, an account id as its root ARN, and 2008-10-17 when it has no Version. A policy's version is the time it was set, in epoch milliseconds. Cluster policies are not enforced: Floci's IAM enforcement checks a connection's identity policies (see Authentication), and no control plane call.

CloudFormation

AWS::DSQL::Cluster waits for ACTIVE, or PENDING_SETUP for a multi-Region cluster. Ref returns the identifier; Fn::GetAtt supports Identifier, ResourceArn, Status, CreationTime, Endpoint, VpcEndpoint, VpcEndpointServiceName and, while the cluster has a policy, PolicyVersion. Properties are checked against the resource schema's types, as on AWS (a PolicyDocument is text). An update leaves a property the template no longer sets as it was, deletion protection included, but removes the tags and the policy it no longer sets; a policy the template does not change keeps its version. A protected cluster makes the stack's deletion fail, as on AWS.

Configuration

Variable Default Description
FLOCI_SERVICES_DSQL_ENABLED true Enable or disable Aurora DSQL
FLOCI_SERVICES_DSQL_MOCK false Clusters without a database, ACTIVE at once and without Docker: enough for the control plane and CloudFormation
FLOCI_SERVICES_DSQL_PORT 5432 Port every cluster endpoint is served on
FLOCI_SERVICES_DSQL_ENDPOINT_SUFFIX localhost.floci.io Domain the endpoints are named under, <cluster-id>.dsql.<region>.<suffix>
FLOCI_SERVICES_DSQL_IMAGE postgres:16-alpine Image each cluster's database runs in
FLOCI_SERVICES_DSQL_DOCKER_NETWORK Floci's network Docker network for the databases

A cluster's data lives in a Docker volume of its own, or under the host persistent path, and is removed with the cluster under the same policy as RDS's (prune-volumes-on-delete). With persistent storage a cluster comes back, with its data, when Floci restarts.

See the Aurora DSQL API Reference and the Aurora DSQL User Guide.