概览与核心价值Pod 安全强化通过限制权限与隔离能力提升安全性。PodSecurity Admission(PSA)替代旧版 PSP,用命名空间级策略约束 Pod 行为。命名空间策略(PSA)apiVersion: v1
kind: Namespace
metadata:
name: secure
labels:
pod-security.kubernetes.io/enforce: restricted
pod-security.kubernetes.io/audit: restricted
pod-security.kubernetes.io/warn: restricted
安全上下文示例apiVersion: apps/v1
kind: Deployment
metadata:
name: app
namespace: secure
spec:
replicas: 2
selector:
matchLabels:
app: app
template:
metadata:
labels:
app: app
spec:
securityContext:
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
containers:
- name: app
image: ghcr.io/company/app:1.0.0
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop: ["ALL"]
readOnlyRootFilesystem: true
参数与验证环境:`Kubernetes v1.28`。验证点:在 `secure` 命名空间创建不合规 Pod 将被拒绝合规 Pod 成功运行,`runAsNonRoot` 与 `readOnlyRootFilesystem` 生效`seccomp` 与 `capabilities` 配置可在容器中查看与验证最佳实践命名空间级别启用 `restricted`,逐步提高安全门槛在镜像构建阶段采用非 root 用户与最小化产物配合策略引擎(如 Gatekeeper)实施更细粒度约束结论通过 PSA 与安全上下文的组合,可在 Kubernetes 中实现 rootless、最小权限与策略化治理,验证简单有效。

发表评论 取消回复