auth_proxy¶
Interface library for providing OAuth2 Proxy with downstream charms’ auth-proxy information.
It is required to integrate a charm into an Identity and Access Proxy (IAP).
Getting Started¶
To install, add charmlibs-interfaces-auth-proxy to your Python dependencies. Then in your Python code, import as:
from charmlibs.interfaces import auth_proxy
Note that you also need to add ``jsonschema`` to your charm’s ``requirements.txt``.
To use the library from the requirer side, add the following to the metadata.yaml of the charm:
requires:
auth-proxy:
interface: auth_proxy
limit: 1
Then, to initialise the library:
from charmlibs.interfaces.auth_proxy import AuthProxyConfig, AuthProxyRequirer
AUTH_PROXY_ALLOWED_ENDPOINTS = ["welcome", "about/app"]
AUTH_PROXY_HEADERS = ["X-Auth-Request-User", "X-Auth-Request-Email"]
AUTH_PROXY_AUTHENTICATED_EMAILS = ["test@example.com", "test@canonical.com"]
AUTH_PROXY_AUTHENTICATED_EMAIL_DOMAINS = ["canonical.com"]
class SomeCharm(CharmBase):
def __init__(self, *args):
# ...
self.auth_proxy = AuthProxyRequirer(self, self._auth_proxy_config)
@property
def external_urls(self) -> list:
# Get ingress-per-unit or externally-configured web urls
# ...
return ["https://example.com/unit-0", "https://example.com/unit-1"]
@property
def _auth_proxy_config(self) -> AuthProxyConfig:
return AuthProxyConfig(
protected_urls=self.external_urls,
allowed_endpoints=AUTH_PROXY_ALLOWED_ENDPOINTS,
headers=AUTH_PROXY_HEADERS,
authenticated_emails=AUTH_PROXY_AUTHENTICATED_EMAILS,
authenticated_email_domains=AUTH_PROXY_AUTHENTICATED_EMAIL_DOMAINS
)
def _on_ingress_ready(self, event):
self._configure_auth_proxy()
def _configure_auth_proxy(self):
self.auth_proxy.update_auth_proxy_config(auth_proxy_config=self._auth_proxy_config)
- class AuthProxyConfig(protected_urls: list[str], headers: list[str] = <factory>, allowed_endpoints: list[str] = <factory>, authenticated_emails: list[str] = <factory>, authenticated_email_domains: list[str] = <factory>, app_name: str | None = None)¶
Bases:
objectHelper class containing a configuration for the charm related with OAuth2 Proxy.
- class AuthProxyConfigChangedEvent(
- handle: Handle,
- protected_urls: list[str],
- headers: list[str],
- allowed_endpoints: list[str],
- authenticated_emails: list[str],
- authenticated_email_domains: list[str],
- relation_id: int,
- relation_app_name: str,
Bases:
EventBaseEvent to notify the Provider charm that the auth proxy config has changed.
- to_auth_proxy_config() AuthProxyConfig¶
Convert the event information to an AuthProxyConfig object.
- exception AuthProxyConfigError¶
Bases:
ExceptionEmitted when invalid auth proxy config is provided.
- class AuthProxyConfigRemovedEvent(handle: Handle, relation_id: int)¶
Bases:
EventBaseEvent to notify the provider charm that the auth proxy config was removed.
- class AuthProxyProvider( )¶
Bases:
AuthProxyRelationProvider side of the auth-proxy relation.
- on¶
Event descriptor for events raised by AuthProxyProvider.
- class AuthProxyRelationRemovedEvent(handle: Handle)¶
Bases:
EventBaseCustom event to notify the charm that the relation was removed.
- class AuthProxyRequirer(
- charm: CharmBase,
- auth_proxy_config: AuthProxyConfig | None = None,
- relation_name: str = 'auth-proxy',
Bases:
AuthProxyRelationRequirer side of the auth-proxy relation.
- on¶
Event descriptor for events raised by AuthProxyRequirer.
- update_auth_proxy_config(
- auth_proxy_config: AuthProxyConfig,
- relation_id: int | None = None,
Update the auth proxy config stored in the object.