Sync: add container security notes

This commit is contained in:
2026-04-24 13:16:42 +08:00
parent 761fa71f69
commit 3b55f3af4d
16 changed files with 626 additions and 144 deletions

View File

@@ -0,0 +1,60 @@
---
title: "Container Lifecycle Hardening"
type: concept
tags: [Container, Security, Kubernetes, DevSecOps, Hardening]
last_updated: 2026-04-24
---
## Definition
容器生命周期安全加固Container Lifecycle Hardening是指在容器的构建Build、部署Deploy、运行Run三个阶段中系统性地应用安全控制措施以减少容器化工作负载的攻击面。
## Three Phases
### Build Phase构建阶段
在构建阶段确保镜像本身不含漏洞和敏感信息:
- 使用经过安全加固的[[Micro Focus]]基础镜像
- 引入 Init 系统([[tini]])防止僵尸进程
- 镜像不含敏感信息密码、API Key
- 启用镜像漏洞扫描
- 每个容器仅运行单一应用
### Deploy Phase部署阶段
在部署到 Kubernetes 时应用安全配置:
- 使用只读根文件系统readOnlyRootFilesystem: true
- 使用 [[emptyDir Volume]] 存储临时文件
- 禁用 Kubernetes API 自动挂载automountServiceAccountToken: false
- 使用私有服务账号配合精确 RBAC
- 避免 hostNetwork 和 hostPort
### Run Phase运行时阶段
运行时持续监控和加固CTP Topic 49 视频中提到将另有专题覆盖)。
## Key Standards (Build Phase)
来自 [[ctp-topic-49-container-lifecycle-hardening-standards]] 的 11 条标准:
1. **Micro Focus Base Image** — 使用经过安全配置的官方基础镜像
2. **Init System** — 使用 [[tini]] 处理信号和防止僵尸进程
3. **No Sensitive Info** — 镜像不含敏感数据,使用 [[Kubernetes Secrets]] 运行时注入
4. **Read-Only Root FS** — 设置 readOnlyRootFilesystem: true
5. **emptyDir for /tmp** — 使用 emptyDir volume 替代 hostPath
6. **Image Scanning** — 启用容器镜像漏洞扫描
7. **Single Application** — 每容器运行单一应用
8. **No K8s API Access** — 禁用 automountServiceAccountToken
9. **Private Service Account** — 使用最小权限的服务账号
10. **No Host Network** — 避免 hostNetwork 配置
11. **No Host Port** — 避免 hostPort 配置
## Relationship to DevSecOps
容器生命周期安全加固是 [[DevSecOps]] 理念在容器领域的具体实践:
- **安全左移Shift-Left**:安全问题在构建阶段就被发现和修复
- **自动化**:通过 IaC 和 CI/CD 流水线自动执行安全检查
- **最小权限**:容器仅获得完成功能所需的最小权限
## Relationship to Supply Chain Security
容器镜像加固是[[Supply Chain Security供应链安全]]体系的重要组成部分:
- 供应链安全的构建阶段CI= 容器镜像加固
- 构建安全镜像 → 防止攻击者在制品中注入恶意代码
## Sources
- [[ctp-topic-49-container-lifecycle-hardening-standards]]
- [[ctp-topic-21-supply-chain-security-in-micro-focus]]