无法使用拒绝所有 GlobalNetworkPolicy 通过 Istio 连接到 EKS 上的应用程序
Unable to connect to application on EKS via Istio with deny-all GlobalNetworkPolicy
我的设置:运行 EKS 1.14 与 Calico 和 Istio 1.5。
正在尝试使用特定的 NetworkPolicies 运行 获取示例图书信息。
我应用了拒绝所有流量的 GlobalNetworkPolicy:
apiVersion: projectcalico.org/v3
kind: GlobalNetworkPolicy
metadata:
name: default-deny
spec:
selector: all()
types:
- Ingress
- Egress
我还为 Istio 添加了 GlobalNetworkPolicy 到命名空间和命名空间内流量:
apiVersion: projectcalico.org/v3
kind: GlobalNetworkPolicy
metadata:
name: allow-istio-system-to-ns
spec:
selector: all()
namespaceSelector: istio-injection == 'enabled'
types:
- Ingress
- Egress
ingress:
- action: Allow
source:
selector: all()
namespaceSelector: projectcalico.org/namespace == 'istio-system'
- action: Allow
source:
selector: all()
namespaceSelector: istio-injection == 'enabled'
egress:
- action: Allow
以及允许 istio 系统上所有入口和出口的 NetworkPolicy
apiVersion: projectcalico.org/v3
kind: NetworkPolicy
metadata:
name: allow-istio-system-all
namespace: istio-system
spec:
selector: all()
types:
- Ingress
- Egress
ingress:
- action: Allow
egress:
- action: Allow
还有一个 NetworkPolicy 允许流量进入端口 80 和 443 上的入口网关。我知道这个是多余的,但我希望将前一个减少到只有必要的入口。
apiVersion: projectcalico.org/v3
kind: NetworkPolicy
metadata:
name: allow-istio-ingress-on-80-443
namespace: istio-system
spec:
selector: app == 'istio-ingressgateway'
ingress:
- action: Allow
protocol: TCP
destination:
ports:
- 80
- 443
还有一些其他不相关的 NetworkPolicies(访问 kube-dns、metrics-server)。
部署 bookinfo 可以使用和不使用策略,部署网关也一样。
组件之间的连接有效(我可以执行一个 pod 并连接到其他 pod)。
但是当我尝试使用策略通过网关 access the productpage 时,我什么也得不到,而不是 HTML 我没有策略。
我是否遗漏了一些应该允许的流量?我应该为主节点或其他地方的负载均衡器制定政策吗?
编辑:如果我允许所有进入 istio 系统和命名空间,它就可以工作。所以我想我只是缺少来自命名空间的一些其他入口,有没有办法将它限制为仅负载均衡器?
首先你的 allow-istio-system-to-ns
yaml 中有一个拼写错误:
namespaceSelector: projectcalico.org/namespace == 'istio-system
行尾应该还有一个'
。
其次,这可能是由于 istio 版本 1.5
.
中策略和混合器的更改引起的
根据 Istio 文档:
The mixer policy is deprecated in Istio 1.5 and not recommended for production usage.
Rate limiting: Consider using Envoy native rate limiting instead of mixer rate limiting. Istio will add support for native rate limiting API through the Istio extensions API.
Control headers and routing: Consider using Envoy ext_authz
filter, lua
filter, or write a filter using the Envoy-wasm
sandbox.
Denials and White/Black Listing: Please use the Authorization Policy for enforcing access control to a workload.
istio 文档中有一个 guide 允许重新启用贬值的功能:
- Check the status of policy enforcement for your mesh.
$ kubectl -n istio-system get cm istio -o jsonpath="{@.data.mesh}" | grep disablePolicyChecks
disablePolicyChecks: true
If policy enforcement is enabled (disablePolicyChecks
is false), no further action is needed.
- Update the
istio
configuration to enable policy checks.
Execute the following command from the root Istio directory:
$ istioctl manifest apply --set values.global.disablePolicyChecks=false --set values.pilot.policy.enabled=true
configuration "istio" replaced
- Validate that policy enforcement is now enabled.
$ kubectl -n istio-system get cm istio -o jsonpath="{@.data.mesh}" | grep disablePolicyChecks
disablePolicyChecks: false
请注意,在 calico 文档中它说它需要以下 istio 版本:
Istio v1.0, v1.1, v1.2, or v1.3
希望对您有所帮助。
出于某种原因,当我用 istio-system 中的标签(例如 istio-injection=disabled
)替换 projectcalico.org/namespace == 'istio-system'
时,它似乎可以工作。
apiVersion: projectcalico.org/v3
kind: GlobalNetworkPolicy
metadata:
name: allow-istio-system-to-ns
spec:
selector: all()
namespaceSelector: istio-injection == 'enabled'
types:
- Ingress
- Egress
ingress:
- action: Allow
source:
selector: all()
namespaceSelector: istio-injection == 'disabled'
- action: Allow
source:
selector: all()
namespaceSelector: istio-injection == 'enabled'
egress:
- action: Allow
我的设置:运行 EKS 1.14 与 Calico 和 Istio 1.5。
正在尝试使用特定的 NetworkPolicies 运行 获取示例图书信息。
我应用了拒绝所有流量的 GlobalNetworkPolicy:
apiVersion: projectcalico.org/v3
kind: GlobalNetworkPolicy
metadata:
name: default-deny
spec:
selector: all()
types:
- Ingress
- Egress
我还为 Istio 添加了 GlobalNetworkPolicy 到命名空间和命名空间内流量:
apiVersion: projectcalico.org/v3
kind: GlobalNetworkPolicy
metadata:
name: allow-istio-system-to-ns
spec:
selector: all()
namespaceSelector: istio-injection == 'enabled'
types:
- Ingress
- Egress
ingress:
- action: Allow
source:
selector: all()
namespaceSelector: projectcalico.org/namespace == 'istio-system'
- action: Allow
source:
selector: all()
namespaceSelector: istio-injection == 'enabled'
egress:
- action: Allow
以及允许 istio 系统上所有入口和出口的 NetworkPolicy
apiVersion: projectcalico.org/v3
kind: NetworkPolicy
metadata:
name: allow-istio-system-all
namespace: istio-system
spec:
selector: all()
types:
- Ingress
- Egress
ingress:
- action: Allow
egress:
- action: Allow
还有一个 NetworkPolicy 允许流量进入端口 80 和 443 上的入口网关。我知道这个是多余的,但我希望将前一个减少到只有必要的入口。
apiVersion: projectcalico.org/v3
kind: NetworkPolicy
metadata:
name: allow-istio-ingress-on-80-443
namespace: istio-system
spec:
selector: app == 'istio-ingressgateway'
ingress:
- action: Allow
protocol: TCP
destination:
ports:
- 80
- 443
还有一些其他不相关的 NetworkPolicies(访问 kube-dns、metrics-server)。 部署 bookinfo 可以使用和不使用策略,部署网关也一样。
组件之间的连接有效(我可以执行一个 pod 并连接到其他 pod)。 但是当我尝试使用策略通过网关 access the productpage 时,我什么也得不到,而不是 HTML 我没有策略。
我是否遗漏了一些应该允许的流量?我应该为主节点或其他地方的负载均衡器制定政策吗?
编辑:如果我允许所有进入 istio 系统和命名空间,它就可以工作。所以我想我只是缺少来自命名空间的一些其他入口,有没有办法将它限制为仅负载均衡器?
首先你的 allow-istio-system-to-ns
yaml 中有一个拼写错误:
namespaceSelector: projectcalico.org/namespace == 'istio-system
行尾应该还有一个'
。
其次,这可能是由于 istio 版本 1.5
.
根据 Istio 文档:
The mixer policy is deprecated in Istio 1.5 and not recommended for production usage.
Rate limiting: Consider using Envoy native rate limiting instead of mixer rate limiting. Istio will add support for native rate limiting API through the Istio extensions API.
Control headers and routing: Consider using Envoy
ext_authz
filter,lua
filter, or write a filter using theEnvoy-wasm
sandbox.Denials and White/Black Listing: Please use the Authorization Policy for enforcing access control to a workload.
istio 文档中有一个 guide 允许重新启用贬值的功能:
- Check the status of policy enforcement for your mesh.
$ kubectl -n istio-system get cm istio -o jsonpath="{@.data.mesh}" | grep disablePolicyChecks disablePolicyChecks: true
If policy enforcement is enabled (
disablePolicyChecks
is false), no further action is needed.
- Update the
istio
configuration to enable policy checks.Execute the following command from the root Istio directory:
$ istioctl manifest apply --set values.global.disablePolicyChecks=false --set values.pilot.policy.enabled=true configuration "istio" replaced
- Validate that policy enforcement is now enabled.
$ kubectl -n istio-system get cm istio -o jsonpath="{@.data.mesh}" | grep disablePolicyChecks disablePolicyChecks: false
请注意,在 calico 文档中它说它需要以下 istio 版本:
Istio v1.0, v1.1, v1.2, or v1.3
希望对您有所帮助。
出于某种原因,当我用 istio-system 中的标签(例如 istio-injection=disabled
)替换 projectcalico.org/namespace == 'istio-system'
时,它似乎可以工作。
apiVersion: projectcalico.org/v3
kind: GlobalNetworkPolicy
metadata:
name: allow-istio-system-to-ns
spec:
selector: all()
namespaceSelector: istio-injection == 'enabled'
types:
- Ingress
- Egress
ingress:
- action: Allow
source:
selector: all()
namespaceSelector: istio-injection == 'disabled'
- action: Allow
source:
selector: all()
namespaceSelector: istio-injection == 'enabled'
egress:
- action: Allow