fix(auth): dispatch honours the factory-resolved opt-out again - #4602
Merged
Conversation
A change that shipped inside an unrelated PR replaced the dispatch-time check of the resolved opt-out flag with a live read of the environment variable alone. The constructor kept resolving auth_disabled (explicit arg from the app factory, i.e. auth.enabled: false in configuration, OR the environment) into self._auth_disabled -- and nothing read it. A deployment that switches auth off by configuration got 401s on every protected route while still logging the auth-is-disabled warning at startup. Dispatch now honours both signals: the factory-resolved flag and the live environment read, so a variable exported after construction still counts. Two regression tests pin each signal separately.
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.
Problem
SSOAuthMiddleware.dispatchgates its unauthenticated pass-through onauth_disabled_via_opt_out()alone — a live read ofBERNSTEIN_AUTH_DISABLED. The constructor still resolves the factory argument (auth.enabled: falsein configuration arrives asauth_disabled=True) intoself._auth_disabled, but nothing reads that attribute any more. The regression shipped inside #4577, which is about skill collision guards; the middleware line was unrelated to that change.Net effect: a deployment that disables auth by configuration logs the loud "auth is DISABLED" warning at startup and then returns 401 on every protected route anyway. The documented opt-out surface (
docs/security/manager-auth.md) no longer matched behaviour.Fix
Dispatch honours both signals:
The live environment read is kept on purpose — a variable exported after the middleware stack is built still counts, which is the one property the #4577 change added.
Tests
test_config_resolved_opt_out_survives_without_the_env_var—auth_disabled=Truefrom the factory bypasses the gate with no env var set; fails before this fix.test_env_opt_out_set_after_construction_still_counts— pins the live-read property so honouring the flag cannot regress the env path.Both run in the existing
test_auth_middleware_defaults.pysuite (33 passed).