15.4. セキュリティーコンテキスト制約の作成

OpenShift CLI (oc) を使用して SCC (Security Context Constraints) を作成することができます。

前提条件

  • OpenShift CLI (oc) がインストールされている。
  • cluster-admin ロールを持つユーザーとしてクラスターにログインしている。

手順

  1. scc_admin.yaml という名前の YAML ファイルで SCC を定義します。

    SecurityContextConstraints オブジェクト定義

    kind: SecurityContextConstraints
    apiVersion: security.openshift.io/v1
    metadata:
      name: scc-admin
    allowPrivilegedContainer: true
    runAsUser:
      type: RunAsAny
    seLinuxContext:
      type: RunAsAny
    fsGroup:
      type: RunAsAny
    supplementalGroups:
      type: RunAsAny
    users:
    - my-admin-user
    groups:
    - my-admin-group

    オプションとして、requiredDropCapabilities フィールドに必要な値を設定して、SCC の特定の機能を取り除くことができます。指定された機能はコンテナーからドロップされます。すべてのケイパビリティーを破棄するには、ALL を指定します。たとえば、KILL 機能、MKNOD 機能、および SYS_CHROOT 機能のない SCC を作成するには、以下を SCC オブジェクトに追加します。

    requiredDropCapabilities:
    - KILL
    - MKNOD
    - SYS_CHROOT
    注記

    allowedCapabilitiesrequiredDropCapabilities の両方に、機能を追加できません。

    CRI-O は、Docker ドキュメント に記載されている同じ一連の機能の値をサポートし ます。

  2. ファイルを渡して SCC を作成します。

    $ oc create -f scc_admin.yaml

    出力例

    securitycontextconstraints "scc-admin" created

検証

  • SCC が作成されていることを確認します。

    $ oc get scc scc-admin

    出力例

    NAME        PRIV      CAPS      SELINUX    RUNASUSER   FSGROUP    SUPGROUP   PRIORITY   READONLYROOTFS   VOLUMES
    scc-admin   true      []        RunAsAny   RunAsAny    RunAsAny   RunAsAny   <none>     false            [awsElasticBlockStore azureDisk azureFile cephFS cinder configMap downwardAPI emptyDir fc flexVolume flocker gcePersistentDisk gitRepo glusterfs iscsi nfs persistentVolumeClaim photonPersistentDisk quobyte rbd secret vsphere]