Merge crew/qc8p: archie-core-qc8p
This commit is contained in:
commit
0219aee5ad
46 files changed
+5150
-243
No files matched your search
@@ -0,0 +1,110 @@
|
||||
// The `archied access reset` command: the locked-out-org and broken-instance
|
||||
// recovery surface (docs/prds/orgs-and-access.md, "Recovering from a
|
||||
// locked-out org"). It restores the shipped role policies for one org and
|
||||
// removes its other org-level policies, or removes the stored instance
|
||||
// policies; the cross-org forbid is engine-enforced and survives any reset.
|
||||
//
|
||||
// It runs only on the State Store host, never over the network, and is
|
||||
// recorded as an audit event. It claims the same store ownership the State
|
||||
// Store holds, so a running store refuses it: stop the store, reset, start
|
||||
// the store.
|
||||
package archied
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/access"
|
||||
"github.com/samcharles93/archie-core/internal/domain/org"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/configuration"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/postgres"
|
||||
)
|
||||
|
||||
// accessResetCommand is the argv selector for the recovery command.
|
||||
const accessResetCommand = "access"
|
||||
|
||||
// IsAccessResetArgs reports whether args selects the access recovery command.
|
||||
func IsAccessResetArgs(args []string) bool {
|
||||
return len(args) > 2 && args[0] == accessResetCommand && args[1] == resetCommand
|
||||
}
|
||||
|
||||
const resetCommand = "reset"
|
||||
|
||||
// RunAccessReset performs the reset and returns the process exit code:
|
||||
// 0 reset, 1 failure, 2 usage.
|
||||
func RunAccessReset(ctx context.Context, args []string, stderr io.Writer) int {
|
||||
fs := flag.NewFlagSet(resetCommand, flag.ContinueOnError)
|
||||
fs.SetOutput(stderr)
|
||||
cfgPath := fs.String("config", configuration.DefaultConfigPath(), "path to a TOML/YAML config file or configuration directory")
|
||||
overlayPath := fs.String("config-overlay", "", "path to a TOML/YAML overlay file or configuration directory applied on top of -config")
|
||||
orgFlag := fs.String("org", "", "org whose access to reset; conflicts with --instance")
|
||||
instance := fs.Bool("instance", false, "reset the stored instance policies")
|
||||
if err := fs.Parse(args); err != nil {
|
||||
return 2
|
||||
}
|
||||
if fs.NArg() > 0 {
|
||||
fmt.Fprintf(stderr, "reset: unexpected argument %q\n", fs.Arg(0))
|
||||
return 2
|
||||
}
|
||||
if (*orgFlag != "" && *instance) || (*orgFlag == "" && !*instance) {
|
||||
fmt.Fprintln(stderr, "reset: give exactly one of --org <org> or --instance")
|
||||
return 2
|
||||
}
|
||||
|
||||
b := newBootstrap()
|
||||
defer b.cleanup()
|
||||
if err := b.loadConfig(ctx, *cfgPath, *overlayPath); err != nil {
|
||||
return 1
|
||||
}
|
||||
if err := b.openStateStorePool(ctx); err != nil {
|
||||
// A running State Store holds the ownership claim; the reset must not
|
||||
// race it. Stop the store, reset, start the store.
|
||||
fmt.Fprintln(stderr, "reset: open the State Store database (stop archie-state-store first)")
|
||||
return 1
|
||||
}
|
||||
resetter, ok := b.st.(access.Resetter)
|
||||
if !ok {
|
||||
fmt.Fprintln(stderr, "reset: the State Store does not support the access reset surface")
|
||||
return 1
|
||||
}
|
||||
var err error
|
||||
switch {
|
||||
case *instance:
|
||||
err = resetter.ResetInstancePolicies(ctx)
|
||||
default:
|
||||
err = resetter.ResetOrgPolicies(ctx, org.OrgID(*orgFlag))
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Fprintf(stderr, "reset: %v\n", err)
|
||||
return 1
|
||||
}
|
||||
if err := recordResetAudit(ctx, b.pg, *orgFlag, *instance); err != nil {
|
||||
fmt.Fprintf(stderr, "reset: audit: %v\n", err)
|
||||
return 1
|
||||
}
|
||||
fmt.Fprintf(stderr, "reset: access policies for %s restored to the shipped set\n", resetTarget(*orgFlag, *instance))
|
||||
return 0
|
||||
}
|
||||
|
||||
// resetTarget names what the reset covered, for the operator's output.
|
||||
func resetTarget(orgID string, instance bool) string {
|
||||
if instance {
|
||||
return "the instance"
|
||||
}
|
||||
return fmt.Sprintf("org %q", orgID)
|
||||
}
|
||||
|
||||
// recordResetAudit writes the one audit row the reset is recorded as. The
|
||||
// policy changes themselves carry their own sys_audit rows; this names the
|
||||
// recovery.
|
||||
func recordResetAudit(ctx context.Context, pool *pgxpool.Pool, orgID string, instance bool) error {
|
||||
key := "reset/instance"
|
||||
if !instance {
|
||||
key = fmt.Sprintf("reset/org/%s", orgID)
|
||||
}
|
||||
return postgres.New(pool).RecordResetAudit(ctx, key)
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package archied
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestIsAccessResetArgs(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
args []string
|
||||
want bool
|
||||
}{
|
||||
{name: "org reset", args: []string{"access", "reset", "--org", "acme"}, want: true},
|
||||
{name: "instance reset", args: []string{"access", "reset", "--instance"}, want: true},
|
||||
{name: "config first", args: []string{"access", "reset", "-config", "/tmp/config.toml", "--org", "acme"}, want: true},
|
||||
{name: "setup is not a reset", args: []string{"setup"}, want: false},
|
||||
{name: "bare access", args: []string{"access"}, want: false},
|
||||
{name: "other subcommand", args: []string{"access", "grant"}, want: false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := IsAccessResetArgs(tt.args); got != tt.want {
|
||||
t.Fatalf("IsAccessResetArgs(%v) = %v, want %v", tt.args, got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunAccessResetUsage(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
args []string
|
||||
wantCode int
|
||||
wantText string
|
||||
}{
|
||||
{name: "no target", args: nil, wantCode: 2, wantText: "exactly one of --org"},
|
||||
{name: "both targets", args: []string{"--org", "acme", "--instance"}, wantCode: 2, wantText: "exactly one of --org"},
|
||||
{name: "unexpected argument", args: []string{"--instance", "extra"}, wantCode: 2, wantText: "unexpected argument"},
|
||||
{name: "unknown flag", args: []string{"--workspace", "net"}, wantCode: 2},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
var stderr strings.Builder
|
||||
code := RunAccessReset(t.Context(), tt.args, &stderr)
|
||||
if code != tt.wantCode {
|
||||
t.Fatalf("RunAccessReset(%v) = %d, want %d (stderr: %s)", tt.args, code, tt.wantCode, stderr.String())
|
||||
}
|
||||
if tt.wantText != "" && !strings.Contains(stderr.String(), tt.wantText) {
|
||||
t.Fatalf("stderr = %q, want it to name %q", stderr.String(), tt.wantText)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,7 @@ import (
|
||||
"github.com/samcharles93/archie-core/internal/container"
|
||||
controlpb "github.com/samcharles93/archie-core/internal/contracts/controlplane/v1"
|
||||
"github.com/samcharles93/archie-core/internal/daemon"
|
||||
"github.com/samcharles93/archie-core/internal/domain/access"
|
||||
"github.com/samcharles93/archie-core/internal/domain/applystatus"
|
||||
"github.com/samcharles93/archie-core/internal/domain/curator"
|
||||
"github.com/samcharles93/archie-core/internal/domain/eda/module"
|
||||
@@ -46,6 +47,7 @@ import (
|
||||
"github.com/samcharles93/archie-core/internal/forge"
|
||||
forgewebhook "github.com/samcharles93/archie-core/internal/forge/webhook"
|
||||
"github.com/samcharles93/archie-core/internal/gateway"
|
||||
infraaccess "github.com/samcharles93/archie-core/internal/infrastructure/access"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/configuration"
|
||||
infraembedding "github.com/samcharles93/archie-core/internal/infrastructure/embedding"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/eventbus/nats"
|
||||
@@ -124,6 +126,11 @@ type boot struct {
|
||||
// set. The b.st field remains solely for the standalone archie-state-store
|
||||
// binary, which serves the task store from Postgres.
|
||||
stateStore storecontract.TaskStore
|
||||
// accessChain is the daemon's policy engine, built once from the stored
|
||||
// policies (openAccessChain); accessProblems is what the readiness
|
||||
// surface reports. Both are nil when no policy store is wired.
|
||||
accessChain access.Authorizer
|
||||
accessProblems []infraaccess.Problem
|
||||
// stateStoreGrants issues per-task, scoped State Store credentials for
|
||||
// agent containers (daemon.StateStoreGrantIssuer), wrapping the same
|
||||
// *staterpc.Client as stateStore. Nil when the State Store adapter isn't
|
||||
@@ -435,6 +442,47 @@ func (b *boot) openStateStoreAdapter() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// openStateStage opens the state-store adapter and its daemon-side surfaces
|
||||
// plus the policy chain, in one step of the composition sequence: the three
|
||||
// are ordered but not interleaved, and any failure fails the boot
|
||||
// (openStateStoreAdapter, openDaemonStateSurfaces, openAccessChain).
|
||||
func (b *boot) openStateStage(ctx context.Context) error {
|
||||
if err := b.openStores(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := b.openDaemonStateSurfaces(); err != nil {
|
||||
return err
|
||||
}
|
||||
return b.openAccessChain(ctx)
|
||||
}
|
||||
|
||||
// openAccessChain builds the policy chain the daemon dispatches through
|
||||
// (docs/prds/orgs-and-access.md, "Where it lives"): the stored policies over
|
||||
// the wire, compiled once at boot. An invalid instance policy fails the boot;
|
||||
// an invalid org, workspace or object policy is retained as a health problem
|
||||
// and its level denies everything.
|
||||
func (b *boot) openAccessChain(ctx context.Context) error {
|
||||
source, ok := b.stateStore.(access.PolicySource)
|
||||
if !ok {
|
||||
return nil // no policy store wired: the chain is not built
|
||||
}
|
||||
stored, err := source.Policies(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("load stored policies: %w", err)
|
||||
}
|
||||
engine, err := infraaccess.New(stored)
|
||||
if err != nil {
|
||||
return fmt.Errorf("validate stored policies: %w", err)
|
||||
}
|
||||
b.accessChain = engine
|
||||
b.accessProblems = engine.Problems()
|
||||
for _, problem := range b.accessProblems {
|
||||
b.log.Error("stored access policy is invalid and denies its level",
|
||||
"policy", problem.Policy.ID, "level", problem.Policy.Level, "err", problem.Err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// openChatSessions opens the conversation store on its own pool from
|
||||
// database_url. The daemon reads it (session curator) and the Gateway serves
|
||||
// it; only the Gateway claims serve ownership (claimGatewayOwnership).
|
||||
@@ -1387,6 +1435,18 @@ func (b *boot) buildDaemon() {
|
||||
if btc, ok := b.stateStore.(storecontract.BindingTaskCreator); ok {
|
||||
b.d.BindingTaskCreator = btc
|
||||
}
|
||||
// Dispatch is the second Authorizer call site: the chain built by
|
||||
// openAccessChain, the principal assembly over the wire, and the denial
|
||||
// record -- wired together or not at all (docs/prds/orgs-and-access.md).
|
||||
b.d.Access = b.accessChain
|
||||
if b.accessChain != nil {
|
||||
if principals, ok := b.stateStore.(access.PrincipalSource); ok {
|
||||
b.d.Principals = principals
|
||||
}
|
||||
if denials, ok := b.stateStore.(access.DenialStore); ok {
|
||||
b.d.Denials = denials
|
||||
}
|
||||
}
|
||||
b.d.PlaybookLedger = playbookLedger(b.stateStore, b.playbooks, b.log)
|
||||
b.setupForgeWebhook()
|
||||
}
|
||||
|
||||
@@ -358,21 +358,11 @@ func Run() int { //nolint:cyclop,funlen // the composition root's setup sequence
|
||||
return 1
|
||||
}
|
||||
|
||||
if err := b.openStores(ctx); err != nil {
|
||||
return 1
|
||||
}
|
||||
// Resolve the State Store surfaces before setupObservability wires the
|
||||
// dashboard's storage surfaces (§10): the shared contract adapter (the
|
||||
// remote *staterpc.Client dialed to [services.state].target; the daemon no
|
||||
// longer owns archie.db in-process, so an empty target is a composition
|
||||
// error, docs/prds/state-store-contract.md §12 step 7) and then, daemon
|
||||
// root only, the workflow-definitions client on this process's step
|
||||
// vocabulary. The daemon resolves step types through that client, so it is
|
||||
// built here -- after the adapter, whose transport it wraps -- and before
|
||||
// buildDaemon captures it. The gateway root shares only the adapter and
|
||||
// resolves no step type, so openDaemonStateSurfaces owns the order and
|
||||
// step_vocabulary_test.go pins the cut.
|
||||
if err := b.openDaemonStateSurfaces(); err != nil {
|
||||
// The state-store adapter, its daemon-side surfaces and the policy chain
|
||||
// dispatch evaluates: one ordered stage of the composition sequence
|
||||
// (openStateStage; docs/prds/state-store-contract.md §12 step 7 and
|
||||
// docs/prds/orgs-and-access.md).
|
||||
if err := b.openStateStage(ctx); err != nil {
|
||||
return 1
|
||||
}
|
||||
if err := b.loadRuntimeConfig(ctx); err != nil {
|
||||
|
||||
@@ -44,6 +44,9 @@ func (b *boot) setupReadinessProbes() {
|
||||
return pingChat(ctx, b.chat)
|
||||
}),
|
||||
}
|
||||
if b.accessProblems != nil {
|
||||
probes = append(probes, readiness.NewProblemProbe("access_policies", b.accessProblems))
|
||||
}
|
||||
b.healthRegistry = health.NewRegistry(probes...)
|
||||
}
|
||||
|
||||
|
||||
@@ -21,11 +21,13 @@ import (
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/app/controlplane"
|
||||
"github.com/samcharles93/archie-core/internal/config"
|
||||
"github.com/samcharles93/archie-core/internal/domain/access"
|
||||
"github.com/samcharles93/archie-core/internal/domain/health"
|
||||
"github.com/samcharles93/archie-core/internal/domain/identity"
|
||||
"github.com/samcharles93/archie-core/internal/domain/org"
|
||||
"github.com/samcharles93/archie-core/internal/domain/storecontract"
|
||||
"github.com/samcharles93/archie-core/internal/domain/storepkg"
|
||||
infraaccess "github.com/samcharles93/archie-core/internal/infrastructure/access"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/postgres"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/readiness"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/staterpc"
|
||||
@@ -70,7 +72,7 @@ type StateStoreOptions struct {
|
||||
// The conversation store belongs to the separate archie-gateway process. The
|
||||
// store service owns its own DB lifecycle, so
|
||||
// b.cleanup() is the sole owner closing b.st here (in-process owner).
|
||||
func RunStateStore(ctx context.Context, options StateStoreOptions) error {
|
||||
func RunStateStore(ctx context.Context, options StateStoreOptions) error { //nolint:cyclop // the composition root's setup sequence is deliberately flat and sequential
|
||||
b := newBootstrap()
|
||||
defer b.cleanup()
|
||||
if err := b.loadConfig(ctx, options.Config, options.Overlay); err != nil {
|
||||
@@ -105,12 +107,15 @@ func RunStateStore(ctx context.Context, options StateStoreOptions) error {
|
||||
return fmt.Errorf("upgrade default org: %w", err)
|
||||
}
|
||||
}
|
||||
if err := b.seedAndValidatePolicies(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
// The validating side's control plane, built here at the composition root
|
||||
// before the first definition is read or replaced.
|
||||
resources, ok := b.st.(controlplane.ResourceStore)
|
||||
if !ok {
|
||||
return fmt.Errorf("state store does not support control-plane resources")
|
||||
}
|
||||
// The validating side's control plane, built here at the composition root
|
||||
// before the first definition is read or replaced.
|
||||
control, err := openStateStoreControlPlane(resources)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -147,6 +152,52 @@ func RunStateStore(ctx context.Context, options StateStoreOptions) error {
|
||||
return serveStateStore(ctx, listener, deps, opts)
|
||||
}
|
||||
|
||||
// seedAndValidatePolicies seeds the shipped role policies for every org
|
||||
// that lacks them, grants the agent identities their org's shipped developer
|
||||
// role, and re-validates every stored policy this process serves
|
||||
// (docs/prds/orgs-and-access.md, "Storing and changing policies" and
|
||||
// "Roles"). An invalid org, workspace or object policy is logged here and
|
||||
// named as a problem by the engines the consumers build; an invalid instance
|
||||
// policy fails this boot -- the store stops serving until it is fixed. A
|
||||
// store without the access surfaces degrades: there is no chain to seed.
|
||||
func (b *boot) seedAndValidatePolicies(ctx context.Context) error {
|
||||
policies, ok := b.st.(access.PolicyStore)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
if agents, ok := b.st.(interface {
|
||||
EnsureAgentOrgMembership(context.Context) error
|
||||
}); ok {
|
||||
if err := agents.EnsureAgentOrgMembership(ctx); err != nil {
|
||||
return fmt.Errorf("grant agent org membership: %w", err)
|
||||
}
|
||||
}
|
||||
if orgs, ok := b.st.(org.Repository); ok {
|
||||
list, err := orgs.ListOrgs(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("list orgs for policy seeding: %w", err)
|
||||
}
|
||||
for _, o := range list {
|
||||
if err := policies.EnsureShippedOrgPolicies(ctx, o.ID); err != nil {
|
||||
return fmt.Errorf("seed shipped org policies for %s: %w", o.ID, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
stored, err := policies.ListPolicies(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("load stored policies: %w", err)
|
||||
}
|
||||
engine, err := infraaccess.New(stored)
|
||||
if err != nil {
|
||||
return fmt.Errorf("validate stored policies: %w", err)
|
||||
}
|
||||
for _, problem := range engine.Problems() {
|
||||
b.log.Error("stored access policy is invalid and denies its level",
|
||||
"policy", problem.Policy.ID, "level", problem.Policy.Level, "err", problem.Err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// reportUnseededResources logs every kind ImportConfig could not seed.
|
||||
//
|
||||
// Reported, not fatal: a stale TOML value in a setting the database owns must
|
||||
@@ -287,6 +338,19 @@ func (b *boot) stateStoreDeps(grants *staterpc.TaskGrants) staterpc.Deps {
|
||||
if wc, ok := b.st.(storecontract.WorkflowCaller); ok {
|
||||
deps.WorkflowCalls = wc
|
||||
}
|
||||
// The policy chain and its denial records are served from the same store
|
||||
// (docs/prds/orgs-and-access.md). A store without them -- one that owns
|
||||
// no tenant boundary yet -- degrades the access RPCs rather than failing
|
||||
// the boot, the same pattern the other optional surfaces use.
|
||||
if ps, ok := b.st.(access.PrincipalSource); ok {
|
||||
deps.Principals = ps
|
||||
}
|
||||
if ps, ok := b.st.(access.PolicyStore); ok {
|
||||
deps.Policies = ps
|
||||
}
|
||||
if ds, ok := b.st.(access.DenialStore); ok {
|
||||
deps.Denials = ds
|
||||
}
|
||||
if css, ok := b.st.(storecontract.ConfigSnapshotStore); ok {
|
||||
deps.ConfigSnapshots = css
|
||||
}
|
||||
|
||||
@@ -138,25 +138,27 @@ func TestOnlyTheDaemonRootRegistersAStepVocabulary(t *testing.T) {
|
||||
t.Error("the gateway root file mentions stepVocabulary; the gateway resolves no workflow step type")
|
||||
}
|
||||
|
||||
// The daemon root opens both halves -- the shared adapter and the
|
||||
// daemon-only definitions client -- through one call, so the sequence costs
|
||||
// Run a single branch. The guarantee is the one this pin always held,
|
||||
// relocated to where the sequence now lives: adapter first, then the client
|
||||
// built on its transport, both before buildDaemon captures the client.
|
||||
// The daemon root opens the state stage -- the shared adapter, the
|
||||
// daemon-only definitions client and the access chain -- through one
|
||||
// call, so the sequence costs Run a single branch. The guarantee is the
|
||||
// one this pin always held, relocated to where the sequence now lives:
|
||||
// adapter first, then the client built on its transport, both before
|
||||
// buildDaemon captures the client.
|
||||
run := parsedBody(t, "main.go", "Run")
|
||||
surfaces := methodCallPosition(run, "openDaemonStateSurfaces")
|
||||
stage := methodCallPosition(run, "openStateStage")
|
||||
build := methodCallPosition(run, "buildDaemon")
|
||||
if surfaces == token.NoPos {
|
||||
t.Fatal("Run never opens the daemon's State Store surfaces; every task pin would fall back to the shipped definitions")
|
||||
if stage == token.NoPos {
|
||||
t.Fatal("Run never opens the daemon's state stage; every task pin would fall back to the shipped definitions")
|
||||
}
|
||||
if build == token.NoPos || surfaces > build {
|
||||
t.Errorf("Run opens the daemon's State Store surfaces at %v, after buildDaemon at %v: the daemon would capture no definitions surface", surfaces, build)
|
||||
if build == token.NoPos || stage > build {
|
||||
t.Errorf("Run opens the state stage at %v, after buildDaemon at %v: the daemon would capture no definitions surface", stage, build)
|
||||
}
|
||||
// Neither half may also be opened from Run directly: a second call site
|
||||
// would be a copy of the sequence outside the order asserted below.
|
||||
for _, direct := range []string{"openStateStoreAdapter", "openDaemonWorkflowDefinitions"} {
|
||||
// No half of the stage may also be opened from Run directly: a second
|
||||
// call site would be a copy of the sequence outside the order asserted
|
||||
// below.
|
||||
for _, direct := range []string{"openStateStoreAdapter", "openDaemonWorkflowDefinitions", "openDaemonStateSurfaces", "openAccessChain"} {
|
||||
if pos := methodCallPosition(run, direct); pos != token.NoPos {
|
||||
t.Errorf("Run calls %s directly at %v; the daemon's State Store surfaces open through openDaemonStateSurfaces alone", direct, pos)
|
||||
t.Errorf("Run calls %s directly at %v; the state stage opens through openStateStage alone", direct, pos)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
controlpb "github.com/samcharles93/archie-core/internal/contracts/controlplane/v1"
|
||||
"github.com/samcharles93/archie-core/internal/domain/access"
|
||||
"github.com/samcharles93/archie-core/internal/domain/health"
|
||||
"github.com/samcharles93/archie-core/internal/domain/identity"
|
||||
"github.com/samcharles93/archie-core/internal/domain/messaging"
|
||||
@@ -33,6 +34,12 @@ type deps struct {
|
||||
// Login drives the browser sign-in flow, or nil when no provider is
|
||||
// configured for it.
|
||||
Login identity.LoginFlow
|
||||
// Access evaluates the policy chain; Principals assembles the request
|
||||
// principal; Denials records refusals
|
||||
// (docs/prds/orgs-and-access.md). Wired together or not at all.
|
||||
Access access.Authorizer
|
||||
Principals access.PrincipalSource
|
||||
Denials access.DenialStore
|
||||
}
|
||||
|
||||
// compose builds the dashboard server for the UI process. It sets exactly the
|
||||
@@ -114,6 +121,11 @@ func compose(d deps) *webui.Server {
|
||||
// rather than opening a path (docs/prds/ui-service-boundary.md). Withholding
|
||||
// it would degrade a page that has an owner, and would leave the dashboard
|
||||
// claiming task logging was not enabled -- see wireTaskLogs.
|
||||
// The policy chain: wired together or not at all
|
||||
// (docs/prds/orgs-and-access.md, "Where it lives").
|
||||
srv.Access = d.Access
|
||||
srv.Principals = d.Principals
|
||||
srv.Denials = d.Denials
|
||||
wireTaskLogs(d, srv)
|
||||
wireCaptureSurfaces(d, srv)
|
||||
return srv
|
||||
|
||||
@@ -181,6 +181,6 @@ func composeUIProcess(t *testing.T) (*webui.Server, int64) {
|
||||
Options: options,
|
||||
Log: slog.New(slog.DiscardHandler),
|
||||
Store: client,
|
||||
Health: newReadinessRegistry(options, client, nil),
|
||||
Health: newReadinessRegistry(options, client, nil, nil),
|
||||
}), task.ID
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/samcharles93/archie-core/internal/domain/health"
|
||||
"github.com/samcharles93/archie-core/internal/domain/messaging"
|
||||
"github.com/samcharles93/archie-core/internal/domain/storecontract"
|
||||
infraaccess "github.com/samcharles93/archie-core/internal/infrastructure/access"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/readiness"
|
||||
)
|
||||
|
||||
@@ -17,8 +18,9 @@ import (
|
||||
//
|
||||
// The component names match the daemon dashboard's, so the readiness view
|
||||
// reads the same whichever process serves it.
|
||||
func newReadinessRegistry(o Options, tasks storecontract.TaskStore, chat messaging.ChatContract) *health.Registry {
|
||||
func newReadinessRegistry(o Options, tasks storecontract.TaskStore, chat messaging.ChatContract, problems []infraaccess.Problem) *health.Registry {
|
||||
return health.NewRegistry(
|
||||
readiness.NewProblemProbe("access_policies", problems),
|
||||
readiness.NewContractProbe("state_db", o.DependencyTimeout, func(ctx context.Context) error {
|
||||
_, err := tasks.StatusCounts(ctx)
|
||||
return err
|
||||
|
||||
@@ -10,11 +10,43 @@ import (
|
||||
"os"
|
||||
"slices"
|
||||
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/access"
|
||||
infraaccess "github.com/samcharles93/archie-core/internal/infrastructure/access"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/gatewayrpc"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/staterpc"
|
||||
"github.com/samcharles93/archie-core/internal/webui"
|
||||
)
|
||||
|
||||
// buildAccessChain loads the stored policies over the wire and builds the
|
||||
// engine. The wire client satisfies the two access contracts the dashboard
|
||||
// needs alongside the engine.
|
||||
// buildAccessChain loads the stored policies over the wire and builds the
|
||||
// engine. A State Store serving no policies has no chain to evaluate: the
|
||||
// dashboard degrades to the credential check rather than refusing to serve,
|
||||
// so an unavailable policy store is a warning, not a boot failure.
|
||||
func buildAccessChain(ctx context.Context, store *staterpc.Client, log *slog.Logger) (access.Authorizer, []infraaccess.Problem, error) {
|
||||
stored, err := store.ListPolicies(ctx)
|
||||
if err != nil {
|
||||
if status.Code(err) == codes.Unavailable {
|
||||
log.Warn("access chain unavailable; the credential check is the gate", "err", err)
|
||||
return nil, nil, nil
|
||||
}
|
||||
return nil, nil, err
|
||||
}
|
||||
engine, err := infraaccess.New(stored)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
for _, problem := range engine.Problems() {
|
||||
log.Error("stored access policy is invalid and denies its level",
|
||||
"policy", problem.Policy.ID, "level", problem.Policy.Level, "err", problem.Err)
|
||||
}
|
||||
return engine, engine.Problems(), nil
|
||||
}
|
||||
|
||||
// Run serves the dashboard until ctx is cancelled. It resolves its own
|
||||
// options, dials the Gateway and State Store contracts itself, composes the
|
||||
// HTTP surface over them, and unwinds listener then clients in reverse order
|
||||
@@ -44,6 +76,15 @@ func Run(ctx context.Context, options Options) error {
|
||||
}
|
||||
cleanups = append(cleanups, closeGateway)
|
||||
|
||||
chain, problems, err := buildAccessChain(ctx, tasks, log)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, problem := range problems {
|
||||
log.Error("stored access policy is invalid and denies its level",
|
||||
"policy", problem.Policy.ID, "level", problem.Policy.Level, "err", problem.Err)
|
||||
}
|
||||
|
||||
authenticate, err := dashboardAuthenticator(ctx, opts, tasks, log)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -58,11 +99,14 @@ func Run(ctx context.Context, options Options) error {
|
||||
Log: log,
|
||||
Store: tasks,
|
||||
Chat: chat,
|
||||
Health: newReadinessRegistry(opts, tasks, chat),
|
||||
Health: newReadinessRegistry(opts, tasks, chat, problems),
|
||||
ControlPlane: tasks.ControlPlane(),
|
||||
Identities: tasks,
|
||||
Authenticate: authenticate,
|
||||
Login: login,
|
||||
Access: chain,
|
||||
Principals: tasks,
|
||||
Denials: tasks,
|
||||
})
|
||||
|
||||
// Live activity has no in-process bus in this process: the pump reads
|
||||
|
||||
@@ -178,7 +178,7 @@ func TestUIServesDashboardAgainstRemoteContracts(t *testing.T) {
|
||||
Log: slog.New(slog.DiscardHandler),
|
||||
Store: stateClient,
|
||||
Chat: chatClient,
|
||||
Health: newReadinessRegistry(options, stateClient, chatClient),
|
||||
Health: newReadinessRegistry(options, stateClient, chatClient, nil),
|
||||
})
|
||||
ts := httptest.NewServer(srv.Handler())
|
||||
defer ts.Close()
|
||||
|
||||
@@ -193,7 +193,7 @@ func composeUIProcessWithLog(t *testing.T) (*webui.Server, int64, int) {
|
||||
Options: options,
|
||||
Log: slog.New(slog.DiscardHandler),
|
||||
Store: client,
|
||||
Health: newReadinessRegistry(options, client, nil),
|
||||
Health: newReadinessRegistry(options, client, nil, nil),
|
||||
})
|
||||
return srv, task.ID, task.Attempt
|
||||
}
|
||||
Reference in new issue
Block a user