Files
floci/docs/services/dsql.md
T
Alessandro Lattao 95bf6df474 feat(dsql): add Aurora DSQL's control plane and AWS::DSQL::Cluster (#6048)
* feat(dsql): add Aurora DSQL's control plane and AWS::DSQL::Cluster

The first half of #6014. Aurora DSQL's REST JSON control plane, with
the answers measured on AWS (eu-west-1): CreateCluster, GetCluster,
ListClusters, UpdateCluster, DeleteCluster, GetVpcEndpointServiceName,
the cluster policy calls and tagging on cluster ARNs. Identifiers are 26
characters of lowercase base32 as DSQL's are, and malformed or unknown
ones are refused with DSQL's messages; a cluster created without
deletionProtectionEnabled is protected, and deleting a protected one is
refused. CreateCluster answers CREATING and the cluster is ACTIVE right
after.

AWS::DSQL::Cluster waits for ACTIVE, returns the identifier from Ref
and Identifier, ResourceArn, Status, CreationTime, Endpoint, VpcEndpoint
and VpcEndpointServiceName through Fn::GetAtt, and a protected cluster
makes the stack's deletion fail, as on AWS.

A cluster has no database behind it here: its endpoint is named as on
AWS, <id>.dsql.<region>.localhost.floci.io, but not served. Serving it
is the second half of #6014, its own pull request.

* fix(dsql): answer the control plane's edge cases as DSQL does

Review of #6048, each answer measured on DSQL (eu-west-1) first:
- ListClusters carries on from a page token whose cluster was deleted
  in between, as AWS does: the token now holds the sort position of the
  next page's first cluster rather than its identifier.
- deletionProtectionEnabled is read as DSQL reads it: text is false
  when it spells false in any case and true otherwise; empty text, a
  number, an object and a list fail with SerializationException.
- The tag calls refuse another account's cluster ARN with 403
  AccessDeniedException instead of reading it in the caller's account.
- A client token reused with other parameters answers 409
  ConflictException; with the same ones, the earlier cluster.
- AWS_OWNED_KMS_KEY names AWS's own key on create and update.

AWS::DSQL::Cluster reads DeletionProtectionEnabled and PolicyDocument
with AWS::NoValue as left out, and an update that drops the
multi-Region properties clears them, as it already reset the key and
deletion protection. ListTagsForResource copies the tags under the
cluster's lock, and a cluster's lock goes with the cluster.

* fix(dsql): answer errors, policies, updates and multi-Region clusters as DSQL does

A review asked for the attribute coverage, the reason ValidationException
carries, a real untag assertion and tests of the stack-update path.
Measuring them on DSQL (eu-west-1, 2026-10-20) found more that did not
match, fixed here too.

- Attributes are written with resource.getAttributes().put, which the
  schema coverage test reads; EncryptionDetails, an object an output
  refuses on AWS, is recorded as a gap.
- DSQL leaves reason out of its model-validation errors. Only the page
  token's refusal carries it, with fieldList naming next-token and its
  own text. maxResults no longer quotes the value.
- Tag calls answer what DSQL answers: 403 for an ARN that is not a
  cluster ARN, 400 BadRequestException for another Region's, 404
  NotFoundException for no cluster. The 403s name the caller.
- Policy versions are epoch milliseconds, DeleteClusterPolicy answers
  the deleted version, and the missing-policy and stale-version errors
  carry DSQL's texts and resourceType.
- Policies are checked and kept as DSQL does: its three refusal texts,
  a service principal, a principal that names no one, a public grant,
  and the lockout check when both policy actions are denied to the
  caller, unless bypassPolicyLockoutSafetyCheck. The kept form is
  Jackson's pretty printer in DSQL's element order, with condition
  operators and keys in HashMap order, as measured.
- The public check shares its condition keys with Lambda web functions
  through PublicAccessConditions, and S3 now takes its fixed-value and
  SourceIp range tests from there. Sharing the whole rule was tried and
  dropped: DSQL was measured to treat some operators otherwise than
  LambdaWeb's and S3's rules do (ForAnyValue:, ArnLike "*",
  StringEquals "*"), so the operator rules stay per service. The
  lockout check is IamPolicyEvaluator's.
- A multi-Region cluster is PENDING_SETUP and lists itself until it and
  each peer name one another, then ACTIVE; its deletion answers
  PENDING_DELETE.
- AWS::DSQL::Cluster reads its properties through CfnPropertyTypes, so
  a PolicyDocument object or DeletionProtectionEnabled "yes" fails as
  on AWS, where Boolean.valueOf made "yes" false. An update leaves a
  property the template no longer sets as it was, deletion protection,
  KMS key and multi-Region alike, and removes only the tags and the
  policy; an earlier change put them back to their defaults, which was
  not measured and is not what CloudFormation does. A policy the
  template does not change keeps its version, and create settles on
  PENDING_SETUP too.

DsqlServiceTest, DsqlClusterPoliciesTest and DsqlCfnProvisionerTest
cover these in isolation, the integration tests over the wire.

* fix(dsql): keep the public access rule to DSQL and forget a deleted policy's version

A review asked to leave S3 and Lambda web functions out of this change,
and pointed at DSQL's own block public access page. The shared helper
is dropped and S3 and Lambda web functions are as on main; folding
their copies into one helper belongs to a separate change.

DSQL now has its own keys: the trusted ones its page lists, and
aws:SourceIp, aws:SourceVpcArn and the three aws:Vpce* keys, which the
page leaves out but DSQL accepts (measured, eu-west-1, 2026-10-20). As
the page says, a policy variable never restricts: StringEquals with
${aws:PrincipalArn}, ${aws:SourceVpc} or a role/${aws:username} ARN is
public on DSQL. ArnEquals reads like ArnLike, as IAM matches both the
same way, so a value that is no ARN, ${aws:SourceArn} among them,
matches nothing and restricts, as measured.

DeleteClusterPolicy left the deleted version on the cluster, so a put
naming it went through; it is now cleared, and a put that names a
version on a cluster with no policy is refused as not found.
2026-10-20 15:34:39 -04:00

87 lines
5.2 KiB
Markdown

# Aurora DSQL
**Protocol:** REST JSON
**Endpoint:** `http://localhost:4566`
Floci serves Aurora DSQL's control plane and `AWS::DSQL::Cluster`. A cluster has no database
behind it here: it is `ACTIVE` as soon as it is created, and its endpoint is named as on AWS but
not served. The answers and messages below were measured on AWS.
## Supported Actions
<!-- floci:actions:start -->
| Action | Description |
| --- | --- |
| `CreateCluster` | Creates a cluster, `CREATING` in the answer and `ACTIVE` right after, 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, `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 |
<!-- floci:actions:end -->
`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's endpoint is `<cluster-id>.dsql.<region>.localhost.floci.io`.
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. Nothing is replicated between them. A customer-managed KMS key
is recorded and reported; nothing is encrypted with it.
## 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](https://docs.aws.amazon.com/aurora-dsql/latest/userguide/rbp-block-public-access.html)
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 does not cover DSQL.
## 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_ENDPOINT_SUFFIX` | `localhost.floci.io` | Domain the endpoints are named under, `<cluster-id>.dsql.<region>.<suffix>` |
See the [Aurora DSQL API Reference](https://docs.aws.amazon.com/aurora-dsql/latest/APIReference/Welcome.html)
and the [Aurora DSQL User Guide](https://docs.aws.amazon.com/aurora-dsql/latest/userguide/what-is-aurora-dsql.html).