我想尝试在Envoy代理中配置一个过滤器,以基于某些IP,主机名,路由表等阻止对该服务的进出。
我已经搜索了文档,看到了可能。但没有得到任何使用实例。
有人可以指出如何做到这一点的例子吗?
此页面上存在一个配置示例: https://www.envoyproxy.io/docs/envoy/latest/api-v2/config/rbac/v2alpha/rbac.proto
最接近我想要的内容,我可以在此页面中看到:
https://www.envoyproxy.io/docs/envoy/latest/configuration/network_filters/rbac_filter#statistics
我发现了这样的东西:
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
但是我无法应用此网络过滤器。所有配置都会给我配置错误。
答案 0 :(得分:0)
我会推荐Istio。您可以设置一个Rule
,以拒绝所有不是源自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 ]
您可以匹配Attribute Vocabulary中指定的其他属性,例如,块curl
命令match: match(request.headers["user-agent"], "curl*")
有关Traffic Management和Denials and White/Black Listing的更多信息,请参见Istio文档。 我也可以向您推荐istio-workshop发布的szihai。
答案 1 :(得分:0)
这是特使团队在他们的guthub问题中提供给我的完整rbac过滤器配置。尚未测试过。
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