7.7.2.3. コントローラーと SecurityContextConstraints の複製
デプロイメントやデーモンセットなど、コントローラーをレプリケートするための SELinux ポリシーをデプロイする場合、コントローラーによって生成された Pod オブジェクトは、ワークロードを作成するユーザーの ID で実行されないことに注意してください。ServiceAccount が選択されていない場合、Pod は、カスタムセキュリティーポリシーの使用を許可しない、制限された SecurityContextConstraints (SCC) の使用に戻る可能性があります。
手順
次のコマンドを実行してプロジェクトを作成します。
$ oc new-project nginx-secure次の
RoleBindingオブジェクトを作成して、SELinux ポリシーをnginx-securenamespace で使用できるようにします。kind: RoleBinding apiVersion: rbac.authorization.k8s.io/v1 metadata: name: spo-nginx namespace: nginx-secure subjects: - kind: ServiceAccount name: spo-deploy-test roleRef: kind: Role name: spo-nginx apiGroup: rbac.authorization.k8s.ioRoleオブジェクトを作成します。apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: creationTimestamp: null name: spo-nginx namespace: nginx-secure rules: - apiGroups: - security.openshift.io resources: - securitycontextconstraints resourceNames: - privileged verbs: - useServiceAccountオブジェクトを作成します。apiVersion: v1 kind: ServiceAccount metadata: creationTimestamp: null name: spo-deploy-test namespace: nginx-secureDeploymentオブジェクトを作成します。apiVersion: apps/v1 kind: Deployment metadata: name: selinux-test namespace: nginx-secure metadata: labels: app: selinux-test spec: replicas: 3 selector: matchLabels: app: selinux-test template: metadata: labels: app: selinux-test spec: serviceAccountName: spo-deploy-test securityContext: seLinuxOptions: type: nginx-secure.process1 containers: - name: nginx-unpriv image: quay.io/security-profiles-operator/test-nginx-unprivileged:1.21 ports: - containerPort: 8080- 1
- デプロイメントが作成される前に、
.seLinuxOptions.typeが存在している必要があります。注記SELinux タイプはワークロードで指定されておらず、SCC によって処理されます。デプロイと
ReplicaSetによって Pod が作成されると、Pod は適切なプロファイルで実行されます。
SCC が、正しいサービスアカウントのみで使用できることを確認してください。詳細は、その他のリソース を参照してください。