Skip to content

fix(routing): reach API Gateway v2 and SSO Admin from an SDK (#561) - #563

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/561-routing-apigatewayv2-sso
Aug 4, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/561-routing-apigatewayv2-sso

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Two plugins were registered, had test files, and could not be reached by any SDK.
Both test files call HandleRequest directly, so every unit test was green while
the feature did not exist from a caller's point of view — the same shape twice, so
they are fixed together.

Closes #561.

Part of #529: its third acceptance criterion ("same check applied to API Gateway
v2") is unverifiable end to end while aws apigatewayv2 create-api 404s, so this
is a prerequisite of the response-shape work rather than drive-by cleanup. #529
itself stays open for that work.

API Gateway v2 was unreachable

No routing signal distinguishes v1 from v2. The apigatewayv2 client's SigV4
signing name is apigateway, its hostname is the same
apigateway.{region}.amazonaws.com, and neither client sends X-Amz-Target. So
every v2 request resolved to apigateway, landed on APIGatewayPlugin, and came
back:

$ aws apigatewayv2 create-api --name p --protocol-type HTTP
NotFoundException … APIGatewayPlugin: unknown operation for POST /v2/apis

extractService now refines a resolved apigateway to apigatewayv2 when the
path begins with /v2/. That is exact rather than heuristic: all 103 requestUris
in the apigatewayv2 model are under /v2/
, and none of the v1 model's URI space
is — v1's roots are /account, /apikeys, /clientcertificates, /domainnames,
/domainnameaccessassociations, /rejectdomainnameaccessassociations,
/restapis, /sdktypes, /tags, /usageplans, /vpclinks. So a /v2/ path
cannot be a v1 call.

The refinement is confined to requests that already resolved to apigateway.
A bare /v2/… path is not evidence of API Gateway by itself, and another service's
endpoint is free to use one — MSK's /v2/clusters is exactly that case, and it is
in the test table.

SSO Admin was unreachable

targetServiceAliases mapped AWSSSOAdminService, a prefix derived by guesswork
that no client sends. The real sso-admin targetPrefix is SWBExternalService:

$ aws sso-admin list-instances
ServiceNotAvailable … service not emulated: swbexternalservice

The real prefix is now mapped alongside the guessed one rather than replacing
it — retaining it costs nothing and keeps working for a caller that builds the
target header by hand from the service name. The comment records the correction,
since the existing one stated the wrong derivation with some confidence.

Verified

End to end against substrate server --address :4620, both previously impossible:

$ aws apigatewayv2 create-api --name pra-v2 --protocol-type HTTP     # 201, was NotFoundException
$ aws sso-admin list-instances
{"Instances": [{"InstanceArn": "arn:aws:sso:::instance/13b848…", "IdentityStoreId": "d-2670d174b0", …}]}
$ aws sso-admin create-permission-set --instance-arn "$ARN" --name ps1   # parses
$ aws sso-admin list-permission-sets --instance-arn "$ARN"              # parses

create-api returns 201 and the response body is populated, but the CLI still
prints nothing for it — its members are PascalCase, which is #529's separate defect
and is fixed later in this milestone. Reachability is what this PR delivers; it is
also what makes that defect observable at all.

v1 regressions checked in the same session: create-rest-api, /restapis,
/usageplans and /account all still reach APIGatewayPlugin, and MSK's
/v1/clusters is unaffected.

Tests

Two table-driven cases in parser_test.go, both red before the fix:
TestParseAWSRequest_APIGatewayVersionRouting (v2 by auth scope and by host; four
v1 paths staying v1; MSK's /v2/clusters staying MSK) and
TestParseAWSRequest_SSOAdminTargetPrefix (both target prefixes resolving to
sso).

Mutation testing found a real gap rather than confirming what was already
there. Six mutants: the apigateway-only guard dropped, the refinement removed,
the refinement inverted, the real SSO prefix reverted, the legacy SSO prefix
dropped — five caught — and HasPrefix loosened to Contains, which survived.
A v1 rest-api id is ten lowercase alphanumerics and a stage name is caller-chosen,
so either can contain v2; /restapis/abcv2ghijk would have been routed to the v2
plugin by that mutant with nothing to catch it. Two cases were added for it and the
mutant is now caught, 6/6.

Docs

docs/services.md: the API Gateway v2 section states how v1 and v2 are
discriminated and that a consumer needs no special client configuration, and SSO /
Identity Store gains a section — it was in the coverage matrix with no detail,
which is consistent with having been unreachable. make docs-reference reports no
change to the generated matrix; no plugin is added or removed.

Both plugins were registered, had test files, and were unreachable from any
client. Both test files call HandleRequest directly, so every unit test was
green while the feature did not exist from a caller's point of view.

API Gateway v2: no signal distinguishes v1 from v2 — the v2 client's SigV4
signing name is "apigateway", its hostname is the same, and neither client
sends X-Amz-Target. extractService now refines a resolved "apigateway" to
"apigatewayv2" for a "/v2/" path. All 103 requestUris in the apigatewayv2
model are under /v2/ and none of v1's are, so the split is exact; the
refinement is confined to requests that already resolved to apigateway, so
another service's /v2/ endpoint cannot be captured.

SSO Admin: targetServiceAliases mapped a guessed "AWSSSOAdminService" that no
client sends. The real sso-admin targetPrefix is "SWBExternalService", now
mapped alongside the guessed one rather than replacing it.

Closes #561. Prerequisite of #529's API Gateway v2 criterion.
@codecov

codecov Bot commented Aug 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 15867b6 into main Aug 4, 2026
16 checks passed
@scttfrdmn
scttfrdmn deleted the fix/561-routing-apigatewayv2-sso branch August 9, 2026 17:48
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.

SSO Admin is unreachable: parser.go maps a guessed X-Amz-Target prefix, not the real SWBExternalService

1 participant