Giter Site home page Giter Site logo

client-go's Introduction

Falco Go Client

Falco Ecosystem Repository Incubating

GoDoc

Go client and SDK for Falco

Learn more about the gRPC API by reading the docs.

Install

go get -u github.com/falcosecurity/client-go

Usage

Network Client creation

If you are binding the Falco gRPC server to a network socket with mTLS (mutual TLS authentication) you need this one. Please remember that since this is enabling mTLS you will need to generate a pair of certificates for this client specifically and provide the CA certificate. If you need something simpler, go for the unix socket.

package main

imports(
    "context"
    "github.com/falcosecurity/client-go/pkg/client"
)

func main() {
    c, err := client.NewForConfig(context.Background(), &client.Config{
        Hostname:   "localhost",
        Port:       5060,
        CertFile:   "/etc/falco/certs/client.crt",
        KeyFile:    "/etc/falco/certs/client.key",
        CARootFile: "/etc/falco/certs/ca.crt",
    })
}

Unix Socket Client creation

If you are binding the Falco gRPC server to unix socket, this is what you need.

package main

imports(
    "context"
    "github.com/falcosecurity/client-go/pkg/client"
)

func main() {
    c, err := client.NewForConfig(context.Background(), &client.Config{
        UnixSocketPath:   "unix:///run/falco/falco.sock",
    })
}

Falco outputs API

outputsClient, err := c.Outputs()
if err != nil {
    log.Fatalf("unable to obtain an output client: %v", err)
}

ctx := context.Background()
fcs, err := outputsClient.Get(ctx, &outputs.Request{})
if err != nil {
    log.Fatalf("could not subscribe: %v", err)
}

for {
    res, err := fcs.Recv()
    if err == io.EOF {
        break
    }
    if err != nil {
        log.Fatalf("error closing stream after EOF: %v", err)
    }
    fmt.Printf("rule: %s\n", res.Rule)
}

Falco version API

// Set up a connection to the server.
c, err := client.NewForConfig(context.Background(), &client.Config{
    Hostname:   "localhost",
    Port:       5060,
    CertFile:   "/etc/falco/certs/client.crt",
    KeyFile:    "/etc/falco/certs/client.key",
    CARootFile: "/etc/falco/certs/ca.crt",
})
if err != nil {
    log.Fatalf("unable to create a Falco client: %v", err)
}
defer c.Close()
versionClient, err := c.Version()
if err != nil {
    log.Fatalf("unable to obtain a version client: %v", err)
}

ctx := context.Background()
res, err := versionClient.Version(ctx, &version.Request{})
if err != nil {
    log.Fatalf("error obtaining the Falco version: %v", err)
}
fmt.Printf("%v\n", res)

Full Examples

Update protos

Perform the following edits to the Makefile:

  1. Update the PROTOS array with the destination path of the .proto file.
  2. Update the PROTO_URLS array with the URL from which to download it.
  3. Update the PROTO_SHAS array with the SHA256 sum of the file to download.
  4. Execute the following commands:
make clean
make protos

Generate mocks for protos

  1. Follow the steps in the Update protos section
  2. Execute the following commands:
make mocks

client-go's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

client-go's Issues

Update the path of proto files into the Makefile

What would you like to be added:

We need to update the path of the proto file(s).

Currently they still points to the branch in Falco where they were done.

PROTO_URLS := https://raw.githubusercontent.com/falcosecurity/falco/feat/grpc-server-poc/userspace/falco/schema.proto https://raw.githubusercontent.com/falcosecurity/falco/feat/grpc-server-poc/userspace/falco/output.proto

Why is this needed:

We need it to point to the dev branch of Falco (since it will become the default and the master branch soon).

Stub gRPC server

Motivation

I'd like having tests for this repository.

Thus, we need a stub gRPC server in order to do some state testing.

Feature

Implementing a stub gRPC server: a gRPC server that provides canned answers.

Alternatives

A mock gRPC server.

But this requires a bit more effort and I'd postpone it to when we'll want to do behavioral testing.

Additional context

None.

makefile default target

What happened:

The default makefile target is a rule (so it does not expand to all protos).

What you expected to happen:

Calling make checks all the proto in the Falco repository and eventually downloads/checks/creates Go API for them.

How to reproduce it (as minimally and precisely as possible):

Just run make vs make protos.

Anything else we need to know?:

missing mocks break `go mod tidy` when client-go is used in other projects

Describe the bug/How to reproduce it

In another go project:

go get -u github.com/falcosecurity/client-go@master

Then run go mod tidy:

 [redacted] imports
	github.com/falcosecurity/client-go/pkg/client tested by
	github.com/falcosecurity/client-go/pkg/client.test imports
	github.com/falcosecurity/client-go/pkg/api/version/mocks: module github.com/falcosecurity/client-go@latest found (v0.1.0), but does not contain package github.com/falcosecurity/client-go/pkg/api/version/mocks

Expected behaviour

No errors when running go mod tidy

Additional context

This is breaking the release pipeline of falco-exporter

/assign

Remove proto files from git index

What would you like to be added:

I would like to remove the proto files from the git index.

Why is this needed:

The proto files (that reside in the Falco repo) are grabbed by the Makefile that then compiles them into Go.

So they are not part of the source code of this repository and I would like to avoid any confusion. The source of truth regarding protos is only one: the Falco ones.
Also, new contributors could get easily confused seeing protos here and protos there.

Missing license

What would you like to be added:

The LICENSE file.

Why is this needed:

Do I really need to explain why? LOL

Volunteer as owner for client go.

Hi Team,

I would like to volunteer as owner of our client go repository, I have some experience writing go with unit test cases. I would love get involved building this go client.

Thanks,

Release v0.2.0 once Falco 0.24.0 is out

Motivation

We just need a tag for projects which are importing this library.

Feature

Just a reminder to release the v0.2.0 once the new Falco version is out.

Alternatives

No alternatives :)

Additional context
/assign

Volunteer as owner

I would like to volunteer as an owner of this repository. I have a lot of experience writing Go, and would like to be involved with code reviews periodically.

Make fails to build protobufs and mocks

Describe the bug
This issue covers two build-related bugs caused by our current Makefile, that break the building system.

First, recent versions of protoc-gen-go fail to build protobufs and grpc services. Apparently, this issue occurs after this release https://github.com/protocolbuffers/protobuf-go/releases/tag/v1.20.0, that states:

The v1.20 protoc-gen-go does not support generating gRPC service definitions. In the future, gRPC service generation will be supported by a new protoc-gen-go-grpc plugin provided by the Go gRPC project.

Second, cat gets called out of context whereas it should be invoked only during the generation of mocks. This leads to a failure of cat because it runs in parallel while downloading the new proto files. Overall, this leads to a failure in building the mocks. This issue can be mitigated by calling make protos prior to make mocks, instead of running make directly.

How to reproduce it
Running make clean, and then make, prompts this output:

$ make
cat: pkg/api/outputs/outputs.proto: No such file or directory
cat: pkg/api/version/version.proto: No such file or directory
pkg/api/schema/schema.proto: OK
--go_out: protoc-gen-go: plugins are not supported; use 'protoc --go-grpc_out=...' to generate gRPC
make: *** [Makefile:41: pkg/api/schema/schema.proto] Error 1

In this output, the first issue is visible in the error message that forces the make command to exit. Instead, the second issue is visible in the first lines that run cat, which is supposed to be ran only after finishing downloading the proto file and running proto-gen-go. As such, even if the protobuf generation succeds (through some hacky fix), then mockgen command fails too.

Expected behaviour
Running make clean && make remove the current built files, download the proto files, generate the protobufs, and generate the mocks.

Environment

  • OS:
NAME="Ubuntu"
VERSION="20.04.3 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.3 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
Linux ubuntu-focal 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
  • go version go1.17 linux/amd64
  • libprotoc 3.12.4
  • protoc-gen-go v1.23.0

Move to google.golang.org/protobuf

Describe the bug

Right now we use the v1 of protobufs in go. That is deprecated and we need to move to v2.

https://blog.golang.org/protobuf-apiv2

How to reproduce it

Expected behaviour

Screenshots

Environment

  • Falco version:
  • System info:
  • Cloud provider or hardware configuration:
  • OS:
  • Kernel:
  • Installation method:

Additional context

Provide a RELEASE.md

Motivation

Should we (soft) pair the client-go version with the Falco (API) one?

Feature

We'll soon have to release this lib and we need to write down the workflow.

Support the new Falco version API

Motivation

Falco is soon providing a new gRPC endpoint to let clients obtains its version (also, in parts: major, minor, patch, prerelease, build).

The PR containing this feature is falcosecurity/falco#872.

Feature

Write a client and examples for it.

Automated releases

What would you like to be added:
Instead of doing releases manually, we want do to them automatically.
Goreleaser does that job very well.

Goreleaser website:
https://goreleaser.com

Why is this needed:

Manual releases are a pain

Make TLS enabled by default

What would you like to be added:

We want to make TLS enabled by default since as proposed the gRPC server will have TLS enabled by default once the implementation is finished.

Why is this needed:

Because we want TLS enabled by default.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.