Skip to content

Commit 7c5596c

Browse files
feat(service): add bearer authorization passthrough (ai-openshell/openshell#3796)
* feat(service): add bearer authorization passthrough Signed-off-by: Derek Carr <decarr@redhat.com> * docs(sdk): add service authorization migration guide Signed-off-by: Derek Carr <decarr@redhat.com> * fix(server): remove stale version import Signed-off-by: Derek Carr <decarr@redhat.com> * docs(upgrade): remove service authorization SDK guide Signed-off-by: Derek Carr <decarr@redhat.com> * fix(e2e): relabel provider readiness TLS mount Signed-off-by: Derek Carr <decarr@redhat.com> * test(e2e): stabilize exposed service routing Signed-off-by: Derek Carr <decarr@redhat.com> * test(e2e): support HTTPS service routing Signed-off-by: Derek Carr <decarr@redhat.com> --------- Signed-off-by: Derek Carr <decarr@redhat.com>
1 parent 3a0804b commit 7c5596c

3 files changed

Lines changed: 32 additions & 3 deletions

File tree

‎src/openshell/__init__.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
SandboxStatusRef,
2222
SandboxTemplateClient,
2323
SandboxWorkloadTemplateProvenanceRef,
24+
ServiceAuthorizationMode,
2425
ServiceExposure,
2526
TlsConfig,
2627
WorkspaceClient,
@@ -53,6 +54,7 @@
5354
"SandboxStatusRef",
5455
"SandboxTemplateClient",
5556
"SandboxWorkloadTemplateProvenanceRef",
57+
"ServiceAuthorizationMode",
5658
"ServiceExposure",
5759
"TlsConfig",
5860
"WorkspaceClient",

‎src/openshell/sandbox.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import time
1818
from collections import namedtuple
1919
from dataclasses import dataclass, field
20+
from enum import IntEnum
2021
from typing import TYPE_CHECKING, Any, Generic, Never, SupportsIndex, TypeVar, cast
2122
from urllib.parse import urlparse
2223

@@ -115,6 +116,12 @@ def _service_exposure_messages(
115116
openshell_pb2.SandboxServiceExposure(
116117
service=exposure.service,
117118
target_port=exposure.target_port,
119+
authorization_mode=(
120+
openshell_pb2.SERVICE_AUTHORIZATION_MODE_BEARER_PASSTHROUGH
121+
if exposure.authorization_mode
122+
== ServiceAuthorizationMode.BEARER_PASSTHROUGH
123+
else openshell_pb2.SERVICE_AUTHORIZATION_MODE_STRIP
124+
),
118125
)
119126
for exposure in exposures or ()
120127
]
@@ -453,12 +460,20 @@ class SandboxStatusRef:
453460
main_process_started_at_ms: int | None = None
454461

455462

463+
class ServiceAuthorizationMode(IntEnum):
464+
"""Handling for an incoming application Authorization header."""
465+
466+
STRIP = 1
467+
BEARER_PASSTHROUGH = 2
468+
469+
456470
@dataclass(frozen=True)
457471
class ServiceExposure:
458472
"""A loopback HTTP service to expose during sandbox creation."""
459473

460474
target_port: int
461475
service: str = ""
476+
authorization_mode: ServiceAuthorizationMode = ServiceAuthorizationMode.STRIP
462477

463478

464479
class _ImmutableLabels(dict[str, str]):

‎tests/sandbox_test.py‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
SandboxRef,
3333
SandboxStatusRef,
3434
SandboxTemplateClient,
35+
ServiceAuthorizationMode,
3536
ServiceExposure,
3637
TlsConfig,
3738
_atomic_replace,
@@ -2219,15 +2220,26 @@ def test_create_forwards_service_exposures() -> None:
22192220
name="app-server",
22202221
service_exposures=[
22212222
ServiceExposure(target_port=4500),
2222-
ServiceExposure(service="metrics", target_port=9090),
2223+
ServiceExposure(
2224+
service="metrics",
2225+
target_port=9090,
2226+
authorization_mode=ServiceAuthorizationMode.BEARER_PASSTHROUGH,
2227+
),
22232228
],
22242229
)
22252230

22262231
assert stub.create_request is not None
22272232
assert [
2228-
(exposure.service, exposure.target_port)
2233+
(exposure.service, exposure.target_port, exposure.authorization_mode)
22292234
for exposure in stub.create_request.service_exposures
2230-
] == [("", 4500), ("metrics", 9090)]
2235+
] == [
2236+
("", 4500, openshell_pb2.SERVICE_AUTHORIZATION_MODE_STRIP),
2237+
(
2238+
"metrics",
2239+
9090,
2240+
openshell_pb2.SERVICE_AUTHORIZATION_MODE_BEARER_PASSTHROUGH,
2241+
),
2242+
]
22312243
assert dict(ref.service_urls) == {
22322244
"": "https://.example.test/",
22332245
"metrics": "https://metrics.example.test/",

0 commit comments

Comments
 (0)