Metadata-Version: 2.5
Name: parallax-aws
Version: 0.1.0
Summary: Parallax AWS credential providers: RDS IAM database authentication as a Credential Source (the sole botocore declarer).
Project-URL: Documentation, https://github.com/davidsunglee/parallax/blob/main/languages/python/docs/guide/README.md
Project-URL: Repository, https://github.com/davidsunglee/parallax
Project-URL: Changelog, https://github.com/davidsunglee/parallax/blob/main/languages/python/docs/releases.md
Author: Parallax
License-Expression: Apache-2.0
License-File: LICENSE
License-File: NOTICE
Requires-Python: >=3.14
Requires-Dist: botocore>=1.43.99
Requires-Dist: parallax-core==0.1.0
Provides-Extra: postgres
Requires-Dist: parallax-postgres==0.1.0; extra == 'postgres'
Requires-Dist: psycopg<3.4,>=3.3.6; extra == 'postgres'
Description-Content-Type: text/markdown

# parallax-aws

Parallax's AWS credential providers: the sole declarer of `botocore`. See
the [Python binding](https://github.com/davidsunglee/parallax/blob/main/languages/python/spec/python.md).
The distribution includes Apache-2.0 `LICENSE` and `NOTICE`; see the
[release notes](https://github.com/davidsunglee/parallax/blob/main/languages/python/docs/releases.md)
for publication status.

## Authenticating an RDS Postgres login with IAM

Install the `postgres` extra — `python -m pip install "parallax-aws[postgres]==0.1.0"` — and each
endpoint is one call:

```python
from parallax.aws.postgres import rds_endpoint
from parallax.postgres import PoolOptions, PostgresAdapter
from parallax.snapshot import connect

writer = rds_endpoint(
    host="orders.cluster-abc.us-east-1.rds.amazonaws.com",
    user="orders_service",
    database="orders",
    region="us-east-1",
    pool=PoolOptions(min_size=2, max_size=20),
)
with connect(PostgresAdapter(writer=writer), model) as root:
    ...
```

What comes back is the ordinary `PostgresEndpoint`, configured, and the
application composes the adapter around it — nothing sits between the
application and the adapter at runtime, and nothing was resolved or opened to
build it. The factory is where three things are stated once, so no deployment
has to remember them: the connection is encrypted, the token is signed for the
host, port and user the endpoint's connections then use, and the endpoint to
sign for is the one the application connects through — so each endpoint signs
for its own host.

`params` keeps the rest of libpq's grammar open — `application_name`,
`options`, `connect_timeout`, and `sslrootcert` with an `sslmode` of
`verify-ca` or `verify-full`, which is what AWS's own certificate bundle is for.
It may strengthen the TLS requirement and may not weaken it, it may not ask for
the GSS encryption libpq would carry the login over in TLS's place, and it may
not restate `host`, `port`, `user`, `dbname` or `password`: a value the token
was not signed for authenticates nothing. `host` names one endpoint for the same
reason — libpq reads a comma-separated list of them, and a token signed for the
list authenticates at none of its members. Every refusal is fixed text, because
`params` is a place other secrets live.

## The source on its own

`RdsIamCredentials` is a `CredentialSource`, and the part of this package that
imports no adapter. An application assembling its own connection string uses it
directly, and a deployment on another engine installs this package without the
`postgres` extra and gets no database driver with it.

```python
from parallax.aws import RdsIamCredentials
from parallax.postgres import PostgresEndpoint

host = "orders.cluster-abc.us-east-1.rds.amazonaws.com"
writer = PostgresEndpoint(
    f"postgresql://orders_service@{host}:5432/orders?sslmode=require",
    credentials=RdsIamCredentials(host=host, port=5432, user="orders_service", region="us-east-1"),
)
```

IAM database authentication is identical on RDS Postgres and Aurora Postgres.
For a cluster, the endpoint above is the one the application connects through:
a token proves nothing at an endpoint it was not signed for. Written this way,
the TLS requirement the factory would have stated is the caller's to spell.

## What has to agree outside Parallax

- the database login exists and holds the IAM role —
  `CREATE USER orders_service; GRANT rds_iam TO orders_service;`;
- the AWS identity the process runs as is allowed `rds-db:connect` on
  `arn:aws:rds-db:<region>:<account>:dbuser:<resource-id>/orders_service`;
- the connection is encrypted. An IAM token is a password, so it travels over
  TLS: `sslmode=require` at least, and `verify-full` with AWS's certificate
  bundle where the deployment can supply one.

## What resolving a token costs

Signing is local — no AWS endpoint is reached to produce a token. What can block
is botocore finding or refreshing the AWS credentials it signs with: the
environment, a profile, an ECS task role, IMDSv2, IRSA, or SSO. The record
bounds the network all of that reaches over, because the seam requires a source
to, and it creates its RDS client on first use rather than at construction, so
composing an adapter stays free of I/O.

One thing it does not bound: a helper command a profile's `credential_process`
names. botocore waits on that command with no timeout, and so does this record —
the program is yours, and so is bounding its wait. Be exact about what an
unbounded one costs, because it is not one connection: the RDS client is created
once under a lock, so a helper that hangs holds every pool worker behind it and
the application stops connecting rather than connects slowly. A helper that
cannot promise to answer — one waiting on a person, or on a network of its own
it has not bounded — belongs behind a session of your own, built on a chain that
does not run it. An injected session is used exactly as given.

There is no token cache and no refresh thread. A connection the server has
already accepted is never disturbed by its token ageing out, and when a source
is asked for a new one is the port's rule rather than this package's — see
`core/spec/m-db-port.md`, "Configuration carries where, and a Credential Source
carries how".

```python
# a session of your own — a profile, static keys, a test double; used as given
RdsIamCredentials(host=endpoint, port=5432, user="app", region="us-east-1", session=session)
```

## When a token cannot be produced

Every botocore or signing failure surfaces as
`CredentialResolutionError: RDS IAM token could not be generated`, with the
native error chained beneath it. The message is fixed text so that nothing a
provider says can leak through it; what the adapter then reports — a startup
that fails naming the refusal, or an acquisition failing with
`reason="credentials_refused"` — is in
[PostgreSQL connection lifecycle](https://github.com/davidsunglee/parallax/blob/main/languages/python/docs/postgresql-lifecycle.md)
under "Where the password lives".
