Documentation
¶
Overview ¶
Package store defines the composite store interface for Shield.
The composite store composes all subsystem store interfaces into a single interface. Implementations (Postgres, SQLite, Memory) satisfy the composite.
Index ¶
- Variables
- func DashboardWritable(scope Scope, kind string, row map[string]any) bool
- func Editable(kind string) bool
- func FilterColumn(kind, field string) bool
- func MarshalDashboard(v any) (json.RawMessage, error)
- func NextRevision(previous any) time.Time
- func Prefix(kind string) string
- func ReferenceField(kind string) string
- func ReportLevels(ctx context.Context, key string) ([]string, error)
- func ReportScope(ctx context.Context) (key, level string, ok bool)
- func ScopeLevels(ctx context.Context, key, level string) ([]string, error)
- func ScopeVisible(ctx context.Context, key, level string) bool
- func ScopeWritable(ctx context.Context, key, level string) error
- func Tenant(ctx context.Context, want string) (string, error)
- func UpdateRevision(before, patch map[string]any) (time.Time, error)
- func ValidReferenceKind(kind string) bool
- func ValidateRetention(scope Scope, cutoff time.Time, keys []string) error
- type AssignmentStore
- type DashboardStore
- type Filter
- type Page
- type PrivacyStatsStore
- type PrivacyStore
- type Scope
- type Store
- type TokenStats
Constants ¶
This section is empty.
Variables ¶
var ErrCollection = errors.New("shield: unsupported dashboard collection")
var ErrConflict = errors.New("shield: resource conflict")
var ErrNotFound = errors.New("shield: scoped resource not found")
var ErrReadOnly = errors.New("shield: resource is read-only in this scope")
ErrReadOnly reports a write to a resource the scope may read but not change: an app-level policy seen from a tenant scope.
var ErrScope = errors.New("shield: tenant and app scope are required")
Functions ¶
func DashboardWritable ¶
DashboardWritable reports whether scope may update or delete row, a stored dashboard row of kind: a policy only in the scope's PolicyScope.
func FilterColumn ¶
func MarshalDashboard ¶
func MarshalDashboard(v any) (json.RawMessage, error)
MarshalDashboard keeps zero and empty values that domain omitempty tags hide. Dashboard editors need explicit false, zero and cleared arrays on reload.
func NextRevision ¶
NextRevision remains distinct after MongoDB's millisecond timestamp encoding.
func ReferenceField ¶
func ReportLevels ¶
ReportLevels resolves which scope levels a compliance report list keyed by key may cover. An empty key is ErrTenantRequired. With no tenant on ctx the list is a filter-only call and gets no level restriction (nil). With a tenant on ctx only its own org level is readable: any other key is ErrTenantMismatch.
func ReportScope ¶
ReportScope is the one compliance report scope ctx may read: a tenant's own org scope, or, with no tenant on ctx, the app scope of the context app (an operator call). App-level reports are shared by every tenant of the app, so a tenant never reads them. ok is false when ctx names neither.
func ScopeLevels ¶
ScopeLevels resolves which scope levels a policy or compliance read keyed by key may cover. level narrows the answer to one level when set.
An empty key is ErrTenantRequired. With no tenant on ctx the read is a filter-only call (cortex's catalogs make these), so it returns nil and the caller adds no level restriction. With a tenant on ctx it returns the levels at which ScopeVisible accepts key, and ErrTenantMismatch when there are none.
func ScopeVisible ¶
ScopeVisible reports whether a policy or compliance scope is readable from ctx: level "org" needs key == context tenant, level "app" needs key == context app.
func ScopeWritable ¶
ScopeWritable checks that ctx may create, change or delete a policy or compliance report in the scope (key, level).
With a tenant on ctx, only that tenant's org scope is writable. App scope is shared by every tenant of the app (Loomplane gives all workspaces one app ID), so a tenant writing there would change every other tenant's safety configuration: app-level writes return ErrTenantMismatch, as does an org key that is not the context tenant. With no tenant on ctx the call is an operator call and any scope is writable. An empty key is ErrTenantRequired.
func Tenant ¶
Tenant returns the tenant a store call runs for. want is a filter's or an entity's TenantID. Empty want takes the context tenant. Both empty is ErrTenantRequired; both set and different is ErrTenantMismatch.
func UpdateRevision ¶
UpdateRevision removes the internal precondition and returns the persisted revision.
func ValidReferenceKind ¶
Types ¶
type AssignmentStore ¶
type DashboardStore ¶
type DashboardStore interface {
DashboardList(context.Context, Scope, string, Filter) (Page, error)
DashboardGet(context.Context, Scope, string, string) (json.RawMessage, error)
DashboardCreate(context.Context, Scope, string, json.RawMessage) (json.RawMessage, error)
DashboardUpdate(context.Context, Scope, string, string, json.RawMessage) (json.RawMessage, error)
DashboardDelete(context.Context, Scope, string, string) error
}
DashboardStore is an additional, strict interface. Legacy engine methods retain their original contracts; dashboard calls must never broaden an empty scope.
type Filter ¶
type Filter struct {
Limit int `json:"limit"`
Offset int `json:"offset"`
Enabled *bool `json:"enabled,omitempty"`
Name string `json:"name,omitempty"`
Field string `json:"field,omitempty"`
Value string `json:"value,omitempty"`
Search string `json:"search,omitempty"`
ReferenceKind string `json:"reference_kind,omitempty"`
ReferenceName string `json:"reference_name,omitempty"`
Direction string `json:"direction,omitempty"`
}
type PrivacyStatsStore ¶
type PrivacyStatsStore interface {
DashboardTokenStats(context.Context, Scope) (TokenStats, error)
}
type PrivacyStore ¶
type Scope ¶
type Scope struct {
TenantID string `json:"tenant_id"`
AppID string `json:"app_id"`
PolicyKey string `json:"policy_key,omitempty"`
PolicyLevel string `json:"policy_level,omitempty"`
}
func (Scope) AppScope ¶
AppScope reports whether the host's authorization adapter granted this scope the app level (PolicyLevel "app"): an operator acting for the whole app. It is never set from request params.
func (Scope) PolicyScope ¶
PolicyScope is where a dashboard policy write lands, the only scope a policy update or delete may touch, and the only scope of the compliance reports a dashboard actor reads: the app scope for an app-scope actor (see AppScope), otherwise the actor tenant's org scope. App-level policies are shared by every tenant of the app, so a tenant actor never writes them; it reads the ones assigned to it (see the store's dashboard list and get).
type Store ¶
type Store interface {
instinct.Store
awareness.Store
boundary.Store
values.Store
judgment.Store
reflex.Store
profile.Store
scan.Store
policy.Store
pii.Store
compliance.Store
// Migrate runs database migrations.
Migrate(ctx context.Context) error
// Ping verifies the store connection is alive.
Ping(ctx context.Context) error
// Close releases store resources.
Close() error
}
Store is the composite store interface that combines all subsystem stores.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package mongo provides a MongoDB implementation of the Shield composite store using grove ORM with index-based migrations.
|
Package mongo provides a MongoDB implementation of the Shield composite store using grove ORM with index-based migrations. |
|
Package postgres provides a PostgreSQL implementation of the Shield composite store using grove ORM with Go-based migrations.
|
Package postgres provides a PostgreSQL implementation of the Shield composite store using grove ORM with Go-based migrations. |
|
Package sqlite provides a SQLite implementation of the Shield composite store using grove ORM with Go-based migrations.
|
Package sqlite provides a SQLite implementation of the Shield composite store using grove ORM with Go-based migrations. |