fischer-agentkit/docs/compliance/dengbao-level3/03-host.md

198 lines
8.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 03 — 主机安全
> GB/T 22239-2019 第三级「设备和计算安全」控制点映射。
> 本维度以**容器与 Pod**为「主机」单元AgentKit 不直接运维 K8s node
## 1. 维度说明
AgentKit 以容器形态运行在客户 K8s 集群。「主机安全」分为两层:
- **容器/Pod 层**AgentKit 责任):镜像安全、运行时安全上下文、
ServiceAccount、Pod 级 RBAC。
- **K8s node 层**客户责任宿主机操作系统内核加固、node 基线、
主机入侵检测HIDS
AgentKit 自身实现:
- **已实现**:非 root 容器、最小权限安全上下文capabilities drop ALL
ServiceAccount 隔离、容器级资源限制。
- **P0 补齐项**容器镜像漏洞扫描CI 集成 Trivy/Grype
Pod 安全审计日志采集标准化。
- **P1 参考**distroless 基础镜像。
## 2. GB/T 22239-2019 三级要求(简要)
| 控制点 ID | 要求摘要 |
|-----------|----------|
| HST-01 | 身份鉴别:设备/系统身份标识与鉴别 |
| HST-02 | 访问控制:操作系统/账户权限最小化,远程管理受控 |
| HST-03 | 安全审计:设备审计日志,覆盖系统管理活动 |
| HST-04 | 入侵防范:主机入侵检测,系统加固 |
| HST-05 | 恶意代码防范:主机防病毒,恶意代码检测 |
| HST-06 | 资源控制CPU/内存/磁盘限制,会话超时 |
| HST-07 | 镜像与补丁管理:系统补丁及时更新,镜像来源可信 |
## 3. AgentKit 实现映射
### 3.1 容器镜像安全HST-07— 部分已实现 / P0 补齐
#### 已实现
- **多阶段构建**builder + runner 两阶段,最终镜像不含构建工具链。
[Dockerfile](file:///Users/chiguyong/Code/Fischer-agentkit/Dockerfile)
- **非 root 用户**runner 阶段创建 `appuser`UID 1001 / GID 1001
`USER appuser` 强制非 root 运行。
- **基础镜像**`python:3.11-slim`(精简版,比 full 镜像减少攻击面)。
- **HEALTHCHECK**:内置健康检查
`/api/v1/health`30s 间隔)。
- **不写字节码**`PYTHONDONTWRITEBYTECODE=1`,减少磁盘 .pyc 残留。
#### P0 补齐项:镜像漏洞扫描
**当前状态P0**。CI 流水线未集成容器镜像漏洞扫描。
**P0 补齐计划**
1. CI 流水线增加 Trivy 扫描步骤:
```yaml
- name: Trivy scan
run: trivy image --severity HIGH,CRITICAL --exit-code 1 fischer-agentkit:${{ github.sha }}
```
2. Helm Chart 增加 `image.digest` 字段,部署时使用不可变 digest 而非 tag。
3. 镜像签名cosign— P1可选。
### 3.2 K8s node 安全基线HST-04 / HST-05— 待评估
**当前状态:待评估**。K8s 宿主机由客户运维AgentKit 不控制 node 操作系统。
客户侧需提供:
- node 操作系统加固基线CIS Benchmark for Kubernetes / 操作系统)。
- 主机入侵检测HIDS如 Falco / OSSEC
- 主机防病毒(如客户机房要求)。
AgentKit 侧的缓解:
- Pod `securityContext` 强制非 root + drop ALL capabilities
[values.yaml](file:///Users/chiguyong/Code/Fischer-agentkit/deploy/helm/agentkit/values.yaml)
`podSecurityContext` / `securityContext` 段),即使 node 被攻破,
容器逃逸到 root 的难度提升。
### 3.3 身份鉴别 / ServiceAccountHST-01— 已实现
AgentKit Pod 使用专用 ServiceAccount不共享 default SA
- **ServiceAccount 创建**
[deploy/helm/agentkit/templates/serviceaccount.yaml](file:///Users/chiguyong/Code/Fischer-agentkit/deploy/helm/agentkit/templates/serviceaccount.yaml)
- **values 配置**
```yaml
serviceAccount:
create: true
name: "" # 留空则用 fullname专用 SA
annotations: {} # 云厂商 workload identity 注解
```
- **Workload Identity**(可选):`workloadIdentity.enabled: true` 时
注入 projected SA token用于访问云 KMS / STS
[values.yaml](file:///Users/chiguyong/Code/Fischer-agentkit/deploy/helm/agentkit/values.yaml)
`workloadIdentity` 段)。
Pod 内应用层身份鉴别见 `04-application.md` §1SSO + JWT
### 3.4 访问控制 / Pod 级 RBACHST-02— 已实现
- **capabilities drop ALL**
```yaml
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop: [ALL]
```
([values.yaml](file:///Users/chiguyong/Code/Fischer-agentkit/deploy/helm/agentkit/values.yaml) `securityContext` 段)
- **runAsNonRoot 强制**`podSecurityContext.runAsNonRoot: true`
K8s admission 拒绝非 root Pod。
- **readOnlyRootFilesystem**:当前为 `false`agentkit 需写临时文件用于缓存/日志),
通过 `emptyDir` 挂载 `/tmp` 实现写入隔离
[deployment.yaml](file:///Users/chiguyong/Code/Fischer-agentkit/deploy/helm/agentkit/templates/deployment.yaml)
`volumes.tmp`)。
- **privileged: false**(默认,未启用特权模式)。
应用层 RBACmember/operator/admin + 9 权限位)见
`04-application.md` §2。
### 3.5 安全审计 / 容器日志HST-03— 已实现 + P0 补齐
#### 已实现
- **stdout/stderr 标准输出**AgentKit 日志全部输出到 stdout
由 K8s 日志采集(如 Loki / Fluent Bit收集。
- **OTel trace**:每个 Pod 的请求 trace 通过 OTLP 导出到 collector
U1强制依赖
- **审计事件**RBAC 变更、deprovisioning、SCIM 操作写入 `auth_audit_log`
+ OTel span event[audit.py](file:///Users/chiguyong/Code/Fischer-agentkit/src/agentkit/server/auth/audit.py))。
- **终端命令审计**:每条终端命令 + 决策executed/confirmed/blocked/denied
写入 `terminal_audit_logs`
[terminal_security.py](file:///Users/chiguyong/Code/Fischer-agentkit/src/agentkit/server/auth/terminal_security.py))。
#### P0 补齐项:审计日志标准化采集
**当前状态P0**。容器日志采集到客户日志平台的链路未标准化。
**P0 补齐计划**
1. Helm Chart 增加 `logging.fluentBitSidecar` 选项(可选 sidecar 采集)。
2. 审计日志 JSON 化structured logging便于 SIEM 解析。
3.`02-network.md` §3.7 的 180 天保留策略协同落地。
### 3.6 入侵防范HST-04— 已实现(容器层)
容器层入侵防范已实现:
- **非 root + drop ALL capabilities**:限制容器内可执行的系统调用。
- **allowPrivilegeEscalation: false**:阻止子进程提权。
- **资源 limits**CPU 1000m / Memory 2Gi 上限,防止容器失控耗尽 node 资源
[values.yaml](file:///Users/chiguyong/Code/Fischer-agentkit/deploy/helm/agentkit/values.yaml)
`resources.limits`)。
- **Liveness/Readiness 探针**:故障 Pod 自动重启
[deployment.yaml](file:///Users/chiguyong/Code/Fischer-agentkit/deploy/helm/agentkit/templates/deployment.yaml)
`livenessProbe` / `readinessProbe`)。
node 层入侵检测HIDS见 §3.2,依赖客户侧。
### 3.7 资源控制HST-06— 已实现
- **Pod resources**
```yaml
resources:
requests: { cpu: 250m, memory: 512Mi }
limits: { cpu: 1000m, memory: 2Gi }
```
- **应用层限流**[RateLimiter](file:///Users/chiguyong/Code/Fischer-agentkit/src/agentkit/server/middleware.py)
IP 维度滑动窗口。
- **会话超时**:终端 session 1800s 闲置断开
[terminal_server.py](file:///Users/chiguyong/Code/Fischer-agentkit/src/agentkit/server/routes/terminal_server.py))。
- **JWT 短时效**access 15min / refresh 7d
[jwt_utils.py](file:///Users/chiguyong/Code/Fischer-agentkit/src/agentkit/server/auth/jwt_utils.py))。
## 4. distroless 基础镜像P1 参考)
**当前状态P1**。当前基础镜像为 `python:3.11-slim`,含 shell + 包管理器,
攻击面大于 distroless。
**P1 升级路径**
1. 切换到 `gcr.io/distroless/python3-debian12` 作为 runner 基础镜像。
2. 需调整distroless 无 shellHEALTHCHECK 的 `python -c` 命令需改为
HTTP 探针K8s livenessProbe httpGet已支持
3. 多阶段构建的 builder 阶段保持 `python:3.11-slim`(构建工具链需要)。
distroless 不阻碍等保三级认证,但作为安全增强项写入整改计划。
## 5. 测评建议
1. **HST-01 / HST-02 / HST-06**:直接展示 ServiceAccount + securityContext
+ resources 配置即可。
2. **HST-03**:已实现部分展示 audit.py + terminal_security.py
P0 补齐日志标准化采集。
3. **HST-07**P0 补齐镜像漏洞扫描后展示 Trivy 扫描报告。
4. **HST-04 / HST-05**容器层已实现node 层由客户提供 HIDS 证据。