<h3 dir="auto">Description</h3>
<p dir="auto">Docker hub supports multi arch images. It would be good if the Airflow image could be updated to support arm64 as well to let it run in the latest Mac M1's</p>
<h3 dir="auto">Use case/motivation</h3>
<p dir="auto">M1 Mac's are becoming more popular for development, the current amd based image run slowly due to emulation.</p>
<h3 dir="auto">Related issues</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Are you willing to submit a PR?</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> Yes I am willing to submit a PR!</li>
</ul>
<h3 dir="auto">Code of Conduct</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I agree to follow this project's <a href="https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md">Code of Conduct</a></li>
</ul>
<h3 dir="auto">Apache Airflow version</h3>
<p dir="auto">2.4.3</p>
<h3 dir="auto">What happened</h3>
<p dir="auto">We just upgraded from Airflow 2.2.5 to 2.4.3. When using Azure OAuth, whenever you load the webserver, it loads it with an error and in a weird looking format:<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/118911990/204397885-b60f951e-d57c-4daa-b8bb-b468ed183852.png"><img src="https://user-images.githubusercontent.com/118911990/204397885-b60f951e-d57c-4daa-b8bb-b468ed183852.png" alt="image" style="max-width: 100%;"></a></p>
<p dir="auto">It loads it in a weird different format every time you hit the refresh button, and has the same error every time (full logs down below):</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="airflow-web sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint &quot;session_session_id_key&quot;
airflow-web DETAIL: Key (session_id)=(7582aee0-4289-4152-99d2-918c98ff64d6) already exists.
airflow-web
airflow-web [SQL: INSERT INTO session (session_id, data, expiry) VALUES (%(session_id)s, %(data)s, %(expiry)s) RETURNING session.id]
airflow-web [parameters: {'session_id': '7582aee0-4289-4152-99d2-918c98ff64d6', 'data': &lt;psycopg2.extensions.Binary object at 0x7fbd53ad71b0&gt;, 'expiry': datetime.datetime(2022, 11, 23, 16, 5, 59, 467562, tzinfo=datetime.timezone.utc)}]
airflow-web (Background on this error at: https://sqlalche.me/e/14/gkpj)
airflow-web"><pre class="notranslate"><code class="notranslate">airflow-web sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "session_session_id_key"
airflow-web DETAIL: Key (session_id)=(7582aee0-4289-4152-99d2-918c98ff64d6) already exists.
airflow-web
airflow-web [SQL: INSERT INTO session (session_id, data, expiry) VALUES (%(session_id)s, %(data)s, %(expiry)s) RETURNING session.id]
airflow-web [parameters: {'session_id': '7582aee0-4289-4152-99d2-918c98ff64d6', 'data': &lt;psycopg2.extensions.Binary object at 0x7fbd53ad71b0&gt;, 'expiry': datetime.datetime(2022, 11, 23, 16, 5, 59, 467562, tzinfo=datetime.timezone.utc)}]
airflow-web (Background on this error at: https://sqlalche.me/e/14/gkpj)
airflow-web
</code></pre></div>
<h3 dir="auto">What you think should happen instead</h3>
<p dir="auto">The webserver should display the normal login page without any errors. Here are the full logs from the kubernetes pod:</p>
<details>
<summary>webserver.logs</summary>
airflow-web 127.0.0.1 - - [23/Nov/2022:15:35:59 +0000] "GET /login/ HTTP/1.1" 200 16330 "https://login.microsoftonline.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36 Edg/106.0.1370.52"
airflow-web 127.0.0.1 - - [23/Nov/2022:15:35:59 +0000] "GET /static/appbuilder/css/font-awesome.min.css HTTP/1.1" 200 0 "https://url/login/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36 Edg/106.0.1370.52"
airflow-web [2022-11-23 15:35:59,423] {app.py:1741} ERROR - Exception on /static/appbuilder/css/bootstrap.min.css [GET]
airflow-web Traceback (most recent call last):
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1802, in _execute_context
airflow-web self.dialect.do_execute(
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 719, in do_execute
airflow-web cursor.execute(statement, parameters)
airflow-web psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "session_session_id_key"
airflow-web DETAIL: Key (session_id)=(7582aee0-4289-4152-99d2-918c98ff64d6) already exists.
airflow-web
airflow-web return super().save_session(*args, **kwargs)
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/flask_session/sessions.py", line 578, in save_session
airflow-web self.db.session.commit()
airflow-web File "", line 2, in commit
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 1428, in commit
airflow-web self._transaction.commit(_to_root=self.future)
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 829, in commit
airflow-web self._prepare_impl()
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 808, in _prepare_impl
airflow-web self.session.flush()
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 3345, in flush
airflow-web self._flush(objects)
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 3485, in flush
airflow-web transaction.rollback(capture_exception=True)
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/util/langhelpers.py", line 70, in exit
airflow-web compat.raise(
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 207, in raise
airflow-web raise exception
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 3445, in _flush
airflow-web flush_context.execute()
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/orm/unitofwork.py", line 456, in execute
airflow-web rec.execute(self)
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/orm/unitofwork.py", line 630, in execute
airflow-web util.preloaded.orm_persistence.save_obj(
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/orm/persistence.py", line 244, in save_obj
airflow-web _emit_insert_statements(
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/orm/persistence.py", line 1221, in _emit_insert_statements
airflow-web result = connection._execute_20(
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1614, in _execute_20
airflow-web return meth(self, args_10style, kwargs_10style, execution_options)
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/sql/elements.py", line 325, in _execute_on_connection
airflow-web return connection._execute_clauseelement(
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1481, in _execute_clauseelement
airflow-web ret = self._execute_context(
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1845, in _execute_context
airflow-web self.handle_dbapi_exception(
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 2026, in handle_dbapi_exception
airflow-web util.raise(
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 207, in raise
airflow-web raise exception
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1802, in _execute_context
airflow-web self.dialect.do_execute(
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 719, in do_execute
airflow-web cursor.execute(statement, parameters)
airflow-web sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "session_session_id_key"
airflow-web DETAIL: Key (session_id)=(7582aee0-4289-4152-99d2-918c98ff64d6) already exists.
airflow-web
airflow-web [SQL: INSERT INTO session (session_id, data, expiry) VALUES (%(session_id)s, %(data)s, %(expiry)s) RETURNING session.id]
airflow-web [parameters: {'session_id': '7582aee0-4289-4152-99d2-918c98ff64d6', 'data': , 'expiry': datetime.datetime(2022, 11, 23, 16, 5, 59, 467562, tzinfo=datetime.timezone.utc)}]
airflow-web (Background on this error at: https://sqlalche.me/e/14/gkpj)
airflow-web
airflow-web During handling of the above exception, another exception occurred:
airflow-web
airflow-web Traceback (most recent call last):
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/flask/app.py", line 1844, in finalize_request
airflow-web response = self.process_response(response)
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/flask/app.py", line 2340, in process_response
airflow-web self.session_interface.save_session(self, ctx.session, response)
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/airflow/www/session.py", line 33, in save_session
airflow-web return super().save_session(*args, **kwargs)
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/flask_session/sessions.py", line 553, in save_session
airflow-web saved_session = self.sql_session_model.query.filter_by(
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 2810, in first
airflow-web return self.limit(1)._iter().first()
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/orm/query.py", line 2894, in _iter
airflow-web result = self.session.execute(
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 1688, in execute
airflow-web conn = self._connection_for_bind(bind)
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 1529, in _connection_for_bind
airflow-web return self._transaction._connection_for_bind(
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 721, in _connection_for_bind
airflow-web self._assert_active()
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 601, in _assert_active
airflow-web raise sa_exc.PendingRollbackError(
airflow-web sqlalchemy.exc.PendingRollbackError: This Session's transaction has been rolled back due to a previous exception during flush. To begin a new transaction with this Session, first issue Session.rollback(). Original exception was: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "session_session_id_key"
airflow-web DETAIL: Key (session_id)=(7582aee0-4289-4152-99d2-918c98ff64d6) already exists.
airflow-web
airflow-web [SQL: INSERT INTO session (session_id, data, expiry) VALUES (%(session_id)s, %(data)s, %(expiry)s) RETURNING session.id]
airflow-web [parameters: {'session_id': '7582aee0-4289-4152-99d2-918c98ff64d6', 'data': , 'expiry': datetime.datetime(2022, 11, 23, 16, 5, 59, 467562, tzinfo=datetime.timezone.utc)}]
airflow-web (Background on this error at: https://sqlalche.me/e/14/gkpj) (Background on this error at: https://sqlalche.me/e/14/7s2a)
airflow-web 127.0.0.1 - - [23/Nov/2022:15:35:59 +0000] "GET /static/appbuilder/css/flags/flags16.css HTTP/1.1" 500 1575 "https://url/login/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36 Edg/106.0.1370.52"
airflow-web 127.0.0.1 - - [23/Nov/2022:15:35:59 +0000] "GET /static/appbuilder/css/ab.css HTTP/1.1" 500 1575 "https://url/login/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36 Edg/106.0.1370.52"
airflow-web 127.0.0.1 - - [23/Nov/2022:15:35:59 +0000] "GET /static/dist/airflowDefaultTheme.731e57571b52cca4350d.css HTTP/1.1" 200 0 "https://url/login/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36 Edg/106.0.1370.52"
airflow-web [2022-11-23 15:35:59,534] {app.py:1741} ERROR - Exception on /static/dist/materialIcons.f9559e4953177b8b9a4a.css [GET]
airflow-web Traceback (most recent call last):
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1802, in _execute_context
airflow-web self.dialect.do_execute(
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 719, in do_execute
airflow-web cursor.execute(statement, parameters)
airflow-web psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "session_session_id_key"
airflow-web DETAIL: Key (session_id)=(7582aee0-4289-4152-99d2-918c98ff64d6) already exists.
airflow-web
airflow-web
airflow-web The above exception was the direct cause of the following exception:
airflow-web
airflow-web Traceback (most recent call last):
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/flask/app.py", line 2525, in wsgi_app
airflow-web response = self.full_dispatch_request()
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/flask/app.py", line 1823, in full_dispatch_request
airflow-web return self.finalize_request(rv)
airflow-web return meth(self, args_10style, kwargs_10style, execution_options)
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/sql/elements.py", line 325, in _execute_on_connection
airflow-web return connection._execute_clauseelement(
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1481, in _execute_clauseelement
airflow-web ret = self._execute_context(
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1845, in _execute_context
airflow-web self.handle_dbapi_exception(
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 2026, in handle_dbapi_exception
airflow-web util.raise(
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 207, in raise
airflow-web raise exception
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1802, in _execute_context
airflow-web self.dialect.do_execute(
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 719, in do_execute
airflow-web cursor.execute(statement, parameters)
airflow-web sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "session_session_id_key"
airflow-web DETAIL: Key (session_id)=(7582aee0-4289-4152-99d2-918c98ff64d6) already exists.
airflow-web
airflow-web [SQL: INSERT INTO session (session_id, data, expiry) VALUES (%(session_id)s, %(data)s, %(expiry)s) RETURNING session.id]
airflow-web [parameters: {'session_id': '7582aee0-4289-4152-99d2-918c98ff64d6', 'data': , 'expiry': datetime.datetime(2022, 11, 23, 16, 5, 59, 574672, tzinfo=datetime.timezone.utc)}]
airflow-web (Background on this error at: https://sqlalche.me/e/14/gkpj)
airflow-web [2022-11-23 15:35:59,591] {app.py:1741} ERROR - Exception on /static/dist/loadingDots.5da42d00b5455806e709.css [GET]
airflow-web Traceback (most recent call last):
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1802, in _execute_context
airflow-web self.dialect.do_execute(
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 719, in do_execute
airflow-web cursor.execute(statement, parameters)
airflow-web psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "session_session_id_key"
airflow-web DETAIL: Key (session_id)=(7582aee0-4289-4152-99d2-918c98ff64d6) already exists.
airflow-web
airflow-web
airflow-web The above exception was the direct cause of the following exception:
airflow-web
airflow-web Traceback (most recent call last):
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/flask/app.py", line 2525, in wsgi_app
airflow-web response = self.full_dispatch_request()
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/flask/app.py", line 1823, in full_dispatch_request
airflow-web return self.finalize_request(rv)
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/flask/app.py", line 1844, in finalize_request
airflow-web response = self.process_response(response)
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/flask/app.py", line 2340, in process_response
airflow-web self.session_interface.save_session(self, ctx.session, response)
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/airflow/www/session.py", line 33, in save_session
airflow-web return super().save_session(*args, **kwargs)
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/flask_session/sessions.py", line 578, in save_session
airflow-web self.db.session.commit()
airflow-web File "", line 2, in commit
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 1428, in commit
airflow-web self._transaction.commit(_to_root=self.future)
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 829, in commit
airflow-web self._prepare_impl()
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 808, in _prepare_impl
airflow-web self.session.flush()
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 3345, in flush
airflow-web self._flush(objects)
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 3485, in flush
airflow-web transaction.rollback(capture_exception=True)
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/util/langhelpers.py", line 70, in exit
airflow-web compat.raise(
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 207, in raise
airflow-web raise exception
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/orm/session.py", line 3445, in _flush
airflow-web flush_context.execute()
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/orm/unitofwork.py", line 456, in execute
airflow-web rec.execute(self)
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/orm/unitofwork.py", line 630, in execute
airflow-web util.preloaded.orm_persistence.save_obj(
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/orm/persistence.py", line 244, in save_obj
airflow-web _emit_insert_statements(
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/orm/persistence.py", line 1221, in _emit_insert_statements
airflow-web result = connection._execute_20(
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1614, in _execute_20
airflow-web return meth(self, args_10style, kwargs_10style, execution_options)
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/sql/elements.py", line 325, in _execute_on_connection
airflow-web return connection._execute_clauseelement(
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1481, in _execute_clauseelement
airflow-web ret = self._execute_context(
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1845, in _execute_context
airflow-web self.handle_dbapi_exception(
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 2026, in handle_dbapi_exception
airflow-web util.raise(
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 207, in raise
airflow-web raise exception
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/engine/base.py", line 1802, in _execute_context
airflow-web self.dialect.do_execute(
airflow-web File "/home/airflow/.local/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 719, in do_execute
airflow-web cursor.execute(statement, parameters)
airflow-web sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "session_session_id_key"
airflow-web DETAIL: Key (session_id)=(7582aee0-4289-4152-99d2-918c98ff64d6) already exists.
</details>
<h3 dir="auto">How to reproduce</h3>
<p dir="auto">Down below is a copy of our webserver_config.py. We are currently running Airflow 2.4.3 on Kubernetes with the Airflow Community helm chart version 8.6.1 (located here: <a href="https://github.com/airflow-helm/charts">https://github.com/airflow-helm/charts</a>). We are also using a postgres external database as our metadata db.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from flask_appbuilder.security.manager import AUTH_OAUTH
from airflow.www.security import AirflowSecurityManager
import logging
from typing import Dict, Any, List, Union
import os
import sys

#Add this as a module to pythons path
sys.path.append('/opt/airflow')

log = logging.getLogger(__name__)
log.setLevel(os.getenv(&quot;AIRFLOW__LOGGING__FAB_LOGGING_LEVEL&quot;, &quot;DEBUG&quot;))

class AzureCustomSecurity(AirflowSecurityManager):
    # In this example, the oauth provider == 'azure'.
    # If you ever want to support other providers, see how it is done here:
    # https://github.com/dpgaspar/Flask-AppBuilder/blob/master/flask_appbuilder/security/manager.py#L550
    def get_oauth_user_info(self, provider, resp):
        # Creates the user info payload from Azure.
        # The user previously allowed your app to act on their behalf,
        #   so now we can query the user and teams endpoints for their data.
        # Username and team membership are added to the payload and returned to FAB.
        if provider == &quot;azure&quot;:
            log.debug(&quot;Azure response received : {0}&quot;.format(resp))
            id_token = resp[&quot;id_token&quot;]
            log.debug(str(id_token))
            me = self._azure_jwt_token_parse(id_token)
            log.debug(&quot;Parse JWT token : {0}&quot;.format(me))
            return {
                &quot;name&quot;: me.get(&quot;name&quot;, &quot;&quot;),
                &quot;email&quot;: me[&quot;upn&quot;],
                &quot;first_name&quot;: me.get(&quot;given_name&quot;, &quot;&quot;),
                &quot;last_name&quot;: me.get(&quot;family_name&quot;, &quot;&quot;),
                &quot;id&quot;: me[&quot;oid&quot;],
                &quot;username&quot;: me[&quot;oid&quot;],
                &quot;role_keys&quot;: me.get(&quot;roles&quot;, []),
            }

# Adding this in because if not the redirect url will start with http and we want https
os.environ[&quot;AIRFLOW__WEBSERVER__ENABLE_PROXY_FIX&quot;] = &quot;True&quot;
WTF_CSRF_ENABLED = False
CSRF_ENABLED = False
AUTH_TYPE = AUTH_OAUTH
AUTH_ROLES_SYNC_AT_LOGIN = True  # Checks roles on every login
# Make sure to replace this with the path to your security manager class
FAB_SECURITY_MANAGER_CLASS = &quot;webserver_config.AzureCustomSecurity&quot;
# a mapping from the values of `userinfo[&quot;role_keys&quot;]` to a list of FAB roles
AUTH_ROLES_MAPPING = {
    &quot;airflow_dev_admin&quot;: [&quot;Admin&quot;],
    &quot;airflow_dev_op&quot;: [&quot;Op&quot;],
    &quot;airflow_dev_user&quot;: [&quot;User&quot;],
    &quot;airflow_dev_viewer&quot;: [&quot;Viewer&quot;]
    }
# force users to re-auth after 30min of inactivity (to keep roles in sync)
PERMANENT_SESSION_LIFETIME = 1800
# If you wish, you can add multiple OAuth providers.
OAUTH_PROVIDERS = [
    {
        &quot;name&quot;: &quot;azure&quot;,
        &quot;icon&quot;: &quot;fa-windows&quot;,
        &quot;token_key&quot;: &quot;access_token&quot;,
        &quot;remote_app&quot;: {
            &quot;client_id&quot;: &quot;CLIENT_ID&quot;,
            &quot;client_secret&quot;: 'AZURE_DEV_CLIENT_SECRET',
            &quot;api_base_url&quot;: &quot;https://login.microsoftonline.com/TENANT_ID&quot;,
            &quot;request_token_url&quot;: None,
            'request_token_params': {
                'scope': 'openid email profile'
            },
            &quot;access_token_url&quot;: &quot;https://login.microsoftonline.com/TENANT_ID/oauth2/v2.0/token&quot;,
            &quot;access_token_params&quot;: {
                'scope': 'openid email profile'
            },
            &quot;authorize_url&quot;: &quot;https://login.microsoftonline.com/TENANT_ID/oauth2/v2.0/authorize&quot;,
            &quot;authorize_params&quot;: {
                'scope': 'openid email profile',
            },
            'jwks_uri':'https://login.microsoftonline.com/common/discovery/v2.0/keys',
        },
    },
]"><pre class="notranslate"><code class="notranslate">from flask_appbuilder.security.manager import AUTH_OAUTH
from airflow.www.security import AirflowSecurityManager
import logging
from typing import Dict, Any, List, Union
import os
import sys

#Add this as a module to pythons path
sys.path.append('/opt/airflow')

log = logging.getLogger(__name__)
log.setLevel(os.getenv("AIRFLOW__LOGGING__FAB_LOGGING_LEVEL", "DEBUG"))

class AzureCustomSecurity(AirflowSecurityManager):
    # In this example, the oauth provider == 'azure'.
    # If you ever want to support other providers, see how it is done here:
    # https://github.com/dpgaspar/Flask-AppBuilder/blob/master/flask_appbuilder/security/manager.py#L550
    def get_oauth_user_info(self, provider, resp):
        # Creates the user info payload from Azure.
        # The user previously allowed your app to act on their behalf,
        #   so now we can query the user and teams endpoints for their data.
        # Username and team membership are added to the payload and returned to FAB.
        if provider == "azure":
            log.debug("Azure response received : {0}".format(resp))
            id_token = resp["id_token"]
            log.debug(str(id_token))
            me = self._azure_jwt_token_parse(id_token)
            log.debug("Parse JWT token : {0}".format(me))
            return {
                "name": me.get("name", ""),
                "email": me["upn"],
                "first_name": me.get("given_name", ""),
                "last_name": me.get("family_name", ""),
                "id": me["oid"],
                "username": me["oid"],
                "role_keys": me.get("roles", []),
            }

# Adding this in because if not the redirect url will start with http and we want https
os.environ["AIRFLOW__WEBSERVER__ENABLE_PROXY_FIX"] = "True"
WTF_CSRF_ENABLED = False
CSRF_ENABLED = False
AUTH_TYPE = AUTH_OAUTH
AUTH_ROLES_SYNC_AT_LOGIN = True  # Checks roles on every login
# Make sure to replace this with the path to your security manager class
FAB_SECURITY_MANAGER_CLASS = "webserver_config.AzureCustomSecurity"
# a mapping from the values of `userinfo["role_keys"]` to a list of FAB roles
AUTH_ROLES_MAPPING = {
    "airflow_dev_admin": ["Admin"],
    "airflow_dev_op": ["Op"],
    "airflow_dev_user": ["User"],
    "airflow_dev_viewer": ["Viewer"]
    }
# force users to re-auth after 30min of inactivity (to keep roles in sync)
PERMANENT_SESSION_LIFETIME = 1800
# If you wish, you can add multiple OAuth providers.
OAUTH_PROVIDERS = [
    {
        "name": "azure",
        "icon": "fa-windows",
        "token_key": "access_token",
        "remote_app": {
            "client_id": "CLIENT_ID",
            "client_secret": 'AZURE_DEV_CLIENT_SECRET',
            "api_base_url": "https://login.microsoftonline.com/TENANT_ID",
            "request_token_url": None,
            'request_token_params': {
                'scope': 'openid email profile'
            },
            "access_token_url": "https://login.microsoftonline.com/TENANT_ID/oauth2/v2.0/token",
            "access_token_params": {
                'scope': 'openid email profile'
            },
            "authorize_url": "https://login.microsoftonline.com/TENANT_ID/oauth2/v2.0/authorize",
            "authorize_params": {
                'scope': 'openid email profile',
            },
            'jwks_uri':'https://login.microsoftonline.com/common/discovery/v2.0/keys',
        },
    },
]
</code></pre></div>
<h3 dir="auto">Operating System</h3>
<p dir="auto">Debian GNU/Linux 11 (bullseye)</p>
<h3 dir="auto">Versions of Apache Airflow Providers</h3>
<p dir="auto">apache-airflow-providers-amazon==6.0.0<br>
apache-airflow-providers-celery==3.0.0<br>
apache-airflow-providers-cncf-kubernetes==4.4.0<br>
apache-airflow-providers-common-sql==1.2.0<br>
apache-airflow-providers-docker==3.2.0<br>
apache-airflow-providers-elasticsearch==4.2.1<br>
apache-airflow-providers-ftp==3.1.0<br>
apache-airflow-providers-google==8.4.0<br>
apache-airflow-providers-grpc==3.0.0<br>
apache-airflow-providers-hashicorp==3.1.0<br>
apache-airflow-providers-http==4.0.0<br>
apache-airflow-providers-imap==3.0.0<br>
apache-airflow-providers-microsoft-azure==4.3.0<br>
apache-airflow-providers-mysql==3.2.1<br>
apache-airflow-providers-odbc==3.1.2<br>
apache-airflow-providers-postgres==5.2.2<br>
apache-airflow-providers-redis==3.0.0<br>
apache-airflow-providers-sendgrid==3.0.0<br>
apache-airflow-providers-sftp==4.1.0<br>
apache-airflow-providers-slack==6.0.0<br>
apache-airflow-providers-sqlite==3.2.1<br>
apache-airflow-providers-ssh==3.2.0</p>
<h3 dir="auto">Deployment</h3>
<p dir="auto">Other 3rd-party Helm chart</p>
<h3 dir="auto">Deployment details</h3>
<p dir="auto">We are currently running Airflow 2.4.3 on Kubernetes with the Airflow Community helm chart version 8.6.1 (located here: <a href="https://github.com/airflow-helm/charts">https://github.com/airflow-helm/charts</a>). We are also using a postgres external database as our metadata db.</p>
<h3 dir="auto">Anything else</h3>
<p dir="auto">There is a workaround for this issue. If you set AIRFLOW__WEBSERVER__WORKERS: "1", then the errors go away. This problem happens anytime you load the webserver. New to posting issues so any other information needed please let me know.</p>
<h3 dir="auto">Are you willing to submit PR?</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> Yes I am willing to submit a PR!</li>
</ul>
<h3 dir="auto">Code of Conduct</h3>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I agree to follow this project's <a href="https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md">Code of Conduct</a></li>
</ul>