Skip to content

Run buf Policies locally #3785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open

Run buf Policies locally #3785

wants to merge 16 commits into from

Conversation

emcfarlane
Copy link
Contributor

@emcfarlane emcfarlane commented Apr 22, 2025

This PR adds support for running local buf Policies. Lint and breaking checks now invoke the set of policy rules alongside the set of configured rules. Only local policies are currently supported, remote will be added with lock file support. The annotations emitted now include the policy name alongside the plugin (e.g. <annotation> (buf-plugin-name, buf-policy-name)). An inbuilt plugin for a policy will include only the policy name.

As an example a policy can be expressed for the buf-plugin-suffix.wasm plugin in a policy.yaml file:

version: v2
lint:
  use:
    - SERVICE_BANNED_SUFFIXES
    - RPC_BANNED_SUFFIXES
plugins:
  - plugin: buf-plugin-suffix.wasm
    options:
      service_banned_suffixes:
        - Mock
        - Test
      rpc_banned_suffixes:
        - Element

Which can then be used in a buf.yaml file:

version: v2
lint:
  disable_builtin: true
policies:
  - policy: policy.yaml

And run with buf lint showing the output annotations for a simple test proto:

a.proto:8:1:Service name "AMock" has banned suffix "Mock". (buf-plugin-suffix.wasm, policy.yaml)
a.proto:9:3:Method name "AMock.GetAllAElement" has banned suffix "Element". (buf-plugin-suffix.wasm, policy.yaml)

@emcfarlane emcfarlane requested a review from doriable April 22, 2025 21:25
Copy link
Contributor

github-actions bot commented Apr 22, 2025

The latest Buf updates on your PR. Results from workflow Buf CI / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedApr 30, 2025, 1:01 PM

Base automatically changed from ed/bufPolicyYaml to main April 28, 2025 14:54
@emcfarlane emcfarlane marked this pull request as ready for review April 28, 2025 18:14
@emcfarlane emcfarlane changed the title Invoke buf policies locally Run buf Policies locally Apr 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant