Skip to content

feat: add the sso-service charm - #4

Draft
nsklikas wants to merge 7 commits into
mainfrom
sso-service-charm
Draft

nsklikas wants to merge 7 commits into
mainfrom
sso-service-charm

Conversation

@nsklikas

@nsklikas nsklikas commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

What

The Kubernetes charm of the SSO Service, which holds the SSO connections of Bring Your Own SSO. It is written on tenant-service-operator's code and structure, and it routes over istio_ingress_route only. Its specification is #3: read that first. That pull request is stacked on this one, not under it, because main has no charm yet and its required checks cannot run on a pull request that has only the specification. This pull request shows only the code.

  • The service and its database (pg-database): the leader runs the migrations, and the service does not start with one pending (run-migration for a manual run).
  • The second Hydra (hydra-sso): the charm is its login and consent provider (ui-endpoint-info, hydra-endpoint-info), registers Kratos's client there (byo-sso-client) and hands Kratos its one byo-sso provider (kratos-external-idp). The login UI gets the service's gRPC address (sso-service-info).
  • Routes: the browser pages on the public gateway under /sso, and the management API on the internal gateway, which has to authorize each request.
  • The envelope key in one Juju secret, generated by the leader in its first hook (get-envelope-key; initial_envelope_key_secret_id to start from a restored key).
  • Callers' tokens are verified against the main Hydra (oauth) or another issuer (authn_issuer, with authn_jwks_url or the keys the service discovers), optionally limited by subject or scope.
  • A proxy for the service's outbound requests, as tenant-service-operator: http_proxy, https_proxy and no_proxy set HTTP_PROXY, HTTPS_PROXY and NO_PROXY in the workload. The service also calls Kratos, hydra-sso and the Tenant Service, so no_proxy has to name the cluster's hosts.
  • Observability as the other charms (logging, tracing, metrics-endpoint with alert rules, grafana-dashboard), receive-ca-cert, and a Terraform module.

Where the code differs from tenant-service-operator's, on purpose

  • The leader publishes its relation data and its routes before the database is ready: the related charms need neither this workload nor its database.
  • The migration check asks the workload once a hook, a failed check migrates nothing, and a failed migration or check is a Blocked status with the reason.
  • A configured initial envelope key that cannot be read, or that differs from the key in use, blocks: a restored database is never started with a new key.
  • The CA bundle is read once a hook, and pushed again after a restart of the workload container alone. A failed update is tried again, and a bundle with CRLF line endings equals its copy: that fix is proposed for tenant-service-operator too (fix: retry a failed CA bundle update and compare the bundle byte for byte tenant-service-operator#65).
  • The DSN percent-encodes the user and the password, and no command line is logged whole: a DSN is an argument.
  • What the service refuses to start without is checked before a plan, one condition and one status each. A tracing provider that has sent no HTTP endpoint is tolerated.

Good to know

  • The interface library is a package. Charmhub takes no new libraries, so sso_service_info is a Python package in this repository (interfaces/sso_service_info), not a file under lib/. The login UI's charm installs it from git at a commit of this branch (feat: add Bring Your Own SSO behind byosso_enabled identity-platform-login-ui-operator#543), and has to pin it again once this merges. Nothing of it is released to Charmhub, and the library release workflow is removed.

  • The image is a development build, ghcr.io/canonical/sso-service:bysso-d3b8476c: the SSO Service has no release yet. That build is older than the service's renamed metrics (sso_attempts_verified_total, sso_verify_attempt_refused_total), so the dashboard's panel of attempts stays empty with it. The pin moves to the first release before this merges.

  • Port 50051 serves the sign-in service without a token, as the Tenant Service's port does for its own, and some of the methods write. Nothing closes those ports to other workloads in the cluster: no charm of the platform ships a NetworkPolicy or a mesh policy. The README says the deployment has to.

  • The public gateway has to be the one the login UI is served on. The charm does not check it.

  • Kratos's client secret at hydra-sso is in the relation data, as every provider of the external_provider interface publishes it today. There is no Juju secret for it.

  • Kratos gets the byo-sso provider as soon as hydra-sso has made the client, whether or not the login UI runs the feature. A login UI with it off shows that provider on its pages, and a click ends in a refusal.

  • The envelope key: get-envelope-key returns it as an action result, which anyone with read access to the model can read. Nothing ties it to the database: an application removed and deployed again under the same name generates a new key for a database whose client secrets the old one sealed. It cannot be rotated.

  • CA certificates: with a provider whose first write is the old unit data (self-signed-certificates does that on a new relation), the unit is active without a usable CA for some minutes after the relation is made.

  • Smaller limits: the Pebble check has no level, so a pod is Ready whether or not the service runs; the two workload alerts need more traffic than a new deployment has; PUBLIC_URL lowercases the gateway's host and drops :443, and the redirect URI of a tenant's SSO connections has that spelling.

  • It needs, from other charms: feat: configure Kratos for multitenancy from the login UI's relation kratos-operator#774, feat: accept a login UI that publishes no device-flow URLs hydra-operator#657, feat: publish the scope that admits a caller in tenant-service-info tenant-service-operator#63, feat: skip the registration webhook for the byo-sso provider tenant-service-operator#64 and feat: add Bring Your Own SSO behind byosso_enabled identity-platform-login-ui-operator#543. Where the Tenant Service limits callers by scope and its charm does not publish it, the Tenant Service refuses every call while this charm is active.

  • The feature also needs a Tenant Service image that has feat: add tenant SSO policy, sign-in context and pending invitations tenant-service#140. tenant-service-operator still pins v0.2.0, which does not.

  • The Terraform workflow gets the permission to comment on a pull request (pull-requests: write, as the login UI operator's has): its last step failed without it. It is the last commit here.

Tests

  • Unit tests (Scenario): 96 pass.
  • Integration tests: 7 of 7 pass on MicroK8s. They deploy the charm with PostgreSQL alone and do not start the service: they cover the blocked state, the migration and the envelope key through their actions, scaling, and the database integration removed and added again.
  • An earlier version of this charm was deployed with the rest of the platform on MicroK8s (Juju 3.6, Istio, Hydra and Kratos 25.4.0): a browser suite of 84 sign-in cases passed twice in a row, and the alerts, the log rule and the dashboard were checked against Prometheus, Loki and Grafana. The code as proposed has not been deployed with the platform: it has the unit and integration tests above.

The libraries of the relations the charm takes part in, as Charmhub has
them. The one exception is tenant_service_info, which is the copy of
canonical/tenant-service-operator's pull request that adds the scope a
caller is admitted by (LIBPATCH 2).
The Kubernetes charm of the SSO Service, which lets a tenant sign its
members in with its own OIDC identity provider. Its code and structure
follow tenant-service-operator's.

The charm runs the service with its database and migrates it on the
leader. It exposes the browser pages and the management API over
istio_ingress_route. It is the login and consent provider of a second
Hydra, registers Kratos's client there and gives Kratos its one byo-sso
provider. It publishes its gRPC address to the login UI, through the
interface package in interfaces/sso_service_info, because Charmhub takes
no new libraries. It keeps the envelope key in a Juju secret, verifies
callers' tokens against the main Hydra or another issuer, applies the CA
bundle of receive-ca-cert, and integrates with the observability stack.
A Terraform module comes with it.

Nothing of the charm is released to Charmhub as a library, so the
library release workflow of the skeleton goes.
Unit tests on ops.testing, state in and state out. The integration tests
deploy the charm with PostgreSQL alone and cover what it does without
the rest of the platform: the integration it blocks on, the database
migration and the envelope key through their actions, scaling, and the
database integration removed and added again.
The job's last step comments its result on the pull request and failed with "Resource not accessible by integration", because the job did not ask for the permission. The format, init and validate steps passed.
@github-actions

Copy link
Copy Markdown

Terraform Format and Style 🖌success

Terraform Initialization ⚙️success

Terraform Validation 🤖success

Validation Output

Success! The configuration is valid.


Pusher: @nsklikas, Action: pull_request, Workflow: Pull Request on Terraform Module

The http_proxy, https_proxy and no_proxy options set HTTP_PROXY,
HTTPS_PROXY and NO_PROXY in the workload, as in tenant-service-operator.
The image is the build that sends the requests to identity providers
through that proxy.
nsklikas added a commit to canonical/tenant-service-operator that referenced this pull request Nov 23, 2026
…byte (#65)

## What

Two gaps in how the charm applies the CA bundle of `receive-ca-cert`
(`_ensure_tls`). Nothing has to merge before this, and nothing waits for
it.

**A failed update was not always tried again.** The charm keeps a copy
of the bundle and acts only when the bundle differs from it. It wrote
the copy before it ran `update-ca-certificates` and pushed the result to
the workload, and it handled only a failure of the first step, by
removing the copy:

- when the push to the workload failed (a Pebble error), the hook
failed, and the retried hook found the copy equal to the bundle and did
nothing: the unit ended active without the CA;
- when the bundle was removed and either step failed, the copy was
already gone, so the removal was never retried and the workload kept the
removed CA.

Both steps are now in one `try`, a Pebble error and an `OSError` (a
request to Pebble that times out, a missing binary) are caught too, and
on failure the earlier copy is put back, so the next reconciliation sees
a difference and runs both steps again.

**A bundle with CRLF line endings never equalled its copy.** The copy
was read as text, which turns `\r\n` into `\n`, so every hook wrote the
copy again, ran `update-ca-certificates` and pulled the workload's file
to compare. The copy is now read without newline translation.

## Good to know

- The CRLF gap did not restart the service: the push happens only when
the workload's file differs.
- **Not changed**: a restart that fails after a successful push is not
forced again on the next hook.
- **Not changed**: when the workload container restarts alone, its
bundle goes back to the image's while the charm's copy still equals the
relation's, so nothing is pushed until the bundle changes or the pod is
replaced.
- The SSO Service's charm has the same method with the same change
(canonical/sso-service-operator#4), and forgets its copy at pebble-ready
for the case above.

## Tests

- Unit tests, one per decision: a failed push is retried (Pebble down,
and Pebble not answering in time), a failed removal is retried, an
applied bundle with CRLF line endings is not applied again. Each fails
without its part of the fix.
- 150 unit tests pass. Not deployed.
sso-service renamed sso_attempts_completed_total to sso_attempts_verified_total, and sso_complete_attempt_refused_total to sso_verify_attempt_refused_total.
nsklikas added a commit to canonical/tenant-service-operator that referenced this pull request Nov 23, 2026
)

## What

A service that calls the Tenant Service with its own client has to ask
for the scope the Tenant Service admits tokens by
(`authn_allowed_scope`). So far the operator had to repeat that scope in
an option of the calling charm. This charm now publishes it in
`tenant-service-info`, next to the URLs.

- **`tenant_service_info` library, LIBPATCH 2**:
`ProviderData.allowed_scope` (optional, empty by default), a third
argument to `update_relations_app_data`, and `get_allowed_scope()` on
the requirer.
- **The charm publishes its `authn_allowed_scope`.** With the option
unset nothing is published.
- **The charm observes the library's `ready`**, so a requirer that
relates to a running Tenant Service gets the address and the scope at
once.
- The option's text and the charm specification say that the scope is
one scope, and that it is published to related charms, which register it
on their clients.

Nothing has to merge before this. The SSO Service's charm reads the
scope, registers it on its client and asks for it, and has no option for
it (canonical/sso-service-operator#4): this pull request goes before
that one.

## Good to know

- **Either side can be upgraded first.** A requirer on LIBPATCH 1
ignores the field, and a provider on LIBPATCH 1 publishes none, which
reads as no scope.
- **The `ready` observer closes a gap that `main` has.** Without it the
data reached a new requirer at the Tenant Service's next reconciliation,
on a settled deployment the next `update-status`: a login UI and an SSO
Service each waited about four minutes after their relation was made. It
matters more now that the scope travels here.

## Tests

- Unit tests: the charm publishes the scope it is configured with, and
none without one; the handler runs when a requirer relates.
- Deployed with the rest of the platform on MicroK8s (Juju 3.6, Istio,
Hydra and Kratos 25.4.0), as a charm packed from this branch and #64
together, with the other charms of the series as they were at that time:
a browser suite of 84 sign-in cases passed twice in a row.
- On that deployment the scope was in the relation data and on the SSO
Service's client at Hydra, a policy read through the SSO Service (which
calls the Tenant Service with that token) was answered, and a requirer
related to the running charm got the address and the scope within
seconds.
nsklikas added a commit to canonical/tenant-service-operator that referenced this pull request Nov 23, 2026
## What

The body the charm gives Kratos for the registration webhook now cancels
the call when the registration came through the `byo-sso` provider, the
provider of the login UI's Bring Your Own SSO
(canonical/identity-platform-login-ui#993). Such a user was invited to a
tenant or admitted by its auto-join, and gets no personal tenant. Kratos
skips a webhook whose body evaluates to `error "cancel"`. Every other
registration sends the body it sent before.

The body compares the end of the request URL's path with the provider's
callback path, with or without the trailing slash that Kratos v25 also
routes. A provider whose id merely starts with `byo-sso`, and a
registration whose query string carries that path, do not cancel.

Nothing has to merge before this. The feature as a whole needs it, with
the SSO Service's charm (canonical/sso-service-operator#4).

## Good to know

- **Best effort, by construction.** Kratos completes the same
registration on its generic callback path
(`/self-service/methods/oidc/callback`, the provider taken from the
state) and on a percent-escaped spelling of the path, and the hook's
context does not name the provider. A person who edits their own
redirect back from the identity provider gets the webhook sent, and with
it a personal tenant next to the tenant that admitted them. Closing that
needs the Tenant Service to decide, not the body.
- **Not in this change, and a blocker for the feature: the image pin.**
The charm still pins tenant-service v0.2.0, and sets the OpenFGA
settings the service dropped with its federation. No release of the
Tenant Service has the services the login UI and the SSO Service call
for Bring Your Own SSO (canonical/tenant-service#140). Until the pin
moves to one that does, the feature cannot be turned on with this charm:
the login UI's charm would report Active and every tenant lookup would
answer `Unimplemented`.

## Tests

- A unit test that the charm publishes that condition around the cancel.
- How jsonnet evaluates the body is not proven by the suite: the body
was evaluated with the go-jsonnet version Kratos uses. The callback
cancels, with a slash too; `byo-sso2`, `byo-sso-staging`, the
registration URL with the path in its query, and another provider do
not.
- Deployed with the rest of the platform on MicroK8s (Juju 3.6, Istio,
Hydra and Kratos 25.4.0), as a charm packed from this branch and #63
together, with the other charms of the series as they were at that time:
a browser suite of 84 sign-in cases passed twice in a row. The
deployment ran the image of canonical/tenant-service#140 with
`authorization_enabled=false`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant