Metadata-Version: 2.4
Name: wormhole-route-registry
Version: 0.1.0
Summary: Registry mapping routes to target urls with authorization
Author-email: Thomas Mendoza <thomas@matalino.software>
Maintainer-email: Thomas Mendoza <thomas@matalino.software>, Conner Cook <cook107@llnl.gov>, Urwah Mir <mir2@llnl.gov>, John Consolati <consolati1@llnl.gov>
License: Apache License
        Version 2.0, January 2004
        http://www.apache.org/licenses/
        
        TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
        
        1. Definitions.
        
        "License" shall mean the terms and conditions for use, reproduction,
        and distribution as defined by Sections 1 through 9 of this document.
        
        "Licensor" shall mean the copyright owner or entity authorized by
        the copyright owner that is granting the License.
        
        "Legal Entity" shall mean the union of the acting entity and all
        other entities that control, are controlled by, or are under common
        control with that entity. For the purposes of this definition,
        "control" means (i) the power, direct or indirect, to cause the
        direction or management of such entity, whether by contract or
        otherwise, or (ii) ownership of fifty percent (50%) or more of the
        outstanding shares, or (iii) beneficial ownership of such entity.
        
        "You" (or "Your") shall mean an individual or Legal Entity
        exercising permissions granted by this License.
        
        "Source" form shall mean the preferred form for making modifications,
        including but not limited to software source code, documentation
        source, and configuration files.
        
        "Object" form shall mean any form resulting from mechanical
        transformation or translation of a Source form, including but
        not limited to compiled object code, generated documentation,
        and conversions to other media types.
        
        "Work" shall mean the work of authorship, whether in Source or
        Object form, made available under the License, as indicated by a
        copyright notice that is included in or attached to the work
        (an example is provided in the Appendix below).
        
        "Derivative Works" shall mean any work, whether in Source or Object
        form, that is based on (or derived from) the Work and for which the
        editorial revisions, annotations, elaborations, or other modifications
        represent, as a whole, an original work of authorship. For the purposes
        of this License, Derivative Works shall not include works that remain
        separable from, or merely link (or bind by name) to the interfaces of,
        the Work and Derivative Works thereof.
        
        "Contribution" shall mean any work of authorship, including
        the original version of the Work and any modifications or additions
        to that Work or Derivative Works thereof, that is intentionally
        submitted to Licensor for inclusion in the Work by the copyright owner
        or by an individual or Legal Entity authorized to submit on behalf of
        the copyright owner. For the purposes of this definition, "submitted"
        means any form of electronic, verbal, or written communication sent
        to the Licensor or its representatives, including but not limited to
        communication on electronic mailing lists, source code control systems,
        and issue tracking systems that are managed by, or on behalf of, the
        Licensor for the purpose of discussing and improving the Work, but
        excluding communication that is conspicuously marked or otherwise
        designated in writing by the copyright owner as "Not a Contribution."
        
        "Contributor" shall mean Licensor and any individual or Legal Entity
        on behalf of whom a Contribution has been received by Licensor and
        subsequently incorporated within the Work.
        
        2. Grant of Copyright License. Subject to the terms and conditions of
        this License, each Contributor hereby grants to You a perpetual,
        worldwide, non-exclusive, no-charge, royalty-free, irrevocable
        copyright license to reproduce, prepare Derivative Works of,
        publicly display, publicly perform, sublicense, and distribute the
        Work and such Derivative Works in Source or Object form.
        
        3. Grant of Patent License. Subject to the terms and conditions of
        this License, each Contributor hereby grants to You a perpetual,
        worldwide, non-exclusive, no-charge, royalty-free, irrevocable
        (except as stated in this section) patent license to make, have made,
        use, offer to sell, sell, import, and otherwise transfer the Work,
        where such license applies only to those patent claims licensable
        by such Contributor that are necessarily infringed by their
        Contribution(s) alone or by combination of their Contribution(s)
        with the Work to which such Contribution(s) was submitted. If You
        institute patent litigation against any entity (including a
        cross-claim or counterclaim in a lawsuit) alleging that the Work
        or a Contribution incorporated within the Work constitutes direct
        or contributory patent infringement, then any patent licenses
        granted to You under this License for that Work shall terminate
        as of the date such litigation is filed.
        
        4. Redistribution. You may reproduce and distribute copies of the
        Work or Derivative Works thereof in any medium, with or without
        modifications, and in Source or Object form, provided that You
        meet the following conditions:
        
        (a) You must give any other recipients of the Work or
        Derivative Works a copy of this License; and
        
        (b) You must cause any modified files to carry prominent notices
        stating that You changed the files; and
        
        (c) You must retain, in the Source form of any Derivative Works
        that You distribute, all copyright, patent, trademark, and
        attribution notices from the Source form of the Work,
        excluding those notices that do not pertain to any part of
        the Derivative Works; and
        
        (d) If the Work includes a "NOTICE" text file as part of its
        distribution, then any Derivative Works that You distribute must
        include a readable copy of the attribution notices contained
        within such NOTICE file, excluding those notices that do not
        pertain to any part of the Derivative Works, in at least one
        of the following places: within a NOTICE text file distributed
        as part of the Derivative Works; within the Source form or
        documentation, if provided along with the Derivative Works; or,
        within a display generated by the Derivative Works, if and
        wherever such third-party notices normally appear. The contents
        of the NOTICE file are for informational purposes only and
        do not modify the License. You may add Your own attribution
        notices within Derivative Works that You distribute, alongside
        or as an addendum to the NOTICE text from the Work, provided
        that such additional attribution notices cannot be construed
        as modifying the License.
        
        You may add Your own copyright statement to Your modifications and
        may provide additional or different license terms and conditions
        for use, reproduction, or distribution of Your modifications, or
        for any such Derivative Works as a whole, provided Your use,
        reproduction, and distribution of the Work otherwise complies with
        the conditions stated in this License.
        
        5. Submission of Contributions. Unless You explicitly state otherwise,
        any Contribution intentionally submitted for inclusion in the Work
        by You to the Licensor shall be under the terms and conditions of
        this License, without any additional terms or conditions.
        Notwithstanding the above, nothing herein shall supersede or modify
        the terms of any separate license agreement you may have executed
        with Licensor regarding such Contributions.
        
        6. Trademarks. This License does not grant permission to use the trade
        names, trademarks, service marks, or product names of the Licensor,
        except as required for reasonable and customary use in describing the
        origin of the Work and reproducing the content of the NOTICE file.
        
        7. Disclaimer of Warranty. Unless required by applicable law or
        agreed to in writing, Licensor provides the Work (and each
        Contributor provides its Contributions) on an "AS IS" BASIS,
        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
        implied, including, without limitation, any warranties or conditions
        of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
        PARTICULAR PURPOSE. You are solely responsible for determining the
        appropriateness of using or redistributing the Work and assume any
        risks associated with Your exercise of permissions under this License.
        
        8. Limitation of Liability. In no event and under no legal theory,
        whether in tort (including negligence), contract, or otherwise,
        unless required by applicable law (such as deliberate and grossly
        negligent acts) or agreed to in writing, shall any Contributor be
        liable to You for damages, including any direct, indirect, special,
        incidental, or consequential damages of any character arising as a
        result of this License or out of the use or inability to use the
        Work (including but not limited to damages for loss of goodwill,
        work stoppage, computer failure or malfunction, or any and all
        other commercial damages or losses), even if such Contributor
        has been advised of the possibility of such damages.
        
        9. Accepting Warranty or Additional Liability. While redistributing
        the Work or Derivative Works thereof, You may choose to offer,
        and charge a fee for, acceptance of support, warranty, indemnity,
        or other liability obligations and/or rights consistent with this
        License. However, in accepting such obligations, You may act only
        on Your own behalf and on Your sole responsibility, not on behalf
        of any other Contributor, and only if You agree to indemnify,
        defend, and hold each Contributor harmless for any liability
        incurred by, or claims asserted against, such Contributor by reason
        of your accepting any such warranty or additional liability.
        
        END OF TERMS AND CONDITIONS
        
        APPENDIX: How to apply the Apache License to your work.
        
        To apply the Apache License to your work, attach the following
        boilerplate notice, with the fields enclosed by brackets "[]"
        replaced with your own identifying information. (Don't include
        the brackets!)  The text should be enclosed in the appropriate
        comment syntax for the file format. We also recommend that a
        file or class name and description of purpose be included on the
        same "printed page" as the copyright notice for easier
        identification within third-party archives.
        
        Copyright 2026, Lawrence Livermore National Security, LLC
        
        Licensed under the Apache License, Version 2.0 (the "License");
        you may not use this file except in compliance with the License.
        You may obtain a copy of the License at
        
        http://www.apache.org/licenses/LICENSE-2.0
        
        Unless required by applicable law or agreed to in writing, software
        distributed under the License is distributed on an "AS IS" BASIS,
        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
        See the License for the specific language governing permissions and
        limitations under the License.
        
        ---- LLVM Exceptions to the Apache 2.0 License ----
        
        As an exception, if, as a result of your compiling your source code, portions of this Software are embedded into an Object form of such source code, you may redistribute such embedded portions in such Object form without complying with the conditions of Sections 4(a), 4(b) and 4(d) of the License.
        
        In addition, if you combine or link compiled forms of this Software with software that is licensed under the GPLv2 ("Combined Software") and if a court of competent jurisdiction determines that the patent provision (Section 3), the indemnity provision (Section 9) or other Section of the License conflicts with the conditions of the GPLv2, you may retroactively and prospectively choose to deem waived or otherwise exclude such Section(s) of the License, but only in their entirety and only with respect to the Combined Software.
        
Keywords: wormhole_route_registry,authorization
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: NOTICE
Requires-Dist: attrs>=26.1.0
Requires-Dist: alembic>=1.18.4
Requires-Dist: dynaconf>=3.2.13
Requires-Dist: fastapi[standard]>=0.136.1
Requires-Dist: requests>=2.34.2
Requires-Dist: sqlalchemy>=2.0.49
Requires-Dist: tenacity>=9.1.4
Requires-Dist: multimethod>=2.0.2
Requires-Dist: pendulum>=3.2.0
Requires-Dist: authlib>=1.7.2
Requires-Dist: joserfc>=1.7.1
Requires-Dist: bcrypt>=5.0.0
Requires-Dist: tomli-w>=1.2.0
Requires-Dist: psycopg2>=2.9.12
Requires-Dist: itsdangerous>=2.2.0
Requires-Dist: APScheduler>=3.11.2
Requires-Dist: celery[librabbitmq]>=5.6.3
Requires-Dist: cryptography>=48.0.0
Requires-Dist: jsonschema>=4.26.0
Requires-Dist: fastapi-offline==1.7.6
Dynamic: license-file

# Route Registry

Route Registry is the Wormhole service that records routes, validates app
authorization metadata, and returns the connection details needed to reach apps
through Piko and Holepunch.

## Table of Contents

- [Description](#description)
- [How Route Registry Fits Into Wormhole](#how-route-registry-fits-into-wormhole)
- [Configuration](#configuration)
- [Deployment](#deployment)
- [Development](#development)
- [API and Workflow Notes](#api-and-workflow-notes)
- [Testing](#testing)
- [Developer Notes](#developer-notes)
- [Governance](#governance)

## Description

Route Registry is a Python FastAPI service that maps public Wormhole route names
and URLs to target tunnel endpoints with authorization metadata. It registers
routes for the Wormhole CLI, fetches and validates app-served
`/-/airlock/authz.json`, stores route/community/domain/user/group state, issues
Piko JWTs for tunnel access, and notifies Holepunch when route state changes.
Major dependencies include FastAPI, SQLAlchemy, Alembic, Dynaconf, Celery,
RabbitMQ, APScheduler, Authlib, cryptography, bcrypt, jsonschema, psycopg2, and
fastapi-offline.

The code uses a layered service architecture. `route_registry/command.py`
provides the CLI entry point for `run`, `listen-tasks`, `openapi`, and
`generate-jwks`; `route_registry/server.py` assembles FastAPI routes and
dependencies; `route_registry/routers` contains public and administrative API
routers; `route_registry/models.py` defines attrs-based domain objects;
`route_registry/pydantic_models.py` defines wire schemas; `route_registry/store`
and `route_registry/service/uow.py` implement SQLAlchemy repositories and unit
of work; `route_registry/services.py` contains domain workflows; and
`route_registry/celery.py` plus `route_registry/track.py` handle async route
validation and periodic status tracking.

Within Wormhole, Route Registry is the control-plane service that tells the CLI
and gateway how a named app should be reached. A route registration returns the
public Wormhole URL, the Airlock/Token Service JWT issuer URL, the Piko tunnel
connect URL, a route endpoint ID, and a signed Piko JWT. Holepunch consumes this
route state to configure Envoy, and Token Service/JWKS are used to authenticate
users and automated callers.

## How Route Registry Fits Into Wormhole

```mermaid
flowchart LR
    CLI["Wormhole CLI"]
    Registry["Route Registry API"]
    DB["Postgres"]
    Worker["Celery worker"]
    MQ["RabbitMQ"]
    Tracker["APScheduler tracker"]
    Token["Token Service"]
    Holepunch["Holepunch admin API"]
    Piko["Piko server"]
    App["Airlock-protected app"]

    CLI --> Registry
    Registry --> DB
    Registry --> Token
    Registry --> Piko
    Registry --> MQ
    MQ --> Worker
    Worker --> App
    Worker --> Holepunch
    Tracker --> DB
    Tracker --> Holepunch
```

The service bridges user-facing route creation and operator-facing gateway
state. It owns route metadata and validation, while Holepunch owns active proxy
behavior.

## Configuration

Route Registry uses Dynaconf. Defaults live in
`route_registry/config/settings.toml`; local overrides can be supplied with
`settings.toml`, `settings.local.toml`, `.secrets.toml`, or `DYNACONF_*`
environment variables.

Important configuration groups include:

| Group | Purpose |
| --- | --- |
| `server` | FastAPI host, port, and loop settings. |
| `db` | SQLAlchemy database URL and credentials. |
| `celery` | RabbitMQ broker and result backend configuration. |
| `auth` | Admin auth, JWT/JWKS, Token Service, and optional OIDC session auth. |
| `url` | Public entry URL, Piko tunnel URL, Token Service URL, and Holepunch admin URL. |
| `track.routes` | Route status check interval and stale-route threshold. |

Generate per-environment JWKS material rather than reusing local files:

```shell
uv run route_registry generate-jwks --write-settings --overwrite
```

This creates `jwks/private.pem`, `jwks/public.pem`, `jwks/kid.txt`, and a local
settings override when requested. Treat generated private keys as secrets.

## Deployment

### OpenShift and Helm

Production and development deployments are CI/OpenShift/Helm based. The parent
chart in `helm/route_registry` deploys:

- `route-registry-core`: FastAPI API service.
- `route-registry-worker`: Celery worker for route validation tasks.
- `postgres`: database stateful workload.
- `rabbitmq`: broker for Celery tasks.

The core image starts the API with OpenTelemetry instrumentation. The worker
image starts `route_registry listen-tasks`. The core deployment runs an init
container that executes `scripts/migrate-db`, which waits for Postgres and runs:

```shell
alembic upgrade head
```

Required runtime secrets include:

| Secret | Purpose |
| --- | --- |
| `postgres-credentials` | Supplies `POSTGRESQL_USER` and `POSTGRESQL_PASSWORD` to the API and migration container. |
| `rabbitmq-secret` | Supplies `rabbitmq-username` and `rabbitmq-password`. |
| `route-registry` | Supplies sensitive Dynaconf values such as auth/JWT/OIDC/admin secrets. |

Manual deployment from `route-registry/helm/route_registry` follows the normal
Helm pattern:

```shell
helm upgrade --install route-registry . -f values.yaml
```

CI validates, publishes, builds the API and worker images, copies images into
OpenShift, deploys pre-production automatically for new versions, and deploys
production manually.

### Local Database

Local development can use SQLite for basic API work, but use Postgres whenever
creating, testing, or reviewing Alembic migrations.

Start a local Postgres instance with Podman:

```shell
podman run --name some-postgres \
  -e POSTGRES_PASSWORD=secret \
  -p 5432:5432 \
  -d postgres:16.10
```

Update `settings.toml` or `settings.local.toml` with the local database URL and
credentials as needed.

## Development

Requirements:

- Python 3.11 or newer
- [uv](https://docs.astral.sh/uv/)
- Postgres for migration work
- RabbitMQ for worker and e2e flows

Create a local environment and install the package:

```shell
uv venv
uv pip install -e .
```

Run the API:

```shell
uv run route_registry run --host localhost --port 5001
```

Run the Celery worker:

```shell
uv run route_registry listen-tasks
```

Run migrations:

```shell
uv run alembic upgrade head
```

Generate OpenAPI:

```shell
uv run route_registry openapi
```

## API and Workflow Notes

Important workflows:

- Register a route: the API creates or updates route state, validates
  authorization metadata, and returns public URL plus Piko tunnel details.
- Validate route authorization: the worker fetches the app-served
  `/-/airlock/authz.json`, validates it against the configured JSON schema, and
  stores resulting allow/deny rules.
- Refresh Holepunch: route validation and tracking workflows call Holepunch
  admin endpoints so the gateway can refresh cached route state.
- Authenticate callers: dependencies support admin header auth, Token Service
  token exchange, route JWT rotation, and optional OIDC session auth.
- Manage communities: community routes allow shared policy and subtoken behavior
  across related routes.

The API is versioned under paths such as `/api/v1`, `/api/v2`, `/api/latest`,
and `/api/stable`.

## Testing

Run lint checks:

```shell
uvx tox -e lint
```

Run non-e2e tests:

```shell
uvx tox -- -m "not e2e"
```

Run e2e tests:

```shell
uv run route_registry generate-jwks --write-settings --overwrite
uvx tox -- -m e2e
```

E2E tests need live supporting resources such as RabbitMQ and generated local
JWKS/settings. Tox delegates to `pytest`, so specific tests can be selected with
normal pytest arguments after `--`.

## Developer Notes

- `alembic/versions` contains database migrations; use Postgres when creating
  or validating migrations.
- `tests/integration` covers repository, unit-of-work, and service behavior.
- `tests/e2e` exercises route registration, validation, JWT rotation, tracker
  status transitions, community endpoints, and admin CRUD.
- Generated artifacts such as virtual environments, local databases, caches, and
  JWKS private keys should not be treated as reusable deployment assets.

## Governance

Contributions are welcome. Contributors should look in `CONTRIBUTING.md` for
project guidelines on how to create and structure pull requests.

This project is licensed under the Apache 2.0 license with LLVM exception. The
full license text is available in `LICENSE`.

LLNL-CODE-2020712
