Repository navigation
mod_authn_dbd, mod_authn_socache: Preserve extra query columns on a c… - #982
arturobernalg wants to merge 1 commit into
Conversation
|
Can you put the test under |
683545a to
ce031dc
Compare
@notroj please do another pass |
notroj
left a comment
There was a problem hiding this comment.
This feels like an awkward, undocumented, API hack to avoid adding an apr_hash_t * argument to the ap_authn_cache_store hook - or creating a new hook which takes that argument for backwards compat reasons.
If this is a useful mod_authn_socache feature, that module is the right place to handle the serialization/deserialization of the hash table which is currently split between the two modules here. (IMO it would also be fine to say this is an anti-feature and you should simply not stick mod_authn_socache in front of the database if you want the extra AUTHENTICATE_ variables)
e.g. is it definitely right for socache to stuff that hash into the same k/v pair as the password? Maybe it is, maybe it's more natural to have two k/v pairs - or one extra k/v pair for each extra env var? not sure.
ce031dc to
9fe86d9
Compare
|
Thanks, reworked along those lines. There's now a separate optional function, ap_authn_cache_store_env(), which takes an apr_table_t with the variables to restore. I went with a table rather than a hash since that's what ends up in r->subprocess_env anyway. ap_authn_cache_store() is unchanged for the other providers. mod_authn_socache does all the (de)serialization now, mod_authn_dbd just hands over the table. I kept it as a single k/v per user. That way the variables expire and get evicted together with the password, and a hit is still one lookup. With separate entries we could hit on the password and miss the variables, which is the original bug again. The format is NUL separated, so values with newlines work too, and if it doesn't fit in the 256 byte read buffer it's just not cached. Also renamed the test to test_017, since trunk has a test_016 in aaa now. |
9fe86d9 to
c643971
Compare
…ache hit
AuthDBDUserPWQuery and AuthDBDUserRealmQuery may select columns beyond
the password, which mod_authn_dbd exports as AUTHENTICATE_<NAME>. With
mod_authn_socache in front of it ("socache dbd"), only the first,
uncached login got them: a cache hit is answered from the cached hash
alone.
Add the optional function ap_authn_cache_store_env(), which takes the
variables a lookup set along with the value to cache. mod_authn_socache
keeps them in the same cache entry, so that they expire with it, and
sets them again on a hit. mod_authn_dbd passes its extra columns
through it, and does not cache a lookup with extra columns in a cache
without it. An entry too long to be read back whole is not cached.
PR 65172.
c643971 to
2547844
Compare
AuthDBDUserPWQuery may select columns beyond the password; each extra column is exported as AUTHENTICATE_ in r->subprocess_env by authn_dbd_password()/authn_dbd_realm(), the documented way to pass along per-user data from the database. With AuthBasicProvider "socache dbd" (the combination the docs recommend for caching), only the first, uncached login for a user goes through that code; once mod_authn_socache has a cache entry, its own check_password()/get_realm_hash() answer directly from the cached password hash and never call back into mod_authn_dbd, so AUTHENTICATE_* silently disappears on every following login until the entry expires.
Have mod_authn_dbd append the already-exported extra columns to the string it hands to ap_authn_cache_store(), as one NAME=VALUE line per column after the password hash (a column whose value contains a newline is left out of the cache, though still set in the current request's own environment, since it would be misread as an extra line). mod_authn_socache splits the hash back off on a cache hit and restores those entries into r->subprocess_env before validating, so a cache hit behaves like a real lookup from the caller's point of view. This does not change the signature of ap_authn_cache_store(), which already takes a plain string.
PR 65172.
Verified with a new pytest case (test/modules/authn_dbd_cache/) against a real built server (SQLite + mod_dbd + a CGI script reading the environment): the first login shows the extra column correctly; a second login with the same credentials, served from the cache, loses it before this change and keeps it after. The existing aaa test suite (84 tests) passes unchanged.
Checklist:
[x] This PR does not report or address a security vulnerability (see SECURITY.md and https://www.apache.org/security/#reporting-a-vulnerability).
[x] Code follows the httpd style guide (https://httpd.apache.org/dev/styleguide.html).
[x] New log messages: none added by this change.
[x] changes-entries/65172.txt is included, following the README.CHANGES template.
[x] Test cases are included (test/modules/authn_dbd_cache/) and pass locally against a real build.