Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Gateway] Add support for gateway token renewal #985

Merged
merged 13 commits into from
Sep 21, 2022

Conversation

kevin-bates
Copy link
Member

This pull request adds the ability for operators to configure a callable to perform authorization token renewal for the token used to access a Gateway server.

The callable class is specified via the GatewayClient.gateway_token_renewer_class configurable trait (or env JUPYTER_GATEWAY_TOKEN_RENEWER_CLASS). The specified class name, once instantiated, must be a subclass (i.e., instance of) jupyter_server.gateway.gateway_client.GatewayTokenRenewerBase, which is an abstract base class requiring the implementation of a single method - get_token():

    @abstractmethod
    def get_token(
        self,
        auth_header_key: str,
        auth_scheme: Union[str, None],
        auth_token: str,
        **kwargs: Any,
    ) -> str:
        """
        Given the current authorization scheme and token, this method returns
        a (potentially) renewed token for use against the Gateway server.
        """
        pass

GatewayTokenRenewerBase derives from LoggingConfigurable and, as a result, can support its own configurable traits that may be necessary to perform token renewal. In addition, the instance's self.parent attribute contains the current instance of GatewayClient, where other attributes are accessible. (Note: auth_header_key, auth_scheme, and auth_token also reside on GatewayClient, but are provided as parameters for convenience.)

The gateway tests have been extended to demonstrate the configuration of a custom token renewer with configurable traits.

@codecov-commenter
Copy link

codecov-commenter commented Sep 19, 2022

Codecov Report

Base: 72.52% // Head: 72.59% // Increases project coverage by +0.06% 🎉

Coverage data is based on head (86a60fa) compared to base (32e0919).
Patch coverage: 82.25% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #985      +/-   ##
==========================================
+ Coverage   72.52%   72.59%   +0.06%     
==========================================
  Files          64       64              
  Lines        8205     8239      +34     
  Branches     1375     1378       +3     
==========================================
+ Hits         5951     5981      +30     
- Misses       1840     1844       +4     
  Partials      414      414              
Impacted Files Coverage Δ
jupyter_server/gateway/gateway_client.py 78.18% <82.25%> (+1.15%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

jupyter_server/gateway/gateway_client.py Outdated Show resolved Hide resolved
jupyter_server/gateway/gateway_client.py Outdated Show resolved Hide resolved
jupyter_server/gateway/gateway_client.py Outdated Show resolved Hide resolved
Copy link
Contributor

@blink1073 blink1073 left a comment

Choose a reason for hiding this comment

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

Thank you!

@blink1073 blink1073 merged commit a4266be into jupyter-server:main Sep 21, 2022
@kevin-bates
Copy link
Member Author

Thank you Steve!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants