Skip to content
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

rpc: bazelize rpc_gen_cycling_test #24400

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 128 additions & 0 deletions bazel/cert.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
"""
This module contains functions to generate a simple CA
"""

# buildifier: disable=function-docstring-args
def _redpanda_private_key(name, certificate):
private_key = certificate + ".key"

pr_key_gen = name + "_key_gen"
native.genrule(
IoannisRP marked this conversation as resolved.
Show resolved Hide resolved
name = pr_key_gen,
srcs = [],
outs = [private_key],
cmd = "$(execpath @openssl//:openssl_exe) ecparam " +
"-name prime256v1 " +
"-genkey " +
"-noout " +
"-out \"$@\"",
tools = [
"@openssl//:openssl_exe",
],
)

return pr_key_gen

def redpanda_selfsigned_cert(name, certificate, common_name, visibility = None):
"""
Generate a Redpanda self-signed certificate.

Args:
name: name of the target
certificate: name to use for output files (crt, key, and csr)
common_name: the CN to use when setting the subject name
visibility: visibility setting
"""

cert = certificate + ".crt"
subj = "/C=US/ST=California/L=San Francisco/O=Redpanda Data/OU=Core/CN=" + common_name

pr_key_gen = _redpanda_private_key(name, certificate)

crt_gen = name + "_crt_gen"
native.genrule(
name = crt_gen,
srcs = [
pr_key_gen,
],
outs = [cert],
cmd = "$(execpath @openssl//:openssl_exe) req " +
"-new -x509 -sha256 " +
"-key $(SRCS) " +
"-out \"$@\" " +
"-subj \"{}\" ".format(subj) +
"-addext \"subjectAltName = IP:127.0.0.1\"",
tools = [
"@openssl//:openssl_exe",
],
)

native.filegroup(
name = name,
srcs = [pr_key_gen, crt_gen],
visibility = visibility,
)

def redpanda_signed_cert(name, certificate, common_name, ca, serial_number, visibility = None):
"""
Generate a Redpanda signed certificate.

Args:
name: name of the target
certificate: name to use for output files (crt, key, and csr)
common_name: the CN to use when setting the subject name
ca: the certificate to be used as the signing CA
serial_number: the serial number of cert when issued by CA
visibility: visibility setting
"""

subj = "/C=US/ST=California/L=San Francisco/O=Redpanda Data/OU=Core/CN=" + common_name

pr_key_gen = _redpanda_private_key(name, certificate)

req_gen = name + "_csr_gen"
native.genrule(
name = req_gen,
srcs = [
pr_key_gen,
],
outs = [certificate + ".csr"],
cmd = "$(execpath @openssl//:openssl_exe) req " +
"-new -sha256 " +
"-key $(SRCS) " +
"-out \"$@\" " +
"-subj \"{}\" ".format(subj),
tools = [
"@openssl//:openssl_exe",
],
)

ca_cert = ca + ".crt"
ca_private_key = ca + ".key"

crt_gen = name + "_crt_gen"
native.genrule(
name = crt_gen,
srcs = [
ca_cert,
ca_private_key,
req_gen,
],
outs = [certificate + ".crt"],
cmd = "$(execpath @openssl//:openssl_exe) x509 " +
"-req -days 1000 -sha256 " +
"-set_serial {} ".format(serial_number) +
"-in $(execpath {}) ".format(req_gen) +
"-CA $(execpaths :{}) ".format(ca_cert) +
"-CAkey $(execpaths :{}) ".format(ca_private_key) +
"-out \"$@\" ",
tools = [
"@openssl//:openssl_exe",
],
)

native.filegroup(
name = name,
srcs = [pr_key_gen, req_gen, crt_gen],
visibility = visibility,
)
22 changes: 22 additions & 0 deletions bazel/thirdparty/openssl.BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@bazel_skylib//rules:common_settings.bzl", "int_flag", "string_flag")
load("@bazel_skylib//rules:select_file.bzl", "select_file")
load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make")

# Make this build faster by setting `build --@openssl//:build_jobs=16` in user.bazelrc
Expand Down Expand Up @@ -55,6 +56,9 @@ configure_make(
"OPENSSL_BUILD_JOBS": "$(BUILD_JOBS)",
},
lib_source = ":srcs",
out_binaries = [
"openssl",
],
out_shared_libs = [
"libssl.so.3",
"libcrypto.so.3",
Expand All @@ -64,3 +68,21 @@ configure_make(
"//visibility:public",
],
)

filegroup(
name = "gen_dir",
srcs = [":openssl"],
output_group = "gen_dir",
visibility = [
"//visibility:public",
],
)

select_file(
name = "openssl_exe",
srcs = ":openssl",
subpath = "bin/openssl",
visibility = [
"//visibility:public",
],
)
12 changes: 11 additions & 1 deletion src/v/rpc/compiler.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ This module contains functions for working with Redpanda RPC system.

load("//bazel:build.bzl", "redpanda_cc_library")

def redpanda_cc_rpc_library(name, src, out = None, include_prefix = None, visibility = None):
def redpanda_cc_rpc_library(name, src, out = None, deps = [], include_prefix = None, visibility = None):
"""
Generate Redpanda RPC library.

Args:
name: name of the library
src: rpc specification json file
out: output header name. defaults to src_service.h (without .json extension)
deps: dependencies defined in the json src file
include_prefix: include_prefix of generated header
visibility: visibility setting
"""
Expand All @@ -30,9 +31,18 @@ def redpanda_cc_rpc_library(name, src, out = None, include_prefix = None, visibi
tools = ["//src/v/rpc:compiler"],
)

rpc_template_deps = [
"//src/v/config",
"//src/v/metrics",
"//src/v/rpc",
"//src/v/finjector",
"//src/v/random:fast_prng",
]

redpanda_cc_library(
name = name,
hdrs = [out],
deps = rpc_template_deps + deps,
include_prefix = include_prefix,
visibility = visibility,
)
110 changes: 109 additions & 1 deletion src/v/rpc/test/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
load("//bazel:test.bzl", "redpanda_cc_bench", "redpanda_cc_btest")
load("//bazel:build.bzl", "redpanda_cc_library")
load("//bazel:cert.bzl", "redpanda_selfsigned_cert", "redpanda_signed_cert")
load("//bazel:test.bzl", "redpanda_cc_bench", "redpanda_cc_btest", "redpanda_test_cc_library")
load("//src/v/rpc:compiler.bzl", "redpanda_cc_rpc_library")

redpanda_test_cc_library(
name = "rpc_integration_fixture",
hdrs = [
"rpc_integration_fixture.h",
],
include_prefix = "rpc/test",
deps = [
"//src/v/base",
"//src/v/config",
"//src/v/net",
"//src/v/rpc",
"@seastar",
],
)

redpanda_cc_btest(
name = "netbuf_test",
timeout = "short",
Expand Down Expand Up @@ -101,6 +118,37 @@ redpanda_cc_btest(
],
)

redpanda_cc_btest(
name = "rpc_gen_cycling_test",
timeout = "short",
srcs = [
"rpc_gen_cycling_test.cc",
],
cpu = 1,
data = [
":cert",
":cert_ca",
":other_cert",
":other_cert_ca",
],
tags = ["exclusive"],
deps = [
":cycling_rpc",
":echo_rpc",
":echo_v2_rpc",
":rpc_integration_fixture",
"//src/v/bytes:random",
"//src/v/model",
"//src/v/random:generators",
"//src/v/rpc",
"//src/v/test_utils:fixture",
"//src/v/test_utils:seastar_boost",
"@boost//:test",
"@seastar",
"@seastar//:testing",
],
)

redpanda_cc_bench(
name = "rpc_bench",
timeout = "short",
Expand All @@ -114,17 +162,77 @@ redpanda_cc_bench(
],
)

redpanda_cc_library(
name = "rpc_gen_types",
hdrs = [
"rpc_gen_types.h",
],
include_prefix = "rpc/test",
deps = [
"//src/v/base",
"//src/v/reflection:adl",
"//src/v/rpc",
"//src/v/serde",
"//src/v/serde:enum",
"//src/v/serde:sstring",
"@seastar",
],
)

redpanda_cc_rpc_library(
name = "cycling_rpc",
src = "cycling_service.json",
out = "cycling_service.h",
include_prefix = "rpc/test",
deps = [
":rpc_gen_types",
],
)

redpanda_cc_rpc_library(
name = "echo_rpc",
src = "echo_service.json",
out = "echo_service.h",
include_prefix = "rpc/test",
deps = [
":rpc_gen_types",
],
)

redpanda_cc_rpc_library(
name = "echo_v2_rpc",
src = "echo_v2_service.json",
out = "echo_v2_service.h",
include_prefix = "rpc/test",
deps = [
":rpc_gen_types",
],
)

redpanda_selfsigned_cert(
name = "cert_ca",
certificate = "root_certificate_authority",
common_name = "redpanda.com",
)

redpanda_selfsigned_cert(
name = "other_cert_ca",
certificate = "root_certificate_authority.other",
common_name = "redpanda.other.com",
)

redpanda_signed_cert(
name = "cert",
ca = "root_certificate_authority",
certificate = "redpanda",
common_name = "cert.com",
serial_number = 1,
)

redpanda_signed_cert(
name = "other_cert",
ca = "root_certificate_authority.other",
certificate = "redpanda.other",
common_name = "cert.other.com",
serial_number = 2,
)
2 changes: 1 addition & 1 deletion src/v/rpc/test/cycling_service.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"namespace": "cycling",
"service_name": "team_movistar",
"includes": [
"rpc_gen_types.h"
"rpc/test/rpc_gen_types.h"
],
"methods": [
{
Expand Down
2 changes: 1 addition & 1 deletion src/v/rpc/test/echo_service.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"namespace": "echo",
"service_name": "echo",
"includes": [
"rpc_gen_types.h"
"rpc/test/rpc_gen_types.h"
],
"methods": [
{
Expand Down
2 changes: 1 addition & 1 deletion src/v/rpc/test/echo_v2_service.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"namespace": "echo_v2",
"service_name": "echo",
"includes": [
"rpc_gen_types.h"
"rpc/test/rpc_gen_types.h"
],
"methods": [
{
Expand Down
Loading
Loading