Grafana

  • By Canonical Observability
Channel Revision Published Runs on
latest/stable 107 Yesterday
Ubuntu 20.04
latest/candidate 110 Yesterday
Ubuntu 20.04
latest/beta 111 Yesterday
Ubuntu 20.04
latest/edge 111 12 Apr 2024
Ubuntu 20.04
1.0/stable 93 12 Dec 2023
Ubuntu 20.04
1.0/candidate 93 22 Nov 2023
Ubuntu 20.04
1.0/beta 93 22 Nov 2023
Ubuntu 20.04
1.0/edge 93 22 Nov 2023
Ubuntu 20.04
juju deploy grafana-k8s
Show information

Platform:

charms.grafana_k8s.v0.grafana_auth

grafana-auth library.

This library implements the grafana-auth relation interface, it contains the Requirer and Provider classes for handling the interface. With this library charms can to configure authentication to Grafana. The provider will set the authentication mode that it needs, and will pass the necessary configuration of that authentication mode. The requirer will consume the authentication configuration to authenticate to Grafana.

Getting Started

From a charm directory, fetch the library using charmcraft:

charmcraft fetch-lib charms.grafana_k8s.v0.grafana_auth

You will also need to add the following library to the charm's requirements.txt file:

  • jsonschema
Provider charm

Example: An example on how to use the AuthProvider with proxy mode using default configuration options. The default arguments are: charm : CharmBase relation_name: str : grafana-auth header_name: str : X-WEBAUTH-USER header_property: str : username auto_sign_up: bool : True sync_ttl: int : None whitelist: list[str] : None headers: list[str] : None headers_encoded: bool : None enable_login_token: bool : None

from charms.grafana_k8s.v0.grafana_auth import GrafanaAuthProxyProvider
from ops.charm import CharmBase
class ExampleProviderCharm(CharmBase):
    def __init__(self, *args):
        super().__init__(*args)
        ...
        self.grafana_auth_proxy_provider = GrafanaAuthProxyProvider(self)
        self.framework.observe(
            self.grafana_auth_proxy_provider.on.urls_available, self._on_urls_available
        )
        ...

Values different than defaults must be set from the class constructor. The official documentation of Grafana provides further explanation on the values that can be assigned to the different variables. Example:

from charms.grafana_k8s.v0.grafana_auth import GrafanaAuthProxyProvider
from ops.charm import CharmBase
class ExampleProviderCharm(CharmBase):
    def __init__(self, *args):
        super().__init__(*args)
        ...
        self.grafana_auth_proxy_provider = GrafanaAuthProxyProvider(
            self,
            header_property="email",
            auto_sign_up=False,
            whitelist=["localhost","canonical.com"],
        )
        self.framework.observe(
            self.grafana_auth_proxy_provider.on.urls_available, self._on_urls_available
        )
        ...
Requirer charm

Example: An example on how to use the auth requirer.

from charms.grafana_k8s.v0.grafana_auth import AuthRequirer
from ops.charm import CharmBase
class ExampleRequirerCharm(CharmBase):
    def __init__(self, *args):
        super().__init__(*args)
        self.auth_requirer = AuthRequirer(
            self,
            auth_requirer=["https://example.com/"]
        )
        self.framework.observe(
            self.auth_requirer.on.auth_conf_available, self._on_auth_conf_available
        )

class UrlsAvailableEvent

Description

Charm event triggered when provider charm extracts the urls from relation data. None

Methods

UrlsAvailableEvent. __init__( self , handle , urls: list , relation_id: int )

UrlsAvailableEvent. snapshot( self )

Description

Returns snapshot. None

UrlsAvailableEvent. restore( self , snapshot: dict )

Description

Restores snapshot. None

class AuthProviderCharmEvents

Description

List of events that the auth provider charm can leverage. None

class AuthProvider

Base class for authentication configuration provider classes.

Description

This class shouldn't be initialized, Its children classes define the authentication mode and configuration to be used.

Methods

AuthProvider. __init__( self , charm: CharmBase , relation_name: str , refresh_event )

class AuthConfAvailableEvent

Description

Charm Event triggered when authentication config is ready. None

Methods

AuthConfAvailableEvent. __init__( self , handle , auth: dict , relation_id: int )

AuthConfAvailableEvent. snapshot( self )

Description

Returns snapshot. None

AuthConfAvailableEvent. restore( self , snapshot: dict )

Description

Restores snapshot. None

class AuthRequirerCharmEvents

Description

List of events that the auth requirer charm can leverage. None

class AuthRequirer

Description

Authentication configuration requirer class. None

Methods

AuthRequirer. __init__( self , charm , urls , relation_name: str , refresh_event )

Constructs an authentication requirer that consumes authentication configuration.

Arguments

charm

CharmBase: the charm which manages this object.

urls

List[str]: a list of urls to access the service the charm needs to authenticate to.

relation_name

str: name of the relation in metadata.yaml that has the grafana_auth interface.

refresh_event

an optional bound event which will be observed to re-set authentication configuration.

Description

The charm initializing this class requires authentication configuration, and it's expected to provide a list of url(s) to the service it's authenticating to. This class can be initialized as follows:

self.auth_requirer = AuthRequirer(
self,
auth_requirer=["https://example.com/"]
)

class GrafanaAuthProxyProvider

Authentication configuration provider class.

Description

Provides proxy mode for authentication to Grafana.

Methods

GrafanaAuthProxyProvider. __init__( self , charm: CharmBase , relation_name: str , refresh_event , header_name: str , header_property: str , auto_sign_up: bool , sync_ttl , whitelist , headers , headers_encoded , enable_login_token )

Constructs GrafanaAuthProxyProvider.

Arguments

charm

CharmBase: the charm which manages this object.

relation_name

str: name of the relation in metadata.yaml that has the grafana_auth interface.

refresh_event

an optional bound event which will be observed to re-set urls.

header_name

str: HTTP Header name that will contain the username or email

header_property

str: HTTP Header property, defaults to username but can also be email.

auto_sign_up

bool: Set to true to enable auto sign-up of users who do not exist in Grafana DB.

sync_ttl

int: Define cache time to live in minutes.

whitelist

list[str]: Limits where auth proxy requests come from by configuring a list of IP addresses.

headers

list[str]: Optionally define more headers to sync other user attributes.

headers_encoded

bool: Non-ASCII strings in header values are encoded using quoted-printable encoding

enable_login_token

bool

Returns

None

Description

The charm initializing this object configures the authentication to grafana using proxy authentication mode. This object can be initialized as follows:

self.grafana_auth_proxy_provider = GrafanaAuthProxyProvider(self)