Skip to content

add AgentRuntimePolicy CR - #4016

Merged
zreigz merged 6 commits into
masterfrom
lukasz/prod-5137-add-agentruntimepolicy-cr
Aug 19, 2026
Merged

add AgentRuntimePolicy CR#4016
zreigz merged 6 commits into
masterfrom
lukasz/prod-5137-add-agentruntimepolicy-cr

Conversation

@zreigz

@zreigz zreigz commented Aug 17, 2026

Copy link
Copy Markdown
Member

Test Plan

Test environment: https://console.plrl-dev-aws.onplural.sh

Checklist

  • I have added a meaningful title and summary to convey the impact of this PR to a user.
  • If required, I have updated the Plural documentation accordingly.
  • I have added tests to cover my changes.
  • I have deployed the agent to a test environment and verified that it works as expected (required only when changing agent code).

Plural Flow: console

@linear

linear Bot commented Aug 17, 2026

Copy link
Copy Markdown

PROD-5137

@soffi-ai

soffi-ai Bot commented Aug 17, 2026

Copy link
Copy Markdown
Soffi AI Summary

This PR introduces a new AgentRuntimePolicy Custom Resource Definition (CRD) to the Plural Console Kubernetes operator, enabling centralized access control over who can create agent runs on an AgentRuntime. The core motivation is a security concern: if target clusters could set their own bindings, cluster operators could potentially grant themselves unauthorized access (e.g., clone/PR privileges) against any repository reachable by the runtime's SCM credentials. By enforcing that bindings are managed exclusively from the management cluster, this attack vector is eliminated.

The implementation spans the full controller stack:

  • CRD type definition (agentruntimepolicy_types.go) declaring the spec (runtime name, cluster ref, access bindings, reconciliation settings) and status fields.
  • Reconciler (agentruntimepolicy_controller.go) wiring the CR into the Console GraphQL API via an upsert operation, with drift detection and configurable reconciliation intervals.
  • GraphQL client method (internal/client/agentruntime.go) for upserting agent runtime policies via the Console API.
  • Generated CRD manifests (in both charts/controller/crds/ and go/controller/config/crd/bases/) and deepcopy boilerplate.
  • RBAC role update granting the controller the required permissions.
  • Unit tests and a sample CR manifest for documentation and validation.
  • Helm chart bundle updates rolling in the new controller version (0.0.205).

Commits

Commit Summary
ba3c154 Introduces the AgentRuntimePolicy CRD type, reconciler, GraphQL client method, generated manifests, RBAC rules, and controller registration — the core of the new access-control resource.
e8544cb Adds API reference documentation for AgentRuntimePolicy to docs/api.md.
94165e2 Fixes the upsert logic for agent runtime policies in the Console GraphQL client to handle edge cases correctly.
c9859d3 Extends the CRD spec with an optional cluster/clusterRef field, enabling the policy to target a specific managed cluster rather than applying globally.
64ad341 General cleanup: removes dead code, tidies imports, and simplifies the reconciler implementation.
e4511bb Fixes golangci-lint violations introduced by the new controller code.

Updated: 2026-08-19 08:43 UTC

Deploy in Soffi

@zreigz zreigz added the enhancement New feature or request label Aug 17, 2026
@greptile-apps

greptile-apps Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR introduces a cluster-scoped AgentRuntimePolicy CRD and controller that applies centrally managed create bindings to management-cluster agent runtimes.

  • Adds the CRD schema, generated deepcopy code, RBAC, sample manifest, and packaged chart artifacts.
  • Registers a reconciler that resolves the management runtime and updates its Console-side create bindings.
  • Adds the Console client method, mock support, and controller tests for initial synchronization and missing runtimes.

Confidence Score: 2/5

The PR is not safe to merge until Console-side policy drift is restored reliably and every binding form accepted by the CRD is either supported or rejected.

The controller can report a policy synchronized while out-of-band create permissions remain active, and accepted ID-based binding inputs are discarded before the Console update.

Files Needing Attention: go/controller/internal/controller/agentruntimepolicy_controller.go, go/controller/api/v1alpha1/agentruntimepolicy_types.go

Security Review

The policy does not detect Console-side binding drift after its initial synchronization, allowing unauthorized create access added out of band to persist despite periodic reconciliation.

Important Files Changed

Filename Overview
go/controller/internal/controller/agentruntimepolicy_controller.go Adds the core reconciliation flow, but misses external binding drift and silently drops ID-based binding identities.
go/controller/api/v1alpha1/agentruntimepolicy_types.go Defines the new cluster-scoped policy and spec hashing; using the broad shared Binding type exposes identity forms the reconciler cannot apply.
go/controller/internal/client/agentruntime.go Adds the typed upsert wrapper; unrelated omitted runtime attributes are preserved by the Console update implementation.
go/controller/internal/controller/agentruntimepolicy_controller_test.go Covers initial synchronization and missing runtimes but not out-of-band binding drift or ID-based bindings.
charts/controller/crds/deployments.plural.sh_agentruntimepolicies.yaml Packages the new CRD schema, including the shared binding fields that are not all supported by reconciliation.
go/controller/config/rbac/role.yaml Adds the expected resource, status, and finalizer permissions for the new CRD.

Reviews (1): Last reviewed commit: "add AgentRuntimePolicy CR" | Re-trigger Greptile

Comment thread go/controller/internal/controller/agentruntimepolicy_controller.go
Comment thread go/controller/internal/controller/agentruntimepolicy_controller.go
// Runtime is the name of the AgentRuntime this policy applies to.
// Defaults to metadata.name if not specified.
// +kubebuilder:validation:Optional
Runtime *string `json:"runtime,omitempty"`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is the cluster specified here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added this

}

func (in *AgentRuntimePolicyReconciler) getAgentRuntime(ctx context.Context, runtimeName string) (*console.AgentRuntimeFragment, string, *ctrl.Result, error) {
cluster, err := in.ConsoleClient.GetClusterByHandle(lo.ToPtr(managementClusterHandle))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldn't assume this is on the management cluster, it should be in the agent runtime policy spec.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@zreigz

zreigz commented Aug 18, 2026

Copy link
Copy Markdown
Member Author

@michaeljguarino PTAL

@michaeljguarino michaeljguarino left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm but ideally we resolve the failing gh actions

@zreigz
zreigz merged commit b25ed06 into master Aug 19, 2026
27 checks passed
@zreigz
zreigz deleted the lukasz/prod-5137-add-agentruntimepolicy-cr branch August 19, 2026 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants