docs: record ecosystem issue split and local credential guard
ci/woodpecker/pr/eco Pipeline was successful
ci/woodpecker/pr/eco Pipeline was successful
Map the cross-repository sub-issues created for marqdo#55 (AI-readable document architecture) and marqdo#56 (ecosystem build/release/feedback) in the repository task navigation, and document the local-only credential policy: credentials live only in the git-ignored root files, submodules never hold them, and CI uses protected Secrets (marqdo#56 §8). Add scripts/check-dev-secrets.py, which scans the main repository and every initialized submodule (index, worktree, untracked non-ignored files, git config, .gitmodules) for the local credential values and fails without printing them. No credential value is committed.
This commit is contained in:
1 parent
af7e3c6926
commit
5bf51f455a
5 files changed
+347
No files matched your search
@@ -11,3 +11,4 @@
|
||||
# Local audit/experiment scratch (issue #25)
|
||||
/.issue-work/
|
||||
/.app-verify/
|
||||
/.secrets/
|
||||
@@ -0,0 +1,86 @@
|
||||
# 本地开发凭据(主仓库唯一位置)
|
||||
|
||||
本文件说明 Marqdo 本地开发所需的凭据放在哪里、如何加载、如何避免进入任何仓库。**本文件不包含任何凭据值。**
|
||||
|
||||
## 1. 唯一位置
|
||||
|
||||
本地凭据只放在主仓库根目录的 git 忽略文件中:
|
||||
|
||||
| 文件 | 用途 | 忽略规则 |
|
||||
| --- | --- | --- |
|
||||
| `.env.local` | 当前工作区的本地开发凭据(推荐,存在时使用) | 根 `.gitignore` 的 `.env.*` |
|
||||
| `.secrets/dev.env` | 与子仓库约定一致的兼容位置(可选,二选一即可) | 根 `.gitignore` 的 `/.secrets/` |
|
||||
|
||||
约束:
|
||||
|
||||
- **只有主仓库持有本地开发凭据**;子仓库(git submodule)不保存、不复制、不回显任何凭据。
|
||||
- 凭据文件权限应为 `600`。
|
||||
- 任何情况下都不得把凭据提交到 Git、写入 CI YAML、issue、PR、日志、测试报告、证据文件或构建产物。
|
||||
- CI 使用平台受保护 Secrets,不使用本地凭据文件;规则见 [marqdo#56](https://git.cflmy.cn/cflmy/marqdo/issues/56) §8.2/§8.4。
|
||||
|
||||
## 2. 变量清单
|
||||
|
||||
`.env.local` 中的变量名(值由维护者提供,不在此记录):
|
||||
|
||||
| 变量 | 用途 |
|
||||
| --- | --- |
|
||||
| `MARQDO_GIT_REMOTE` / `MARQDO_GIT_USERNAME` / `MARQDO_GIT_TOKEN` | 自建 Gitea HTTPS 推送与 API |
|
||||
| `MARQDO_WOODPECKER_URL` / `MARQDO_WOODPECKER_TOKEN` | 自建 Woodpecker CI API |
|
||||
| `MARQDO_CI_SECRET` | 可选 CI 校验密钥 |
|
||||
| `MARQDO_LLM_BASE_URL` | 模型服务 OpenAI-compatible 根地址(`https://llm.cflmy.cn/v1`) |
|
||||
| `MARQDO_LLM_API_KEY` | 模型服务开发密钥(唯一字面值来源) |
|
||||
| `CFLMY_API_KEY` | `MARQDO_LLM_API_KEY` 的别名;`marqdo-ext-ai` 的 `scripts/real_model_smoke.sh` 默认读取该变量名 |
|
||||
| `MARQDO_AI_CREDENTIAL_ENV` | 供 AI 扩展真实模型 smoke 使用的凭据变量名(`CFLMY_API_KEY`) |
|
||||
| `MARQDO_AI_MODEL_ENDPOINT` | 模型服务 `host:port`(`llm.cflmy.cn:443`) |
|
||||
| `MARQDO_AI_MODEL` | 默认模型 id(`deepseek-flash`) |
|
||||
|
||||
模型服务可用模型以 `GET $MARQDO_LLM_BASE_URL/models` 实时结果为准,不要在文档、测试或工单里写死“最新模型表”。
|
||||
|
||||
## 3. 加载方式
|
||||
|
||||
```sh
|
||||
set -a; . ./.env.local; set +a
|
||||
```
|
||||
|
||||
只在该 shell 会话内生效;不要 `export` 到全局 shell 配置,也不要把加载命令写进仓库脚本的默认路径。
|
||||
|
||||
## 4. 真实模型开发验证
|
||||
|
||||
`marqdo-ext-ai` 的真实模型 smoke(需要真实 CLI 与 Bundle 制品,产物由根候选提供):
|
||||
|
||||
```sh
|
||||
set -a; . ./.env.local; set +a
|
||||
MARQDO_BIN=<verified marqdo> MARQDO_STDLIB_DIR=<installed Bundle> \
|
||||
sh extensions/ai/scripts/real_model_smoke.sh
|
||||
```
|
||||
|
||||
脚本只按 `MARQDO_AI_CREDENTIAL_ENV` 名称读取环境变量,不打印、不落盘凭据;缺少凭据时退出 2 并保持 `UNVERIFIED`。
|
||||
|
||||
2026-11-30 的网关可用性探测(**不是**扩展验收):对 `https://llm.cflmy.cn/v1/chat/completions` 使用 `deepseek-flash` 的真实请求返回 HTTP 200,响应 `model=deepseek-flash`,`finish_reason=stop`。该结果只证明开发凭据与网关可用;AI 扩展的真实验收仍必须按其工单与 [marqdo#56](https://git.cflmy.cn/cflmy/marqdo/issues/56) §8 在真实 CLI/Bundle 组合上执行,结果状态用 `real-api-verified` / `real-api-failed` / `not-run` / `credential-unavailable` / `provider-unavailable` 如实记录。
|
||||
|
||||
## 5. 防泄漏检查
|
||||
|
||||
提交或推送前在根目录运行:
|
||||
|
||||
```sh
|
||||
python3 scripts/check-dev-secrets.py # 精确值扫描(默认,必须 PASS)
|
||||
python3 scripts/check-dev-secrets.py --generic # 额外提示 key 形状文本(建议)
|
||||
```
|
||||
|
||||
检查内容:
|
||||
|
||||
1. 根 `.env.local`、`.secrets/*.env` 等本地凭据文件必须被所在仓库 git 忽略;
|
||||
2. 从这些文件读取的凭据值不得出现在主仓库或任何已初始化子仓库的 index、tracked worktree、未忽略的 untracked 文件、`.git/config` 或 `.gitmodules` 中;
|
||||
3. 凭据值不打印;命中时只报告仓库与文件路径,退出码 1。
|
||||
|
||||
脚本本地运行,不依赖网络,不把凭据写进参数或临时文件之外的任何位置(临时文件在本次进程内删除)。CI 没有本地凭据文件时该检查为空扫描,因此 CI 的密钥防护靠平台 Secrets 与人工复核,不能把本地检查当成 CI 替代。
|
||||
|
||||
## 6. 子仓库要求
|
||||
|
||||
- 子仓库不得新增 `.env`/`.secrets` 依赖;子仓库 CI 不持有真实模型密钥、发布私钥或主仓库令牌。
|
||||
- 子仓库若确实需要外部服务测试,只接收显式传入的 `--allow-env` 变量名或 CI Secrets,并在缺少凭据时如实记 `credential-unavailable` / `UNVERIFIED`。
|
||||
- 发现任何子仓库出现凭据值:立即轮换该凭据,清除记录,并在该子仓库与主仓库记录事件。
|
||||
|
||||
## 7. 轮换
|
||||
|
||||
模型服务与 Git/CI 令牌均由维护者控制。若凭据可能已进入某个远端、日志或制品:按 [marqdo#56](https://git.cflmy.cn/cflmy/marqdo/issues/56) §8 的纪律停止使用、轮换、重新登记证据;不得以删除文件的方式假装未泄漏。
|
||||
@@ -106,6 +106,8 @@ bash scripts/integration.sh # 生态候选:真实 CLI 制品 +
|
||||
|
||||
需要 Linux x86_64/glibc ≥ 2.39、Python 3.11+、Git、Rust、C 编译器和 curl;`integration.sh` 另需 jsonschema 与冻结 CLI 归档。详细命令与组件验收入口见各仓库 `README.md` 与 [各仓库任务](REPOSITORY-TASKS.md)。
|
||||
|
||||
本地开发凭据(Git/CI/模型服务)只放在主仓库根目录的 git 忽略文件,子仓库不持有;加载方式、变量清单、真实模型 smoke 与防泄漏检查见 [本地开发凭据](DEVELOPMENT-CREDENTIALS.md)。提交或推送前运行 `python3 scripts/check-dev-secrets.py`。
|
||||
|
||||
## 迁移台账
|
||||
|
||||
标准库与扩展的现状、历史归属和切换顺序以 [迁移台账](MIGRATION.md) 为准。当前 CLI 内置标准库仍是基础发行的现行权威;`marqdo-stdlib` 聚合与九个功能仓库的迁移完成前,不得声称 Stdlib 拆分完成,也不得先删旧实现造成产品回归。
|
||||
@@ -4,6 +4,15 @@
|
||||
|
||||
生态治理采用“根 → 领域聚合 → 功能组件”最多两级 Gitlink:功能仓库实现与修复、领域聚合仓库维护合同与组合验收、主仓库固定 gitlink、治理与发行。`planned` 组件可以挂载真实开发提交,实际入口随验收登记。当前 Web 领域为 active(聚合仓 `marqdo-ext-web`,子组件 `marqdo-web-design`/`marqdo-web-preview` 在其 catalog 激活并登记真实入口;`web-components` 仍 planned)。先推进 CLI 外部 Bundle、九个标准库,以及 HTTP、Regex、Archive 的迁出;这些改动在同一候选组合中验证后切换基础发行。官网和 VS Code 可独立推进。[迁移台账](MIGRATION.md) · [开发流程](DEVELOPMENT.md)
|
||||
|
||||
## 全生态架构工单(2026-11-30)
|
||||
|
||||
两个 P0 架构工单在推进,跨仓子工单已按唯一责任仓库拆分(状态以 Gitea issue 为准,本节只做导航):
|
||||
|
||||
- [marqdo#55](https://git.cflmy.cn/cflmy/marqdo/issues/55) AI 可读文档架构:cli [#25](https://git.cflmy.cn/cflmy/marqdo-cli/issues/25)、lint [#13](https://git.cflmy.cn/cflmy/marqdo-lint/issues/13)、knowledge [#14](https://git.cflmy.cn/cflmy/marqdo-knowledge/issues/14)、ext-ai [#3](https://git.cflmy.cn/cflmy/marqdo-ext-ai/issues/3)、app-harness [#15](https://git.cflmy.cn/cflmy/marqdo-app-harness/issues/15);View 阅读/审计展示沿用 [view#16](https://git.cflmy.cn/cflmy/marqdo-view/issues/16)/[#17](https://git.cflmy.cn/cflmy/marqdo-view/issues/17)/[#18](https://git.cflmy.cn/cflmy/marqdo-view/issues/18)。
|
||||
- [marqdo#56](https://git.cflmy.cn/cflmy/marqdo/issues/56) 多平台构建、发布、验收与用户反馈:cli [#26](https://git.cflmy.cn/cflmy/marqdo-cli/issues/26)、view [#19](https://git.cflmy.cn/cflmy/marqdo-view/issues/19)、lint [#14](https://git.cflmy.cn/cflmy/marqdo-lint/issues/14)、prove [#9](https://git.cflmy.cn/cflmy/marqdo-prove/issues/9)、knowledge [#13](https://git.cflmy.cn/cflmy/marqdo-knowledge/issues/13)、ext-ai [#4](https://git.cflmy.cn/cflmy/marqdo-ext-ai/issues/4)、app-harness [#16](https://git.cflmy.cn/cflmy/marqdo-app-harness/issues/16)、主仓库 [#57](https://git.cflmy.cn/cflmy/marqdo/issues/57);MQDH 发行本体见 [app-harness#2](https://git.cflmy.cn/cflmy/marqdo-app-harness/issues/2)。
|
||||
|
||||
标准库/扩展库的逐仓入口与平台兼容工单,在入口模板(cli#25)与 Lint 规则(lint#13)冻结后按仓建立;planned 仓不发空工单。本地开发凭据只在主仓库根目录的 git 忽略文件,子仓库不持有,见 [本地开发凭据](DEVELOPMENT-CREDENTIALS.md)。
|
||||
|
||||
## 集成和语言
|
||||
|
||||
| 仓库 | 要完成的任务 |
|
||||
|
||||
Executable
+249
@@ -0,0 +1,249 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Local credential guard for the Marqdo workspace.
|
||||
|
||||
The only place for local development credentials is the root repository's
|
||||
git-ignored credential files (``.env.local`` or ``.secrets/*.env``). This
|
||||
script proves two properties before a commit/push:
|
||||
|
||||
1. every credential file that exists in the workspace is ignored by git;
|
||||
2. no credential value read from those files appears in the main repository or
|
||||
in any initialized submodule (git index, tracked worktree files, untracked
|
||||
files that are not ignored, git config or ``.gitmodules``).
|
||||
|
||||
It never prints a credential value. It is local-only: CI has no credential
|
||||
file, so CI must keep using platform Secrets instead (see
|
||||
docs/DEVELOPMENT-CREDENTIALS.md and marqdo#56 §8).
|
||||
|
||||
Usage:
|
||||
python3 scripts/check-dev-secrets.py # exact-value scan (default)
|
||||
python3 scripts/check-dev-secrets.py --generic # also warn about key-shaped text
|
||||
python3 scripts/check-dev-secrets.py --strict # make generic warnings failures
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
# Credential files that are allowed to exist, but must be ignored by git.
|
||||
CREDENTIAL_FILES = (
|
||||
".env.local",
|
||||
".env.local.sh",
|
||||
".secrets/dev.env",
|
||||
".secrets/git.env",
|
||||
)
|
||||
|
||||
# Credential variable names inside those files.
|
||||
SECRET_NAME_RE = re.compile(
|
||||
r"(?:^|_)(?:API_?KEY|KEY|TOKEN|SECRET|PASSWORD|CREDENTIAL)(?:_|$)", re.IGNORECASE
|
||||
)
|
||||
|
||||
# Shape-only heuristic used by --generic. Deliberately narrow to avoid noise.
|
||||
GENERIC_PATTERNS = (
|
||||
r"sk-[A-Za-z0-9_]{24,}",
|
||||
r"ghp_[A-Za-z0-9]{30,}",
|
||||
r"-----BEGIN [A-Z ]*PRIVATE KEY-----",
|
||||
)
|
||||
|
||||
# Documented fixtures that intentionally contain fake key-shaped strings.
|
||||
GENERIC_ALLOWLIST = (
|
||||
"packages/client/ui-secret-mask/tests/secret-rule.client.spec.ts",
|
||||
"packages/credentials/credentials-local/tests/local.spec.ts",
|
||||
"apps/web/tests/rich-text-quotes.e2e.ts",
|
||||
"packages/session/message-quotes/tests/quote-user-text.client.spec.tsx",
|
||||
)
|
||||
|
||||
MIN_VALUE_LEN = 16
|
||||
|
||||
|
||||
def git(repo: Path, *args: str) -> subprocess.CompletedProcess[str]:
|
||||
return subprocess.run(
|
||||
["git", "-C", str(repo), *args],
|
||||
check=False,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
|
||||
|
||||
def display(repo: Path) -> str:
|
||||
try:
|
||||
rel = repo.relative_to(ROOT)
|
||||
return str(rel) if rel != Path(".") else "(main repo)"
|
||||
except ValueError:
|
||||
return str(repo)
|
||||
|
||||
|
||||
def workspace_repos() -> list[Path]:
|
||||
repos = [ROOT]
|
||||
result = git(ROOT, "config", "--file", ".gitmodules", "--get-regexp", r"^submodule\..*\.path$")
|
||||
if result.returncode == 0:
|
||||
for line in result.stdout.splitlines():
|
||||
_, _, path = line.partition(" ")
|
||||
candidate = ROOT / path.strip()
|
||||
if candidate.exists() and (candidate / ".git").exists():
|
||||
repos.append(candidate)
|
||||
return repos
|
||||
|
||||
|
||||
def read_credentials() -> dict[str, str]:
|
||||
"""Return {variable name: literal value} for local credential files."""
|
||||
values: dict[str, str] = {}
|
||||
for rel in CREDENTIAL_FILES:
|
||||
path = ROOT / rel
|
||||
if not path.is_file():
|
||||
continue
|
||||
for raw in path.read_text(encoding="utf-8", errors="replace").splitlines():
|
||||
line = raw.strip()
|
||||
if not line or line.startswith("#") or "=" not in line:
|
||||
continue
|
||||
name, _, value = line.partition("=")
|
||||
name = name.strip()
|
||||
if name.startswith("export "):
|
||||
name = name[len("export ") :].strip()
|
||||
value = value.strip()
|
||||
if len(value) >= 2 and value[0] == value[-1] and value[0] in "\"'":
|
||||
value = value[1:-1]
|
||||
if not SECRET_NAME_RE.search(name):
|
||||
continue
|
||||
# ``CFLMY_API_KEY=$MARQDO_LLM_API_KEY`` is an alias, not a literal.
|
||||
if value.startswith("$") or len(value) < MIN_VALUE_LEN:
|
||||
continue
|
||||
values[name] = value
|
||||
return values
|
||||
|
||||
|
||||
def check_ignored(repo: Path) -> list[str]:
|
||||
problems: list[str] = []
|
||||
for rel in CREDENTIAL_FILES:
|
||||
path = repo / rel
|
||||
if not path.is_file():
|
||||
continue
|
||||
ignored = git(repo, "check-ignore", "-q", "--", rel)
|
||||
if ignored.returncode != 0:
|
||||
problems.append(f"{display(repo)}: credential file {rel} exists but is NOT ignored")
|
||||
return problems
|
||||
|
||||
|
||||
def grep_patterns(repo: Path, patterns_file: Path) -> tuple[int, set[str]]:
|
||||
"""Return (returncode, matching files) for a fixed-string multi-pattern grep.
|
||||
|
||||
The worktree pass includes untracked, non-ignored files; the index pass
|
||||
covers staged content. ``--untracked`` and ``--cached`` cannot be combined.
|
||||
"""
|
||||
found: set[str] = set()
|
||||
passes = (("--untracked",), ("--cached",))
|
||||
for extra in passes:
|
||||
result = git(repo, "grep", "-l", "-F", "-f", str(patterns_file), *extra)
|
||||
if result.returncode not in (0, 1):
|
||||
return result.returncode, found
|
||||
for line in result.stdout.splitlines():
|
||||
found.add(line)
|
||||
return 0, found
|
||||
|
||||
|
||||
def scan_repo(repo: Path, values: list[str], generic: bool) -> tuple[list[str], list[str]]:
|
||||
leaks: list[str] = []
|
||||
warnings: list[str] = []
|
||||
|
||||
# git config may embed credentials in remote URLs or extraheaders.
|
||||
for git_dir_rel in (".git",):
|
||||
marker = repo / git_dir_rel
|
||||
config = marker / "config" if marker.is_dir() else None
|
||||
if config is not None and config.is_file():
|
||||
text = config.read_text(encoding="utf-8", errors="replace")
|
||||
for value in values:
|
||||
if value in text:
|
||||
leaks.append(f"{display(repo)}: credential value in {git_dir_rel}/config")
|
||||
|
||||
if not values:
|
||||
return leaks, warnings
|
||||
|
||||
with tempfile.NamedTemporaryFile("w", encoding="utf-8", delete=True, prefix="mq-secret-") as handle:
|
||||
handle.write("\n".join(values) + "\n")
|
||||
handle.flush()
|
||||
patterns = Path(handle.name)
|
||||
code, hits = grep_patterns(repo, patterns)
|
||||
if code != 0:
|
||||
warnings.append(f"{display(repo)}: git grep failed (exit {code}); result UNVERIFIED")
|
||||
else:
|
||||
for hit in sorted(hits):
|
||||
leaks.append(f"{display(repo)}: credential value in {hit}")
|
||||
|
||||
if generic:
|
||||
for pattern in GENERIC_PATTERNS:
|
||||
result = git(repo, "grep", "-l", "-E", "-e", pattern)
|
||||
if result.returncode not in (0, 1):
|
||||
warnings.append(f"{display(repo)}: generic scan failed (exit {result.returncode})")
|
||||
continue
|
||||
for hit in result.stdout.splitlines():
|
||||
if any(hit.endswith(suffix) or suffix in hit for suffix in GENERIC_ALLOWLIST):
|
||||
continue
|
||||
warnings.append(f"{display(repo)}: key-shaped text in {hit}")
|
||||
|
||||
return leaks, warnings
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--generic", action="store_true", help="warn about key-shaped text")
|
||||
parser.add_argument("--strict", action="store_true", help="treat generic warnings as failures")
|
||||
parser.add_argument("--quiet", action="store_true")
|
||||
args = parser.parse_args()
|
||||
|
||||
credentials = read_credentials()
|
||||
repos = workspace_repos()
|
||||
problems: list[str] = []
|
||||
warnings: list[str] = []
|
||||
|
||||
for repo in repos:
|
||||
problems.extend(check_ignored(repo))
|
||||
|
||||
if not credentials:
|
||||
print("[WARN] no local credential file found; exact-value scan is vacuous", file=sys.stderr)
|
||||
|
||||
values = list(credentials.values())
|
||||
for repo in repos:
|
||||
leaks, repo_warnings = scan_repo(repo, values, args.generic)
|
||||
problems.extend(leaks)
|
||||
warnings.extend(repo_warnings)
|
||||
|
||||
# A credential value must never appear in a tracked .gitmodules either.
|
||||
gitmodules = ROOT / ".gitmodules"
|
||||
if gitmodules.is_file():
|
||||
text = gitmodules.read_text(encoding="utf-8", errors="replace")
|
||||
for value in values:
|
||||
if value in text:
|
||||
problems.append("(main repo): credential value in .gitmodules")
|
||||
|
||||
if problems:
|
||||
print(f"[FAIL] credential guard found {len(problems)} problem(s):", file=sys.stderr)
|
||||
for problem in problems:
|
||||
print(f" - {problem}", file=sys.stderr)
|
||||
print("Credential values are not printed. Rotate the credential if it reached a remote.",
|
||||
file=sys.stderr)
|
||||
return 1
|
||||
|
||||
for warning in warnings:
|
||||
print(f"[WARN] {warning}", file=sys.stderr)
|
||||
if warnings and args.strict:
|
||||
print("[FAIL] --strict: generic warnings are failures", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
if not args.quiet:
|
||||
names = ", ".join(sorted(credentials)) or "none"
|
||||
print(
|
||||
f"[PASS] {len(repos)} git repos scanned for {len(values)} credential value(s); "
|
||||
f"no leak in index, worktree, config or .gitmodules; local credential files ignored."
|
||||
)
|
||||
print(f" credential variables considered: {names}")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in new issue
Block a user