splunk / splunk/splunk-sdk-python
`SPLUNK_HOME` absolute-path check in `splunklib.ai.tools` fails on Windows
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 743
- 派生
- 387
- 平均合并
- 42 分钟
- 30 天内合并 PR
- 4
描述
Describe the bug
_splunk_home() in splunklib/ai/tools.py validates that SPLUNK_HOME is an absolute path via splunk_home.startswith("/"). This check is POSIX-only. On Windows, SPLUNK_HOME is a drive-letter path (e.g. C:\Program Files\Splunk), which never starts with / even though it is a valid absolute path. As a result, _splunk_home() — and anything built on it, such as locate_app() — unconditionally raises RuntimeError("SPLUNK_HOME is not absolute") on Windows, regardless of the actual value of SPLUNK_HOME. This makes the splunklib.ai.tools module entirely unusable on Windows.
To Reproduce
- On a Windows host, set a valid absolute
SPLUNK_HOME, e.g.:set SPLUNK_HOME=C:\Program Files\Splunk - Run:
(or callfrom splunklib.ai.tools import locate_app locate_app()_splunk_home()directly, or invoke anything in the SDK that depends on it, such as an app built withsplunklib.ai.tools) - Observe:
even thoughRuntimeError: SPLUNK_HOME is not absoluteSPLUNK_HOMEis a correctly-formed absolute Windows path.
Expected behavior
_splunk_home() should recognize Windows absolute paths (drive-letter paths, UNC paths) as valid — e.g. by using os.path.isabs(splunk_home) instead of splunk_home.startswith("/"). Any SDK functionality depending on SPLUNK_HOME should work identically on Windows and POSIX systems given a correct value.
Logs or Screenshots
RuntimeError: SPLUNK_HOME is not absolute
Raised from:
def _splunk_home() -> str:
splunk_home = os.environ.get("SPLUNK_HOME", "/opt/splunk")
if not splunk_home.startswith("/"):
raise RuntimeError("SPLUNK_HOME is not absolute")
return splunk_home
Splunk (please complete the following information):
- Version: 10.4.2
- OS: Windows Server 2022 (build 20348)
- Deployment: single-instance
SDK (please complete the following information):
- Version: 3.0.0
- Language Runtime Version: Python 3.13.11
- OS: Windows Server 2022 (build 20348)
Additional context
- The default fallback value (
"/opt/splunk"whenSPLUNK_HOMEis unset) is also POSIX-only and would need a Windows-aware equivalent, or the fallback should be removed in favor of requiring an explicit value. - This affects any app that vendors or depends on
splunklib.ai.toolsand is deployed on Windows — the failure is unconditional and unrelated to app configuration, credentials, orSPLUNK_HOME's actual correctness.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 splunklib/ai/tools.py 中的 _splunk_home() 开始,然后跟踪 locate_app() 以及依赖它的其他调用方。验证 Windows 驱动器号路径和 UNC 路径以及 POSIX 路径的绝对路径行为,并确认有效的 Windows SPLUNK_HOME 值不再引发错误,而无效值仍会引发错误。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- backend
- Issue 类型
- 缺陷
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 冷清
- 描述清晰度
- 描述清楚
- 新手友好度
- 74/100