Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Extensions ignore --use-context and --config-file and get the current context's credentials

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

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

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

调研方向

Start in the extension dispatch path in src/cli.ts (around lines 341-354), where loadCfg() is called without the parsed --use-context, --config-file or --command-profile values, then follow buildContextEnv in src/extension/context.ts. Compare with the early config sniffing at src/cli.ts:150-206. Done when the reproduction commands print URL=http://b.example:9200 ARGS=x for both flag positions, and tests cover global flags before and after the extension name.

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

描述

Summary

Extensions always receive the env for the config file's current_context, ignoring --use-context and --config-file. The extension dispatch path in src/cli.ts (lines ~341-354) calls loadCfg() with no options, so buildContextEnv (src/extension/context.ts) builds ELASTIC_ES_URL/ELASTIC_ES_API_KEY/etc. from the default context. The early config load at src/cli.ts:150-206 doesn't help here: it sniffs --use-context/--config-file/--command-profile, but extension dispatch never threads those values into loadCfg().

A related symptom: dispatch forwards process.argv.slice(3), so when a global flag comes before the extension name, the flag, its value, and the extension name all get passed to the extension as positional args.

Reproduction

Built dist/cli.js, using a fake HOME so nothing touches the real ~/.elastic:

R=/tmp/a22; mkdir -p $R/home/.elastic $R/ext
printf '#!/bin/sh\necho "URL=$ELASTIC_ES_URL ARGS=$*"\n' > $R/ext/run; chmod +x $R/ext/run
echo "[{\"name\":\"dumpenv\",\"source\":\"local:$R/ext\",\"path\":\"$R/ext\",\"entrypoint\":\"$R/ext/run\"}]" > $R/home/.elastic/extensions.json
cat > $R/cfg.yml <<'Y'
current_context: a
contexts:
  a: { elasticsearch: { url: "http://a.example:9200", auth: { api_key: "AAA" } } }
  b: { elasticsearch: { url: "http://b.example:9200", auth: { api_key: "BBB" } } }
Y
export HOME=$R/home ELASTIC_CLI_CONFIG_FILE=$R/cfg.yml
node dist/cli.js --use-context b dumpenv x
node dist/cli.js dumpenv --use-context b x
unset ELASTIC_CLI_CONFIG_FILE; node dist/cli.js --config-file $R/cfg.yml dumpenv x

Actual:

URL=http://a.example:9200 ARGS=b dumpenv x
URL=http://a.example:9200 ARGS=--use-context b x
URL= ARGS=/tmp/a22/cfg.yml dumpenv x

Expected: URL=http://b.example:9200 ARGS=x for the first two commands. The third should use cfg.yml and output ARGS=x.

Notes

This is a security concern as well as a correctness one. A user who runs --use-context staging to keep a tool away from prod still hands the extension the prod credentials. The root banner check (earlyConfig.value.banner) isn't part of this bug, because earlyConfig is loaded with the sniffed overrides. Open PR #718 (#700) doesn't change the extension dispatch path.

Acceptance criteria

  • Extension dispatch passes the parsed --use-context, --config-file and --command-profile values to loadConfig, and the extension env reflects the chosen context.
  • Global flags placed before the extension name are not forwarded to the extension as args.
  • Tests cover both flag positions.

Related

#512, #576, #700, #718


authored by Pi Coding Agent (Claude Opus 5.5)

主要语言
TypeScript
星标
47
派生
27
平均合并
2 天 6 小时
30 天内合并 PR
52

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

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

elastic/cli 的其他 Issue

查看 elastic/cli 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

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