$ oc -n openshift-security-profiles patch spod spod --type merge \
-p '{"spec":{"allowedSyscalls": ["exit", "exit_group", "futex", "nanosleep"]}}'
使用高级任务启用指标、配置 Webhook 或限制系统调用。
安全配置文件操作符默认情况下不会限制seccomp
配置文件中的系统调用
。您可以在spod
配置中定义允许的系统调用
列表。
要定义allowedSyscalls
列表,请通过运行以下命令调整spec
参数
$ oc -n openshift-security-profiles patch spod spod --type merge \
-p '{"spec":{"allowedSyscalls": ["exit", "exit_group", "futex", "nanosleep"]}}'
操作符将只安装 当在 |
您可以使用baseProfileName
属性来设置给定运行时启动容器所需的最小syscalls
。
编辑SeccompProfile
类型对象,并在spec
字段中添加baseProfileName: runc-v1.0.0
apiVersion: security-profiles-operator.x-k8s.io/v1beta1
kind: SeccompProfile
metadata:
namespace: my-namespace
name: example-name
spec:
defaultAction: SCMP_ACT_ERRNO
baseProfileName: runc-v1.0.0
syscalls:
- action: SCMP_ACT_ALLOW
names:
- exit_group
启用配置文件记录时,在spod
守护进程内部运行的控制器会监控集群中所有可用的Pod。这在大型集群中可能导致非常高的内存使用率,从而导致spod
守护进程内存不足或崩溃。
为防止崩溃,可以将spod
守护进程配置为仅将标记为需要配置文件记录的Pod加载到缓存内存中。
SPO内存优化默认未启用。 |
运行以下命令启用内存优化:
$ oc -n openshift-security-profiles patch spod spod --type=merge -p '{"spec":{"enableMemoryOptimization":true}}'
要为Pod记录安全配置文件,必须使用spo.x-k8s.io/enable-recording: "true"
标签标记该Pod。
apiVersion: v1
kind: Pod
metadata:
name: my-recording-pod
labels:
spo.x-k8s.io/enable-recording: "true"
# ...
可以使用spod
配置中的daemonResourceRequirements
字段调整守护进程容器的默认资源需求。
要指定守护进程容器的内存和CPU请求和限制,请运行以下命令:
$ oc -n openshift-security-profiles patch spod spod --type merge -p \
'{"spec":{"daemonResourceRequirements": { \
"requests": {"memory": "256Mi", "cpu": "250m"}, \
"limits": {"memory": "512Mi", "cpu": "500m"}}}}'
spod
守护进程Pod的默认优先级类名称设置为system-node-critical
。可以通过在spod
配置中设置priorityClassName
字段的值来配置自定义优先级类名称。
运行以下命令配置优先级类名称:
$ oc -n openshift-security-profiles patch spod spod --type=merge -p '{"spec":{"priorityClassName":"my-priority-class"}}'
securityprofilesoperatordaemon.openshift-security-profiles.x-k8s.io/spod patched
openshift-security-profiles
命名空间提供指标端点,这些端点受kube-rbac-proxy容器保护。所有指标都由openshift-security-profiles
命名空间内的metrics
服务公开。
安全配置文件Operator包含一个集群角色和相应的绑定spo-metrics-client
,用于从集群内检索指标。有两个指标路径可用:
metrics.openshift-security-profiles/metrics
:用于控制器运行时指标
metrics.openshift-security-profiles/metrics-spod
:用于Operator守护进程指标
要查看指标服务的状况,请运行以下命令:
$ oc get svc/metrics -n openshift-security-profiles
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
metrics ClusterIP 10.0.0.228 <none> 443/TCP 43s
要检索指标,请使用openshift-security-profiles
命名空间中的默认ServiceAccount
令牌查询服务端点,方法是运行以下命令:
$ oc run --rm -i --restart=Never --image=registry.fedoraproject.org/fedora-minimal:latest \
-n openshift-security-profiles metrics-test -- bash -c \
'curl -ks -H "Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)" https://metrics.openshift-security-profiles/metrics-spod'
# HELP security_profiles_operator_seccomp_profile_total Counter about seccomp profile operations.
# TYPE security_profiles_operator_seccomp_profile_total counter
security_profiles_operator_seccomp_profile_total{operation="delete"} 1
security_profiles_operator_seccomp_profile_total{operation="update"} 2
要从不同的命名空间检索指标,请将ServiceAccount
链接到spo-metrics-client
ClusterRoleBinding
,方法是运行以下命令:
$ oc get clusterrolebinding spo-metrics-client -o wide
NAME ROLE AGE USERS GROUPS SERVICEACCOUNTS
spo-metrics-client ClusterRole/spo-metrics-client 35m openshift-security-profiles/default
controller-runtime metrics
和DaemonSet端点metrics-spod
提供一组默认指标。守护进程还提供其他指标,这些指标始终以security_profiles_operator_
为前缀。
指标键 | 可能的标签 | 类型 | 用途 |
---|---|---|---|
|
|
计数器 |
Seccomp配置文件操作的数量。 |
|
|
计数器 |
Seccomp配置文件审计操作的数量。需要启用日志增强功能。 |
|
|
计数器 |
Seccomp配置文件bpf操作的数量。需要启用bpf记录器。 |
|
|
计数器 |
Seccomp配置文件错误的数量。 |
|
|
计数器 |
SELinux配置文件操作的数量。 |
|
|
计数器 |
SELinux配置文件审计操作的数量。需要启用日志增强功能。 |
|
|
计数器 |
SELinux配置文件错误的数量。 |
安全配置文件Operator包含一个日志增强功能,该功能默认情况下处于禁用状态。日志增强器容器以privileged
权限运行,以读取本地节点的审计日志。日志增强器在主机PID命名空间hostPID
中运行。
日志增强器必须具有读取主机进程的权限。 |
运行以下命令修补spod
配置以启用日志增强器:
$ oc -n openshift-security-profiles patch spod spod \
--type=merge -p '{"spec":{"enableLogEnricher":true}}'
securityprofilesoperatordaemon.security-profiles-operator.x-k8s.io/spod patched
安全配置文件Operator将自动重新部署 |
运行以下命令查看审计日志:
$ oc -n openshift-security-profiles logs -f ds/spod log-enricher
I0623 12:51:04.257814 1854764 deleg.go:130] setup "msg"="starting component: log-enricher" "buildDate"="1980-01-01T00:00:00Z" "compiler"="gc" "gitCommit"="unknown" "gitTreeState"="clean" "goVersion"="go1.16.2" "platform"="linux/amd64" "version"="0.4.0-dev"
I0623 12:51:04.257890 1854764 enricher.go:44] log-enricher "msg"="Starting log-enricher on node: 127.0.0.1"
I0623 12:51:04.257898 1854764 enricher.go:46] log-enricher "msg"="Connecting to local GRPC server"
I0623 12:51:04.258061 1854764 enricher.go:69] log-enricher "msg"="Reading from file /var/log/audit/audit.log"
2021/06/23 12:51:04 Seeked /var/log/audit/audit.log - &{Offset:0 Whence:2}
您可以使用安全配置文件Operator日志增强器来跟踪应用程序。
要跟踪应用程序,请创建一个SeccompProfile
日志记录配置文件。
apiVersion: security-profiles-operator.x-k8s.io/v1beta1
kind: SeccompProfile
metadata:
name: log
namespace: default
spec:
defaultAction: SCMP_ACT_LOG
创建一个Pod对象以使用该配置文件。
apiVersion: v1
kind: Pod
metadata:
name: log-pod
spec:
securityContext:
runAsNonRoot: true
seccompProfile:
type: Localhost
localhostProfile: operator/default/log.json
containers:
- name: log-container
image: quay.io/security-profiles-operator/test-nginx-unprivileged:1.21
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop: [ALL]
运行以下命令检查日志增强器输出:
$ oc -n openshift-security-profiles logs -f ds/spod log-enricher
…
I0623 12:59:11.479869 1854764 enricher.go:111] log-enricher "msg"="audit" "container"="log-container" "executable"="/" "namespace"="default" "node"="127.0.0.1" "pid"=1905792 "pod"="log-pod" "syscallID"=3 "syscallName"="close" "timestamp"="1624453150.205:1061" "type"="seccomp"
I0623 12:59:11.487323 1854764 enricher.go:111] log-enricher "msg"="audit" "container"="log-container" "executable"="/" "namespace"="default" "node"="127.0.0.1" "pid"=1905792 "pod"="log-pod" "syscallID"=157 "syscallName"="prctl" "timestamp"="1624453150.205:1062" "type"="seccomp"
I0623 12:59:11.492157 1854764 enricher.go:111] log-enricher "msg"="audit" "container"="log-container" "executable"="/" "namespace"="default" "node"="127.0.0.1" "pid"=1905792 "pod"="log-pod" "syscallID"=157 "syscallName"="prctl" "timestamp"="1624453150.205:1063" "type"="seccomp"
…
I0623 12:59:20.258523 1854764 enricher.go:111] log-enricher "msg"="audit" "container"="log-container" "executable"="/usr/sbin/nginx" "namespace"="default" "node"="127.0.0.1" "pid"=1905792 "pod"="log-pod" "syscallID"=12 "syscallName"="brk" "timestamp"="1624453150.235:2873" "type"="seccomp"
I0623 12:59:20.263349 1854764 enricher.go:111] log-enricher "msg"="audit" "container"="log-container" "executable"="/usr/sbin/nginx" "namespace"="default" "node"="127.0.0.1" "pid"=1905792 "pod"="log-pod" "syscallID"=21 "syscallName"="access" "timestamp"="1624453150.235:2874" "type"="seccomp"
I0623 12:59:20.354091 1854764 enricher.go:111] log-enricher "msg"="audit" "container"="log-container" "executable"="/usr/sbin/nginx" "namespace"="default" "node"="127.0.0.1" "pid"=1905792 "pod"="log-pod" "syscallID"=257 "syscallName"="openat" "timestamp"="1624453150.235:2875" "type"="seccomp"
I0623 12:59:20.358844 1854764 enricher.go:111] log-enricher "msg"="audit" "container"="log-container" "executable"="/usr/sbin/nginx" "namespace"="default" "node"="127.0.0.1" "pid"=1905792 "pod"="log-pod" "syscallID"=5 "syscallName"="fstat" "timestamp"="1624453150.235:2876" "type"="seccomp"
I0623 12:59:20.363510 1854764 enricher.go:111] log-enricher "msg"="audit" "container"="log-container" "executable"="/usr/sbin/nginx" "namespace"="default" "node"="127.0.0.1" "pid"=1905792 "pod"="log-pod" "syscallID"=9 "syscallName"="mmap" "timestamp"="1624453150.235:2877" "type"="seccomp"
I0623 12:59:20.454127 1854764 enricher.go:111] log-enricher "msg"="audit" "container"="log-container" "executable"="/usr/sbin/nginx" "namespace"="default" "node"="127.0.0.1" "pid"=1905792 "pod"="log-pod" "syscallID"=3 "syscallName"="close" "timestamp"="1624453150.235:2878" "type"="seccomp"
I0623 12:59:20.458654 1854764 enricher.go:111] log-enricher "msg"="audit" "container"="log-container" "executable"="/usr/sbin/nginx" "namespace"="default" "node"="127.0.0.1" "pid"=1905792 "pod"="log-pod" "syscallID"=257 "syscallName"="openat" "timestamp"="1624453150.235:2879" "type"="seccomp"
…
配置文件绑定和配置文件记录对象可以使用Webhook。配置文件绑定和记录对象配置是MutatingWebhookConfiguration
CR,由安全配置文件Operator管理。
要更改Webhook配置,spod
CR 公开了一个webhookOptions
字段,允许修改failurePolicy
、namespaceSelector
和objectSelector
变量。这允许您将Webhook设置为“软失败”或将其限制为命名空间的子集,以便即使Webhook失败,也不会影响其他命名空间或资源。
通过创建以下补丁文件,将recording.spo.io
Webhook配置设置为仅记录标记为spo-record=true
的Pod:
spec:
webhookOptions:
- name: recording.spo.io
objectSelector:
matchExpressions:
- key: spo-record
operator: In
values:
- "true"
运行以下命令修补spod/spod
实例:
$ oc -n openshift-security-profiles patch spod \
spod -p $(cat /tmp/spod-wh.patch) --type=merge
要查看生成的MutatingWebhookConfiguration
对象,请运行以下命令:
$ oc get MutatingWebhookConfiguration \
spo-mutating-webhook-configuration -oyaml