スキップしてコンテンツを表示

Amazon Cognito と外部 SAML ID プロバイダーの統合と構成を安全に実施する方法を教えてください。

所要時間2分
0

Amazon Cognito ユーザープールにおいて、外部 SAML ID プロバイダー (IdP) の暗号化 SAML アサーションを使用する設定を行いたいと考えています。この方法で、アプリケーションのユーザー認証を安全に行えるようにしたいです。

解決策

SAML IdP をユーザープールに追加する

Amazon Cognito ユーザープールがない場合は、「ユーザープールの開始方法」を参照してください。ユーザープールの作成後、IdP 側で SAML アプリケーションを構成します。Amazon Cognito ユーザープールに SAML IdP を追加する方法については、「ユーザープールに SAML ID プロバイダーを追加し、管理する」を参照してください。

暗号化 SAML アサーションを Amazon Cognito に送信するために、暗号化証明書を SAML IdP に提供する

まず、Amazon Cognito コンソールで暗号化証明書をダウンロードします。次に、SAML IdP の構成インターフェイスで暗号化証明書をインポートします。暗号化証明書をインポートして有効化する方法については、使用する IdP のマニュアルを参照してください。たとえば、Microsoft Learn のウェブサイトでは、「Microsoft Entra の SAML トークン暗号化を構成する」を参照します。

暗号化 SAML アサーションフローを確認する

次の手順を実行します。

  1. ブラウザの開発者ツールを開き、HTTP Archive (HAR) ファイルを作成します。
  2. Amazon Cognito ユーザープールのマネージドログインページに移動します。
  3. [SAML IdP] を選択します。Amazon Cognito は、ユーザーを IdP のサインインページにリダイレクトします。
  4. IdP が saml2/idpresponse エンドポイントに送信した SAML アサーションリクエストを HAR ファイルから取得します。
  5. HAR ファイルの SAML アサーション応答をブラウザで表示します。

暗号化された SAML アサーションを含む、デコードされた SAML 応答の例:

<saml:EncryptedAssertion>
    <xenc:EncryptedData
        xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"
        Type="http://www.w3.org/2001/04/xmlenc#Element">
        <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc"/>
        <ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
            <xenc:EncryptedKey>
                <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p"/>
                <xenc:CipherData>
                    <xenc:CipherValue>
                        <!-- Encrypted key data -->
                        hY7PK8L9eM+2Uw7....[abbreviated]....4nmB2gTfLwqX=
                    </xenc:CipherValue>
                </xenc:CipherData>
            </xenc:EncryptedKey>
        </ds:KeyInfo>
        <xenc:CipherData>
            <xenc:CipherValue>
                <!-- Encrypted assertion data -->
                kB4urcHh7K5HHJ....[abbreviated]....8JpWGpfTj=
            </xenc:CipherValue>
        </xenc:CipherData>
    </xenc:EncryptedData>
</saml:EncryptedAssertion>

デコードされた非暗号化 SAML 応答の例:

<saml:Assertion
    ID="ASRT#########"
    Version="2.0"
    IssueInstant="2024-07-10T10:00:00Z">

    <saml:Issuer>https://idp.example.com/saml</saml:Issuer>

    <saml:Subject>
        <saml:NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:transient">
            USER123456789
        </saml:NameID>
        <saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
            <saml:SubjectConfirmationData
                NotOnOrAfter="2024-07-10T11:00:00Z"
                Recipient="https://app.example.com/saml/acs"/>
        </saml:SubjectConfirmation>
    </saml:Subject>

    <saml:Conditions
        NotBefore="2024-07-10T10:00:00Z"
        NotOnOrAfter="2024-07-10T11:00:00Z">
        <saml:AudienceRestriction>
            <saml:Audience>https://app.example.com/saml</saml:Audience>
        </saml:AudienceRestriction>
    </saml:Conditions>

    <saml:AuthnStatement
        AuthnInstant="2024-07-10T10:00:00Z"
        SessionNotOnOrAfter="2024-07-10T18:00:00Z"
        SessionIndex="SESSION123456789">
        <saml:AuthnContext>
            <saml:AuthnContextClassRef>
                urn:oasis:names:tc:SAML:2.0:ac:classes:Password
            </saml:AuthnContextClassRef>
        </saml:AuthnContext>
    </saml:AuthnStatement>

    <saml:AttributeStatement>
        <saml:Attribute Name="uid"
            NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">
            <saml:AttributeValue>user123</saml:AttributeValue>
        </saml:Attribute>
        <saml:Attribute Name="email"
            NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">
            <saml:AttributeValue>user@example.com</saml:AttributeValue>
        </saml:Attribute>
        <saml:Attribute Name="roles"
            NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">
            <saml:AttributeValue>user</saml:AttributeValue>
            <saml:AttributeValue>admin</saml:AttributeValue>
        </saml:Attribute>
    </saml:AttributeStatement>
</saml:Assertion>

注: 応答の saml:EncryptedAssertion は、暗号化 SAML アサーションが存在することを示します。使用する IdP のみが、適切なプライベートキーを利用するとコンテンツを復号し、読み取ることができます。saml:EncryptedAssertion が応答に含まれていない場合は、SAML アサーションは暗号化されておらず、ユーザーと認証の詳細はクリアテキストで表示されます。

関連情報

ユーザープールで SAML ID プロバイダーを使用する

Azure AD を使用してフェデレーション認証に Amazon Cognito を設定する方法

認証の応答に SAML アサーションを構成する

AWS公式更新しました 2ヶ月前
コメントはありません

関連するコンテンツ