From 3dcaf3fbaf18e0fc195a231d06517b087c1b392c Mon Sep 17 00:00:00 2001 From: jerryfane Date: Sun, 15 Nov 2026 19:03:10 +0100 Subject: [PATCH] Service edit form: a checkbox for forward_role (156) Turning forward_role on needed pasted settings, which replace every field the paste names or omits. The edit form now has 'Tell the service which agent is calling'; the form owns it like its other fields (ticked keeps or sets it, unticked clears it); pasted settings still set it. --- README.md | 2 +- internal/dashboard/pages.go | 1 + internal/dashboard/services.go | 4 +++- internal/dashboard/services_test.go | 22 ++++++++++++++++++---- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e8571bd..4a6f5ba 100644 --- a/README.md +++ b/README.md @@ -247,7 +247,7 @@ A call is ` http:////` with header `X-Keyring-Tok - does not count a call against the daily limit if the service was unreachable; - writes one audit line per call, with no keys, tokens, query strings or bodies. The audit log, like the store, is refused if other users can read it. -**Naming the caller to a service you run.** With `"forward_role": true` on a service, every call carries `X-Keyring-Role: `, so a service the fleet runs itself (a build server, for example) can log which agent sent a call; through a relay all callers otherwise look the same. It is off by default (third-party APIs get no role names) and refused for services that forward nothing (signing, `gcloud-login`, `egress-proxy`). The keyring drops a caller-sent `X-Keyring-Role` on every call, so the header cannot be forged through it; anything that reaches the service without the keyring can still send one. Set it in `access.json` or with pasted settings when connecting or editing; the service page shows it. +**Naming the caller to a service you run.** With `"forward_role": true` on a service, every call carries `X-Keyring-Role: `, so a service the fleet runs itself (a build server, for example) can log which agent sent a call; through a relay all callers otherwise look the same. It is off by default (third-party APIs get no role names) and refused for services that forward nothing (signing, `gcloud-login`, `egress-proxy`). The keyring drops a caller-sent `X-Keyring-Role` on every call, so the header cannot be forged through it; anything that reaches the service without the keyring can still send one. Turn it on with the "Tell the service which agent is calling" box on the service's edit form, with `"forward_role": true` in pasted settings, or in `access.json`; the service page shows it. A service that echoes a key in some other encoding (for example base64 inside a larger text) is not protected; do not route such a service through the keyring. diff --git a/internal/dashboard/pages.go b/internal/dashboard/pages.go index 23f0cf6..caee74c 100644 --- a/internal/dashboard/pages.go +++ b/internal/dashboard/pages.go @@ -309,6 +309,7 @@ Sign in with Apple: {"service":"NAME","auth":"sign-in-with-apple-sign","si + Or paste settings from an agent

Replaces every setting above, including the project (include "project" to keep it), and the key stays as chosen. Leave "service" out; a service cannot be renamed here. "extra_headers" (header name to the name of another stored key, for example {"Modal-Secret":"MODAL_PROXY_SECRET"}) replaces the extra secret headers; leave it out to keep them, or use {} to remove them. The test method (shown above) is kept; change a POST test to something else in access.json. Optional fixed_headers sets up to two nonsecret header values, for example {"CF-R2-Jurisdiction":"default"}; without it the fixed headers are removed. Never put credentials here.

diff --git a/internal/dashboard/services.go b/internal/dashboard/services.go index 260c58c..b84ab67 100644 --- a/internal/dashboard/services.go +++ b/internal/dashboard/services.go @@ -49,7 +49,7 @@ type serviceForm struct { // OAuth client settings of an oauth2 service (#142): the secret is a key // name, never a value. ClientID, TokenURL, ClientSecretKey string - // ForwardRole is shown, and changed only by pasting settings. + // ForwardRole: the form's checkbox, or forward_role in pasted settings. ForwardRole bool } @@ -137,6 +137,7 @@ func (b *Backend) saveService(w http.ResponseWriter, r *http.Request, sid string Pasted: strings.TrimSpace(r.PostFormValue("pasted")), ClientID: strings.TrimSpace(r.PostFormValue("client_id")), TokenURL: strings.TrimSpace(r.PostFormValue("token_url")), ClientSecretKey: strings.TrimSpace(r.PostFormValue("client_secret_key")), + ForwardRole: r.PostFormValue("forward_role") == "yes", } again := func(status int, msg string) { // Refused pasted settings are not shown again: they may hold a value @@ -216,6 +217,7 @@ func (b *Backend) saveService(w http.ResponseWriter, r *http.Request, sid string updated := cur updated.Base, updated.Key, updated.Auth, updated.Header, updated.Param = f.Base, f.Key, f.Auth, f.Header, f.Param updated.TestPath, updated.TLSPinSHA256, updated.Project = f.TestPath, f.TLSPin, f.Project + updated.ForwardRole = f.ForwardRole if pasted { updated.FixedHeaders, updated.ForwardRole = fixed, forwardRole } diff --git a/internal/dashboard/services_test.go b/internal/dashboard/services_test.go index b163d54..cec6648 100644 --- a/internal/dashboard/services_test.go +++ b/internal/dashboard/services_test.go @@ -300,9 +300,9 @@ func TestServiceProjectFromTheDashboard(t *testing.T) { } } -// Jarvis 488215: forward_role is set by pasted settings, survives a plain -// form edit, shows on the service page, and its change is audited. -func TestForwardRoleSetByPasteKeptByFormEdit(t *testing.T) { +// Jarvis 488215: forward_role is set by pasted settings or the edit form's +// checkbox, shows on the service page, and its change is audited. +func TestForwardRoleSetByPasteOrCheckbox(t *testing.T) { e := newEnv(t) base := e.proxy.Config().Services["api"].Base w := e.edit("api", url.Values{"pasted": {`{"base":"` + base + `","auth":"bearer","forward_role":true}`}}) @@ -315,8 +315,22 @@ func TestForwardRoleSetByPasteKeptByFormEdit(t *testing.T) { if !strings.Contains(e.request("GET", "/services/api", nil).Body.String(), "X-Keyring-Role") { t.Fatal("service page does not show that the agent's name is sent") } + // The edit form has a checkbox for it, shown ticked: kept when ticked, + // cleared when not. + if !strings.Contains(e.request("GET", "/services/api", nil).Body.String(), `name="forward_role" value="yes" checked`) { + t.Fatal("edit form does not show forward_role ticked") + } + w = e.edit("api", url.Values{"key": {"API_KEY"}, "base": {base}, "auth": {"bearer"}, "test_path": {"/ping"}, "forward_role": {"yes"}}) + if w.Header().Get("Location") != "/services/api?done=saved" || !e.proxy.Config().Services["api"].ForwardRole { + t.Fatalf("a ticked form edit dropped forward_role: %d", w.Code) + } w = e.edit("api", url.Values{"key": {"API_KEY"}, "base": {base}, "auth": {"bearer"}, "test_path": {"/ping"}}) + if w.Header().Get("Location") != "/services/api?done=saved" || e.proxy.Config().Services["api"].ForwardRole { + t.Fatalf("unticking did not clear forward_role: %d", w.Code) + } + // And the plain form turns it on, with nothing pasted. + w = e.edit("api", url.Values{"key": {"API_KEY"}, "base": {base}, "auth": {"bearer"}, "test_path": {"/ping"}, "forward_role": {"yes"}}) if w.Header().Get("Location") != "/services/api?done=saved" || !e.proxy.Config().Services["api"].ForwardRole { - t.Fatalf("a form edit dropped forward_role: %d", w.Code) + t.Fatalf("ticking the box did not set forward_role: %d", w.Code) } }