← Back to Pull requests

[API] Hash bcrypt passwords without passlib and drop the bcrypt pin #11249

Open
unknown opened this pull request with 359 lines diff across 4 files
View on GitHub
unknown unknown commented on Oct 31, 2026 15:51 UTC
Author

<!-- Describe the changes in this PR -->
Fixes #11203.

bcrypt was pinned to 4.0.1 in #7390 because passlib's bcrypt backend breaks on bcrypt 5.0: its startup self-test hashes a secret longer than 72 bytes, which bcrypt 5 now rejects with ValueError. On 4.1 to 4.3 it works but logs a traceback, since it reads the removed bcrypt.__about__. conda-forge has no 4.0.1 builds for Python 3.13+, so current skypilot can't be installed there.

This PR:

  • hashes and verifies $2a$/$2b$/$2y$ hashes with the bcrypt package directly (legacy $2$ hashes are mapped to $2a$ the way passlib did), and keeps passlib only for the htpasswd schemes (apr_md5_crypt, ldap_sha1, ...). Those are still needed: the deploy docs build SKYPILOT_INITIAL_BASIC_AUTH with htpasswd -nb, which gives an apr1 hash.

  • truncates the password to 72 bytes before hashing or checking, which is what bcrypt < 5.0 did silently, so users created with long passwords can still log in.

  • relaxes the pin to bcrypt>=4.0.1 and switches the dashboard e2e script off passlib's bcrypt.
  • crypt_ctx keeps the same hash/verify/identify methods, so call sites are unchanged. Once this is released, the pin in the conda-forge feedstock recipe can be dropped too.

    <!-- Describe the tests ran -->
    <!-- Unit tests (tests/test_*.py) are part of GitHub CI; below are tests that launch on the cloud. -->

    Tested (run the relevant ones):

  • Code formatting: install pre-commit (auto-check on commit) or bash format.sh

  • Any manual or new tests for this PR (please specify below)

  • All smoke tests: /smoke-test (CI) or pytest tests/test_smoke.py (local)

  • Relevant individual tests: /smoke-test -k test_name (CI) or pytest tests/test_smoke.py::test_name (local)

  • Backward compatibility: /quicktest-core (CI) or pytest tests/smoke_tests/test_backward_compat.py (local)
  • <!-- CI commands (/-prefixed) can only be triggered by repo members -->

  • New TestCryptContext in tests/unit_tests/test_sky/server/test_common_auth.py covers a bcrypt round trip, a long-password hash and a $2$ hash made with passlib + bcrypt 4.0.1, and real htpasswd -nbB / -nb / -nbs output. On master with bcrypt 5.0.0 the three bcrypt cases fail with the ValueError above.

  • pytest tests/unit_tests/test_sky/users tests/unit_tests/test_sky/server/{test_common_auth,test_server,test_common,test_metrics,test_auth_db_deadline}.py: 671 passed with bcrypt 5.0.0 and 4.0.1 (670 on 4.3.0 before the $2$ commit) (Python 3.11). On master with bcrypt 5.0.0, 11 tests in test_sky/users/test_server.py fail.

  • Ran BasicAuthMiddleware against a real user DB with bcrypt 5.0.0: the apr1 admin user and a bcrypt user with an 80-byte password both get in, while wrong passwords and the 71-byte prefix get 401.

  • yapf, isort, pylint and mypy $(cat tests/mypy_files.txt) are clean.
  • Diff: 359 lines (+269 / -90) across 4 files Reviewer: ska2704 Review duration: 43171m
    All Vouch review confidence checks passed
    Residual risk 0.23 = Change Risk (0.43) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 359 lines diff across 4 files
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.352
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #11249"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 42.6% (MEDIUM) · Higher = larger blast radius
    42.6%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 22.7% · Safe to merge
    22.7%