Giter Site home page Giter Site logo

modsecurity-envoy's Introduction

ModSecurity-envoy

The ModSecurity-Envoy is Envoy version compiled with HTTP filter (can be opt-in/out) running ModSecurity (V3). In other words you can run and configure WAF (ModSecurity) rules on HTTP Traffic that flows through envoy.

The most common use case is for ModSecurity-Envoy is to apply WAF on East-West traffic inside kubernetes deployments. As Envoy is the de-facto standard proxy in kubernetes deployments and is usually deployed in every pod you can deploy this Envoy version and Enable ModSecurity-Envoy Filter on all pods or on the most important ones.

Some of the ideas behind the project are described in this blog

Compilation

Dependencies

ModSecurity-Envoy depends on Envoy (as a git submodule) and ModSecurity (a sibling directory). The modsecurity directory contains two symbolic links to the sibling directory.

git clone [email protected]:octarinesec/ModSecurity-envoy.git
git clone [email protected]:SpiderLabs/ModSecurity.git

cd ModSecurity-envoy
git submodule update --init

The directory structure should be as follows:

.
+-- ModSecurity-envoy
|  +-- modsecurity
|  |  +-- include -> ../../ModSecurity/headers
|  |  +-- libmodsecurity.a -> ../../ModSecurity/src/.libs/libmodsecurity.a
+-- ModSecurity

For more details on how to compile ModSecurity read ModSecurity's documentation.

Compiling on host

You can compile ModSecurity-Envoy on host, the same as you would compile Envoy. However, you will need these additional dependencies:

sudo apt-get install -y libtool cmake realpath clang-format-5.0 automake 
sudo apt-get install -y g++ flex bison curl doxygen libyajl-dev libgeoip-dev libtool dh-autoreconf libcurl4-gnutls-dev libxml2 libpcre++-dev libxml2-dev

To build run

bazel build //:envoy

For more information on envoy's building system read Envoy's documentation.

Using the docker images

You can build docker images for envoy-build and envoy See ci/README.md

Configuration

ModSecurity-Envoy Filter accept the configuration defined in http_filter.proto

You will need to modify the Envoy config file to add the filter to the filter chain for a particular HTTP route configuration. See the examples in conf.

Note: By adding metadata to specific routes, you can have granular control to disable the filter:

metadata:
filter_metadata:
    envoy.filters.http.modsecurity:
      # To only disable requests / responses processing
      # disable_request: true
      # disable_response: true
      # Or, as a shorthand, use disable to disable both
      disable: true

The configuration for the filter is provided under the http_filters:

        http_filters:
        # before envoy.router because order matters!
        - name: envoy.filters.http.modsecurity
          config:
            # ModSecurity rules can either be provided by a path
            rules_path: /etc/modsecurity.conf
            # Additionally you can provide inline rules (will be loaded after processing the rules_path, if provided)
            rules_inline: |
              # ModSecurity rules
              # ...
            # Optionally, you can provide a webhook configuration
            webhook:
              # The http_uri field is mandatory
              http_uri:
                uri: http://localhost:10000/wh_callback
                cluster: service2
                timeout:
                  seconds: 3
              # Optionally you can provide a secret to sign the webhooks with an HMAC-256 (for more information see the .proto file)
              secret: webhook_secret
        - name: envoy.router
          config: {}

OWASP ModSecurity Core Rule Set (CRS)

CRS is a set of generic attack detection rules for use with ModSecurity and aims to protect web applications from wide range of attacks. For more information check out https://modsecurity.org/crs/

Download and extract the latest rules to the directory.

wget https://github.com/SpiderLabs/owasp-modsecurity-crs/archive/v3.1.1.tar.gz
tar xvzf v3.1.1.tar.gz

The configuration examples include the relevant OWASP rules. See ./conf/modsecurity.conf and ./conf/lds.yaml for usage example.

Testing

TODO

How it works

First let's run an echo server that we will use as our upstream

docker run -p 5555:80 kennethreitz/httpbin

Now let's run the envoy

sudo ./bazel-bin/envoy-static -c conf/envoy-modsecurity-example-lds.yaml -l info

Make our first request

curl -X GET "http://127.0.0.1:8585/get" -H "accept: application/json"

Let's download Nikto which is the most popular Open Source web server scanner

wget https://github.com/sullo/nikto/archive/master.zip
unzip master.zip
perl nikto-master/program/nikto.pl -h localhost:5555

Now we can cat /var/log/modsec_audit.log and see all detected attacks which in production can be piped to a SIEM of your choice or any other centralized log.

Let's try and add our own RULE as each WAF are designed to be configurable to protect different web applications.

Make sure the following line is in modsecurity-example.conf or in the configuration under rules_inline.

SecRule ARGS:param1 "test" "id:1,deny,msg:'this',msg:'is',msg:'a',msg:'test'"

This line will detect any url with argument ?param1=test param.

reload Envoy's configuration and execute the following command curl -X GET "http://127.0.0.1:8585/get?param1=test" -H "accept: application/json"

check the logs via tail -f and you will see the following output

ModSecurity: Warning. Matched "Operator `Rx' with parameter `test' against variable `ARGS:param1' (Value: `test' ) [file "crs-setup.conf"] [line "7"] [id "1"] [rev ""] [msg "test"] [data ""] [severity "0"] [ver ""] [maturity "0"] [accuracy "0"] [hostname ""] [uri "/"] [unique_id "152991475598.002681"] [ref "o0,4v13,4"]

If we have a webhook installed, triggering a rule will result in a similar request:

POST /wh_callback
Headers:
host: localhost:10000
content-type: application/json
content-length: 530
x-envoy-webhook-signature-type: HMAC-SHA256
x-envoy-webhook-signature-value: d7c224c82cee677e32dc3ae0d2e60fae5a0c9714613b55bd0791fd226d8f22e7
x-envoy-internal: true
x-envoy-expected-rq-timeout-ms: 3000

{"accuracy": 0, "clientIpAddress": "127.0.0.1", "data": "", "id": "156690498720.063187", "isDisruptive": false, "match": "Matched \"Operator `Rx' with parameter `test' against variable `ARGS:param1' (Value: `test' )", "maturity": 0, "message": "Test rule", "noAuditLog": false, "phase": 1, "reference": "o0,4v13,4", "rev": "", "ruleFile": "<<reference missing or not informed>>", "ruleId": 1, "ruleLine": 6, "saveMessage": true, "serverIpAddress": "127.0.0.1", "severity": 0, "uriNoQueryStringDecoded": "/", "ver": "", "tags": []}

modsecurity-envoy's People

Contributors

roekatz avatar thehh1974 avatar yevgenypats avatar yoshpe avatar

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  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  avatar  avatar  avatar  avatar

modsecurity-envoy's Issues

Envoy 1.7.1 compile

Hi, I am having some issues compiling this using the provided guide in the README.md with 1.7.1.

Starting local Bazel server and connecting to it...
DEBUG: /home/master/.cache/bazel/_bazel_master/dade022b46ca8a8ec61a5f966e5c06df/external/io_bazel_rules_go/proto/def.bzl:138:3: You no longer need to call proto_register_toolchains(), it does nothing
External dependency cache directory /home/master/.cache/bazel/_bazel_master/dade022b46ca8a8ec61a5f966e5c06df/external/envoy_deps_cache_2c744dffd279d7e9e0910ce594eb4f4f
make: Entering directory '/home/master/.cache/bazel/_bazel_master/dade022b46ca8a8ec61a5f966e5c06df/external/envoy_deps'
No need to rebuild /home/master/.cache/bazel/_bazel_master/dade022b46ca8a8ec61a5f966e5c06df/external/envoy_deps_cache_2c744dffd279d7e9e0910ce594eb4f4f/cares.dep.env
No need to rebuild /home/master/.cache/bazel/_bazel_master/dade022b46ca8a8ec61a5f966e5c06df/external/envoy_deps_cache_2c744dffd279d7e9e0910ce594eb4f4f/libevent.dep.env
No need to rebuild /home/master/.cache/bazel/_bazel_master/dade022b46ca8a8ec61a5f966e5c06df/external/envoy_deps_cache_2c744dffd279d7e9e0910ce594eb4f4f/gperftools.dep.env
No need to rebuild /home/master/.cache/bazel/_bazel_master/dade022b46ca8a8ec61a5f966e5c06df/external/envoy_deps_cache_2c744dffd279d7e9e0910ce594eb4f4f/yaml-cpp.dep.env
No need to rebuild /home/master/.cache/bazel/_bazel_master/dade022b46ca8a8ec61a5f966e5c06df/external/envoy_deps_cache_2c744dffd279d7e9e0910ce594eb4f4f/benchmark.dep.env
No need to rebuild /home/master/.cache/bazel/_bazel_master/dade022b46ca8a8ec61a5f966e5c06df/external/envoy_deps_cache_2c744dffd279d7e9e0910ce594eb4f4f/luajit.dep.env
No need to rebuild /home/master/.cache/bazel/_bazel_master/dade022b46ca8a8ec61a5f966e5c06df/external/envoy_deps_cache_2c744dffd279d7e9e0910ce594eb4f4f/nghttp2.dep.env
No need to rebuild /home/master/.cache/bazel/_bazel_master/dade022b46ca8a8ec61a5f966e5c06df/external/envoy_deps_cache_2c744dffd279d7e9e0910ce594eb4f4f/zlib.dep.env
make: Leaving directory '/home/master/.cache/bazel/_bazel_master/dade022b46ca8a8ec61a5f966e5c06df/external/envoy_deps'

real	0m0.045s
user	0m0.015s
sys	0m0.011s
DEBUG: /home/master/.cache/bazel/_bazel_master/dade022b46ca8a8ec61a5f966e5c06df/external/envoy/bazel/repositories.bzl:76:5: Fetching external dependencies...
DEBUG: /home/master/.cache/bazel/_bazel_master/dade022b46ca8a8ec61a5f966e5c06df/external/envoy/bazel/repositories.bzl:82:5: 
DEBUG: /home/master/.cache/bazel/_bazel_master/dade022b46ca8a8ec61a5f966e5c06df/external/envoy/bazel/repositories.bzl:83:5: External dependency cache directory /home/master/.cache/bazel/_bazel_master/dade022b46ca8a8ec61a5f966e5c06df/external/envoy_deps_cache_2c744dffd279d7e9e0910ce594eb4f4f
make: Entering directory '/home/master/.cache/bazel/_bazel_master/dade022b46ca8a8ec61a5f966e5c06df/external/envoy_deps'
No need to rebuild /home/master/.cache/bazel/_bazel_master/dade022b46ca8a8ec61a5f966e5c06df/external/envoy_deps_cache_2c744dffd279d7e9e0910ce594eb4f4f/cares.dep.env
No need to rebuild /home/master/.cache/bazel/_bazel_master/dade022b46ca8a8ec61a5f966e5c06df/external/envoy_deps_cache_2c744dffd279d7e9e0910ce594eb4f4f/libevent.dep.env
No need to rebuild /home/master/.cache/bazel/_bazel_master/dade022b46ca8a8ec61a5f966e5c06df/external/envoy_deps_cache_2c744dffd279d7e9e0910ce594eb4f4f/gperftools.dep.env
No need to rebuild /home/master/.cache/bazel/_bazel_master/dade022b46ca8a8ec61a5f966e5c06df/external/envoy_deps_cache_2c744dffd279d7e9e0910ce594eb4f4f/yaml-cpp.dep.env
No need to rebuild /home/master/.cache/bazel/_bazel_master/dade022b46ca8a8ec61a5f966e5c06df/external/envoy_deps_cache_2c744dffd279d7e9e0910ce594eb4f4f/benchmark.dep.env
No need to rebuild /home/master/.cache/bazel/_bazel_master/dade022b46ca8a8ec61a5f966e5c06df/external/envoy_deps_cache_2c744dffd279d7e9e0910ce594eb4f4f/luajit.dep.env
No need to rebuild /home/master/.cache/bazel/_bazel_master/dade022b46ca8a8ec61a5f966e5c06df/external/envoy_deps_cache_2c744dffd279d7e9e0910ce594eb4f4f/nghttp2.dep.env
No need to rebuild /home/master/.cache/bazel/_bazel_master/dade022b46ca8a8ec61a5f966e5c06df/external/envoy_deps_cache_2c744dffd279d7e9e0910ce594eb4f4f/zlib.dep.env
make: Leaving directory '/home/master/.cache/bazel/_bazel_master/dade022b46ca8a8ec61a5f966e5c06df/external/envoy_deps'

real	0m0.045s
user	0m0.015s
sys	0m0.011s
DEBUG: /home/master/.cache/bazel/_bazel_master/dade022b46ca8a8ec61a5f966e5c06df/external/envoy/bazel/repositories.bzl:84:5: External dep build exited with return code: 0
WARNING: /home/master/.cache/bazel/_bazel_master/dade022b46ca8a8ec61a5f966e5c06df/external/com_github_grpc_grpc/BUILD:1972:1: in srcs attribute of cc_library rule @com_github_grpc_grpc//:grpc_nanopb: please do not import '@com_github_grpc_grpc//third_party/nanopb:pb_common.c' directly. You should either move the file to this package or depend on an appropriate rule there. Since this rule was created by the macro 'grpc_generate_one_off_targets', the error might have been caused by the macro implementation in /home/master/.cache/bazel/_bazel_master/dade022b46ca8a8ec61a5f966e5c06df/external/com_github_grpc_grpc/bazel/grpc_build_system.bzl:172:12
WARNING: /home/master/.cache/bazel/_bazel_master/dade022b46ca8a8ec61a5f966e5c06df/external/com_github_grpc_grpc/BUILD:1972:1: in srcs attribute of cc_library rule @com_github_grpc_grpc//:grpc_nanopb: please do not import '@com_github_grpc_grpc//third_party/nanopb:pb_decode.c' directly. You should either move the file to this package or depend on an appropriate rule there. Since this rule was created by the macro 'grpc_generate_one_off_targets', the error might have been caused by the macro implementation in /home/master/.cache/bazel/_bazel_master/dade022b46ca8a8ec61a5f966e5c06df/external/com_github_grpc_grpc/bazel/grpc_build_system.bzl:172:12
WARNING: /home/master/.cache/bazel/_bazel_master/dade022b46ca8a8ec61a5f966e5c06df/external/com_github_grpc_grpc/BUILD:1972:1: in srcs attribute of cc_library rule @com_github_grpc_grpc//:grpc_nanopb: please do not import '@com_github_grpc_grpc//third_party/nanopb:pb_encode.c' directly. You should either move the file to this package or depend on an appropriate rule there. Since this rule was created by the macro 'grpc_generate_one_off_targets', the error might have been caused by the macro implementation in /home/master/.cache/bazel/_bazel_master/dade022b46ca8a8ec61a5f966e5c06df/external/com_github_grpc_grpc/bazel/grpc_build_system.bzl:172:12
INFO: Analysed target //http-filter-modsecurity:envoy (290 packages loaded).
INFO: Found 1 target...
ERROR: /home/master/ModSecurity-envoy/http-filter-modsecurity/BUILD:13:1: Linking of rule '//http-filter-modsecurity:envoy' failed (Exit 1)
/usr/bin/ld.gold: error: http-filter-modsecurity/libmodsecurity.a:1:9: syntax error, unexpected STRING
/usr/bin/ld.gold: error: http-filter-modsecurity/libmodsecurity.a: not an object or archive
bazel-out/k8-fastbuild/bin/http-filter-modsecurity/_objs/http_filter_lib/http_filter.pic.o:http_filter.cc:function Envoy::Http::HttpModSecurityFilterConfig::HttpModSecurityFilterConfig(modsecurity::Decoder const&): error: undefined reference to 'modsecurity::ModSecurity::ModSecurity()'
bazel-out/k8-fastbuild/bin/http-filter-modsecurity/_objs/http_filter_lib/http_filter.pic.o:http_filter.cc:function Envoy::Http::HttpModSecurityFilterConfig::HttpModSecurityFilterConfig(modsecurity::Decoder const&): error: undefined reference to 'modsecurity::ModSecurity::setConnectorInformation(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
bazel-out/k8-fastbuild/bin/http-filter-modsecurity/_objs/http_filter_lib/http_filter.pic.o:http_filter.cc:function Envoy::Http::HttpModSecurityFilterConfig::HttpModSecurityFilterConfig(modsecurity::Decoder const&): error: undefined reference to 'modsecurity::ModSecurity::setServerLogCb(void (*)(void*, void const*), int)'
bazel-out/k8-fastbuild/bin/http-filter-modsecurity/_objs/http_filter_lib/http_filter.pic.o:http_filter.cc:function Envoy::Http::HttpModSecurityFilterConfig::HttpModSecurityFilterConfig(modsecurity::Decoder const&): error: undefined reference to 'modsecurity::Rules::loadFromUri(char const*)'
bazel-out/k8-fastbuild/bin/http-filter-modsecurity/_objs/http_filter_lib/http_filter.pic.o:http_filter.cc:function Envoy::Http::HttpModSecurityFilter::HttpModSecurityFilter(std::shared_ptr<Envoy::Http::HttpModSecurityFilterConfig>): error: undefined reference to 'modsecurity::Transaction::Transaction(modsecurity::ModSecurity*, modsecurity::Rules*, void*)'
bazel-out/k8-fastbuild/bin/http-filter-modsecurity/_objs/http_filter_lib/http_filter.pic.o:http_filter.cc:function Envoy::Http::HttpModSecurityFilter::~HttpModSecurityFilter(): error: undefined reference to 'modsecurity::Transaction::~Transaction()'
bazel-out/k8-fastbuild/bin/http-filter-modsecurity/_objs/http_filter_lib/http_filter.pic.o:http_filter.cc:function Envoy::Http::HttpModSecurityFilterConfig::~HttpModSecurityFilterConfig(): error: undefined reference to 'modsecurity::ModSecurity::~ModSecurity()'
bazel-out/k8-fastbuild/bin/http-filter-modsecurity/_objs/http_filter_lib/http_filter.pic.o:http_filter.cc:function Envoy::Http::HttpModSecurityFilter::onDestroy(): error: undefined reference to 'modsecurity::Transaction::processLogging()'
bazel-out/k8-fastbuild/bin/http-filter-modsecurity/_objs/http_filter_lib/http_filter.pic.o:http_filter.cc:function Envoy::Http::HttpModSecurityFilter::decodeHeaders(Envoy::Http::HeaderMap&, bool)::{lambda(Envoy::Http::HeaderEntry const&, void*)#1}::operator()(Envoy::Http::HeaderEntry const&, void*) const: error: undefined reference to 'modsecurity::Transaction::addRequestHeader(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
bazel-out/k8-fastbuild/bin/http-filter-modsecurity/_objs/http_filter_lib/http_filter.pic.o:http_filter.cc:function Envoy::Http::HttpModSecurityFilter::decodeHeaders(Envoy::Http::HeaderMap&, bool): error: undefined reference to 'modsecurity::Transaction::processURI(char const*, char const*, char const*)'
bazel-out/k8-fastbuild/bin/http-filter-modsecurity/_objs/http_filter_lib/http_filter.pic.o:http_filter.cc:function Envoy::Http::HttpModSecurityFilter::decodeHeaders(Envoy::Http::HeaderMap&, bool): error: undefined reference to 'modsecurity::Transaction::processRequestHeaders()'
bazel-out/k8-fastbuild/bin/http-filter-modsecurity/_objs/http_filter_lib/http_filter.pic.o:http_filter.cc:function Envoy::Http::HttpModSecurityFilter::decodeData(Envoy::Buffer::Instance&, bool): error: undefined reference to 'modsecurity::Transaction::appendRequestBody(unsigned char const*, unsigned long)'
bazel-out/k8-fastbuild/bin/http-filter-modsecurity/_objs/http_filter_lib/http_filter.pic.o:http_filter.cc:function Envoy::Http::HttpModSecurityFilter::decodeData(Envoy::Buffer::Instance&, bool): error: undefined reference to 'modsecurity::Transaction::processRequestBody()'
bazel-out/k8-fastbuild/bin/http-filter-modsecurity/_objs/http_filter_lib/http_filter.pic.o:http_filter.cc:function Envoy::Http::HttpModSecurityFilter::encodeHeaders(Envoy::Http::HeaderMap&, bool)::{lambda(Envoy::Http::HeaderEntry const&, void*)#1}::operator()(Envoy::Http::HeaderEntry const&, void*) const: error: undefined reference to 'modsecurity::Transaction::addResponseHeader(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
bazel-out/k8-fastbuild/bin/http-filter-modsecurity/_objs/http_filter_lib/http_filter.pic.o:http_filter.cc:function Envoy::Http::HttpModSecurityFilter::encodeHeaders(Envoy::Http::HeaderMap&, bool): error: undefined reference to 'modsecurity::Transaction::processResponseHeaders(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
bazel-out/k8-fastbuild/bin/http-filter-modsecurity/_objs/http_filter_lib/http_filter.pic.o:http_filter.cc:function Envoy::Http::HttpModSecurityFilter::encodeData(Envoy::Buffer::Instance&, bool): error: undefined reference to 'modsecurity::Transaction::appendResponseBody(unsigned char const*, unsigned long)'
bazel-out/k8-fastbuild/bin/http-filter-modsecurity/_objs/http_filter_lib/http_filter.pic.o:http_filter.cc:function Envoy::Http::HttpModSecurityFilter::encodeData(Envoy::Buffer::Instance&, bool): error: undefined reference to 'modsecurity::Transaction::processResponseBody()'
bazel-out/k8-fastbuild/bin/http-filter-modsecurity/_objs/http_filter_lib/http_filter.pic.o:http_filter.cc:function modsecurity::debug_log::DebugLog::DebugLog(): error: undefined reference to 'vtable for modsecurity::debug_log::DebugLog'
/usr/bin/ld.gold: the vtable symbol may be undefined because the class is missing its key function
bazel-out/k8-fastbuild/bin/http-filter-modsecurity/_objs/http_filter_lib/http_filter.pic.o:http_filter.cc:function modsecurity::RulesProperties::RulesProperties(modsecurity::debug_log::DebugLog*): error: undefined reference to 'modsecurity::audit_log::AuditLog::AuditLog()'
bazel-out/k8-fastbuild/bin/http-filter-modsecurity/_objs/http_filter_lib/http_filter.pic.o:http_filter.cc:function modsecurity::RulesProperties::RulesProperties(modsecurity::debug_log::DebugLog*): error: undefined reference to 'modsecurity::RulesExceptions::RulesExceptions()'
bazel-out/k8-fastbuild/bin/http-filter-modsecurity/_objs/http_filter_lib/http_filter.pic.o:http_filter.cc:function modsecurity::RulesProperties::RulesProperties(modsecurity::debug_log::DebugLog*): error: undefined reference to 'modsecurity::RulesExceptions::~RulesExceptions()'
bazel-out/k8-fastbuild/bin/http-filter-modsecurity/_objs/http_filter_lib/http_filter.pic.o:http_filter.cc:function modsecurity::RuleMessage::log[abi:cxx11](modsecurity::RuleMessage const*, int): error: undefined reference to 'modsecurity::RuleMessage::log[abi:cxx11](modsecurity::RuleMessage const*, int, int)'
collect2: error: ld returned 1 exit status
Target //http-filter-modsecurity:envoy failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 11.234s, Critical Path: 4.27s
INFO: 0 processes.
FAILED: Build did NOT complete successfully

[Question]: How Can I Set Custom Header with Rule Environment

Hi
I'm using modsecurity-envoy.
I'm trying set a header after rule action like below. But doesn't work. I'm not sure, Is this modsecurity issue or modsecurity-envoy issue or this configuration isn't right?

Rules

SecRule ARGS:json.isbn  "4545454" "id:4,phase:2,deny,status:400,setenv:ACTION=Blocked,msg:'Test JSON rule'"
Header set X-Action "%{ACTION}e" env=ACTION

Logs

[2019-09-11 07:38:12.912][23535][error][filter] [http-filter-modsecurity/http_filter.cc:36] Failed to load rules: Rules error. File: /root/ModSecurity-envoy/conf/modsecurity.conf. Line: 16. Column: 42. Invalid input:  Header set X-Action "%{ACTION}e" env=ACTION

Unable to see any audit or debug logs

After following the entire readme, I am still not able to see any logs in audit log or the debug log. I tried a couple of different HTTP filter config but nothing seems to print anything in the audit log.

Error building code on host

Thanks for creating this project.

Is there a pre-built docker image that is available for use? This would be preferable, if available.

I tried to build this from source following the instructions in README.md. I tried both the building via the CI container and building on the host. Are there particular version of toolchains and dependencies the build works with?

built using Clang 7.0.1 (tried with GCC 7 too but it did not get as far as clang did) and bazel 0.29.1 (higher versions of Bazel fail too). Error below

INFO: From Generating Descriptor Set proto_library @envoy_api//envoy/config/filter/http/rbac/v2:rbac:
external/com_google_protobuf: warning: directory does not exist.
ERROR: /home/test/envoy-modsecurity/ModSecurity-envoy/http-filter-modsecurity/BUILD:20:1: C++ compilation of rule '//http-filter-modsecurity:http_filter_lib' failed (Exit 1) envoy_cc_wrapper failed: error executing command /home/test/.cache/bazel/_bazel_test/c2e9e5f6ad8dc853e36159518115dacf/external/local_config_cc/extra_tools/envoy_cc_wrapper -U_FORTIFY_SOURCE -fstack-protector -Wall -Wthread-safety -Wself-assign ... (remaining 885 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
In file included from http-filter-modsecurity/http_filter.cc:5:
In file included from http-filter-modsecurity/http_filter.h:14:
In file included from modsecurity/include/modsecurity/rules.h:29:
modsecurity/include/modsecurity/rule.h:68:7: error: 'modsecurity::Rule' has virtual functions but non-virtual destructor [-Werror,-Wnon-virtual-dtor]
class Rule {
^
In file included from http-filter-modsecurity/http_filter.cc:5:
In file included from http-filter-modsecurity/http_filter.h:14:
In file included from modsecurity/include/modsecurity/rules.h:30:
In file included from modsecurity/include/modsecurity/rule_with_operator.h:32:
modsecurity/include/modsecurity/rule_with_actions.h:46:5: error: 'modsecurity::RuleWithActions' has virtual functions but non-virtual destructor [-Werror,-Wnon-virtual-dtor]
~RuleWithActions();
^
In file included from http-filter-modsecurity/http_filter.cc:5:
In file included from http-filter-modsecurity/http_filter.h:14:
modsecurity/include/modsecurity/rules.h:44:27: error: comparison of integers of different signs: 'int' and 'std::vector::size_type' (aka 'unsigned long') [-Werror,-Wsign-compare]
for (int j = 0; j < m_rules.size(); j++) {
~ ^ ~~~~~~~~~~~~~~
http-filter-modsecurity/http_filter.cc:33:42: error: no member named 'loadFromUri' in 'modsecurity::Rules'
int rulesLoaded = modsec_rules_->loadFromUri(rules_path().c_str());
~~~~~~~~~~~~~ ^
http-filter-modsecurity/http_filter.cc:36:73: error: no member named 'getParserError' in 'modsecurity::Rules'
ENVOY_LOG(error, "Failed to load rules: {}", modsec_rules_->getParserError());
~~~~~~~~~~~~~ ^
bazel-out/k8-fastbuild/bin/external/envoy/source/common/common/virtual_includes/minimal_logger_lib/common/common/logger.h:334:76: note: expanded from macro 'ENVOY_LOG'
#define ENVOY_LOG(LEVEL, ...) ENVOY_LOG_TO_LOGGER(ENVOY_LOGGER(), LEVEL, ##VA_ARGS)
^~~~~~~~~~~
bazel-out/k8-fastbuild/bin/external/envoy/source/common/common/virtual_includes/minimal_logger_lib/common/common/logger.h:319:89: note: expanded from macro 'ENVOY_LOG_TO_LOGGER'
#define ENVOY_LOG_TO_LOGGER(LOGGER, LEVEL, ...) ENVOY_LOG_COMP_AND_LOG(LOGGER, LEVEL, ##VA_ARGS)
^~~~~~~~~~~
bazel-out/k8-fastbuild/bin/external/envoy/source/common/common/virtual_includes/minimal_logger_lib/common/common/logger.h:307:31: note: expanded from macro 'ENVOY_LOG_COMP_AND_LOG'
LOGGER.LEVEL(LOG_PREFIX VA_ARGS);
^~~~~~~~~~~
http-filter-modsecurity/http_filter.cc:42:42: error: no member named 'load' in 'modsecurity::Rules'
int rulesLoaded = modsec_rules
->load(rules_inline().c_str());
~~~~~~~~~~~~~ ^
http-filter-modsecurity/http_filter.cc:45:73: error: no member named 'getParserError' in 'modsecurity::Rules'
ENVOY_LOG(error, "Failed to load rules: {}", modsec_rules
->getParserError());
~~~~~~~~~~~~~ ^
bazel-out/k8-fastbuild/bin/external/envoy/source/common/common/virtual_includes/minimal_logger_lib/common/common/logger.h:334:76: note: expanded from macro 'ENVOY_LOG'
#define ENVOY_LOG(LEVEL, ...) ENVOY_LOG_TO_LOGGER(ENVOY_LOGGER(), LEVEL, ##VA_ARGS)
^~~~~~~~~~~
bazel-out/k8-fastbuild/bin/external/envoy/source/common/common/virtual_includes/minimal_logger_lib/common/common/logger.h:319:89: note: expanded from macro 'ENVOY_LOG_TO_LOGGER'
#define ENVOY_LOG_TO_LOGGER(LOGGER, LEVEL, ...) ENVOY_LOG_COMP_AND_LOG(LOGGER, LEVEL, ##VA_ARGS)
^~~~~~~~~~~
bazel-out/k8-fastbuild/bin/external/envoy/source/common/common/virtual_includes/minimal_logger_lib/common/common/logger.h:307:31: note: expanded from macro 'ENVOY_LOG_COMP_AND_LOG'
LOGGER.LEVEL(LOG_PREFIX VA_ARGS);
^~~~~~~~~~~
http-filter-modsecurity/http_filter.cc:77:35: error: no matching constructor for initialization of 'modsecurity::Transaction'
modsec_transaction
.reset(new modsecurity::Transaction(config
->modsec
.get(), config
->modsec_rules_.get(), this));
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
modsecurity/include/modsecurity/transaction.h:322:5: note: candidate constructor not viable: no known conversion from 'std::_shared_ptr<modsecurity::Rules, gnu_cxx::S_atomic>::element_type *' (aka 'modsecurity::Rules *') to 'modsecurity::RulesSet *' for 2nd argument
Transaction(ModSecurity *transaction, RulesSet *rules, void *logCbData);
^
modsecurity/include/modsecurity/transaction.h:323:5: note: candidate constructor not viable: requires 4 arguments, but 3 were provided
Transaction(ModSecurity *transaction, RulesSet *rules, char *id,
^
modsecurity/include/modsecurity/transaction.h:327:5: note: candidate constructor not viable: requires 1 argument, but 3 were provided
Transaction ( const Transaction & ) = delete;
^
http-filter-modsecurity/http_filter.cc:326:77: error: no member named 'EnabledRuleEngine' in 'modsecurity::Rules'
return modsec_transaction
->getRuleEngineState() == modsecurity::Rules::EnabledRuleEngine ?
~~~~~~~~~~~~~~~~~~~~^
http-filter-modsecurity/http_filter.cc:342:77: error: no member named 'EnabledRuleEngine' in 'modsecurity::Rules'
return modsec_transaction
->getRuleEngineState() == modsecurity::Rules::EnabledRuleEngine ?
~~~~~~~~~~~~~~~~~~~~^
http-filter-modsecurity/http_filter.cc:355:77: error: no member named 'EnabledRuleEngine' in 'modsecurity::Rules'
return modsec_transaction
->getRuleEngineState() == modsecurity::Rules::EnabledRuleEngine ?
~~~~~~~~~~~~~~~~~~~~^
http-filter-modsecurity/http_filter.cc:368:77: error: no member named 'EnabledRuleEngine' in 'modsecurity::Rules'
return modsec_transaction
->getRuleEngineState() == modsecurity::Rules::EnabledRuleEngine ?
~~~~~~~~~~~~~~~~~~~~^
12 errors generated.
Target //:envoy-static failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 2339.942s, Critical Path: 38.58s
INFO: 1984 processes: 1984 linux-sandbox.
FAILED: Build did NOT complete successfully

Add to upstream Envoy?

Hello! ๐Ÿ‘‹

This is a pretty cool project! I was wondering if there are plans to add this filter to the upstream Envoy codebase where it'll be actively maintained against the latest API's, dependencies, etc. and make it more accessible to others?

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.