Skip to content

Commit ab7dd68

Browse files
committed
✨(backend) allow prefixing resource server scopes
When declaring scopes with our OIDC provider, they require us to prefix each scope with our application name. This is to prevent reserving generic scopes like rooms:list for only our app, as they manage a large federation. I’m proposing a workaround where, if a resource server prefix is detected in the scope, it’s stripped out. This solution is simple and sufficient in my opinion. Since the scopes are defined in the database, I don’t want to update them directly. Additionally, each self-hosted instance may have a different application name, so the prefix should be configurable via a Django setting.
1 parent c7f5dab commit ab7dd68

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

src/backend/core/external_api/permissions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import logging
44
from typing import Dict
55

6+
from django.conf import settings
7+
68
from rest_framework import exceptions, permissions
79

810
from .. import models
@@ -55,6 +57,12 @@ def has_permission(self, request, view):
5557
if isinstance(token_scopes, str):
5658
token_scopes = token_scopes.split()
5759

60+
if settings.OIDC_RS_SCOPES_PREFIX:
61+
token_scopes = [
62+
scope.replace(f"{settings.OIDC_RS_SCOPES_PREFIX}:", "")
63+
for scope in token_scopes
64+
]
65+
5866
if required_scope not in token_scopes:
5967
raise exceptions.PermissionDenied(
6068
f"Insufficient permissions. Required scope: {required_scope}"

src/backend/core/tests/test_external_api_rooms.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ def test_resource_server_creates_user_on_first_authentication(settings):
373373

374374
settings.OIDC_RS_CLIENT_ID = "some_client_id"
375375
settings.OIDC_RS_CLIENT_SECRET = "some_client_secret"
376+
settings.OIDC_RS_SCOPES_PREFIX = "lasuite_meet"
376377

377378
settings.OIDC_OP_URL = "https://oidc.example.com"
378379
settings.OIDC_VERIFY_SSL = False
@@ -389,7 +390,7 @@ def test_resource_server_creates_user_on_first_authentication(settings):
389390
"aud": "some_client_id", # settings.OIDC_RS_CLIENT_ID
390391
"sub": "very-specific-sub",
391392
"client_id": "some_service_provider",
392-
"scope": "openid lasuite_meet rooms:list",
393+
"scope": "openid lasuite_meet lasuite_meet:rooms:list",
393394
"active": True,
394395
},
395396
)
@@ -489,6 +490,7 @@ def test_resource_server_authentication_successful(settings):
489490

490491
settings.OIDC_RS_CLIENT_ID = "some_client_id"
491492
settings.OIDC_RS_CLIENT_SECRET = "some_client_secret"
493+
settings.OIDC_RS_SCOPES_PREFIX = "lasuite_meet"
492494

493495
settings.OIDC_OP_URL = "https://oidc.example.com"
494496
settings.OIDC_VERIFY_SSL = False
@@ -505,7 +507,7 @@ def test_resource_server_authentication_successful(settings):
505507
"aud": "some_client_id", # settings.OIDC_RS_CLIENT_ID
506508
"sub": "very-specific-sub",
507509
"client_id": "some_service_provider",
508-
"scope": "openid lasuite_meet rooms:list",
510+
"scope": "openid lasuite_meet lasuite_meet:rooms:list",
509511
"active": True,
510512
},
511513
)

src/backend/meet/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,9 @@ class Base(Configuration):
538538
OIDC_RS_ENCRYPTION_KEY_TYPE = values.Value(
539539
default="RSA", environ_name="OIDC_RS_ENCRYPTION_KEY_TYPE", environ_prefix=None
540540
)
541+
OIDC_RS_SCOPES_PREFIX = values.Value(
542+
default=None, environ_name="OIDC_RS_SCOPES_PREFIX", environ_prefix=None
543+
)
541544

542545
# Video conference configuration
543546
LIVEKIT_CONFIGURATION = {

0 commit comments

Comments
 (0)