Files
floci/src/main/java
Sam Fakhreddine be892864db fix(lambda): resolve launched-container placeholder creds to the owning account (#2657)
* fix(lambda): resolve launched-container placeholder creds to the function's owning account

A Lambda that never assumes an execution role falls through to placeholder
credentials, and the literal AWS_ACCESS_KEY_ID=test that ContainerLauncher then
injected is not a 12-digit account ID, so AccountResolver resolved every such
container to the emulator's default (management) account regardless of which
account actually owns the function. Account-partitioned reads and writes then
collide or miss whenever the real resource lives elsewhere -- observed as five
accounts' LoggingStack custom resources simultaneously colliding on one
AWSServiceRoleForAutoscaling during an LZA Stage 1 run, and
non-deterministically, since account IDs are re-minted every pipeline run.

sdkBaselineEnv now takes the workload's owning account and injects it as the
placeholder access key. It wins over Floci's own ambient AWS_ACCESS_KEY_ID: the
server process's credentials describe the server, not a container it launches,
and a deployment that exports AWS_ACCESS_KEY_ID (the floci-lza image sets it
unconditionally) would otherwise make the owning-account branch dead code.
Mounted ~/.aws and real execution-role credentials still take precedence, and
launch paths that don't know the owning account are unaffected.

Recovered from 092cb16a5 + d25f1cefc, re-derived onto upstream's current shape:
the fork's 3-arg overload would collide with upstream's flociEndpoint overload,
so the account rides on the injectedCredentials-carrying signatures instead, and
ContainerLauncher passes the lambdaAccountId it already resolves. The host env
lookup moved behind a package-private seam so the precedence is actually
testable -- the fork's own regression test asserted it without ever forcing the
host env to be set, and so could not have failed. Drops the branch's local-only
issues/*.md ledger entry and scripts/describe-sg-as.sh diagnostic.

* fix(lambda): pass the owning account into Kubernetes-launched Lambda pods too

The pod launcher builds the same baseline AWS environment as the Docker one and
so had the same defect: a Lambda that never assumes an execution role fell
through to the "test" placeholder access key and resolved to the emulator's
default account. It already derives the owning account for its layer downloads,
so it now passes it to sdkBaselineEnv as well.

ECS, MWAA and Flink container managers deliberately stay on the account-less
overload -- those workloads have no owning Lambda function to derive one from.

* fix(lambda): resolve owning-account placeholder AKID to the test secret in SigV4 validation

sdkBaselineEnv gives a Lambda without an execution role and a known owning
account that account ID (a bare 12-digit string) as AWS_ACCESS_KEY_ID, paired
with the "test" placeholder secret. Floci's own SigV4 validators for S3
presigned URLs, ElastiCache IAM auth, and RDS IAM auth look up the secret for
an unregistered access key and previously fell back to either null or the
access key itself, which only coincidentally matched when both sides were the
literal "test"/"test" pair. Once the access key became a 12-digit account ID
instead, the fallback no longer matched the "test" secret the client actually
signed with, and every such presigned URL or IAM auth token failed validation.

Each validator's fallback now recognizes a bare 12-digit access key
specifically as this placeholder and expects the "test" secret for it, while
any other unregistered access key keeps its prior behavior (InvalidAccessKeyId
for S3, signature mismatch for ElastiCache/RDS) so a genuinely unknown key is
still rejected.

* fix(lambda): force test secret and session token on the owner-account placeholder path

The owner-account AKID branch in LaunchedContainerAwsEnv still paired the numeric
owner-account access key with Floci's own ambient AWS_SECRET_ACCESS_KEY when one was
set. The S3, RDS, and ElastiCache SigV4 validators only accept a numeric access key
paired with the literal "test" secret, so a non-test ambient secret produced a
credential pair nothing could verify, breaking presigned URLs and IAM-auth tokens.
Force the secret and session token to "test" whenever the owner-account AKID wins,
and scope the ambient-credential-forwarding warning to the branch where it actually
forwards them.

* fix(security): reject unregistered numeric access keys in SigV4 validators

The S3 presigned-URL filter, RDS SigV4 validator, and ElastiCache SigV4 validator each
treated any unregistered 12-digit access key ID as a valid credential when paired with
the literal "test" secret. Since AccountResolver reads a 12-digit access key ID as the
request's account directly, this let a client forge a signed request or IAM-auth token
for an arbitrary account number using the well-known "test" secret, bypassing S3 auth
enforcement and RDS/ElastiCache IAM authentication for any matching database or cache
user. Remove the numeric-access-key fallback from all three validators; an unregistered
key is rejected the same way any other unknown key is.

This narrows the owner-account placeholder credentials added for launched Lambdas to
paths that don't require a real signature check; ledgered in issues/ for a follow-up
that mints real per-account session credentials instead.

* fix(lambda): reject partial user credential overrides on the placeholder path

Both the Docker and Kubernetes launchers appended a Lambda's own Environment
config after the owner-account/placeholder AWS credential baseline. When the
function defined only a subset of AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY/
AWS_SESSION_TOKEN, that partial value overrode just its own key in the
baseline tuple, pairing a user-chosen value with the owner-account's other
credential parts -- a combination no SigV4 validator accepts and which could
resolve requests to the wrong account. Credential injection from a function's
Environment is now all-or-nothing: only a fully-specified triad is allowed to
override the baseline; anything less is dropped so the baseline stays intact.
2026-08-28 17:42:18 -04:00
..