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

未关闭
#9,764 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@Kiko0301 已经在做这个了。

开始于 2026年11月25日。

  • #9768 来自 @Kiko0301 —— 未关闭

评估

难度
3/5
预计耗时
1-2 天
新手友好度
50/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
cli, security

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Python
星标
61.2k
派生
9.2k
平均合并
1 天 14 小时
30 天内合并 PR
180

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

crewAIInc/crewAI 的其他 Issue

查看 crewAIInc/crewAI 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。