Skip to content

Commit

Permalink
⭐️ ranger guard middleware (#20)
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Hartmann <[email protected]>

Signed-off-by: Christoph Hartmann <[email protected]>
  • Loading branch information
chris-rock authored Sep 22, 2022
1 parent cff95c3 commit 5faaff8
Show file tree
Hide file tree
Showing 45 changed files with 2,691 additions and 4 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ generate/examples:
go generate ./examples/pingpong
go generate ./examples/oneof
go generate ./examples/swagger
go generate ./examples/rangerguard

.PHONY: run/example/server
run/example/server: install generate/examples
Expand Down
4 changes: 2 additions & 2 deletions examples/oneof/oneof.ranger.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions examples/pingpong/pingpong.ranger.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 61 additions & 0 deletions examples/rangerguard/client/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package main

import (
"context"
"crypto/tls"
"net/http"
"os"
"time"

"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
pb "go.mondoo.com/ranger-rpc/examples/rangerguard"
"go.mondoo.com/ranger-rpc/plugins/authentication/cert"
"go.mondoo.com/ranger-rpc/plugins/rangerguard/crypto"
)

func main() {
// inefficient, just for testing
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})

tlsconfig := &tls.Config{
InsecureSkipVerify: true,
}

tr := &http.Transport{
MaxIdleConns: 10,
IdleConnTimeout: 30 * time.Second,
DisableCompression: true,
TLSClientConfig: tlsconfig,
}

// key for signing the requests
privateKey, err := crypto.PrivateKeyFromFile("../server/private-key.p8")
if err != nil {
log.Error().Err(err).Msg("could not read private key")
}

plugin, err := cert.NewRangerPlugin(cert.ClientConfig{
PrivateKey: privateKey,
Issuer: "ranger_guard",
Subject: "ranger_guard_client",
Kid: "1",
})
if err != nil {
log.Error().Err(err).Msg("could not create signer plugin")
}

log.Info().Msgf("start proto cLient")
protoClient, err := pb.NewHelloWorldClient("https://localhost:8443/hello/", &http.Client{Transport: tr}, plugin)
if err != nil {
log.Error().Err(err).Msg("could not create hello world client")
}

data := &pb.HelloReq{Subject: "World"}
protoResp, err := protoClient.Hello(context.Background(), data)
if err == nil {
log.Info().Msgf("Response %s", protoResp.Text) // prints "Hello World"
} else {
log.Error().Err(err).Msg("Could not get the response")
}
}
6 changes: 6 additions & 0 deletions examples/rangerguard/hello.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package rangerguard

// To regenerate the protocol buffer output for this package, run
// go generate

//go:generate protoc --go_out=. --go_opt=paths=source_relative --rangerrpc_out=. hello.proto
Loading

0 comments on commit 5faaff8

Please sign in to comment.