You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tooling.apache.org by "andrewmusselman (via GitHub)" <gi...@apache.org> on 2026/03/25 22:12:06 UTC

[I] LDAP state in dev/debug/test modes and users (tooling-trusted-releases)

andrewmusselman opened a new issue, #944:
URL: https://github.com/apache/tooling-trusted-releases/issues/944

   Discussion point that came up during key revokation in #922 
   
   From @dave2wave:
   ```
   I think we need to be clear on ldap state in development/debug/test modes and users. ASVS L2 finds our inconsistencies. We should probably discuss the rules we really need. This way you can properly handle edge cases.
   ```
   
   # LDAP State in Dev/Debug/Test Modes — Discussion Points
   
   ## Context
   
   ASVS L2 compliance review has surfaced inconsistencies in how ATR handles LDAP-dependent authentication and authorization across its operating modes: **Production**, **Debug**, and **Debug+ALLOW_TESTS**. The core tension is that LDAP is the source of truth for user identity, account status, committee membership, and admin roles — but in development scenarios it may be unavailable, partially available, or entirely bypassed.
   
   This document maps the specific inconsistencies found in the codebase and proposes rules to discuss.
   
   ---
   
   ## 1. The Three Operating Modes (and what actually changes)
   
   | Behavior | Production | Debug (no ALLOW_TESTS) | Debug + ALLOW_TESTS |
   |---|---|---|---|
   | LDAP credentials required? | Yes (startup fails without them in `principal.py`) | No (graceful degradation) | No |
   | `ldap.is_active()` when no credentials | N/A | **Returns `True` for everyone** | Returns `True` for everyone |
   | `"test"` user gets admin? | No | No | **Yes** |
   | `"test"` user bypasses LDAP entirely? | No | No | **Yes** (hardcoded in `principal.py`, `ldap.py`, `user.py`) |
   | Rate limiting enabled? | Yes | Yes | **No** |
   | Session cache file used for auth? | No | **Yes** (fallback in `AuthoriserLDAP`) | Yes |
   | `_augment_test_membership()` adds "test" to everyone? | No | No | **Yes** |
   | Test login endpoint (`/test/login`) available? | No (404) | No (404) | **Yes** (creates session with no LDAP) |
   
   ### Discussion Point 1a: `is_active()` silently returns `True` when LDAP is unconfigured
   
   In `atr/ldap.py` line 248:
   
   ```python
   async def is_active(asf_uid: str) -> bool:
       if get_bind_credentials() is None:
           return True  # ← Any UID is treated as active
   ```
   
   This means if a developer accidentally runs without LDAP credentials, **every user is considered active including banned accounts**. This is the primary path for checking banned/deleted accounts in `blueprints/common.py`, `jwtoken.py`, and `ssh.py`.
   
   **Question**: Should this be `return False` (fail-closed) when LDAP is unavailable in non-Debug modes? Or should it raise an error rather than silently succeeding?
   
   ### Discussion Point 1b: `fetch_admin_users()` and `fetch_tooling_users()` degrade differently
   
   When LDAP is unavailable:
   - `fetch_admin_users()` returns `frozenset()` — no admins (fail-closed)
   - `fetch_tooling_users(extra)` returns `extra` — the additional users still get tooling access
   
   This is inconsistent. One fails closed, the other partially open.
   
   ---
   
   ## 2. The "test" User — A Synthetic Identity with Real Privileges
   
   When `ALLOW_TESTS=True`, a synthetic `"test"` user is created across at least **seven different code paths**, each with its own hardcoded bypass:
   
   | Location | What it does |
   |---|---|
   | `ldap.is_active()` | Returns `True` without checking LDAP |
   | `user.is_admin()` / `is_admin_async()` | Returns `True` — test is a full admin |
   | `principal.AuthoriserLDAP.cache_refresh()` | Hardcodes `committees={"test"}, projects={"test"}` |
   | `principal._augment_test_membership()` | Adds "test" committee/project to **every authenticated user** |
   | `server._initialise_test_environment()` | Creates DB records: test committee, project, with `"test"` as sole member |
   | `get/test.py::test_login` | Creates a session cookie with `uid="test"` and no LDAP verification |
   | `user.projects()` | Makes the test project visible to all users |
   
   ### Discussion Point 2a: The test user is an admin everywhere, not just for the test project
   
   `user.is_admin("test")` returns `True` globally. This means in ALLOW_TESTS mode, the test user can access admin functions like "browse as", LDAP lookup, release deletion, token revocation, and project management. If ALLOW_TESTS accidentally leaks into a production-like environment, this is a privilege escalation path.
   
   **Question**: Should the test user be admin of the test project only, or is full admin necessary for testing? Could we scope it?
   
   ### Discussion Point 2b: `_augment_test_membership()` modifies real users' memberships
   
   In `principal.py` line 412:
   
   ```python
   def _augment_test_membership(committees, projects):
       if config.get().ALLOW_TESTS:
           committees = committees.union({"test"})
           projects = projects.union({"test"})
       return committees, projects
   ```
   
   This is called for **every user**, not just the test user. Every real developer who authenticates via LDAP in Debug+ALLOW_TESTS mode is silently granted membership in the "test" committee and project. This is intentional (so devs can interact with the test project) but is never documented or surfaced to the user.
   
   **Question**: Is this the right approach, or should developers be explicitly added to the test committee in the database instead?
   
   ### Discussion Point 2c: The `/test/login` endpoint bypasses all authentication
   
   ```python
   session_data = atr.models.session.CookieData(
       uid="test", fullname="Test User",
       pmcs=["test"], projects=["test"],
       isMember=False, isChair=False, ...
   )
   util.write_quart_session_cookie(session_data)
   ```
   
   This creates a valid session with no password, no LDAP check, and no OAuth flow. The guard is only `config.get().ALLOW_TESTS`. There is also a config check that `ALLOW_TESTS` can only be enabled in Debug mode, but Debug mode itself is only restricted via `util.is_dev_environment()`.
   
   **Question**: What are the exact conditions for `is_dev_environment()` and are they sufficient? If it only checks for the absence of `PRODUCTION=true`, a misconfigured deployment could end up in Debug mode.
   
   ---
   
   ## 3. Session Cache File — A Parallel Auth Path
   
   In `principal.py::AuthoriserLDAP.cache_refresh()`, when running in Debug mode (even without ALLOW_TESTS), there's a **session cache file** fallback:
   
   ```python
   if config.get_mode() == config.Mode.Debug:
       session_cache = await util.session_cache_read()
       if asf_uid in session_cache:
           # Use cached data instead of querying LDAP
   ```
   
   This reads from `state/cache/user_session_cache.json` and bypasses LDAP entirely for committee/project membership data. If this file contains stale data (e.g., a user was removed from a committee), the application won't know.
   
   ### Discussion Point 3: The session cache has no TTL or integrity check
   
   The cache file is a plain JSON file with no expiration timestamp, no signature, and no validation. If it exists and contains an entry for a UID, that entry is trusted completely. Compared to the in-memory `principal.Cache` which has a 600-second TTL, this file-based cache has infinite TTL.
   
   **Question**: Should this file-based cache be removed, given a TTL, or at minimum documented as a development-only convenience that will never be enabled in production?
   
   ---
   
   ## 4. SSH Authentication — Different LDAP Failure Semantics
   
   The SSH server in `ssh.py` checks LDAP directly during `begin_auth()`:
   
   ```python
   account = await ldap.account_lookup(username)
   if account is None or ldap.is_banned(account):
       log.failed_authentication("account_banned_or_deleted")
       return True  # ← Still requires auth, but won't match keys
   ```
   
   But `ldap.account_lookup()` calls `get_bind_credentials()`, which returns `None` when LDAP isn't configured. When credentials are `None`, `account_lookup` returns `None`. This means the SSH path treats "LDAP unavailable" the same as "account doesn't exist" — which means **SSH auth fails closed** when LDAP is down.
   
   Meanwhile, the web path (`blueprints/common.py`) calls `ldap.is_active()`, which returns `True` when LDAP is unavailable — **web auth fails open**.
   
   ### Discussion Point 4: SSH fails closed, Web fails open — same system, opposite behavior
   
   | Auth Path | LDAP unavailable → | LDAP says user is banned → |
   |---|---|---|
   | Web (`is_active`) | **Allows access** | Denies access |
   | SSH (`account_lookup`) | **Denies access** | Denies access |
   | JWT (`is_active`) | **Allows access** | Denies access |
   | PAT validation (`is_active`) | **Allows access** | Denies access |
   
   **Question**: Should all paths have the same failure mode? The safe default for a security-sensitive application is fail-closed.
   
   ---
   
   ## 5. JWT/PAT Authentication and LDAP Coupling
   
   In `jwtoken.py`, the `verify()` function checks `ldap.is_active()` after validating the JWT signature:
   
   ```python
   if not await ldap.is_active(asf_uid):
       raise base.ASFQuartException("Account is disabled", errorcode=401)
   ```
   
   But since `is_active()` returns `True` when LDAP is unconfigured, a valid JWT for a banned user would be accepted if LDAP credentials are missing.
   
   Additionally, PAT hash validation is skipped when the `atr_th` claim is absent — this is documented as intentional ("not all JWTs come from PATs"), but it means there's a class of JWTs that have no revocation check at all.
   
   ### Discussion Point 5: Should JWT verification require LDAP to be available?
   
   If LDAP is down in production, the current behavior is to accept all JWTs regardless of account status. This could be acceptable (short-lived tokens, 30-minute TTL), but it contradicts the security model where LDAP is authoritative for account status.
   
   ---
   
   ## 6. Proposed Rules for Discussion
   
   Based on the above findings, here are candidate rules for the team to decide on:
   
   1. **Fail-closed by default**: `ldap.is_active()` should return `False` (or raise) when LDAP is unavailable, unless Debug mode is active AND ALLOW_TESTS is enabled. The current `return True` is dangerous.
   
   2. **Consistent LDAP failure behavior**: All auth paths (web, SSH, JWT, PAT) should behave the same way when LDAP is down. Pick one: fail-open or fail-closed.
   
   3. **Scope the test user**: The `"test"` user should have minimal privileges needed for end-to-end testing — member of test committee/project only, not a global admin. Create a separate `TEST_ADMIN` flag if admin testing is needed.
   
   4. **Remove or TTL the session cache file**: The `user_session_cache.json` fallback is an undocumented auth bypass in Debug mode. Either remove it, add a TTL, or clearly mark it in code comments and developer docs.
   
   5. **Audit `_augment_test_membership()`**: Decide whether silently adding "test" committee/project membership to every real user is the right approach, or if this should be database-driven.
   
   6. **Document the mode matrix**: Create a clear, authoritative table (like the one in §1) that lives in the codebase and is tested. When behavior changes based on `ALLOW_TESTS` or `Mode.Debug`, there should be a single place to understand the full picture.
   
   7. **Guard Debug mode more strictly**: Verify that `is_dev_environment()` is sufficient to prevent Debug mode in production-like deployments. Consider requiring an explicit opt-in (e.g., a file on disk) rather than just the absence of a `PRODUCTION` env var.
   
   8. **Rate limiting in test mode**: Rate limiting is entirely disabled when `ALLOW_TESTS` is on. If integration tests need higher limits, consider raising the limits rather than removing them entirely, so tests still exercise the rate-limiting code paths.


-- 
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: dev-unsubscribe@tooling.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tooling.apache.org
For additional commands, e-mail: dev-help@tooling.apache.org


Re: [I] LDAP state in dev/debug/test modes and users (tooling-trusted-releases)

Posted by "dave2wave (via GitHub)" <gi...@apache.org>.
dave2wave commented on issue #944:
URL: https://github.com/apache/tooling-trusted-releases/issues/944#issuecomment-4166130091

   Once the `_global_mode` is set it is `final`.


-- 
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: dev-unsubscribe@tooling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tooling.apache.org
For additional commands, e-mail: dev-help@tooling.apache.org


Re: [I] LDAP state in dev/debug/test modes and users (tooling-trusted-releases)

Posted by "dave2wave (via GitHub)" <gi...@apache.org>.
dave2wave commented on issue #944:
URL: https://github.com/apache/tooling-trusted-releases/issues/944#issuecomment-4166125429

   I think that ALLOW_TESTS should be replaced by an explicit mode. Something like:
   
   ```
   Mode.Production
   Mode.Debug
   Mode.Test
   Mode.Profiling
   ```
   
   Then we replace current use of `ALLOW_TEST` with `Mode.Test`
   


-- 
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: dev-unsubscribe@tooling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tooling.apache.org
For additional commands, e-mail: dev-help@tooling.apache.org


Re: [I] LDAP state in dev/debug/test modes and users (tooling-trusted-releases)

Posted by "dave2wave (via GitHub)" <gi...@apache.org>.
dave2wave closed issue #944: LDAP state in dev/debug/test modes and users
URL: https://github.com/apache/tooling-trusted-releases/issues/944


-- 
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: dev-unsubscribe@tooling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tooling.apache.org
For additional commands, e-mail: dev-help@tooling.apache.org


Re: [I] LDAP state in dev/debug/test modes and users (tooling-trusted-releases)

Posted by "alitheg (via GitHub)" <gi...@apache.org>.
alitheg commented on issue #944:
URL: https://github.com/apache/tooling-trusted-releases/issues/944#issuecomment-4143295147

   In fact, we already do have a `util.` function that tells us if LDAP is configured. Based on our conversation yesterday, it sounds like we should unify some checks into 3/4 distinct modes:
   
   - Production
   - Development
   - Development without LDAP
   - CI
   
   The last two could be the same, a "test" mode perhaps. I also suggested having a function which runs on server startup and if it detects production mode will run some explicit checks like "is ALLOW_TESTS turned off" and "is LDAP configured" and if not it would bail out of the server start.


-- 
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: dev-unsubscribe@tooling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tooling.apache.org
For additional commands, e-mail: dev-help@tooling.apache.org


Re: [I] LDAP state in dev/debug/test modes and users (tooling-trusted-releases)

Posted by "asf-tooling (via GitHub)" <gi...@apache.org>.
asf-tooling commented on issue #944:
URL: https://github.com/apache/tooling-trusted-releases/issues/944#issuecomment-4409947018

   <!-- gofannon-issue-triage-bot v2 -->
   
   **Automated triage** — analyzed at `main@2da7807a`
   
   **Type:** `discussion`  •  **Classification:** `actionable`  •  **Confidence:** `high`
   **Application domain(s):** `authentication_authorization`, `shared_infrastructure`
   
   ### Summary
   This issue tracks LDAP state management inconsistencies across operating modes (Production, Debug, Test). Several items from the prior discussion have already been implemented: @dave2wave's suggestion to replace ALLOW_TESTS with Mode.Test is done (config.py Mode enum, is_test_mode()), @alitheg's suggestion for is_ldap_configured() exists, and production startup validation exists in config.validate(). However, key inconsistencies remain: is_active() still fails open when LDAP is unconfigured, fetch_admin_users/fetch_tooling_users degrade inconsistently, the session cache file has no TTL, SSH fails closed while web fails open, and the test user has unrestricted admin access. @dave2wave's last comment asks what work remains.
   
   ### Where this lives in the code today
   
   #### `atr/ldap.py` — `is_active` (lines 287-300)
   _needs modification_
   Returns True (fail-open) when LDAP credentials are not configured, allowing any UID to be treated as active including banned accounts in non-test environments.
   
   ```python
   async def is_active(asf_uid: str) -> bool:
       import atr.config as config
   
       if config.is_test_mode():
           if asf_uid == "test":
               return True
           if asf_uid == "test-banned":
               return False
       if get_bind_credentials() is None:
           return True
       account = await account_lookup(asf_uid)
       if account is None:
           return False
       return not is_banned(account)
   ```
   
   #### `atr/ldap.py` — `fetch_admin_users` (lines 173-200)
   _needs modification_
   Returns frozenset() (fail-closed) when LDAP unavailable, inconsistent with fetch_tooling_users which returns the 'extra' set.
   
   ```python
   async def fetch_admin_users() -> frozenset[str]:
       import atr.log as log
   
       credentials = get_bind_credentials()
       if credentials is None:
           log.warning("LDAP bind DN or password not configured, returning empty admin set")
           return frozenset()
   
       bind_dn, bind_password = credentials
   
       def _query_ldap() -> frozenset[str]:
           users: set[str] = set()
           with Search(bind_dn, bind_password) as ldap_search:
               for base in (LDAP_ROOT_BASE, LDAP_TOOLING_BASE):
                   try:
                       result = ldap_search.search(ldap_base=base, ldap_scope="BASE")
                       if (not result) or (len(result) != 1):
                           continue
                       for member_dn in result[0].member:
                           parsed = parse_dn(member_dn)
                           uids = parsed.get("uid", [])
                           if uids:
                               users.add(uids[0])
                   except Exception as e:
                       log.warning(f"Failed to query LDAP group {base}: {e}")
           return frozenset(users)
   
       return await asyncio.to_thread(_query_ldap)
   ```
   
   #### `atr/ldap.py` — `fetch_tooling_users` (lines 203-231)
   _needs modification_
   Returns 'extra' users (partially open) when LDAP unavailable, inconsistent with fetch_admin_users which fails closed.
   
   ```python
   async def fetch_tooling_users(extra: set[str]) -> set[str]:
       import atr.log as log
   
       credentials = get_bind_credentials()
       if credentials is None:
           log.warning("LDAP bind DN or password not configured, returning extra tooling users only")
           return extra
   
       bind_dn, bind_password = credentials
   
       def _query_ldap() -> set[str]:
           users: set[str] = set()
           with Search(bind_dn, bind_password) as ldap_search:
               for base in (LDAP_TOOLING_BASE,):
                   try:
                       result = ldap_search.search(ldap_base=base, ldap_scope="BASE")
                       if (not result) or (len(result) != 1):
                           continue
                       for member_dn in result[0].member:
                           parsed = parse_dn(member_dn)
                           uids = parsed.get("uid", [])
                           if uids:
                               users.add(uids[0])
                   except Exception as e:
                       log.warning(f"Failed to query LDAP group {base}: {e}")
           return users
   
       tooling = await asyncio.to_thread(_query_ldap)
       return tooling | extra
   ```
   
   #### `atr/principal.py` — `AuthoriserLDAP.cache_refresh` (lines 277-302)
   _needs modification_
   The session cache file fallback in Debug mode has no TTL, signature, or integrity check. If the file contains stale data, ATR won't detect changes.
   
   ```python
       async def cache_refresh(self, asf_uid: str) -> None:
           if not self.__cache.outdated(asf_uid):
               return
   
           if config.is_test_mode() and (asf_uid == "test"):
               # The test user does not exist in LDAP, so we hardcode their data
               committees = frozenset({"test"})
               projects = frozenset({"test"})
               self.__cache.member_of[asf_uid] = committees
               self.__cache.participant_of[asf_uid] = projects
               self.__cache.last_refreshed[asf_uid] = int(time.time())
               return
   
           if config.get_mode() == config.Mode.Debug:
               session_cache = await util.session_cache_read()
               if asf_uid in session_cache:
                   cached_session = session_cache[asf_uid]
                   committees = frozenset(cached_session.get("pmcs", []))
                   projects = frozenset(cached_session.get("projects", []))
                   committees, projects = _augment_test_membership(committees, projects)
   
                   self.__cache.member_of[asf_uid] = committees
                   self.__cache.participant_of[asf_uid] = projects
                   self.__cache.last_refreshed[asf_uid] = int(time.time())
                   log.info(f"Loaded session data for {asf_uid} from session cache file")
                   return
   ```
   
   #### `atr/user.py` — `is_admin` (lines 50-60)
   _needs modification_
   The test user gets full global admin privileges, not scoped to the test project. This is a privilege escalation risk if test mode is accidentally enabled.
   
   ```python
   def is_admin(user_id: str | None) -> bool:
       if user_id is None:
           return False
       if config.is_test_mode() and (user_id == "test"):
           return True
       # TODO: is_user_session_downgraded only works in a Quart async context
       if util.is_user_session_downgraded():
           return False
       if user_id in _get_additional_admin_users():
           return True
       return user_id in cache.admins_get()
   ```
   
   #### `atr/principal.py` — `_augment_test_membership` (lines 404-411)
   _needs modification_
   Adds test committee/project membership to ALL authenticated users in test mode, not just the test user. Intentional but undocumented.
   
   ```python
   def _augment_test_membership(
       committees: frozenset[str],
       projects: frozenset[str],
   ) -> tuple[frozenset[str], frozenset[str]]:
       if config.is_test_mode():
           committees = committees.union({"test"})
           projects = projects.union({"test"})
       return committees, projects
   ```
   
   #### `atr/config.py` — `Mode` (lines 146-150)
   _currently does this_
   Mode enum already exists as @dave2wave proposed - ALLOW_TESTS has been replaced by Mode.Test.
   
   ```python
   class Mode(enum.Enum):
       Debug = "Debug"
       Test = "Test"
       Production = "Production"
       Profiling = "Profiling"
   ```
   
   #### `atr/config.py` — `is_ldap_configured` (lines 217-219)
   _currently does this_
   Already exists as @alitheg suggested - explicit gate to check LDAP configuration.
   
   ```python
   def is_ldap_configured() -> bool:
       conf = get()
       return bool(conf.LDAP_BIND_DN and conf.LDAP_BIND_PASSWORD)
   ```
   
   #### `atr/config.py` — `validate` (lines 230-242)
   _currently does this_
   Production startup safety checks already exist as @alitheg proposed. LDAP must be configured, no additional admins allowed, dev URLs rejected.
   
   ```python
   def validate() -> None:
       ...
       if (not is_dev_environment()) and (get_mode() == Mode.Debug):
           raise RuntimeError("Debug mode can only be set in development environment")
   
       # Production-specific guards
       if is_production_mode():
           if not (conf.LDAP_BIND_DN and conf.LDAP_BIND_PASSWORD):
               raise RuntimeError("LDAP bind credentials must be configured in production mode")
           if conf.ADMIN_USERS_ADDITIONAL or conf.TOOLING_USERS_ADDITIONAL:
               raise RuntimeError("Cannot manually configure additional users in production")
           if is_dev_environment():
               raise RuntimeError("Production mode cannot use a development APP_HOST")
   ```
   
   #### `atr/config.py` — `get_mode` (lines 183-206)
   _currently does this_
   Mode is set once and cached (effectively final as @dave2wave requested). Mutual exclusion is enforced.
   
   ```python
   def get_mode() -> Mode:
       global _global_mode
   
       profiling = decouple.config("PROFILING", default=False, cast=bool)
       production = decouple.config("PRODUCTION", default=False, cast=bool)
       test = decouple.config("TESTS", default=False, cast=bool)
   
       # Make sure we don't set more than one - which would fall back into whichever is first in the next conditional
       # This prevents accidental production in test mode, for example
       enabled = [name for name, val in [("PROFILING", profiling), ("PRODUCTION", production), ("TESTS", test)] if val]
       if len(enabled) > 1:
           exit(f"Only one mode flag may be set, but got: {', '.join(enabled)}")
   
       if _global_mode is None:
           if profiling:
               _global_mode = Mode.Profiling
           elif production:
               _global_mode = Mode.Production
           elif test:
               _global_mode = Mode.Test
           else:
               _global_mode = Mode.Debug
   
       return _global_mode
   ```
   
   #### `atr/get/test.py` — `test_login` (lines 46-64)
   _currently does this_
   Test login endpoint now gated by config.is_test_mode() rather than ALLOW_TESTS directly. Creates session with no LDAP verification.
   
   ```python
   @get.typed
   async def test_login(_session: web.Public, _test_login: Literal["test/login"]) -> web.WerkzeugResponse:
       """
       URL: /test/login
       """
       # Some test routes work anywhere outside of production
       # but test logins should be Test mode only
       if not config.is_test_mode():
           return quart.abort(404)
   
       await util.write_session(
           sql.UserSession(
               uid="test",
               fullname="Test User",
               committees=["test"],
               projects=["test"],
           )
       )
       return await web.redirect(root.index)
   ```
   
   ### Proposed approach
   Several items from the discussion are already implemented: Mode.Test replaces ALLOW_TESTS conceptually, is_ldap_configured() exists as an explicit gate, _global_mode is effectively final, and production startup validation catches misconfigurations. The remaining work items form a checklist of security improvements:
   
   1. **Make is_active() use is_ldap_configured() as a gate** — in non-test, non-debug modes, if LDAP is not configured, this should either raise or return False (fail-closed), not silently return True. The production validate() check ensures this can't happen in prod, but the defense-in-depth argument says is_active() should not silently succeed.
   
   2. **Unify degradation semantics** — fetch_admin_users() and fetch_tooling_users() should degrade consistently (both fail-closed when LDAP unavailable).
   
   3. **Add TTL to session cache file** — The file-based session cache in AuthoriserLDAP.cache_refresh() should either be removed or given a timestamp/TTL to prevent stale data from persisting indefinitely.
   
   4. **Document the test user's scope** — The test user being a full admin is documented in authorization-security.md but the team should decide whether to scope it.
   
   5. **Reconcile SSH vs web failure modes** — Both should fail the same way (ideally closed) when LDAP is unavailable.
   
   Since @dave2wave asked 'what work remains?' and no response has been given yet, this issue should remain open as a tracking issue for these remaining items. No single patch resolves all points; each is a discrete piece of work that warrants its own PR.
   
   ### Open questions
   - Should is_active() return False (fail-closed) when LDAP is unavailable outside of Debug/Test mode, or should it raise an error?
   - Should the test user's admin privileges be scoped to only the test project, or is full admin required for comprehensive testing?
   - Should the session cache file (util.session_cache_read) be given a TTL, removed entirely, or replaced with a different mechanism?
   - Should fetch_tooling_users() return frozenset() instead of 'extra' when LDAP is unavailable, to match fetch_admin_users() behavior?
   - Are there concrete sub-issues or PRs already filed for the remaining items, or should they be created?
   
   ### Files examined
   - `atr/principal.py`
   - `atr/ldap.py`
   - `atr/user.py`
   - `atr/get/test.py`
   - `atr/docs/authorization-security.md`
   - `tests/unit/test_ldap.py`
   - `atr/config.py`
   - `atr/sessions.py`
   
   ---
   *Draft from a triage agent. A human reviewer should validate before merging any change. The agent did not run tests or verify diffs apply.*


-- 
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: dev-unsubscribe@tooling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tooling.apache.org
For additional commands, e-mail: dev-help@tooling.apache.org


Re: [I] LDAP state in dev/debug/test modes and users (tooling-trusted-releases)

Posted by "alitheg (via GitHub)" <gi...@apache.org>.
alitheg commented on issue #944:
URL: https://github.com/apache/tooling-trusted-releases/issues/944#issuecomment-4133686847

   I think it's potentially worth also having `ldap.is_configured() -> bool` which could be used as an explicit gate around checks elsewhere in the system. We'd be saying "if it's not configured, don't bother checking for active/banned". And that function could also possibly raise if it found unconfigured LDAP in production 


-- 
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: dev-unsubscribe@tooling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tooling.apache.org
For additional commands, e-mail: dev-help@tooling.apache.org


Re: [I] LDAP state in dev/debug/test modes and users (tooling-trusted-releases)

Posted by "dave2wave (via GitHub)" <gi...@apache.org>.
dave2wave commented on issue #944:
URL: https://github.com/apache/tooling-trusted-releases/issues/944#issuecomment-4247424275

   @sbp what work remains?


-- 
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: dev-unsubscribe@tooling.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tooling.apache.org
For additional commands, e-mail: dev-help@tooling.apache.org