diff --git a/internal/app/archied/state_store.go b/internal/app/archied/state_store.go index d1e76bc8c..0fc6037f7 100644 --- a/internal/app/archied/state_store.go +++ b/internal/app/archied/state_store.go @@ -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" @@ -105,6 +107,46 @@ func RunStateStore(ctx context.Context, options StateStoreOptions) error { return fmt.Errorf("upgrade default org: %w", err) } } + // The shipped role policies mean the org level always has policies + // (docs/prds/orgs-and-access.md, "Roles"): seed them for every org that + // lacks them, then re-validate every stored policy this process serves. + // 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. + if policies, ok := b.st.(access.PolicyStore); ok { + // An agent is granted access the way a user is: its assigned org, + // with the shipped developer role, so dispatch's principal evaluates. + 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) + } + } resources, ok := b.st.(controlplane.ResourceStore) if !ok { return fmt.Errorf("state store does not support control-plane resources") @@ -287,6 +329,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 } diff --git a/internal/contracts/state/v1/state.pb.go b/internal/contracts/state/v1/state.pb.go index 887637d55..189fc3c35 100644 --- a/internal/contracts/state/v1/state.pb.go +++ b/internal/contracts/state/v1/state.pb.go @@ -9822,6 +9822,925 @@ func (*RemoveInstalledPackageResponse) Descriptor() ([]byte, []int) { return file_state_v1_state_proto_rawDescGZIP(), []int{182} } +type GetPrincipalRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + IdentityId string `protobuf:"bytes,1,opt,name=identity_id,json=identityId,proto3" json:"identity_id,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *GetPrincipalRequest) Reset() { + *x = GetPrincipalRequest{} + mi := &file_state_v1_state_proto_msgTypes[183] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *GetPrincipalRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetPrincipalRequest) ProtoMessage() {} + +func (x *GetPrincipalRequest) ProtoReflect() protoreflect.Message { + mi := &file_state_v1_state_proto_msgTypes[183] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetPrincipalRequest.ProtoReflect.Descriptor instead. +func (*GetPrincipalRequest) Descriptor() ([]byte, []int) { + return file_state_v1_state_proto_rawDescGZIP(), []int{183} +} + +func (x *GetPrincipalRequest) GetIdentityId() string { + if x != nil { + return x.IdentityId + } + return "" +} + +// PrincipalMembership mirrors org.Membership: an identity's role in an org, +// or in one workspace of it. +type PrincipalMembership struct { + state protoimpl.MessageState `protogen:"open.v1"` + OrgId string `protobuf:"bytes,1,opt,name=org_id,json=orgId,proto3" json:"org_id,omitempty"` + WorkspaceId string `protobuf:"bytes,2,opt,name=workspace_id,json=workspaceId,proto3" json:"workspace_id,omitempty"` + Role string `protobuf:"bytes,3,opt,name=role,proto3" json:"role,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *PrincipalMembership) Reset() { + *x = PrincipalMembership{} + mi := &file_state_v1_state_proto_msgTypes[184] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *PrincipalMembership) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*PrincipalMembership) ProtoMessage() {} + +func (x *PrincipalMembership) ProtoReflect() protoreflect.Message { + mi := &file_state_v1_state_proto_msgTypes[184] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use PrincipalMembership.ProtoReflect.Descriptor instead. +func (*PrincipalMembership) Descriptor() ([]byte, []int) { + return file_state_v1_state_proto_rawDescGZIP(), []int{184} +} + +func (x *PrincipalMembership) GetOrgId() string { + if x != nil { + return x.OrgId + } + return "" +} + +func (x *PrincipalMembership) GetWorkspaceId() string { + if x != nil { + return x.WorkspaceId + } + return "" +} + +func (x *PrincipalMembership) GetRole() string { + if x != nil { + return x.Role + } + return "" +} + +type AccessPrincipal struct { + state protoimpl.MessageState `protogen:"open.v1"` + IdentityId string `protobuf:"bytes,1,opt,name=identity_id,json=identityId,proto3" json:"identity_id,omitempty"` + OrgId string `protobuf:"bytes,2,opt,name=org_id,json=orgId,proto3" json:"org_id,omitempty"` + Memberships []*PrincipalMembership `protobuf:"bytes,3,rep,name=memberships,proto3" json:"memberships,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *AccessPrincipal) Reset() { + *x = AccessPrincipal{} + mi := &file_state_v1_state_proto_msgTypes[185] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *AccessPrincipal) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AccessPrincipal) ProtoMessage() {} + +func (x *AccessPrincipal) ProtoReflect() protoreflect.Message { + mi := &file_state_v1_state_proto_msgTypes[185] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AccessPrincipal.ProtoReflect.Descriptor instead. +func (*AccessPrincipal) Descriptor() ([]byte, []int) { + return file_state_v1_state_proto_rawDescGZIP(), []int{185} +} + +func (x *AccessPrincipal) GetIdentityId() string { + if x != nil { + return x.IdentityId + } + return "" +} + +func (x *AccessPrincipal) GetOrgId() string { + if x != nil { + return x.OrgId + } + return "" +} + +func (x *AccessPrincipal) GetMemberships() []*PrincipalMembership { + if x != nil { + return x.Memberships + } + return nil +} + +type GetPrincipalResponse struct { + state protoimpl.MessageState `protogen:"open.v1"` + Principal *AccessPrincipal `protobuf:"bytes,1,opt,name=principal,proto3" json:"principal,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *GetPrincipalResponse) Reset() { + *x = GetPrincipalResponse{} + mi := &file_state_v1_state_proto_msgTypes[186] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *GetPrincipalResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetPrincipalResponse) ProtoMessage() {} + +func (x *GetPrincipalResponse) ProtoReflect() protoreflect.Message { + mi := &file_state_v1_state_proto_msgTypes[186] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetPrincipalResponse.ProtoReflect.Descriptor instead. +func (*GetPrincipalResponse) Descriptor() ([]byte, []int) { + return file_state_v1_state_proto_rawDescGZIP(), []int{186} +} + +func (x *GetPrincipalResponse) GetPrincipal() *AccessPrincipal { + if x != nil { + return x.Principal + } + return nil +} + +// AccessPolicy mirrors internal/domain/access.Policy: one Cedar policy +// document and the level-scope tuple that places it in the chain. +type AccessPolicy struct { + state protoimpl.MessageState `protogen:"open.v1"` + PolicyId string `protobuf:"bytes,1,opt,name=policy_id,json=policyId,proto3" json:"policy_id,omitempty"` + Level string `protobuf:"bytes,2,opt,name=level,proto3" json:"level,omitempty"` + OrgId string `protobuf:"bytes,3,opt,name=org_id,json=orgId,proto3" json:"org_id,omitempty"` + WorkspaceId string `protobuf:"bytes,4,opt,name=workspace_id,json=workspaceId,proto3" json:"workspace_id,omitempty"` + ObjectKind string `protobuf:"bytes,5,opt,name=object_kind,json=objectKind,proto3" json:"object_kind,omitempty"` + ObjectId string `protobuf:"bytes,6,opt,name=object_id,json=objectId,proto3" json:"object_id,omitempty"` + Text string `protobuf:"bytes,7,opt,name=text,proto3" json:"text,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *AccessPolicy) Reset() { + *x = AccessPolicy{} + mi := &file_state_v1_state_proto_msgTypes[187] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *AccessPolicy) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AccessPolicy) ProtoMessage() {} + +func (x *AccessPolicy) ProtoReflect() protoreflect.Message { + mi := &file_state_v1_state_proto_msgTypes[187] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AccessPolicy.ProtoReflect.Descriptor instead. +func (*AccessPolicy) Descriptor() ([]byte, []int) { + return file_state_v1_state_proto_rawDescGZIP(), []int{187} +} + +func (x *AccessPolicy) GetPolicyId() string { + if x != nil { + return x.PolicyId + } + return "" +} + +func (x *AccessPolicy) GetLevel() string { + if x != nil { + return x.Level + } + return "" +} + +func (x *AccessPolicy) GetOrgId() string { + if x != nil { + return x.OrgId + } + return "" +} + +func (x *AccessPolicy) GetWorkspaceId() string { + if x != nil { + return x.WorkspaceId + } + return "" +} + +func (x *AccessPolicy) GetObjectKind() string { + if x != nil { + return x.ObjectKind + } + return "" +} + +func (x *AccessPolicy) GetObjectId() string { + if x != nil { + return x.ObjectId + } + return "" +} + +func (x *AccessPolicy) GetText() string { + if x != nil { + return x.Text + } + return "" +} + +type ListPoliciesRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *ListPoliciesRequest) Reset() { + *x = ListPoliciesRequest{} + mi := &file_state_v1_state_proto_msgTypes[188] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *ListPoliciesRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ListPoliciesRequest) ProtoMessage() {} + +func (x *ListPoliciesRequest) ProtoReflect() protoreflect.Message { + mi := &file_state_v1_state_proto_msgTypes[188] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ListPoliciesRequest.ProtoReflect.Descriptor instead. +func (*ListPoliciesRequest) Descriptor() ([]byte, []int) { + return file_state_v1_state_proto_rawDescGZIP(), []int{188} +} + +type ListPoliciesResponse struct { + state protoimpl.MessageState `protogen:"open.v1"` + Policies []*AccessPolicy `protobuf:"bytes,1,rep,name=policies,proto3" json:"policies,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *ListPoliciesResponse) Reset() { + *x = ListPoliciesResponse{} + mi := &file_state_v1_state_proto_msgTypes[189] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *ListPoliciesResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ListPoliciesResponse) ProtoMessage() {} + +func (x *ListPoliciesResponse) ProtoReflect() protoreflect.Message { + mi := &file_state_v1_state_proto_msgTypes[189] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ListPoliciesResponse.ProtoReflect.Descriptor instead. +func (*ListPoliciesResponse) Descriptor() ([]byte, []int) { + return file_state_v1_state_proto_rawDescGZIP(), []int{189} +} + +func (x *ListPoliciesResponse) GetPolicies() []*AccessPolicy { + if x != nil { + return x.Policies + } + return nil +} + +type PutPolicyRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Policy *AccessPolicy `protobuf:"bytes,1,opt,name=policy,proto3" json:"policy,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *PutPolicyRequest) Reset() { + *x = PutPolicyRequest{} + mi := &file_state_v1_state_proto_msgTypes[190] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *PutPolicyRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*PutPolicyRequest) ProtoMessage() {} + +func (x *PutPolicyRequest) ProtoReflect() protoreflect.Message { + mi := &file_state_v1_state_proto_msgTypes[190] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use PutPolicyRequest.ProtoReflect.Descriptor instead. +func (*PutPolicyRequest) Descriptor() ([]byte, []int) { + return file_state_v1_state_proto_rawDescGZIP(), []int{190} +} + +func (x *PutPolicyRequest) GetPolicy() *AccessPolicy { + if x != nil { + return x.Policy + } + return nil +} + +type PutPolicyResponse struct { + state protoimpl.MessageState `protogen:"open.v1"` + Version int64 `protobuf:"varint,1,opt,name=version,proto3" json:"version,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *PutPolicyResponse) Reset() { + *x = PutPolicyResponse{} + mi := &file_state_v1_state_proto_msgTypes[191] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *PutPolicyResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*PutPolicyResponse) ProtoMessage() {} + +func (x *PutPolicyResponse) ProtoReflect() protoreflect.Message { + mi := &file_state_v1_state_proto_msgTypes[191] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use PutPolicyResponse.ProtoReflect.Descriptor instead. +func (*PutPolicyResponse) Descriptor() ([]byte, []int) { + return file_state_v1_state_proto_rawDescGZIP(), []int{191} +} + +func (x *PutPolicyResponse) GetVersion() int64 { + if x != nil { + return x.Version + } + return 0 +} + +type DeletePolicyRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Policy *AccessPolicy `protobuf:"bytes,1,opt,name=policy,proto3" json:"policy,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *DeletePolicyRequest) Reset() { + *x = DeletePolicyRequest{} + mi := &file_state_v1_state_proto_msgTypes[192] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *DeletePolicyRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DeletePolicyRequest) ProtoMessage() {} + +func (x *DeletePolicyRequest) ProtoReflect() protoreflect.Message { + mi := &file_state_v1_state_proto_msgTypes[192] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DeletePolicyRequest.ProtoReflect.Descriptor instead. +func (*DeletePolicyRequest) Descriptor() ([]byte, []int) { + return file_state_v1_state_proto_rawDescGZIP(), []int{192} +} + +func (x *DeletePolicyRequest) GetPolicy() *AccessPolicy { + if x != nil { + return x.Policy + } + return nil +} + +type DeletePolicyResponse struct { + state protoimpl.MessageState `protogen:"open.v1"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *DeletePolicyResponse) Reset() { + *x = DeletePolicyResponse{} + mi := &file_state_v1_state_proto_msgTypes[193] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *DeletePolicyResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DeletePolicyResponse) ProtoMessage() {} + +func (x *DeletePolicyResponse) ProtoReflect() protoreflect.Message { + mi := &file_state_v1_state_proto_msgTypes[193] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DeletePolicyResponse.ProtoReflect.Descriptor instead. +func (*DeletePolicyResponse) Descriptor() ([]byte, []int) { + return file_state_v1_state_proto_rawDescGZIP(), []int{193} +} + +type EnsureShippedOrgPoliciesRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + OrgId string `protobuf:"bytes,1,opt,name=org_id,json=orgId,proto3" json:"org_id,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *EnsureShippedOrgPoliciesRequest) Reset() { + *x = EnsureShippedOrgPoliciesRequest{} + mi := &file_state_v1_state_proto_msgTypes[194] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *EnsureShippedOrgPoliciesRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EnsureShippedOrgPoliciesRequest) ProtoMessage() {} + +func (x *EnsureShippedOrgPoliciesRequest) ProtoReflect() protoreflect.Message { + mi := &file_state_v1_state_proto_msgTypes[194] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use EnsureShippedOrgPoliciesRequest.ProtoReflect.Descriptor instead. +func (*EnsureShippedOrgPoliciesRequest) Descriptor() ([]byte, []int) { + return file_state_v1_state_proto_rawDescGZIP(), []int{194} +} + +func (x *EnsureShippedOrgPoliciesRequest) GetOrgId() string { + if x != nil { + return x.OrgId + } + return "" +} + +type EnsureShippedOrgPoliciesResponse struct { + state protoimpl.MessageState `protogen:"open.v1"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *EnsureShippedOrgPoliciesResponse) Reset() { + *x = EnsureShippedOrgPoliciesResponse{} + mi := &file_state_v1_state_proto_msgTypes[195] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *EnsureShippedOrgPoliciesResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EnsureShippedOrgPoliciesResponse) ProtoMessage() {} + +func (x *EnsureShippedOrgPoliciesResponse) ProtoReflect() protoreflect.Message { + mi := &file_state_v1_state_proto_msgTypes[195] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use EnsureShippedOrgPoliciesResponse.ProtoReflect.Descriptor instead. +func (*EnsureShippedOrgPoliciesResponse) Descriptor() ([]byte, []int) { + return file_state_v1_state_proto_rawDescGZIP(), []int{195} +} + +// AccessDenial mirrors internal/domain/access.Denial: one refusal with the +// level that decided it and the deciding policies. The store coalesces +// identical denials within a minute into one row with a count. +type AccessDenial struct { + state protoimpl.MessageState `protogen:"open.v1"` + OrgId string `protobuf:"bytes,1,opt,name=org_id,json=orgId,proto3" json:"org_id,omitempty"` + Principal string `protobuf:"bytes,2,opt,name=principal,proto3" json:"principal,omitempty"` + Action string `protobuf:"bytes,3,opt,name=action,proto3" json:"action,omitempty"` + ResourceKind string `protobuf:"bytes,4,opt,name=resource_kind,json=resourceKind,proto3" json:"resource_kind,omitempty"` + ResourceId string `protobuf:"bytes,5,opt,name=resource_id,json=resourceId,proto3" json:"resource_id,omitempty"` + Level string `protobuf:"bytes,6,opt,name=level,proto3" json:"level,omitempty"` + Policies []string `protobuf:"bytes,7,rep,name=policies,proto3" json:"policies,omitempty"` + Count int64 `protobuf:"varint,8,opt,name=count,proto3" json:"count,omitempty"` + At *timestamppb.Timestamp `protobuf:"bytes,9,opt,name=at,proto3" json:"at,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *AccessDenial) Reset() { + *x = AccessDenial{} + mi := &file_state_v1_state_proto_msgTypes[196] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *AccessDenial) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*AccessDenial) ProtoMessage() {} + +func (x *AccessDenial) ProtoReflect() protoreflect.Message { + mi := &file_state_v1_state_proto_msgTypes[196] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use AccessDenial.ProtoReflect.Descriptor instead. +func (*AccessDenial) Descriptor() ([]byte, []int) { + return file_state_v1_state_proto_rawDescGZIP(), []int{196} +} + +func (x *AccessDenial) GetOrgId() string { + if x != nil { + return x.OrgId + } + return "" +} + +func (x *AccessDenial) GetPrincipal() string { + if x != nil { + return x.Principal + } + return "" +} + +func (x *AccessDenial) GetAction() string { + if x != nil { + return x.Action + } + return "" +} + +func (x *AccessDenial) GetResourceKind() string { + if x != nil { + return x.ResourceKind + } + return "" +} + +func (x *AccessDenial) GetResourceId() string { + if x != nil { + return x.ResourceId + } + return "" +} + +func (x *AccessDenial) GetLevel() string { + if x != nil { + return x.Level + } + return "" +} + +func (x *AccessDenial) GetPolicies() []string { + if x != nil { + return x.Policies + } + return nil +} + +func (x *AccessDenial) GetCount() int64 { + if x != nil { + return x.Count + } + return 0 +} + +func (x *AccessDenial) GetAt() *timestamppb.Timestamp { + if x != nil { + return x.At + } + return nil +} + +type RecordDenialRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Denial *AccessDenial `protobuf:"bytes,1,opt,name=denial,proto3" json:"denial,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *RecordDenialRequest) Reset() { + *x = RecordDenialRequest{} + mi := &file_state_v1_state_proto_msgTypes[197] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *RecordDenialRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*RecordDenialRequest) ProtoMessage() {} + +func (x *RecordDenialRequest) ProtoReflect() protoreflect.Message { + mi := &file_state_v1_state_proto_msgTypes[197] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use RecordDenialRequest.ProtoReflect.Descriptor instead. +func (*RecordDenialRequest) Descriptor() ([]byte, []int) { + return file_state_v1_state_proto_rawDescGZIP(), []int{197} +} + +func (x *RecordDenialRequest) GetDenial() *AccessDenial { + if x != nil { + return x.Denial + } + return nil +} + +type RecordDenialResponse struct { + state protoimpl.MessageState `protogen:"open.v1"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *RecordDenialResponse) Reset() { + *x = RecordDenialResponse{} + mi := &file_state_v1_state_proto_msgTypes[198] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *RecordDenialResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*RecordDenialResponse) ProtoMessage() {} + +func (x *RecordDenialResponse) ProtoReflect() protoreflect.Message { + mi := &file_state_v1_state_proto_msgTypes[198] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use RecordDenialResponse.ProtoReflect.Descriptor instead. +func (*RecordDenialResponse) Descriptor() ([]byte, []int) { + return file_state_v1_state_proto_rawDescGZIP(), []int{198} +} + +type ListDenialsRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + OrgId string `protobuf:"bytes,1,opt,name=org_id,json=orgId,proto3" json:"org_id,omitempty"` + Limit int32 `protobuf:"varint,2,opt,name=limit,proto3" json:"limit,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *ListDenialsRequest) Reset() { + *x = ListDenialsRequest{} + mi := &file_state_v1_state_proto_msgTypes[199] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *ListDenialsRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ListDenialsRequest) ProtoMessage() {} + +func (x *ListDenialsRequest) ProtoReflect() protoreflect.Message { + mi := &file_state_v1_state_proto_msgTypes[199] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ListDenialsRequest.ProtoReflect.Descriptor instead. +func (*ListDenialsRequest) Descriptor() ([]byte, []int) { + return file_state_v1_state_proto_rawDescGZIP(), []int{199} +} + +func (x *ListDenialsRequest) GetOrgId() string { + if x != nil { + return x.OrgId + } + return "" +} + +func (x *ListDenialsRequest) GetLimit() int32 { + if x != nil { + return x.Limit + } + return 0 +} + +type ListDenialsResponse struct { + state protoimpl.MessageState `protogen:"open.v1"` + Denials []*AccessDenial `protobuf:"bytes,1,rep,name=denials,proto3" json:"denials,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *ListDenialsResponse) Reset() { + *x = ListDenialsResponse{} + mi := &file_state_v1_state_proto_msgTypes[200] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *ListDenialsResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ListDenialsResponse) ProtoMessage() {} + +func (x *ListDenialsResponse) ProtoReflect() protoreflect.Message { + mi := &file_state_v1_state_proto_msgTypes[200] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ListDenialsResponse.ProtoReflect.Descriptor instead. +func (*ListDenialsResponse) Descriptor() ([]byte, []int) { + return file_state_v1_state_proto_rawDescGZIP(), []int{200} +} + +func (x *ListDenialsResponse) GetDenials() []*AccessDenial { + if x != nil { + return x.Denials + } + return nil +} + var File_state_v1_state_proto protoreflect.FileDescriptor const file_state_v1_state_proto_rawDesc = "" + @@ -10464,7 +11383,62 @@ const file_state_v1_state_proto_rawDesc = "" + "\x1dRemoveInstalledPackageRequest\x12\x15\n" + "\x06org_id\x18\x01 \x01(\tR\x05orgId\x12\x12\n" + "\x04name\x18\x02 \x01(\tR\x04name\" \n" + - "\x1eRemoveInstalledPackageResponse2\x8d6\n" + + "\x1eRemoveInstalledPackageResponse\"6\n" + + "\x13GetPrincipalRequest\x12\x1f\n" + + "\videntity_id\x18\x01 \x01(\tR\n" + + "identityId\"c\n" + + "\x13PrincipalMembership\x12\x15\n" + + "\x06org_id\x18\x01 \x01(\tR\x05orgId\x12!\n" + + "\fworkspace_id\x18\x02 \x01(\tR\vworkspaceId\x12\x12\n" + + "\x04role\x18\x03 \x01(\tR\x04role\"\x8a\x01\n" + + "\x0fAccessPrincipal\x12\x1f\n" + + "\videntity_id\x18\x01 \x01(\tR\n" + + "identityId\x12\x15\n" + + "\x06org_id\x18\x02 \x01(\tR\x05orgId\x12?\n" + + "\vmemberships\x18\x03 \x03(\v2\x1d.state.v1.PrincipalMembershipR\vmemberships\"O\n" + + "\x14GetPrincipalResponse\x127\n" + + "\tprincipal\x18\x01 \x01(\v2\x19.state.v1.AccessPrincipalR\tprincipal\"\xcd\x01\n" + + "\fAccessPolicy\x12\x1b\n" + + "\tpolicy_id\x18\x01 \x01(\tR\bpolicyId\x12\x14\n" + + "\x05level\x18\x02 \x01(\tR\x05level\x12\x15\n" + + "\x06org_id\x18\x03 \x01(\tR\x05orgId\x12!\n" + + "\fworkspace_id\x18\x04 \x01(\tR\vworkspaceId\x12\x1f\n" + + "\vobject_kind\x18\x05 \x01(\tR\n" + + "objectKind\x12\x1b\n" + + "\tobject_id\x18\x06 \x01(\tR\bobjectId\x12\x12\n" + + "\x04text\x18\a \x01(\tR\x04text\"\x15\n" + + "\x13ListPoliciesRequest\"J\n" + + "\x14ListPoliciesResponse\x122\n" + + "\bpolicies\x18\x01 \x03(\v2\x16.state.v1.AccessPolicyR\bpolicies\"B\n" + + "\x10PutPolicyRequest\x12.\n" + + "\x06policy\x18\x01 \x01(\v2\x16.state.v1.AccessPolicyR\x06policy\"-\n" + + "\x11PutPolicyResponse\x12\x18\n" + + "\aversion\x18\x01 \x01(\x03R\aversion\"E\n" + + "\x13DeletePolicyRequest\x12.\n" + + "\x06policy\x18\x01 \x01(\v2\x16.state.v1.AccessPolicyR\x06policy\"\x16\n" + + "\x14DeletePolicyResponse\"8\n" + + "\x1fEnsureShippedOrgPoliciesRequest\x12\x15\n" + + "\x06org_id\x18\x01 \x01(\tR\x05orgId\"\"\n" + + " EnsureShippedOrgPoliciesResponse\"\x95\x02\n" + + "\fAccessDenial\x12\x15\n" + + "\x06org_id\x18\x01 \x01(\tR\x05orgId\x12\x1c\n" + + "\tprincipal\x18\x02 \x01(\tR\tprincipal\x12\x16\n" + + "\x06action\x18\x03 \x01(\tR\x06action\x12#\n" + + "\rresource_kind\x18\x04 \x01(\tR\fresourceKind\x12\x1f\n" + + "\vresource_id\x18\x05 \x01(\tR\n" + + "resourceId\x12\x14\n" + + "\x05level\x18\x06 \x01(\tR\x05level\x12\x1a\n" + + "\bpolicies\x18\a \x03(\tR\bpolicies\x12\x14\n" + + "\x05count\x18\b \x01(\x03R\x05count\x12*\n" + + "\x02at\x18\t \x01(\v2\x1a.google.protobuf.TimestampR\x02at\"E\n" + + "\x13RecordDenialRequest\x12.\n" + + "\x06denial\x18\x01 \x01(\v2\x16.state.v1.AccessDenialR\x06denial\"\x16\n" + + "\x14RecordDenialResponse\"A\n" + + "\x12ListDenialsRequest\x12\x15\n" + + "\x06org_id\x18\x01 \x01(\tR\x05orgId\x12\x14\n" + + "\x05limit\x18\x02 \x01(\x05R\x05limit\"G\n" + + "\x13ListDenialsResponse\x120\n" + + "\adenials\x18\x01 \x03(\v2\x16.state.v1.AccessDenialR\adenials2\xce:\n" + "\x11StateStoreService\x12S\n" + "\x0eInstallPackage\x12\x1f.state.v1.InstallPackageRequest\x1a .state.v1.InstallPackageResponse\x12b\n" + "\x13GetInstalledPackage\x12$.state.v1.GetInstalledPackageRequest\x1a%.state.v1.GetInstalledPackageResponse\x12h\n" + @@ -10551,7 +11525,14 @@ const file_state_v1_state_proto_rawDesc = "" + "\x1aStreamUndispatchedCaptures\x12+.state.v1.StreamUndispatchedCapturesRequest\x1a,.state.v1.StreamUndispatchedCapturesResponse0\x01\x12_\n" + "\x12EnqueueBindingTask\x12#.state.v1.EnqueueBindingTaskRequest\x1a$.state.v1.EnqueueBindingTaskResponse\x12V\n" + "\x0fEnqueueCallTask\x12 .state.v1.EnqueueCallTaskRequest\x1a!.state.v1.EnqueueCallTaskResponse\x12_\n" + - "\x12WorkflowCallStatus\x12#.state.v1.WorkflowCallStatusRequest\x1a$.state.v1.WorkflowCallStatusResponseB\xa4\x01\n" + + "\x12WorkflowCallStatus\x12#.state.v1.WorkflowCallStatusRequest\x1a$.state.v1.WorkflowCallStatusResponse\x12M\n" + + "\fGetPrincipal\x12\x1d.state.v1.GetPrincipalRequest\x1a\x1e.state.v1.GetPrincipalResponse\x12M\n" + + "\fListPolicies\x12\x1d.state.v1.ListPoliciesRequest\x1a\x1e.state.v1.ListPoliciesResponse\x12D\n" + + "\tPutPolicy\x12\x1a.state.v1.PutPolicyRequest\x1a\x1b.state.v1.PutPolicyResponse\x12M\n" + + "\fDeletePolicy\x12\x1d.state.v1.DeletePolicyRequest\x1a\x1e.state.v1.DeletePolicyResponse\x12q\n" + + "\x18EnsureShippedOrgPolicies\x12).state.v1.EnsureShippedOrgPoliciesRequest\x1a*.state.v1.EnsureShippedOrgPoliciesResponse\x12M\n" + + "\fRecordDenial\x12\x1d.state.v1.RecordDenialRequest\x1a\x1e.state.v1.RecordDenialResponse\x12J\n" + + "\vListDenials\x12\x1c.state.v1.ListDenialsRequest\x1a\x1d.state.v1.ListDenialsResponseB\xa4\x01\n" + "\fcom.state.v1B\n" + "StateProtoP\x01ZGgithub.com/samcharles93/archie-core/internal/contracts/state/v1;statev1\xa2\x02\x03SXX\xaa\x02\bState.V1\xca\x02\bState\\V1\xe2\x02\x14State\\V1\\GPBMetadata\xea\x02\tState::V1b\x06proto3" @@ -10567,7 +11548,7 @@ func file_state_v1_state_proto_rawDescGZIP() []byte { return file_state_v1_state_proto_rawDescData } -var file_state_v1_state_proto_msgTypes = make([]protoimpl.MessageInfo, 185) +var file_state_v1_state_proto_msgTypes = make([]protoimpl.MessageInfo, 203) var file_state_v1_state_proto_goTypes = []any{ (*RegisterTaskGrantRequest)(nil), // 0: state.v1.RegisterTaskGrantRequest (*RegisterTaskGrantResponse)(nil), // 1: state.v1.RegisterTaskGrantResponse @@ -10752,13 +11733,31 @@ var file_state_v1_state_proto_goTypes = []any{ (*ListInstalledPackagesResponse)(nil), // 180: state.v1.ListInstalledPackagesResponse (*RemoveInstalledPackageRequest)(nil), // 181: state.v1.RemoveInstalledPackageRequest (*RemoveInstalledPackageResponse)(nil), // 182: state.v1.RemoveInstalledPackageResponse - nil, // 183: state.v1.EventType.SchemaEntry - nil, // 184: state.v1.StatusCountsResponse.CountsEntry - (*timestamppb.Timestamp)(nil), // 185: google.protobuf.Timestamp + (*GetPrincipalRequest)(nil), // 183: state.v1.GetPrincipalRequest + (*PrincipalMembership)(nil), // 184: state.v1.PrincipalMembership + (*AccessPrincipal)(nil), // 185: state.v1.AccessPrincipal + (*GetPrincipalResponse)(nil), // 186: state.v1.GetPrincipalResponse + (*AccessPolicy)(nil), // 187: state.v1.AccessPolicy + (*ListPoliciesRequest)(nil), // 188: state.v1.ListPoliciesRequest + (*ListPoliciesResponse)(nil), // 189: state.v1.ListPoliciesResponse + (*PutPolicyRequest)(nil), // 190: state.v1.PutPolicyRequest + (*PutPolicyResponse)(nil), // 191: state.v1.PutPolicyResponse + (*DeletePolicyRequest)(nil), // 192: state.v1.DeletePolicyRequest + (*DeletePolicyResponse)(nil), // 193: state.v1.DeletePolicyResponse + (*EnsureShippedOrgPoliciesRequest)(nil), // 194: state.v1.EnsureShippedOrgPoliciesRequest + (*EnsureShippedOrgPoliciesResponse)(nil), // 195: state.v1.EnsureShippedOrgPoliciesResponse + (*AccessDenial)(nil), // 196: state.v1.AccessDenial + (*RecordDenialRequest)(nil), // 197: state.v1.RecordDenialRequest + (*RecordDenialResponse)(nil), // 198: state.v1.RecordDenialResponse + (*ListDenialsRequest)(nil), // 199: state.v1.ListDenialsRequest + (*ListDenialsResponse)(nil), // 200: state.v1.ListDenialsResponse + nil, // 201: state.v1.EventType.SchemaEntry + nil, // 202: state.v1.StatusCountsResponse.CountsEntry + (*timestamppb.Timestamp)(nil), // 203: google.protobuf.Timestamp } var file_state_v1_state_proto_depIdxs = []int32{ - 185, // 0: state.v1.Identity.created_at:type_name -> google.protobuf.Timestamp - 185, // 1: state.v1.Identity.updated_at:type_name -> google.protobuf.Timestamp + 203, // 0: state.v1.Identity.created_at:type_name -> google.protobuf.Timestamp + 203, // 1: state.v1.Identity.updated_at:type_name -> google.protobuf.Timestamp 4, // 2: state.v1.ListIdentitiesResponse.identities:type_name -> state.v1.Identity 4, // 3: state.v1.GetIdentityResponse.identity:type_name -> state.v1.Identity 5, // 4: state.v1.CreateIdentityRequest.audit:type_name -> state.v1.IdentityAudit @@ -10774,24 +11773,24 @@ var file_state_v1_state_proto_depIdxs = []int32{ 4, // 14: state.v1.ResolveIdentitySubjectResponse.identity:type_name -> state.v1.Identity 5, // 15: state.v1.BindIdentitySubjectRequest.audit:type_name -> state.v1.IdentityAudit 4, // 16: state.v1.BindIdentitySubjectResponse.identity:type_name -> state.v1.Identity - 185, // 17: state.v1.Task.created_at:type_name -> google.protobuf.Timestamp - 185, // 18: state.v1.Task.updated_at:type_name -> google.protobuf.Timestamp - 185, // 19: state.v1.Event.at:type_name -> google.protobuf.Timestamp - 185, // 20: state.v1.CapturedEvent.received_at:type_name -> google.protobuf.Timestamp + 203, // 17: state.v1.Task.created_at:type_name -> google.protobuf.Timestamp + 203, // 18: state.v1.Task.updated_at:type_name -> google.protobuf.Timestamp + 203, // 19: state.v1.Event.at:type_name -> google.protobuf.Timestamp + 203, // 20: state.v1.CapturedEvent.received_at:type_name -> google.protobuf.Timestamp 27, // 21: state.v1.EventType.header_conditions:type_name -> state.v1.EventTypeHeaderCondition 28, // 22: state.v1.EventType.payload_conditions:type_name -> state.v1.EventTypePayloadCondition - 183, // 23: state.v1.EventType.schema:type_name -> state.v1.EventType.SchemaEntry - 185, // 24: state.v1.EventType.created_at:type_name -> google.protobuf.Timestamp - 185, // 25: state.v1.EventType.updated_at:type_name -> google.protobuf.Timestamp + 201, // 23: state.v1.EventType.schema:type_name -> state.v1.EventType.SchemaEntry + 203, // 24: state.v1.EventType.created_at:type_name -> google.protobuf.Timestamp + 203, // 25: state.v1.EventType.updated_at:type_name -> google.protobuf.Timestamp 30, // 26: state.v1.Mapping.fields:type_name -> state.v1.MappingField - 185, // 27: state.v1.Mapping.created_at:type_name -> google.protobuf.Timestamp - 185, // 28: state.v1.Mapping.updated_at:type_name -> google.protobuf.Timestamp - 185, // 29: state.v1.Mapping.last_matched_at:type_name -> google.protobuf.Timestamp + 203, // 27: state.v1.Mapping.created_at:type_name -> google.protobuf.Timestamp + 203, // 28: state.v1.Mapping.updated_at:type_name -> google.protobuf.Timestamp + 203, // 29: state.v1.Mapping.last_matched_at:type_name -> google.protobuf.Timestamp 32, // 30: state.v1.Binding.matcher:type_name -> state.v1.BindingMatcher - 185, // 31: state.v1.Binding.created_at:type_name -> google.protobuf.Timestamp - 185, // 32: state.v1.Binding.updated_at:type_name -> google.protobuf.Timestamp - 185, // 33: state.v1.Source.created_at:type_name -> google.protobuf.Timestamp - 185, // 34: state.v1.Source.updated_at:type_name -> google.protobuf.Timestamp + 203, // 31: state.v1.Binding.created_at:type_name -> google.protobuf.Timestamp + 203, // 32: state.v1.Binding.updated_at:type_name -> google.protobuf.Timestamp + 203, // 33: state.v1.Source.created_at:type_name -> google.protobuf.Timestamp + 203, // 34: state.v1.Source.updated_at:type_name -> google.protobuf.Timestamp 24, // 35: state.v1.EnqueueChatTaskResponse.task:type_name -> state.v1.Task 24, // 36: state.v1.ClaimNextResponse.task:type_name -> state.v1.Task 24, // 37: state.v1.ClaimByIssueResponse.task:type_name -> state.v1.Task @@ -10802,25 +11801,25 @@ var file_state_v1_state_proto_depIdxs = []int32{ 24, // 42: state.v1.TaskByIDResponse.task:type_name -> state.v1.Task 24, // 43: state.v1.OpenPRsResponse.tasks:type_name -> state.v1.Task 24, // 44: state.v1.TasksResponse.tasks:type_name -> state.v1.Task - 184, // 45: state.v1.StatusCountsResponse.counts:type_name -> state.v1.StatusCountsResponse.CountsEntry + 202, // 45: state.v1.StatusCountsResponse.counts:type_name -> state.v1.StatusCountsResponse.CountsEntry 25, // 46: state.v1.InsertEventRequest.event:type_name -> state.v1.Event 25, // 47: state.v1.EventsSinceResponse.events:type_name -> state.v1.Event 25, // 48: state.v1.TaskEventsResponse.events:type_name -> state.v1.Event 35, // 49: state.v1.WorkflowStatsResponse.stats:type_name -> state.v1.WorkflowStat 36, // 50: state.v1.StageStatsResponse.stats:type_name -> state.v1.StageStat 37, // 51: state.v1.TokensByDayResponse.tokens:type_name -> state.v1.DayTokens - 185, // 52: state.v1.ConfigSnapshot.published_at:type_name -> google.protobuf.Timestamp + 203, // 52: state.v1.ConfigSnapshot.published_at:type_name -> google.protobuf.Timestamp 92, // 53: state.v1.PutConfigSnapshotRequest.snapshot:type_name -> state.v1.ConfigSnapshot 92, // 54: state.v1.GetConfigSnapshotResponse.snapshot:type_name -> state.v1.ConfigSnapshot - 185, // 55: state.v1.ChannelStatus.observed_at:type_name -> google.protobuf.Timestamp + 203, // 55: state.v1.ChannelStatus.observed_at:type_name -> google.protobuf.Timestamp 97, // 56: state.v1.PutChannelStatusRequest.channels:type_name -> state.v1.ChannelStatus 97, // 57: state.v1.ListChannelStatusResponse.channels:type_name -> state.v1.ChannelStatus - 185, // 58: state.v1.ApplyStatus.reported_at:type_name -> google.protobuf.Timestamp + 203, // 58: state.v1.ApplyStatus.reported_at:type_name -> google.protobuf.Timestamp 102, // 59: state.v1.PutApplyStatusRequest.status:type_name -> state.v1.ApplyStatus 102, // 60: state.v1.ListApplyStatusResponse.statuses:type_name -> state.v1.ApplyStatus - 185, // 61: state.v1.TaskLogEntry.time:type_name -> google.protobuf.Timestamp - 185, // 62: state.v1.ReadTaskLogRequest.since:type_name -> google.protobuf.Timestamp - 185, // 63: state.v1.ReadTaskLogRequest.until:type_name -> google.protobuf.Timestamp + 203, // 61: state.v1.TaskLogEntry.time:type_name -> google.protobuf.Timestamp + 203, // 62: state.v1.ReadTaskLogRequest.since:type_name -> google.protobuf.Timestamp + 203, // 63: state.v1.ReadTaskLogRequest.until:type_name -> google.protobuf.Timestamp 107, // 64: state.v1.ReadTaskLogResponse.entries:type_name -> state.v1.TaskLogEntry 26, // 65: state.v1.InsertCaptureRequest.capture:type_name -> state.v1.CapturedEvent 26, // 66: state.v1.StreamCapturesResponse.capture:type_name -> state.v1.CapturedEvent @@ -10845,173 +11844,195 @@ var file_state_v1_state_proto_depIdxs = []int32{ 174, // 85: state.v1.InstallPackageResponse.package:type_name -> state.v1.InstalledPackage 174, // 86: state.v1.GetInstalledPackageResponse.package:type_name -> state.v1.InstalledPackage 174, // 87: state.v1.ListInstalledPackagesResponse.packages:type_name -> state.v1.InstalledPackage - 175, // 88: state.v1.StateStoreService.InstallPackage:input_type -> state.v1.InstallPackageRequest - 177, // 89: state.v1.StateStoreService.GetInstalledPackage:input_type -> state.v1.GetInstalledPackageRequest - 179, // 90: state.v1.StateStoreService.ListInstalledPackages:input_type -> state.v1.ListInstalledPackagesRequest - 181, // 91: state.v1.StateStoreService.RemoveInstalledPackage:input_type -> state.v1.RemoveInstalledPackageRequest - 0, // 92: state.v1.StateStoreService.RegisterTaskGrant:input_type -> state.v1.RegisterTaskGrantRequest - 2, // 93: state.v1.StateStoreService.RevokeTaskGrant:input_type -> state.v1.RevokeTaskGrantRequest - 6, // 94: state.v1.StateStoreService.ListIdentities:input_type -> state.v1.ListIdentitiesRequest - 8, // 95: state.v1.StateStoreService.GetIdentity:input_type -> state.v1.GetIdentityRequest - 10, // 96: state.v1.StateStoreService.CreateIdentity:input_type -> state.v1.CreateIdentityRequest - 11, // 97: state.v1.StateStoreService.RenameIdentity:input_type -> state.v1.RenameIdentityRequest - 12, // 98: state.v1.StateStoreService.SuspendIdentity:input_type -> state.v1.SuspendIdentityRequest - 13, // 99: state.v1.StateStoreService.ReactivateIdentity:input_type -> state.v1.ReactivateIdentityRequest - 14, // 100: state.v1.StateStoreService.RetireIdentity:input_type -> state.v1.RetireIdentityRequest - 20, // 101: state.v1.StateStoreService.ResolveIdentitySubject:input_type -> state.v1.ResolveIdentitySubjectRequest - 22, // 102: state.v1.StateStoreService.BindIdentitySubject:input_type -> state.v1.BindIdentitySubjectRequest - 38, // 103: state.v1.StateStoreService.EnqueueIssue:input_type -> state.v1.EnqueueIssueRequest - 40, // 104: state.v1.StateStoreService.EnqueueChatTask:input_type -> state.v1.EnqueueChatTaskRequest - 42, // 105: state.v1.StateStoreService.ClaimNext:input_type -> state.v1.ClaimNextRequest - 44, // 106: state.v1.StateStoreService.ClaimByIssue:input_type -> state.v1.ClaimByIssueRequest - 46, // 107: state.v1.StateStoreService.Transition:input_type -> state.v1.TransitionRequest - 48, // 108: state.v1.StateStoreService.Update:input_type -> state.v1.UpdateRequest - 50, // 109: state.v1.StateStoreService.Requeue:input_type -> state.v1.RequeueRequest - 52, // 110: state.v1.StateStoreService.ParkTask:input_type -> state.v1.ParkTaskRequest - 54, // 111: state.v1.StateStoreService.RecoverStale:input_type -> state.v1.RecoverStaleRequest - 56, // 112: state.v1.StateStoreService.ArchiveTask:input_type -> state.v1.ArchiveTaskRequest - 58, // 113: state.v1.StateStoreService.RetryTask:input_type -> state.v1.RetryTaskRequest - 60, // 114: state.v1.StateStoreService.BeginRemediation:input_type -> state.v1.BeginRemediationRequest - 62, // 115: state.v1.StateStoreService.UpdateReviewPayload:input_type -> state.v1.UpdateReviewPayloadRequest - 64, // 116: state.v1.StateStoreService.SetReviewCursors:input_type -> state.v1.SetReviewCursorsRequest - 66, // 117: state.v1.StateStoreService.TaskByIssue:input_type -> state.v1.TaskByIssueRequest - 68, // 118: state.v1.StateStoreService.OpenTaskByPR:input_type -> state.v1.OpenTaskByPRRequest - 70, // 119: state.v1.StateStoreService.TaskByID:input_type -> state.v1.TaskByIDRequest - 72, // 120: state.v1.StateStoreService.OpenPRs:input_type -> state.v1.OpenPRsRequest - 74, // 121: state.v1.StateStoreService.ClearTerminalTasks:input_type -> state.v1.ClearTerminalTasksRequest - 76, // 122: state.v1.StateStoreService.Tasks:input_type -> state.v1.TasksRequest - 78, // 123: state.v1.StateStoreService.StatusCounts:input_type -> state.v1.StatusCountsRequest - 80, // 124: state.v1.StateStoreService.InsertEvent:input_type -> state.v1.InsertEventRequest - 82, // 125: state.v1.StateStoreService.EventsSince:input_type -> state.v1.EventsSinceRequest - 84, // 126: state.v1.StateStoreService.TaskEvents:input_type -> state.v1.TaskEventsRequest - 86, // 127: state.v1.StateStoreService.WorkflowStats:input_type -> state.v1.WorkflowStatsRequest - 88, // 128: state.v1.StateStoreService.StageStats:input_type -> state.v1.StageStatsRequest - 90, // 129: state.v1.StateStoreService.TokensByDay:input_type -> state.v1.TokensByDayRequest - 93, // 130: state.v1.StateStoreService.PutConfigSnapshot:input_type -> state.v1.PutConfigSnapshotRequest - 95, // 131: state.v1.StateStoreService.GetConfigSnapshot:input_type -> state.v1.GetConfigSnapshotRequest - 98, // 132: state.v1.StateStoreService.PutChannelStatus:input_type -> state.v1.PutChannelStatusRequest - 100, // 133: state.v1.StateStoreService.ListChannelStatus:input_type -> state.v1.ListChannelStatusRequest - 103, // 134: state.v1.StateStoreService.PutApplyStatus:input_type -> state.v1.PutApplyStatusRequest - 105, // 135: state.v1.StateStoreService.ListApplyStatus:input_type -> state.v1.ListApplyStatusRequest - 108, // 136: state.v1.StateStoreService.ReadTaskLog:input_type -> state.v1.ReadTaskLogRequest - 110, // 137: state.v1.StateStoreService.StreamTaskLogContent:input_type -> state.v1.StreamTaskLogContentRequest - 112, // 138: state.v1.StateStoreService.InsertCapture:input_type -> state.v1.InsertCaptureRequest - 114, // 139: state.v1.StateStoreService.StreamCaptures:input_type -> state.v1.StreamCapturesRequest - 116, // 140: state.v1.StateStoreService.InsertMapping:input_type -> state.v1.InsertMappingRequest - 118, // 141: state.v1.StateStoreService.GetMapping:input_type -> state.v1.GetMappingRequest - 120, // 142: state.v1.StateStoreService.ListMappings:input_type -> state.v1.ListMappingsRequest - 122, // 143: state.v1.StateStoreService.UpdateMapping:input_type -> state.v1.UpdateMappingRequest - 124, // 144: state.v1.StateStoreService.DeleteMapping:input_type -> state.v1.DeleteMappingRequest - 126, // 145: state.v1.StateStoreService.RecordMappingMatch:input_type -> state.v1.RecordMappingMatchRequest - 128, // 146: state.v1.StateStoreService.InsertEventType:input_type -> state.v1.InsertEventTypeRequest - 130, // 147: state.v1.StateStoreService.UpdateEventType:input_type -> state.v1.UpdateEventTypeRequest - 132, // 148: state.v1.StateStoreService.DeleteEventType:input_type -> state.v1.DeleteEventTypeRequest - 134, // 149: state.v1.StateStoreService.ListEventTypes:input_type -> state.v1.ListEventTypesRequest - 136, // 150: state.v1.StateStoreService.InsertBinding:input_type -> state.v1.InsertBindingRequest - 138, // 151: state.v1.StateStoreService.GetBinding:input_type -> state.v1.GetBindingRequest - 140, // 152: state.v1.StateStoreService.ListBindings:input_type -> state.v1.ListBindingsRequest - 142, // 153: state.v1.StateStoreService.UpdateBinding:input_type -> state.v1.UpdateBindingRequest - 144, // 154: state.v1.StateStoreService.DeleteBinding:input_type -> state.v1.DeleteBindingRequest - 146, // 155: state.v1.StateStoreService.ApproveBinding:input_type -> state.v1.ApproveBindingRequest - 148, // 156: state.v1.StateStoreService.InsertSource:input_type -> state.v1.InsertSourceRequest - 150, // 157: state.v1.StateStoreService.GetSource:input_type -> state.v1.GetSourceRequest - 152, // 158: state.v1.StateStoreService.ListSources:input_type -> state.v1.ListSourcesRequest - 154, // 159: state.v1.StateStoreService.SetSourceSigning:input_type -> state.v1.SetSourceSigningRequest - 156, // 160: state.v1.StateStoreService.SetSourceSecret:input_type -> state.v1.SetSourceSecretRequest - 158, // 161: state.v1.StateStoreService.ArmedBindingsForSource:input_type -> state.v1.ArmedBindingsForSourceRequest - 160, // 162: state.v1.StateStoreService.RecordDispatch:input_type -> state.v1.RecordDispatchRequest - 162, // 163: state.v1.StateStoreService.RecordPlaybookDispatch:input_type -> state.v1.RecordPlaybookDispatchRequest - 164, // 164: state.v1.StateStoreService.DeletePlaybookDispatches:input_type -> state.v1.DeletePlaybookDispatchesRequest - 166, // 165: state.v1.StateStoreService.StreamUndispatchedCaptures:input_type -> state.v1.StreamUndispatchedCapturesRequest - 168, // 166: state.v1.StateStoreService.EnqueueBindingTask:input_type -> state.v1.EnqueueBindingTaskRequest - 170, // 167: state.v1.StateStoreService.EnqueueCallTask:input_type -> state.v1.EnqueueCallTaskRequest - 172, // 168: state.v1.StateStoreService.WorkflowCallStatus:input_type -> state.v1.WorkflowCallStatusRequest - 176, // 169: state.v1.StateStoreService.InstallPackage:output_type -> state.v1.InstallPackageResponse - 178, // 170: state.v1.StateStoreService.GetInstalledPackage:output_type -> state.v1.GetInstalledPackageResponse - 180, // 171: state.v1.StateStoreService.ListInstalledPackages:output_type -> state.v1.ListInstalledPackagesResponse - 182, // 172: state.v1.StateStoreService.RemoveInstalledPackage:output_type -> state.v1.RemoveInstalledPackageResponse - 1, // 173: state.v1.StateStoreService.RegisterTaskGrant:output_type -> state.v1.RegisterTaskGrantResponse - 3, // 174: state.v1.StateStoreService.RevokeTaskGrant:output_type -> state.v1.RevokeTaskGrantResponse - 7, // 175: state.v1.StateStoreService.ListIdentities:output_type -> state.v1.ListIdentitiesResponse - 9, // 176: state.v1.StateStoreService.GetIdentity:output_type -> state.v1.GetIdentityResponse - 15, // 177: state.v1.StateStoreService.CreateIdentity:output_type -> state.v1.CreateIdentityResponse - 16, // 178: state.v1.StateStoreService.RenameIdentity:output_type -> state.v1.RenameIdentityResponse - 17, // 179: state.v1.StateStoreService.SuspendIdentity:output_type -> state.v1.SuspendIdentityResponse - 18, // 180: state.v1.StateStoreService.ReactivateIdentity:output_type -> state.v1.ReactivateIdentityResponse - 19, // 181: state.v1.StateStoreService.RetireIdentity:output_type -> state.v1.RetireIdentityResponse - 21, // 182: state.v1.StateStoreService.ResolveIdentitySubject:output_type -> state.v1.ResolveIdentitySubjectResponse - 23, // 183: state.v1.StateStoreService.BindIdentitySubject:output_type -> state.v1.BindIdentitySubjectResponse - 39, // 184: state.v1.StateStoreService.EnqueueIssue:output_type -> state.v1.EnqueueIssueResponse - 41, // 185: state.v1.StateStoreService.EnqueueChatTask:output_type -> state.v1.EnqueueChatTaskResponse - 43, // 186: state.v1.StateStoreService.ClaimNext:output_type -> state.v1.ClaimNextResponse - 45, // 187: state.v1.StateStoreService.ClaimByIssue:output_type -> state.v1.ClaimByIssueResponse - 47, // 188: state.v1.StateStoreService.Transition:output_type -> state.v1.TransitionResponse - 49, // 189: state.v1.StateStoreService.Update:output_type -> state.v1.UpdateResponse - 51, // 190: state.v1.StateStoreService.Requeue:output_type -> state.v1.RequeueResponse - 53, // 191: state.v1.StateStoreService.ParkTask:output_type -> state.v1.ParkTaskResponse - 55, // 192: state.v1.StateStoreService.RecoverStale:output_type -> state.v1.RecoverStaleResponse - 57, // 193: state.v1.StateStoreService.ArchiveTask:output_type -> state.v1.ArchiveTaskResponse - 59, // 194: state.v1.StateStoreService.RetryTask:output_type -> state.v1.RetryTaskResponse - 61, // 195: state.v1.StateStoreService.BeginRemediation:output_type -> state.v1.BeginRemediationResponse - 63, // 196: state.v1.StateStoreService.UpdateReviewPayload:output_type -> state.v1.UpdateReviewPayloadResponse - 65, // 197: state.v1.StateStoreService.SetReviewCursors:output_type -> state.v1.SetReviewCursorsResponse - 67, // 198: state.v1.StateStoreService.TaskByIssue:output_type -> state.v1.TaskByIssueResponse - 69, // 199: state.v1.StateStoreService.OpenTaskByPR:output_type -> state.v1.OpenTaskByPRResponse - 71, // 200: state.v1.StateStoreService.TaskByID:output_type -> state.v1.TaskByIDResponse - 73, // 201: state.v1.StateStoreService.OpenPRs:output_type -> state.v1.OpenPRsResponse - 75, // 202: state.v1.StateStoreService.ClearTerminalTasks:output_type -> state.v1.ClearTerminalTasksResponse - 77, // 203: state.v1.StateStoreService.Tasks:output_type -> state.v1.TasksResponse - 79, // 204: state.v1.StateStoreService.StatusCounts:output_type -> state.v1.StatusCountsResponse - 81, // 205: state.v1.StateStoreService.InsertEvent:output_type -> state.v1.InsertEventResponse - 83, // 206: state.v1.StateStoreService.EventsSince:output_type -> state.v1.EventsSinceResponse - 85, // 207: state.v1.StateStoreService.TaskEvents:output_type -> state.v1.TaskEventsResponse - 87, // 208: state.v1.StateStoreService.WorkflowStats:output_type -> state.v1.WorkflowStatsResponse - 89, // 209: state.v1.StateStoreService.StageStats:output_type -> state.v1.StageStatsResponse - 91, // 210: state.v1.StateStoreService.TokensByDay:output_type -> state.v1.TokensByDayResponse - 94, // 211: state.v1.StateStoreService.PutConfigSnapshot:output_type -> state.v1.PutConfigSnapshotResponse - 96, // 212: state.v1.StateStoreService.GetConfigSnapshot:output_type -> state.v1.GetConfigSnapshotResponse - 99, // 213: state.v1.StateStoreService.PutChannelStatus:output_type -> state.v1.PutChannelStatusResponse - 101, // 214: state.v1.StateStoreService.ListChannelStatus:output_type -> state.v1.ListChannelStatusResponse - 104, // 215: state.v1.StateStoreService.PutApplyStatus:output_type -> state.v1.PutApplyStatusResponse - 106, // 216: state.v1.StateStoreService.ListApplyStatus:output_type -> state.v1.ListApplyStatusResponse - 109, // 217: state.v1.StateStoreService.ReadTaskLog:output_type -> state.v1.ReadTaskLogResponse - 111, // 218: state.v1.StateStoreService.StreamTaskLogContent:output_type -> state.v1.StreamTaskLogContentResponse - 113, // 219: state.v1.StateStoreService.InsertCapture:output_type -> state.v1.InsertCaptureResponse - 115, // 220: state.v1.StateStoreService.StreamCaptures:output_type -> state.v1.StreamCapturesResponse - 117, // 221: state.v1.StateStoreService.InsertMapping:output_type -> state.v1.InsertMappingResponse - 119, // 222: state.v1.StateStoreService.GetMapping:output_type -> state.v1.GetMappingResponse - 121, // 223: state.v1.StateStoreService.ListMappings:output_type -> state.v1.ListMappingsResponse - 123, // 224: state.v1.StateStoreService.UpdateMapping:output_type -> state.v1.UpdateMappingResponse - 125, // 225: state.v1.StateStoreService.DeleteMapping:output_type -> state.v1.DeleteMappingResponse - 127, // 226: state.v1.StateStoreService.RecordMappingMatch:output_type -> state.v1.RecordMappingMatchResponse - 129, // 227: state.v1.StateStoreService.InsertEventType:output_type -> state.v1.InsertEventTypeResponse - 131, // 228: state.v1.StateStoreService.UpdateEventType:output_type -> state.v1.UpdateEventTypeResponse - 133, // 229: state.v1.StateStoreService.DeleteEventType:output_type -> state.v1.DeleteEventTypeResponse - 135, // 230: state.v1.StateStoreService.ListEventTypes:output_type -> state.v1.ListEventTypesResponse - 137, // 231: state.v1.StateStoreService.InsertBinding:output_type -> state.v1.InsertBindingResponse - 139, // 232: state.v1.StateStoreService.GetBinding:output_type -> state.v1.GetBindingResponse - 141, // 233: state.v1.StateStoreService.ListBindings:output_type -> state.v1.ListBindingsResponse - 143, // 234: state.v1.StateStoreService.UpdateBinding:output_type -> state.v1.UpdateBindingResponse - 145, // 235: state.v1.StateStoreService.DeleteBinding:output_type -> state.v1.DeleteBindingResponse - 147, // 236: state.v1.StateStoreService.ApproveBinding:output_type -> state.v1.ApproveBindingResponse - 149, // 237: state.v1.StateStoreService.InsertSource:output_type -> state.v1.InsertSourceResponse - 151, // 238: state.v1.StateStoreService.GetSource:output_type -> state.v1.GetSourceResponse - 153, // 239: state.v1.StateStoreService.ListSources:output_type -> state.v1.ListSourcesResponse - 155, // 240: state.v1.StateStoreService.SetSourceSigning:output_type -> state.v1.SetSourceSigningResponse - 157, // 241: state.v1.StateStoreService.SetSourceSecret:output_type -> state.v1.SetSourceSecretResponse - 159, // 242: state.v1.StateStoreService.ArmedBindingsForSource:output_type -> state.v1.ArmedBindingsForSourceResponse - 161, // 243: state.v1.StateStoreService.RecordDispatch:output_type -> state.v1.RecordDispatchResponse - 163, // 244: state.v1.StateStoreService.RecordPlaybookDispatch:output_type -> state.v1.RecordPlaybookDispatchResponse - 165, // 245: state.v1.StateStoreService.DeletePlaybookDispatches:output_type -> state.v1.DeletePlaybookDispatchesResponse - 167, // 246: state.v1.StateStoreService.StreamUndispatchedCaptures:output_type -> state.v1.StreamUndispatchedCapturesResponse - 169, // 247: state.v1.StateStoreService.EnqueueBindingTask:output_type -> state.v1.EnqueueBindingTaskResponse - 171, // 248: state.v1.StateStoreService.EnqueueCallTask:output_type -> state.v1.EnqueueCallTaskResponse - 173, // 249: state.v1.StateStoreService.WorkflowCallStatus:output_type -> state.v1.WorkflowCallStatusResponse - 169, // [169:250] is the sub-list for method output_type - 88, // [88:169] is the sub-list for method input_type - 88, // [88:88] is the sub-list for extension type_name - 88, // [88:88] is the sub-list for extension extendee - 0, // [0:88] is the sub-list for field type_name + 184, // 88: state.v1.AccessPrincipal.memberships:type_name -> state.v1.PrincipalMembership + 185, // 89: state.v1.GetPrincipalResponse.principal:type_name -> state.v1.AccessPrincipal + 187, // 90: state.v1.ListPoliciesResponse.policies:type_name -> state.v1.AccessPolicy + 187, // 91: state.v1.PutPolicyRequest.policy:type_name -> state.v1.AccessPolicy + 187, // 92: state.v1.DeletePolicyRequest.policy:type_name -> state.v1.AccessPolicy + 203, // 93: state.v1.AccessDenial.at:type_name -> google.protobuf.Timestamp + 196, // 94: state.v1.RecordDenialRequest.denial:type_name -> state.v1.AccessDenial + 196, // 95: state.v1.ListDenialsResponse.denials:type_name -> state.v1.AccessDenial + 175, // 96: state.v1.StateStoreService.InstallPackage:input_type -> state.v1.InstallPackageRequest + 177, // 97: state.v1.StateStoreService.GetInstalledPackage:input_type -> state.v1.GetInstalledPackageRequest + 179, // 98: state.v1.StateStoreService.ListInstalledPackages:input_type -> state.v1.ListInstalledPackagesRequest + 181, // 99: state.v1.StateStoreService.RemoveInstalledPackage:input_type -> state.v1.RemoveInstalledPackageRequest + 0, // 100: state.v1.StateStoreService.RegisterTaskGrant:input_type -> state.v1.RegisterTaskGrantRequest + 2, // 101: state.v1.StateStoreService.RevokeTaskGrant:input_type -> state.v1.RevokeTaskGrantRequest + 6, // 102: state.v1.StateStoreService.ListIdentities:input_type -> state.v1.ListIdentitiesRequest + 8, // 103: state.v1.StateStoreService.GetIdentity:input_type -> state.v1.GetIdentityRequest + 10, // 104: state.v1.StateStoreService.CreateIdentity:input_type -> state.v1.CreateIdentityRequest + 11, // 105: state.v1.StateStoreService.RenameIdentity:input_type -> state.v1.RenameIdentityRequest + 12, // 106: state.v1.StateStoreService.SuspendIdentity:input_type -> state.v1.SuspendIdentityRequest + 13, // 107: state.v1.StateStoreService.ReactivateIdentity:input_type -> state.v1.ReactivateIdentityRequest + 14, // 108: state.v1.StateStoreService.RetireIdentity:input_type -> state.v1.RetireIdentityRequest + 20, // 109: state.v1.StateStoreService.ResolveIdentitySubject:input_type -> state.v1.ResolveIdentitySubjectRequest + 22, // 110: state.v1.StateStoreService.BindIdentitySubject:input_type -> state.v1.BindIdentitySubjectRequest + 38, // 111: state.v1.StateStoreService.EnqueueIssue:input_type -> state.v1.EnqueueIssueRequest + 40, // 112: state.v1.StateStoreService.EnqueueChatTask:input_type -> state.v1.EnqueueChatTaskRequest + 42, // 113: state.v1.StateStoreService.ClaimNext:input_type -> state.v1.ClaimNextRequest + 44, // 114: state.v1.StateStoreService.ClaimByIssue:input_type -> state.v1.ClaimByIssueRequest + 46, // 115: state.v1.StateStoreService.Transition:input_type -> state.v1.TransitionRequest + 48, // 116: state.v1.StateStoreService.Update:input_type -> state.v1.UpdateRequest + 50, // 117: state.v1.StateStoreService.Requeue:input_type -> state.v1.RequeueRequest + 52, // 118: state.v1.StateStoreService.ParkTask:input_type -> state.v1.ParkTaskRequest + 54, // 119: state.v1.StateStoreService.RecoverStale:input_type -> state.v1.RecoverStaleRequest + 56, // 120: state.v1.StateStoreService.ArchiveTask:input_type -> state.v1.ArchiveTaskRequest + 58, // 121: state.v1.StateStoreService.RetryTask:input_type -> state.v1.RetryTaskRequest + 60, // 122: state.v1.StateStoreService.BeginRemediation:input_type -> state.v1.BeginRemediationRequest + 62, // 123: state.v1.StateStoreService.UpdateReviewPayload:input_type -> state.v1.UpdateReviewPayloadRequest + 64, // 124: state.v1.StateStoreService.SetReviewCursors:input_type -> state.v1.SetReviewCursorsRequest + 66, // 125: state.v1.StateStoreService.TaskByIssue:input_type -> state.v1.TaskByIssueRequest + 68, // 126: state.v1.StateStoreService.OpenTaskByPR:input_type -> state.v1.OpenTaskByPRRequest + 70, // 127: state.v1.StateStoreService.TaskByID:input_type -> state.v1.TaskByIDRequest + 72, // 128: state.v1.StateStoreService.OpenPRs:input_type -> state.v1.OpenPRsRequest + 74, // 129: state.v1.StateStoreService.ClearTerminalTasks:input_type -> state.v1.ClearTerminalTasksRequest + 76, // 130: state.v1.StateStoreService.Tasks:input_type -> state.v1.TasksRequest + 78, // 131: state.v1.StateStoreService.StatusCounts:input_type -> state.v1.StatusCountsRequest + 80, // 132: state.v1.StateStoreService.InsertEvent:input_type -> state.v1.InsertEventRequest + 82, // 133: state.v1.StateStoreService.EventsSince:input_type -> state.v1.EventsSinceRequest + 84, // 134: state.v1.StateStoreService.TaskEvents:input_type -> state.v1.TaskEventsRequest + 86, // 135: state.v1.StateStoreService.WorkflowStats:input_type -> state.v1.WorkflowStatsRequest + 88, // 136: state.v1.StateStoreService.StageStats:input_type -> state.v1.StageStatsRequest + 90, // 137: state.v1.StateStoreService.TokensByDay:input_type -> state.v1.TokensByDayRequest + 93, // 138: state.v1.StateStoreService.PutConfigSnapshot:input_type -> state.v1.PutConfigSnapshotRequest + 95, // 139: state.v1.StateStoreService.GetConfigSnapshot:input_type -> state.v1.GetConfigSnapshotRequest + 98, // 140: state.v1.StateStoreService.PutChannelStatus:input_type -> state.v1.PutChannelStatusRequest + 100, // 141: state.v1.StateStoreService.ListChannelStatus:input_type -> state.v1.ListChannelStatusRequest + 103, // 142: state.v1.StateStoreService.PutApplyStatus:input_type -> state.v1.PutApplyStatusRequest + 105, // 143: state.v1.StateStoreService.ListApplyStatus:input_type -> state.v1.ListApplyStatusRequest + 108, // 144: state.v1.StateStoreService.ReadTaskLog:input_type -> state.v1.ReadTaskLogRequest + 110, // 145: state.v1.StateStoreService.StreamTaskLogContent:input_type -> state.v1.StreamTaskLogContentRequest + 112, // 146: state.v1.StateStoreService.InsertCapture:input_type -> state.v1.InsertCaptureRequest + 114, // 147: state.v1.StateStoreService.StreamCaptures:input_type -> state.v1.StreamCapturesRequest + 116, // 148: state.v1.StateStoreService.InsertMapping:input_type -> state.v1.InsertMappingRequest + 118, // 149: state.v1.StateStoreService.GetMapping:input_type -> state.v1.GetMappingRequest + 120, // 150: state.v1.StateStoreService.ListMappings:input_type -> state.v1.ListMappingsRequest + 122, // 151: state.v1.StateStoreService.UpdateMapping:input_type -> state.v1.UpdateMappingRequest + 124, // 152: state.v1.StateStoreService.DeleteMapping:input_type -> state.v1.DeleteMappingRequest + 126, // 153: state.v1.StateStoreService.RecordMappingMatch:input_type -> state.v1.RecordMappingMatchRequest + 128, // 154: state.v1.StateStoreService.InsertEventType:input_type -> state.v1.InsertEventTypeRequest + 130, // 155: state.v1.StateStoreService.UpdateEventType:input_type -> state.v1.UpdateEventTypeRequest + 132, // 156: state.v1.StateStoreService.DeleteEventType:input_type -> state.v1.DeleteEventTypeRequest + 134, // 157: state.v1.StateStoreService.ListEventTypes:input_type -> state.v1.ListEventTypesRequest + 136, // 158: state.v1.StateStoreService.InsertBinding:input_type -> state.v1.InsertBindingRequest + 138, // 159: state.v1.StateStoreService.GetBinding:input_type -> state.v1.GetBindingRequest + 140, // 160: state.v1.StateStoreService.ListBindings:input_type -> state.v1.ListBindingsRequest + 142, // 161: state.v1.StateStoreService.UpdateBinding:input_type -> state.v1.UpdateBindingRequest + 144, // 162: state.v1.StateStoreService.DeleteBinding:input_type -> state.v1.DeleteBindingRequest + 146, // 163: state.v1.StateStoreService.ApproveBinding:input_type -> state.v1.ApproveBindingRequest + 148, // 164: state.v1.StateStoreService.InsertSource:input_type -> state.v1.InsertSourceRequest + 150, // 165: state.v1.StateStoreService.GetSource:input_type -> state.v1.GetSourceRequest + 152, // 166: state.v1.StateStoreService.ListSources:input_type -> state.v1.ListSourcesRequest + 154, // 167: state.v1.StateStoreService.SetSourceSigning:input_type -> state.v1.SetSourceSigningRequest + 156, // 168: state.v1.StateStoreService.SetSourceSecret:input_type -> state.v1.SetSourceSecretRequest + 158, // 169: state.v1.StateStoreService.ArmedBindingsForSource:input_type -> state.v1.ArmedBindingsForSourceRequest + 160, // 170: state.v1.StateStoreService.RecordDispatch:input_type -> state.v1.RecordDispatchRequest + 162, // 171: state.v1.StateStoreService.RecordPlaybookDispatch:input_type -> state.v1.RecordPlaybookDispatchRequest + 164, // 172: state.v1.StateStoreService.DeletePlaybookDispatches:input_type -> state.v1.DeletePlaybookDispatchesRequest + 166, // 173: state.v1.StateStoreService.StreamUndispatchedCaptures:input_type -> state.v1.StreamUndispatchedCapturesRequest + 168, // 174: state.v1.StateStoreService.EnqueueBindingTask:input_type -> state.v1.EnqueueBindingTaskRequest + 170, // 175: state.v1.StateStoreService.EnqueueCallTask:input_type -> state.v1.EnqueueCallTaskRequest + 172, // 176: state.v1.StateStoreService.WorkflowCallStatus:input_type -> state.v1.WorkflowCallStatusRequest + 183, // 177: state.v1.StateStoreService.GetPrincipal:input_type -> state.v1.GetPrincipalRequest + 188, // 178: state.v1.StateStoreService.ListPolicies:input_type -> state.v1.ListPoliciesRequest + 190, // 179: state.v1.StateStoreService.PutPolicy:input_type -> state.v1.PutPolicyRequest + 192, // 180: state.v1.StateStoreService.DeletePolicy:input_type -> state.v1.DeletePolicyRequest + 194, // 181: state.v1.StateStoreService.EnsureShippedOrgPolicies:input_type -> state.v1.EnsureShippedOrgPoliciesRequest + 197, // 182: state.v1.StateStoreService.RecordDenial:input_type -> state.v1.RecordDenialRequest + 199, // 183: state.v1.StateStoreService.ListDenials:input_type -> state.v1.ListDenialsRequest + 176, // 184: state.v1.StateStoreService.InstallPackage:output_type -> state.v1.InstallPackageResponse + 178, // 185: state.v1.StateStoreService.GetInstalledPackage:output_type -> state.v1.GetInstalledPackageResponse + 180, // 186: state.v1.StateStoreService.ListInstalledPackages:output_type -> state.v1.ListInstalledPackagesResponse + 182, // 187: state.v1.StateStoreService.RemoveInstalledPackage:output_type -> state.v1.RemoveInstalledPackageResponse + 1, // 188: state.v1.StateStoreService.RegisterTaskGrant:output_type -> state.v1.RegisterTaskGrantResponse + 3, // 189: state.v1.StateStoreService.RevokeTaskGrant:output_type -> state.v1.RevokeTaskGrantResponse + 7, // 190: state.v1.StateStoreService.ListIdentities:output_type -> state.v1.ListIdentitiesResponse + 9, // 191: state.v1.StateStoreService.GetIdentity:output_type -> state.v1.GetIdentityResponse + 15, // 192: state.v1.StateStoreService.CreateIdentity:output_type -> state.v1.CreateIdentityResponse + 16, // 193: state.v1.StateStoreService.RenameIdentity:output_type -> state.v1.RenameIdentityResponse + 17, // 194: state.v1.StateStoreService.SuspendIdentity:output_type -> state.v1.SuspendIdentityResponse + 18, // 195: state.v1.StateStoreService.ReactivateIdentity:output_type -> state.v1.ReactivateIdentityResponse + 19, // 196: state.v1.StateStoreService.RetireIdentity:output_type -> state.v1.RetireIdentityResponse + 21, // 197: state.v1.StateStoreService.ResolveIdentitySubject:output_type -> state.v1.ResolveIdentitySubjectResponse + 23, // 198: state.v1.StateStoreService.BindIdentitySubject:output_type -> state.v1.BindIdentitySubjectResponse + 39, // 199: state.v1.StateStoreService.EnqueueIssue:output_type -> state.v1.EnqueueIssueResponse + 41, // 200: state.v1.StateStoreService.EnqueueChatTask:output_type -> state.v1.EnqueueChatTaskResponse + 43, // 201: state.v1.StateStoreService.ClaimNext:output_type -> state.v1.ClaimNextResponse + 45, // 202: state.v1.StateStoreService.ClaimByIssue:output_type -> state.v1.ClaimByIssueResponse + 47, // 203: state.v1.StateStoreService.Transition:output_type -> state.v1.TransitionResponse + 49, // 204: state.v1.StateStoreService.Update:output_type -> state.v1.UpdateResponse + 51, // 205: state.v1.StateStoreService.Requeue:output_type -> state.v1.RequeueResponse + 53, // 206: state.v1.StateStoreService.ParkTask:output_type -> state.v1.ParkTaskResponse + 55, // 207: state.v1.StateStoreService.RecoverStale:output_type -> state.v1.RecoverStaleResponse + 57, // 208: state.v1.StateStoreService.ArchiveTask:output_type -> state.v1.ArchiveTaskResponse + 59, // 209: state.v1.StateStoreService.RetryTask:output_type -> state.v1.RetryTaskResponse + 61, // 210: state.v1.StateStoreService.BeginRemediation:output_type -> state.v1.BeginRemediationResponse + 63, // 211: state.v1.StateStoreService.UpdateReviewPayload:output_type -> state.v1.UpdateReviewPayloadResponse + 65, // 212: state.v1.StateStoreService.SetReviewCursors:output_type -> state.v1.SetReviewCursorsResponse + 67, // 213: state.v1.StateStoreService.TaskByIssue:output_type -> state.v1.TaskByIssueResponse + 69, // 214: state.v1.StateStoreService.OpenTaskByPR:output_type -> state.v1.OpenTaskByPRResponse + 71, // 215: state.v1.StateStoreService.TaskByID:output_type -> state.v1.TaskByIDResponse + 73, // 216: state.v1.StateStoreService.OpenPRs:output_type -> state.v1.OpenPRsResponse + 75, // 217: state.v1.StateStoreService.ClearTerminalTasks:output_type -> state.v1.ClearTerminalTasksResponse + 77, // 218: state.v1.StateStoreService.Tasks:output_type -> state.v1.TasksResponse + 79, // 219: state.v1.StateStoreService.StatusCounts:output_type -> state.v1.StatusCountsResponse + 81, // 220: state.v1.StateStoreService.InsertEvent:output_type -> state.v1.InsertEventResponse + 83, // 221: state.v1.StateStoreService.EventsSince:output_type -> state.v1.EventsSinceResponse + 85, // 222: state.v1.StateStoreService.TaskEvents:output_type -> state.v1.TaskEventsResponse + 87, // 223: state.v1.StateStoreService.WorkflowStats:output_type -> state.v1.WorkflowStatsResponse + 89, // 224: state.v1.StateStoreService.StageStats:output_type -> state.v1.StageStatsResponse + 91, // 225: state.v1.StateStoreService.TokensByDay:output_type -> state.v1.TokensByDayResponse + 94, // 226: state.v1.StateStoreService.PutConfigSnapshot:output_type -> state.v1.PutConfigSnapshotResponse + 96, // 227: state.v1.StateStoreService.GetConfigSnapshot:output_type -> state.v1.GetConfigSnapshotResponse + 99, // 228: state.v1.StateStoreService.PutChannelStatus:output_type -> state.v1.PutChannelStatusResponse + 101, // 229: state.v1.StateStoreService.ListChannelStatus:output_type -> state.v1.ListChannelStatusResponse + 104, // 230: state.v1.StateStoreService.PutApplyStatus:output_type -> state.v1.PutApplyStatusResponse + 106, // 231: state.v1.StateStoreService.ListApplyStatus:output_type -> state.v1.ListApplyStatusResponse + 109, // 232: state.v1.StateStoreService.ReadTaskLog:output_type -> state.v1.ReadTaskLogResponse + 111, // 233: state.v1.StateStoreService.StreamTaskLogContent:output_type -> state.v1.StreamTaskLogContentResponse + 113, // 234: state.v1.StateStoreService.InsertCapture:output_type -> state.v1.InsertCaptureResponse + 115, // 235: state.v1.StateStoreService.StreamCaptures:output_type -> state.v1.StreamCapturesResponse + 117, // 236: state.v1.StateStoreService.InsertMapping:output_type -> state.v1.InsertMappingResponse + 119, // 237: state.v1.StateStoreService.GetMapping:output_type -> state.v1.GetMappingResponse + 121, // 238: state.v1.StateStoreService.ListMappings:output_type -> state.v1.ListMappingsResponse + 123, // 239: state.v1.StateStoreService.UpdateMapping:output_type -> state.v1.UpdateMappingResponse + 125, // 240: state.v1.StateStoreService.DeleteMapping:output_type -> state.v1.DeleteMappingResponse + 127, // 241: state.v1.StateStoreService.RecordMappingMatch:output_type -> state.v1.RecordMappingMatchResponse + 129, // 242: state.v1.StateStoreService.InsertEventType:output_type -> state.v1.InsertEventTypeResponse + 131, // 243: state.v1.StateStoreService.UpdateEventType:output_type -> state.v1.UpdateEventTypeResponse + 133, // 244: state.v1.StateStoreService.DeleteEventType:output_type -> state.v1.DeleteEventTypeResponse + 135, // 245: state.v1.StateStoreService.ListEventTypes:output_type -> state.v1.ListEventTypesResponse + 137, // 246: state.v1.StateStoreService.InsertBinding:output_type -> state.v1.InsertBindingResponse + 139, // 247: state.v1.StateStoreService.GetBinding:output_type -> state.v1.GetBindingResponse + 141, // 248: state.v1.StateStoreService.ListBindings:output_type -> state.v1.ListBindingsResponse + 143, // 249: state.v1.StateStoreService.UpdateBinding:output_type -> state.v1.UpdateBindingResponse + 145, // 250: state.v1.StateStoreService.DeleteBinding:output_type -> state.v1.DeleteBindingResponse + 147, // 251: state.v1.StateStoreService.ApproveBinding:output_type -> state.v1.ApproveBindingResponse + 149, // 252: state.v1.StateStoreService.InsertSource:output_type -> state.v1.InsertSourceResponse + 151, // 253: state.v1.StateStoreService.GetSource:output_type -> state.v1.GetSourceResponse + 153, // 254: state.v1.StateStoreService.ListSources:output_type -> state.v1.ListSourcesResponse + 155, // 255: state.v1.StateStoreService.SetSourceSigning:output_type -> state.v1.SetSourceSigningResponse + 157, // 256: state.v1.StateStoreService.SetSourceSecret:output_type -> state.v1.SetSourceSecretResponse + 159, // 257: state.v1.StateStoreService.ArmedBindingsForSource:output_type -> state.v1.ArmedBindingsForSourceResponse + 161, // 258: state.v1.StateStoreService.RecordDispatch:output_type -> state.v1.RecordDispatchResponse + 163, // 259: state.v1.StateStoreService.RecordPlaybookDispatch:output_type -> state.v1.RecordPlaybookDispatchResponse + 165, // 260: state.v1.StateStoreService.DeletePlaybookDispatches:output_type -> state.v1.DeletePlaybookDispatchesResponse + 167, // 261: state.v1.StateStoreService.StreamUndispatchedCaptures:output_type -> state.v1.StreamUndispatchedCapturesResponse + 169, // 262: state.v1.StateStoreService.EnqueueBindingTask:output_type -> state.v1.EnqueueBindingTaskResponse + 171, // 263: state.v1.StateStoreService.EnqueueCallTask:output_type -> state.v1.EnqueueCallTaskResponse + 173, // 264: state.v1.StateStoreService.WorkflowCallStatus:output_type -> state.v1.WorkflowCallStatusResponse + 186, // 265: state.v1.StateStoreService.GetPrincipal:output_type -> state.v1.GetPrincipalResponse + 189, // 266: state.v1.StateStoreService.ListPolicies:output_type -> state.v1.ListPoliciesResponse + 191, // 267: state.v1.StateStoreService.PutPolicy:output_type -> state.v1.PutPolicyResponse + 193, // 268: state.v1.StateStoreService.DeletePolicy:output_type -> state.v1.DeletePolicyResponse + 195, // 269: state.v1.StateStoreService.EnsureShippedOrgPolicies:output_type -> state.v1.EnsureShippedOrgPoliciesResponse + 198, // 270: state.v1.StateStoreService.RecordDenial:output_type -> state.v1.RecordDenialResponse + 200, // 271: state.v1.StateStoreService.ListDenials:output_type -> state.v1.ListDenialsResponse + 184, // [184:272] is the sub-list for method output_type + 96, // [96:184] is the sub-list for method input_type + 96, // [96:96] is the sub-list for extension type_name + 96, // [96:96] is the sub-list for extension extendee + 0, // [0:96] is the sub-list for field type_name } func init() { file_state_v1_state_proto_init() } @@ -11025,7 +12046,7 @@ func file_state_v1_state_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: unsafe.Slice(unsafe.StringData(file_state_v1_state_proto_rawDesc), len(file_state_v1_state_proto_rawDesc)), NumEnums: 0, - NumMessages: 185, + NumMessages: 203, NumExtensions: 0, NumServices: 1, }, diff --git a/internal/contracts/state/v1/state_grpc.pb.go b/internal/contracts/state/v1/state_grpc.pb.go index 967633d44..6c5ae245a 100644 --- a/internal/contracts/state/v1/state_grpc.pb.go +++ b/internal/contracts/state/v1/state_grpc.pb.go @@ -100,6 +100,13 @@ const ( StateStoreService_EnqueueBindingTask_FullMethodName = "/state.v1.StateStoreService/EnqueueBindingTask" StateStoreService_EnqueueCallTask_FullMethodName = "/state.v1.StateStoreService/EnqueueCallTask" StateStoreService_WorkflowCallStatus_FullMethodName = "/state.v1.StateStoreService/WorkflowCallStatus" + StateStoreService_GetPrincipal_FullMethodName = "/state.v1.StateStoreService/GetPrincipal" + StateStoreService_ListPolicies_FullMethodName = "/state.v1.StateStoreService/ListPolicies" + StateStoreService_PutPolicy_FullMethodName = "/state.v1.StateStoreService/PutPolicy" + StateStoreService_DeletePolicy_FullMethodName = "/state.v1.StateStoreService/DeletePolicy" + StateStoreService_EnsureShippedOrgPolicies_FullMethodName = "/state.v1.StateStoreService/EnsureShippedOrgPolicies" + StateStoreService_RecordDenial_FullMethodName = "/state.v1.StateStoreService/RecordDenial" + StateStoreService_ListDenials_FullMethodName = "/state.v1.StateStoreService/ListDenials" ) // StateStoreServiceClient is the client API for StateStoreService service. @@ -252,6 +259,19 @@ type StateStoreServiceClient interface { // relation server-side, so the grant only names the caller. EnqueueCallTask(ctx context.Context, in *EnqueueCallTaskRequest, opts ...grpc.CallOption) (*EnqueueCallTaskResponse, error) WorkflowCallStatus(ctx context.Context, in *WorkflowCallStatusRequest, opts ...grpc.CallOption) (*WorkflowCallStatusResponse, error) + // Access: the stored policy chain and its denial records + // (docs/prds/orgs-and-access.md). ListPolicies is the engine's snapshot; + // the writes are administrative. RecordDenial is the dashboard's and + // dispatch's write path; ListDenials is the operator surface. + // The principal assembly the Authorizer evaluates: an identity, the org + // it serves, and its memberships (internal/domain/access). + GetPrincipal(ctx context.Context, in *GetPrincipalRequest, opts ...grpc.CallOption) (*GetPrincipalResponse, error) + ListPolicies(ctx context.Context, in *ListPoliciesRequest, opts ...grpc.CallOption) (*ListPoliciesResponse, error) + PutPolicy(ctx context.Context, in *PutPolicyRequest, opts ...grpc.CallOption) (*PutPolicyResponse, error) + DeletePolicy(ctx context.Context, in *DeletePolicyRequest, opts ...grpc.CallOption) (*DeletePolicyResponse, error) + EnsureShippedOrgPolicies(ctx context.Context, in *EnsureShippedOrgPoliciesRequest, opts ...grpc.CallOption) (*EnsureShippedOrgPoliciesResponse, error) + RecordDenial(ctx context.Context, in *RecordDenialRequest, opts ...grpc.CallOption) (*RecordDenialResponse, error) + ListDenials(ctx context.Context, in *ListDenialsRequest, opts ...grpc.CallOption) (*ListDenialsResponse, error) } type stateStoreServiceClient struct { @@ -1099,6 +1119,76 @@ func (c *stateStoreServiceClient) WorkflowCallStatus(ctx context.Context, in *Wo return out, nil } +func (c *stateStoreServiceClient) GetPrincipal(ctx context.Context, in *GetPrincipalRequest, opts ...grpc.CallOption) (*GetPrincipalResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(GetPrincipalResponse) + err := c.cc.Invoke(ctx, StateStoreService_GetPrincipal_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *stateStoreServiceClient) ListPolicies(ctx context.Context, in *ListPoliciesRequest, opts ...grpc.CallOption) (*ListPoliciesResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(ListPoliciesResponse) + err := c.cc.Invoke(ctx, StateStoreService_ListPolicies_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *stateStoreServiceClient) PutPolicy(ctx context.Context, in *PutPolicyRequest, opts ...grpc.CallOption) (*PutPolicyResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(PutPolicyResponse) + err := c.cc.Invoke(ctx, StateStoreService_PutPolicy_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *stateStoreServiceClient) DeletePolicy(ctx context.Context, in *DeletePolicyRequest, opts ...grpc.CallOption) (*DeletePolicyResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(DeletePolicyResponse) + err := c.cc.Invoke(ctx, StateStoreService_DeletePolicy_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *stateStoreServiceClient) EnsureShippedOrgPolicies(ctx context.Context, in *EnsureShippedOrgPoliciesRequest, opts ...grpc.CallOption) (*EnsureShippedOrgPoliciesResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(EnsureShippedOrgPoliciesResponse) + err := c.cc.Invoke(ctx, StateStoreService_EnsureShippedOrgPolicies_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *stateStoreServiceClient) RecordDenial(ctx context.Context, in *RecordDenialRequest, opts ...grpc.CallOption) (*RecordDenialResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(RecordDenialResponse) + err := c.cc.Invoke(ctx, StateStoreService_RecordDenial_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *stateStoreServiceClient) ListDenials(ctx context.Context, in *ListDenialsRequest, opts ...grpc.CallOption) (*ListDenialsResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(ListDenialsResponse) + err := c.cc.Invoke(ctx, StateStoreService_ListDenials_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + // StateStoreServiceServer is the server API for StateStoreService service. // All implementations must embed UnimplementedStateStoreServiceServer // for forward compatibility. @@ -1249,6 +1339,19 @@ type StateStoreServiceServer interface { // relation server-side, so the grant only names the caller. EnqueueCallTask(context.Context, *EnqueueCallTaskRequest) (*EnqueueCallTaskResponse, error) WorkflowCallStatus(context.Context, *WorkflowCallStatusRequest) (*WorkflowCallStatusResponse, error) + // Access: the stored policy chain and its denial records + // (docs/prds/orgs-and-access.md). ListPolicies is the engine's snapshot; + // the writes are administrative. RecordDenial is the dashboard's and + // dispatch's write path; ListDenials is the operator surface. + // The principal assembly the Authorizer evaluates: an identity, the org + // it serves, and its memberships (internal/domain/access). + GetPrincipal(context.Context, *GetPrincipalRequest) (*GetPrincipalResponse, error) + ListPolicies(context.Context, *ListPoliciesRequest) (*ListPoliciesResponse, error) + PutPolicy(context.Context, *PutPolicyRequest) (*PutPolicyResponse, error) + DeletePolicy(context.Context, *DeletePolicyRequest) (*DeletePolicyResponse, error) + EnsureShippedOrgPolicies(context.Context, *EnsureShippedOrgPoliciesRequest) (*EnsureShippedOrgPoliciesResponse, error) + RecordDenial(context.Context, *RecordDenialRequest) (*RecordDenialResponse, error) + ListDenials(context.Context, *ListDenialsRequest) (*ListDenialsResponse, error) mustEmbedUnimplementedStateStoreServiceServer() } @@ -1502,6 +1605,27 @@ func (UnimplementedStateStoreServiceServer) EnqueueCallTask(context.Context, *En func (UnimplementedStateStoreServiceServer) WorkflowCallStatus(context.Context, *WorkflowCallStatusRequest) (*WorkflowCallStatusResponse, error) { return nil, status.Error(codes.Unimplemented, "method WorkflowCallStatus not implemented") } +func (UnimplementedStateStoreServiceServer) GetPrincipal(context.Context, *GetPrincipalRequest) (*GetPrincipalResponse, error) { + return nil, status.Error(codes.Unimplemented, "method GetPrincipal not implemented") +} +func (UnimplementedStateStoreServiceServer) ListPolicies(context.Context, *ListPoliciesRequest) (*ListPoliciesResponse, error) { + return nil, status.Error(codes.Unimplemented, "method ListPolicies not implemented") +} +func (UnimplementedStateStoreServiceServer) PutPolicy(context.Context, *PutPolicyRequest) (*PutPolicyResponse, error) { + return nil, status.Error(codes.Unimplemented, "method PutPolicy not implemented") +} +func (UnimplementedStateStoreServiceServer) DeletePolicy(context.Context, *DeletePolicyRequest) (*DeletePolicyResponse, error) { + return nil, status.Error(codes.Unimplemented, "method DeletePolicy not implemented") +} +func (UnimplementedStateStoreServiceServer) EnsureShippedOrgPolicies(context.Context, *EnsureShippedOrgPoliciesRequest) (*EnsureShippedOrgPoliciesResponse, error) { + return nil, status.Error(codes.Unimplemented, "method EnsureShippedOrgPolicies not implemented") +} +func (UnimplementedStateStoreServiceServer) RecordDenial(context.Context, *RecordDenialRequest) (*RecordDenialResponse, error) { + return nil, status.Error(codes.Unimplemented, "method RecordDenial not implemented") +} +func (UnimplementedStateStoreServiceServer) ListDenials(context.Context, *ListDenialsRequest) (*ListDenialsResponse, error) { + return nil, status.Error(codes.Unimplemented, "method ListDenials not implemented") +} func (UnimplementedStateStoreServiceServer) mustEmbedUnimplementedStateStoreServiceServer() {} func (UnimplementedStateStoreServiceServer) testEmbeddedByValue() {} @@ -2960,6 +3084,132 @@ func _StateStoreService_WorkflowCallStatus_Handler(srv interface{}, ctx context. return interceptor(ctx, in, info, handler) } +func _StateStoreService_GetPrincipal_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetPrincipalRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(StateStoreServiceServer).GetPrincipal(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: StateStoreService_GetPrincipal_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(StateStoreServiceServer).GetPrincipal(ctx, req.(*GetPrincipalRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _StateStoreService_ListPolicies_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ListPoliciesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(StateStoreServiceServer).ListPolicies(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: StateStoreService_ListPolicies_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(StateStoreServiceServer).ListPolicies(ctx, req.(*ListPoliciesRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _StateStoreService_PutPolicy_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(PutPolicyRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(StateStoreServiceServer).PutPolicy(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: StateStoreService_PutPolicy_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(StateStoreServiceServer).PutPolicy(ctx, req.(*PutPolicyRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _StateStoreService_DeletePolicy_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DeletePolicyRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(StateStoreServiceServer).DeletePolicy(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: StateStoreService_DeletePolicy_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(StateStoreServiceServer).DeletePolicy(ctx, req.(*DeletePolicyRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _StateStoreService_EnsureShippedOrgPolicies_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(EnsureShippedOrgPoliciesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(StateStoreServiceServer).EnsureShippedOrgPolicies(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: StateStoreService_EnsureShippedOrgPolicies_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(StateStoreServiceServer).EnsureShippedOrgPolicies(ctx, req.(*EnsureShippedOrgPoliciesRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _StateStoreService_RecordDenial_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(RecordDenialRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(StateStoreServiceServer).RecordDenial(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: StateStoreService_RecordDenial_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(StateStoreServiceServer).RecordDenial(ctx, req.(*RecordDenialRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _StateStoreService_ListDenials_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ListDenialsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(StateStoreServiceServer).ListDenials(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: StateStoreService_ListDenials_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(StateStoreServiceServer).ListDenials(ctx, req.(*ListDenialsRequest)) + } + return interceptor(ctx, in, info, handler) +} + // StateStoreService_ServiceDesc is the grpc.ServiceDesc for StateStoreService service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -3279,6 +3529,34 @@ var StateStoreService_ServiceDesc = grpc.ServiceDesc{ MethodName: "WorkflowCallStatus", Handler: _StateStoreService_WorkflowCallStatus_Handler, }, + { + MethodName: "GetPrincipal", + Handler: _StateStoreService_GetPrincipal_Handler, + }, + { + MethodName: "ListPolicies", + Handler: _StateStoreService_ListPolicies_Handler, + }, + { + MethodName: "PutPolicy", + Handler: _StateStoreService_PutPolicy_Handler, + }, + { + MethodName: "DeletePolicy", + Handler: _StateStoreService_DeletePolicy_Handler, + }, + { + MethodName: "EnsureShippedOrgPolicies", + Handler: _StateStoreService_EnsureShippedOrgPolicies_Handler, + }, + { + MethodName: "RecordDenial", + Handler: _StateStoreService_RecordDenial_Handler, + }, + { + MethodName: "ListDenials", + Handler: _StateStoreService_ListDenials_Handler, + }, }, Streams: []grpc.StreamDesc{ { diff --git a/internal/domain/access/request.go b/internal/domain/access/request.go index ccefcfa7f..a5f2ee23f 100644 --- a/internal/domain/access/request.go +++ b/internal/domain/access/request.go @@ -6,6 +6,7 @@ package access import ( + "context" "time" "github.com/samcharles93/archie-core/internal/domain/identity" @@ -129,6 +130,16 @@ func DeniedAt(level Level, policies []string) Decision { return Decision{Level: level, Policies: policies} } +// PrincipalSource assembles the principal for one identity: the org it +// serves and its memberships. The State Store implements it (the memberships +// live in the State Store); the dashboard and dispatch call it over the wire. +type PrincipalSource interface { + // PrincipalFor returns the assembled principal. An identity in no org + // resolves to the default org, a principal with no role, which no + // shipped policy permits. + PrincipalFor(ctx context.Context, id identity.IdentityID) (Principal, error) +} + // Denial is one recorded refusal: who was refused, doing what, to what, by // which level and which policies (docs/prds/orgs-and-access.md, "Denials"). type Denial struct { diff --git a/internal/infrastructure/postgres/access.go b/internal/infrastructure/postgres/access.go new file mode 100644 index 000000000..27036188c --- /dev/null +++ b/internal/infrastructure/postgres/access.go @@ -0,0 +1,234 @@ +// Access policies and denial records: the Postgres implementation of +// internal/domain/access's PolicyStore, Resetter and DenialStore +// (docs/prds/orgs-and-access.md). Policy changes are versioned per level +// scope and audited as one sys_audit row per change naming who made it. +package postgres + +import ( + "context" + "encoding/json" + "fmt" + "strings" + + "github.com/jackc/pgx/v5" + + "github.com/samcharles93/archie-core/internal/domain/access" + "github.com/samcharles93/archie-core/internal/domain/identity" + "github.com/samcharles93/archie-core/internal/domain/org" + "github.com/samcharles93/archie-core/internal/infrastructure/postgres/postgresdb" +) + +var ( + _ access.PolicyStore = (*Store)(nil) + _ access.Resetter = (*Store)(nil) + _ access.DenialStore = (*Store)(nil) +) + +// shippedOrgPolicyIDs lists an org's shipped role policy IDs: the seed's +// conflict keys, and what an org reset keeps. +func shippedOrgPolicyIDs() []string { + ids := make([]string, 0, 4) + for _, p := range access.ShippedOrgPolicies("") { + ids = append(ids, p.ID) + } + return ids +} + +// accessScopeOf is the scope tuple every access query carries. +func accessScopeOf(p access.Policy) (string, string, string, string, string, string) { + return string(p.Level), string(p.OrgID), string(p.WorkspaceID), + string(p.ObjectKind), p.ObjectID, p.ID +} + +// auditKey is the sys_audit record_key for one policy: its scope and ID, so +// an operator can trace one policy document's changes. +func auditKey(p access.Policy) string { + joined := strings.Join([]string{ + string(p.Level), string(p.OrgID), string(p.WorkspaceID), + string(p.ObjectKind), p.ObjectID, p.ID, + }, "/") + return strings.Trim(joined, "/") +} + +// textJSON wraps a policy text as the JSON string sys_audit stores. +func textJSON(text string) []byte { + out, _ := json.Marshal(text) + return out +} + +// ListPolicies returns every stored policy across levels. +func (s *Store) ListPolicies(ctx context.Context) ([]access.Policy, error) { + rows, err := s.queries().ListAccessPolicies(ctx) + if err != nil { + return nil, err + } + out := make([]access.Policy, 0, len(rows)) + for _, r := range rows { + out = append(out, access.Policy{ + ID: r.PolicyID, + Level: access.Level(r.Level), + OrgID: org.OrgID(r.OrgID), + WorkspaceID: org.WorkspaceID(r.WorkspaceID), + ObjectKind: access.ResourceKind(r.ObjectKind), + ObjectID: r.ObjectID, + Text: r.Text, + }) + } + return out, nil +} + +// PutPolicy stores or replaces one policy by its scope+ID key, bumps the +// level's version, and writes the audit row -- in one transaction, so a +// version that never moved cannot advertise a change that half-landed. +func (s *Store) PutPolicy(ctx context.Context, p access.Policy) (int64, error) { + if err := p.Validate(); err != nil { + return 0, err + } + q := s.queries() + level, orgID, wsID, kind, id, policyID := accessScopeOf(p) + var version int64 + err := pgx.BeginFunc(ctx, s.pool, func(tx pgx.Tx) error { + q := q.WithTx(tx) + if err := q.UpsertAccessPolicy(ctx, postgresdb.UpsertAccessPolicyParams{ + Level: level, OrgID: orgID, WorkspaceID: wsID, + ObjectKind: kind, ObjectID: id, + PolicyID: policyID, Text: p.Text, + }); err != nil { + return err + } + v, err := q.UpsertAccessPolicyVersion(ctx, postgresdb.UpsertAccessPolicyVersionParams{ + Level: level, OrgID: orgID, WorkspaceID: wsID, + }) + if err != nil { + return err + } + version = v + return q.InsertAccessPolicyAudit(ctx, postgresdb.InsertAccessPolicyAuditParams{ + RecordKey: auditKey(p), + NewValue: textJSON(p.Text), + RecordVersion: version, + Actor: "archied", + Source: "archied", + RequestID: "", + }) + }) + if err != nil { + return 0, err + } + return version, nil +} + +// DeletePolicy removes one stored policy; an unknown key is +// ErrPolicyNotFound. +func (s *Store) DeletePolicy(ctx context.Context, p access.Policy) error { + if err := p.Validate(); err != nil { + return err + } + level, orgID, wsID, kind, id, policyID := accessScopeOf(p) + deleted, err := s.queries().DeleteAccessPolicy(ctx, postgresdb.DeleteAccessPolicyParams{ + Level: level, OrgID: orgID, WorkspaceID: wsID, + ObjectKind: kind, ObjectID: id, PolicyID: policyID, + }) + if err != nil { + return err + } + if deleted == 0 { + return access.ErrPolicyNotFound + } + if _, err := s.queries().UpsertAccessPolicyVersion(ctx, postgresdb.UpsertAccessPolicyVersionParams{ + Level: level, OrgID: orgID, WorkspaceID: wsID, + }); err != nil { + return err + } + // A level-scope with no policies left keeps no version row. + return s.queries().DeleteAccessPolicyVersion(ctx, postgresdb.DeleteAccessPolicyVersionParams{ + Level: level, OrgID: orgID, WorkspaceID: wsID, + }) +} + +// EnsureShippedOrgPolicies seeds an org's shipped role policies when it +// carries none of them, so a restart never overwrites an edited role policy. +func (s *Store) EnsureShippedOrgPolicies(ctx context.Context, orgID org.OrgID) error { + shipped := access.ShippedOrgPolicies(orgID) + count, err := s.queries().CountShippedOrgPolicies(ctx, postgresdb.CountShippedOrgPoliciesParams{ + OrgID: string(orgID), Column2: shippedOrgPolicyIDs(), + }) + if err != nil { + return err + } + if count > 0 { + return nil + } + for _, p := range shipped { + if _, err := s.PutPolicy(ctx, p); err != nil { + return err + } + } + return nil +} + +// ResetOrgPolicies restores the shipped role policies for one org and +// removes its other org-level policies. It is the store-side half of +// `archied access reset --org`, which runs on this host and records the +// reset as an audit event. +func (s *Store) ResetOrgPolicies(ctx context.Context, orgID org.OrgID) error { + if orgID == "" { + return fmt.Errorf("%w: no org", access.ErrInvalidPolicy) + } + if err := s.queries().DeleteOrgPoliciesNotShipped(ctx, postgresdb.DeleteOrgPoliciesNotShippedParams{ + OrgID: string(orgID), Column2: shippedOrgPolicyIDs(), + }); err != nil { + return err + } + for _, p := range access.ShippedOrgPolicies(orgID) { + if _, err := s.PutPolicy(ctx, p); err != nil { + return err + } + } + return nil +} + +// ResetInstancePolicies removes every stored instance policy. The +// cross-org forbid is engine-enforced and survives any reset. +func (s *Store) ResetInstancePolicies(ctx context.Context) error { + return s.queries().ResetInstancePolicies(ctx) +} + +// RecordDenial records one refusal. The store coalesces identical denials +// within a minute into one row with a count, so a retry storm does not +// flood the surface. +func (s *Store) RecordDenial(ctx context.Context, d access.Denial) error { + if d.Org == "" || d.Principal == "" { + return fmt.Errorf("%w: org and principal are required", access.ErrInvalidPolicy) + } + return s.queries().RecordDenial(ctx, postgresdb.RecordDenialParams{ + OrgID: string(d.Org), Principal: string(d.Principal), Action: string(d.Action), + ResourceKind: string(d.Kind), ResourceID: d.ResourceID, Level: string(d.Level), + Policies: d.Policies, + }) +} + +// ListDenials returns an org's most recent denials, newest first. +func (s *Store) ListDenials(ctx context.Context, orgID org.OrgID, limit int) ([]access.Denial, error) { + rows, err := s.queries().ListDenials(ctx, postgresdb.ListDenialsParams{ + OrgID: string(orgID), Limit: int32(limit), + }) + if err != nil { + return nil, err + } + out := make([]access.Denial, 0, len(rows)) + for _, r := range rows { + out = append(out, access.Denial{ + Principal: identity.IdentityID(r.Principal), + Org: org.OrgID(r.OrgID), + Action: access.Action(r.Action), + Kind: access.ResourceKind(r.ResourceKind), + ResourceID: r.ResourceID, + Level: access.Level(r.Level), + Policies: r.Policies, + At: r.CreatedAt, + Count: r.Count, + }) + } + return out, nil +} diff --git a/internal/infrastructure/postgres/access_test.go b/internal/infrastructure/postgres/access_test.go new file mode 100644 index 000000000..807fceaed --- /dev/null +++ b/internal/infrastructure/postgres/access_test.go @@ -0,0 +1,225 @@ +package postgres + +import ( + "errors" + "testing" + + "github.com/samcharles93/archie-core/internal/domain/access" + "github.com/samcharles93/archie-core/internal/domain/identity" +) + +func newStoreForAccess(t *testing.T) *Store { + t.Helper() + pool, _ := migrated(t) + return New(pool) +} + +func TestAccessPolicyStore(t *testing.T) { + s := newStoreForAccess(t) + ctx := t.Context() + + // PutPolicy stores one policy and reports a versioned level. + p := access.Policy{ + ID: "test-policy", Level: access.LevelOrg, OrgID: "soc", + Text: `permit(principal, action, resource) when { resource.kind == "binding" };`, + } + v1, err := s.PutPolicy(ctx, p) + if err != nil { + t.Fatalf("PutPolicy: %v", err) + } + if v1 != 2 { // the counter starts at 1; the first write bumps it + t.Fatalf("PutPolicy version = %d, want 2", v1) + } + v2, err := s.PutPolicy(ctx, p) + if err != nil { + t.Fatalf("second PutPolicy: %v", err) + } + if v2 <= v1 { + t.Fatalf("second PutPolicy version = %d, want > %d", v2, v1) + } + + // A malformed policy is refused by the store's own structural check. + bad := access.Policy{ID: "bad", Level: access.LevelOrg, OrgID: "soc"} + if _, err := s.PutPolicy(ctx, bad); !errors.Is(err, access.ErrInvalidPolicy) { + t.Fatalf("PutPolicy(structurally invalid) = %v, want ErrInvalidPolicy", err) + } + + // ListPolicies round-trips the scope tuple. + list, err := s.ListPolicies(ctx) + if err != nil { + t.Fatalf("ListPolicies: %v", err) + } + if len(list) != 1 { + t.Fatalf("ListPolicies = %d policies, want 1", len(list)) + } + if list[0].ID != "test-policy" || list[0].OrgID != "soc" { + t.Fatalf("ListPolicies[0] = %+v, want the stored policy", list[0]) + } + + // DeletePolicy removes it and reports an unknown key as a sentinel. + if err := s.DeletePolicy(ctx, p); err != nil { + t.Fatalf("DeletePolicy: %v", err) + } + if err := s.DeletePolicy(ctx, p); !errors.Is(err, access.ErrPolicyNotFound) { + t.Fatalf("second DeletePolicy = %v, want ErrPolicyNotFound", err) + } +} + +func TestEnsureShippedOrgPolicies(t *testing.T) { + s := newStoreForAccess(t) + ctx := t.Context() + + if err := s.EnsureShippedOrgPolicies(ctx, "soc"); err != nil { + t.Fatalf("EnsureShippedOrgPolicies: %v", err) + } + list, err := s.ListPolicies(ctx) + if err != nil { + t.Fatalf("ListPolicies: %v", err) + } + if len(list) != 4 { + t.Fatalf("seeding produced %d policies, want the 4 shipped roles", len(list)) + } + + // An edited role policy survives a re-seed: an org that already carries + // the shipped IDs is left untouched. + edited := list[0] + edited.Text = `permit(principal, action, resource) when { resource.kind == "edited" };` + if _, err := s.PutPolicy(ctx, edited); err != nil { + t.Fatalf("PutPolicy(edit): %v", err) + } + if err := s.EnsureShippedOrgPolicies(ctx, "soc"); err != nil { + t.Fatalf("re-seed: %v", err) + } + after, err := s.ListPolicies(ctx) + if err != nil { + t.Fatalf("ListPolicies after re-seed: %v", err) + } + for _, p := range after { + if p.ID == edited.ID && p.Text != edited.Text { + t.Fatalf("re-seed overwrote an edited role policy %s", p.ID) + } + } +} + +func TestResetPolicies(t *testing.T) { + s := newStoreForAccess(t) + ctx := t.Context() + + if err := s.ResetOrgPolicies(ctx, "soc"); err != nil { + t.Fatalf("ResetOrgPolicies: %v", err) + } + // An operator's custom org policy on top of the shipped set. + custom := access.Policy{ + ID: "org-lockdown", Level: access.LevelOrg, OrgID: "soc", + Text: `forbid(principal, action, resource) when { resource.kind == "source" };`, + } + if _, err := s.PutPolicy(ctx, custom); err != nil { + t.Fatalf("PutPolicy(custom): %v", err) + } + // A workspace policy must survive an org reset. + ws := access.Policy{ + ID: "ws-rule", Level: access.LevelWorkspace, OrgID: "soc", WorkspaceID: "net", + Text: `permit(principal, action, resource) when { resource.kind == "binding" };`, + } + if _, err := s.PutPolicy(ctx, ws); err != nil { + t.Fatalf("PutPolicy(ws): %v", err) + } + // And an instance policy must survive an org reset but not an instance + // reset. + instance := access.Policy{ + ID: "instance-rule", Level: access.LevelInstance, + Text: `forbid(principal, action, resource) when { resource.kind == "secret" };`, + } + if _, err := s.PutPolicy(ctx, instance); err != nil { + t.Fatalf("PutPolicy(instance): %v", err) + } + + if err := s.ResetOrgPolicies(ctx, "soc"); err != nil { + t.Fatalf("org reset: %v", err) + } + after, err := s.ListPolicies(ctx) + if err != nil { + t.Fatalf("ListPolicies: %v", err) + } + orgPolicies := 0 + for _, p := range after { + switch { + case p.Level == access.LevelOrg && p.OrgID == "soc": + orgPolicies++ + case p.Level == access.LevelOrg: + t.Fatalf("org reset touched policy %s of another org", p.ID) + } + } + if orgPolicies != 4 { + t.Fatalf("org-level policies after reset = %d, want the 4 shipped roles", orgPolicies) + } + + if err := s.ResetInstancePolicies(ctx); err != nil { + t.Fatalf("ResetInstancePolicies: %v", err) + } + after, err = s.ListPolicies(ctx) + if err != nil { + t.Fatalf("ListPolicies after instance reset: %v", err) + } + for _, p := range after { + if p.Level == access.LevelInstance { + t.Fatalf("instance reset left policy %s", p.ID) + } + } + if len(after) == 0 { + t.Fatal("instance reset removed non-instance policies") + } +} + +func TestDenialStore(t *testing.T) { + s := newStoreForAccess(t) + ctx := t.Context() + + denial := access.Denial{ + Principal: identity.IdentityID("11111111-1111-5111-8111-111111111111"), + Org: "soc", Action: access.ActionRead, Kind: access.KindBinding, + ResourceID: "b1", Level: access.LevelOrg, + Policies: []string{access.PolicyOrgRead, access.PolicyOrgEdit}, + } + if err := s.RecordDenial(ctx, denial); err != nil { + t.Fatalf("RecordDenial: %v", err) + } + if err := s.RecordDenial(ctx, denial); err != nil { + t.Fatalf("repeat RecordDenial: %v", err) + } + // A different action is a separate row. + other := denial + other.Action = access.ActionDelete + if err := s.RecordDenial(ctx, other); err != nil { + t.Fatalf("RecordDenial(other action): %v", err) + } + + rows, err := s.ListDenials(ctx, "soc", 10) + if err != nil { + t.Fatalf("ListDenials: %v", err) + } + if len(rows) != 2 { + t.Fatalf("ListDenials = %d rows, want 2", len(rows)) + } + if rows[0].Action != access.ActionDelete { + t.Fatalf("newest denial = %v, want the delete denial", rows[0].Action) + } + for _, r := range rows { + if r.Action == access.ActionRead { + if r.Count != 2 { + t.Fatalf("repeated denial count = %d, want 2 (coalesced within the minute)", r.Count) + } + if len(r.Policies) != 2 { + t.Fatalf("denial policies = %v, want the deciding policies", r.Policies) + } + } + } + // Another org sees none of these. + if rows, err := s.ListDenials(ctx, "other", 10); err != nil || len(rows) != 0 { + t.Fatalf("ListDenials(other org) = %d rows %v, want none", len(rows), err) + } + // An org-less denial is refused at the producer. + if err := s.RecordDenial(ctx, access.Denial{Action: access.ActionRead}); err == nil { + t.Fatal("RecordDenial accepted a denial with no org or principal") + } +} diff --git a/internal/infrastructure/postgres/migrations/0016_access_policies.sql b/internal/infrastructure/postgres/migrations/0016_access_policies.sql new file mode 100644 index 000000000..55be2cd45 --- /dev/null +++ b/internal/infrastructure/postgres/migrations/0016_access_policies.sql @@ -0,0 +1,60 @@ +-- Access policies and denial records: the stored half of the policy chain +-- (docs/prds/orgs-and-access.md, "Storing and changing policies" and +-- "Denials"). The shipped cross-org forbid is engine-enforced and has no row +-- here; the shipped role policies are seeded per org as ordinary rows with +-- the shipped IDs, so a reset overwrites them and an edit sticks until reset. +-- +-- The scope tuple (level, org_id, workspace_id, object_kind, object_id) is +-- the policy's place in the chain; policy_id names the document inside it. +-- The version counter is per level-scope: PutPolicy bumps it and returns it, +-- so the engine's next load can detect a change. + +-- +goose Up + +CREATE TABLE access_policies ( + level text NOT NULL CHECK (level IN ('instance', 'org', 'workspace', 'object')), + org_id text NOT NULL DEFAULT '', + workspace_id text NOT NULL DEFAULT '', + object_kind text NOT NULL DEFAULT '', + object_id text NOT NULL DEFAULT '', + policy_id text NOT NULL, + text text NOT NULL, + updated_at timestamptz NOT NULL DEFAULT now(), + PRIMARY KEY (level, org_id, workspace_id, object_kind, object_id, policy_id) +); + +CREATE TABLE access_policy_versions ( + level text NOT NULL CHECK (level IN ('instance', 'org', 'workspace', 'object')), + org_id text NOT NULL DEFAULT '', + workspace_id text NOT NULL DEFAULT '', + version bigint NOT NULL DEFAULT 1, + updated_at timestamptz NOT NULL DEFAULT now(), + PRIMARY KEY (level, org_id, workspace_id) +); + +-- One denial row per (principal, action, resource, level, policies, minute): +-- a retry storm inside one minute is a count bump, not a row flood +-- (docs/prds/orgs-and-access.md, "Audit retention"). +CREATE TABLE access_denials ( + id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY, + org_id text NOT NULL, + principal text NOT NULL, + action text NOT NULL, + resource_kind text NOT NULL, + resource_id text NOT NULL, + level text NOT NULL, + policies text[] NOT NULL DEFAULT '{}', + minute_at timestamptz NOT NULL DEFAULT date_trunc('minute', now()), + count bigint NOT NULL DEFAULT 1, + created_at timestamptz NOT NULL DEFAULT now(), + updated_at timestamptz NOT NULL DEFAULT now() +); +CREATE UNIQUE INDEX idx_access_denials_dedup ON access_denials + (org_id, principal, action, resource_kind, resource_id, level, policies, minute_at); + +-- +goose Down + +DROP INDEX idx_access_denials_dedup; +DROP TABLE access_denials; +DROP TABLE access_policy_versions; +DROP TABLE access_policies; \ No newline at end of file diff --git a/internal/infrastructure/postgres/orgs.go b/internal/infrastructure/postgres/orgs.go index 0bfc91240..c0bfc59ea 100644 --- a/internal/infrastructure/postgres/orgs.go +++ b/internal/infrastructure/postgres/orgs.go @@ -17,6 +17,7 @@ import ( "github.com/jackc/pgx/v5" "github.com/jackc/pgx/v5/pgtype" + "github.com/samcharles93/archie-core/internal/domain/access" "github.com/samcharles93/archie-core/internal/domain/identity" "github.com/samcharles93/archie-core/internal/domain/org" "github.com/samcharles93/archie-core/internal/infrastructure/postgres/postgresdb" @@ -150,6 +151,43 @@ func (s *Store) AssignAgent(ctx context.Context, value org.AgentAssignment) erro }) } +// EnsureAgentOrgMembership grants every agent identity the shipped developer +// role in the org it serves. It runs at the State Store's boot, after the +// default-org upgrade, so dispatch's chain has a principal to evaluate. +// Idempotent: an existing membership (any role) is left alone. +func (s *Store) EnsureAgentOrgMembership(ctx context.Context) error { + return s.queries().EnsureAgentOrgMembership(ctx) +} + +// PrincipalFor assembles the access principal for one identity: the org it +// serves and its memberships (internal/domain/access). An identity in no org +// is the default org with no role, which the shipped role policies never +// permit. +func (s *Store) PrincipalFor(ctx context.Context, id identity.IdentityID) (access.Principal, error) { + resolved, err := s.OrgForIdentity(ctx, id) + if err != nil { + return access.Principal{}, err + } + rows, err := s.queries().ListMembershipsByIdentity(ctx, string(id)) + if err != nil { + return access.Principal{}, err + } + memberships := make([]org.Membership, 0, len(rows)) + for _, r := range rows { + var ws org.WorkspaceID + if r.WorkspaceID.Valid { + ws = org.WorkspaceID(r.WorkspaceID.String) + } + memberships = append(memberships, org.Membership{ + IdentityID: id, + OrgID: org.OrgID(r.OrgID), + WorkspaceID: ws, + Role: org.Role(r.Role), + }) + } + return access.Principal{IdentityID: id, Org: resolved, Memberships: memberships}, nil +} + // OrgForIdentity returns the org an identity serves: the assigned org for an // agent, the org of one of its memberships for a person, and the default org // for an identity in no org. diff --git a/internal/infrastructure/postgres/postgresdb/access.sql.go b/internal/infrastructure/postgres/postgresdb/access.sql.go new file mode 100644 index 000000000..7f7f287d6 --- /dev/null +++ b/internal/infrastructure/postgres/postgresdb/access.sql.go @@ -0,0 +1,328 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.31.1 +// source: access.sql + +package postgresdb + +import ( + "context" +) + +const countShippedOrgPolicies = `-- name: CountShippedOrgPolicies :one +SELECT count(*) FROM access_policies +WHERE level = 'org' AND org_id = $1 AND policy_id = ANY($2::text[]) +` + +type CountShippedOrgPoliciesParams struct { + OrgID string + Column2 []string +} + +// How many of an org's shipped role policies are stored. The seeding runs +// only when the org carries none of them, so a restart never overwrites an +// edited role policy (the shipped IDs are reserved for the shipped text). +func (q *Queries) CountShippedOrgPolicies(ctx context.Context, arg CountShippedOrgPoliciesParams) (int64, error) { + row := q.db.QueryRow(ctx, countShippedOrgPolicies, arg.OrgID, arg.Column2) + var count int64 + err := row.Scan(&count) + return count, err +} + +const deleteAccessPolicy = `-- name: DeleteAccessPolicy :execrows +DELETE FROM access_policies +WHERE level = $1 AND org_id = $2 AND workspace_id = $3 AND object_kind = $4 + AND object_id = $5 AND policy_id = $6 +` + +type DeleteAccessPolicyParams struct { + Level string + OrgID string + WorkspaceID string + ObjectKind string + ObjectID string + PolicyID string +} + +func (q *Queries) DeleteAccessPolicy(ctx context.Context, arg DeleteAccessPolicyParams) (int64, error) { + result, err := q.db.Exec(ctx, deleteAccessPolicy, + arg.Level, + arg.OrgID, + arg.WorkspaceID, + arg.ObjectKind, + arg.ObjectID, + arg.PolicyID, + ) + if err != nil { + return 0, err + } + return result.RowsAffected(), nil +} + +const deleteAccessPolicyVersion = `-- name: DeleteAccessPolicyVersion :exec +DELETE FROM access_policy_versions v +WHERE v.level = $1 AND v.org_id = $2 AND v.workspace_id = $3 + AND NOT EXISTS (SELECT 1 FROM access_policies p + WHERE p.level = v.level AND p.org_id = v.org_id AND p.workspace_id = v.workspace_id) +` + +type DeleteAccessPolicyVersionParams struct { + Level string + OrgID string + WorkspaceID string +} + +// Tidy a level-scope with no policies left: its version row has no reader. +func (q *Queries) DeleteAccessPolicyVersion(ctx context.Context, arg DeleteAccessPolicyVersionParams) error { + _, err := q.db.Exec(ctx, deleteAccessPolicyVersion, arg.Level, arg.OrgID, arg.WorkspaceID) + return err +} + +const deleteOrgPoliciesNotShipped = `-- name: DeleteOrgPoliciesNotShipped :exec +DELETE FROM access_policies +WHERE level = 'org' AND org_id = $1 AND NOT (policy_id = ANY($2::text[])) +` + +type DeleteOrgPoliciesNotShippedParams struct { + OrgID string + Column2 []string +} + +// The org reset's removal half: every org-level policy except the shipped +// role set. +func (q *Queries) DeleteOrgPoliciesNotShipped(ctx context.Context, arg DeleteOrgPoliciesNotShippedParams) error { + _, err := q.db.Exec(ctx, deleteOrgPoliciesNotShipped, arg.OrgID, arg.Column2) + return err +} + +const getAccessPolicy = `-- name: GetAccessPolicy :one +SELECT text FROM access_policies +WHERE level = $1 AND org_id = $2 AND workspace_id = $3 AND object_kind = $4 + AND object_id = $5 AND policy_id = $6 +` + +type GetAccessPolicyParams struct { + Level string + OrgID string + WorkspaceID string + ObjectKind string + ObjectID string + PolicyID string +} + +func (q *Queries) GetAccessPolicy(ctx context.Context, arg GetAccessPolicyParams) (string, error) { + row := q.db.QueryRow(ctx, getAccessPolicy, + arg.Level, + arg.OrgID, + arg.WorkspaceID, + arg.ObjectKind, + arg.ObjectID, + arg.PolicyID, + ) + var text string + err := row.Scan(&text) + return text, err +} + +const insertAccessPolicyAudit = `-- name: InsertAccessPolicyAudit :exec +INSERT INTO sys_audit (at, table_name, record_key, field, old_value, new_value, record_version, actor, source, request_id) +VALUES (now(), 'access_policies', $1, 'text', $2, $3, $4, $5, $6, $7) +` + +type InsertAccessPolicyAuditParams struct { + RecordKey string + OldValue []byte + NewValue []byte + RecordVersion int64 + Actor string + Source string + RequestID string +} + +// One audit row per policy change: the policy's old and new text +// (docs/prds/orgs-and-access.md, "Storing and changing policies"). +func (q *Queries) InsertAccessPolicyAudit(ctx context.Context, arg InsertAccessPolicyAuditParams) error { + _, err := q.db.Exec(ctx, insertAccessPolicyAudit, + arg.RecordKey, + arg.OldValue, + arg.NewValue, + arg.RecordVersion, + arg.Actor, + arg.Source, + arg.RequestID, + ) + return err +} + +const listAccessPolicies = `-- name: ListAccessPolicies :many + +SELECT level, org_id, workspace_id, object_kind, object_id, policy_id, text, updated_at +FROM access_policies ORDER BY level, org_id, workspace_id, object_kind, object_id, policy_id +` + +// Access policies and denial records (internal/domain/access): the durable +// half of the policy-chain contract. Versioning is per level-scope; every +// policy change writes one sys_audit row naming who made it. +func (q *Queries) ListAccessPolicies(ctx context.Context) ([]AccessPolicy, error) { + rows, err := q.db.Query(ctx, listAccessPolicies) + if err != nil { + return nil, err + } + defer rows.Close() + var items []AccessPolicy + for rows.Next() { + var i AccessPolicy + if err := rows.Scan( + &i.Level, + &i.OrgID, + &i.WorkspaceID, + &i.ObjectKind, + &i.ObjectID, + &i.PolicyID, + &i.Text, + &i.UpdatedAt, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const listDenials = `-- name: ListDenials :many +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 +` + +type ListDenialsParams struct { + OrgID string + Limit int32 +} + +func (q *Queries) ListDenials(ctx context.Context, arg ListDenialsParams) ([]AccessDenial, error) { + rows, err := q.db.Query(ctx, listDenials, arg.OrgID, arg.Limit) + if err != nil { + return nil, err + } + defer rows.Close() + var items []AccessDenial + for rows.Next() { + var i AccessDenial + if err := rows.Scan( + &i.ID, + &i.OrgID, + &i.Principal, + &i.Action, + &i.ResourceKind, + &i.ResourceID, + &i.Level, + &i.Policies, + &i.MinuteAt, + &i.Count, + &i.CreatedAt, + &i.UpdatedAt, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, 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) +ON CONFLICT (org_id, principal, action, resource_kind, resource_id, level, policies, minute_at) +DO UPDATE SET count = access_denials.count + 1, updated_at = now() +` + +type RecordDenialParams struct { + OrgID string + Principal string + Action string + ResourceKind string + ResourceID string + Level string + Policies []string +} + +// One row per (principal, action, resource, level, policies, minute); +// a repeat inside the minute bumps the count (docs/prds/orgs-and-access.md, +// "Audit retention"). +func (q *Queries) RecordDenial(ctx context.Context, arg RecordDenialParams) error { + _, err := q.db.Exec(ctx, recordDenial, + arg.OrgID, + arg.Principal, + arg.Action, + arg.ResourceKind, + arg.ResourceID, + arg.Level, + arg.Policies, + ) + return err +} + +const resetInstancePolicies = `-- name: ResetInstancePolicies :exec +DELETE FROM access_policies WHERE level = 'instance' +` + +func (q *Queries) ResetInstancePolicies(ctx context.Context) error { + _, err := q.db.Exec(ctx, resetInstancePolicies) + return err +} + +const upsertAccessPolicy = `-- name: UpsertAccessPolicy :exec +INSERT INTO access_policies (level, org_id, workspace_id, object_kind, object_id, policy_id, text) +VALUES ($1, $2, $3, $4, $5, $6, $7) +ON CONFLICT (level, org_id, workspace_id, object_kind, object_id, policy_id) +DO UPDATE SET text = excluded.text, updated_at = now() +` + +type UpsertAccessPolicyParams struct { + Level string + OrgID string + WorkspaceID string + ObjectKind string + ObjectID string + PolicyID string + Text string +} + +func (q *Queries) UpsertAccessPolicy(ctx context.Context, arg UpsertAccessPolicyParams) error { + _, err := q.db.Exec(ctx, upsertAccessPolicy, + arg.Level, + arg.OrgID, + arg.WorkspaceID, + arg.ObjectKind, + arg.ObjectID, + arg.PolicyID, + arg.Text, + ) + return err +} + +const upsertAccessPolicyVersion = `-- name: UpsertAccessPolicyVersion :one +INSERT INTO access_policy_versions (level, org_id, workspace_id, version) VALUES ($1, $2, $3, 2) +ON CONFLICT (level, org_id, workspace_id) +DO UPDATE SET version = access_policy_versions.version + 1, updated_at = now() +RETURNING version +` + +type UpsertAccessPolicyVersionParams struct { + Level string + OrgID string + WorkspaceID string +} + +func (q *Queries) UpsertAccessPolicyVersion(ctx context.Context, arg UpsertAccessPolicyVersionParams) (int64, error) { + row := q.db.QueryRow(ctx, upsertAccessPolicyVersion, arg.Level, arg.OrgID, arg.WorkspaceID) + var version int64 + err := row.Scan(&version) + return version, err +} diff --git a/internal/infrastructure/postgres/postgresdb/models.go b/internal/infrastructure/postgres/postgresdb/models.go index 06e7999ec..002a7774d 100644 --- a/internal/infrastructure/postgres/postgresdb/models.go +++ b/internal/infrastructure/postgres/postgresdb/models.go @@ -10,6 +10,40 @@ import ( "github.com/jackc/pgx/v5/pgtype" ) +type AccessDenial struct { + ID int64 + OrgID string + Principal string + Action string + ResourceKind string + ResourceID string + Level string + Policies []string + MinuteAt time.Time + Count int64 + CreatedAt time.Time + UpdatedAt time.Time +} + +type AccessPolicy struct { + Level string + OrgID string + WorkspaceID string + ObjectKind string + ObjectID string + PolicyID string + Text string + UpdatedAt time.Time +} + +type AccessPolicyVersion struct { + Level string + OrgID string + WorkspaceID string + Version int64 + UpdatedAt time.Time +} + type ApplyStatus struct { Process string Kind string diff --git a/internal/infrastructure/postgres/postgresdb/orgs.sql.go b/internal/infrastructure/postgres/postgresdb/orgs.sql.go index e1e1cc4ac..f67643b44 100644 --- a/internal/infrastructure/postgres/postgresdb/orgs.sql.go +++ b/internal/infrastructure/postgres/postgresdb/orgs.sql.go @@ -11,6 +11,22 @@ import ( "github.com/jackc/pgx/v5/pgtype" ) +const ensureAgentOrgMembership = `-- name: EnsureAgentOrgMembership :exec +INSERT INTO memberships (identity_id, org_id, role) +SELECT a.identity_id, a.org_id, 'developer' FROM org_agents a +ON CONFLICT (identity_id, org_id, COALESCE(workspace_id, '')) DO NOTHING +` + +// Every agent identity serves its org with the shipped developer role: an +// agent is granted access the way a user is +// (docs/prds/orgs-and-access.md, "Identity"). Idempotent, so an operator's +// later role change survives a restart, and the shipped seed never +// overwrites it. +func (q *Queries) EnsureAgentOrgMembership(ctx context.Context) error { + _, err := q.db.Exec(ctx, ensureAgentOrgMembership) + return err +} + const ensureMembership = `-- name: EnsureMembership :exec INSERT INTO memberships (identity_id, org_id, workspace_id, role) VALUES ($1, $2, $3, $4) diff --git a/internal/infrastructure/postgres/queries/access.sql b/internal/infrastructure/postgres/queries/access.sql new file mode 100644 index 000000000..245921c11 --- /dev/null +++ b/internal/infrastructure/postgres/queries/access.sql @@ -0,0 +1,71 @@ +-- Access policies and denial records (internal/domain/access): the durable +-- half of the policy-chain contract. Versioning is per level-scope; every +-- policy change writes one sys_audit row naming who made it. + +-- name: ListAccessPolicies :many +SELECT level, org_id, workspace_id, object_kind, object_id, policy_id, text, updated_at +FROM access_policies ORDER BY level, org_id, workspace_id, object_kind, object_id, policy_id; + +-- name: UpsertAccessPolicy :exec +INSERT INTO access_policies (level, org_id, workspace_id, object_kind, object_id, policy_id, text) +VALUES ($1, $2, $3, $4, $5, $6, $7) +ON CONFLICT (level, org_id, workspace_id, object_kind, object_id, policy_id) +DO UPDATE SET text = excluded.text, updated_at = now(); + +-- name: GetAccessPolicy :one +SELECT text FROM access_policies +WHERE level = $1 AND org_id = $2 AND workspace_id = $3 AND object_kind = $4 + AND object_id = $5 AND policy_id = $6; + +-- name: DeleteAccessPolicy :execrows +DELETE FROM access_policies +WHERE level = $1 AND org_id = $2 AND workspace_id = $3 AND object_kind = $4 + AND object_id = $5 AND policy_id = $6; + +-- name: CountShippedOrgPolicies :one +-- How many of an org's shipped role policies are stored. The seeding runs +-- only when the org carries none of them, so a restart never overwrites an +-- edited role policy (the shipped IDs are reserved for the shipped text). +SELECT count(*) FROM access_policies +WHERE level = 'org' AND org_id = $1 AND policy_id = ANY($2::text[]); + +-- name: DeleteOrgPoliciesNotShipped :exec +-- The org reset's removal half: every org-level policy except the shipped +-- role set. +DELETE FROM access_policies +WHERE level = 'org' AND org_id = $1 AND NOT (policy_id = ANY($2::text[])); + +-- name: ResetInstancePolicies :exec +DELETE FROM access_policies WHERE level = 'instance'; + +-- name: UpsertAccessPolicyVersion :one +INSERT INTO access_policy_versions (level, org_id, workspace_id, version) VALUES ($1, $2, $3, 2) +ON CONFLICT (level, org_id, workspace_id) +DO UPDATE SET version = access_policy_versions.version + 1, updated_at = now() +RETURNING version; + +-- name: DeleteAccessPolicyVersion :exec +-- Tidy a level-scope with no policies left: its version row has no reader. +DELETE FROM access_policy_versions v +WHERE v.level = $1 AND v.org_id = $2 AND v.workspace_id = $3 + AND NOT EXISTS (SELECT 1 FROM access_policies p + WHERE p.level = v.level AND p.org_id = v.org_id AND p.workspace_id = v.workspace_id); + +-- name: InsertAccessPolicyAudit :exec +-- One audit row per policy change: the policy's old and new text +-- (docs/prds/orgs-and-access.md, "Storing and changing policies"). +INSERT INTO sys_audit (at, table_name, record_key, field, old_value, new_value, record_version, actor, source, request_id) +VALUES (now(), 'access_policies', $1, 'text', $2, $3, $4, $5, $6, $7); + +-- name: RecordDenial :exec +-- One row per (principal, action, resource, level, policies, minute); +-- a repeat inside the minute bumps the count (docs/prds/orgs-and-access.md, +-- "Audit retention"). +INSERT INTO access_denials (org_id, principal, action, resource_kind, resource_id, level, policies) +VALUES ($1, $2, $3, $4, $5, $6, $7) +ON CONFLICT (org_id, principal, action, resource_kind, resource_id, level, policies, minute_at) +DO UPDATE SET count = access_denials.count + 1, updated_at = now(); + +-- name: ListDenials :many +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; \ No newline at end of file diff --git a/internal/infrastructure/postgres/queries/orgs.sql b/internal/infrastructure/postgres/queries/orgs.sql index 6665de881..42bc601d8 100644 --- a/internal/infrastructure/postgres/queries/orgs.sql +++ b/internal/infrastructure/postgres/queries/orgs.sql @@ -40,4 +40,13 @@ SELECT COALESCE( (SELECT m.org_id FROM memberships m WHERE m.identity_id = $1 ORDER BY m.created_at, m.org_id, m.workspace_id NULLS LAST LIMIT 1), 'default' -)::text AS org_id; \ No newline at end of file +)::text AS org_id; +-- name: EnsureAgentOrgMembership :exec +-- Every agent identity serves its org with the shipped developer role: an +-- agent is granted access the way a user is +-- (docs/prds/orgs-and-access.md, "Identity"). Idempotent, so an operator's +-- later role change survives a restart, and the shipped seed never +-- overwrites it. +INSERT INTO memberships (identity_id, org_id, role) +SELECT a.identity_id, a.org_id, 'developer' FROM org_agents a +ON CONFLICT (identity_id, org_id, COALESCE(workspace_id, '')) DO NOTHING; diff --git a/internal/infrastructure/staterpc/access.go b/internal/infrastructure/staterpc/access.go new file mode 100644 index 000000000..d8c3edec8 --- /dev/null +++ b/internal/infrastructure/staterpc/access.go @@ -0,0 +1,177 @@ +// Access: the policy-chain and denial-record RPCs (docs/prds/orgs-and-access.md). +// The policies surface is the engine's snapshot plus the administrative +// writes; the denials surface is the two callers' write path and the +// operator's read. +package staterpc + +import ( + "context" + "errors" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + pb "github.com/samcharles93/archie-core/internal/contracts/state/v1" + "github.com/samcharles93/archie-core/internal/domain/access" + "github.com/samcharles93/archie-core/internal/domain/identity" + "github.com/samcharles93/archie-core/internal/domain/org" +) + +var ( + errPoliciesUnavailable = status.Error(codes.Unavailable, "access policy store unavailable") + errDenialsUnavailable = status.Error(codes.Unavailable, "access denial store unavailable") +) + +func accessPolicyProto(p access.Policy) *pb.AccessPolicy { + return &pb.AccessPolicy{ + PolicyId: p.ID, Level: string(p.Level), OrgId: string(p.OrgID), + WorkspaceId: string(p.WorkspaceID), ObjectKind: string(p.ObjectKind), + ObjectId: p.ObjectID, Text: p.Text, + } +} + +func accessPolicyValue(p *pb.AccessPolicy) access.Policy { + return access.Policy{ + ID: p.GetPolicyId(), Level: access.Level(p.GetLevel()), + OrgID: org.OrgID(p.GetOrgId()), WorkspaceID: org.WorkspaceID(p.GetWorkspaceId()), + ObjectKind: access.ResourceKind(p.GetObjectKind()), ObjectID: p.GetObjectId(), + Text: p.GetText(), + } +} + +func accessDenialProto(d access.Denial) *pb.AccessDenial { + out := &pb.AccessDenial{ + OrgId: string(d.Org), Principal: string(d.Principal), Action: string(d.Action), + ResourceKind: string(d.Kind), ResourceId: d.ResourceID, Level: string(d.Level), + Policies: d.Policies, Count: d.Count, + } + if !d.At.IsZero() { + out.At = timestamp(d.At) + } + return out +} + +func accessDenialValue(d *pb.AccessDenial) access.Denial { + value := access.Denial{ + Org: org.OrgID(d.GetOrgId()), + Principal: identity.IdentityID(d.GetPrincipal()), + Action: access.Action(d.GetAction()), + Kind: access.ResourceKind(d.GetResourceKind()), + ResourceID: d.GetResourceId(), + Level: access.Level(d.GetLevel()), + Policies: d.GetPolicies(), + Count: d.GetCount(), + } + if d.GetAt() != nil { + value.At = d.GetAt().AsTime() + } + return value +} + +func (s *server) GetPrincipal(ctx context.Context, request *pb.GetPrincipalRequest) (*pb.GetPrincipalResponse, error) { + if s.deps.Principals == nil { + return nil, status.Error(codes.Unavailable, "identity store unavailable") + } + value, err := s.deps.Principals.PrincipalFor(ctx, identity.IdentityID(request.IdentityId)) + if err != nil { + return nil, identityStatus(err) + } + memberships := make([]*pb.PrincipalMembership, len(value.Memberships)) + for i := range value.Memberships { + m := value.Memberships[i] + memberships[i] = &pb.PrincipalMembership{ + OrgId: string(m.OrgID), WorkspaceId: string(m.WorkspaceID), Role: string(m.Role), + } + } + return &pb.GetPrincipalResponse{Principal: &pb.AccessPrincipal{ + IdentityId: string(value.IdentityID), + OrgId: string(value.Org), + Memberships: memberships, + }}, nil +} + +func (s *server) ListPolicies(ctx context.Context, _ *pb.ListPoliciesRequest) (*pb.ListPoliciesResponse, error) { + if s.deps.Policies == nil { + return nil, errPoliciesUnavailable + } + values, err := s.deps.Policies.ListPolicies(ctx) + if err != nil { + return nil, accessStatus(err) + } + out := make([]*pb.AccessPolicy, len(values)) + for i := range values { + out[i] = accessPolicyProto(values[i]) + } + return &pb.ListPoliciesResponse{Policies: out}, nil +} + +func (s *server) PutPolicy(ctx context.Context, request *pb.PutPolicyRequest) (*pb.PutPolicyResponse, error) { + if s.deps.Policies == nil { + return nil, errPoliciesUnavailable + } + version, err := s.deps.Policies.PutPolicy(ctx, accessPolicyValue(request.Policy)) + if err != nil { + return nil, accessStatus(err) + } + return &pb.PutPolicyResponse{Version: version}, nil +} + +func (s *server) DeletePolicy(ctx context.Context, request *pb.DeletePolicyRequest) (*pb.DeletePolicyResponse, error) { + if s.deps.Policies == nil { + return nil, errPoliciesUnavailable + } + if err := s.deps.Policies.DeletePolicy(ctx, accessPolicyValue(request.Policy)); err != nil { + return nil, accessStatus(err) + } + return &pb.DeletePolicyResponse{}, nil +} + +func (s *server) EnsureShippedOrgPolicies(ctx context.Context, request *pb.EnsureShippedOrgPoliciesRequest) (*pb.EnsureShippedOrgPoliciesResponse, error) { + if s.deps.Policies == nil { + return nil, errPoliciesUnavailable + } + if err := s.deps.Policies.EnsureShippedOrgPolicies(ctx, org.OrgID(request.OrgId)); err != nil { + return nil, accessStatus(err) + } + return &pb.EnsureShippedOrgPoliciesResponse{}, nil +} + +func (s *server) RecordDenial(ctx context.Context, request *pb.RecordDenialRequest) (*pb.RecordDenialResponse, error) { + if s.deps.Denials == nil { + return nil, errDenialsUnavailable + } + if err := s.deps.Denials.RecordDenial(ctx, accessDenialValue(request.Denial)); err != nil { + return nil, accessStatus(err) + } + return &pb.RecordDenialResponse{}, nil +} + +func (s *server) ListDenials(ctx context.Context, request *pb.ListDenialsRequest) (*pb.ListDenialsResponse, error) { + if s.deps.Denials == nil { + return nil, errDenialsUnavailable + } + limit := int(request.GetLimit()) + if limit <= 0 || limit > 1000 { + limit = 100 + } + values, err := s.deps.Denials.ListDenials(ctx, org.OrgID(request.OrgId), limit) + if err != nil { + return nil, accessStatus(err) + } + out := make([]*pb.AccessDenial, len(values)) + for i := range values { + out[i] = accessDenialProto(values[i]) + } + return &pb.ListDenialsResponse{Denials: out}, nil +} + +// accessStatus maps an access sentinel to its gRPC status. +func accessStatus(err error) error { + if errors.Is(err, access.ErrPolicyNotFound) { + return status.Error(codes.NotFound, access.ErrPolicyNotFound.Error()) + } + if errors.Is(err, access.ErrInvalidPolicy) { + return status.Error(codes.InvalidArgument, access.ErrInvalidPolicy.Error()) + } + return mapError(err) +} diff --git a/internal/infrastructure/staterpc/access_client.go b/internal/infrastructure/staterpc/access_client.go new file mode 100644 index 000000000..a6fa18d43 --- /dev/null +++ b/internal/infrastructure/staterpc/access_client.go @@ -0,0 +1,90 @@ +// Access: the client half of the policy-chain and denial-record RPCs +// (docs/prds/orgs-and-access.md). The reset surface is deliberately absent: +// `archied access reset` runs on the State Store host, never over the wire. +package staterpc + +import ( + "context" + + pb "github.com/samcharles93/archie-core/internal/contracts/state/v1" + "github.com/samcharles93/archie-core/internal/domain/access" + "github.com/samcharles93/archie-core/internal/domain/identity" + "github.com/samcharles93/archie-core/internal/domain/org" +) + +// The Client satisfies the access contracts the two callers depend on. +var ( + _ access.PolicyStore = (*Client)(nil) + _ access.DenialStore = (*Client)(nil) + _ access.PrincipalSource = (*Client)(nil) +) + +func (c *Client) PrincipalFor(ctx context.Context, id identity.IdentityID) (access.Principal, error) { + r, err := c.client.GetPrincipal(ctx, &pb.GetPrincipalRequest{IdentityId: string(id)}) + if err != nil { + return access.Principal{}, unmapError(err) + } + value := r.GetPrincipal() + memberships := make([]org.Membership, len(value.GetMemberships())) + for i := range value.GetMemberships() { + m := value.GetMemberships()[i] + memberships[i] = org.Membership{ + IdentityID: id, + OrgID: org.OrgID(m.GetOrgId()), + WorkspaceID: org.WorkspaceID(m.GetWorkspaceId()), + Role: org.Role(m.GetRole()), + } + } + return access.Principal{ + IdentityID: identity.IdentityID(value.GetIdentityId()), + Org: org.OrgID(value.GetOrgId()), + Memberships: memberships, + }, nil +} + +func (c *Client) ListPolicies(ctx context.Context) ([]access.Policy, error) { + r, err := c.client.ListPolicies(ctx, &pb.ListPoliciesRequest{}) + if err != nil { + return nil, unmapError(err) + } + out := make([]access.Policy, len(r.Policies)) + for i := range r.Policies { + out[i] = accessPolicyValue(r.Policies[i]) + } + return out, nil +} + +func (c *Client) PutPolicy(ctx context.Context, p access.Policy) (int64, error) { + r, err := c.client.PutPolicy(ctx, &pb.PutPolicyRequest{Policy: accessPolicyProto(p)}) + if err != nil { + return 0, unmapError(err) + } + return r.Version, nil +} + +func (c *Client) DeletePolicy(ctx context.Context, p access.Policy) error { + _, err := c.client.DeletePolicy(ctx, &pb.DeletePolicyRequest{Policy: accessPolicyProto(p)}) + return unmapError(err) +} + +func (c *Client) EnsureShippedOrgPolicies(ctx context.Context, orgID org.OrgID) error { + _, err := c.client.EnsureShippedOrgPolicies(ctx, &pb.EnsureShippedOrgPoliciesRequest{OrgId: string(orgID)}) + return unmapError(err) +} + +func (c *Client) RecordDenial(ctx context.Context, d access.Denial) error { + _, err := c.client.RecordDenial(ctx, &pb.RecordDenialRequest{Denial: accessDenialProto(d)}) + return unmapError(err) +} + +func (c *Client) ListDenials(ctx context.Context, orgID org.OrgID, limit int) ([]access.Denial, error) { + r, err := c.client.ListDenials(ctx, &pb.ListDenialsRequest{OrgId: string(orgID), Limit: int32(limit)}) + if err != nil { + return nil, unmapError(err) + } + out := make([]access.Denial, len(r.Denials)) + for i := range r.Denials { + out[i] = accessDenialValue(r.Denials[i]) + } + return out, nil +} diff --git a/internal/infrastructure/staterpc/server.go b/internal/infrastructure/staterpc/server.go index cb3a76bb6..5b71e72be 100644 --- a/internal/infrastructure/staterpc/server.go +++ b/internal/infrastructure/staterpc/server.go @@ -17,6 +17,7 @@ import ( controlpb "github.com/samcharles93/archie-core/internal/contracts/controlplane/v1" pb "github.com/samcharles93/archie-core/internal/contracts/state/v1" + "github.com/samcharles93/archie-core/internal/domain/access" "github.com/samcharles93/archie-core/internal/domain/binding" "github.com/samcharles93/archie-core/internal/domain/identity" "github.com/samcharles93/archie-core/internal/domain/mapping" @@ -99,6 +100,18 @@ type Deps struct { // (docs/prds/eda-playbook-engine.md gap 2). Optional: nil disables the // two playbook dispatch RPCs with codes.Unavailable. PlaybookDispatcher storecontract.PlaybookDispatcher + // Principals assembles the access principal for one identity: the org it + // serves and its memberships. Optional: nil answers GetPrincipal with + // codes.Unavailable. + Principals access.PrincipalSource + // Policies is the stored policy chain (docs/prds/orgs-and-access.md). + // Optional: nil answers the access RPCs with codes.Unavailable. The reset + // surface is deliberately not an RPC: `archied access reset` runs on the + // State Store host, never over the network. + Policies access.PolicyStore + // Denials records and lists denial records. Optional: nil disables the + // pair with codes.Unavailable. + Denials access.DenialStore // TaskLogs reads one task attempt's persisted log out of the state // directory this process owns. Optional, and nil is the honest default for // a store service that shares no state directory with the daemon: diff --git a/proto/state/v1/state.proto b/proto/state/v1/state.proto index 48fb14798..2db3d049d 100644 --- a/proto/state/v1/state.proto +++ b/proto/state/v1/state.proto @@ -165,6 +165,20 @@ service StateStoreService { // relation server-side, so the grant only names the caller. rpc EnqueueCallTask(EnqueueCallTaskRequest) returns (EnqueueCallTaskResponse); rpc WorkflowCallStatus(WorkflowCallStatusRequest) returns (WorkflowCallStatusResponse); + + // Access: the stored policy chain and its denial records + // (docs/prds/orgs-and-access.md). ListPolicies is the engine's snapshot; + // the writes are administrative. RecordDenial is the dashboard's and + // dispatch's write path; ListDenials is the operator surface. + // The principal assembly the Authorizer evaluates: an identity, the org + // it serves, and its memberships (internal/domain/access). + rpc GetPrincipal(GetPrincipalRequest) returns (GetPrincipalResponse); + rpc ListPolicies(ListPoliciesRequest) returns (ListPoliciesResponse); + rpc PutPolicy(PutPolicyRequest) returns (PutPolicyResponse); + rpc DeletePolicy(DeletePolicyRequest) returns (DeletePolicyResponse); + rpc EnsureShippedOrgPolicies(EnsureShippedOrgPoliciesRequest) returns (EnsureShippedOrgPoliciesResponse); + rpc RecordDenial(RecordDenialRequest) returns (RecordDenialResponse); + rpc ListDenials(ListDenialsRequest) returns (ListDenialsResponse); } message RegisterTaskGrantRequest { @@ -923,3 +937,56 @@ message RemoveInstalledPackageRequest { string org_id = 1; string name = 2; } message RemoveInstalledPackageResponse {} // Task mirrors internal/domain/workflow.Task. + +message GetPrincipalRequest { string identity_id = 1; } +// PrincipalMembership mirrors org.Membership: an identity's role in an org, +// or in one workspace of it. +message PrincipalMembership { + string org_id = 1; + string workspace_id = 2; + string role = 3; +} +message AccessPrincipal { + string identity_id = 1; + string org_id = 2; + repeated PrincipalMembership memberships = 3; +} +message GetPrincipalResponse { AccessPrincipal principal = 1; } + +// AccessPolicy mirrors internal/domain/access.Policy: one Cedar policy +// document and the level-scope tuple that places it in the chain. +message AccessPolicy { + string policy_id = 1; + string level = 2; + string org_id = 3; + string workspace_id = 4; + string object_kind = 5; + string object_id = 6; + string text = 7; +} +message ListPoliciesRequest {} +message ListPoliciesResponse { repeated AccessPolicy policies = 1; } +message PutPolicyRequest { AccessPolicy policy = 1; } +message PutPolicyResponse { int64 version = 1; } +message DeletePolicyRequest { AccessPolicy policy = 1; } +message DeletePolicyResponse {} +message EnsureShippedOrgPoliciesRequest { string org_id = 1; } +message EnsureShippedOrgPoliciesResponse {} +// AccessDenial mirrors internal/domain/access.Denial: one refusal with the +// level that decided it and the deciding policies. The store coalesces +// identical denials within a minute into one row with a count. +message AccessDenial { + string org_id = 1; + string principal = 2; + string action = 3; + string resource_kind = 4; + string resource_id = 5; + string level = 6; + repeated string policies = 7; + int64 count = 8; + google.protobuf.Timestamp at = 9; +} +message RecordDenialRequest { AccessDenial denial = 1; } +message RecordDenialResponse {} +message ListDenialsRequest { string org_id = 1; int32 limit = 2; } +message ListDenialsResponse { repeated AccessDenial denials = 1; }