Skip to content

fix(connections): sign RDS IAM tokens for the database endpoint, not the local forward - #1953

Merged
datlechin merged 1 commit into
mainfrom
fix/rds-iam-token-signing-endpoint
Jul 25, 2026
Merged

datlechin merged 1 commit into
mainfrom
fix/rds-iam-token-signing-endpoint

Conversation

@datlechin

Copy link
Copy Markdown
Member

Follow-up to #1432, from @imdkbj's report that IAM auth still fails while a hand-generated token works:

connection to server at "127.0.0.1", port 54321 failed: FATAL:  PAM authentication failed for user "deepak_test"

Root cause

An RDS IAM token is a SigV4 presigned URL whose signature covers Host: <host>:<port>, and RDS validates it against its own endpoint. The address the client dials does not have to match; the address the token was signed for does. TablePro signed the token with the connection handed to the driver, which is the endpoint it dials, not the one it talks to.

That is the wrong endpoint in two cases:

  1. A tunnel TablePro opens. tunneledConnection rewrites host and port to 127.0.0.1:<local port> for all four tunnel kinds, and preserved the original only for pgpass. So RDS IAM over SSH, Cloudflare, Cloud SQL Auth Proxy, or SOCKS signed a token for loopback and was rejected every time. Region detection failed the same way, which is why the docs told tunnel users to fill in the region by hand: that never could have worked either.
  2. A forward the user runs. 127.0.0.1:54321 is outside TablePro's tunnel port range, so the reporter runs their own forward. TablePro had no way to know the real endpoint and signed a doomed token in silence.

Only MySQL, MariaDB, and PostgreSQL are affected. ElastiCache signs a replication group ID and Keyspaces signs a region, neither of which carries a host.

Changes

  • The pre-tunnel endpoint is now a first-class concept. tunneledConnection records it for every tunnel kind instead of the pgpass-only pgpassOriginalHost carve-out, and both pgpass and IAM read preTunnelHost / preTunnelPort. It travels in additionalFields, so it survives the health-monitor reconnect and the metadata connection pool, which both rebuild drivers from the stored effective connection.
  • New RDSSigningEndpointResolver, pure and no I/O: endpoint override, then the pre-tunnel endpoint, then the configured endpoint. The region derives from the signing host, so a tunneled RDS connection no longer needs the region typed in.
  • New optional RDS Endpoint field in host[:port] form, for a forward TablePro did not open or a CNAME. The port falls back to the engine default. DBeaver added the same field for the same report (dbeaver#15141), as did DataGrip's AWS toolkit.
  • A loopback signing host fails fast with a message naming the field to fill, instead of shipping a token that can only come back as PAM authentication failed.
  • Dedupe. The MySQL and PostgreSQL plugins carried byte-identical inline copies of AWSAuthFields.standard(); they now call it. That also fixes drift the copies had already picked up: they were missing .withDynamicOptions(.awsProfiles), so MySQL and PostgreSQL showed a plain Profile Name text field while MariaDB showed the list of profiles on disk.

PluginKit ABI

Two cases on the non-@frozen AWSAuthError and one new static func on AWSAuthFields. scripts/check-pluginkit-abi.sh against origin/main reports those three lines added and nothing removed, renamed, or resignatured, so this is additive: no currentPluginKitVersion bump and no plugin re-release. Labelled abi-additive.

+  case rdsEndpointUnresolved(host: Swift::String)
+  case rdsEndpointInvalid(Swift::String)
+  public static func rdsEndpointField() -> TableProPluginKit::ConnectionField

Tests

RDSSigningEndpointResolverTests covers the precedence chain, an override with and without a port, a pasted URL, malformed input, and loopback rejection for both the configured and the pre-tunnel host. DatabaseManagerTunnelTests asserts the pre-tunnel endpoint is recorded for a tunneled connection and absent for a direct one. RegistryAWSIAMFieldsTests checks the new field reaches MySQL, MariaDB, and PostgreSQL, that the shared AWS field set does not carry it (so ElastiCache and Keyspaces never show it), and that the profile field lists profiles on all three.

Docs: docs/databases/aws-iam.mdx gains a tunnels and port forwards section, corrected region guidance, and troubleshooting for both the new error and the PAM failure.

@mintlify

mintlify Bot commented Jul 25, 2026

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
TablePro 🟢 Ready View Preview Jul 25, 2026, 7:35 AM

💡 Tip: Enable Workflows to automatically generate PRs for you.

@datlechin
datlechin merged commit 4345886 into main Jul 25, 2026
3 checks passed
@datlechin
datlechin deleted the fix/rds-iam-token-signing-endpoint branch July 25, 2026 07:36

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 339788cb63

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +45 to +49
if let schemeRange = text.range(of: "://") {
text = String(text[schemeRange.upperBound...])
}
if let slashIndex = text.firstIndex(of: "/") {
text = String(text[..<slashIndex])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Parse pasted URLs by authority

When the override is a valid connection URL containing user information, such as postgresql://[email protected]:5432/db, removing only the scheme and path leaves user@ in the signing host. makeEndpoint accepts that value, region detection still succeeds, and TablePro generates a token signed for user@mydb..., which RDS rejects. Since this code and its new test explicitly support pasted URLs, extract the URL authority/host and port with URLComponents (or reject URLs containing userinfo) rather than slicing the string.

Useful? React with 👍 / 👎.

@mintlify

mintlify Bot commented Jul 25, 2026

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
TablePro 🟡 Building – Jul 25, 2026, 7:34 AM

💡 Tip: Enable Workflows to automatically generate PRs for you.

This branch was successfully deployed

1 active deployment
staging - docs — 339788cb Deployed Jul 25, 2026 by mintlify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant