Levaj2000/AI-Identity

GitHub: Levaj2000/AI-Identity

为 AI Agent 提供加密身份认证、策略执行与基于 OCSF 标准的防篡改审计日志,支持离线独立验证取证记录完整性。

Stars: 1 | Forks: 0

# AI Identity [![CI](https://static.pigsec.cn/wp-content/uploads/repos/cas/ad/ad5834178f7599af9fdda11629d49cae07f2997beec49821b2920eff5bfd50e7.svg)](https://github.com/Levaj2000/AI-Identity/actions/workflows/ci.yml) [![PyPI - langchain-ai-identity](https://img.shields.io/pypi/v/langchain-ai-identity?label=langchain-ai-identity&color=blue)](https://pypi.org/project/langchain-ai-identity/) [![License](https://img.shields.io/badge/license-proprietary%20core%20·%20MIT%20verifier-blue)](LICENSE) **为 AI agent 提供身份认证、治理机制与取证问责体系。** 每个 agent 都会获得一个加密身份标识、可执行策略、符合合规要求的审计日志,以及防篡改的取证记录轨迹。整个系统构建所围绕的核心设计约束是:**信任 AI Identity 的证据绝不等于需要信任 AI Identity 平台本身。** 依赖方(relying party)进行独立验证所需的一切信息均采用开放许可协议,并支持离线运行。 ## 无需向我们请求即可验证声明 审计记录采用 Merkle 批次处理,并且已签名的 checkpoint 会公开发布,因此您在与我们任何人沟通之前,就可以先确认证据的真实性。 ``` # 1. 从公开 feed 拉取已签名的 checkpoint — 无需 auth,无需账号 curl -s "https://api.ai-identity.co/evidence-anchor/checkpoints?limit=1" # 2. 离线验证已导出的 audit chain — 零依赖,采用 MIT license python3 cli/ai_identity_verify.py chain export.json # 3. 根据已签名的 checkpoint 验证 Merkle inclusion proof python3 cli/ai_identity_verify.py inclusion-proof bundle.json ``` checkpoint 历史记录每六小时也会同步镜像到本仓库的 [`evidence-anchor-mirror`](https://github.com/Levaj2000/AI-Identity/tree/evidence-anchor-mirror) 分支,并实施仅追加(append-only)强制策略 —— 任何被重写的批次、消失的根节点或被篡改的信封都会导致运行失败,而不会覆盖现有记录。如果某个 checkpoint 能够离线验证,但却未出现在公开数据流中,这就是一个被篡改的信号。 ## 标准 记录格式不应由我们私自定义,因此我们将其贡献到了上游项目: - **OCSF** —— `attestation` 对象和 `record_integrity` 配置文件已合并入 [OCSF 1.9](https://github.com/ocsf/ocsf-schema)。本仓库正是生成这些格式的参考实现;emitter 会直接写入合并后的数据结构。 - **CPEX** —— OCSF 审计插件已基于 Apache-2.0 协议贡献给 IBM 的 CPEX 网关。 - **CoSAI WS4** —— CMF ↔ OCSF 交叉映射与互操作资料存放在 [`docs/cosai-ws4-ocsf-mapping/`](docs/cosai-ws4-ocsf-mapping/) 中。 | | URL | |---|---| | **Dashboard** | [ai-identity.co](https://ai-identity.co) | | **API 文档** | [api.ai-identity.co/docs](https://api.ai-identity.co/docs) | | **Checkpoint 数据流** | [api.ai-identity.co/evidence-anchor/checkpoints](https://api.ai-identity.co/evidence-anchor/checkpoints) | ## 集成 ### LangChain AI Identity 提供了开箱即用的 LangChain 集成方案,作为一个独立的 PyPI 包提供: ``` pip install langchain-ai-identity ``` ``` from langchain_ai_identity import create_ai_identity_agent agent = create_ai_identity_agent( tools=[...], agent_id="", ai_identity_api_key="aid_sk_...", openai_api_key="sk-...", ) result = agent.invoke({"input": "What is the latest news on AI safety?"}) ``` 每次 LLM 调用都会经过身份验证、策略检查,并记录在带有防篡改机制的审计追踪中。请查阅 [langchain-ai-identity PyPI 页面](https://pypi.org/project/langchain-ai-identity/) 获取完整文档。 ### 离线取证验证 (CLI) 审计员和应急响应人员可以离线验证审计链的完整性 —— 无需网络连接或信任厂商: ``` python3 cli/ai_identity_verify.py chain export.json ``` 该 CLI 是一个单文件、零依赖的 Python 脚本,能够独立验证从 AI Identity 导出的 HMAC-SHA256 哈希链。 ## 架构 ``` ai-identity/ ├── api/ # FastAPI API server — identity service, admin API (port 8001) ├── gateway/ # FastAPI proxy gateway — request routing & policy enforcement (port 8002) ├── common/ # Shared code — DB models, auth, config, schemas ├── dashboard/ # React + TypeScript + Tailwind — agent management UI ├── sdk/ # Client SDKs — Python, TypeScript, LangChain integration ├── cli/ # Offline forensic verification CLI ├── alembic/ # Database migrations ├── scripts/ # Dev scripts — seed data, migrations └── pyproject.toml ``` ### 组件 1. **身份服务** (`api/`) —— Agent CRUD、API key 签发(`aid_sk_` 前缀)、密钥轮换、权限管理 2. **代理网关** (`gateway/`) —— 验证 agent 密钥,评估策略,转发或拦截请求,并记录决策 3. **共享库** (`common/`) —— SQLAlchemy 模型、Pydantic schema、认证工具及配置 —— 由 api/ 和 gateway/ 共同引用 4. **Dashboard** (`dashboard/`) —— 用于 agent 管理、策略编辑器、实时流量监控和支出图表的 React SPA 5. **SDK** (`sdk/`) —— Python 和 TypeScript 客户端库,以及 [LangChain 集成](https://pypi.org/project/langchain-ai-identity/) 6. **取证 CLI** (`cli/`) —— 用于 DFIR 和合规审查的独立离线审计链验证器 ## 快速开始 ### Docker(推荐) ``` git clone https://github.com/Levaj2000/AI-Identity.git cd AI-Identity make setup # generates .env with security keys make up # builds and starts api + gateway + postgres ``` 服务将启动在 **localhost:8001** (API) 和 **localhost:8002** (Gateway)。 运行 `make help` 查看所有可用命令(migrate、seed、logs、shell 等)。 ### 手动设置 **前置条件:** Python 3.11+、Node.js 18+、PostgreSQL ``` # 1. 创建虚拟环境 python -m venv .venv source .venv/bin/activate # 2. 安装依赖 pip install -r api/requirements.txt pip install -r gateway/requirements.txt pip install -e common/ # 3. 复制环境变量 cp .env.example .env # 使用你的 database URL 和 secrets 编辑 .env # 4. 启动 API server (端口 8001) uvicorn api.app.main:app --reload --port 8001 # 5. 启动 gateway (端口 8002) — 在单独的终端中 uvicorn gateway.app.main:app --reload --port 8002 ``` ### Dashboard ``` cd dashboard cp .env.example .env # defaults to localhost:8001 API npm install && npm run dev ``` Dashboard 通过 Vercel 部署至 [ai-identity.co](https://ai-identity.co)。PR 预览部署会自动生成。 ### 运行测试 ``` # 所有测试 pytest # 仅 API 测试 pytest api/tests/ # 仅 Gateway 测试 pytest gateway/tests/ ``` ## API Keys Agent API key 使用 `aid_sk_` 前缀,存储时采用 SHA-256 哈希加密,并遵循仅显示一次(show-once)的模式。密钥仅在创建时显示一次。 密钥轮换支持 24 小时的宽限期 —— 在过渡期间,新旧密钥均可正常使用。 ## 技术栈 - **后端**: Python 3.11, FastAPI, SQLAlchemy, Alembic, Pydantic - **数据库**: PostgreSQL (Neon) - **前端**: React 19, TypeScript, Vite, Tailwind CSS - **取证**: HMAC-SHA256 哈希链审计日志,离线 CLI 验证器 - **集成**: LangChain ([PyPI](https://pypi.org/project/langchain-ai-identity/)) - **CI/CD**: GitHub Actions, Ruff (lint + format), pytest (1,000+ tests) - **部署**: GKE Autopilot (API + Gateway), Vercel (Dashboard), GitHub Actions CI/CD 配合 Cloud Build ## 许可协议 **平台:专有** —— API、网关、dashboard、Mandate Service 以及共享库均保留所有权利。本仓库公开是为了方便进行代码审计,而非为了允许被复用。 **验证与集成接口:宽松许可** —— 信任 AI Identity 的证据绝不等于需要信任 AI Identity 平台本身,因此依赖方进行独立验证所需的所有内容均采用开放许可协议: | 组件 | 许可证 | |---|---| | [`cli/`](cli/) —— 离线验证器(内置于每个 Case File 包中)+ 审计审查 CLI | MIT | | [`sdk/langchain/`](sdk/langchain/) —— LangChain SDK ([PyPI](https://pypi.org/project/langchain-ai-identity/)) | MIT | | CPEX OCSF 审计插件 —— 已贡献给上游的 IBM CPEX 网关 | Apache-2.0 | 记录格式遵循开放标准:我们的 schema 贡献已合并入上游的 [ocsf/ocsf-schema](https://github.com/ocsf/ocsf-schema) (OCSF 1.9) 中。请参阅 [LICENSE](LICENSE) 了解完整条款。
标签:CVE, Merkle树, 合规治理, 审计日志, 数字签名, 测试用例, 请求拦截, 逆向工具, 防篡改