"""Sign people in to Superset with their exe.dev login. exe.dev's HTTPS proxy lets in only you and the people you share the VM with, and tells the app who each one is in an X-ExeDev-Email header. It removes any X-ExeDev-Email a browser sends itself. superset_config.py loads this module, which trusts that header on requests that arrive through the port Docker publishes on the VM's localhost, where the proxy connects. Requests from other containers don't count, and requests without the header (curl on the VM, say) get Superset's own login page. - The first time someone arrives, they become a Superset user named after their email address. - Addresses in SUPERSET_ADMIN_EMAILS (comma-separated, in .env) get the Admin role. Everyone else starts with SUPERSET_NEW_USER_ROLE (default Gamma: no data until an admin grants some). - Every request is checked, so a session always belongs to the person exe.dev says is there. Their Superset password is random and never needed. Anything that can connect to port 8000 on the VM can send the header too, so treat a shell on the VM as admin access to Superset (it already is: the secrets are in ~/superset/.env). Don't publish Superset's port anywhere else. """ import logging import os import secrets import socket import struct from flask import request from flask_login import current_user, login_user, logout_user log = logging.getLogger(__name__) ADMINS = {e.strip().lower() for e in os.environ.get("SUPERSET_ADMIN_EMAILS", "").split(",") if e.strip()} NEW_USER_ROLE = os.environ.get("SUPERSET_NEW_USER_ROLE", "Gamma") def _gateway(): """The container's default gateway, where Docker's published port connects from.""" try: with open("/proc/net/route") as f: for line in f.readlines()[1:]: fields = line.split() if fields[1] == "00000000": return socket.inet_ntoa(struct.pack("