Skip to content

refactor(config): remove legacy unauth REDIS_URL fallbacks in slot/ssh/capacity services (#589 follow-up) #645

Closed

Description

@AndriiPasternak31

Summary

Three backend services keep a legacy unauthenticated redis://redis:6379 fallback in their os.getenv calls — outside the diff of PR #643 but breaking the single-source-of-truth principle that PR establishes (config.py raises if REDIS_URL lacks credentials, but these modules use os.getenv directly and skip that fail-fast guard).

Affected files

src/backend/services/slot_service.py:402
    redis_url = os.getenv("REDIS_URL", "redis://redis:6379")

src/backend/services/ssh_service.py:549
    redis_url = os.getenv("REDIS_URL", "redis://redis:6379")

src/backend/services/capacity_manager.py:162
    url = redis_url or os.getenv("REDIS_URL", "redis://redis:6379")

(ssh_service.py:43 may have a second occurrence — sweep the repo when fixing.)

Why this matters

In production these branches aren't hit because docker-compose always sets REDIS_URL with creds. But:

  1. Test/CI paths that import these modules without first importing src/backend/config.py skip the fail-fast guard — they silently fall back to unauth localhost, then hit NOAUTH at runtime instead of a clear "REDIS_URL must include credentials" message at startup.

  2. A future operator running these services outside the docker stack (debug shell, one-off script) gets a confusing connection error rather than the actionable error SEC: Redis has no requirepass — agent containers have unauthenticated full read/write access to platform task queue (AISEC-C1) #589 establishes.

  3. Single source of truth violated — config.py is the canonical Redis URL gate; os.getenv("REDIS_URL", "...") scattered across services means any new service can introduce a fresh fallback without fail-fast coverage.

Recommended fix

Replace each os.getenv("REDIS_URL", "redis://redis:6379") with an import from config:

from config import REDIS_URL
# ... use REDIS_URL directly

For capacity_manager.py:162 (which accepts an explicit redis_url parameter):

from config import REDIS_URL as _DEFAULT_REDIS_URL
url = redis_url or _DEFAULT_REDIS_URL

After the sweep, grep should return zero matches:

grep -rn 'os\.getenv.*REDIS_URL\|getenv("REDIS_URL"' src/backend/services/
# expected: empty

Acceptance criteria

  • All three services import REDIS_URL from config instead of using os.getenv fallback
  • No remaining redis://redis:6379 literal anywhere under src/backend/services/
  • Existing tests still pass (these are unit-level imports; should be safe)
  • Add a unit test that asserts no os.getenv("REDIS_URL" pattern exists in src/backend/services/ (lint-style guard against regression)

Out of scope

  • src/scheduler/config.py:14 — already uses os.getenv("REDIS_URL", "") correctly with fail-fast
  • src/backend/config.py:32 — same, this is the canonical gate

Related

Activity

  1. added
    priority-p2
    security
    severity-low
    on May 4, 2026
  2. added
    status-in-progress
    on May 7, 2026
  3. self-assigned this
    on May 7, 2026
  4. added
    status-in-dev
    and removed
    status-in-progress
    on May 7, 2026
  5. vybe commented on Jun 1, 2026

    @vybe
    Contributor

    Shipped in v0.6.0 (released via #998).

  6. added
    complexity-low
    theme-security
    and removed
    status-in-dev
    on Jun 1, 2026
  7. added a commit that references this issue on Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

complexity-lowpriority-p2securityseverity-lowtheme-security

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions