|
8 | 8 | from jose import jwt |
9 | 9 | from jose.exceptions import JWTError, ExpiredSignatureError |
10 | 10 |
|
| 11 | +# --- Caches --- |
| 12 | +DISCOVERY_CACHE: Dict[str, Any] = {} |
| 13 | +JWKS_CACHE: Dict[str, Any] = {} |
| 14 | + |
11 | 15 | # --- Configuration --- |
12 | 16 | KEYCLOAK_URL = os.getenv("KEYCLOAK_URL", "http://keycloak.tools.svc.cluster.local") |
13 | 17 | KEYCLOAK_REALM = os.getenv("KEYCLOAK_REALM", "default") |
|
19 | 23 | KEYCLOAK_AUDIENCE = os.getenv("KEYCLOAK_AUDIENCE", "account") |
20 | 24 | ROLE_MAPPING_FILE = os.getenv("ROLE_MAPPING_FILE", "role_mapping.yaml") |
21 | 25 |
|
22 | | -# --- Caches --- |
23 | | -DISCOVERY_CACHE: Dict[str, Any] = {} |
24 | | -JWKS_CACHE: Dict[str, Any] = {} |
| 26 | +LOG_LEVEL = os.getenv("LOG_LEVEL", "INFO").upper() |
| 27 | +LOG_FORMAT = "%(asctime)s - %(levelname)s - %(message)s" |
25 | 28 |
|
26 | 29 | # --- Logging --- |
27 | | -logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s") |
28 | | -app_logger = logging.getLogger("forwardauth") |
29 | | -app_logger.setLevel(logging.DEBUG) |
| 30 | +numeric_level = getattr(logging, LOG_LEVEL, logging.INFO) |
| 31 | +logging.basicConfig(level=numeric_level, format=LOG_FORMAT) |
| 32 | +app_logger = logging.getLogger("traefik_authproxy") |
| 33 | +app_logger.setLevel(numeric_level) |
30 | 34 |
|
31 | 35 | # --- App Initialization --- |
32 | 36 | app = FastAPI( |
@@ -150,6 +154,7 @@ def is_public_path(path: str) -> bool: |
150 | 154 | @app.post("/auth") |
151 | 155 | async def authenticate(request: Request): |
152 | 156 | forwarded_uri = request.headers.get("X-Forwarded-Uri", "/") |
| 157 | + app_logger.debug(f"Received request on forwarded URI: {forwarded_uri}") |
153 | 158 |
|
154 | 159 | if is_public_path(forwarded_uri): |
155 | 160 | app_logger.info(f"Public access granted to: {forwarded_uri}") |
|
0 commit comments