Using RBAC Network Filter to block ingress or egress to/from service in Envoy Proxy

9/25/2018

I want to try and configure a Filter in Envoy Proxy to block ingress and egress to the service based on some IP's, hostname, routing table, etc.

I have searched for the documentation and see it's possible. But didn't get any examples, of its usage.

Can someone point out some example of how It can be done?

I have figured out something like this:

network_filters:
   - name: service-access
     config: 
        rules: 
           action: ALLOW
           policies:
             "service-access":
                 principals:
                    source_ip: 192.168.135.211
                 permissions:
                    - destination_ip: 0.0.0.0
                    - destination_port: 443

But I am not able to apply this network filter. All the configurations give me configuration error.

-- Ashu
envoyproxy
kubernetes

2 Answers

10/1/2018

This is a complete rbac filter config given to me by envoy team in their guthub issue. Haven't tested it out though.

static_resources:
      listeners:
      - name: "ingress listener"
        address:
          socket_address:
            address: 0.0.0.0
            port_value: 9001
        filter_chains:
          filters:
          - name: envoy.http_connection_manager
            config:
              codec_type: auto
              stat_prefix: ingress_http
              route_config:
                name: local_route
                virtual_hosts:
                - name: local_service
                  domains:
                  - "*"
                  routes:
                  - match:
                      prefix: "/"  
                    route:
                      cluster: local_service
                    per_filter_config:
                      envoy.filters.http.rbac:
                        rbac:
                          rules:
                            action: ALLOW
                            policies:
                              "per-route-rule":
                                permissions:
                                - any: true
                                principals:
                                - any: true
              http_filters:
              - name: envoy.filters.http.rbac 
                config: 
                  rules: 
                    action: ALLOW
                    policies:
                      "general-rules":
                        permissions:
                        - any: true
                        principals:
                        - any: true
              - name: envoy.router
                config: {}
              access_log:
                name: envoy.file_access_log
                config: {path: /dev/stdout}

      clusters:
      - name: local_service
        connect_timeout: 0.250s
        type: static
        lb_policy: round_robin
        http2_protocol_options: {}
        hosts:
        - socket_address:
            address: 127.0.0.1
            port_value: 9000

    admin:
      access_log_path: "/dev/null"
      address:
        socket_address:
          address: 0.0.0.0
          port_value: 8080
-- Ashu
Source: StackOverflow

9/26/2018

I would recommend Istio. You can set up a Rule that will deny all traffic not originating from 192.168.0.1 IP.

apiVersion: "config.istio.io/v1alpha2"
kind: denier
metadata:
  name: denyreviewsv3handler
spec:
  status:
    code: 7
    message: Not allowed
---
apiVersion: "config.istio.io/v1alpha2"
kind: checknothing
metadata:
  name: denyreviewsv3request
spec:
---
apiVersion: "config.istio.io/v1alpha2"
kind: rule
metadata:
  name: denyreviewsv3
spec:
  match: source.ip != ip("192.168.0.1")
  actions:
  - handler: denyreviewsv3handler.denier
    instances: [ denyreviewsv3request.checknothing ]

You can match other attributes specified in Attribute Vocabulary, for example, block curl command match: match(request.headers["user-agent"], "curl*")

More about Traffic Management and Denials and White/Black Listing can be found in Istio documentation. I can also recommend you this istio-workshop published by szihai.

-- Crou
Source: StackOverflow