fix(controlplane): instance settings are written by the system org only
Issue: archie-core-f5zso
This commit is contained in:
2 files changed
+40
-1
No files matched your search
@@ -0,0 +1,27 @@
|
||||
package controlplane
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/storecontract"
|
||||
)
|
||||
|
||||
func TestInstanceOnlyKindsRefuseOtherOrgs(t *testing.T) {
|
||||
tests := []struct {
|
||||
name, org, kind string
|
||||
refused bool
|
||||
}{
|
||||
{"another org writes an instance setting", "acme", ToolSettingsKind, true},
|
||||
{"the system org writes an instance setting", storecontract.DefaultOrgID, ToolSettingsKind, false},
|
||||
{"another org writes an org-scoped kind", "acme", PersonasKind, false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
err := (&Server{}).checkOrgWrite(t.Context(), tt.org, tt.kind, []byte(`{}`))
|
||||
if refused := errors.Is(err, ErrValidation); refused != tt.refused {
|
||||
t.Fatalf("refused = %v, want %v (err %v)", refused, tt.refused, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -152,11 +152,23 @@ func (s *Server) readResource(ctx context.Context, orgID, kind string, into any)
|
||||
return nil
|
||||
}
|
||||
|
||||
// instanceOnlyKinds are the kinds the runtime layers from the system org's
|
||||
// copy alone. Another org's write would be stored and never applied.
|
||||
var instanceOnlyKinds = map[string]bool{
|
||||
RepositoryPoliciesKind: true, ChannelSettingsKind: true, SchedulingPolicyKind: true,
|
||||
ReviewSettingsKind: true, TaskPolicyKind: true, ToolSettingsKind: true,
|
||||
PluginSettingsKind: true, ContainerRuntimePoliciesKind: true, AgentProfileKind: true,
|
||||
ExtensionSettingsKind: true, UpdateSettingsKind: true, WorkflowExecutionSettingsKind: true,
|
||||
}
|
||||
|
||||
// checkOrgWrite applies the rules a resource's static validation cannot: the
|
||||
// policy is the system org's alone, an org's providers need its policy's
|
||||
// leave and its own credentials, and every alias must name a model the
|
||||
// writing org may use.
|
||||
// writing org may use. Instance settings are refused from any other org.
|
||||
func (s *Server) checkOrgWrite(ctx context.Context, orgID, kind string, value []byte) error {
|
||||
if instanceOnlyKinds[kind] && orgID != storecontract.DefaultOrgID {
|
||||
return fmt.Errorf("%w: %s is an instance setting and only the system org writes it", ErrValidation, kind)
|
||||
}
|
||||
switch kind {
|
||||
case OrgModelPolicyKind:
|
||||
if orgID != storecontract.DefaultOrgID {
|
||||
|
||||
Reference in new issue
Block a user