Read secret Home identity from the app's sign-in redirect
Production preflight refused all six apps with home-issuer-mismatch and home-consumer-mismatch. Each app stores <P>_HOME_ISSUER and <P>_HOME_CONSUMER_ID as secrets, so the config API returns no value and the snapshot's fields stayed empty. When the stored var is a secret, observe now takes the value from the app's public GET /auth/start redirect. The redirect is never followed. It must be a 302 or 303 from the https origin with one Location that is exactly the Home issuer's /authorize and carries one non-empty consumer. Anything else, a failed request included, leaves the value empty, so the existing mismatch codes refuse. The nonce is not kept or logged. A plain var keeps its direct comparison and is never rescued by the redirect. The activation gate now applies the same two codes. Rollback passes no client, so it never needs the sign-in door. The secrets stay under the existing digest preservation.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 files changed,
+386
−10
adopt/delivery.go+42 −0adopt/delivery_test.go+14 −1adopt/homeidentity_test.go+278 −0adopt/observer.go+4 −1adopt/snapshot.go+48 −8
CI passed — run details
CI log
=== vet === go vet ./... === fmt === === test === CGO_ENABLED=0 go test ./... ok amadan.net/oficina/alta/adopt 18.258s ok amadan.net/oficina/alta/carlosop 0.054s ? amadan.net/oficina/alta/carlosop/fakecarlos [no test files] ok amadan.net/oficina/alta/cmd/alta 0.178s ok amadan.net/oficina/alta/cmd/alta-adopt 22.107s ok amadan.net/oficina/alta/console 0.003s ? amadan.net/oficina/alta/console/fakeconsole [no test files] ok amadan.net/oficina/alta/homeop 0.004s ok amadan.net/oficina/alta/homeop/fakehome 0.049s ok amadan.net/oficina/alta/internal/web 0.118s ok amadan.net/oficina/alta/provision 12.261s === compat === cd homecompat && go vet ./... && CGO_ENABLED=0 go test ./... ok amadan.net/oficina/home/altacompat 0.579s
diff --git a/adopt/delivery.go b/adopt/delivery.go| index 2f0d28c..dadfad7 100644 |
| --- a/adopt/delivery.go |
| +++ b/adopt/delivery.go |
| @@ -280,3 +280,45 @@ func Reverted(before, now Delivery) error { |
| } |
| return nil |
| } |
| + |
| +// signInIdentity reads the Home issuer and consumer an app really signs |
| +// in with, from the redirect its GET /auth/start answers. Apps store both |
| +// as secrets, whose values the config API never returns, and the redirect |
| +// is public. The redirect is never followed. Anything but a 302 or 303 |
| +// from an https origin, carrying the one Location authorizeTarget accepts, |
| +// answers two empty strings, which the mismatch codes then refuse; that |
| +// includes a request that fails. The Location holds a sign-in nonce, so it |
| +// is neither returned nor logged. |
| +func signInIdentity(ctx context.Context, h *http.Client, origin string) (issuer, consumer string) { |
| + u, err := url.Parse(origin) |
| + if err != nil || u.Scheme != "https" || u.Host == "" { |
| + return "", "" |
| + } |
| + c := *h |
| + c.CheckRedirect = func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse } |
| + status, hdr, _, err := get(ctx, &c, origin+"/auth/start") |
| + if err != nil || (status != http.StatusFound && status != http.StatusSeeOther) { |
| + return "", "" |
| + } |
| + loc := hdr.Values("Location") |
| + if len(loc) != 1 { |
| + return "", "" |
| + } |
| + return authorizeTarget(loc[0]) |
| +} |
| + |
| +// authorizeTarget is the issuer and consumer of a Location that is exactly |
| +// HomeIssuerOrigin's /authorize with one non-empty consumer parameter, and |
| +// two empty strings for any other. |
| +func authorizeTarget(location string) (issuer, consumer string) { |
| + u, err := url.Parse(location) |
| + if err != nil || u.User != nil || u.Scheme+"://"+u.Host != HomeIssuerOrigin || |
| + u.Path != "/authorize" || u.RawPath != "" || u.Fragment != "" { |
| + return "", "" |
| + } |
| + q, err := url.ParseQuery(u.RawQuery) |
| + if err != nil || len(q["consumer"]) != 1 || q["consumer"][0] == "" { |
| + return "", "" |
| + } |
| + return HomeIssuerOrigin, q["consumer"][0] |
| +} |
diff --git a/adopt/delivery_test.go b/adopt/delivery_test.go| index 1f0ee5e..6a6eaab 100644 |
| --- a/adopt/delivery_test.go |
| +++ b/adopt/delivery_test.go |
| @@ -18,7 +18,10 @@ type site struct { |
| health int |
| ops func(w http.ResponseWriter) |
| redirectVersion bool |
| - versionHost atomic.Value // the Host the last /api/version asked |
| + versionHost atomic.Value // the Host the last /api/version asked |
| + signIn func(w http.ResponseWriter) // GET /auth/start; nil is a 404 |
| + signIns atomic.Int64 // GET /auth/start requests |
| + followed atomic.Int64 // requests that chased the redirect |
| } |
| // lastHost is the host the last version probe was addressed to. |
| @@ -39,6 +42,16 @@ func (s *site) handler() http.Handler { |
| _, _ = w.Write([]byte(s.version)) |
| }) |
| mux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(s.health) }) |
| + mux.HandleFunc("/auth/start", func(w http.ResponseWriter, r *http.Request) { |
| + s.signIns.Add(1) |
| + if s.signIn == nil { |
| + http.NotFound(w, r) |
| + return |
| + } |
| + s.signIn(w) |
| + }) |
| + // Every https origin lands on this site, the issuer's too. |
| + mux.HandleFunc("/authorize", func(w http.ResponseWriter, r *http.Request) { s.followed.Add(1) }) |
| mux.HandleFunc("/api/v1/operations", func(w http.ResponseWriter, r *http.Request) { |
| if s.ops == nil { |
| http.NotFound(w, r) |
diff --git a/adopt/homeidentity_test.go b/adopt/homeidentity_test.go| new file mode 100644 |
| index 0000000..d33f2cb |
| --- /dev/null |
| +++ b/adopt/homeidentity_test.go |
| @@ -0,0 +1,278 @@ |
| +package adopt |
| + |
| +import ( |
| + "context" |
| + "fmt" |
| + "net/http" |
| + "net/http/httptest" |
| + "strings" |
| + "testing" |
| + |
| + "amadan.net/oficina/alta/carlosop" |
| + "amadan.net/oficina/alta/provision" |
| +) |
| + |
| +const signInNonce = "NONCE-MUST-NOT-TRAVEL" |
| + |
| +// redirectTo answers status with one Location. |
| +func redirectTo(status int, location string) func(http.ResponseWriter) { |
| + return func(w http.ResponseWriter) { |
| + w.Header().Set("Location", location) |
| + w.WriteHeader(status) |
| + } |
| +} |
| + |
| +// signInFor is the redirect production answers for slug. |
| +func signInFor(slug string) func(http.ResponseWriter) { |
| + return redirectTo(http.StatusSeeOther, HomeIssuerOrigin+"/authorize?consumer="+slug+"&nonce="+signInNonce) |
| +} |
| + |
| +// secretHome stores the fixture's Home issuer and consumer as production |
| +// does, as secrets in the default layer, and serves the live sign-in. |
| +func secretHome(x *carlosFixture) { |
| + x.f.SetSecret(x.app.Slug, "", x.app.Prefix+"_HOME_ISSUER") |
| + x.f.SetSecret(x.app.Slug, "", x.app.Prefix+"_HOME_CONSUMER_ID") |
| + x.site.signIn = signInFor(x.app.Slug) |
| +} |
| + |
| +// The adoption tuple's consumer is the bare slug for each of the six apps. |
| +func TestAdoptionConsumerIsTheBareSlug(t *testing.T) { |
| + want := []string{"docs", "sheets", "slides", "calendar", "calls", "memoria"} |
| + if len(provision.Apps) != len(want) { |
| + t.Fatalf("%d apps", len(provision.Apps)) |
| + } |
| + for _, slug := range want { |
| + if _, ok := provision.AppBySlug(slug); !ok { |
| + t.Fatalf("no app %s", slug) |
| + } |
| + if got := provision.ConsumerID(provision.AdoptionLabel, slug); got != slug { |
| + t.Fatalf("ConsumerID(%s) = %q", slug, got) |
| + } |
| + } |
| +} |
| + |
| +// Production's shape passes for every app: both values secret, both read |
| +// from the sign-in redirect, which is never followed. |
| +func TestPreflightReadsSecretHomeIdentityFromSignIn(t *testing.T) { |
| + for _, a := range provision.Apps { |
| + t.Run(a.Slug, func(t *testing.T) { |
| + x := newCarlosFixture(t, a.Slug) |
| + secretHome(x) |
| + snap, codes := x.preflight(t, nil) |
| + wantCodes(t, codes) |
| + if snap.HomeIssuer != HomeIssuerOrigin || snap.HomeConsumer != a.Slug { |
| + t.Fatalf("issuer %q consumer %q", snap.HomeIssuer, snap.HomeConsumer) |
| + } |
| + if x.site.signIns.Load() != 1 || x.site.followed.Load() != 0 { |
| + t.Fatalf("sign-in read %d times, followed %d times", x.site.signIns.Load(), x.site.followed.Load()) |
| + } |
| + if strings.Contains(fmt.Sprintf("%+v", snap), signInNonce) { |
| + t.Fatal("the snapshot carries the nonce") |
| + } |
| + }) |
| + } |
| +} |
| + |
| +func TestPreflightAcceptsAFoundRedirect(t *testing.T) { |
| + x := newCarlosFixture(t, "docs") |
| + secretHome(x) |
| + x.site.signIn = redirectTo(http.StatusFound, HomeIssuerOrigin+"/authorize?nonce=n&consumer=docs") |
| + _, codes := x.preflight(t, nil) |
| + wantCodes(t, codes) |
| +} |
| + |
| +// Everything short of the exact redirect leaves both values empty. |
| +func TestPreflightRefusesSignInLookalikes(t *testing.T) { |
| + const good = "/authorize?consumer=docs&nonce=n" |
| + both := []string{"home-consumer-mismatch", "home-issuer-mismatch"} |
| + cases := map[string]struct { |
| + answer func(http.ResponseWriter) |
| + want []string |
| + }{ |
| + "other origin": {redirectTo(303, "https://id.example"+good), both}, |
| + "issuer subdomain": {redirectTo(303, "https://x.id.oficina.works"+good), both}, |
| + "issuer as a prefix": {redirectTo(303, "https://id.oficina.works.example"+good), both}, |
| + "explicit port": {redirectTo(303, "https://id.oficina.works:443"+good), both}, |
| + "http scheme": {redirectTo(303, "http://id.oficina.works"+good), both}, |
| + "userinfo": {redirectTo(303, "https://user@id.oficina.works"+good), both}, |
| + "userinfo lookalike": {redirectTo(303, "https://id.oficina.works@evil.example"+good), both}, |
| + "wrong path": {redirectTo(303, HomeIssuerOrigin+"/login?consumer=docs"), both}, |
| + "trailing slash": {redirectTo(303, HomeIssuerOrigin+"/authorize/?consumer=docs"), both}, |
| + "encoded path": {redirectTo(303, HomeIssuerOrigin+"/%61uthorize?consumer=docs"), both}, |
| + "fragment": {redirectTo(303, HomeIssuerOrigin+good+"#consumer=docs"), both}, |
| + "repeated consumer": {redirectTo(303, HomeIssuerOrigin+"/authorize?consumer=docs&consumer=docs"), both}, |
| + "empty consumer": {redirectTo(303, HomeIssuerOrigin+"/authorize?consumer=&nonce=n"), both}, |
| + "no consumer": {redirectTo(303, HomeIssuerOrigin+"/authorize?nonce=n"), both}, |
| + "malformed query": {redirectTo(303, HomeIssuerOrigin+"/authorize?consumer=docs&x=%zz"), both}, |
| + "semicolon query": {redirectTo(303, HomeIssuerOrigin+"/authorize?consumer=docs;consumer=x"), both}, |
| + "relative location": {redirectTo(303, good), both}, |
| + "scheme-relative": {redirectTo(303, "//id.oficina.works"+good), both}, |
| + "no location": {func(w http.ResponseWriter) { w.WriteHeader(303) }, both}, |
| + "two locations": {func(w http.ResponseWriter) { |
| + w.Header().Add("Location", HomeIssuerOrigin+good) |
| + w.Header().Add("Location", HomeIssuerOrigin+good) |
| + w.WriteHeader(303) |
| + }, both}, |
| + "200 with a location": {redirectTo(200, HomeIssuerOrigin+good), both}, |
| + "301": {redirectTo(301, HomeIssuerOrigin+good), both}, |
| + "307": {redirectTo(307, HomeIssuerOrigin+good), both}, |
| + "oversized body": {func(w http.ResponseWriter) { |
| + w.Header().Set("Location", HomeIssuerOrigin+good) |
| + w.WriteHeader(303) |
| + _, _ = w.Write(make([]byte, bodyLimit+1)) |
| + }, both}, |
| + "connection dropped": {func(w http.ResponseWriter) { panic(http.ErrAbortHandler) }, both}, |
| + "wrong consumer": {signInFor("sheets"), []string{"home-consumer-mismatch"}}, |
| + } |
| + for name, c := range cases { |
| + t.Run(name, func(t *testing.T) { |
| + x := newCarlosFixture(t, "docs") |
| + secretHome(x) |
| + x.site.signIn = c.answer |
| + _, codes := x.preflight(t, nil) |
| + wantCodes(t, codes, c.want...) |
| + if x.site.followed.Load() != 0 { |
| + t.Fatal("the redirect was followed") |
| + } |
| + }) |
| + } |
| + t.Run("no sign-in door", func(t *testing.T) { |
| + x := newCarlosFixture(t, "docs") |
| + secretHome(x) |
| + x.site.signIn = nil |
| + _, codes := x.preflight(t, nil) |
| + wantCodes(t, codes, both...) |
| + }) |
| +} |
| + |
| +// A plain var is compared as it is: the redirect never rescues it. |
| +func TestPreflightNeverFallsBackFromAPlainVar(t *testing.T) { |
| + t.Run("issuer", func(t *testing.T) { |
| + x := newCarlosFixture(t, "docs") |
| + secretHome(x) |
| + x.f.SetVar("docs", "", "DOCS_HOME_ISSUER", "https://id.example") |
| + _, codes := x.preflight(t, nil) |
| + wantCodes(t, codes, "home-issuer-mismatch") |
| + }) |
| + t.Run("consumer", func(t *testing.T) { |
| + x := newCarlosFixture(t, "docs") |
| + secretHome(x) |
| + x.f.SetVar("docs", "", "DOCS_HOME_CONSUMER_ID", "oficina-docs") |
| + _, codes := x.preflight(t, nil) |
| + wantCodes(t, codes, "home-consumer-mismatch") |
| + }) |
| + t.Run("consumer absent", func(t *testing.T) { |
| + x := newCarlosFixture(t, "docs") |
| + secretHome(x) |
| + x.f.Unset("docs", "", "DOCS_HOME_CONSUMER_ID") |
| + _, codes := x.preflight(t, nil) |
| + wantCodes(t, codes, "home-consumer-mismatch") |
| + }) |
| + t.Run("both plain makes no sign-in read", func(t *testing.T) { |
| + x := newCarlosFixture(t, "docs") |
| + x.site.signIn = signInFor("docs") |
| + _, codes := x.preflight(t, nil) |
| + wantCodes(t, codes) |
| + if x.site.signIns.Load() != 0 { |
| + t.Fatal("plain vars read the sign-in door") |
| + } |
| + }) |
| +} |
| + |
| +// A secret in the overlay is not the app's own stored identity. |
| +func TestPreflightRefusesASecretConsumerInTheOverlay(t *testing.T) { |
| + x := newCarlosFixture(t, "docs") |
| + secretHome(x) |
| + x.f.SetOverlay("docs", docsRoute, "DOCS_HOME_CONSUMER_ID", "docs") |
| + _, codes := x.preflight(t, nil) |
| + wantCodes(t, codes, "home-consumer-mismatch") |
| +} |
| + |
| +// A secret is only believed when the stored layer agrees with the |
| +// effective view about it. |
| +func TestStoredSecretNeedsTheSameKindAndDigest(t *testing.T) { |
| + l := carlosop.Layer{Vars: []carlosop.Var{{Key: "K", Kind: "secret", Digest: "d1"}, {Key: "P", Kind: "env", Digest: "d1"}}} |
| + cases := map[string]struct { |
| + ev *carlosop.EffectiveVar |
| + want bool |
| + }{ |
| + "held": {&carlosop.EffectiveVar{Key: "K", Kind: "secret", Digest: "d1"}, true}, |
| + "absent": {nil, false}, |
| + "other digest": {&carlosop.EffectiveVar{Key: "K", Kind: "secret", Digest: "d2"}, false}, |
| + "effective plain": {&carlosop.EffectiveVar{Key: "K", Kind: "env", Digest: "d1"}, false}, |
| + "stored plain": {&carlosop.EffectiveVar{Key: "P", Kind: "secret", Digest: "d1"}, false}, |
| + "not stored": {&carlosop.EffectiveVar{Key: "X", Kind: "secret", Digest: "d1"}, false}, |
| + } |
| + for name, c := range cases { |
| + if got := storedSecret(l, c.ev); got != c.want { |
| + t.Errorf("%s: %v", name, got) |
| + } |
| + } |
| +} |
| + |
| +// The sign-in is only believed from an https origin. |
| +func TestSignInIdentityRefusesAPlainHTTPOrigin(t *testing.T) { |
| + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { signInFor("docs")(w) })) |
| + t.Cleanup(srv.Close) |
| + if iss, cons := signInIdentity(context.Background(), srv.Client(), srv.URL); iss != "" || cons != "" { |
| + t.Fatalf("issuer %q consumer %q", iss, cons) |
| + } |
| +} |
| + |
| +// configure runs Preflight again before writing: a sign-in that has moved |
| +// sends nothing. |
| +func TestConfigureRefusesAMovedSignInBeforeWriting(t *testing.T) { |
| + w := newWriteFixture(t, "docs") |
| + secretHome(w.carlosFixture) |
| + w.site.signIn = signInFor("sheets") |
| + if _, err := w.configure(true); err == nil || !strings.Contains(err.Error(), "home-consumer-mismatch") { |
| + t.Fatalf("configure: %v", err) |
| + } |
| + if w.puts() != 0 { |
| + t.Fatal("configure wrote past a moved sign-in") |
| + } |
| +} |
| + |
| +func secretHomeBefore(w *writeFixture) { secretHome(w.carlosFixture) } |
| + |
| +// The activation gate holds the live sign-in to the same rule. |
| +func TestObserverRefusesAMovedSignIn(t *testing.T) { |
| + x := newObserverFixture(t, "calendar", secretHomeBefore) |
| + if _, err := x.observe(); err != nil { |
| + t.Fatalf("Observe with production's shape: %v", err) |
| + } |
| + x.site.signIn = signInFor("sheets") |
| + if _, err := x.observe(); err == nil || !strings.Contains(err.Error(), "home-consumer-mismatch") { |
| + t.Fatalf("Observe: %v", err) |
| + } |
| +} |
| + |
| +// The secrets themselves stay under digest preservation: a reseal is |
| +// drift even though the sign-in still answers the same. |
| +func TestObserverRefusesResealedHomeSecrets(t *testing.T) { |
| + for _, key := range []string{"CALENDAR_HOME_ISSUER", "CALENDAR_HOME_CONSUMER_ID"} { |
| + t.Run(key, func(t *testing.T) { |
| + x := newObserverFixture(t, "calendar", secretHomeBefore) |
| + x.f.SetSecret("calendar", "", key) |
| + if _, err := x.observe(); err == nil || !strings.Contains(err.Error(), "drift-changed:"+key) { |
| + t.Fatalf("Observe: %v", err) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// A rollback has to reach an app that is down, so it never asks the |
| +// sign-in door, and a broken one does not stop it. |
| +func TestRollbackDoesNotNeedTheSignIn(t *testing.T) { |
| + w := newWriteFixture(t, "docs") |
| + secretHome(w.carlosFixture) |
| + w.configured(t) |
| + w.site.signIn = nil |
| + before := w.site.signIns.Load() |
| + if err := w.rollback(true); err != nil { |
| + t.Fatalf("RollbackAgentKeys: %v", err) |
| + } |
| + if w.site.signIns.Load() != before { |
| + t.Fatal("the rollback read the sign-in door") |
| + } |
| +} |
diff --git a/adopt/observer.go b/adopt/observer.go| index 3cdb092..f6d0465 100644 |
| --- a/adopt/observer.go |
| +++ b/adopt/observer.go |
| @@ -82,7 +82,9 @@ func (o *Observer) now() time.Time { |
| // (drift-<code>); |
| // - config: the fresh read equals the after snapshot, every key's |
| // digest, kind and source and every layer's version |
| -// (config-<code>); no team-mode key (team-mode-<KEY>); both agent |
| +// (config-<code>); no team-mode key (team-mode-<KEY>); the Home |
| +// issuer and consumer are still the ones the app must trust |
| +// (home-issuer-mismatch, home-consumer-mismatch); both agent |
| // keys are plain vars from the write layer carrying the sent |
| // digests (agent-key-<KEY>); |
| // - the delivery check is current: its after version is the fresh |
| @@ -137,6 +139,7 @@ func (o *Observer) Observe(ctx context.Context, app, teamSQID string) (provision |
| addAll("drift-", Preserved(ev.base, fresh, keys)...) |
| addAll("config-", sameConfig(ev.after, fresh)...) |
| addAll("team-mode-", TeamModeKeys(a, fresh.Vars)...) |
| + addAll("", homeCodes(a, fresh)...) |
| for _, k := range keys { |
| v := findVar(fresh.Vars, k) |
| if v == nil || v.Kind != "env" || v.From != layerName(ev.base.WriteLayer) || v.Digest != carlosop.EnvDigest(ev.write.Sent[k]) { |
diff --git a/adopt/snapshot.go b/adopt/snapshot.go| index e260d4d..802cab4 100644 |
| --- a/adopt/snapshot.go |
| +++ b/adopt/snapshot.go |
| @@ -96,6 +96,33 @@ func canonicalRecord(host string, ds []carlosop.Domain, all []carlosop.Instance) |
| return d, rec, "", nil |
| } |
| +// storedSecret reports whether a stored layer holds key as a secret with |
| +// exactly the digest the effective view reports. |
| +func storedSecret(l carlosop.Layer, ev *carlosop.EffectiveVar) bool { |
| + if ev == nil || ev.Kind != "secret" { |
| + return false |
| + } |
| + for _, v := range l.Vars { |
| + if v.Key == ev.Key && v.Kind == "secret" && v.Digest == ev.Digest { |
| + return true |
| + } |
| + } |
| + return false |
| +} |
| + |
| +// homeCodes lists how snap's Home issuer and consumer differ from the |
| +// ones app must trust. |
| +func homeCodes(app provision.App, snap Snapshot) []string { |
| + var codes []string |
| + if snap.HomeIssuer != HomeIssuerOrigin { |
| + codes = append(codes, "home-issuer-mismatch") |
| + } |
| + if snap.HomeConsumer != provision.ConsumerID(provision.AdoptionLabel, app.Slug) { |
| + codes = append(codes, "home-consumer-mismatch") |
| + } |
| + return codes |
| +} |
| + |
| // observe reads one snapshot of app's canonical host, and the app's |
| // instance list it found that host's record in. The codes are the |
| // refusals that leave no snapshot to check: domain-missing, |
| @@ -106,6 +133,11 @@ func canonicalRecord(host string, ds []carlosop.Domain, all []carlosop.Instance) |
| // a probe of a name not served would say nothing. With h nil it makes no |
| // delivery probe, and the snapshot's Delivery is empty: the config and |
| // identity alone. |
| +// |
| +// The Home issuer and consumer are a plain var's own value. Only a value |
| +// stored as a secret, which the console never returns, is taken from the |
| +// app's live sign-in redirect (signInIdentity), and so only with h: a plain |
| +// value that mismatches is never rescued by the redirect. |
| func observe(ctx context.Context, c *carlosop.Client, h *http.Client, app provision.App) (Snapshot, []carlosop.Instance, []string, error) { |
| ds, err := c.Domains(ctx, app.Slug) |
| if err != nil { |
| @@ -176,6 +208,7 @@ func observeRecord(ctx context.Context, c *carlosop.Client, h *http.Client, app |
| return Snapshot{}, nil, err |
| } |
| snap.HomeIssuer = plainValue(snap.Layer, iss) |
| + secretIssuer, secretConsumer := storedSecret(snap.Layer, iss), false |
| // The overlay's plain values are not readable, so a consumer ID that |
| // comes from it stays "" and is refused. |
| if cons := findVar(eff.Vars, app.Prefix+"_HOME_CONSUMER_ID"); cons != nil && cons.From != "overlay" { |
| @@ -186,11 +219,22 @@ func observeRecord(ctx context.Context, c *carlosop.Client, h *http.Client, app |
| } |
| } |
| snap.HomeConsumer = plainValue(src, cons) |
| + secretConsumer = storedSecret(src, cons) |
| } |
| if h == nil { |
| return snap, nil, nil |
| } |
| - if snap.Delivery, err = Probe(ctx, h, provision.PublicOrigin(provision.AdoptionLabel, app.Slug)); err != nil { |
| + origin := provision.PublicOrigin(provision.AdoptionLabel, app.Slug) |
| + if secretIssuer || secretConsumer { |
| + issuer, consumer := signInIdentity(ctx, h, origin) |
| + if secretIssuer { |
| + snap.HomeIssuer = issuer |
| + } |
| + if secretConsumer { |
| + snap.HomeConsumer = consumer |
| + } |
| + } |
| + if snap.Delivery, err = Probe(ctx, h, origin); err != nil { |
| return Snapshot{}, nil, err |
| } |
| return snap, nil, nil |
| @@ -258,7 +302,8 @@ func inherits(eff carlosop.Effective, writeLayer string, keys [2]string) bool { |
| // - domain-missing, domain-ambiguous, domain-not-live, instance-missing |
| // (the canonical domain is not one live claim routed to a record); |
| // - instance-moving, owned-environment, layer-overlay; |
| -// - home-issuer-mismatch, home-consumer-mismatch; |
| +// - home-issuer-mismatch, home-consumer-mismatch: a plain var's value, |
| +// or for a secret the app's live sign-in redirect (observe); |
| // - team-mode-<KEY>; |
| // - agent-keys-present, unless each present key is a plain var in the |
| // write layer whose digest is EnvDigest(mine[key]) (the journal's own |
| @@ -287,12 +332,7 @@ func Preflight(ctx context.Context, c *carlosop.Client, h *http.Client, app prov |
| if snap.Identity.Owned { |
| add("owned-environment") |
| } |
| - if snap.HomeIssuer != HomeIssuerOrigin { |
| - add("home-issuer-mismatch") |
| - } |
| - if snap.HomeConsumer != provision.ConsumerID(provision.AdoptionLabel, app.Slug) { |
| - add("home-consumer-mismatch") |
| - } |
| + codes = append(codes, homeCodes(app, snap)...) |
| for _, k := range TeamModeKeys(app, snap.Vars) { |
| add("team-mode-" + k) |
| } |