7.6.2. Pod への seccomp プロファイルの適用
Pod を作成して、作成したプロファイルの 1 つを適用します。
手順
securityContextを定義する Pod オブジェクトを作成します。apiVersion: v1 kind: Pod metadata: name: test-pod spec: securityContext: runAsNonRoot: true seccompProfile: type: Localhost localhostProfile: operator/profile1.json containers: - name: test-container image: quay.io/security-profiles-operator/test-nginx-unprivileged:1.21 securityContext: allowPrivilegeEscalation: false capabilities: drop: [ALL]次のコマンドを実行して、
seccompProfile.localhostProfile属性のプロファイルパスを表示します。$ oc get seccompprofile profile1 --output wide出力例
NAME STATUS AGE SECCOMPPROFILE.LOCALHOSTPROFILE profile1 Installed 14s operator/profile1.json次のコマンドを実行して、localhost プロファイルへのパスを表示します。
$ oc get sp profile1 --output=jsonpath='{.status.localhostProfile}'出力例
operator/profile1.jsonlocalhostProfileの出力をパッチファイルに適用します。spec: template: spec: securityContext: seccompProfile: type: Localhost localhostProfile: operator/profile1.json次のコマンドを実行して、プロファイルを他のワークロード (
Deploymentオブジェクトなど) に適用します。$ oc -n my-namespace patch deployment myapp --patch-file patch.yaml --type=merge出力例
deployment.apps/myapp patched
検証
次のコマンドを実行して、プロファイルが正しく適用されたことを確認します。
$ oc -n my-namespace get deployment myapp --output=jsonpath='{.spec.template.spec.securityContext}' | jq .出力例
{ "seccompProfile": { "localhostProfile": "operator/profile1.json", "type": "localhost" } }
7.6.2.1. ProfileBindings を使用してワークロードをプロファイルにバインドする リンクのコピーリンクがクリップボードにコピーされました!
ProfileBinding リソースを使用して、セキュリティープロファイルをコンテナーの SecurityContext にバインドできます。
手順
quay.io/security-profiles-operator/test-nginx-unprivileged:1.21イメージを使用する Pod をサンプルのSeccompProfileプロファイルにバインドするには、Pod とSeccompProfileオブジェクトと同じ namespace にProfileBindingオブジェクトを作成します。apiVersion: security-profiles-operator.x-k8s.io/v1alpha1 kind: ProfileBinding metadata: namespace: my-namespace name: nginx-binding spec: profileRef: kind: SeccompProfile1 name: profile2 image: quay.io/security-profiles-operator/test-nginx-unprivileged:1.213 次のコマンドを実行して、namespace に
enable-binding=trueのラベルを付けます。$ oc label ns my-namespace spo.x-k8s.io/enable-binding=truetest-pod.yamlという名前の Pod を定義します。apiVersion: v1 kind: Pod metadata: name: test-pod spec: containers: - name: test-container image: quay.io/security-profiles-operator/test-nginx-unprivileged:1.21Pod を作成します。
$ oc create -f test-pod.yaml注記Pod がすでに存在する場合、Pod を再作成しなければバインディングは適切に機能しません。
検証
次のコマンドを実行して、Pod が
ProfileBindingを継承していることを確認します。$ oc get pod test-pod -o jsonpath='{.spec.containers[*].securityContext.seccompProfile}'出力例
{"localhostProfile":"operator/profile.json","type":"Localhost"}