mobile wallpaper 1mobile wallpaper 2mobile wallpaper 3mobile wallpaper 4
453 字
1 分钟
CNAPP 云原生应用保护平台详解
2024-10-08

一、云原生安全挑战#

1.1 容器架构变化#

graph TB subgraph "传统架构" A["物理机"] --> B["虚拟机"] B --> C["应用"] end subgraph "容器架构" D["容器编排 K8s"] --> E["Pod"] E --> F["容器"] F --> G["镜像仓库"] G --> H["CI/CD Pipeline"] H --> I["Helm Chart"] end style D fill:#90EE90 style G fill:#FFD700

容器带来的新挑战:

挑战说明
攻击面扩大镜像、容器运行时、Kubernetes API
快速迭代容器生命周期短、变更频繁
多租户共享内核、隔离难度大
合规要求等保 2.0、K8s 安全基线

1.2 CNAPP 定义#

graph TB A["CNAPP"] --> B["CSPM"] A --> C["Cloud SWG"] A --> D["Cloud Workload Protection"] A --> E["容器安全"] A --> F["K8s 安全"] B --> G["资产可视化"] B --> H["合规检测"] B --> I["配置管理"] D --> J["运行时防护"] D --> K["威胁检测"]

二、云原生安全架构#

2.1 多层防护体系#

security_layers:
# 基础设施层
infra:
- cloud_account_security
- network_segmentation
- identity_foundation
# 容器平台层
platform:
- kubernetes_security
- container_registry
- secret_management
# 应用层
application:
- image_scanning
- vulnerability_management
- network_policy
# 运行时层
runtime:
- behavior_monitoring
- threat_detection
- incident_response

2.2 防御矩阵#

层次防护措施工具
镜像扫描、合规、质量门禁Trivy, Clair, Anchore
KubernetesRBAC、NetworkPolicy、准入控制OPA, Kyverno
容器隔离、限制、特权控制seccomp, AppArmor, SELinux
网络零信任、微分段Cilium, Calico, Istio
运行时行为检测、威胁狩猎Falco, Sysdig, Tetragon
合规等保 2.0、K8s CIS 基线kube-bench, Kubearmor

三、镜像安全#

3.1 镜像扫描流程#

flowchart LR A[代码提交] --> B["构建镜像"] B --> C[层析扫描] C --> D{Critical 漏洞?} D -->|是| E["阻断构建"] D -->|否| F[推送 Registry] F --> G["分发部署"] G --> H["运行时监控"]

3.2 镜像扫描配置#

image_scanning:
# 构建阶段
build_time:
# 阻断规则
block_critical: true
block_high_with_exploit: true
block_malware: true
# 扫描项
checks:
- CVE 漏洞
- 恶意软件
- 敏感信息
- 配置错误
- 证书过期
# 部署阶段
deploy_time:
admission_control: true
block_untrusted_images: true
require_signed: true
# 运行时
runtime:
continuous_scanning: true
alert_on_new_critical: true

3.3 准入控制(Admission Control)#

# OPA Gatekeeper 策略
admission_policies:
# 禁止特权容器
- name: no_privileged_containers
enforcement: deny
condition: |
input.request.object.spec.containers.any(c, c.securityContext.privileged == true)
# 只允许已签名镜像
- name: require_signed_images
enforcement: deny
condition: |
input.request.kind == "Pod"
not input.image_signature_valid
# 资源限制
- name: enforce_resource_limits
enforcement: audit
condition: |
all_containers_have_limits

四、Kubernetes 安全#

4.1 RBAC 最小权限#

# ServiceAccount 配置
service_accounts:
# 应用场景分配
web_app:
name: web-sa
namespace: production
rules:
- apiGroups: [""]
resources: ["pods", "services"]
verbs: ["get", "list"]
# 数据库访问
db_app:
name: db-sa
namespace: production
rules:
- apiGroups: [""]
resources: ["configmaps", "secrets"]
verbs: ["get"]
- apiGroups: [""]
resources: ["pods/exec"]
verbs: ["create"]
resourceNames: ["db-backup-command"]

4.2 网络策略#

# 默认拒绝所有入站流量
network_policy:
name: default-deny-ingress
spec:
podSelector: {}
policyTypes:
- Ingress
# 允许特定流量
web_to_db_policy:
name: allow-web-to-db
podSelector:
matchLabels:
app: database
ingress:
- from:
- podSelector:
matchLabels:
app: web
ports:
- port: 5432

4.3 Pod 安全标准#

pod_security_standards:
# 基线级别
baseline:
seccomp: RuntimeDefault
capabilities: DROP ALL
privileged: false
# 限制级别
restricted:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault

五、运行时安全#

5.1 Falco 规则#

falco_rules:
# 异常行为检测
rules:
- name: shell_in_container
condition: >
spawned_process
and container
and proc.name in (shell_binaries)
output: >
Shell spawned in container
(user=%user.name container=%container.name
shell=%proc.name command=%proc.cmdline)
priority: WARNING
- name: write_binary_dir
condition: >
open_write
and container
and dirs_in_etc
output: >
File to /etc directory
(user=%user.name container=%container.name
file=%fd.name command=%proc.cmdline)
priority: CRITICAL

5.2 Tetragon 追踪#

tetragon_policy:
# 敏感操作追踪
tracing:
- name:敏感文件访问
event: openat
args:
- path
selectors:
- pid: 0
comm:
- malware
flags:
- O_WRONLY
- name: 网络连接
event: connect
args:
- remote_addr
selectors:
- pid: 0

六、合规检测#

6.1 K8s CIS 基线#

cis_benchmark_checks:
# Master 节点
master:
- id: "1.1.1"
title: "API Server 加密传输"
check: |
kubectl get pod -n kube-system kube-apiserver -o yaml |
grep -q "tls-cert-file"
# Worker 节点
worker:
- id: "4.2.1"
title: "容器镜像扫描"
check: |
kubelet 配置 ImageWebhook
# 合规报告
compliance_report:
format: pdf
standards:
- CIS Kubernetes
- PCI-DSS
- SOC2

6.2 修复工作流#

flowchart TB A["违规检测"] --> B{严重性} B -->|Critical| C["立即修复"] B -->|High| D["计划修复"] B -->|Medium| E["下一迭代"] B -->|Low| F["记录跟踪"] C --> G["自动修复"] D --> H["工单系统"] G --> I["验证"] H --> I

七、阿里云 ACK 安全#

7.1 ACK 加固项#

aliyun_ack_security:
# 网络策略
network:
Terway 网络模式: CNI_Elastic
NetworkPolicy 强制: true
# 容器运行时
runtime:
镜像沙箱: 开启
Root 权限检查: 开启
# 密钥管理
secrets:
阿里云 KMS 加密: true
外部密钥: HashiCorp Vault
# 合规
compliance:
等保 2.0: 开启
CIS 基线: 自动检查

7.2 容器镜像服务企业版#

container_registry:
# 镜像签名
sign:
mechanism: KMS + kritis-validation-hook
notary: 阿里云镜像公证
# 漏洞扫描
scan:
阻断策略:阻断 Critical
扫描范围: 依赖镜像
# 访问控制
access:
vpc 内网推送: true
扫码授权: RAM Role

八、产品对比#

厂商产品核心能力
阿里云ACK 安全概览 + 云安全中心云原生深度集成
腾讯云容器安全服务TKE 集成
华为云HSS 容器安全防护漏洞管理、基线检测
深信服云安全资源池 CSSP统一管控
绿盟科技云原生安全防护平台 CNSP镜像扫描、准入控制

十、总结#

CNAPP 是云原生时代的安全平台,核心是镜像安全、K8s 加固、运行时检测、合规管理的一体化。

支持与分享

如果这篇文章对你有帮助,欢迎支持作者或分享给更多人

CNAPP 云原生应用保护平台详解
https://blog.souloss.com/posts/cloud-security/cnapp-cloud-native-security/
作者
Souloss
发布于
2024-10-08
许可协议
CC BY-NC-SA 4.0

部分信息可能已经过时