Relocate agent-run authorization to its package

The agent-run actions and policies lived in the core probo policy set,
which forced every authorization change for the agent-run domain to
touch unrelated core files. Move the actions and the OWNER/ADMIN and
VIEWER/AUDITOR policies into the agentrun package and have it expose a
PolicySet that probod registers into the authorizer at composition
time, so the rules live alongside the domain logic they govern.

Signed-off-by: Bryan Frimin <bryan@probo.com>
This commit is contained in:
Bryan Frimin
2026-06-08 14:50:23 +02:00
parent f5a73c7be1
commit 98a8d90391
7 changed files with 84 additions and 8 deletions

23
pkg/agentrun/actions.go Normal file
View File

@@ -0,0 +1,23 @@
// Copyright (c) 2026 Probo Inc <hello@getprobo.com>.
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
package agentrun
// Agent run service actions.
// Format: agent:run:<action>
const (
ActionAgentRunGet = "agent:run:get"
ActionAgentRunList = "agent:run:list"
ActionAgentRunApprove = "agent:run:approve"
)

56
pkg/agentrun/policies.go Normal file
View File

@@ -0,0 +1,56 @@
// Copyright (c) 2026 Probo Inc <hello@getprobo.com>.
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
package agentrun
import (
"go.probo.inc/probo/pkg/iam"
"go.probo.inc/probo/pkg/iam/policy"
)
var organizationCondition = policy.Equals("principal.organization_id", "resource.organization_id")
// FullAccessPolicy grants complete agent-run access, including approval
// decisions, to organization owners and admins.
var FullAccessPolicy = policy.NewPolicy(
"agentrun:full-access",
"Agent Run Full Access",
policy.Allow(
ActionAgentRunGet,
ActionAgentRunList,
ActionAgentRunApprove,
).WithSID("agent-run-full-access").When(organizationCondition),
).WithDescription("Full agent-run access including approval decisions")
// ReadAccessPolicy grants read-only agent-run access to viewers and auditors.
var ReadAccessPolicy = policy.NewPolicy(
"agentrun:read-access",
"Agent Run Read Access",
policy.Allow(
ActionAgentRunGet,
ActionAgentRunList,
).WithSID("agent-run-read-access").When(organizationCondition),
).WithDescription("Read-only agent-run access")
// PolicySet returns the PolicySet for the agent-run service. It is owned by
// this package and registered into the authorizer at composition time so the
// agent-run authorization rules live alongside the agent-run domain logic
// instead of in the core probo policy set.
func PolicySet() *iam.PolicySet {
return iam.NewPolicySet().
AddRolePolicy("OWNER", FullAccessPolicy).
AddRolePolicy("ADMIN", FullAccessPolicy).
AddRolePolicy("VIEWER", ReadAccessPolicy).
AddRolePolicy("AUDITOR", ReadAccessPolicy)
}

View File

@@ -133,10 +133,6 @@ const (
ActionThirdPartyRiskAssessmentCreate = "core:thirdParty-risk-assessment:create"
ActionThirdPartyRiskAssessmentList = "core:thirdParty-risk-assessment:list"
// AgentRun actions
ActionAgentRunGet = "core:agent-run:get"
ActionAgentRunList = "core:agent-run:list"
// Framework actions
ActionFrameworkGet = "core:framework:get"
ActionFrameworkList = "core:framework:list"

View File

@@ -56,7 +56,6 @@ var ViewerPolicy = policy.NewPolicy(
ActionThirdPartyDataPrivacyAgreementGet,
ActionThirdPartyRiskAssessmentList,
ActionThirdPartyRelationList,
ActionAgentRunGet, ActionAgentRunList,
ActionFrameworkGet, ActionFrameworkList,
ActionControlGet, ActionControlList,
ActionMeasureGet, ActionMeasureList,
@@ -145,7 +144,6 @@ var AuditorPolicy = policy.NewPolicy(
ActionThirdPartyDataPrivacyAgreementGet,
ActionThirdPartyRiskAssessmentList,
ActionThirdPartyRelationList,
ActionAgentRunGet, ActionAgentRunList,
ActionFrameworkGet, ActionFrameworkList,
ActionControlGet, ActionControlList,
ActionMeasureGet, ActionMeasureList,

View File

@@ -595,6 +595,7 @@ func (impl *Implm) Run(
)
agentRunService := agentrun.NewService(pgClient)
iamService.Authorizer.RegisterPolicySet(agentrun.PolicySet())
thirdPartyService := thirdparty.NewService(pgClient, fileService, thirdPartyVetter)
riskManagementService := riskmanagement.NewService(pgClient)

View File

@@ -11,6 +11,7 @@ import (
"fmt"
"go.gearno.de/kit/log"
"go.probo.inc/probo/pkg/agentrun"
"go.probo.inc/probo/pkg/coredata"
"go.probo.inc/probo/pkg/gid"
"go.probo.inc/probo/pkg/iam"
@@ -370,7 +371,7 @@ func (r *queryResolver) Node(ctx context.Context, id gid.GID) (types.Node, error
return types.NewWebhookSubscription(wc), nil
}
case coredata.AgentRunEntityType:
action = probo.ActionAgentRunGet
action = agentrun.ActionAgentRunGet
loadNode = func(ctx context.Context, scope *coredata.Scope, id gid.GID) (types.Node, error) {
run, err := r.agentRun.Get(ctx, scope, id)
if err != nil {

View File

@@ -12,6 +12,7 @@ import (
"time"
"go.gearno.de/kit/log"
"go.probo.inc/probo/pkg/agentrun"
"go.probo.inc/probo/pkg/coredata"
"go.probo.inc/probo/pkg/gid"
"go.probo.inc/probo/pkg/iam"
@@ -1175,7 +1176,7 @@ func (r *organizationResolver) Tasks(ctx context.Context, obj *types.Organizatio
// AgentRuns is the resolver for the agentRuns field.
func (r *organizationResolver) AgentRuns(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.AgentRunOrderBy) (*types.AgentRunConnection, error) {
scope, err := r.authorize(ctx, obj.ID, probo.ActionAgentRunList)
scope, err := r.authorize(ctx, obj.ID, agentrun.ActionAgentRunList)
if err != nil {
return nil, err
}