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

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

                Author: ASF GitHub Bot
            Created on: 03/Dec/26 10:52
            Start Date: 03/Dec/26 10:52
    Worklog Time Spent: 10m 
      Work Description: hanicz opened a new pull request, #1560:
URL: https://github.com/apache/knox/pull/1560

   …cesses
   
   [KNOX-3628](https://issues.apache.org/jira/browse/KNOX-3628) - Cached 
gateway credentials survive changes made to the credential store by other 
processes
   
   ## What changes were proposed in this pull request?
   
   `DefaultKeystoreService` returned cached credentials without checking the 
credential store file. A change made by another JVM, such as `knoxcli 
create-alias` or `create-k8s-alias`, was never picked up: the gateway kept the 
old value until it restarted, even across a config reload. The LDAP proxy bind 
password is one example. `expireAfterAccess` made this worse, because every 
lookup reset the TTL.
   
   - Each credential cache entry (`CachedCredential`) now stores the 
`KeyStoreFileStamp` (mtime, size, file key) of the store it was read from. If 
the stamp no longer matches, the lookup is treated as a miss and the value is 
reloaded from the file.
   - The stamp is read before the store is loaded, so a change made during the 
load still forces a reload. This works with the keystore file cache on or off.
   - In-process writes no longer re-cache the values they wrote. They 
invalidate them, so the next read loads from the file and can't pair our value 
with a concurrent external write.
   - The `getCredentialForCluster(cluster, alias, KeyStore)` variant no longer 
caches, because it can't tell which file state the given `KeyStore` came from. 
No SPI changes.
   - Missing aliases are still not cached, so the KNOX-3513 retry is unaffected.
   - The timestamp-granularity rule is shared with `CachedKeyStore` through 
`KeyStoreFileStamp.validUntil()`.
   
   ## How was this patch tested?
   
   - **New `DefaultKeystoreServiceTest` cases**, all run with the keystore file 
cache on and off:
     - an external change returns the new value;
     - an alias removed externally is no longer returned;
     - an unchanged store is served from the cache without a reload;
     - in-process add/remove still works next to other cached aliases.
   
     `testCredentialCache` was rewritten: it asserted that a cached value 
outlives a change of the security dir, which is exactly the old behavior.
   - **New `KnoxLDAPServerManagerTest` case:** after an external alias change, 
a stop/initialize reload resolves the new password.
   - Both external-change tests fail without the fix (old value returned).
   - `mvn -pl gateway-server verify`: 1182 tests pass; checkstyle, PMD and 
forbiddenapis are clean.
   - **Manual test** on a running gateway, with the LDAP proxy bound through 
`${ALIAS=...}`:
     - rotating the alias with knoxcli and touching `gateway-reloadable.xml` 
took effect without a restart, both to a wrong password and back;
     - JFR file-read tracing showed no further reads of the untouched 
credential store across reloads 6+ minutes apart.
   
   ## Integration Tests
   
   None added. The unit tests cover the external-change scenario directly, and 
the manual test above covers the reload end to end.
   
   ## Performance implications
   
   A credential cache hit now costs one `stat` of the credential store 
(metadata only; no lock, no file read). A cached `getKeystore` with a password 
alias now does two stats instead of one. A change to a store causes one reload 
per cached alias of that store. There is no other impact.




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

            Worklog Id:     (was: 1058416)
    Remaining Estimate: 0h
            Time Spent: 10m

> Cached gateway credentials survive changes made to the credential store by 
> other processes
> ------------------------------------------------------------------------------------------
>
>                 Key: KNOX-3628
>                 URL: https://issues.apache.org/jira/browse/KNOX-3628
>             Project: Apache Knox
>          Issue Type: Bug
>          Components: Server
>    Affects Versions: 3.0.0
>            Reporter: Tamás Hanicz
>            Assignee: Tamás Hanicz
>            Priority: Major
>          Time Spent: 10m
>  Remaining Estimate: 0h
>




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

Reply via email to