7.6.2. Pod への seccomp プロファイルの適用


Pod を作成して、作成したプロファイルの 1 つを適用します。

手順

  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]
  2. 次のコマンドを実行して、seccompProfile.localhostProfile 属性のプロファイルパスを表示します。

    $ oc get seccompprofile profile1 --output wide

    出力例

    NAME       STATUS     AGE   SECCOMPPROFILE.LOCALHOSTPROFILE
    profile1   Installed  14s   operator/profile1.json

  3. 次のコマンドを実行して、localhost プロファイルへのパスを表示します。

    $ oc get sp profile1 --output=jsonpath='{.status.localhostProfile}'

    出力例

    operator/profile1.json

  4. localhostProfile の出力をパッチファイルに適用します。

    spec:
      template:
        spec:
          securityContext:
            seccompProfile:
              type: Localhost
              localhostProfile: operator/profile1.json
  5. 次のコマンドを実行して、プロファイルを他のワークロード (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 にバインドできます。

手順

  1. 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: SeccompProfile 
    1
    
        name: profile 
    2
    
      image: quay.io/security-profiles-operator/test-nginx-unprivileged:1.21 
    3
    1
    kind: 変数はプロファイルの種類を参照します。
    2
    name: 変数は、プロファイルの名前を参照します。
    3
    イメージ属性にワイルドカードを使用する (image: "*") と、デフォルトのセキュリティープロファイルを有効にすることができます。
    重要

    image: "*" ワイルドカード属性を使用すると、すべての新しい Pod が、指定された namespace 内のデフォルトのセキュリティープロファイルにバインドされます。

  2. 次のコマンドを実行して、namespace に enable-binding=true のラベルを付けます。

    $ oc label ns my-namespace spo.x-k8s.io/enable-binding=true
  3. test-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.21
  4. Pod を作成します。

    $ 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"}

Red Hat logoGithubredditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

Red Hat ドキュメントについて

Legal Notice

Theme

© 2026 Red Hat
トップに戻る