mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 14:10:49 -05:00
fee688bd051a5bde4e2e8a4d5e0f5d75c7ffe00a
9
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
3944d6edc2 |
fix(dsql): enforce IAM and the cluster's policy on the control plane (#6328)
* fix(dsql): enforce IAM and the cluster's policy on the control plane
A cluster's resource-based policy governs DSQL's control plane as well as
its connections (measured, eu-west-1): a Deny of dsql:GetCluster,
UpdateCluster, TagResource or GetVpcEndpointServiceName refuses that call,
and a call it does not name still answers. With IAM enforcement on, Floci
left every DSQL control plane route unchecked: no rule in
IamActionRegistry mapped one, so the policies, identity or resource, were
never read there.
IamActionRegistry maps every operation of DSQL's model to its action, the
stream operations Floci does not serve included, and
IamRestRouteCoverageTest now checks all of them against botocore's routes,
vendored for DSQL by regen_rest_routes.py. ResourceArnBuilder names the
resource each call is checked against, as the Service Authorization
Reference gives it: the cluster, the stream, or the ARN a tagging route
names, minted in the request's partition. CreateCluster and ListClusters
are checked against cluster/*, as DSQL checks them (measured; the
reference lists ListClusters with no resource). The enforcement filter
then reads the cluster's policy through DsqlResourcePolicyProvider, as it
reads a topic's or a function's.
* fix(dsql): check tagging at /tags too, where the ARN is in the query or body
Asked in review: Floci serves DSQL's tagging at /tags as well as at
/tags/{arn}, naming the ARN in the resourceArn query parameter or body field,
and the rules matched only the path form, so a bare /tags call reached DSQL's
tag handler unchecked. The rules now match both, as Scheduler's do, and the
control plane test tags, lists and untags through each form.
|
||
|
|
f60cf120c6 |
fix(dsql): evaluate the cluster's resource-based policy on connect (#6319)
DSQL evaluates a cluster's resource-based policy when a client connects (measured, eu-west-1): an explicit Deny that applies to the caller refuses the connection with the hint "User: <caller> is not authorized to perform: dsql:<action> on resource: <cluster ARN> with an explicit deny in a resource-based policy", under the statement's conditions, aws:PrincipalArn and aws:SourceIp among them, and a statement that does not apply leaves the caller's own policies to decide. With IAM enforcement on, the endpoint checked only the caller's identity policies. DsqlResourcePolicyProvider supplies a cluster's policy through ResourcePolicyProviders, as the SNS and Lambda providers do, and the endpoint evaluates it with the caller's policies and SCPs as LambdaTaskAuthorizer and LambdaWebIamAuth evaluate a function's policy: evaluateResourcePolicyFor, then evaluateResolvedResourcePolicy, with the client's address as aws:SourceIp. With enforcement off nothing is evaluated, as for every other policy in Floci. DsqlService already built the cluster policy's context for the lockout check and the "is not authorized" sentence for the tag refusals; both now come from DsqlPrincipals (policyContext, notAuthorized), which the endpoint uses too, instead of a third copy. The policy also governs control plane calls on DSQL (measured), but Floci's IAM enforcement names DSQL's control plane resources as *, so that is left as it is. |
||
|
|
1f25fd88cf |
fix(dsql): take TLS started with no SSLRequest, as DSQL does (#6296)
DSQL's own connectors, and libpq's and pgjdbc's sslnegotiation=direct, start TLS at once with no SSLRequest. The endpoint read their ClientHello as a plaintext startup packet and refused it as not TLS. The endpoint now reads a connection's first byte. A TLS handshake record goes straight to the handshake with that byte handed back, and anything else takes the SSLRequest path as before. The byte is TlsProxyServer's TLS_HANDSHAKE, now public, the one the TLS proxy already tells TLS apart by; its peek runs on a Vert.x socket, the endpoint's on a blocking one, so only the constant is shared. As DSQL does (measured, eu-west-1): the endpoint picks the ALPN protocol postgresql whenever a client offers it, after an SSLRequest too, and none otherwise; a direct handshake that does not end with postgresql picked completes and the connection closes without a message. DsqlWireClient opens TLS through one handshake helper, with an ALPN list, after an SSLRequest (tls) or at once (direct), and signs in separately. |
||
|
|
d20084ade3 |
fix(dsql): refuse a connection that sends no TLS server name (#6282)
DSQL knows the cluster only by the TLS server name, and refuses a connection that sends none with FATAL 08P01 "unable to accept connection, sni was not received" once its password is in, whatever the password (measured). The endpoint fell back to the host in the token and let such a connection in. It now refuses it as DSQL does, and admit takes the cluster from the server name alone. The integration tests connected to 127.0.0.1 through pgjdbc's NonValidatingFactory and sent no server name; DsqlClusterFixture now gives pgjdbc a NonValidatingFactory that names the cluster, as the compatibility test's factory does. |
||
|
|
564ae350a1 |
fix(dsql): refuse a startup packet or client message outside DSQL's limits (#6258)
* fix(dsql): refuse a startup packet or client message outside DSQL's limits The endpoint took a client message up to 64 MB and dropped the connection without a word past that; DSQL takes 10 MiB and answers FATAL 08P01 "invalid message length" as soon as a longer, or shorter than 4, length arrives. Measuring the startup packet alongside showed it one byte off as well: DSQL takes 9,999 bytes and answers "invalid length of startup packet" from 10,000, where the endpoint took 10,000 and refused more in silence. Both are DSQL's now, for the startup inside TLS, the password message and every message after signing in. What the database sends is not DSQL's to limit, so it is still read up to 64 MB. PostgresWire.checkedLength throws its own InvalidLengthException, still an IOException, so a reader can tell such a packet from a broken connection; the RDS proxy and Redshift's bridge end the connection on it as before. * fix(dsql): refuse any packet before TLS as not TLS, whatever its length The first head capped the packets read before TLS at the startup limit too, so a 10,000-byte plaintext startup packet, first or after a GSSENCRequest, closed the connection in silence where it had been refused as not TLS; above 10,000 bytes main closed in silence as well. Measured on DSQL, it reads no more than such a packet's length and code: a plaintext startup packet of any length is refused with "SSL is mandatory", and one under 8 bytes ends the connection without a word. The endpoint now reads the body only when it fits a startup packet, so the refusal reaches the client in order, and refuses a longer one unread. |
||
|
|
42fd858311 |
feat(dsql): speak DSQL's dialect and keep its transaction limits (#6185)
* feat(dsql): speak DSQL's dialect and keep its transaction limits The third part of the DSQL data plane, after #6102 and #6143: the cluster's database answers the way Aurora DSQL does, as measured on AWS. CREATE [UNIQUE] INDEX ASYNC answers a job_id, with sys.jobs and sys.wait_for_job; a plain CREATE INDEX is refused. What DSQL refuses is refused with its SQLSTATE and message: what the statement shows (TRUNCATE, DO, LISTEN, VACUUM, sequence caches, isolation levels, locking clauses, advisory locks, ADD CONSTRAINT) in DsqlStatements, and what only the catalog can tell (column types, a function's language, temporary and partitioned tables, triggers) inside the database, by event triggers, since the statement alone cannot say. A transaction runs one DDL statement, never with DML, and modifies at most 3,000 rows, a cascade's included. Its age follows what was measured with a client that only reads: the client's next message after 300 seconds ends it with 54000 and closes the connection with 08P01, an idle one is ended unasked 15 seconds later, a statement running across the limit completes and then fails with 54000, and a failed transaction left idle as long is closed with 25P03. A first model, the age checked at the next statement, was dropped once the reading client showed DSQL's own timer. A write conflict is DSQL's 40001 OC000, and an error's context keeps the statement a cascade ran while dropping what sys functions ran. * fix(dsql): close the dialect's gaps found in review, as measured on DSQL Measured on Aurora DSQL before each change: - set_config of default_transaction_isolation or transaction_isolation, a quoted SET of one and ALTER ROLE ... SET of one answer 0A000 "not supported"; ALTER DATABASE ... SET or RESET is AlterDatabaseSet. - CREATE TABLE AS, SELECT INTO and materialized views are CreateTableAs, refused by the event trigger so a function body cannot reach them either. - An expression key, or a domain over jsonb or bytea, is refused like the type itself, named as declared: the check reads the index's own columns and follows a domain to its base type. - CREATE, ALTER and DROP ROLE and GRANT or REVOKE of a role are DDL. PostgreSQL fires no event trigger for them, so they run through sys.run_role_ddl, which counts them first, under PostgreSQL's tags. - A statement past the transaction age limit fails with 54000, in a transaction block or not, nothing its transaction wrote is kept, and the rest of its query, a COMMIT included, does not run. The age limit is reworked as the review asked. Each session has one check scheduled at a time, on the endpoint's scheduler and by the injected Clock, cancelled when the transaction or the connection ends; a failed transaction's idle wait restarts after every client message. At the limit a statement still running is cancelled with the client's own cancel request, and its 57014 reaches the client as DSQL's 54000. DSQL lets the statement finish and fails it then; stopping it at the limit ends the same way. Two other ways were tried and dropped: dropping a late statement's answer in the relay let a COMMIT in the same query commit, and a mark the endpoint writes for the database to check is invisible to the client's repeatable read snapshot. The age test now moves the clock and holds a row instead of sleeping, and shares its cluster setup with the data plane test through DsqlClusterFixture. Also fixed: a -- comment ends at a carriage return, a quoted advisory lock name is refused, CACHE is read from tokens rather than the raw text, a BEGIN queued behind a long statement starts once that statement is answered, tables that predate the counting triggers get them, and sys.create_index_async runs one index statement and nothing else. sys.wait_for_job with an unknown id keeps waiting, as DSQL's does. |
||
|
|
6e5b3c6c1d |
feat(dsql): map IAM roles to database roles with AWS IAM GRANT (#6143)
* feat(dsql): map IAM roles to database roles with AWS IAM GRANT A role other than admin now signs in to a cluster for the IAM role that AWS IAM GRANT mapped to it, as on DSQL: the token's principal (a Lambda function's execution role, an ECS task's role, an AssumeRole session) is looked up in sys.iam_pg_role_mappings, and an unmapped role is refused with DSQL's 28000. AWS IAM GRANT and REVOKE become calls to procedures in the cluster's sys schema, with DSQL's command tags and its refusals for a superuser and for a role the caller holds no ADMIN option on. sys.iam_session_user() and sys.current_session_id() answer the session's identity. Since the identity travels in dsql.* settings, the dsql prefix is reserved as DSQL reserves it, measured on AWS: SET, RESET, set_config, ALTER ROLE ... SET and a function's SET clause of a dsql. parameter answer 42602 with DSQL's detail. Errors lose their source location and the context lines of the sys functions, as DSQL's never show them. * fix(dsql): refuse dropping a mapped role and keep the session identity out of the session's reach DROP ROLE, USER and GROUP of a role an IAM identity is mapped to now answer DSQL's 2BP01, with one detail line per mapping in grant order, as measured on DSQL. The statement becomes a call to sys.drop_roles, which refuses a mapped role and otherwise drops the roles as the caller. A role dropped where Floci cannot see it, inside a function body, stops being listed in sys.iam_pg_role_mappings, and its mappings go with the next grant or revoke. The session identity no longer travels in dsql.* startup settings, which a set_config inside a DO block or a function body could overwrite. The endpoint writes it as the superuser into sys.session_identity, keyed by the backend's pid, before it forwards the first ReadyForQuery, and no role of the cluster can write that table. Catching every set_config of a dsql. parameter was rejected: only a PostgreSQL extension written in C can reserve a prefix, so the gap inside DO blocks and function bodies is documented as it is. Command tags are settled per batch: each Query, Sync and FunctionCall gets its own, and a Parse's tag, a Bind's statement, a Close and an Execute's result take effect when the database answers them, in its order. A pipelined batch no longer loses its tags to an earlier ReadyForQuery, and a Parse the database refuses leaves the statement it named as it was. Closed statements and portals are forgotten, and portals with their transaction. Also, as measured on DSQL: AWS IAM GRANT takes an IAM user's ARN, a repeated grant answers its notice whoever the grantor was, and a failed read of the mappings refuses the connection as 08006 with its cause logged, instead of as a role refused. An error's context drops everything a sys function ran, the statements it executed included. |
||
|
|
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. |
||
|
|
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. |