question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is Azure App Service ARR Affinity Required to be Enabled?

See original GitHub issue

For my web app, the redirect from Azure AD back to the web app after successful sign-in requires that I enable ARR Affinity on the web app if it is scaled out to more than one instance, otherwise an infinite redirect loop between my web app and Azure AD ensues. I don’t believe this should be a requirement so I’d like to understand what I have misconfigured. There should be no problem with a different backend instance of a web app handling the redirect back from Azure AD and accepting the JWT token.

Which Version of MSAL are you using ? Microsoft.Identity.Client 4.30.0 Microsoft.Identity.Web 1.9.1 Microsoft.Identity.WebUI 1.9.1

Platform netcore 3.1 on Linux Docker container in Azure App Service.

What authentication flow has the issue?

  • Web App
    • Whatever is the default

Is this a new or existing app? This is a new app or experiment

Repro

services.AddMicrosoftIdentityWebAppAuthentication(Configuration);
    "AzureAd": {
        "Instance": "https://login.microsoftonline.com/",
        "Domain": "XXX",
        "TenantId": "XXX",
        "ClientId": "XXX",
        "CallbackPath": "/signin",
        "SignedOutCallbackPath": "/signout"
    },

Web App scaled out to 2 instances, disable ARR Affinity on web app

Expected behavior App redirects to Azure AD to sign-in user, authenticated user is redirected back to web app and can now use app.

Actual behavior

  • App redirects to Azure AD to sign-in user, authenticated user is redirected back to web app.
  • App redirects to Azure AD to sign-in user, authenticated user is redirected back to web app.
  • App redirects to Azure AD to sign-in user, authenticated user is redirected back to web app.
  • … (loop)

Web App scaled out to 2 instances, enable ARR Affinity on web app

Expected and Actual behavior App redirects to Azure AD to sign-in user, authenticated user is redirected back to web app and can now use app.

Web App scaled down to 1 instance, disable ARR Affinity on web app

Expected and Actual behavior App redirects to Azure AD to sign-in user, authenticated user is redirected back to web app and can now use app.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:8

github_iconTop GitHub Comments

1reaction
jmprieurcommented, Apr 27, 2021
1reaction
krispennercommented, Apr 27, 2021

So it seems that the ASP .NET Core data protection (DP) keys are not automatically sync’d across backend App Service instances of the same app. I’m sure this is meant to be automatic, but maybe not for Linux based App Services (containers) but only for Windows based web apps. Anyways, I have added my own encryption key to be shared across instances and it’s hosted in blob storage and secured via key vault. By ensuring the DP key is shared across all instances of the Linux App Service the Open ID Connect message state parameter is being properly decrypted on any backend instance of the web app.

@jmprieur I’d suggest you make note of this in your documentation for anyone trying to use Microsoft.Identity.Web in a scaled out Linux App Service as this is required unless they enable the session affinity cookie on the web app which is not ideal.

services.AddDataProtection()
    .SetApplicationName("MyApp")
    .SetDefaultKeyLifetime(TimeSpan.FromDays(30))
    .PersistKeysToAzureBlobStorage(new Uri("https://mystore.blob.core.windows.net/keyrings/master.xml"), new DefaultAzureCredential())
    .ProtectKeysWithAzureKeyVault(new Uri("https://myvault.vault.azure.net/keys/MasterEncryptionKey"), new DefaultAzureCredential());
Read more comments on GitHub >

github_iconTop Results From Across the Web

Azure App Service - ARR Affinity - Auto-scaling - Stateful ...
Azure WebApps by default have ARR Affinity cookie enabled, this cookie pairs a client request to a specific server. However, Azure Web Apps ......
Read more >
ARR Affinity Azure App Services
ARR cleverly identifies the user by assigning them a special cookie (known as an affinity cookie), which allows the service to choose the ......
Read more >
How does the ARR Affinity Cookie actually do ...
ARR affinity is a good solution for legacy application compatibility as they may not have been designed with load balancing in mind.
Read more >
ARR Affinity in Azure App Service
If ARR Affinity is enabled, the IIS server acting as the load balancer will place a cookie on responses that causes a user...
Read more >
Disable Session affinity cookie (ARR cookie) for Azure web ...
ARR cleverly identifies the user by assigning them a special cookie (known as an affinity cookie), which allows the service to choose the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found