metropolis/proto: Add protobuf linting

This adds linting for our proto definitions. All failing linter rules
are currently disabled and will be enabled/fixed in a future commit.

Closes monogon-dev/monogon#7

Change-Id: Ifb9531511f0bc2a0b740722a493d7c3bf8d6d19c
Reviewed-on: https://review.monogon.dev/c/monogon/+/3747
Tested-by: Jenkins CI
Reviewed-by: Leopold Schabel <leo@monogon.tech>
diff --git a/MODULE.bazel b/MODULE.bazel
index 5576a51..405d187 100644
--- a/MODULE.bazel
+++ b/MODULE.bazel
@@ -66,6 +66,7 @@
 bazel_dep(name = "rules_cc", version = "0.0.10")
 bazel_dep(name = "rules_proto", version = "7.1.0")
 bazel_dep(name = "rules_proto_grpc_doc", version = "5.0.1")
+bazel_dep(name = "rules_proto_grpc_buf", version = "5.0.1")
 
 # Currently supported version are listed here:
 # https://protobuf.dev/support/version-support/
diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock
index 976b2a5..ae1b97d 100644
--- a/MODULE.bazel.lock
+++ b/MODULE.bazel.lock
@@ -134,6 +134,8 @@
     "https://bcr.bazel.build/modules/rules_proto/7.1.0/source.json": "39f89066c12c24097854e8f57ab8558929f9c8d474d34b2c00ac04630ad8940e",
     "https://bcr.bazel.build/modules/rules_proto_grpc/5.0.1/MODULE.bazel": "af7a76546e6fb5cfb37d30ece061bad276ceb785eb4ea43d6f74fc35cff71dfc",
     "https://bcr.bazel.build/modules/rules_proto_grpc/5.0.1/source.json": "eb2a5cd4344970803514e64bce3bb16840fe9476a4e9695d95c6e0475d821606",
+    "https://bcr.bazel.build/modules/rules_proto_grpc_buf/5.0.1/MODULE.bazel": "9c4191770ed1f3ca9eb780e8d50eaccff4f64335d8464321236a2e798165ccfb",
+    "https://bcr.bazel.build/modules/rules_proto_grpc_buf/5.0.1/source.json": "a80fd644b0249c95beccb78ac24f541af46dac511e20c858bfbe913ac29adb51",
     "https://bcr.bazel.build/modules/rules_proto_grpc_doc/5.0.1/MODULE.bazel": "2b0a43ecf9dc2a847498bf9cd36b3c270f7254b0a771cb7dcb3e2e5cff8c5d32",
     "https://bcr.bazel.build/modules/rules_proto_grpc_doc/5.0.1/source.json": "3b6f8b72e81196756859c7486595df297d7721d62ff37f71804ca9e4ed84ef8f",
     "https://bcr.bazel.build/modules/rules_python/0.10.2/MODULE.bazel": "cc82bc96f2997baa545ab3ce73f196d040ffb8756fd2d66125a530031cd90e5f",
@@ -1648,6 +1650,136 @@
         ]
       }
     },
+    "@@rules_proto_grpc_buf~//:module_extensions.bzl%download_plugins": {
+      "general": {
+        "bzlTransitiveDigest": "4Dbzp21JPls910QFYOOAw335SKlbrWNH86DoU7GtoyM=",
+        "usagesDigest": "TOAAucELsVvCXROTyq9qDqsfsexVeATllPss2PI2vvQ=",
+        "recordedFileInputs": {},
+        "recordedDirentsInputs": {},
+        "envVariables": {},
+        "generatedRepoSpecs": {
+          "buf_lint_plugin_darwin_arm64": {
+            "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl",
+            "ruleClassName": "http_file",
+            "attributes": {
+              "executable": true,
+              "sha256": "dea822195a4b092b84cfd531ba6b95923a131f2c4537b7ed29f9905619153060",
+              "url": "https://github.com/bufbuild/buf/releases/download/v1.34.0/protoc-gen-buf-lint-darwin-arm64"
+            }
+          },
+          "buf_breaking_plugin_linux_x86_64": {
+            "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl",
+            "ruleClassName": "http_file",
+            "attributes": {
+              "executable": true,
+              "sha256": "a1b754fb589f4362bc57b605645c29f7a3b8aca442c7ddca4c15c98f71fecbf6",
+              "url": "https://github.com/bufbuild/buf/releases/download/v1.34.0/protoc-gen-buf-breaking-Linux-X86_64"
+            }
+          },
+          "buf_breaking_plugin_windows_x86_64": {
+            "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl",
+            "ruleClassName": "http_file",
+            "attributes": {
+              "executable": true,
+              "sha256": "9d8845eb234515f62efb362e6d7d9d77e6eb12f6a97679754709de3f31968130",
+              "url": "https://github.com/bufbuild/buf/releases/download/v1.34.0/protoc-gen-buf-breaking-Windows-X86_64.exe"
+            }
+          },
+          "buf_lint_plugin_windows_x86_64": {
+            "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl",
+            "ruleClassName": "http_file",
+            "attributes": {
+              "executable": true,
+              "sha256": "c23ba1f7450abb64dc91652e9f67a75fe6189dc63b2e02d56eb4f9b44ddf6bc2",
+              "url": "https://github.com/bufbuild/buf/releases/download/v1.34.0/protoc-gen-buf-lint-windows-x86_64.exe"
+            }
+          },
+          "buf_breaking_plugin_darwin_arm64": {
+            "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl",
+            "ruleClassName": "http_file",
+            "attributes": {
+              "executable": true,
+              "sha256": "f244140c3459782b65bd2bd29a12972f116ddd2ed0c1d2a189cdd1b2c0aab1ba",
+              "url": "https://github.com/bufbuild/buf/releases/download/v1.34.0/protoc-gen-buf-breaking-Darwin-Arm64"
+            }
+          },
+          "buf_lint_plugin_windows_arm64": {
+            "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl",
+            "ruleClassName": "http_file",
+            "attributes": {
+              "executable": true,
+              "sha256": "1681e7ab55fbf1b6b1ef54e1def9904e30dd63d405a803a9a1debdb118b66e75",
+              "url": "https://github.com/bufbuild/buf/releases/download/v1.34.0/protoc-gen-buf-lint-windows-arm64.exe"
+            }
+          },
+          "buf_breaking_plugin_darwin_x86_64": {
+            "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl",
+            "ruleClassName": "http_file",
+            "attributes": {
+              "executable": true,
+              "sha256": "03ccd305ebd1f9bd8af67084628797bbaf3aa6ac33048b4e4d329efc8d7bae7e",
+              "url": "https://github.com/bufbuild/buf/releases/download/v1.34.0/protoc-gen-buf-breaking-Darwin-X86_64"
+            }
+          },
+          "buf_breaking_plugin_linux_arm64": {
+            "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl",
+            "ruleClassName": "http_file",
+            "attributes": {
+              "executable": true,
+              "sha256": "e317d99943f5f363c82fb31b33b845d8a01ffcbebe0e94e072fb3b8c0699f3f9",
+              "url": "https://github.com/bufbuild/buf/releases/download/v1.34.0/protoc-gen-buf-breaking-Linux-Arm64"
+            }
+          },
+          "buf_breaking_plugin_windows_arm64": {
+            "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl",
+            "ruleClassName": "http_file",
+            "attributes": {
+              "executable": true,
+              "sha256": "5f6ad60fb8cf86e944ee524d66ab5370459fd95e0f3c01e312d80a123be98ae0",
+              "url": "https://github.com/bufbuild/buf/releases/download/v1.34.0/protoc-gen-buf-breaking-Windows-Arm64.exe"
+            }
+          },
+          "buf_lint_plugin_linux_x86_64": {
+            "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl",
+            "ruleClassName": "http_file",
+            "attributes": {
+              "executable": true,
+              "sha256": "af3140ab9872dc7cb0fc14f7b5577d5433d17c1c07a8ed990be1d24222877d32",
+              "url": "https://github.com/bufbuild/buf/releases/download/v1.34.0/protoc-gen-buf-lint-linux-x86_64"
+            }
+          },
+          "buf_lint_plugin_darwin_x86_64": {
+            "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl",
+            "ruleClassName": "http_file",
+            "attributes": {
+              "executable": true,
+              "sha256": "45b3faeb82948a4876ec9ffa1f44a1ffe67845ce5d2959210c4e7d74a24b9e14",
+              "url": "https://github.com/bufbuild/buf/releases/download/v1.34.0/protoc-gen-buf-lint-darwin-x86_64"
+            }
+          },
+          "buf_lint_plugin_linux_arm64": {
+            "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl",
+            "ruleClassName": "http_file",
+            "attributes": {
+              "executable": true,
+              "sha256": "8a7a6fc1b95780f61c92136748fb95a2ccebce56e57ed4a0ca22acb96638c9aa",
+              "url": "https://github.com/bufbuild/buf/releases/download/v1.34.0/protoc-gen-buf-lint-linux-arm64"
+            }
+          }
+        },
+        "moduleExtensionMetadata": {
+          "useAllRepos": "REGULAR",
+          "reproducible": false
+        },
+        "recordedRepoMappingEntries": [
+          [
+            "rules_proto_grpc_buf~",
+            "bazel_tools",
+            "bazel_tools"
+          ]
+        ]
+      }
+    },
     "@@rules_proto_grpc_doc~//:module_extensions.bzl%download_plugins": {
       "general": {
         "bzlTransitiveDigest": "ybxRl6YFHDy8eL+PUtwBdKA+CivDuyAhuHGoG658FiI=",
diff --git a/metropolis/proto/BUILD.bazel b/metropolis/proto/BUILD.bazel
index 6db5882..42aecdc 100644
--- a/metropolis/proto/BUILD.bazel
+++ b/metropolis/proto/BUILD.bazel
@@ -1,9 +1,32 @@
+load("@rules_proto_grpc_buf//:defs.bzl", "buf_proto_breaking_test", "buf_proto_lint_test")
 load("@rules_proto_grpc_doc//:defs.bzl", "doc_html_compile")
 
 doc_html_compile(
-    name = "docs",
+    name = "proto_docs",
     protos = [
         "//metropolis/proto/api:api_proto",
         "//metropolis/proto/common:common_proto",
     ],
 )
+
+buf_proto_lint_test(
+    name = "proto_lint_test",
+    except_rules = [
+        "PACKAGE_VERSION_SUFFIX",
+        "RPC_REQUEST_RESPONSE_UNIQUE",
+        "ENUM_VALUE_PREFIX",  # TODO: evaluate correctness
+        "ENUM_ZERO_VALUE_SUFFIX",  # TODO: evaluate correctness
+        "RPC_REQUEST_STANDARD_NAME",  # TODO: evaluate correctness
+        "RPC_RESPONSE_STANDARD_NAME",  # TODO: evaluate correctness
+        "SERVICE_SUFFIX",  # TODO: evaluate correctness
+        "FIELD_LOWER_SNAKE_CASE",  # TODO: evaluate correctness
+    ],
+    protos = [
+        "//metropolis/proto/api:api_proto",
+        "//metropolis/proto/common:common_proto",
+    ],
+    use_rules = [
+        "DEFAULT",
+        "COMMENTS",
+    ],
+)