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

Add SAML integration #19

Merged
merged 44 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
2a43d53
Add SAML integration
amandahla Aug 11, 2023
c03be75
Refactor integration tests and add SAML integrator integration test
amandahla Aug 14, 2023
c34ba8a
Add unit tests
amandahla Aug 14, 2023
601d583
Update SAML library
amandahla Aug 15, 2023
9cf937d
Add missing configuration saml2_enabled
amandahla Aug 16, 2023
0c15249
Merge remote-tracking branch 'origin/main' into ISD-797-synapse-add-s…
amandahla Aug 16, 2023
074b494
Update libraries
amandahla Aug 16, 2023
f75594c
Move integration tests to the same module
amandahla Aug 16, 2023
81ea1ee
Restore same tests with SAML integration test
amandahla Aug 16, 2023
96c2217
Container replan does not restart if there is no change in the plan. …
amandahla Aug 17, 2023
87cd23a
Add public_baseurl configuration
amandahla Aug 17, 2023
4f92ff2
Add NGINX workload
amandahla Aug 21, 2023
e518395
Merge remote-tracking branch 'origin/main' into ISD-797-synapse-add-s…
amandahla Aug 21, 2023
29d1500
Fix NGINX rock
amandahla Aug 21, 2023
20e4a97
Replace Exception for PebbleServiceError in SAML observer
amandahla Aug 21, 2023
8934eca
Remove type ignore in conftest
amandahla Aug 21, 2023
2388cee
Use usefixtures when possible
amandahla Aug 22, 2023
f60cb45
Separate arrange,act,assert in unit tests
amandahla Aug 22, 2023
924c7f8
Fix some lints and typos
amandahla Aug 22, 2023
09a81c7
Fix service in SAML config and add SAML integration test with SSO
amandahla Aug 22, 2023
4f6f177
Replace replan for restart_synapse
amandahla Aug 23, 2023
f99a6c1
Refactor test_enable_saml_success unit test
amandahla Aug 23, 2023
c4c9b8e
Change integration tests parameters to constants
amandahla Aug 23, 2023
1de2379
Add working dir to container.exec
amandahla Aug 23, 2023
619fc48
Change Prometheus and Grafana to latest/stable channel
amandahla Aug 23, 2023
3580364
Fix SAML configuration
amandahla Aug 24, 2023
0b1e860
Add SAML integration test using samltest.id
amandahla Aug 24, 2023
52f7fe1
Remove session variable
amandahla Aug 24, 2023
883528e
Remove nginx_route
amandahla Aug 24, 2023
c1eef48
Merge branch 'main' into ISD-797-synapse-add-saml-configuration
amandahla Aug 25, 2023
dbfeefd
Merge remote-tracking branch 'origin/main' into ISD-797-synapse-add-s…
amandahla Aug 25, 2023
44eb836
Add attributemaps to work with login.ubuntu.com
amandahla Aug 25, 2023
08152d6
Fix tests
amandahla Aug 25, 2023
b330132
Use saml-test-idp
weiiwang01 Aug 27, 2023
cb3deff
Update sso_login interface
weiiwang01 Aug 28, 2023
d346693
Update series of saml-integrator
weiiwang01 Aug 28, 2023
7340d93
Fix woke and test workload
amandahla Aug 28, 2023
e5130e8
Change some fixtures
amandahla Aug 28, 2023
7907233
Merge remote-tracking branch 'origin/use-saml-test-idp' into ISD-797-…
amandahla Aug 28, 2023
956bbe7
Remove some duplicated tests and change saml test to get server_name …
amandahla Aug 28, 2023
cbda31b
Small fixes
amandahla Aug 29, 2023
3e1c5c4
Add public_baseurl to the test
amandahla Aug 29, 2023
84f761e
Remove cosl from requirements
amandahla Aug 29, 2023
95fe2b4
Readding cosl
amandahla Aug 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ options:
Configures whether to report statistics.
default: false
type: boolean
public_baseurl:
type: string
description: |
The public-facing base URL that clients use to access this Homeserver.
Defaults to https://<server_name>/. Only used if there is integration with
SAML integrator charm.
12 changes: 6 additions & 6 deletions lib/charms/grafana_k8s/v0/grafana_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def __init__(self, *args):
# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version

LIBPATCH = 32
LIBPATCH = 33
amandahla marked this conversation as resolved.
Show resolved Hide resolved

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -665,14 +665,14 @@ def _template_panels(
continue
if not existing_templates:
datasource = panel.get("datasource")
if type(datasource) == str:
if isinstance(datasource, str):
if "loki" in datasource:
panel["datasource"] = "${lokids}"
elif "grafana" in datasource:
continue
else:
panel["datasource"] = "${prometheusds}"
elif type(datasource) == dict:
elif isinstance(datasource, dict):
# In dashboards exported by Grafana 9, datasource type is dict
dstype = datasource.get("type", "")
if dstype == "loki":
Expand All @@ -686,7 +686,7 @@ def _template_panels(
logger.error("Unknown datasource format: skipping")
continue
else:
if type(panel["datasource"]) == str:
if isinstance(panel["datasource"], str):
if panel["datasource"].lower() in replacements.values():
# Already a known template variable
continue
Expand All @@ -701,7 +701,7 @@ def _template_panels(
if replacement:
used_replacements.append(ds)
panel["datasource"] = replacement or panel["datasource"]
elif type(panel["datasource"]) == dict:
elif isinstance(panel["datasource"], dict):
dstype = panel["datasource"].get("type", "")
if panel["datasource"].get("uid", "").lower() in replacements.values():
# Already a known template variable
Expand Down Expand Up @@ -831,7 +831,7 @@ def _modify_panel(panel: dict, topology: dict, transformer: "CosTool") -> dict:
if "datasource" not in panel.keys():
continue

if type(panel["datasource"]) == str:
if isinstance(panel["datasource"], str):
if panel["datasource"] not in known_datasources:
continue
querytype = known_datasources[panel["datasource"]]
Expand Down
38 changes: 32 additions & 6 deletions lib/charms/nginx_ingress_integrator/v0/nginx_route.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright 2023 Canonical Ltd.
# Licensed under the Apache2.0, see LICENCE file in charm source for details.
# Licensed under the Apache2.0. See LICENSE file in charm source for details.
"""Library for the nginx-route relation.

This library contains the require and provide functions for handling
Expand Down Expand Up @@ -34,12 +34,12 @@
```python
from charms.nginx_ingress_integrator.v0.nginx_route import NginxRouteRequirer

# In your charm's `__init__` method.
# In your charm's `__init__` method (assuming your app is listening on port 8080).
require_nginx_route(
charm=self,
service_hostname=self.config["external_hostname"],
service_hostname=self.app.name,
service_name=self.app.name,
service_port=80
service_port=8080
)

```
Expand All @@ -52,6 +52,23 @@
You _must_ require nginx route as part of the `__init__` method
rather than, for instance, a config-changed event handler, for the relation
changed event to be properly handled.

In the example above we're setting `service_hostname` (which translates to the
external hostname for the application when related to nginx-ingress-integrator)
to `self.app.name` here. This ensures by default the charm will be available on
the name of the deployed juju application, but can be overridden in a
production deployment by setting `service-hostname` on the
nginx-ingress-integrator charm. For example:
```bash
juju deploy nginx-ingress-integrator
juju deploy my-charm
juju relate nginx-ingress-integrator my-charm:nginx-route
# The service is now reachable on the ingress IP(s) of your k8s cluster at
# 'http://my-charm'.
juju config nginx-ingress-integrator service-hostname='my-charm.example.com'
# The service is now reachable on the ingress IP(s) of your k8s cluster at
# 'http://my-charm.example.com'.
```
"""
import logging
import typing
Expand All @@ -69,7 +86,7 @@

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 2
LIBPATCH = 3

__all__ = ["require_nginx_route", "provide_nginx_route"]

Expand Down Expand Up @@ -153,7 +170,9 @@ def _config_reconciliation(self, _event: typing.Any = None) -> None:
relation_app_data.update({k: str(v) for k, v in self._config.items()})


def require_nginx_route( # pylint: disable=too-many-locals,too-many-branches
# C901 is ignored since the method has too many ifs but wouldn't be
# necessarily good to reduce to smaller methods.
def require_nginx_route( # pylint: disable=too-many-locals,too-many-branches # noqa: C901
*,
charm: ops.charm.CharmBase,
service_hostname: str,
Expand Down Expand Up @@ -303,6 +322,9 @@ def _on_relation_changed(self, event: ops.charm.RelationChangedEvent) -> None:

Args:
event: Event triggering the relation-changed hook for the relation.

Raises:
RuntimeError: if _on_relation changed is triggered by a broken relation.
"""
# `self.unit` isn't available here, so use `self.model.unit`.
if not self._charm.model.unit.is_leader():
Expand Down Expand Up @@ -376,6 +398,10 @@ def provide_nginx_route(
on_nginx_route_broken: Callback function for the nginx-route-broken event.
nginx_route_relation_name: Specifies the relation name of the relation handled by this
provider class. The relation must have the nginx-route interface.

Raises:
RuntimeError: If provide_nginx_route was invoked twice with
the same nginx-route relation name
"""
if __provider_references.get(charm, {}).get(nginx_route_relation_name) is not None:
raise RuntimeError(
Expand Down
13 changes: 1 addition & 12 deletions lib/charms/prometheus_k8s/v0/prometheus_scrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,7 @@ def _on_scrape_targets_changed(self, event):
from collections import defaultdict
from pathlib import Path
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
from urllib.error import HTTPError, URLError
from urllib.parse import urlparse
from urllib.request import urlopen

import yaml
from charms.observability_libs.v0.juju_topology import JujuTopology
Expand All @@ -370,7 +368,7 @@ def _on_scrape_targets_changed(self, event):

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 38
LIBPATCH = 39

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -2266,16 +2264,7 @@ def _static_config_extra_labels(self, target: Dict[str, str]) -> Dict[str, str]:
logger.debug("Could not perform DNS lookup for %s", target["hostname"])
dns_name = target["hostname"]
extra_info["dns_name"] = dns_name
label_re = re.compile(r'(?P<label>juju.*?)="(?P<value>.*?)",?')

try:
with urlopen(f'http://{target["hostname"]}:{target["port"]}/metrics') as resp:
data = resp.read().decode("utf-8").splitlines()
for metric in data:
for match in label_re.finditer(metric):
extra_info[match.group("label")] = match.group("value")
except (HTTPError, URLError, OSError, ConnectionResetError, Exception) as e:
logger.debug("Could not scrape target: %s", e)
return extra_info

@property
Expand Down
Loading