Synapse
- Canonical IS DevOps
Channel | Revision | Published | Runs on |
---|---|---|---|
latest/stable | 426 | 20 Sep 2024 | |
latest/edge | 523 | 07 Jan 2025 | |
2/edge | 636 | Today | |
1/stable | 303 | 30 Jul 2024 | |
1/edge | 620 | 27 Mar 2025 |
juju deploy synapse
Deploy Kubernetes operators easily with Juju, the Universal Operator Lifecycle Manager. Need a Kubernetes cluster? Install MicroK8s to create a full CNCF-certified Kubernetes system in under 60 seconds.
Platform:
charms.synapse.v1.matrix_auth
-
- Last updated 14 Feb 2025
- Revision Library version 1.6
Library to manage the plugin integrations with the Synapse charm.
This library contains the Requires and Provides classes for handling the integration
between an application and a charm providing the matrix_plugin
integration.
Summary
Provider
Handles requests from requirers.
- Observes: relation_changed → Triggers workload reconciliation. relation_departed → Triggers workload reconciliation.
- During reconciliation: If the unit is the leader, update_relation_data is called. If registration_secrets (IRC registration encrypted content) are present, the required files are created, and Synapse configuration is updated.
Requirer (IRC Bridge, Bidirectional)
Requests data (uses homeserver URL, registration shared secret and encryption key) from the provider and updates its configuration accordingly.
- Observes: matrix_auth_request_processed (emitted after valid relation_changed) → Triggers workload reconciliation.
- During reconciliation: Configures IRC using data from get_remote_relation_data. Updates relation data with IRC registration, calling update_relation_data.
Requirer (Maubot, Unidirectional)
Requests data (uses homeserver URL) from the provider but does not send registration data back.
Observes: matrix_auth_request_processed (emitted after valid relation_changed) → Triggers workload reconciliation.
Why setting a encryption key?
In a CMR (Cross-Model Relation), the provider cannot read a secret created by the requirer. To securely share the IRC appservice configuration, the provider generates an encryption key that both sides use: the requirer encrypts the content, and the provider decrypts it.
This key is generated once by the provider and stored as a secret. The same applies to the registration shared secret, as both remain unchanged throughout Synapse's lifecycle.
When the relation is removed, if there are no observers for the secret, it is deleted.
Requirer Charm
from charms.synapse.v0.matrix_auth import MatrixAuthRequires
class MatrixAuthRequirerCharm(ops.CharmBase):
def __init__(self, *args):
super().__init__(*args)
self.plugin_auth = MatrixAuthRequires(self)
self.framework.observe(self.matrix_auth.on.matrix_auth_request_processed, self._handler)
...
def _handler(self, events: MatrixAuthRequestProcessed) -> None:
...
As shown above, the library provides a custom event to handle the scenario in which a matrix authentication (homeserver and shared secret) has been added or updated.
The MatrixAuthRequires provides an update_relation_data
method to update the relation data by
passing a MatrixAuthRequirerData
data object, requesting a new authentication.
Provider Charm
Following the previous example, this is an example of the provider charm.
from charms.synapse.v0.matrix_auth import MatrixAuthProvides
class MatrixAuthProviderCharm(ops.CharmBase):
def __init__(self, *args):
super().__init__(*args)
self.plugin_auth = MatrixAuthProvides(self)
...
The MatrixAuthProvides object wraps the list of relations into a relations
property
and provides an update_relation_data
method to update the relation data by passing
a MatrixAuthRelationData
data object.
class MatrixAuthProviderCharm(ops.CharmBase):
...
def _on_config_changed(self, _) -> None:
for relation in self.model.relations[self.plugin_auth.relation_name]:
self.plugin_auth.update_relation_data(relation, self._get_matrix_auth_data())
Index
def
encrypt_string(
key: bytes,
plaintext: SecretStr
)
Encrypt a string using Fernet.
Arguments
encryption key in bytes.
text to encrypt.
Returns
encrypted text.
def
decrypt_string(
key: bytes,
ciphertext: str
)
Decrypt a string using Fernet.
Arguments
encryption key in bytes.
encrypted text.
Returns
decrypted text.
class MatrixAuthProviderData
Represent the MatrixAuth provider data.
Attributes
Methods
Store the Matrix shared secret as a Juju secret.
Arguments
the Juju model
relation to grant access to the secrets to.
Description
If the secret exists, grant access to the relation. If not found, create one.
MatrixAuthProviderData. set_encryption_key_secret_id( self , model , relation )
Store the encryption key to encrypt/decrypt appservice registrations.
Arguments
the Juju model
relation to grant access to the secrets to.
Retrieve the shared secret corresponding to the shared_secret_id.
Arguments
the Juju model.
the secret ID for the shared secret.
Returns
the shared secret or None if not found.
MatrixAuthProviderData. to_relation_data( self , model , relation )
Convert an instance of MatrixAuthProviderData to the relation representation.
Arguments
the Juju model.
relation to grant access to the secrets to.
Returns
Dict containing the representation.
MatrixAuthProviderData. from_relation( cls , model , relation )
Initialize a new instance of the MatrixAuthProviderData class from the relation.
Arguments
the relation.
Returns
A MatrixAuthProviderData instance.
class MatrixAuthRequirerData
Represent the MatrixAuth requirer data.
Attributes
Methods
MatrixAuthRequirerData. get_encryption_key_secret( cls , model , encryption_key_secret_id )
Retrieve the encryption key secret corresponding to the encryption_key_secret_id.
Arguments
the Juju model.
the secret ID for the encryption key secret.
Returns
the encryption key secret as bytes or None if not found.
MatrixAuthRequirerData. to_relation_data( self , model , relation )
Convert an instance of MatrixAuthRequirerData to the relation representation.
Description
Args: model: the Juju model. relation: relation to grant access to the secrets to.
Returns: Dict containing the representation.
Raises: ValueError if encryption key not found.
MatrixAuthRequirerData. from_relation( cls , model , relation )
Get a MatrixAuthRequirerData from the relation data.
Arguments
the Juju model.
the relation.
Returns
the relation data and the processed entries for it.
class MatrixAuthRequestProcessed
Description
MatrixAuth event emitted when a new request is processed. None
Methods
MatrixAuthRequestProcessed. get_matrix_auth_provider_relation_data( self )
Get a MatrixAuthProviderData for the relation data.
Returns
the MatrixAuthProviderData for the relation data.
class MatrixAuthRequestReceived
Description
MatrixAuth event emitted when a new request is made. None
class MatrixAuthRequiresEvents
MatrixAuth requirer events.
Attributes
Description
This class defines the events that a MatrixAuth requirer can emit.
class MatrixAuthProvidesEvents
MatrixAuth provider events.
Attributes
Description
This class defines the events that a MatrixAuth provider can emit.
class MatrixAuthProvides
Provider side of the MatrixAuth relation.
Attributes
Methods
MatrixAuthProvides. __init__( self , charm , relation_name: str )
Construct.
Arguments
the provider charm.
the relation name.
MatrixAuthProvides. get_remote_relation_data( self )
Retrieve the remote relation data.
Returns
the relation data.
MatrixAuthProvides. update_relation_data( self , relation , matrix_auth_provider_data: MatrixAuthProviderData )
Arguments
the relation for which to update the data.
a MatrixAuthProviderData instance wrapping the data to be updated.
Description
Update the relation data. Since provider values should not be changed while instance exists, this method updates relation data only if invalid or empty.
class MatrixAuthRequires
Requirer side of the MatrixAuth requires relation.
Attributes
Methods
MatrixAuthRequires. __init__( self , charm , relation_name: str )
Construct.
Arguments
the provider charm.
the relation name.
MatrixAuthRequires. get_remote_relation_data( self )
Retrieve the remote relation data.
Returns
the relation data.
MatrixAuthRequires. update_relation_data( self , relation , matrix_auth_requirer_data: MatrixAuthRequirerData )
Update the relation data.
Arguments
the relation for which to update the data.
MatrixAuthRequirerData wrapping the data to be updated.