Skip to content

About

A Charmed Operator for running Ory Hydra on Kubernetes

Topics

Resources

Contributing

Security policy

Stars

9 stars

Watchers

4 watching

Forks

Latest commit

 

History

1,357 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Charmed Ory Hydra

CharmHub Badge Juju License

Continuous Integration Status pre-commit Conventional Commits

Description

Python Operator for Ory Hydra - a scalable, security first OAuth 2.0 and OpenID Connect server. For more details and documentation, visit https://www.ory.sh/docs/hydra/.

Usage

juju deploy postgresql-k8s --channel 14/stable --trust
juju deploy self-signed-certificates --channel latest/stable --trust
juju deploy identity-platform-login-ui-operator --channel latest/edge --trust
juju deploy traefik-k8s --channel latest/stable --trust

juju deploy hydra --trust

juju integrate postgresql-k8s hydra
juju integrate identity-platform-login-ui-operator hydra
juju integrate traefik-k8s:certificates self-signed-certificates:certificates
juju integrate traefik-k8s hydra:public-ingress

You can follow the deployment status with watch -c juju status --color.

Integrations

PostgreSQL

This charm requires an integration with postgresql-k8s-operator.

Ingress

The Hydra Operator offers integration with the traefik-k8s-operator for ingress. Hydra has two APIs which can be exposed through ingress, the public API and the admin API.

If you have traefik deployed and configured in your hydra model, to provide ingress to the admin API run:

juju integrate traefik-admin hydra:admin-ingress

To provide ingress to the public API run:

juju integrate traefik-public hydra:public-ingress

Note that the public ingress needs to be secured with HTTPS if the charm config dev is not true.

Kratos

This charm offers integration with kratos-operator. In order to integrate hydra with kratos, it needs to be able to access hydra's admin API endpoint. To enable that, integrate the two charms:

juju integrate kratos hydra

Identity Platform Login UI

The following instructions assume that you have deployed traefik-admin and traefik-public charms and integrated them with hydra. Note that the UI charm should run behind a proxy.

This charm offers integration with identity-platform-login-ui-operator. In order to integrate them, run:

juju integrate hydra:ui-endpoint-info identity-platform-login-ui-operator:ui-endpoint-info
juju integrate identity-platform-login-ui-operator:hydra-endpoint-info hydra:hydra-endpoint-info

Run Hydra from backup

When migrating an Ory Hydra instance—for example, to a new server or environment—you need to ensure the new instance can decrypt existing user sessions and data. Hydra relies on two crucial secrets for this:

  1. System Secret: Used to encrypt sensitive data stored in the database, such as session payloads and JSON Web Key Sets (JWKS).
  2. Cookie Secret: Used to encrypt and sign Hydra's cookies.

If you restore Hydra from a database backup without using the original secrets, the new instance will generate its own, rendering the backed-up data unusable. The Charmed Hydra Operator provides several helper actions and configuration options to manage these secrets and enable seamless server migration.

Key Management Actions

The operator includes two Juju actions for managing secrets on a running Hydra instance.

get-secret-keys

This action retrieves the current secret keys used by Hydra. It's essential for backing up secrets before a migration.

# Get the system secret keys
juju run hydra/0 get-secret-keys type=system

# Get the cookie secret keys
juju run hydra/0 get-secret-keys type=cookie

add-secret-key

This action adds a new secret key to Hydra's configuration. This is useful for key rotation or for adding a key from a backup to an existing deployment.

juju run hydra/0 add-secret-key type=cookie key=YOUR_NEW_COOKIE_SECRET

NOTE: key length MUST be >16 characters

Config

When deploying a new Hydra instance, you can use the following Juju configuration options to pre-seed the secrets, preventing the charm from generating new ones. These configurations only work on the initial deployment.

  • initial_system_secret_id: The ID of a Juju secret containing the system keys.
  • initial_cookie_secret_id: The ID of a Juju secret containing the cookie keys.

These config have no effect after the charm has been deployed and secrets have been generated.

Migration Walkthrough

Let's walk through a common server migration scenario. Assume you have an existing Hydra deployment (old-model) integrated with a PostgreSQL database, and you want to migrate it to a new Juju model (new-model).

First we need to get the old Hydra secret keys:

$ juju run -m old-model hydra/0 get-secret-keys type=system -q
system: '["old-system-key-1", "old-system-key-2"]'

$ juju run -m old-model hydra/0 get-secret-keys type=cookie -q
cookie: '["old-cookie-key-1", "old-cookie-key-2"]'

In your new model, create Juju secrets using the values you just retrieved:

$ juju add-secret -m new-model hydra-system-keys system1=old-system-key-1 system2=old-system-key-2

$ juju add-secret -m new-model hydra-cookie-keys cookie1=old-cookie-key-1 cookie2=old-cookie-key-2

💡 Important: The order of the key-value pairs matters. The first key you provide (e.g., system1) will become the primary secret for the new Hydra instance.

Now we can deploy the Hydra in the new model, referencing the Juju secrets you just created:

juju deploy -m new-model hydra --config initial_system_secret_id=secret:<system-secret-id> --config initial_cookie_secret_id=secret:<cookie-secret-id>

After deployment, you must grant the Hydra charm access to the secrets:

juju grant-secret -m new-model system hydra
juju grant-secret -m new-model cookie hydra

Now, integrate the new Hydra instance with your migrated PostgreSQL database and any other necessary applications:

juju integrate -m new-model hydra postgresql
# ... integrate with other applications as needed

Once the new Hydra instance is running and integrated, it should be able to decrypt and use the backed-up database data seamlessly. You can verify this by checking that the new instance's JWKS endpoint (https://hydra-url/.well-known/jwks.json) matches the one from your old deployment.

Listing and Exporting OAuth Clients

The list-oauth-clients action inspects registered OAuth 2.0 clients through either paginated inline responses or a complete JSON file export.

Default and Paginated Inline Listing

When invoked without parameters, list-oauth-clients returns a single page of at most 100 clients in the clients JSON string:

juju run hydra/0 list-oauth-clients

When no OAuth clients are registered, the action succeeds with clients: '[]' and omits next-page-token. When more pages remain, the action includes a non-empty next-page-token in the result (it never returns an is-last-page field). Pass that opaque value back as page-token to retrieve the next page, and optionally adjust page-size (default 100):

juju run hydra/0 list-oauth-clients page-size=50
juju run hydra/0 list-oauth-clients page-size=50 page-token=<next-page-token>

Inline action results are bounded by a conservative 90 KiB UTF-8 encoded budget (covering result keys, serialized clients, and continuation metadata) to stay within Juju's practical action result limit. If a page exceeds 90 KiB, the action fails without truncating the client list and instructs you to specify a smaller page-size or export=json.

Complete JSON Export and Retrieval

To export the entire OAuth client inventory across all pages into a JSON file in the charm container, set export=json. You may optionally pass page-size to control the per-page fetch batch size, but export=json always starts from the first page and cannot be combined with a non-empty page-token:

juju run hydra/0 list-oauth-clients export=json

In export mode, the action returns only file location and count metadata (export-path, export-unit, export-container, and client-count) and omits clients and next-page-token. Download the file with juju scp using the exact export-unit, export-container, and export-path returned by the action:

juju scp --container charm \
  hydra/0:/var/lib/juju/agents/unit-hydra-0/charm/oauth-client-exports/oauth-clients.json \
  ./oauth-clients.json

Always use the returned export-unit (for example hydra/0) rather than hydra/leader, because leadership can change between running the action and copying the file.

Operational Constraints and Retention

  • Secret exclusion: Both inline results and exported JSON files exclude OAuth client secrets (client-secret). Exporting clients is not a secret backup mechanism.
  • Empty inventory success: An empty client inventory succeeds in both modes, producing clients: '[]' inline or a JSON file containing [] with client-count: 0.
  • Resource budgets and deadline: Exports enforce a maximum file size of 100 MiB and a five-minute (300-second) total deadline. If any page fetch fails, times out, repeats a continuation token, or exceeds 100 MiB, the action fails, removes incomplete output, and leaves any previous completed export on that unit intact.
  • Latest-only temporary retention: Each unit writes exports to a private directory (0700) and file (0600) at <charm-dir>/oauth-client-exports/oauth-clients.json inside the charm container, retaining only the latest successful export on that unit. Running another successful export on the same unit atomically replaces the previous file, and unit restarts or pod replacements remove temporary files. Retrieve each export with juju scp before starting another export on that unit.
  • Non-snapshot semantics: Paginated listing and export=json fetch pages sequentially from Hydra and do not provide a transactional snapshot if clients are created, modified, or deleted concurrently.
  • Upgraded charm revision required: The page-size, page-token, and export parameters require refreshing the application to a charm revision that defines the updated list-oauth-clients action schema.

OCI Images

The image used by this charm is hosted on Docker Hub and maintained by Ory.

Security

Please see SECURITY.md for guidelines on reporting security issues.

Contributing

Please see the Juju SDK docs for guidelines on enhancements to this charm following best practice guidelines, and CONTRIBUTING.md for developer guidance.

License

The Charmed Hydra Operator is free software, distributed under the Apache Software License, version 2.0. See LICENSE for more information.

About

A Charmed Operator for running Ory Hydra on Kubernetes

Topics

Resources

Contributing

Security policy

Stars

9 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages