Files
floci/docs
Alessandro Lattao 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.
2026-10-21 14:10:30 -04:00
..
2026-03-15 17:43:56 -05:00