クイック スタート: Azure Spring Apps Enterprise プランを使用してアプリケーションのシングル サインオンを構成する

注意

Azure Spring Apps は、Azure Spring Cloud サービスの新しい名前です。 サービスの名前は新しくなりましたが、スクリーンショット、ビデオ、図などの資産の更新に取り組んでいる間、場所によってはしばらく古い名前が表示されます。

この記事の適用対象:❌ Basic または Standard ✔️ Enterprise

このクイック スタートでは、Azure Spring Apps Enterprise プランで実行されているアプリケーションのシングル サインオンを構成する方法について説明します。

前提条件

シングル サインオン資格情報を準備する

アプリケーションのシングル サインオンを構成するには、資格情報を準備する必要があります。 以降のセクションでは、既存のプロバイダーを使用する手順、または Microsoft Entra ID を使用したアプリケーション登録のプロビジョニング手順について説明します。

既存のプロバイダーを使用する

既存の ID プロバイダーを使用してシングル サインオンを構成するには、次の手順に従います。 Microsoft Entra アプリの登録をプロビジョニングする場合は、次のセクション「Microsoft Entra ID を使用してアプリケーション登録を作成して構成する」に進んでください。

  1. Spring Cloud Gateway for VMware Tanzu と API portal for VMware Tanzu へのリダイレクトを許可するように既存の ID プロバイダーを構成します。 Spring Cloud Gateway には、ゲートウェイへの再エントリを許可する単一の URI があります。 API portal には、ユーザー インターフェイスと基になる API をサポートするための 2 つの URI があります。 次のコマンドでは、シングル サインオン プロバイダーの構成に追加するこれらの URI を取得します。

    export GATEWAY_URL=$(az spring gateway show \
        --resource-group <resource-group-name> \
        --service <Azure-Spring-Apps-service-instance-name> | jq -r '.properties.url')
    
    export PORTAL_URL=$(az spring api-portal show \
        --resource-group <resource-group-name> \
        --service <Azure-Spring-Apps-service-instance-name> | jq -r '.properties.url')
    
    echo "https://${GATEWAY_URL}/login/oauth2/code/sso"
    echo "https://${PORTAL_URL}/oauth2-redirect.html"
    echo "https://${PORTAL_URL}/login/oauth2/code/sso"
    
  2. ID プロバイダーの Client IDClient Secret を取得します。

  3. ID プロバイダーの Issuer URI を取得します。 発行者 URI (発行者識別子としてアサートされる URI) を使用してプロバイダーを構成する必要があります。 たとえば、指定された issuer-urihttps://example.com の場合、OpenID プロバイダー構成要求は https://example.com/.well-known/openid-configuration に対して行われます。 結果は OpenID プロバイダー構成応答である必要があります。

    注意

    OpenID Connect 検出プロトコルをサポートする承認サーバーのみを使用できます。

  4. 後で使用するために、ID プロバイダーの JWK URI を取得します。 JWK URI の形式は通常、${ISSUER_URI}/keys または ${ISSUER_URI}/<version>/keys になります。 ID サービス アプリケーションでは、パブリック JSON Web Key (JWK) を使用して、シングル サインオン ID プロバイダーの承認サーバーによって発行された JSON Web Token (JWT) を検証します。

Microsoft Entra ID を使用してアプリケーション登録を作成して構成する

アプリケーションを Microsoft Entra ID に登録するには、次の手順に従います。 既存のプロバイダーの資格情報を使用している場合は、次のセクション「ID サービス アプリケーションをデプロイする」に進んでください。

  1. 次のコマンドを使用して、Microsoft Entra ID でアプリケーションの登録を作成し、出力を保存します。

    az ad app create --display-name <app-registration-name> > ad.json
    
  2. 次のコマンドを使用して、アプリケーション ID を取得し、クライアント シークレットを収集します。

    export APPLICATION_ID=$(cat ad.json | jq -r '.appId')
    az ad app credential reset --id ${APPLICATION_ID} --append > sso.json
    
  3. 次のコマンドを使用して、アプリケーションの登録にサービス プリンシパルを割り当てます。

    az ad sp create --id ${APPLICATION_ID}
    
  4. 次のコマンドを使用して、Spring Cloud Gateway と API portal の URL を取得し、必要な応答 URL を Active Directory アプリ登録に追加します。

    export APPLICATION_ID=$(cat ad.json | jq -r '.appId')
    
    export GATEWAY_URL=$(az spring gateway show \
        --resource-group <resource-group-name> \
        --service <Azure-Spring-Apps-service-instance-name> | jq -r '.properties.url')
    
    export PORTAL_URL=$(az spring api-portal show \
        --resource-group <resource-group-name> \
        --service <Azure-Spring-Apps-service-instance-name> | jq -r '.properties.url')
    
    az ad app update \
        --id ${APPLICATION_ID} \
        --web-redirect-uris "https://${GATEWAY_URL}/login/oauth2/code/sso" "https://${PORTAL_URL}/oauth2-redirect.html" "https://${PORTAL_URL}/login/oauth2/code/sso"
    
  5. 次のコマンドを使用して、アプリケーションの Client ID を取得します。 出力を保存して、後でこのクイックスタートの中で使用します。

    cat sso.json | jq -r '.appId'
    
  6. 次のコマンドを使用して、アプリケーションの Client Secret を取得します。 出力を保存して、後でこのクイックスタートの中で使用します。

    cat sso.json | jq -r '.password'
    
  7. 次のコマンドを実行して、Issuer URI を取得します。 出力を保存して、後でこのクイックスタートの中で使用します。

    export TENANT_ID=$(cat sso.json | jq -r '.tenant')
    echo "https://login.microsoftonline.com/${TENANT_ID}/v2.0"
    
  8. 次のコマンドの出力から JWK URI を取得します。 ID サービス アプリケーションは、パブリック JSON Web Key (JWK) を使用して、Active Directory によって発行された JSON Web Token (JWT) を検証します。

    export TENANT_ID=$(cat sso.json | jq -r '.tenant')
    echo "https://login.microsoftonline.com/${TENANT_ID}/discovery/v2.0/keys"
    

ID サービス アプリケーションをデプロイする

シングル サインオン エクスペリエンスを完了するには、次の手順を使用して ID サービス アプリケーションをデプロイします。 ID サービス アプリケーションは、ユーザーの識別に役立つ 1 つのルートを提供します。

  1. プロジェクト フォルダーに移動します。

  2. 次のコマンドを使用して identity-service アプリケーションを作成します。

    az spring app create \
        --resource-group <resource-group-name> \
        --name identity-service \
        --service <Azure-Spring-Apps-service-instance-name>
    
  3. 次のコマンドを使用を使用して、アプリケーション構成サービスにバインドすることで、ID サービスの外部化された構成を有効にします。

    az spring application-configuration-service bind \
        --resource-group <resource-group-name> \
        --app identity-service \
        --service <Azure-Spring-Apps-service-instance-name>
    
  4. 次のコマンドを使用して、サービス レジストリにバインドすることで、ID サービスのサービス検出と登録を有効にします。

    az spring service-registry bind \
        --resource-group <resource-group-name> \
        --app identity-service \
        --service <Azure-Spring-Apps-service-instance-name>
    
  5. 次のコマンドを使用して、ID サービスをデプロイします。

    az spring app deploy \
        --resource-group <resource-group-name> \
        --name identity-service \
        --service <Azure-Spring-Apps-service-instance-name> \
        --config-file-pattern identity/default \
        --source-path apps/acme-identity \
        --build-env BP_JVM_VERSION=17 \
        --env "JWK_URI=<jwk-uri>"
    
  6. 次のコマンドを使用して、ID サービスに要求をルーティングします。

    az spring gateway route-config create \
        --resource-group <resource-group-name> \
        --name identity-routes \
        --service <Azure-Spring-Apps-service-instance-name> \
        --app-name identity-service \
        --routes-file azure-spring-apps-enterprise/resources/json/routes/identity-service.json
    

Spring Cloud Gateway のシングル サインオンを構成する

シングル サインオンを使用して要求を認証するように Spring Cloud Gateway を構成できます。 シングル サインオンを使用するように Spring Cloud Gateway を構成するには、次の手順に従います。

  1. 次のコマンドを使用して、シングル サインオンを使用するように Spring Cloud Gateway を構成します。

    export GATEWAY_URL=$(az spring gateway show \
        --resource-group <resource-group-name> \
        --service <Azure-Spring-Apps-service-instance-name> | jq -r '.properties.url')
    
    az spring gateway update \
        --resource-group <resource-group-name> \
        --service <Azure-Spring-Apps-service-instance-name> \
        --api-description "Fitness Store API" \
        --api-title "Fitness Store" \
        --api-version "v1.0" \
        --server-url "https://${GATEWAY_URL}" \
        --allowed-origins "*" \
        --client-id <client-id> \
        --client-secret <client-secret> \
        --scope "openid,profile" \
        --issuer-uri <issuer-uri>
    
  2. 認証に Spring Cloud Gateway を使用するようにカート サービス アプリケーションに指示します。 次のコマンドを使用して、必要な環境変数を指定します。

    az spring app update \
        --resource-group <resource-group-name> \
        --name cart-service \
        --service <Azure-Spring-Apps-service-instance-name> \
        --env "AUTH_URL=https://${GATEWAY_URL}" "CART_PORT=8080"
    
  3. 認証に Spring Cloud Gateway を使用するようにオーダー サービス アプリケーションに指示します。 次のコマンドを使用して、必要な環境変数を指定します。

    az spring app update \
        --resource-group <resource-group-name> \
        --name order-service \
        --service <Azure-Spring-Apps-service-instance-name> \
        --env "AcmeServiceSettings__AuthUrl=https://${GATEWAY_URL}"
    
  4. 次のコマンドを使用して、Spring Cloud Gateway の URL を取得します。

    echo "https://${GATEWAY_URL}"
    

    ブラウザーで出力 URL を開いて、更新されたアプリケーションを探索できます。 これでログイン機能が機能するようになり、カートにアイテムを追加して注文することができます。 サインインすると、顧客情報ボタンに、サインインしたユーザー名が表示されます。

API portal のシングル サインオンを構成する

API を探索する前に、シングル サインオンを使用して認証を要求するように API portal for VMware Tanzu を構成できます。 次のコマンドを使用して、API portal のシングル サインオンを構成します。

export PORTAL_URL=$(az spring api-portal show \
    --resource-group <resource-group-name> \
    --service <Azure-Spring-Apps-service-instance-name> | jq -r '.properties.url')

az spring api-portal update \
    --resource-group <resource-group-name> \
    --service <Azure-Spring-Apps-service-instance-name> \
    --client-id <client-id> \
    --client-secret <client-secret> \
    --scope "openid,profile,email" \
    --issuer-uri <issuer-uri>

次のコマンドを使用して、API portal の URL を取得します。

export PORTAL_URL=$(az spring api-portal show \
    --resource-group <resource-group-name> \
    --service <Azure-Spring-Apps-service-instance-name> | jq -r '.properties.url')

echo "https://${PORTAL_URL}"

ブラウザーで出力 URL を開いて、アプリケーション API を探索できます。 API を探索する前にサインオンするように指示されます。


リソースをクリーンアップする

後続のクイック スタートおよびチュートリアルを引き続き実行する場合は、これらのリソースをそのまま残しておくことができます。 不要になったら、リソース グループを削除します。これにより、リソース グループ内のリソースが削除されます。 Azure CLI を使用してリソース グループを削除するには、次のコマンドを使用します。

echo "Enter the Resource Group name:" &&
read resourceGroupName &&
az group delete --name $resourceGroupName &&
echo "Press [ENTER] to continue ..."

次のステップ

次の省略可能なクイックスタートのいずれかに進んでください。