GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Update thriftmux test container to support tls via a command line flag by ddelnano · Pull Request #413 · pixie-io/pixie

Update thriftmux test container to support tls via a command line flag #413

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.

Sign up for GitHub

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

Closed
ddelnano wants to merge 7 commits into pixie-io:main from ddelnano:ddelnano/update-thriftmux-container-to-work-with-mtls

Uh oh!

There was an error while loading. Please reload this page.

Closed

Update thriftmux test container to support tls via a command line flag #413

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
7 commits
Select commit Hold shift + click to select a range
16af9e5
Update thriftmux container to work with mtls
ddelnano Feb 28, 2022
4952fca
Configure logback to fix netty logging to surface netty-tcnative link…
ddelnano Mar 1, 2022
8869962
Add byteman to create a stable file path for the netty-tcnative share…
ddelnano Mar 2, 2022
5312893
Update cert_generator to allow for specifying a pkcs1 or pkcs8 key. R…
ddelnano Mar 16, 2022
0a7318a
Add TODO comment to remove byteman in the future
ddelnano Mar 16, 2022
ded0efb
Update thriftmux client request validation to work with mtls container
Mar 17, 2022
bdb22d9
Fix linting issues
Mar 17, 2022
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

5 changes: 5 additions & 0 deletions 5 bazel/pl_workspace.bzl
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ def _package_manager_setup():
"libsasl2-2",
"libssl1.1",
"libgcc1",
"libcrypt1",
# TODO(ddelnano): byteman is required until dealing with
# netty's libnetty_tcnative.so's random file name is solved for.
# See #407 for more details.
"libbyteman-java",
Comment thread
ddelnano marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

],
sources = ["@debian_sid//file:Packages.json"],
)
Expand Down
3 changes: 3 additions & 0 deletions 3 bazel/thrift.bzl
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ def thrift_deps(scala_version):
"com.twitter:scrooge-core_%s:%s" % (scala_minor_version, finagle_version),
"com.twitter:finagle-http_%s:%s" % (scala_minor_version, finagle_version),
"org.apache.thrift:libthrift:0.10.0",
"org.slf4j:slf4j-api:1.7.36",
"ch.qos.logback:logback-core:1.2.10",
"ch.qos.logback:logback-classic:1.2.10",
],
repositories = ["https://repo1.maven.org/maven2"],
)
27 changes: 24 additions & 3 deletions 27 src/common/testing/test_utils/cert_generator/cert_generator.go
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"crypto/x509"
"crypto/x509/pkix"
"encoding/pem"
"fmt"
"math/big"
"os"
"time"
Expand Down Expand Up @@ -114,9 +115,28 @@ func generateAndWriteCertPair(ca *x509.Certificate, caKey *rsa.PrivateKey, certP
if err != nil {
panic(err)
}
err = pem.Encode(keyOut, &pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(privateKey)})
if err != nil {
panic(err)

keyType := viper.GetString("secret_key_type")
if keyType == "pkcs1" {

err = pem.Encode(keyOut, &pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(privateKey)})
if err != nil {
panic(err)
}

} else if keyType == "pkcs8" {

b, err := x509.MarshalPKCS8PrivateKey(privateKey)
if err != nil {
panic(err)
}

err = pem.Encode(keyOut, &pem.Block{Type: "PRIVATE KEY", Bytes: b})
if err != nil {
panic(err)
}
} else {
panic(fmt.Sprintf("Unsupported private key type: %s"))
}
err = keyOut.Close()
if err != nil {
Expand All @@ -130,6 +150,7 @@ func main() {
pflag.String("client_key", "", "Path where to write client.key")
pflag.String("server_crt", "", "Path where to write server.crt")
pflag.String("server_key", "", "Path where to write server.key")
pflag.String("secret_key_type", "pkcs1", "Which private key type to use. Possible options include pkcs1, pkcs8")

pflag.Parse()
viper.BindPFlags(pflag.CommandLine)
Expand Down
6 changes: 3 additions & 3 deletions 6 src/stirling/source_connectors/socket_tracer/mux_trace_bpf_test.cc
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ class MuxTraceTest : public SocketTraceBPFTest</* TClientSideTracing */ true> {

LOG(INFO) << absl::StrFormat("Client PID: %d", client_pid);

if (tokens[1] != thriftmux_client_output) {
if (!absl::StrContains(out, thriftmux_client_output)) {
return error::Internal(
absl::StrFormat("Expected output from thriftmux to be '%s', received '%s' instead",
thriftmux_client_output, tokens[1]));
absl::StrFormat("Expected output from thriftmux to include '%s', received '%s' instead",
thriftmux_client_output, out));
}
return client_pid;
}
Expand Down
83 changes: 83 additions & 0 deletions 83 src/stirling/source_connectors/socket_tracer/testing/containers/thriftmux/BUILD.bazel
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,67 @@
#
# SPDX-License-Identifier: Apache-2.0

load("@package_bundle//file:packages.bzl", "packages")
load("@io_bazel_rules_docker//java:image.bzl", "DEFAULT_JAVA_BASE", "jar_app_layer")
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
load("@io_bazel_rules_docker//container:container.bzl", "container_image", "container_layer")
load("@io_bazel_rules_docker//scala:image.bzl", "scala_image")
load("@io_bazel_rules_scala//scala:scala.bzl", "scala_binary", "scala_library")
load("@io_bazel_rules_scala//thrift:thrift.bzl", "thrift_library")
load("@io_bazel_rules_scala//twitter_scrooge:twitter_scrooge.bzl", "scrooge_scala_library")

package(default_visibility = ["//src/stirling:__subpackages__"])

genrule(
name = "certs",
outs = [
"ca.crt",
"client.crt",
"client.key",
"server.crt",
"server.key",
],
cmd = """
$(location //src/common/testing/test_utils/cert_generator:cert_generator) \
--ca_crt $(location ca.crt) \
--client_crt $(location client.crt) \
--client_key $(location client.key) \
--server_crt $(location server.crt) \
--server_key $(location server.key) \
--secret_key_type pkcs8
""",
tools = [
"//src/common/testing/test_utils/cert_generator",
],
)

pkg_tar(
name = "ssl_keys",
srcs = [
"ca.crt",
"client.crt",
"client.key",
"server.crt",
"server.key",
],
mode = "0755",
package_dir = "/etc/ssl",
strip_prefix = "/src/stirling/source_connectors/socket_tracer/testing/containers/thriftmux",
)

# TODO(ddelnano): byteman is required until dealing with
# netty's libnetty_tcnative.so's random file name is solved for.
# See #407 for more details.
pkg_tar(
name = "byteman_rule",
srcs = [
"byteman_rule.txt",
],
mode = "0755",
package_dir = "/etc/byteman",
strip_prefix = "/src/stirling/source_connectors/socket_tracer/testing/containers/thriftmux",
)

thrift_library(
name = "thrift_library",
srcs = glob(["**/*.thrift"]),
Expand Down Expand Up @@ -54,6 +108,15 @@ scrooge_scala_library(
],
)

scala_library(
name = "logging",
deps = [
"@maven//:ch_qos_logback_logback_classic",
"@maven//:ch_qos_logback_logback_core",
"@maven//:org_slf4j_slf4j_api",
],
)

scala_binary(
name = "server_bin",
srcs = glob(["**/*.scala"]),
Expand All @@ -72,11 +135,31 @@ scala_binary(
],
)

container_image(
name = "thriftmux_base",
base = DEFAULT_JAVA_BASE,
debs = [
packages["libbyteman-java"],
packages["libcrypt1"],
],
tars = [
":ssl_keys",
":byteman_rule",
],
)

scala_image(
name = "server_image",
srcs = glob(["**/*.scala"]),
base = ":thriftmux_base",
jvm_flags = [
"-javaagent:/usr/share/java/byteman-4.0.11.jar=script:/etc/byteman/byteman_rule.txt,boot:/usr/share/java/byteman-4.0.11.jar",
"-Dorg.jboss.byteman.transform.all",
"-Dio.netty.native.deleteLibAfterLoading=false",
],
main_class = "Server",
deps = [
":logging",
":thriftmux_scrooge",
],
)
10 changes: 9 additions & 1 deletion 10 ...stirling/source_connectors/socket_tracer/testing/containers/thriftmux/README.md
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ This container can be run as a thriftmux server or client.
$ bazel run src/stirling/source_connectors/socket_tracer/testing/containers/thriftmux:server_image

# Run the client. This requires using 'docker run' directly to override the default entrypoint
$ docker run --entrypoint /usr/bin/java bazel/src/stirling/source_connectors/socket_tracer/testing/containers/thriftmux:server_image -cp @/app/px/src/stirling/source_connectors/socket_tracer/testing/containers/thriftmux/server_image.classpath Client
$ docker exec -it ${container_id} /usr/bin/java -cp @/app/px/src/stirling/source_connectors/socket_tracer/testing/containers/thriftmux/server_image.classpath Client

# Run the server and client with TLS enabled
$ bazel run src/stirling/source_connectors/socket_tracer/testing/containers/thriftmux:server_image -- --use-tls true

# Add TLS certs to java keystore
docker exec -it ${container_id} /usr/lib/jvm/java-11-openjdk-amd64/bin/keytool -importcert -keystore /etc/ssl/certs/java/cacerts -file /etc/ssl/ca.crt -noprompt -storepass changeit

$ docker exec -it ${container_id} /usr/bin/java -cp @/app/px/src/stirling/source_connectors/socket_tracer/testing/containers/thriftmux/server_image.classpath Client --use-tls true
```

See `mux_container_bpf_test.cc` for use case.
9 changes: 9 additions & 0 deletions 9 src/stirling/source_connectors/socket_tracer/testing/containers/thriftmux/byteman_rule.txt
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
RULE Create predictable dynamic library path for tcnative
CLASS io.netty.util.internal.PlatformDependent
METHOD createTempFile
AT ENTRY
BIND filePath:String = $1;
isTcNativeLib:boolean = filePath.contains("tcnative");
IF isTcNativeLib
DO return new File("/tmp/libnetty_tcnative_linux_x86.so")
ENDRULE
42 changes: 34 additions & 8 deletions 42 ..._connectors/socket_tracer/testing/containers/thriftmux/src/main/scala/client/Client.scala
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,13 +1,39 @@
import com.twitter.util.{Await, Future}
import com.twitter.finagle.thriftmux.thriftscala.TestService
import com.twitter.finagle.ssl._
import com.twitter.finagle.ssl.client.SslClientConfiguration
import com.twitter.finagle.{Thrift, ThriftMux}

object Client extends App {
val stackClient = ThriftMux.client.withLabel("thriftmux_example")
val svcPerEndpoint = stackClient
.methodBuilder("inet!localhost:8080")
.servicePerEndpoint[TestService.ServicePerEndpoint]
val svc = ThriftMux.Client.methodPerEndpoint[TestService.ServicePerEndpoint, TestService.MethodPerEndpoint](svcPerEndpoint)
val r = Await.result(svc.query("String"))
println(r)
import java.io.File;

object Client {
def main(args: Array[String]): Unit = {
var useTls = false
args.grouped(2).toList.collect {
case Array("--use-tls", tls: String) => useTls = tls.toBoolean
}
val keyCredentials = KeyCredentials.CertAndKey(
new File("/etc/ssl/client.crt"),
new File("/etc/ssl/client.key"),
)
val sslConfig = SslClientConfiguration(
None,
keyCredentials,
)
var stackClient = if (useTls) {
ThriftMux.client
.withLabel("thriftmux_example")
.withTransport
.tls(sslConfig)
} else {
ThriftMux.client
.withLabel("thriftmux_example")
}
val svcPerEndpoint = stackClient
.methodBuilder("inet!localhost:8080")
.servicePerEndpoint[TestService.ServicePerEndpoint]
val svc = ThriftMux.Client.methodPerEndpoint[TestService.ServicePerEndpoint, TestService.MethodPerEndpoint](svcPerEndpoint)
val r = Await.result(svc.query("String"))
println(r)
}
}
39 changes: 30 additions & 9 deletions 39 ..._connectors/socket_tracer/testing/containers/thriftmux/src/main/scala/server/Server.scala
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,21 +1,42 @@
import com.twitter.finagle.{Http, Service}
import com.twitter.finagle.http
import com.twitter.finagle.{Thrift, ThriftMux}
import com.twitter.finagle.ssl._
import com.twitter.finagle.ssl.server.SslServerConfiguration
import com.twitter.util.{Await, Future}
import java.net.{InetSocketAddress, InetAddress}
import com.twitter.finagle.thriftmux.thriftscala.TestService

import java.io.File;

object Server {
def main(args: Array[String]): Unit = {
val server = ThriftMux.server
.serveIface(
new InetSocketAddress(InetAddress.getLoopbackAddress, 8080),
new TestService.MethodPerEndpoint {
def query(x: String): Future[String] = Future.value(x + x)
def question(y: String): Future[String] = Future.value(y + y)
def inquiry(z: String): Future[String] = Future.value(z + z)
},
)
var useTls = false
args.grouped(2).toList.collect {
case Array("--use-tls", tls: String) => useTls = tls.toBoolean
}
val keyCredentials = KeyCredentials.CertAndKey(
new File("/etc/ssl/server.crt"),
new File("/etc/ssl/server.key"),
)
val sslConfig = SslServerConfiguration(
keyCredentials,
)
val addr = new InetSocketAddress(InetAddress.getLoopbackAddress, 8080)
val testSvc = new TestService.MethodPerEndpoint {
def query(x: String): Future[String] = Future.value(x + x)
def question(y: String): Future[String] = Future.value(y + y)
def inquiry(z: String): Future[String] = Future.value(z + z)
}
var server = if (useTls) {
ThriftMux.server
.withTransport
.tls(sslConfig)
.serveIface(addr, testSvc)
} else {
ThriftMux.server
.serveIface(addr, testSvc)
}
Await.ready(server)
}
}
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.