Skip to content

Add policy client and protocol plumbing#38514

Open
dsa0x wants to merge 7 commits into
mainfrom
policy-pr1-foundation
Open

Add policy client and protocol plumbing#38514
dsa0x wants to merge 7 commits into
mainfrom
policy-pr1-foundation

Conversation

@dsa0x
Copy link
Copy Markdown
Member

@dsa0x dsa0x commented May 4, 2026

This is part of a stacked series to upstream the policy work in smaller, reviewable pieces:

This PR introduces the policy package and the basic protocol/client plumbing that the rest of the stack builds on.
The goal here is to land the policy-specific infrastructure first so the later PRs can focus on runtime behavior.

Included here

  • policy client setup and implementation
  • RPC protocol types,
  • policy diagnostics/types
  • callback service plumbing
  • generated protobufs
  • protobuf compile tool updates

Target Release

1.16.x

Rollback Plan

  • If a change needs to be reverted, we will roll out an update to the code within 7 days.

Changes to Security Controls

Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.

CHANGELOG entry

  • This change is user-facing and I added a changelog entry.
  • This change is not user-facing.

@dsa0x dsa0x added the no-changelog-needed Add this to your PR if the change does not require a changelog entry label May 4, 2026
@dsa0x dsa0x marked this pull request as ready for review May 18, 2026 09:52
@dsa0x dsa0x requested a review from a team as a code owner May 18, 2026 09:52
Copy link
Copy Markdown
Member

@SarahFrench SarahFrench left a comment

Choose a reason for hiding this comment

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

👋🏻 I've been taking a look at this today and will resume tomorrow, but here are some initial comments that mainly revolve around testing.

Comment thread internal/policy/proto/callback_grpc.pb.go
Comment thread internal/policy/client.go Outdated
return s.evaluateModuleFn(req)
}

func TestClientEvaluate(t *testing.T) {
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.

I think there can be more test coverages here, both for this and the other 2 Evaluate-type methods.

For example:

  • You could have the evaluateResourceFn return an empty or nil response alongside a non-nil error - does the response from Evaluate handle that error as expected?
  • You could also include more data in the response from evaluateResourceFn and make more assertions about how it's transformed by the Evaluate method. E.g. if you include some PolicyDetails data and assert that diagnostics from in there are transformed as expected into diagnostics in the response from Evaluate.

return diags
}

func (diagnostic *Diagnostic) ToHCL() *hcl.Diagnostic {
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.

Could this benefit from some test coverage?

I know the concept of 'diagnostic extras' isn't new to the codebase, but this implementation is and it might be worth adding some light tests asserting that these behave in the way we expect.

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.

➕ to that idea, I was also looking at the proto definition of diagnostic and it's a little difficult to understand exactly what data we will receive in a diagnostic. Perhaps some tests could serve as documentation of "these are some examples of what this extra info will look like"

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 did have more extensive tests in subsequent PRs that exercise assertions around the different kinds of policy results and diagnostics. Putting them further up the stack just helped that one test exercises a lot more paths. But I understand that context is kinda lost in this task break down. I have added some more here for this unit.

Comment thread internal/policy/client_test.go Outdated
Copy link
Copy Markdown
Member

@austinvalle austinvalle left a comment

Choose a reason for hiding this comment

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

Very nice 👍🏻, I appreciate you breaking these out 😆. I left some comments and questions!

Comment thread internal/policy/proto/callback.proto Outdated
Comment thread internal/policy/proto/callback.proto Outdated
Comment thread internal/policy/proto/callback.proto
Comment thread internal/policy/proto/callback.proto
Comment thread internal/policy/proto/diagnostics.proto
Comment thread internal/policy/proto/policy.proto
Comment thread internal/policy/proto/types.proto Outdated
Comment thread internal/policy/proto/diagnostics.go
Comment thread internal/policy/proto/diagnostics.go Outdated
Comment thread internal/policy/result.go Outdated
dsa0x added 2 commits May 19, 2026 13:36
- More testing for the callbacks and policy client
- setup a mock callback registry
- Rename Evaluate to EvaluateResource
- More comments
- Use optional for Snippet
@dsa0x dsa0x force-pushed the policy-pr1-foundation branch from cc00cb2 to 9c5c4f8 Compare May 19, 2026 12:49
@dsa0x dsa0x force-pushed the policy-pr1-foundation branch from 9c5c4f8 to a607df3 Compare May 19, 2026 12:49
@dsa0x dsa0x requested review from SarahFrench and austinvalle May 19, 2026 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-changelog-needed Add this to your PR if the change does not require a changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants