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

Abierto
#9,764 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@Kiko0301 ya está trabajando en esto.

Desde el 25/11/2026.

  • #9768 de @Kiko0301 — abierto

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
50/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python
Área
cli, security

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Python
Estrellas
61.2k
Forks
9.2k
Merge medio
1 d 14 h
PR fusionados (30 d)
180

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de crewAIInc/crewAI

Todos los issues de crewAIInc/crewAI

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.