File tree Expand file tree Collapse file tree 3 files changed +13
-14
lines changed Expand file tree Collapse file tree 3 files changed +13
-14
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ class Settings(BaseSettings):
21
21
WEBSITE_AUTH_ENCRYPTION_KEY : str = Field (
22
22
default = "" , alias = "WEBSITE_AUTH_ENCRYPTION_KEY"
23
23
)
24
+ WEBSITE_OS_TYPE : str = Field (default = "test" , alias = "WEBSITE_OS_TYPE" )
24
25
MY_SECRET_CONFIG : str = Field (default = "" , alias = "MY_SECRET_CONFIG" )
25
26
26
27
Original file line number Diff line number Diff line change 10
10
11
11
12
12
async def verify_health_auth_header (
13
- x_ms_auth_internal_token : Annotated [str , Header ()] = ""
13
+ x_ms_auth_internal_token : Annotated [str | None , Header ()] = None
14
14
) -> bool :
15
15
"""Returns true if SHA256 of header_value matches WEBSITE_AUTH_ENCRYPTION_KEY.
16
+ This only works on Windows-based app services. Therefore, this feature is turned off for other OS types.
16
17
Documentation: https://learn.microsoft.com/en-us/azure/app-service/monitor-instances-health-check?tabs=python#authentication-and-security
17
18
18
19
x_ms_auth_internal_token: Value of the x-ms-auth-internal-token header.
19
20
RETURNS (bool): Specifies whether the header matches.
20
21
"""
21
- logger .info (f"Header value: '{ x_ms_auth_internal_token } '" )
22
- logger .info (f"Encryption key: '{ settings .WEBSITE_AUTH_ENCRYPTION_KEY } '" )
23
- website_auth_encryption_key = settings .WEBSITE_AUTH_ENCRYPTION_KEY
24
- hash = base64 .b64encode (
25
- sha256 (website_auth_encryption_key .encode ('utf-8' )).digest ()
26
- ).decode ('utf-8' )
27
- # if hash != x_ms_auth_internal_token:
28
- # raise HTTPException(
29
- # status_code=400, detail="x-ms-auth-internal-token is invalid"
30
- # )
31
- # else:
32
- # return True
22
+ if settings .WEBSITE_OS_TYPE .lower () == "windows" :
23
+ website_auth_encryption_key = settings .WEBSITE_AUTH_ENCRYPTION_KEY
24
+ hash = base64 .b64encode (
25
+ sha256 (website_auth_encryption_key .encode ("utf-8" )).digest ()
26
+ ).decode ("utf-8" )
27
+ if hash != x_ms_auth_internal_token :
28
+ raise HTTPException (
29
+ status_code = 400 , detail = "x-ms-auth-internal-token is invalid"
30
+ )
33
31
return True
Original file line number Diff line number Diff line change @@ -128,7 +128,7 @@ def setup_opentelemetry(app: FastAPI):
128
128
# Create instrumenter
129
129
FastAPIInstrumentor .instrument_app (
130
130
app ,
131
- excluded_urls = f".*.in.applicationinsights.azure.com/.*" ,
131
+ excluded_urls = f".*.in.applicationinsights.azure.com/.*, { settings . API_V1_STR } /health/heartbeat " ,
132
132
tracer_provider = tracer_provider ,
133
133
meter_provider = meter_provider ,
134
134
)
You can’t perform that action at this time.
0 commit comments