[BUG] The eval handshake falls back to $HOME when the account has no passwd entry

Aperta
#9,764 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@Kiko0301 ci sta già lavorando.

Dal 25/11/2026.

  • #9768 di @Kiko0301 — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
50/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
cli, security

Direzione di ricerca

The fallback is in _account_home() in the crewai_core eval_handshake module, and awaiting_dir() and run_awaited_by_evaluation() depend on it. The CLI copy is _awaiting_dir in crewai_cli.crew_run_tui. Run the reproduction script from the issue with the pwd lookup patched to raise KeyError, and confirm that the directory resolves through $HOME. Done means both helpers raise OSError when the account database has no entry, with no $HOME fallback, and the existing call sites treat that as no evaluation waiting.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Description

crewai_core.eval_handshake decides whether a run may upload its trace without asking, by looking for a token file in this user's crewAI data directory. Its module docstring promises that a project's .env cannot move that directory:

Nor can it move the directory: it is found from this account's home in the account database, never from HOME or XDG_DATA_HOME, which a .env can set.

But _account_home does not hold that promise when the account database has no entry for the process's uid:

def _account_home() -> Path:
    """This account's home from the account database, never `$HOME`."""
    if os.name == "posix":
        with contextlib.suppress(ImportError, KeyError, OSError):
            import pwd

            return Path(pwd.getpwuid(os.getuid()).pw_dir)
    return Path.home()

Path.home() is os.path.expanduser("~"), which reads $HOME on POSIX. Running an arbitrary uid that has no passwd entry is standard practice in containers (OpenShift, docker run --user 1001), and there pwd.getpwuid(...) raises KeyError, is suppressed, and _account_home() returns $HOME - exactly the variable a project's .env can set.

The CLI copy of the same logic, crewai_cli.crew_run_tui._awaiting_dir, has the same fallback (except (ImportError, KeyError, OSError): home = Path.home()).

Consequence: in such a container, a project whose .env carries HOME=<repo> plus CREWAI_EVAL_AWAITING_RUN=<32 hex>, with a checked-in file <repo>/.local/share/crewai/eval-awaiting/<32 hex>, makes run_awaited_by_evaluation() true for an ordinary crewai run. That flips should_enable_tracing to True before any consent check, so the run's trace is uploaded although nobody ran crewai eval and nobody approved tracing - the bypass the docstring says is impossible.

Steps to Reproduce

The relevant path can be exercised without a real container by simulating the three conditions (uid missing from the account database, POSIX branch, $HOME planted):

import os
import sys
import types
from pathlib import Path

from crewai_core import eval_handshake

fake_pwd = types.ModuleType("pwd")
fake_pwd.getpwuid = lambda uid: (_ for _ in ()).throw(KeyError(uid))
sys.modules["pwd"] = fake_pwd
eval_handshake.os.name = "posix"
eval_handshake.os.getuid = lambda: 4242
Path.home = classmethod(lambda cls: Path("<repo>"))  # what $HOME would resolve to

os.environ["CREWAI_EVAL_AWAITING_RUN"] = "a" * 32
assert eval_handshake.awaiting_dir() == Path("<repo>/.local/share/crewai/eval-awaiting")
assert eval_handshake.run_awaited_by_evaluation() is True   # with the planted file present

On a real POSIX container where pwd.getpwuid(os.getuid()) raises KeyError, HOME is read from the project's .env the same way, with no patching at all.

Expected Behavior

When the account database cannot name this account's home, the handshake should fail closed - report no trusted folder (for example raise OSError, which both call sites already handle as "no evaluation is waiting") instead of falling back to $HOME. The CLI's copy of _awaiting_dir should do the same, so crewai eval also never writes its token under a folder a .env chose.

AI assistance

I used an AI coding agent to investigate, reproduce, and prepare this report, and reviewed its results. Per CONTRIBUTING.md, please apply the llm-generated label; external contributors cannot add it with my current permissions.

Lingua principale
Python
Stelle
61.2k
Fork
9.2k
Merge medio
1g 14h
PR unite (30g)
180

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di crewAIInc/crewAI

Tutte le issue di crewAIInc/crewAI

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.