fix(archieui): resolve service tokens from env and correct the stale State Store config comment
D1: the UI read [services.*].target_token verbatim, but the config loader does not expand environment variables. A deployment that presents the gateway and state tokens by env (as config.example.toml documents for remote consumers) would leave archie-ui with an empty token, and staterpc.Dial then refuses a non-loopback start. Mirror the daemon's stateStoreResolvedToken / gatewayResolvedToken: explicit key, then GATEWAY_TOKEN / STATE_STORE_TOKEN. D5: internal/config/services.go claimed the State Store service 'is not yet extracted into its own process' and that target_token 'remains dead configuration', both false since the daemon made an empty services.state.target a hard startup error. State current truth. D3: document that Web.Listen = 'off' is read with opposite meanings by the dsaemon (disables the dashboard) and the UI process (falls through to the default listener), pinning it as the one overloaded key an operator preparing the split would set.
This commit is contained in:
1 parent
0994b5e4e6
commit
ac7b4492a2
3 files changed
+92
-9
No files matched your search
@@ -71,11 +71,26 @@ type projection struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func project(cfg config.Config) projection {
|
func project(cfg config.Config) projection {
|
||||||
|
// Token resolution mirrors the daemon's (stateStoreResolvedToken /
|
||||||
|
// gatewayResolvedToken): the explicit [services.*].target_token key,
|
||||||
|
// then the secret/env var. The config loader does not expand env, so a
|
||||||
|
// deployment that presents the gateway/state tokens by environment —
|
||||||
|
// which config.example.toml documents for remote consumers — would
|
||||||
|
// otherwise leave the UI with an empty token and staterpc.Dial would
|
||||||
|
// refuse a non-loopback start.
|
||||||
|
gatewayToken := cfg.Services.Gateway.TargetToken
|
||||||
|
if gatewayToken == "" {
|
||||||
|
gatewayToken = os.Getenv("GATEWAY_TOKEN")
|
||||||
|
}
|
||||||
|
stateToken := cfg.Services.State.TargetToken
|
||||||
|
if stateToken == "" {
|
||||||
|
stateToken = os.Getenv("STATE_STORE_TOKEN")
|
||||||
|
}
|
||||||
return projection{
|
return projection{
|
||||||
listen: cfg.Web.Listen,
|
listen: cfg.Web.Listen,
|
||||||
trustForwardedHeaders: cfg.Web.TrustForwardedHeaders,
|
trustForwardedHeaders: cfg.Web.TrustForwardedHeaders,
|
||||||
gateway: ServiceTarget{Target: cfg.Services.Gateway.Target, Token: cfg.Services.Gateway.TargetToken},
|
gateway: ServiceTarget{Target: cfg.Services.Gateway.Target, Token: gatewayToken},
|
||||||
state: ServiceTarget{Target: cfg.Services.State.Target, Token: cfg.Services.State.TargetToken},
|
state: ServiceTarget{Target: cfg.Services.State.Target, Token: stateToken},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,6 +119,14 @@ func merge(o Options, p projection) Options {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func withDefaults(o Options) Options {
|
func withDefaults(o Options) Options {
|
||||||
|
// This is the one config key the UI and the daemon read with opposite
|
||||||
|
// meanings: in the daemon, Web.Listen = "off" disables the dashboard
|
||||||
|
// (config.Config "off" is a sentinel, not an address). In a dedicated UI
|
||||||
|
// process there is no sense disabling the only thing it does, so "off"
|
||||||
|
// falls through to the default listener. None of the other projected
|
||||||
|
// values is overloaded this way; if "off" ever means something else here
|
||||||
|
// it must be pinned with a test, because it is exactly where an operator
|
||||||
|
// preparing the split would set it.
|
||||||
if o.Listen == "" || o.Listen == "off" {
|
if o.Listen == "" || o.Listen == "off" {
|
||||||
o.Listen = defaultListen
|
o.Listen = defaultListen
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -130,3 +130,63 @@ func TestResolveRequiresBothServiceTargets(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestResolveTokenFallsBackToEnv pins D1: the UI process reads the same
|
||||||
|
// [services.*].target_token keys the daemon does, but the config loader does
|
||||||
|
// not expand environment variables. A deployment that presents the gateway
|
||||||
|
// and state tokens by environment (config.example.toml documents this for
|
||||||
|
// remote consumers) must still authenticate, so an empty target_token falls
|
||||||
|
// back to GATEWAY_TOKEN / STATE_STORE_TOKEN exactly as the daemon's
|
||||||
|
// stateStoreResolvedToken and gatewayResolvedToken do.
|
||||||
|
func TestResolveTokenFallsBackToEnv(t *testing.T) {
|
||||||
|
path := t.TempDir() + "/ui.toml"
|
||||||
|
contents := `bot_user = "widget"
|
||||||
|
|
||||||
|
[web]
|
||||||
|
listen = "127.0.0.1:9999"
|
||||||
|
|
||||||
|
[services.gateway]
|
||||||
|
target = "127.0.0.1:8585"
|
||||||
|
|
||||||
|
[services.state]
|
||||||
|
target = "127.0.0.1:9090"
|
||||||
|
`
|
||||||
|
if err := os.WriteFile(path, []byte(contents), 0o600); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Setenv("GATEWAY_TOKEN", "env-gateway")
|
||||||
|
t.Setenv("STATE_STORE_TOKEN", "env-state")
|
||||||
|
|
||||||
|
resolved, err := Resolve(Options{Config: path}, slog.New(slog.DiscardHandler))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Resolve: %v", err)
|
||||||
|
}
|
||||||
|
if resolved.Gateway.Token != "env-gateway" {
|
||||||
|
t.Errorf("Gateway.Token = %q, want env GATEWAY_TOKEN", resolved.Gateway.Token)
|
||||||
|
}
|
||||||
|
if resolved.State.Token != "env-state" {
|
||||||
|
t.Errorf("State.Token = %q, want env STATE_STORE_TOKEN", resolved.State.Token)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The explicit key still wins over the environment.
|
||||||
|
keyed := `bot_user = "widget"
|
||||||
|
|
||||||
|
[services.gateway]
|
||||||
|
target = "127.0.0.1:8585"
|
||||||
|
target_token = "keyed-gateway"
|
||||||
|
[services.state]
|
||||||
|
target = "127.0.0.1:9090"
|
||||||
|
`
|
||||||
|
path2 := t.TempDir() + "/keyed.toml"
|
||||||
|
if err := os.WriteFile(path2, []byte(keyed), 0o600); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
resolved2, err := Resolve(Options{Config: path2}, slog.New(slog.DiscardHandler))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Resolve (keyed): %v", err)
|
||||||
|
}
|
||||||
|
if resolved2.Gateway.Token != "keyed-gateway" {
|
||||||
|
t.Errorf("Gateway.Token = %q, want the explicit target_token over env", resolved2.Gateway.Token)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,13 +3,13 @@ package config
|
|||||||
// Services selects contract adapters at application composition time.
|
// Services selects contract adapters at application composition time.
|
||||||
type Services struct {
|
type Services struct {
|
||||||
Gateway ServiceConnection `toml:"gateway" yaml:"gateway"`
|
Gateway ServiceConnection `toml:"gateway" yaml:"gateway"`
|
||||||
// State selects the State Store contract adapter. Unlike Gateway, an
|
// State selects the State Store contract adapter. The State Store is its
|
||||||
// empty Target means local (the *store.Store in-process adapter): the
|
// own process (cmd/archie-state-store) and owns archie.db; an empty Target
|
||||||
// State Store service is not yet extracted into its own process. The
|
// is a startup error in archied/archie-gateway, which no longer serve a
|
||||||
// standalone archie-state-store binary (.4.3) is the consumer of
|
// local store (docs/prds/state-store-contract.md §12 step 7). The daemon
|
||||||
// [services.state].target_token; the daemon does not read it yet, so
|
// and agent dial the remote StateStoreService and present target_token
|
||||||
// it remains dead configuration until the daemon points at the
|
// when the target is non-loopback. Token resolution mirrors the daemon's:
|
||||||
// extracted store. Setting Target would dial the gRPC StateStoreService.
|
// the explicit key, then the STATE_STORE_TOKEN secret/env var.
|
||||||
State ServiceConnection `toml:"state" yaml:"state"`
|
State ServiceConnection `toml:"state" yaml:"state"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user