[ 
https://issues.apache.org/jira/browse/KNOX-3568?focusedWorklogId=1054320&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1054320
 ]

ASF GitHub Bot logged work on KNOX-3568:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 12/Nov/26 15:45
            Start Date: 12/Nov/26 15:45
    Worklog Time Spent: 10m 
      Work Description: smolnar82 commented on code in PR #1511:
URL: https://github.com/apache/knox/pull/1511#discussion_r4552692363


##########
gateway-provider-security-jwt/src/main/java/org/apache/knox/gateway/provider/federation/jwt/filter/K8sDestinationAudienceValidator.java:
##########
@@ -695,6 +704,22 @@ private Optional<String> pathFromHeader(final 
HttpServletRequest request) {
     return AudienceResource.normalizeAndTidy(rawPath);
   }
 
+  // Raw header values, so that even a value that fails to parse is recorded.

Review Comment:
   Thanks, @lmccay . I made a small change that clarifies the above method.





Issue Time Tracking
-------------------

    Worklog Id:     (was: 1054320)
    Time Spent: 40m  (was: 0.5h)

> Audit the outcome of every delegated (act-bearing) request checked by 
> K8sDestinationAudienceValidator
> -----------------------------------------------------------------------------------------------------
>
>                 Key: KNOX-3568
>                 URL: https://issues.apache.org/jira/browse/KNOX-3568
>             Project: Apache Knox
>          Issue Type: Improvement
>          Components: JWT, KnoxIDF
>            Reporter: Sandor Molnar
>            Assignee: Sandor Molnar
>            Priority: Critical
>             Fix For: 3.1.0
>
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> With RFC 8693 on-behalf-of token exchange, a delegated token names the user 
> in {{sub}} and the acting workload in the {{act}} claim. Knox records the 
> delegation when it mints the token ({{TokenResource}}, 
> {{addingActorClaimToToken}}). KNOX-3477 also adds {{act_chain=}} to the 
> {{authentication|success}} record in {{gateway-audit.log}} once a delegated 
> token is accepted.
> What's not recorded is which destination the delegated token was presented 
> to, or any delegated request that was rejected. When 
> {{K8sDestinationAudienceValidator}} (KNOX-3491/KNOX-3509) rejects a token, 
> the only trace is a {{gateway.log}} WARN with no actor and no destination. If 
> a workload misuses or replays a delegated token, nothing ties the attempt to 
> that workload. Because the backend services only see the end user, Knox is 
> the one place that can record it.
> h3. Proposal
> For tokens carrying an {{act}} claim, write two kinds of records to 
> {{gateway-audit.log}}:
> # a *validator record*, written by {{K8sDestinationAudienceValidator}}, 
> stating what the audience check decided;
> # a *final record*, written by {{AbstractJWTFilter.validateToken}}, stating 
> what Knox decided for the request.
> Both records for a request share the root/parent/request correlation ids that 
> {{AuditLayout}} already writes on every line, so they can be joined.
> h4. Validator record
> Written whenever the topology's request audience validator is 
> {{request.audience.k8s.destination.validation}}, the validator runs, and the 
> token has an {{act}} claim.
> * Uses a new action, e.g. {{Action.AUDIENCE_VALIDATION}}, so it can be 
> filtered separately from {{authentication}} records.
> * The outcome is the audience check's result: {{success}}, or {{failure}} 
> with the reason.
> * Carries {{claims_verified=false}}. The audience check runs before signature 
> verification, so the claims in this record are not verified yet.
> * Fields:
> ** {{sub}}: the user. It goes in the message, because the audit context's 
> {{username}} column is only populated later, in 
> {{continueWithEstablishedSecurityContext}}.
> ** {{act_chain}}: the actor chain from outermost (most recent) to innermost. 
> Use the same rendering as KNOX-3477 ({{SubjectUtils.renderActorChain}}).
> ** {{dest_service}}: the destination as read from the configured 
> {{request.audience.k8s.server.name.header.name}} (and/or the namespace from 
> the destination SPIFFE-id header, if that's configured).
> ** {{path}}: the request path (the configured path header if set, otherwise 
> the request URI). No query string.
> ** {{reason}}: on failure only.
> h4. Final record
> Written by the filter once the outcome is known, for every delegated request 
> it rejects or accepts.
> * *Accepted:* extend the existing KNOX-3477 
> {{authentication|success|act_chain=...}} record with {{dest_service}} and 
> {{path}} rather than writing a second success line. The validator exposes the 
> destination and path it parsed through a request attribute, so the filter 
> doesn't parse them again.
> * *Rejected:* a new {{authentication|failure}} record (none exists today) 
> with {{sub}}, {{act_chain}}, {{dest_service}}, {{path}} and the reason. This 
> covers every rejection: expiry, the audience check, not-before, a disabled 
> token, the idle timeout, and the signature.
> When the audience check passes but a later check fails (e.g. a forged token 
> rejected on its signature), the validator record shows {{success}} with 
> {{claims_verified=false}}, and the final record shows the actual rejection.
> h3. Constraints
> * Tokens without {{act}} produce no new record. Existing behavior for those 
> tokens is unchanged.
> * No token material is logged: no raw JWT, no signature. The token id 
> ({{displayableTokenId}}) is allowed.
> * Every value that comes from a header or claim ({{sub}}, {{act}} entries, 
> header values, path, and the rejection reason) is sanitized before logging, 
> in both records. CR, LF and other control characters are escaped or removed, 
> and long values are truncated, so a value can't inject or fake log lines.
> * The same sanitization is applied to the existing 
> {{failedToValidateAudience}} reasons, which currently copy raw header values 
> into {{gateway.log}}.
> h3. Acceptance criteria
> * Every delegated request writes exactly one final record, accepted or 
> rejected.
> * Every delegated request that reaches {{K8sDestinationAudienceValidator}} 
> also writes exactly one validator record, marked {{claims_verified=false}}.
> * Both records for a request can be correlated by request id.
> * Non-delegated tokens produce no new record of either kind.
> * No raw JWT or signature appears in any record.
> * Header and claim values are sanitized against CR/LF and control-character 
> injection.
> * Unit tests cover:
> ** an accepted request (validator record {{success}}, final record extends 
> the KNOX-3477 success record);
> ** a rejection for an {{aud}}/destination mismatch (validator record 
> {{failure}}, final record {{failure}});
> ** an audience check that passes followed by a signature failure (validator 
> record {{success}}, final record {{failure}});
> ** an expired delegated token (final record only);
> ** a nested {{act}} chain with 2 or more levels, checking the order;
> ** a token without {{act}} (no new records);
> ** an injection attempt (CR/LF in the destination header and in {{act.sub}}).



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to