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.


-- 
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]

Reply via email to