smolnar82 opened a new pull request, #1511: URL: https://github.com/apache/knox/pull/1511
[KNOX-3568](https://issues.apache.org/jira/browse/KNOX-3568) - Audit the outcome of every delegated (act-bearing) request checked by K8sDestinationAudienceValidator ## What changes were proposed in this pull request? Requests presenting a delegated token (one carrying an RFC 8693 `act` claim) now leave an audit trail at the destination, whether the token is accepted or rejected. Tokens without an `act` claim produce no new records. - **Audience-check record:** `K8sDestinationAudienceValidator` writes an `audience-validation` record (a new `Action`) with the outcome of the check: `event_type=delegated_audience_check claims_verified=false token_id=... sub=... act_chain=... dest_service=... [dest_spiffe_id=...] path=...`, plus `reason=audience_invalid detail=...` on failure. The destination header values are recorded raw, so even a value that fails to parse shows up. - **Rejection record:** whenever `AbstractJWTFilter` rejects a delegated token, it writes an `authentication` failure record with `event_type=delegated_request_rejected` and a machine-parseable reason: `audience_invalid`, `token_expired`, `signature_invalid`, `untrusted_issuer`, `not_before`, `token_disabled`, `idle_timeout_exceeded` or `token_state_unknown`. - **Success record:** the existing authentication success record for a delegated token (`act_chain=...`) now also carries the destination fields (`dest_service`, `dest_spiffe_id`, `path`). - **Safety:** - The claims are read before the signature is verified, so the records say `claims_verified=false`. - Every value is length-capped and stripped of line-breaking characters, and quoted if it contains whitespace or `"`. - The token is identified only by its displayable id, and no token material is written. - The record's resource name drops the query string, which may carry credentials. - The audience-failure reason logged by `AbstractJWTFilter` is now sanitized the same way. The new logic lives in `DelegatedRequestAuditing`. A new `rejectToken` helper in `AbstractJWTFilter` writes the rejection record and then calls the existing `handleValidationError`. ## How was this patch tested? - New unit tests: - `DelegatedRequestAuditingTest`: field rendering, sanitization, quoting and query stripping. - `K8sDestinationAudienceValidatorAuditTest`: audience-check records for accepted and rejected tokens, nested act chains, raw header values, and no record for tokens without `act`. - `DelegatedRequestAuditTest`: the full `JWTFederationFilter` trail, i.e. the audience check followed by the success record or the rejection record with its reason. - `mvn verify` on `gateway-util-common` and `gateway-provider-security-jwt` passes (728 tests in the JWT provider module). - Docker Compose integration suite run locally: 151 passed. ## Integration Tests `knoxauthtoken.xml` now runs the k8s destination audience validator (`x-dest-server-name` header, `validate.audiences.without.act.claim=false`). Tokens without an `act` claim are unaffected, so the existing KNOX-3478 token-forwarding tests on that topology still pass. The new `delegated_audit_helpers.py` reads `gateway-audit.log` from the mounted log directory and finds a request's records by request id, using a random query marker. - `test_delegation.py`: - An accepted delegated token leaves an audience-validation success record and an authentication success record with the act chain and destination. - A token presented for another destination gets a 400 and leaves an audience-validation failure record and a `delegated_request_rejected` record, both with `reason=audience_invalid`. - A token exchanged twice is audited with its whole act chain, most recent actor first (`sam<-recursiveUser`). - No audit line contains the token's signature. - `test_token_exchange.py`: a same-subject exchanged token (no `act` claim) leaves no audience-validation record and a plain authentication success record. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
