Coder Social home page Coder Social logo

anchorfree / fluentbit-ip-cleanup-filter Goto Github PK

View Code? Open in Web Editor NEW
4.0 8.0 1.0 75 KB

Fluent-bit filter plugin written in Lua to anonymize IPv4 and IPv6 addresses from log records

License: Apache License 2.0

Makefile 2.90% Lua 97.10%
fluent-bit logging lua plugin docker kubernetes team-kyiv-devops project-logging

fluentbit-ip-cleanup-filter's Introduction

Provides a Lua filter for fluent-bit to anonymize IPv4 and IPv6 addresses from log records.

Motivation

Most filters and plugins from fluent-bit/fluentd ecosystem assume a prior knowledge of the structure of incoming log records. However, in environment with multiple sources of logs which are not under your control, there is no way to know upfront the key names or spectrum of possible values (i.e. how IP address is enclosed in the value: simple <ipaddr> or <ipaddr>:<port> or even <some-data><ipaddr><some-data>). Thus, there is no way to apply a default fluent-bit's Modify filter or any of the myriad of fluentd plugins to solve given problem.

fluentbit-ip-cleanup-filter implements fluent-bit's Lua filter plugin that finds all IPv4 and IPv6 entries in the record (no matter of it's structure) using LPeg and replaces them with values provided in configuration.

Benchmarks

Section in progress

Usage

Docker

  • Clone this repo and cd into it
  • Run fluent-bit with the sample configuration (fluent-bit.conf) mounting current directory inside container:
# Contents of fluent-bit.conf
[INPUT]
    Name   dummy
    Dummy {"ipPort":"127.0.0.1:3233", "email":"[email protected]"}
    Tag    dummy.log

[FILTER]
    Name            lua
    Match           *
    Protected_mode  false
    script          cleanup_ip.lua
    call            clean

[OUTPUT]
    Name   stdout
    Match  *
$ docker run -ti --rm -v $PWD:/fluent-bit/etc -e VENDOR_PATH="/fluent-bit/etc/" fluent/fluent-bit
Fluent Bit v1.4.6
* Copyright (C) 2019-2020 The Fluent Bit Authors
* Copyright (C) 2015-2018 Treasure Data
* Fluent Bit is a CNCF sub-project under the umbrella of Fluentd
* https://fluentbit.io

[2020/06/30 16:05:19] [ info] [storage] version=1.0.3, initializing...
[2020/06/30 16:05:19] [ info] [storage] in-memory
[2020/06/30 16:05:19] [ info] [storage] normal synchronization mode, checksum disabled, max_chunks_up=128
[2020/06/30 16:05:19] [ info] [engine] started (pid=1)
[2020/06/30 16:05:19] [ info] [sp] stream processor started
[0] dummy.log: [1593533120.216797700, {"ipPort"=>"0.0.0.0:3233", "email"=>"[email protected]"}]
[1] dummy.log: [1593533121.216744100, {"ipPort"=>"0.0.0.0:3233", "email"=>"[email protected]"}]
[2] dummy.log: [1593533122.217766100, {"ipPort"=>"0.0.0.0:3233", "email"=>"[email protected]"}]
[3] dummy.log: [1593533123.219193500, {"ipPort"=>"0.0.0.0:3233", "email"=>"[email protected]"}]

Kubernetes

Starting from v2.10.0, the official fluent-bit chart supports init containers via initContainers value. Below is the example of values.yaml that installs fluentbit-ip-cleanup-filter before starting fluent-bit:

env:
  # https://github.com/AnchorFree/fluentbit-ip-cleanup-filter#configuration
  - name: VENDOR_PATH
    value: &plugin_path /fluent-bit/plugins

extraVolumes:
  - name: &vol_name plugins
    emptyDir:
      medium: Memory
      sizeLimit: 5Mi

extraVolumeMounts:
  - name: *vol_name
    mountPath: *plugin_path

# https://docs.fluentbit.io/manual/pipeline/filters/lua
extraEntries:
  filter: |-
    [FILTER]
        Name            lua
        Match           *
        script          /fluent-bit/plugins/cleanup_ip.lua
        call            clean

initContainers:
  load-plugin:
    image: "appropriate/curl:latest"
    imagePullPolicy: "IfNotPresent"
    volumeMounts:
      - name: *vol_name
        mountPath: *plugin_path
    command:
      - "/bin/sh"
      - "-c"
      - |
        curl -sS https://codeload.github.com/AnchorFree/fluentbit-ip-cleanup-filter/zip/master -o /plugin.zip
        unzip /plugin.zip
        cp -av /fluentbit-ip-cleanup-filter-master/* /fluent-bit/plugins/

Configuration

It is possible to configure script parameters via environment variables:

VENDOR_PATH - path to ./vendor directory (relies on how volumes are mounted in container)
IPV4_REPL   - replacement for IPv4 addresses (default: 0.0.0.0)
IPV6_REPL   - replacement for IPv6 addresses (default: 0000:0000:0000:0000:0000:0000:0000:0000)

Compatibility

Requires at least fluent-bit v1.4.3 (supports code 2 for plugin return values).

Development

Update ./vendor

Currently containers from fluent/fluent-bit are running Lua 5.1 under Linux. Thus, ./vendor should be built under linux, using Lua 5.1 and luarocks:

$ luarocks install --tree vendor lpeg
$ luarocks install --tree vendor lpeg_patterns
$ luarocks install --tree vendor lunajson

Local development

Install dev dependencies:

$ make install-dev

Lint code (requires luacheck):

$ make lint

Format code (requires lua-format):

$ make format

Run tests:

$ make test

fluentbit-ip-cleanup-filter's People

Contributors

pavdmyt avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

pavdmyt

fluentbit-ip-cleanup-filter's Issues

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.