Skip to content

node: name the failed check in the label gate's 403 - #984

Merged
aojea merged 1 commit into
google:mainfrom
HosniBelfeki:fix/label-gate-denial-reason
Nov 28, 2026
Merged

aojea merged 1 commit into
google:mainfrom
HosniBelfeki:fix/label-gate-denial-reason

Conversation

@HosniBelfeki

Copy link
Copy Markdown
Contributor

Follow-up to #954: now that a failed label check carries ErrLabelsNotSatisfied, the label gate's 403 can name the check the provider's credential failed instead of guessing from what the caller sent.

The egress proxy picked the text from the request: any refusal other than ErrProviderNotGranted became "Required labels not attested by provider" when the caller sent X-Mesh-Required-Labels, and "provider does not attest the egress floor" when a floor was set. The A2A gate answered "Required labels not attested by provider" for every refusal. The log line already had the real reason; only the text the caller sees was wrong.

With the credentials checkProvider actually refuses:

Provider credential Before After
Expired, caller requires labels Required labels not attested by provider Forbidden: destination is not an enrolled peer
Signed by an untrusted key, caller requires labels Required labels not attested by provider Forbidden: destination is not an enrolled peer
None, egress floor set Forbidden: provider does not attest the egress floor Forbidden: destination is not an enrolled peer
Lacks a required label Required labels not attested by provider unchanged
Lacks a floor label Forbidden: provider does not attest the egress floor unchanged
Not granted the service Forbidden: provider is not granted mcp://calc (A2A: Required labels not attested by provider) Forbidden: provider is not granted mcp://calc

labelGateDenial reads the check from the error, and the egress proxy and the A2A gate both use it. Status codes are unchanged.

TestLabelGateDenialNamesTheFailedCheck covers the six rows; the first three fail with the previous logic.

Not changed here: the CONNECT path tries several providers and still answers "Required labels not attested by provider" when any of them refused, since each may have refused for a different reason.

Tested in Docker (golang:1.26): go test ./internal/node/..., go test -race on the label gate, A2A and egress proxy tests, TestUngrantedServiceIsNeitherPublishedNorServed and TestA2ACUJ from tests/integration, go vet, and golangci-lint v2.14.0.

The egress proxy chose the text of a label-gate refusal from what the
caller sent rather than from what the provider's credential failed. A
caller that sent X-Mesh-Required-Labels and reached a peer whose
credential had expired, or was signed by an untrusted key, was told
"Required labels not attested by provider". With an egress floor set, a
peer with no credential at all was reported as not attesting the floor.
The A2A gate answered "Required labels not attested by provider" for
every refusal, including a provider not granted the service.

labelGateDenial now reads the check from the error: ErrProviderNotGranted
names the missing grant, ErrLabelsNotSatisfied names the caller's
requirement or the floor, and anything else says the destination is not
an enrolled peer. The egress proxy and the A2A gate both use it. Status
codes are unchanged.
@HosniBelfeki
HosniBelfeki requested a review from aojea as a code owner November 28, 2026 19:06

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the error reporting logic in the label gate by introducing a centralized helper function labelGateDenial in internal/node/labels_gate.go. This helper determines the specific reason for a 403 Forbidden response based on the verification error, required labels, and egress floor. The a2aEgressGate in a2a_service.go and createEgressProxy in sidecar.go have been updated to use this helper, reducing code duplication. Additionally, a comprehensive unit test TestLabelGateDenialNamesTheFailedCheck has been added to labels_gate_test.go to verify the correct error messages are returned for various failure scenarios. No issues were found, and there is no additional feedback to provide.

@aojea
aojea merged commit b70f4e3 into google:main Nov 28, 2026
19 checks passed
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.

2 participants