Restore mtime-based eviction on get_rsa_key - #69943
Open
dwoz wants to merge 1 commit into
Open
Conversation
The server-side PKI refactor (PR saltstack#67799) collapsed the two-layer memoize helper into a single decorated get_rsa_key(path, passphrase), dropping the file mtime from the memoize key. salt.utils.decorators.memoize is a plain str-keyed dict cache with no mtime handling, so a private key rotated on disk was served stale from the process's in-memory cache until restart. Restore the pre-refactor pattern: a memoized _get_key_with_evict(path, timestamp, passphrase) inner helper called from get_rsa_key with str(os.path.getmtime(path)) so an mtime bump invalidates the cache entry and the fresh key is loaded from disk. Fixes saltstack#69941
Contributor
Author
|
@mattp- Please review |
twangboy
approved these changes
Aug 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
salt.crypt.get_rsa_keyso a rotated private key on disk is picked up without a process restart._get_key_with_evict(path, timestamp, passphrase)helper (memoized) and threadstr(os.path.getmtime(path))through as the eviction key fromget_rsa_key.PrivateKey.from_file.Investigation notes
The eviction was dropped as an incidental change in the server-side PKI refactor merged as #67799 ("new feature: refactor server-side PKI") by @mattp-, specifically follow-up commit
ce9308f126f("migrate remaining master side pki to cache"). That refactor moved the disk-load logic intoPrivateKey.from_fileand simplified the outer function to:The
@salt.utils.decorators.memoizedecorator is a plain str-keyed dict cache (seesalt/utils/decorators/__init__.py::memoize) with no built-in mtime handling. Before the refactor, an inner_get_key_with_evict(path, timestamp, passphrase)was the memoized function andget_rsa_keysuppliedstr(os.path.getmtime(path))as the eviction argument, so a rotated key file (new mtime) produced a different memoize key and the cached entry was bypassed. Collapsing to a single decorated function dropped that eviction semantic.The mtime pattern still exists in
_auth_singleton_keyatsalt/crypt.py:893for theAsyncAuthinstance singleton cache, but that is a separate cache and does not compensate for theget_rsa_keyregression.This PR restores the original two-layer pattern with the newer
PrivateKey.from_fileloader inside the helper. It is intentionally the minimal restoration: no changes toget_rsa_pub_key,PublicKey.decrypt, orPrivateKey.encryptcaching.Test plan
pytest tests/pytests/unit/crypt/clean locally (31 passed, 5 FIPS-only skipped)test_get_rsa_key_evicts_on_mtime_changefails on unpatched 3008.x, passes with fixpre-commit run --files salt/crypt.py tests/pytests/unit/crypt/test_crypt_cryptography.py changelog/69941.fixed.mdcleanFixes #69941