Skip to content

feat(pilot): add thin Central proxy + JWKS-based bench↔Central auth#164

Merged
prathameshkurunkar7 merged 12 commits into
frappe:mainfrom
prathameshkurunkar7:central-billing-client
Jul 18, 2026
Merged

feat(pilot): add thin Central proxy + JWKS-based bench↔Central auth#164
prathameshkurunkar7 merged 12 commits into
frappe:mainfrom
prathameshkurunkar7:central-billing-client

Conversation

@prathameshkurunkar7

@prathameshkurunkar7 prathameshkurunkar7 commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

feat(pilot): Central billing client + site-billing admin routes

The pilot side of the tab: a Central billing client and the sites//billing/* admin routes the site calls.

Adds

CentralClient billing methods (summary, plans, gateways, profile, payment-method setup/confirm/remove, top-up + checkout status, reconcile) — POST support + {"message": …} unwrap.
sites//billing/* routes (@require_scope) that proxy them. Usage meters are composed here — percentages from the bench host (psutil) merged with Central's plan labels.
Tests: client endpoint/verb/body/unwrap contract.
Depends on the Central PR - frappe/central#119.

Edit:

feat(pilot): thin Central proxy + JWKS-based bench↔Central auth

Stops mirroring Central's API inside Pilot and wires up the bench's two-way trust with Central.

Thin proxy: one allowlisted route (sites//central/) forwards pilot-facing Central calls with the bench's token — deletes ~15 hand-mirrored billing methods/routes. Adding a Central method now needs no Pilot change.

bench enroll: exchanges a bootstrap token for the bench's credential + JWKS config and writes them to bench.toml (idempotent; also reads a create-time metadata seed so first-boot enrollment needs no arguments).
Verifying Central-minted SIDs (downward auth) already existed on this branch and lines up with the new token shape.

- CentralClient billing methods (summary, plans, gateways, profile, payment setup/confirm/remove, top-up, reconcile)
- sites/<site>/billing/* admin routes; usage meters composed from host stats
- tests cover the client endpoint/verb/body contract

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Reviews (8): Last reviewed commit: "fix(admin): drop dead latest_system_metr..." | Re-trigger Greptile

Comment thread admin/backend/views/billing.py Outdated
Comment thread admin/backend/views/billing.py Outdated
Return the billing-error shape (not 500) when Central's summary isn't a dict, and
measure disk usage on the bench's own mount instead of root.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Comment thread admin/backend/views/billing.py Outdated
@adityahase

Copy link
Copy Markdown
Member

@tanmoysrt @Aradhya-Tripathi Are we showing any billing settings in Pilot? (AFAICT, the first iteration had the billing in the sidebar.

Otherwise, most of this is just a passthrough Site > Pilot > Central. Might as well be Site > Central.

@prathameshkurunkar7

Will it make anything simpler? Just thinking out loud.

@Aradhya-Tripathi

Copy link
Copy Markdown
Collaborator

We ideally dont want to show any billing information in Pilot and passthrough directly to central from site.

Cc: @Prathamesh correct me if thats not in your plan.

@prathameshkurunkar7

Copy link
Copy Markdown
Contributor Author

We ideally dont want to show any billing information in Pilot and passthrough directly to central from site.

Cc: @Prathamesh correct me if thats not in your plan.

We can't do this right? We decided on this because Central cannot directly authenticate requests from site. Site to Pilot has JWT authentication and Pilot to Central has the X-Pilot-Auth token via bench.toml.
@Aradhya-Tripathi @adityahase

@Aradhya-Tripathi

Copy link
Copy Markdown
Collaborator

We ideally dont want to show any billing information in Pilot and passthrough directly to central from site.

Cc: @Prathamesh correct me if thats not in your plan.

We can't do this right? We decided on this because Central cannot directly authenticate requests from site. Site to Pilot has JWT authentication and Pilot to Central has the X-Pilot-Auth token via bench.toml.
@Aradhya-Tripathi @adityahase

The in app billing lives but its centrals responsibility iirc.

@tanmoysrt

tanmoysrt commented Jul 13, 2026

Copy link
Copy Markdown
Member

Just a thought.

Maybe use pilot as proxy only ?
No need to implement the methods for api calls, it can be /central/<site_name>/<central's_api_route> or /central/<central's_api_route>

Pilot can attach some context like site name and its auth token to the request.

@prathameshkurunkar7

Copy link
Copy Markdown
Contributor Author

Just a thought.

Maybe use pilot as proxy only ? No need to implement the methods for api calls, it can be /central/<site_name>/<central's_api_route> or /central/<central's_api_route>

Pilot can attach some context like site name and its auth token to the request.

Pilot as proxy can work I suppose. Giving it a try.

@prathameshkurunkar7
prathameshkurunkar7 marked this pull request as draft July 13, 2026 09:24
@Prathamesh

Prathamesh commented Jul 13, 2026 via email

Copy link
Copy Markdown

prathameshkurunkar7 and others added 3 commits July 14, 2026 14:19
Replace the ~15 hand-mirrored billing methods (CentralClient) and their Flask
routes with one allowlisted proxy route: `sites/<site>/central/<method>`
forwards a pilot-facing Central call with the bench's X-Pilot-Token. Central
resolves team + asset from the credential, so no ids travel from the site.
CentralClient is now a thin transport (credentials + heartbeat + forward).
Adding a Central method needs no Pilot change.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
`bench enroll` exchanges a single-use bootstrap token for this bench's
long-lived Central credential + JWKS trust config, writing both into bench.toml
(idempotent). Seed resolution: explicit args → --seed-file → a canonical
metadata path, so a bare `bench enroll` on first boot picks up whatever VM
metadata dropped there. CentralConfig gains a transient `bootstrap_token`.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@prathameshkurunkar7 prathameshkurunkar7 changed the title feat(pilot): Central billing client + site-billing admin routes feat(pilot): add thin Central proxy + JWKS-based bench↔Central auth Jul 14, 2026
Condense the module/comment blocks and docstrings added for the Central proxy
and enrollment to at most two lines each, per the repo's low-verbosity guideline.
Comments only — no behaviour change.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@prathameshkurunkar7
prathameshkurunkar7 marked this pull request as ready for review July 15, 2026 05:07
@tanmoysrt

Copy link
Copy Markdown
Member

Linked issue : #185

Integrate the backend refactor (api/v1, providers, pilot/integrations).
Conflicts resolved: app.py taken from main; the Central proxy kept as-is.
Adapting the Central integration to the new layout is a follow-up.
…yout

Adapt the Central work to the structure merged from main:
- pilot/integrations/central/ package — client.py (CentralClient) + bootstrap.py
  (enrollment), public surface re-exported (matches git/ and s3/).
- admin/backend/api/v1/sites/central.py — proxy registered on sites_bp, using
  middleware.require_scope + api.responses.error_response.
- enroll command → pilot/commands/admin/enroll.py; central tests →
  tests/pilot/integrations/.
- Update the command-discovery and route-inventory baselines for the new enroll
  command and sites.central_proxy route.
@prathameshkurunkar7
prathameshkurunkar7 dismissed Aradhya-Tripathi’s stale review July 17, 2026 06:39

Did the requested change.

@tanmoysrt tanmoysrt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for now. Will refactor later if needed

prathameshkurunkar7 and others added 2 commits July 17, 2026 12:15
Bring in the config-module refactor (pilot/config/*_config.py -> *.py).
Re-add the Central integration's `bootstrap_token` on the new
CentralConfig (field + from_dict) after the modify/delete conflict, and
point the proxy test at the relocated admin_auth session helpers.
…Reader)

The function had no callers (it once backed the removed billing usage meters)
and referenced MonitorHistoryReader, which no longer exists — a merge artifact
that failed the mypy CI check. main has no such function. Removing it.
@prathameshkurunkar7
prathameshkurunkar7 merged commit 7b10a3b into frappe:main Jul 18, 2026
5 checks passed
tanmoysrt pushed a commit to tanmoysrt/bench-cli that referenced this pull request Jul 18, 2026
…g-client

feat(pilot): add thin Central proxy + JWKS-based Pilot↔Central auth
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.

5 participants