Skip to content

Syk/refactor config - #101

Merged
itsoyou merged 1 commit into
mainfrom
syk/refactor-config
Sep 4, 2026
Merged

itsoyou merged 1 commit into
mainfrom
syk/refactor-config

Conversation

@itsoyou

@itsoyou itsoyou commented Sep 1, 2026

Copy link
Copy Markdown
Member

SYN-95


Note

Medium Risk
Changes how Synapse module config is parsed and validated at startup and tightens metadata-resource shape; misconfiguration may now surface as validation errors, though auth logic is largely the same with added guards.

Overview
Replaces the single config.py with a synapse_token_authenticator/config/ package where JWT, OIDC, OAuth, and EPA settings are Pydantic dataclass models with structured validation (JWK sources, algorithms, OAuth jwt/introspection requirements, etc.). TokenAuthenticatorConfig now skips missing or explicit null YAML sections and instantiates only the enabled blocks.

OAuth/EPA expose_metadata_resource is now a dict that must include name; invalid metadata objects fail at config load. OIDC allowed_client_ids accepts a list or space-separated string; numeric project_id / organization_id are coerced to strings. Unknown config keys are ignored (extra="ignore") to reduce breakage.

TokenAuthenticator reads typed config attributes directly, returns early when a flow is not configured, and _verify_jwt rejects invalid key types instead of relying on asserts. README documents the metadata object shape. Large unit test coverage added under tests/test_config/ plus OIDC client allowlist and EPA JWKS-set scenarios.

Reviewed by Cursor Bugbot for commit 5a91af6. Bugbot is set up for automated code reviews on this repo. Configure here.

@itsoyou
itsoyou requested a review from a team as a code owner September 1, 2026 11:06
@codecov

codecov Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.95527% with 69 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.71%. Comparing base (5c7f1b9) to head (12545c3).

Files with missing lines Patch % Lines
synapse_token_authenticator/token_authenticator.py 56.36% 11 Missing and 13 partials ⚠️
synapse_token_authenticator/config/epa.py 75.30% 11 Missing and 9 partials ⚠️
synapse_token_authenticator/config/oauth.py 83.17% 10 Missing and 8 partials ⚠️
synapse_token_authenticator/config/oidc.py 80.76% 2 Missing and 3 partials ⚠️
synapse_token_authenticator/config/jwt.py 91.66% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #101      +/-   ##
==========================================
+ Coverage   76.43%   77.71%   +1.27%     
==========================================
  Files           9       13       +4     
  Lines         764      875     +111     
  Branches      136      157      +21     
==========================================
+ Hits          584      680      +96     
- Misses        121      123       +2     
- Partials       59       72      +13     
Files with missing lines Coverage Δ
synapse_token_authenticator/claims_validator.py 81.00% <100.00%> (+0.19%) ⬆️
synapse_token_authenticator/config/__init__.py 100.00% <100.00%> (ø)
synapse_token_authenticator/config/jwt.py 91.66% <91.66%> (ø)
synapse_token_authenticator/config/oidc.py 80.76% <80.76%> (ø)
synapse_token_authenticator/config/oauth.py 83.17% <83.17%> (ø)
synapse_token_authenticator/config/epa.py 75.30% <75.30%> (ø)
synapse_token_authenticator/token_authenticator.py 69.04% <56.36%> (-1.53%) ⬇️

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5c7f1b9...12545c3. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread synapse_token_authenticator/config/oidc.py Outdated
Comment thread tests/test_config/test_oauth.py
Comment thread synapse_token_authenticator/config/epa.py Outdated
Comment thread synapse_token_authenticator/config/oauth.py

@FrenchGithubUser FrenchGithubUser left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, just a few notes:

you should also change the call sites like if (oidc := getattr(self.config, "oidc", None)) is not None: now as it's written in the jira ticket

and can also use typing in __init__.py with something like:

class TokenAuthenticatorConfig:
    """
    Parses and validates the provided config dictionary.
    """

    jwt: JwtConfig | None
    oidc: OIDCConfig | None
    oauth: OAuthConfig | None
    epa: EPaConfig | None

    def __init__(self, other: dict):
        self.jwt = JwtConfig(**jwt) if (jwt := other.get("jwt")) else None
        self.oidc = OIDCConfig(**oidc) if (oidc := other.get("oidc")) else None
        self.oauth = OAuthConfig(**oauth) if (oauth := other.get("oauth")) else None
        self.epa = EPaConfig(**epa) if (epa := other.get("epa")) else None

Comment thread synapse_token_authenticator/config/epa.py
Comment thread synapse_token_authenticator/config.py
Comment thread synapse_token_authenticator/config/oauth.py Outdated
Comment thread synapse_token_authenticator/config/oauth.py Outdated
Comment thread synapse_token_authenticator/config/__init__.py
Comment thread synapse_token_authenticator/token_authenticator.py
Comment thread synapse_token_authenticator/config/epa.py Outdated
Comment thread synapse_token_authenticator/token_authenticator.py Outdated
Comment thread synapse_token_authenticator/config/epa.py

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit b3ec458. Configure here.

Comment thread synapse_token_authenticator/config/oidc.py
Comment thread synapse_token_authenticator/config/epa.py Outdated
Comment thread synapse_token_authenticator/config/epa.py Outdated
Comment thread synapse_token_authenticator/config/oauth.py Outdated

@jason-famedly jason-famedly left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, this was quite large which can't be helped. I still have a few lingering questions about getting rid of a few more of the Anys running around. I believe they are part of the Pydantic validation and should not be too much of a concern. Only other concern I have is out-of-scope: What happens when a InvalidJWKValue is raised? Lets explore this another day as it would have existed before.

LGTM! 🚀

@jason-famedly

Copy link
Copy Markdown
Member

(and don't forget to squash!)

chore: update epa config

chore: update jwt config to dataclass

chore: update oidc config as dataclass

chore: update oauth config

chore: update comments

chore: update expose_metadata_resource to dict
@itsoyou
itsoyou force-pushed the syk/refactor-config branch from 8e4cdfd to 12545c3 Compare September 4, 2026 12:36
@itsoyou
itsoyou added this pull request to the merge queue Sep 4, 2026
Merged via the queue into main with commit 75ea954 Sep 4, 2026
6 checks passed
@itsoyou
itsoyou deleted the syk/refactor-config branch September 4, 2026 12:50
@jason-famedly jason-famedly mentioned this pull request Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants