Files
floci/src/main/java
Brian Taylor 5b363ffa2d fix(lambda): implement GetLayerVersionByArn (#2812)
* fix(lambda): implement GetLayerVersionByArn

GET /2018-10-31/layers?find=LayerVersion&Arn={arn} is GetLayerVersionByArn,
but only ListLayers was bound to that path and it ignored both query
parameters. A GetLayerVersionByArn call was therefore answered with a
ListLayers body and HTTP 200: an SDK deserialises that against the
GetLayerVersionByArn output shape, finds none of its members, and hands the
caller an empty result instead of the layer version or a
ResourceNotFoundException.

AWS gives the two actions the same method and path, discriminated only by
`find`, and JAX-RS cannot route on a query parameter, so the branch lives in
the handler.

The semantics below were measured against the live service rather than
inferred from the reference:

  find=LayerVersion&Arn=<present>  200 + LayerVersion object
  find=LayerVersion&Arn=<absent>   404 ResourceNotFoundException
  find=LayerVersion, no Arn        400 ValidationException, must not be null
  find=LayerVersion&Arn=junk       400 ValidationException, pattern in message
  find=Nonsense                    200 + ListLayers body
  find=layerversion                200 + ListLayers body (match is case-sensitive)

The Arn pattern enforced here is the one the live service reports in its own
ValidationException, not the one the API reference publishes: it constrains
the region segment more tightly and additionally accepts the AWS-managed
arn:<partition>:lambda:::awslayer:<name> form, which the reference omits.

The response reuses the builder GetLayerVersion already returns, and resolves
Content.Location against the layer's own region rather than the caller's,
matching the lookup resolveLayerByArn already keys on.

* fix(lambda): scope GetLayerVersionByArn to the caller's account

resolveLayerByArn keys on region, layer name and version. Storage is already
partitioned per account, so that lookup runs inside the caller's own partition
— an ARN naming a different account did not reach that account's layers, but it
did resolve to the caller's own same-named layer and return it.

Measured on main, without this action: account B publishes
arn:...:111111111111:layer:acct-probe:1, then calls CreateFunction with
Layers=[arn:...:000000000000:layer:acct-probe:1]. The call succeeds and the
function records account A's ARN while B's own layer is what resolves. Account
B never sees account A's layer — GetLayerVersion by name and ListLayers both
return nothing for it — so this is a wrong-resource answer, not a cross-account
read.

GetLayerVersionByArn is the one layer action that takes an account explicitly,
so it honours it: an ARN outside the caller's account is a 404, which is what
the caller already gets from GetLayerVersion for a layer it cannot see. No
layer can be shared cross-account here — layer permissions are unimplemented —
so a foreign account is always a miss, and the check is the place sharing would
hook in if that changes.

The same account-blindness reaches CreateFunction and UpdateFunctionConfiguration
through validateLayersResolvable, and the container launcher through the same
resolver. Those are pre-existing on main and change behaviour for existing
actions, so they are left for a separate change rather than folded in here.

* fix(lambda): reject a layer ARN naming another partition

The account guard compared only the account, and resolveLayerByArn drops
the partition as well as the account, so an ARN in another accepted
partition with the same account, region, name and version resolved to
the caller's local layer and was returned under the foreign-partition
ARN. The live service rejects those outright with
InvalidParameterValueException.
2026-08-31 09:10:49 -04:00
..