Shibboleth IdP v4を使ってcybozu.comとのSAML認証を設定する

目次

はじめに

Shibbolethは、 学術認証フェデレーション (External link) (学認:GakuNin)で利用している、シングルサインオンを実現するためのソフトウェアです。

Shibbolethを使って、cybozu.comへのシングルサインオンを行うための設定手順を説明します。
cybozu.comとの連携に必要な設定箇所だけを記載しています。
Shibboleth IdPサーバーの構築方法の詳細は、 貴学にてIdPv4をインストールする場合の構築手順(外部サイト) (External link) を参照してください。
cybozu.comのSAML認証は、SP-initiated SSOとして動作します。

動作環境

前提条件

  • ShibbolethではIdP(Identify Provider)の機能を利用し、cybozu.comはSP(Service Provider)として動作します。
  • Shibboleth IdPサーバーの構築、およびユーザー情報を管理するサーバーの構築は、行われているものとします。

検証環境

Shibboleth IdP v4.2.1で動作を確認しています。

事前の準備

手順1:cybozu.com環境の準備

cybozu.com環境を用意します。
環境がない場合は、 サイボウズドットコム ストア (External link) から試用環境を申し込んでください。
「お試しになるサービス」は、任意のサービスを選択してください。

手順2:ログインユーザーの追加

SAML認証でログインするユーザーを追加します。
ユーザーを追加する手順は、 ユーザーを追加する (External link) を参照してください。
例としてログイン名が「user」のユーザーを追加します。

手順3:ServiceProviderメタデータファイルのダウンロード

cybozu.comをSPとしてShibboleth IdPに登録するためのメタデータをダウンロードします。
このファイルは、あとの手順で使用します。

  1. cybozu.comにログインし、[cybozu.com共通管理]を開きます。
  2. 「システム管理」の[ログイン]を開きます。
  3. 「SAML認証を有効にする」のチェックボックスを選択します。
  4. 「Service Providerメタデータのダウンロード」をクリックして、メタデータファイルをダウンロードします。
  5. ファイル名を「cybozu-sp-metadata.xml」に変更します。

Shibboleth IdPでの設定(IdP側)

cybozu.comとの連携するために、Shibbolethの設定ファイルを変更します。

以降、Shibboleth IdPは/opt/shibboleth-idp/以下にインストールされているものとして記載します。
適宜インストールしているディレクトリーに合わせて読み替えてください。

手順1:cybozu.comをSPとして登録する

  1. 事前の準備でダウンロードしたメタデータファイルを、Shibboleth IdPサーバーに配置します。
    配置する場所: /opt/shibboleth-idp/metadata/cybozu-sp-metadata.xml

  2. /opt/shibboleth-idp/conf/metadata-providers.xmlを開きます。

  3. ファイルの末尾に、次の内容を追記して保存します。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    
        <!-- 以下の内容を追記する ここから --> 
        <!-- cybozu.com -->
        <MetadataProvider id="cybozu" xsi:type="FilesystemMetadataProvider"
            xmlns="urn:mace:shibboleth:2.0:metadata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="urn:mace:shibboleth:2.0:metadata http://shibboleth.net/schema/idp/shibboleth-metadata.xsd"
            failFastInitialization="true"
            metadataFile="/opt/shibboleth-idp/metadata/cybozu-sp-metadata.xml"
            maxRefreshDelay="PT48H">
        </MetadataProvider>
        <!-- ここまで --> 
    </MetadataProvider>

手順2:アサーションの暗号化を解除する

Shibboleth IdPでは、すべてのSPに対して送信するアサーションは暗号化されます。
参考: 特定のSPへのアサーションを暗号化しない設定(外部サイト) (External link)

cybozu.comでは、アサーションの暗号化に対応していないため、暗号化を解除します。
また、レスポンスに署名をするためアサーションへの署名も不要です。

  1. /opt/shibboleth-idp/conf/relying-party.xmlを開きます。

  2. <util:list id="shibboleth.RelyingPartyOverrides">要素の中に、次の内容を追記して保存します。
    <bean>要素のc:relyingPartyIdsの値は、連携するcybozu.comのURLに変更してください。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    
            <!-- 以下の内容を追記する ここから -->
            <!-- cybozu.com -->
            <bean parent="RelyingPartyByName"
                  c:relyingPartyIds="https://sample.cybozu.com">
                <property name="profileConfigurations">
                    <list>
                        <bean parent="SAML2.SSO"
                            p:encryptAssertions="false"
                            p:signAssertions="true"
                            p:signResponses="false"
                        />
                    </list>
                </property>
            </bean>
            <!-- ここまで -->
          </util:list>

手順3:NameIDにcybozu.comでユーザーを識別するための要素を入れる

cybozu.comでのSAML認証では、SAML ResponseのNameIDの値がcybozu.comの「ログイン名」と一致する必要があります。
ShibbolethではNameIDとして、ログインのたびに異なるID(transientId)が割り当てられるため、ユーザーを一意に特定できません。
そのため、cybozu.comのログイン名と一致する値をNameIDとして受け渡します。

attribute-filter.xml
  1. /opt/shibboleth-idp/conf/attribute-filter.xmlを開きます。

  2. <AttributeFilterPolicyGroup>要素の中に、次の内容を追記して保存します。
    <PolicyRequirementRule>要素のvalueの値は、連携するcybozu.comのURLに変更してください。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    
         <!-- 以下の内容を追記する ここから -->
         <!-- cybozu.com -->
         <AttributeFilterPolicy id="cybozu">
            <PolicyRequirementRule xsi:type="Requester" value="https://sample.cybozu.com" />
            <!-- cybozu.comのログイン名がユーザーIDの場合 -->
            <AttributeRule attributeID="uid" permitAny="true" />
            <!-- cybozu.comのログイン名がメールアドレスの場合 -->
            <AttributeRule attributeID="mail" permitAny="true" />
        </AttributeFilterPolicy>
        <!-- ここまで -->
saml-nameid.xml
  1. /opt/shibboleth-idp/conf/saml-nameid.xmlを開きます。

  2. <util:list id="shibboleth.SAML2NameIDGenerators">要素の中に、次の内容を追記して保存します。

    • cybozu.comのログイン名にIDを利用する場合

      1
      2
      3
      4
      5
      6
      7
      8
      
      <!-- SAML 2 NameID Generation -->
          <util:list id="shibboleth.SAML2NameIDGenerators">
              <ref bean="shibboleth.SAML2TransientGenerator" />
              <!-- 以下の内容を追記する ここから -->
              <bean parent="shibboleth.SAML2AttributeSourcedGenerator"
              p:format="urn:oasis:names:tc:SAML:1.1:nameid-format:username"
              p:attributeSourceIds="#{ {'uid'} }" />
              <!-- ここまで -->
    • cybozu.comのログイン名にメールアドレスを利用する場合

      1
      2
      3
      4
      5
      6
      7
      8
      
      <!-- SAML 2 NameID Generation -->
          <util:list id="shibboleth.SAML2NameIDGenerators">
              <ref bean="shibboleth.SAML2TransientGenerator" />
              <!-- 以下の内容を追記する ここから -->
              <bean parent="shibboleth.SAML2AttributeSourcedGenerator"
                p:format="urn:oasis:names:tc:SAML:1.1:nameid-format:username"
                p:attributeSourceIds="#{ {'mail'} }" />
              <!-- ここまで -->
relying-party.xml
  1. /opt/shibboleth-idp/conf/relying-party.xmlを開きます。

  2. <util:list id="shibboleth.RelyingPartyOverrides">要素の中に、次の内容を追記して保存します。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    
            <!-- cybozu.com -->
            <bean parent="RelyingPartyByName"
                c:relyingPartyIds="https://sample.cybozu.com">
                <property name="profileConfigurations">
                    <list>
                        <bean parent="SAML2.SSO"
                            p:encryptAssertions="false"
                            p:signAssertions="true"
                            p:signResponses="false"
                            <!-- 以下の内容を追記する ここから -->
                            p:nameIDFormatPrecedence="urn:oasis:names:tc:SAML:1.1:nameid-format:username"
                            <!-- ここまで -->
                        />
                    </list>
                </property>
            </bean>
    
        </util:list>

手順4:Jettyの再起動

Shibboleth IdPの設定を変更したら、Jettyを再起動してください。

1
systemctl restart jetty

手順5:SAMLResponseを確認する

SAMLResponseで、NameIDのテキストがcybozu.comでユーザーを識別するための要素になっていることを確認します。

  1. 次のコマンドを実行します。

    • --principal:cybozu.comと連携するユーザーのアカウント名

    • --requester:cybozu.comのURL

      1
      2
      
      /opt/shibboleth-idp/bin/aacli.sh \
      --principal=user --requester="https://sample.cybozu.com" --saml2
  2. <saml2:Subject>の要素の値が、cybozu.comのログイン名になっていることを確認します。
    次の例では、5〜7行目の<saml2:Subject>の要素の値が、cybozu.comのログイン名「user」になっています。

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    
    <?xml version="1.0" encoding="UTF-8"?>
      <saml2:Assertion xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion" ID="_68614df3778292ff49673274acf8ebc5" IssueInstant="2022-08-22T00:31:18.945Z" Version="2.0">
        <saml2:Issuer>https://IdPのサーバー名/idp/shibboleth</saml2:Issuer>
        <saml2:Subject>
            <saml2:NameID Format="urn:oasis:names:tc:SAML:1.1:nameid-format:username" NameQualifier="https://IdPのサーバー名/idp/shibboleth" SPNameQualifier="https://sample.cybozu.com">
              user
            </saml2:NameID>
        </saml2:Subject>
        <saml2:AttributeStatement>
            <saml2:Attribute FriendlyName="schacHomeOrganization" Name="urn:oid:1.3.6.1.4.1.25178.1.2.9" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri">
                <saml2:AttributeValue>compute-1.amazonaws.com</saml2:AttributeValue>
            </saml2:Attribute>
            <saml2:Attribute FriendlyName="uid" Name="urn:oid:0.9.2342.19200300.100.1.1" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri">
                <saml2:AttributeValue>user</saml2:AttributeValue>
            </saml2:Attribute>
            <saml2:Attribute FriendlyName="mail" Name="urn:oid:0.9.2342.19200300.100.1.3" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri">
                <saml2:AttributeValue>user@example.com</saml2:AttributeValue>
            </saml2:Attribute>
        </saml2:AttributeStatement>
    </saml2:Assertion>

cybozu.comでの設定(SP側)

手順1:公開鍵の証明書ファイルを取得する

Shibboleth IdPのサーバーから、SAMLの署名に利用する公開鍵の証明書ファイルを取得します。
/opt/shibboleth-idp/conf/idp.propertiesidp.signing.certに指定している証明書ファイルです。

手順2:cybozu.comへShibboleth IdPの情報を登録する

Identity Provider(IdP)の情報を設定する手順の詳細は、 STEP2:cybozu.comでSAML認証を設定する (External link) を参照してください。

  1. cybozu.comにログインし、[cybozu.com共通管理]を開きます。
  2. 「システム管理」の[ログイン]を開きます。
  3. 「SAML認証を有効にする」のチェックボックスを選択します。
  4. IdPの情報を入力します。
    • Identity ProviderのSSOエンドポイントURL
      https://IdPのサーバー名/idp/profile/SAML2/Redirect/SSO
    • cybozu.comからのログアウト後に遷移するURL
      cybozu.comからログアウトした後に表示されるIdPのURL
  5. 「証明書を登録する」の[参照]をクリックし、公開鍵の証明書ファイルを指定します。
  6. [保存]をクリックします。

動作確認

SAML認証を使用してcybozu.comにシングルサインオンできることを確認します。
次の操作ができれば完了です。

  • Webブラウザーでcybozu.comにアクセスすると、IdPの認証に成功し、ログイン後の画面が表示される。
  • 正常にログアウトできる。

SAML認証の設定に失敗してcybozu.comにログインできなくなった場合には、 SAML認証を回避するURL (External link) からcybozu.comにログインして、SAML認証の設定を見直してください。

information

このTips 2022年11月版cybozu.comおよびShibboleth IdP v4.2.1で確認した内容です。