2.4.8.3. SCC 策略示例
应用安全性上下文约束 (SCC) 策略,通过在策略中定义条件来控制 Pod 的权限。如需更多信息,请参阅管理安全性上下文约束 (SCC)。您的 SCC 策略可能类似以下 YAML 文件:
apiVersion: policy.open-cluster-management.io/v1 kind: Policy metadata: name: policy-scc namespace: open-cluster-management annotations: policy.open-cluster-management.io/standards: NIST-CSF policy.open-cluster-management.io/categories: PR.PT Protective Technology policy.open-cluster-management.io/controls: PR.PT-3 Least Functionality spec: complianceType: musthave remediationAction: inform disabled: false namespaces: exclude: ["kube-*"] include: ["default"] object-templates: - complianceType: musthave objectDefinition: apiVersion: security.openshift.io/v1 kind: SecurityContextConstraints # restricted scc metadata: annotations: kubernetes.io/description: restricted denies access to all host features and requires pods to be run with a UID, and SELinux context that are allocated to the namespace. This is the most restrictive SCC and it is used by default for authenticated users. name: sample-restricted-scc allowHostDirVolumePlugin: false allowHostIPC: false allowHostNetwork: false allowHostPID: false allowHostPorts: false allowPrivilegeEscalation: true allowPrivilegedContainer: false allowedCapabilities: [] defaultAddCapabilities: [] fsGroup: type: MustRunAs groups: - system:authenticated priority: null readOnlyRootFilesystem: false requiredDropCapabilities: - KILL - MKNOD - SETUID - SETGID runAsUser: type: MustRunAsRange seLinuxContext: type: MustRunAs supplementalGroups: type: RunAsAny users: [] volumes: - configMap - downwardAPI - emptyDir - persistentVolumeClaim - projected - secret --- apiVersion: apps.open-cluster-management.io/v1 kind: PlacementBinding metadata: name: binding-policy-scc namespace: open-cluster-management-policies placementRef: name: placement-policy-scc kind: PlacementRule apiGroup: apps.open-cluster-management.io subjects: - name: policy-scc kind: Policy apiGroup: policy.mcm.ibm.com --- apiVersion: apps.open-cluster-management.io/v1 kind: PlacementBinding metadata: name: policy-scc-production-clusters namespace: open-cluster-management-policies placementRef: name: production-clusters kind: PlacementRule apiGroup: apps.open-cluster-management.io subjects: - name: policy-scc kind: Policy apiGroup: policy.mcm.ibm.com --- apiVersion: apps.open-cluster-management.io/v1 kind: PlacementRule metadata: name: placement-policy-scc namespace: open-cluster-management-policies spec: clusterConditions: - type: ManagedClusterConditionAvailable status: "True" clusterSelector: matchExpressions: []
apiVersion: policy.open-cluster-management.io/v1
kind: Policy
metadata:
name: policy-scc
namespace: open-cluster-management
annotations:
policy.open-cluster-management.io/standards: NIST-CSF
policy.open-cluster-management.io/categories: PR.PT Protective Technology
policy.open-cluster-management.io/controls: PR.PT-3 Least Functionality
spec:
complianceType: musthave
remediationAction: inform
disabled: false
namespaces:
exclude: ["kube-*"]
include: ["default"]
object-templates:
- complianceType: musthave
objectDefinition:
apiVersion: security.openshift.io/v1
kind: SecurityContextConstraints # restricted scc
metadata:
annotations:
kubernetes.io/description: restricted denies access to all host features and requires pods to be run with a UID, and SELinux context that are allocated to the namespace. This is the most restrictive SCC and it is used by default for authenticated users.
name: sample-restricted-scc
allowHostDirVolumePlugin: false
allowHostIPC: false
allowHostNetwork: false
allowHostPID: false
allowHostPorts: false
allowPrivilegeEscalation: true
allowPrivilegedContainer: false
allowedCapabilities: []
defaultAddCapabilities: []
fsGroup:
type: MustRunAs
groups:
- system:authenticated
priority: null
readOnlyRootFilesystem: false
requiredDropCapabilities:
- KILL
- MKNOD
- SETUID
- SETGID
runAsUser:
type: MustRunAsRange
seLinuxContext:
type: MustRunAs
supplementalGroups:
type: RunAsAny
users: []
volumes:
- configMap
- downwardAPI
- emptyDir
- persistentVolumeClaim
- projected
- secret
---
apiVersion: apps.open-cluster-management.io/v1
kind: PlacementBinding
metadata:
name: binding-policy-scc
namespace: open-cluster-management-policies
placementRef:
name: placement-policy-scc
kind: PlacementRule
apiGroup: apps.open-cluster-management.io
subjects:
- name: policy-scc
kind: Policy
apiGroup: policy.mcm.ibm.com
---
apiVersion: apps.open-cluster-management.io/v1
kind: PlacementBinding
metadata:
name: policy-scc-production-clusters
namespace: open-cluster-management-policies
placementRef:
name: production-clusters
kind: PlacementRule
apiGroup: apps.open-cluster-management.io
subjects:
- name: policy-scc
kind: Policy
apiGroup: policy.mcm.ibm.com
---
apiVersion: apps.open-cluster-management.io/v1
kind: PlacementRule
metadata:
name: placement-policy-scc
namespace: open-cluster-management-policies
spec:
clusterConditions:
- type: ManagedClusterConditionAvailable
status: "True"
clusterSelector:
matchExpressions: []
要了解如何管理 SCC 策略,请参阅管理安全性上下文约束策略以了解更多详细信息。如需了解其他配置策略,请参阅 Kubernetes 配置策略控制器。请参阅管理安全策略以管理其他策略。