feat(access): denial retention knob, State Store sweep and dashboard denials page (#1842)
Add [access].denial_retention (default 90 days, matching the audit-retention seed) wired through config defaults and validation; the State Store sweeps denial records older than the configured age hourly via the new access.DenialPruner / PruneDenials store query. The dashboard gains GET /api/access/denials (read_audit-gated, so org admins/owners see their org's records; the store scopes by the credential's org) and an /org/denials page backed by a Pinia store.
This commit is contained in:
1 parent
369e741df1
commit
da01f2cbe1
28 files changed
+625
-116
No files matched your search
@@ -93,9 +93,7 @@ func compose(ctx context.Context, d deps) *webui.Server {
|
||||
// client already carries them: withholding them would degrade two pages
|
||||
// that have an owner, which is a different thing from the intake surfaces
|
||||
// below.
|
||||
if policies, ok := d.Store.(access.PolicyStore); ok {
|
||||
srv.Policies = policies
|
||||
}
|
||||
wireAccessSurfaces(srv, d.Store)
|
||||
wireAudit(srv, d.Store)
|
||||
wireOrgSurface(srv, d.Store)
|
||||
wireAlerts(srv, d.Store)
|
||||
@@ -134,6 +132,17 @@ func compose(ctx context.Context, d deps) *webui.Server {
|
||||
return srv
|
||||
}
|
||||
|
||||
// wireAccessSurfaces attaches the stored policy chain and the denial-record
|
||||
// list when the state client carries them.
|
||||
func wireAccessSurfaces(srv *webui.Server, store storecontract.TaskStore) {
|
||||
if policies, ok := store.(access.PolicyStore); ok {
|
||||
srv.Policies = policies
|
||||
}
|
||||
if denials, ok := store.(access.DenialStore); ok {
|
||||
srv.DenialLister = denials
|
||||
}
|
||||
}
|
||||
|
||||
// wireAudit attaches the State Store's org-scoped audit feed. A store that
|
||||
// cannot serve it leaves the audit routes answering 503 rather than showing an
|
||||
// empty timeline.
|
||||
|
||||
@@ -74,10 +74,12 @@ func serviceAlert(name string) alert.Input {
|
||||
}
|
||||
|
||||
// startSweeps starts the store's periodic work: auto-updating packages,
|
||||
// checking service health and pruning alerts, and applying audit retention.
|
||||
// checking service health and pruning alerts, and applying audit and denial
|
||||
// retention.
|
||||
func (b *server) startSweeps(ctx context.Context, deps staterpc.Deps) {
|
||||
go b.autoUpdatePackages(ctx, deps.Packages)
|
||||
go b.sweepAuditRetention(ctx)
|
||||
go b.sweepDenials(ctx)
|
||||
go b.sweepScheduleRuns(ctx, deps)
|
||||
if deps.Alerts != nil {
|
||||
go b.sweepAlerts(ctx, deps.Alerts)
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package statestore
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/access"
|
||||
)
|
||||
|
||||
// denialSweepInterval is how often the configured denial retention is applied.
|
||||
const denialSweepInterval = time.Hour
|
||||
|
||||
// sweepDenials deletes denial records older than the configured
|
||||
// access.denial_retention until ctx ends. A non-positive retention keeps the
|
||||
// records forever, so the sweep does not run at all in that case.
|
||||
func (b *server) sweepDenials(ctx context.Context) {
|
||||
pruner, ok := b.st.(access.DenialPruner)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
retention := b.cfg.Access.DenialRetention.Std()
|
||||
if retention <= 0 {
|
||||
return
|
||||
}
|
||||
ticker := time.NewTicker(denialSweepInterval)
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
cutoff := time.Now().Add(-retention)
|
||||
rows, err := pruner.PruneDenials(ctx, cutoff)
|
||||
switch {
|
||||
case err != nil:
|
||||
if ctx.Err() == nil {
|
||||
b.log.WarnContext(ctx, "prune access denials", "err", err)
|
||||
}
|
||||
case rows > 0:
|
||||
b.log.InfoContext(ctx, "pruned access denials", "rows", rows, "cutoff", cutoff.UTC())
|
||||
}
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-ticker.C:
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -414,6 +414,7 @@ type Config struct {
|
||||
Containers ContainerConfig `toml:"containers" yaml:"containers"`
|
||||
Chat ChatConfig `toml:"chat" yaml:"chat"`
|
||||
Capture CaptureConfig `toml:"capture" yaml:"capture"`
|
||||
Access AccessConfig `toml:"access" yaml:"access"`
|
||||
Bindings BindingsConfig `toml:"bindings" yaml:"bindings"`
|
||||
|
||||
// Memory holds memory provider configuration (from config.memory.yaml).
|
||||
@@ -662,6 +663,14 @@ type CaptureConfig struct {
|
||||
RateBurst int `toml:"rate_burst" yaml:"rate_burst"`
|
||||
}
|
||||
|
||||
// AccessConfig configures the access surfaces: the stored policy chain and
|
||||
// the denial records the State Store keeps.
|
||||
type AccessConfig struct {
|
||||
// DenialRetention is how long a recorded access denial is kept before
|
||||
// the State Store's sweep deletes it. Zero means the 90-day default.
|
||||
DenialRetention Duration `toml:"denial_retention" yaml:"denial_retention"`
|
||||
}
|
||||
|
||||
// BindingsConfig configures the playbook-binding store (t2db). When
|
||||
// EncryptionKey is unset, binding secrets are persisted as plaintext
|
||||
// (legacy behaviour); when set, they are AES-256-GCM encrypted at rest
|
||||
|
||||
@@ -5,6 +5,7 @@ package access
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/org"
|
||||
)
|
||||
@@ -61,3 +62,12 @@ type DenialStore interface {
|
||||
// ListDenials returns an org's most recent denials, newest first.
|
||||
ListDenials(ctx context.Context, orgID org.OrgID, limit int) ([]Denial, error)
|
||||
}
|
||||
|
||||
// DenialPruner deletes denial records older than a cutoff. The State Store's
|
||||
// retention sweep is its only caller: the configured retention decides the
|
||||
// cutoff, and this deletes nothing else.
|
||||
type DenialPruner interface {
|
||||
// PruneDenials deletes every denial record created before cutoff and
|
||||
// returns how many rows it removed.
|
||||
PruneDenials(ctx context.Context, cutoff time.Time) (int64, error)
|
||||
}
|
||||
@@ -52,6 +52,7 @@ var dashboardPages = []DashboardPage{
|
||||
{Path: "/org/scheduling-policy", Label: "Scheduling policy", Description: "Work discovery and forge labels."},
|
||||
{Path: "/settings/tools", Label: "Tools & MCP", Description: "Agent tools and MCP servers."},
|
||||
{Path: "/org/audit", Label: "Audit", Description: "Settings, access, identity and runtime events."},
|
||||
{Path: "/org/denials", Label: "Denials", Description: "Access requests the policy chain refused, newest first."},
|
||||
{Path: "/settings/plugins", Label: "Plugins", Description: "Extension directories loaded at startup."},
|
||||
{Path: "/settings/secret-engines", Label: "Secret engines"},
|
||||
{Path: "/settings/container-runtime", Label: "Container runtime"},
|
||||
|
||||
@@ -42,6 +42,11 @@ const (
|
||||
defaultCaptureRatePerSecond = 1.0
|
||||
defaultCaptureRateBurst = 5
|
||||
|
||||
// defaultDenialRetention keeps denial records for 90 days, the same
|
||||
// horizon the audit-retention seed gives the audit trail
|
||||
// (docs/prds/orgs-and-access.md, "Audit retention").
|
||||
defaultDenialRetention = 90 * 24 * time.Hour
|
||||
|
||||
// defaultHealthListen is the daemon's own liveness address.
|
||||
defaultHealthListen = "127.0.0.1:8485"
|
||||
|
||||
@@ -70,6 +75,7 @@ func (l *Loader) applyDefaults(cfg *config.Config) {
|
||||
applyContainerDefaults(cfg)
|
||||
applyToolPolicyDefaults(cfg)
|
||||
applyCaptureDefaults(cfg)
|
||||
applyAccessDefaults(cfg)
|
||||
applyNATSDefaults(cfg)
|
||||
applyMemoryDefaults(cfg)
|
||||
applyCuratorDefaults(cfg)
|
||||
@@ -249,6 +255,14 @@ func applyForgeDefaults(cfg *config.Config) {
|
||||
}
|
||||
}
|
||||
|
||||
// applyAccessDefaults fills the access surfaces' settings. See
|
||||
// [config.AccessConfig].
|
||||
func applyAccessDefaults(cfg *config.Config) {
|
||||
if cfg.Access.DenialRetention == 0 {
|
||||
cfg.Access.DenialRetention = config.Duration(defaultDenialRetention)
|
||||
}
|
||||
}
|
||||
|
||||
// applyNATSDefaults resolves the nats mode from URL when the operator left it
|
||||
// unset. URL set implies external; URL empty implies embedded.
|
||||
func applyNATSDefaults(cfg *config.Config) {
|
||||
|
||||
@@ -17,6 +17,7 @@ var DeniedKeys = map[string]string{
|
||||
"org": "Pins the deployment's org at startup.",
|
||||
"memory.engine": "Constructs the memory engine at startup.",
|
||||
"capture.*": "Constructs the dashboard capture receiver at startup.",
|
||||
"access.*": "Read by the State Store's denial sweep at startup; a change needs a restart.",
|
||||
"log.level": "Constructs each service's logging handlers at startup.",
|
||||
"log.*": "Constructs each service's logging handlers at startup.",
|
||||
"tools.mcp_servers[].headers": "Process credentials supplied at startup; values are never published.",
|
||||
|
||||
@@ -75,7 +75,10 @@ func validateBootstrap(cfg *config.Config) error {
|
||||
if err := validateCurators(cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
return validateCapture(cfg)
|
||||
if err := validateCapture(cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
return validateAccess(cfg)
|
||||
}
|
||||
|
||||
// validateDatabaseOwned checks the settings the control plane owns:
|
||||
@@ -96,6 +99,14 @@ func validateDatabaseOwned(cfg *config.Config) error {
|
||||
return validateRepositoryContents(cfg)
|
||||
}
|
||||
|
||||
// validateAccess rejects a negative denial retention.
|
||||
func validateAccess(cfg *config.Config) error {
|
||||
if cfg.Access.DenialRetention < 0 {
|
||||
return fmt.Errorf("%w: access.denial_retention must not be negative", ErrInvalidInput)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// validateCurators rejects a curator definition with no interval. The
|
||||
// interval is a live-path value: a definition missing it is refused with a
|
||||
// clear error rather than defaulted at registration or pass time, so a
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
|
||||
@@ -22,9 +23,10 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
_ access.PolicyStore = (*Store)(nil)
|
||||
_ access.Resetter = (*Store)(nil)
|
||||
_ access.DenialStore = (*Store)(nil)
|
||||
_ access.PolicyStore = (*Store)(nil)
|
||||
_ access.Resetter = (*Store)(nil)
|
||||
_ access.DenialStore = (*Store)(nil)
|
||||
_ access.DenialPruner = (*Store)(nil)
|
||||
)
|
||||
|
||||
// shippedOrgPolicyIDs lists an org's shipped role policy IDs: the seed's
|
||||
@@ -403,3 +405,26 @@ func (s *Store) ListDenials(ctx context.Context, orgID org.OrgID, limit int) ([]
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// denialPruneBatch is one delete's bound, so a single sweep does not own the
|
||||
// table for an unbounded time.
|
||||
const denialPruneBatch = 10_000
|
||||
|
||||
// PruneDenials deletes the denial records created before cutoff in bounded
|
||||
// batches and returns how many rows it removed. The State Store's retention
|
||||
// sweep is the only caller: the configured retention sets the cutoff.
|
||||
func (s *Store) PruneDenials(ctx context.Context, cutoff time.Time) (int64, error) {
|
||||
var total int64
|
||||
for {
|
||||
removed, err := s.queries().PruneDenials(ctx, postgresdb.PruneDenialsParams{
|
||||
Cutoff: cutoff.UTC(), Batch: denialPruneBatch,
|
||||
})
|
||||
if err != nil {
|
||||
return total, err
|
||||
}
|
||||
total += removed
|
||||
if removed < denialPruneBatch {
|
||||
return total, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ package postgresdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
@@ -329,6 +330,32 @@ func (q *Queries) LockPolicyWrite(ctx context.Context, key string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
const pruneDenials = `-- name: PruneDenials :execrows
|
||||
DELETE FROM access_denials
|
||||
WHERE id IN (
|
||||
SELECT id FROM access_denials
|
||||
WHERE created_at < $1::timestamptz
|
||||
ORDER BY created_at
|
||||
LIMIT $2::bigint
|
||||
)
|
||||
`
|
||||
|
||||
type PruneDenialsParams struct {
|
||||
Cutoff time.Time
|
||||
Batch int64
|
||||
}
|
||||
|
||||
// The retention sweep's delete: every denial record created before the
|
||||
// cutoff, oldest first in bounded batches so one sweep does not own the
|
||||
// table for an unbounded time.
|
||||
func (q *Queries) PruneDenials(ctx context.Context, arg PruneDenialsParams) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, pruneDenials, arg.Cutoff, arg.Batch)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const recordDenial = `-- name: RecordDenial :exec
|
||||
INSERT INTO access_denials (org_id, principal, action, resource_kind, resource_id, level, policies)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||
|
||||
@@ -74,6 +74,18 @@ DO UPDATE SET count = access_denials.count + 1, updated_at = now();
|
||||
SELECT id, org_id, principal, action, resource_kind, resource_id, level, policies, minute_at, count, created_at, updated_at
|
||||
FROM access_denials WHERE org_id = $1 ORDER BY id DESC LIMIT $2;
|
||||
|
||||
-- name: PruneDenials :execrows
|
||||
-- The retention sweep's delete: every denial record created before the
|
||||
-- cutoff, oldest first in bounded batches so one sweep does not own the
|
||||
-- table for an unbounded time.
|
||||
DELETE FROM access_denials
|
||||
WHERE id IN (
|
||||
SELECT id FROM access_denials
|
||||
WHERE created_at < sqlc.arg(cutoff)::timestamptz
|
||||
ORDER BY created_at
|
||||
LIMIT sqlc.arg(batch)::bigint
|
||||
);
|
||||
|
||||
-- name: InsertAccessResetAudit :exec
|
||||
INSERT INTO sys_audit (at, table_name, record_key, field, record_version, actor, source, request_id, org_id)
|
||||
VALUES (now(), 'access_policies', $1, 'reset', 1, 'archie-state-store access reset', 'archie-state-store', '', $2);
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
// The Client satisfies the access contracts the two callers depend on.
|
||||
var (
|
||||
_ access.PolicyStore = (*Client)(nil)
|
||||
_ access.DenialRecorder = (*Client)(nil)
|
||||
_ access.DenialStore = (*Client)(nil)
|
||||
_ access.PrincipalSource = (*Client)(nil)
|
||||
)
|
||||
|
||||
@@ -82,3 +82,17 @@ func (c *Client) RecordDenial(ctx context.Context, d access.Denial) error {
|
||||
_, err := c.access.RecordDenial(ctx, &pb.RecordDenialRequest{Denial: accessDenialProto(d)})
|
||||
return unmapError(err)
|
||||
}
|
||||
|
||||
// ListDenials returns the denials the credential's org holds, newest first.
|
||||
// The org is the one the State Store derives from the caller's credential, so
|
||||
// the contract's orgID is not sent: no request field sets scope.
|
||||
func (c *Client) ListDenials(ctx context.Context, _ org.OrgID, limit int) ([]access.Denial, error) {
|
||||
if limit <= 0 || limit > 1000 {
|
||||
limit = 100
|
||||
}
|
||||
r, err := c.access.ListDenials(ctx, &pb.ListDenialsRequest{Limit: int32(limit)})
|
||||
if err != nil {
|
||||
return nil, unmapError(err)
|
||||
}
|
||||
return mapValues(r.GetDenials(), accessDenialValue), nil
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package webui
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/access"
|
||||
)
|
||||
|
||||
const defaultDenialsListLimit = 100
|
||||
|
||||
// handleListDenials lists the caller's org's recorded access denials, newest
|
||||
// first. The route's read_audit grant limits it to the org's admins and
|
||||
// owners, and the store scopes the list by the credential's org, so no
|
||||
// request field chooses the org an operator reads.
|
||||
func (s *Server) handleListDenials(w http.ResponseWriter, r *http.Request) {
|
||||
if s.DenialLister == nil {
|
||||
http.Error(w, "denial records unavailable", http.StatusServiceUnavailable)
|
||||
return
|
||||
}
|
||||
limit, err := strconv.ParseInt(r.URL.Query().Get("limit"), 10, 32)
|
||||
if err != nil || limit <= 0 || limit > 1000 {
|
||||
limit = defaultDenialsListLimit
|
||||
}
|
||||
denials, err := s.DenialLister.ListDenials(r.Context(), policyOrg(r), int(limit))
|
||||
if err != nil {
|
||||
writeControlPlaneError(w, err)
|
||||
return
|
||||
}
|
||||
if denials == nil {
|
||||
denials = []access.Denial{}
|
||||
}
|
||||
writeJSON(w, map[string]any{"denials": denials})
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
package webui
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/access"
|
||||
"github.com/samcharles93/archie-core/internal/domain/org"
|
||||
infraaccess "github.com/samcharles93/archie-core/internal/infrastructure/access"
|
||||
)
|
||||
|
||||
// fakeDenialStore records the scope it was asked for and serves fixed rows.
|
||||
type fakeDenialStore struct {
|
||||
orgID org.OrgID
|
||||
limit int
|
||||
denials []access.Denial
|
||||
}
|
||||
|
||||
func (f *fakeDenialStore) RecordDenial(context.Context, access.Denial) error { return nil }
|
||||
|
||||
func (f *fakeDenialStore) ListDenials(_ context.Context, orgID org.OrgID, limit int) ([]access.Denial, error) {
|
||||
f.orgID, f.limit = orgID, limit
|
||||
out := make([]access.Denial, 0, len(f.denials))
|
||||
for _, d := range f.denials {
|
||||
if d.Org == orgID {
|
||||
out = append(out, d)
|
||||
}
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// TestDenialsRouteRequiresAdmin pins the denials route's grant: reading the
|
||||
// org's denial records needs the same read_audit grant as the audit feed, so a
|
||||
// viewer and a developer are refused and an admin reaches the handler.
|
||||
func TestDenialsRouteRequiresAdmin(t *testing.T) {
|
||||
const path = "/api/access/denials"
|
||||
tests := []struct {
|
||||
role org.Role
|
||||
want int
|
||||
}{
|
||||
{org.RoleViewer, http.StatusForbidden},
|
||||
{org.RoleDeveloper, http.StatusForbidden},
|
||||
{org.RoleAdmin, http.StatusOK},
|
||||
{org.RoleOwner, http.StatusOK},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(string(tt.role), func(t *testing.T) {
|
||||
principal := memberOf("alice", "acme", tt.role)
|
||||
srv := &Server{
|
||||
Accounts: accountBoundaryStore{},
|
||||
Access: infraaccess.New(access.ShippedOrgPolicies("acme")),
|
||||
Principals: principalOf(principal),
|
||||
DenialLister: &fakeDenialStore{},
|
||||
}
|
||||
req := httptest.NewRequestWithContext(t.Context(), http.MethodGet, "https://archie.example"+path, nil)
|
||||
req.Header.Set("X-Archie-CSRF", "1")
|
||||
req.AddCookie(&http.Cookie{Name: "archie_session", Value: "valid"})
|
||||
rec := httptest.NewRecorder()
|
||||
srv.Handler().ServeHTTP(rec, req)
|
||||
if rec.Code != tt.want {
|
||||
t.Fatalf("status = %d, want %d body=%s", rec.Code, tt.want, rec.Body.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestHandleListDenialsScopesToCallersOrg pins the handler's scoping: the list
|
||||
// is asked for the caller's org only, so another org's records are never
|
||||
// fetched, and the limit comes from the query, clamped to the default.
|
||||
func TestHandleListDenialsScopesToCallersOrg(t *testing.T) {
|
||||
store := &fakeDenialStore{denials: []access.Denial{
|
||||
{Org: "acme", Principal: "alice", Action: access.ActionRead, Kind: access.KindTask, ResourceID: "7", Level: access.LevelOrg},
|
||||
{Org: "other", Principal: "bob", Action: access.ActionRead, Kind: access.KindTask, ResourceID: "9", Level: access.LevelOrg},
|
||||
}}
|
||||
srv := &Server{DenialLister: store}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
caller org.OrgID
|
||||
query string
|
||||
wantOrg org.OrgID
|
||||
wantRows int
|
||||
wantCap int
|
||||
}{
|
||||
{"the caller's org is the scope, with the query's limit", "acme", "?limit=5", "acme", 1, 5},
|
||||
{"another org's caller gets that org, not acme's rows", "other", "", "other", 1, defaultDenialsListLimit},
|
||||
{"an oversized limit falls back to the default", "acme", "?limit=5000", "acme", 1, defaultDenialsListLimit},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
principal := memberOf("alice", tt.caller, org.RoleAdmin)
|
||||
ctx := org.WithOrg(access.WithPrincipal(t.Context(), principal), tt.caller)
|
||||
req := httptest.NewRequestWithContext(ctx, http.MethodGet, "/api/access/denials"+tt.query, nil)
|
||||
rec := httptest.NewRecorder()
|
||||
srv.handleListDenials(rec, req)
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("status = %d, want 200 body=%s", rec.Code, rec.Body.String())
|
||||
}
|
||||
if store.orgID != tt.wantOrg {
|
||||
t.Fatalf("listed org = %q, want %q", store.orgID, tt.wantOrg)
|
||||
}
|
||||
if store.limit != tt.wantCap {
|
||||
t.Fatalf("limit = %d, want %d", store.limit, tt.wantCap)
|
||||
}
|
||||
var body struct {
|
||||
Denials []access.Denial `json:"denials"`
|
||||
}
|
||||
if err := json.Unmarshal(rec.Body.Bytes(), &body); err != nil {
|
||||
t.Fatalf("decode body: %v", err)
|
||||
}
|
||||
if len(body.Denials) != tt.wantRows {
|
||||
t.Fatalf("rows = %d, want %d", len(body.Denials), tt.wantRows)
|
||||
}
|
||||
for _, d := range body.Denials {
|
||||
if d.Org != tt.wantOrg {
|
||||
t.Fatalf("row from org %q in a %q list", d.Org, tt.wantOrg)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestHandleListDenialsUnwired pins the unwired answer: a dashboard without
|
||||
// the denial list answers 503 rather than an empty list.
|
||||
func TestHandleListDenialsUnwired(t *testing.T) {
|
||||
srv := &Server{}
|
||||
req := httptest.NewRequestWithContext(t.Context(), http.MethodGet, "/api/access/denials", nil)
|
||||
rec := httptest.NewRecorder()
|
||||
srv.handleListDenials(rec, req)
|
||||
if rec.Code != http.StatusServiceUnavailable {
|
||||
t.Fatalf("status = %d, want 503", rec.Code)
|
||||
}
|
||||
}
|
||||
@@ -45,6 +45,7 @@ func pageProbes() []pageProbe {
|
||||
{"org_members", http.MethodPost, "/api/orgs/_/members"},
|
||||
{"org_agents", http.MethodPut, "/api/orgs/_/agents/_"},
|
||||
{"org_policies", http.MethodPut, "/api/access/policies"},
|
||||
{"org_denials", http.MethodGet, "/api/access/denials"},
|
||||
{"org_audit", http.MethodGet, "/api/audit"},
|
||||
{"org_config", http.MethodPost, "/api/control-plane/resources/_/commands/replace"},
|
||||
}
|
||||
|
||||
@@ -305,8 +305,8 @@ func routeOverride(action access.Action, path string) (access.Action, access.Res
|
||||
switch {
|
||||
case matchSegment(path, "/api/tasks/", "/logs"), matchSegment(path, "/api/tasks/", "/sandbox"):
|
||||
return access.ActionReadLogs, access.KindTask, segmentValue(path, 2), true
|
||||
case matchPrefix(path, "/api/access/policies"):
|
||||
return policyAction(action), access.KindPolicy, "", true
|
||||
case matchPrefix(path, "/api/access"):
|
||||
return accessRoute(action, path)
|
||||
case matchPrefix(path, "/api/identities"):
|
||||
return actionManage(action), access.KindIdentity, segmentValue(path, 2), true
|
||||
case matchPrefix(path, "/api/orgs"):
|
||||
@@ -406,8 +406,17 @@ func kindOf(path string) access.ResourceKind {
|
||||
return access.KindDashboard
|
||||
}
|
||||
|
||||
// actionManage lifts a create or update on a managed surface to the manage
|
||||
// action the role vocabulary carries.
|
||||
// accessRoute maps the access routes: policy management on the policies
|
||||
// routes, and on the denials route the same read_audit grant the audit feed
|
||||
// carries, which the shipped role policies give an org's admins and owners
|
||||
// only -- denial records are the access trail's operator surface.
|
||||
func accessRoute(action access.Action, path string) (access.Action, access.ResourceKind, string, bool) {
|
||||
if matchPrefix(path, "/api/access/policies") {
|
||||
return policyAction(action), access.KindPolicy, "", true
|
||||
}
|
||||
return access.ActionReadAudit, access.KindAudit, "", true
|
||||
}
|
||||
|
||||
// policyAction lifts every write on the policy routes to manage_policies.
|
||||
func policyAction(action access.Action) access.Action {
|
||||
if action == access.ActionRead {
|
||||
@@ -416,6 +425,8 @@ func policyAction(action access.Action) access.Action {
|
||||
return access.ActionManagePolicies
|
||||
}
|
||||
|
||||
// actionManage lifts a create or update on a managed surface to the manage
|
||||
// action the role vocabulary carries.
|
||||
func actionManage(action access.Action) access.Action {
|
||||
switch action {
|
||||
case access.ActionCreate, access.ActionUpdate:
|
||||
|
||||
@@ -117,6 +117,9 @@ type Server struct {
|
||||
// Policies is the stored access policy chain, behind the policies page.
|
||||
// Nil answers 503.
|
||||
Policies access.PolicyStore
|
||||
// DenialLister lists the caller's org's recorded denials, behind the
|
||||
// denials page. Nil answers 503.
|
||||
DenialLister access.DenialStore
|
||||
// Audit is the org-scoped audit feed, behind the audit page and the live
|
||||
// tail. Nil answers 503 on every audit route.
|
||||
Audit audit.Store
|
||||
@@ -379,6 +382,7 @@ func (s *Server) registerConfigAndLogRoutes(mux *http.ServeMux) {
|
||||
mux.HandleFunc("GET /api/access/policies", s.handleListPolicies)
|
||||
mux.HandleFunc("PUT /api/access/policies", s.handlePutPolicy)
|
||||
mux.HandleFunc("DELETE /api/access/policies", s.handleDeletePolicy)
|
||||
mux.HandleFunc("GET /api/access/denials", s.handleListDenials)
|
||||
mux.HandleFunc("GET /api/control-plane/resources/{kind}", s.handleControlPlaneQuery)
|
||||
mux.HandleFunc("GET /api/control-plane/resources/{kind}/history", s.handleControlPlaneHistory)
|
||||
mux.HandleFunc("POST /api/control-plane/resources/{kind}/commands/{command}", s.handleControlPlaneCommand)
|
||||
|
||||
Reference in new issue
Block a user