Skip to content

Commit 961d9c7

Browse files
committed
RSPEED-2435: fix rh-identity health probe path matching with root_path
When root_path is set (e.g. /api/lightspeed), the request path becomes /api/lightspeed/liveness instead of /liveness. The exact match fails and health probes get rejected with 401. Match only the final path segment to handle any prefix. Signed-off-by: Major Hayden <major@redhat.com>
1 parent c5f5bfb commit 961d9c7

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

src/authentication/rh_identity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ async def __call__(self, request: Request) -> AuthTuple:
217217
identity_header = request.headers.get("x-rh-identity")
218218
if not identity_header:
219219
# Skip auth for health probes when configured
220-
if request.url.path in ("/readiness", "/liveness"):
220+
if request.url.path.endswith(("/readiness", "/liveness")):
221221
if configuration.authentication_configuration.skip_for_health_probes:
222222
return NO_AUTH_TUPLE
223223
logger.warning("Missing x-rh-identity header")

tests/unit/authentication/test_rh_identity.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def create_request_with_header(header_value: Optional[str]) -> Mock:
111111
"""
112112
request = Mock(spec=Request)
113113
request.headers = {"x-rh-identity": header_value} if header_value else {}
114+
request.url = Mock(path="/test")
114115
request.state = Mock()
115116
return request
116117

@@ -467,7 +468,15 @@ def _mock_configuration(
467468
mocker.patch("authentication.rh_identity.configuration", mock_config)
468469

469470
@pytest.mark.asyncio
470-
@pytest.mark.parametrize("path", ["/readiness", "/liveness"])
471+
@pytest.mark.parametrize(
472+
"path",
473+
[
474+
"/readiness",
475+
"/liveness",
476+
"/api/lightspeed/readiness",
477+
"/api/lightspeed/liveness",
478+
],
479+
)
471480
async def test_probe_paths_skip_auth_when_enabled(
472481
self, mocker: MockerFixture, path: str
473482
) -> None:
@@ -481,7 +490,15 @@ async def test_probe_paths_skip_auth_when_enabled(
481490
assert result == NO_AUTH_TUPLE
482491

483492
@pytest.mark.asyncio
484-
@pytest.mark.parametrize("path", ["/readiness", "/liveness"])
493+
@pytest.mark.parametrize(
494+
"path",
495+
[
496+
"/readiness",
497+
"/liveness",
498+
"/api/lightspeed/readiness",
499+
"/api/lightspeed/liveness",
500+
],
501+
)
485502
async def test_probe_paths_require_auth_when_disabled(
486503
self, mocker: MockerFixture, path: str
487504
) -> None:

0 commit comments

Comments
 (0)