Red Hat Training

A Red Hat training course is available for OpenShift Container Platform

第14章 LDAP フェイルオーバーの設定

OpenShift Container Platform は Lightweight Directory Access Protocol (LDAP) セットアップで使用するための 認証プロバイダーを提供しますが、接続できるのは単一の LDAP サーバーのみです。OpenShift Container Platform インストール時に、LDAP フェイルオーバーの System Security Services Daemon (SSSD) を設定し、ある LDAP サーバーが失敗した場合にクラスターにアクセスできるようにします。

この設定には、詳細な設定および通信先となる OpenShift Container Platform の認証サーバー (リモート Basic 認証サーバー とも呼ばれます) が別途必要となります。メールアドレスなどの追加の属性を OpenShift Container Platform に渡すようにこのサーバーを設定し、それらの属性を Web コンソールで表示できるようにします。

このトピックでは、専用の物理または仮想マシン (VM) のセットアップを完了する方法や、コンテナーでの SSSD の設定方法についても説明します。

重要

このトピックのすべてのセクションを完了する必要があります。

14.1. 基本リモート認証の前提条件

  • セットアップを始める前に、LDAP サーバーの以下の情報について知っておく必要があります。

    • ディレクトリーサーバーが FreeIPA、Active Directory、または別の LDAP ソリューションでサポートされているかどうか。
    • LDAP サーバーの Uniform Resource Identifier (URI) (例: ldap.example.com)。
    • LDAP サーバーの CA 証明書の場所。
    • LDAP サーバーがユーザーグループの RFC 2307 または RFC2307bis に対応しているかどうか。
  • サーバーを準備します。

    • remote-basic.example.com: リモート基本認証サーバーとして使用する VM。

      • Red Hat Enterprise Linux 7.0 以降などの、このサーバーの SSSD バージョン 1.12.0 を含むオペレーティングシステムを選択します。
    • openshift.example.com: OpenShift Container Platform の新規インストール。

      • 認証方法をこのクラスターに設定することはできません。
      • このクラスターで OpenShift Container Platform を起動することはできません。

14.2. 証明書の生成およびリモート Basic 認証サーバーとの共有

Ansible ホストインベントリーファイル (デフォルトは /etc/ansible/hosts) に一覧表示された 1 つ目のマスターホストで以下の手順を実行します。

  1. リモート Basic 認証サーバーと OpenShift Container Platform 間の通信に新異性をもたせるために、このセットアップの他のフェーズで使用する Transport Layer Security (TLS) 証明書のセットを作成します。以下のコマンドを実行します。

    # openshift start \
        --public-master=https://openshift.example.com:8443 \
        --write-config=/etc/origin/

    出力には、/etc/origin/master/ca.crt および /etc/origin/master/ca.key の署名用証明書が含まれます。

  2. 署名用証明書を使用してリモート Basic 認証サーバーで使用するキーを生成します。

    # mkdir -p /etc/origin/remote-basic/
    # oc adm ca create-server-cert \
        --cert='/etc/origin/remote-basic/remote-basic.example.com.crt' \
        --key='/etc/origin/remote-basic/remote-basic.example.com.key' \
        --hostnames=remote-basic.example.com \ 1
        --signer-cert='/etc/origin/master/ca.crt' \
        --signer-key='/etc/origin/master/ca.key' \
        --signer-serial='/etc/origin/master/ca.serial.txt'
    1
    リモート Basic 認証サーバーにアクセスする必要のある、すべてのホスト名およびインターネット IP アドレスのコンマ区切りの一覧です。
    注記

    生成する証明書ファイルは 2 年間有効です。この期間は、--expire-days および --signer-expire-days の値を変更して変更することができますが、セキュリティー上の理由により、730 より大きな値を設定しないでください。

    重要

    リモート Basic 認証サーバーにアクセスする必要のあるすべてのホスト名およびインターフェース IP アドレスを一覧表示しない場合、HTTPS 接続は失敗します。

  3. 必要な証明書およびキーをリモート Basic 認証サーバーにコピーします。

    # scp /etc/origin/master/ca.crt \
          root@remote-basic.example.com:/etc/pki/CA/certs/
    
    # scp /etc/origin/remote-basic/remote-basic.example.com.crt \
          root@remote-basic.example.com:/etc/pki/tls/certs/
    
    # scp /etc/origin/remote-basic/remote-basic.example.com.key \
          root@remote-basic.example.com:/etc/pki/tls/private/

14.3. SSSD での LDAP フェイルオーバーの設定

リモート Basic 認証サーバーで以下の手順を実行します。

メールアドレスおよび表示名などの属性を取得し、それらを OpenShift Container Platform に渡して Web インターフェースに表示することができるように SSSD を設定します。以下の手順では、メールアドレスを OpenShift Container Platform に指定するように SSSD を設定します。

  1. 必要な SSSD および Web サーバーコンポーネントをインストールします。

    # yum install -y sssd \
                     sssd-dbus \
                     realmd \
                     httpd \
                     mod_session \
                     mod_ssl \
                     mod_lookup_identity \
                     mod_authnz_pam \
                     php \
                     mod_php
  2. LDAP サーバーに対してこの VM を認証するように SSSD を設定します。LDAP サーバーが FreeIPA または Active Directory 環境の場合、realmd を使用してこのマシンをドメインに参加させることができます。

    # realm join ldap.example.com

    より高度なケースの場合は、『システムレベル認証ガイド』を参照してください。

  3. SSSD を使用して LDAP のフェイルオーバーの状態を使用するには、ldap_uri 行の /etc/sssd/sssd.conf ファイルにその他のエントリーを追加します。FreeIPA に登録されたシステムは DNS SRV レコードを使用してフェイルオーバーを自動的に処理します。
  4. /etc/sssd/sssd.conf ファイルの [domain/DOMAINNAME] セクションを変更し、この属性を追加します。

    [domain/example.com]
    ...
    ldap_user_extra_attrs = mail 1
    1
    LDAP ソリューションのメールアドレスを取得するために正しい属性を指定します。IPA については、mail を指定します。他の LDAP ソリューションは email などの別の属性を使用する可能性があります。
  5. /etc/sssd/sssd.conf ファイルの domain パラメーターには [domain/DOMAINNAME] セクションに一覧表示されているドメイン名のみが含まれていることを確認します。

    domains = example.com
  6. メール属性を取得するために Apache パーミッションを付与します。以下の行を /etc/sssd/sssd.conf ファイルの [ifp] セクションに追加します。

    [ifp]
    user_attributes = +mail
    allowed_uids = apache, root
  7. すべての変更が適切に適用されていることを確認するには、SSSD を再起動します。

    $ systemctl restart sssd.service
  8. ユーザー情報が適切に取得できるかどうかをテストします。

    $ getent passwd <username>
    username:*:12345:12345:Example User:/home/username:/usr/bin/bash
  9. 指定したメール属性がドメインからメールアドレスを返すことを確認します。

    # dbus-send --print-reply --system --dest=org.freedesktop.sssd.infopipe \
        /org/freedesktop/sssd/infopipe org.freedesktop.sssd.infopipe.GetUserAttr \
        string:username \ 1
        array:string:mail 2
    
    method return time=1528091855.672691 sender=:1.2787 -> destination=:1.2795 serial=13 reply_serial=2
       array [
          dict entry(
             string "mail"
             variant             array [
                   string "username@example.com"
                ]
          )
       ]
    1
    LDAP ソリューションにユーザー名を指定します。
    2
    設定した属性を指定します。
  10. LDAP ユーザーとしての VM へのログインを試行し、LDAP 認証情報を使用してログインできることを確認します。ログインにはローカルコンソールまたは SSH などのリモートサービスを使用できます。
重要

デフォルトで、すべてのユーザーは LDAP 認証情報を使用してリモート Basic 認証サーバーにログインできます。この動作は変更することができます。

14.4. Apache での SSSD の使用の設定

  1. 以下の内容を含む /etc/pam.d/openshift ファイルを作成します。

    auth required pam_sss.so
    account required pam_sss.so

    この設定により、認証要求が openshift スタックに対して発行された時に PAM (プラグ可能な認証モジュール) は pam_sss.so を使用して認証とアクセス制御を決定できるようになります。

  2. /etc/httpd/conf.modules.d/55-authnz_pam.conf ファイルを編集して、以下の行のコメントを解除します。

    LoadModule authnz_pam_module modules/mod_authnz_pam.so
  3. Apache httpd.conf ファイルをリモート基本認証用に設定するには、openshift-remote-basic-auth.conf ファイルを /etc/httpd/conf.d ディレクトリーに作成します。以下のテンプレートを使用して必要な設定および値を指定します。

    重要

    テンプレートの詳細を確認し、その内容を環境に合うようにカスタマイズします。

    LoadModule request_module modules/mod_request.so
    LoadModule php7_module modules/libphp7.so
    
    # Nothing needs to be served over HTTP.  This virtual host simply redirects to
    # HTTPS.
    <VirtualHost *:80>
      DocumentRoot /var/www/html
      RewriteEngine              On
      RewriteRule     ^(.*)$     https://%{HTTP_HOST}$1 [R,L]
    </VirtualHost>
    
    <VirtualHost *:443>
      # This needs to match the certificates you generated.  See the CN and X509v3
      # Subject Alternative Name in the output of:
      # openssl x509 -text -in /etc/pki/tls/certs/remote-basic.example.com.crt
      ServerName remote-basic.example.com
    
      DocumentRoot /var/www/html
    
      # Secure all connections with TLS
      SSLEngine on
      SSLCertificateFile /etc/pki/tls/certs/remote-basic.example.com.crt
      SSLCertificateKeyFile /etc/pki/tls/private/remote-basic.example.com.key
      SSLCACertificateFile /etc/pki/CA/certs/ca.crt
    
      # Require that TLS clients provide a valid certificate
      SSLVerifyClient require
      SSLVerifyDepth 10
    
      # Other SSL options that may be useful
      # SSLCertificateChainFile ...
      # SSLCARevocationFile ...
    
      # Send logs to a specific location to make them easier to find
      ErrorLog logs/remote_basic_error_log
      TransferLog logs/remote_basic_access_log
      LogLevel warn
    
      # PHP script that turns the Apache REMOTE_USER env var
      # into a JSON formatted response that OpenShift understands
      <Location /check_user.php>
        # all requests not using SSL are denied
        SSLRequireSSL
        # denies access when SSLRequireSSL is applied
        SSLOptions +StrictRequire
        # Require both a valid basic auth user (so REMOTE_USER is always set)
        # and that the CN of the TLS client matches that of the OpenShift master
        <RequireAll>
          Require valid-user
          Require expr %{SSL_CLIENT_S_DN_CN} == 'system:openshift-master'
        </RequireAll>
        # Use basic auth since OpenShift will call this endpoint with a basic challenge
        AuthType Basic
        AuthName openshift
        AuthBasicProvider PAM
        AuthPAMService openshift
    
        # Store attributes in environment variables. Specify the email attribute that
        # you confirmed.
        LookupOutput Env
        LookupUserAttr mail REMOTE_USER_MAIL
        LookupUserGECOS REMOTE_USER_DISPLAY_NAME
    
        # Other options that might be useful
    
        # While REMOTE_USER is used as the sub field and serves as the immutable ID,
        # REMOTE_USER_PREFERRED_USERNAME could be used to have a different username
        # LookupUserAttr <attr_name> REMOTE_USER_PREFERRED_USERNAME
    
        # Group support may be added in a future release
        # LookupUserGroupsIter REMOTE_USER_GROUP
      </Location>
    
      # Deny everything else
      <Location ~ "^((?!\/check_user\.php).)*$">
          Deny from all
      </Location>
    </VirtualHost>
  4. check_user.php スクリプトを /var/www/html ディレクトリーに作成します。以下のコードを組み込みます。

    <?php
    // Get the user based on the Apache var, this should always be
    // set because we 'Require valid-user' in the configuration
    $user = apache_getenv('REMOTE_USER');
    
    // However, we assume it may not be set and
    // build an error response by default
    $data = array(
        'error' => 'remote PAM authentication failed'
    );
    
    // Build a success response if we have a user
    if (!empty($user)) {
        $data = array(
            'sub' => $user
        );
        // Map of optional environment variables to optional JSON fields
        $env_map = array(
            'REMOTE_USER_MAIL' => 'email',
            'REMOTE_USER_DISPLAY_NAME' => 'name',
            'REMOTE_USER_PREFERRED_USERNAME' => 'preferred_username'
        );
    
        // Add all non-empty environment variables to JSON data
        foreach ($env_map as $env_name => $json_name) {
            $env_data = apache_getenv($env_name);
            if (!empty($env_data)) {
                $data[$json_name] = $env_data;
            }
        }
    }
    
    // We always output JSON from this script
    header('Content-Type: application/json', true);
    
    // Write the response as JSON
    echo json_encode($data);
    ?>
  5. Apache がモジュールを読み込めるようにします。/etc/httpd/conf.modules.d/55-lookup_identity.conf ファイルを変更し、以下の行のコメントを解除します。

    LoadModule lookup_identity_module modules/mod_lookup_identity.so
  6. SELinux ブール値を設定し、SElinux が Apache が D-BUS を介して SSSD に接続することを許可するようにします。

    # setsebool -P httpd_dbus_sssd on
  7. SELinux に Apache による PAM サブシステムへの問い合わせを受け入れることを指示するブール値を設定します。

    # setsebool -P allow_httpd_mod_auth_pam on
  8. Apache を起動します。

    # systemctl start httpd.service

14.5. OpenShift Container Platform が SSSD を基本リモート認証サーバーとして使用する設定

作成した新規のアイデンティティープロバイダーのデフォルト設定を変更します。Ansible ホストインベンリーファイルに一覧表示される最初のマスターホストで以下の手順を実行します。

  1. /etc/origin/master/master-config.yaml ファイルを開きます。
  2. identityProviders セクションの場所を見つけ、これを以下のコードに置き換えます。

      identityProviders:
      - name: sssd
        challenge: true
        login: true
        mappingMethod: claim
        provider:
          apiVersion: v1
          kind: BasicAuthPasswordIdentityProvider
          url: https://remote-basic.example.com/check_user.php
          ca: /etc/origin/master/ca.crt
          certFile: /etc/origin/master/openshift-master.crt
          keyFile: /etc/origin/master/openshift-master.key
  3. 更新された設定を使って OpenShift Container Platform を起動します。

    # openshift start \
        --public-master=https://openshift.example.com:8443 \
        --master-config=/etc/origin/master/master-config.yaml \
        --node-config=/etc/origin/node-node1.example.com/node-config.yaml
  4. oc CLI を使用してログインをテストします。

    oc login https://openshift.example.com:8443

    有効な LDAP 認証情報のみを使用してログインすることができます。

  5. アイデンティティーを一覧表示し、各ユーザー名のメールアドレスが表示されていることを確認します。以下のコマンドを実行します。

    $ oc get identity -o yaml