Skip to content

Commit 30bf8ff

Browse files
committed
fix: remove default issuer and add models docstring
1 parent 87ea27a commit 30bf8ff

File tree

8 files changed

+11
-8
lines changed

8 files changed

+11
-8
lines changed

diracx-cli/src/diracx/cli/internal/legacy.py

+1
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ def generate_helm_values(
230230
helm_values["diracx"] = diracx_config
231231
diracx_config["hostname"] = diracx_hostname
232232

233+
diracx_settings["DIRACX_SERVICE_AUTH_TOKEN_ISSUER"] = diracx_url
233234
diracx_settings["DIRACX_SERVICE_AUTH_ALLOWED_REDIRECTS"] = json.dumps(
234235
[
235236
urljoin(diracx_url, "api/docs/oauth2-redirect"),

diracx-core/src/diracx/core/models.py

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""Models are used to define the data structure of the requests and responses
2+
for the DiracX API. They are shared between the client components (cli, api) and
3+
services components (db, logic, routers).
4+
"""
5+
16
from __future__ import annotations
27

38
from datetime import datetime

diracx-core/src/diracx/core/settings.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,7 @@ class AuthSettings(ServiceSettingsBase):
134134
# State key is used to encrypt/decrypt the state dict passed to the IAM
135135
state_key: FernetKey
136136

137-
# TODO: this should probably be something mandatory
138-
# to set by the user
139-
token_issuer: str = "http://lhcbdirac.cern.ch/" # noqa: S105
137+
token_issuer: str
140138
token_key: TokenSigningKey
141139
token_algorithm: str = "RS256" # noqa: S105
142140
access_token_expire_minutes: int = 20

diracx-db/src/diracx/db/sql/sandbox_metadata/db.py

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class SandboxMetadataDB(BaseSQLDB):
2323

2424
async def get_owner_id(self, user: UserInfo) -> int | None:
2525
"""Get the id of the owner from the database."""
26-
# TODO: Follow https://github.com/DIRACGrid/diracx/issues/49
2726
stmt = select(SBOwners.OwnerID).where(
2827
SBOwners.Owner == user.preferred_username,
2928
SBOwners.OwnerGroup == user.dirac_group,

diracx-logic/src/diracx/logic/auth/token.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,6 @@ async def exchange_token(
273273
"Dynamic registration of users is not yet implemented"
274274
)
275275

276-
# Extract attributes from the settings and configuration
277-
issuer = settings.token_issuer
278-
279276
# Check that the subject is part of the dirac users
280277
if sub not in config.Registry[vo].Groups[dirac_group].Users:
281278
raise PermissionError(
@@ -320,7 +317,7 @@ async def exchange_token(
320317
access_payload: AccessTokenPayload = {
321318
"sub": sub,
322319
"vo": vo,
323-
"iss": issuer,
320+
"iss": settings.token_issuer,
324321
"dirac_properties": list(properties),
325322
"jti": str(uuid4()),
326323
"preferred_username": preferred_username,

diracx-routers/tests/auth/test_standard.py

+1
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,7 @@ async def test_refresh_token_invalid(test_client, auth_httpx_mock: HTTPXMock):
613613
).decode()
614614

615615
new_auth_settings = AuthSettings(
616+
token_issuer="https://iam-auth.web.cern.ch/",
616617
token_algorithm="EdDSA",
617618
token_key=pem,
618619
state_key=Fernet.generate_key(),

diracx-testing/src/diracx/testing/utils.py

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ def test_auth_settings(
100100
from diracx.core.settings import AuthSettings
101101

102102
yield AuthSettings(
103+
token_issuer=ISSUER,
103104
token_algorithm="EdDSA",
104105
token_key=private_key_pem,
105106
state_key=fernet_key,

run_local.sh

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export DIRACX_OS_DB_JOBPARAMETERSDB='{"sqlalchemy_dsn": "sqlite+aiosqlite:///'${
3838
export DIRACX_SERVICE_AUTH_TOKEN_KEY="file://${signing_key}"
3939
export DIRACX_SERVICE_AUTH_STATE_KEY="${state_key}"
4040
hostname_lower=$(hostname | tr -s '[:upper:]' '[:lower:]')
41+
export DIRACX_SERVICE_AUTH_TOKEN_ISSUER="http://${hostname_lower}:8000"
4142
export DIRACX_SERVICE_AUTH_ALLOWED_REDIRECTS='["http://'"$hostname_lower"':8000/docs/oauth2-redirect"]'
4243
export DIRACX_SANDBOX_STORE_BUCKET_NAME=sandboxes
4344
export DIRACX_SANDBOX_STORE_AUTO_CREATE_BUCKET=true

0 commit comments

Comments
 (0)