chore(ers): failing tests for environment-first strategy ordering - #3980
Conversation
First-match-wins chain building stops at the first matching strategy. When that strategy is entity_type: environment, the chain holds only an ENVIRONMENT entity. GetDecision resolves tokens with skipEnvironmentEntities=true, so the chain filters to empty and the request fails with "no subject entities to resolve"; the error is not errResolvedTokenChainRequiresHydration, so the hydration fallback does not fire. Adds tests pinning that behavior end to end through the real ERS v2 handler, plus a control proving the same token resolves when a subject strategy is first. Also asserts that opentdf-ers-test.yaml -- the config the README tells operators to start the platform with -- selects an environment strategy first for a Keycloak-shaped token, since its client_environment_sql strategy is conditioned on "azp exists" and listed ahead of every subject strategy. Tests only; no behavior change. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: Paul Flynn <pflynn-virtru@users.noreply.github.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Team Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
|
Flips the two characterization tests to assert the outcome that should hold, so they fail and demonstrate the bug rather than pinning it. RED: - resolveEntitiesFromToken must resolve alice's subject entity when an entity_type: environment strategy is configured ahead of the subject strategy. Fails with "no subject entities to resolve - all were environment entities and skipped". - opentdf-ers-test.yaml must select a subject-resolving strategy for a Keycloak token. Fails: client_environment_sql (environment, "azp exists") wins ahead of user_subject_sql. Both assert the required outcome rather than a mechanism, so reordering the YAML, skipping environment-typed strategies when picking the chain winner, or rejecting the ordering at config load all satisfy them. Controls stay green: the same strategies in subject-first order resolve, and the environment-first chain is well-formed until the decision flow filters it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: Paul Flynn <pflynn-virtru@users.noreply.github.com>
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
|
Replaces the hand-written realERSV2Client adapter, which was "real" only in that it delegated to the ERS implementation; the client half was still test scaffolding standing in for sdkconnect. The harness now mounts the generated entityresolutionv2connect.NewEntityResolutionServiceHandler over the real ERSV2 on an httptest server, and the PDP reaches it through sdkconnect.NewEntityResolutionServiceClientV2ConnectWrapper -- the same client sdk.New builds. Proto marshalling, the Connect codec, and the production client wrapper are all exercised; only the strategy configuration is test-supplied. Call-count assertions move to a connect.Interceptor keyed on the generated procedure constants, so they observe real RPCs instead of adapter bookkeeping. Same RED, same failure reason. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: Paul Flynn <pflynn-virtru@users.noreply.github.com>
|
Benchmark results, click to expandBenchmark authorization.GetDecisions Results:
Benchmark authorization.v2.GetMultiResourceDecision Results:
Benchmark Statistics
Bulk Benchmark Results
TDF3 Benchmark Results:
|
These tests fail on purpose. Tests only, no behavior change — the point is to demonstrate the bug.
The failures
Why
First-match-wins chain building (
multi-strategy/v2/registration.go:300) stops at the first matching strategy. When that strategy isentity_type: environment, the chain holds only anENVIRONMENTentity.GetDecisionresolves tokens withskipEnvironmentEntities = true(just_in_time_pdp.go:160), sofilterEntityChainempties the chain and the request fails. The error is noterrResolvedTokenChainRequiresHydration, so the fallback atjust_in_time_pdp.go:461never fires — the decision request just errors.This is reachable with a config already in-tree.
opentdf-ers-test.yaml, whichREADME.md:84tells operators to start the platform with, runsfailure_strategy: continueand listsclient_environment_sql(entity_type: environment, conditionazp exists) ahead of every subject strategy. Every Keycloak token carriesazp.Nothing guards the ordering:
entity_typehas no config validation,SelectStrategiespreserves configuration order, andEntityChaininentity.protohas no category or cardinality constraints. No BDD feature usesentity_type: environment— every ERS feature is subject-only, which is why the suite is green on#3964.Tests
service/internal/access/v2/just_in_time_pdp_environment_chain_test.go— runs the real ERS v2 handler through the PDP via a thinsdkconnectadapter....ResolvesSubjectWhenEnvironmentStrategyIsFirst...ResolvesSubjectWhenSubjectStrategyIsFirst...EnvironmentFirstChainIsWellFormedButEmptyAfterFilteringservice/entityresolution/multi-strategy/shipped_config_test.go— parsesopentdf-ers-test.yamland runs the real matcher.TestShippedERSConfigResolvesASubjectForKeycloakTokenTestShippedERSConfigOrderingIsUnvalidatedBoth RED tests assert the required outcome, not a mechanism, so any plausible fix satisfies them: reorder the YAML, skip environment-typed strategies when picking the chain winner, keep the environment entity but continue to the first subject match, or reject the ordering at config load.
Note on the ADR
The ADR does not cover this. Its first-match-wins language (lines 406, 425-427) is scoped to single-entity
ResolveEntity. § Future Considerations → Entity Chains Handling (line 775) states chains are not yet handled and lists "how failure strategies apply across entity chains" as open. Deciding chain semantics for environment-typed strategies likely warrants an ADR amendment.🤖 Generated with Claude Code