7.7.2.3. コントローラーと SecurityContextConstraints の複製


デプロイメントやデーモンセットなど、コントローラーをレプリケートするための SELinux ポリシーをデプロイする場合、コントローラーによって生成された Pod オブジェクトは、ワークロードを作成するユーザーの ID で実行されないことに注意してください。ServiceAccount が選択されていない場合、Pod は、カスタムセキュリティーポリシーの使用を許可しない、制限された SecurityContextConstraints (SCC) の使用に戻る可能性があります。

手順

  1. 次のコマンドを実行してプロジェクトを作成します。

    $ oc new-project nginx-secure
  2. 次の RoleBinding オブジェクトを作成して、SELinux ポリシーを nginx-secure namespace で使用できるようにします。

    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.io
  3. Role オブジェクトを作成します。

    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:
      - use
  4. ServiceAccount オブジェクトを作成します。

    apiVersion: v1
    kind: ServiceAccount
    metadata:
      creationTimestamp: null
      name: spo-deploy-test
      namespace: nginx-secure
  5. Deployment オブジェクトを作成します。

    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.process 
    1
    
          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 が、正しいサービスアカウントのみで使用できることを確認してください。詳細は、その他のリソース を参照してください。

Red Hat logoGithubredditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

会社概要

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

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

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

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

Legal Notice

Theme

© 2026 Red Hat
トップに戻る