Merge pull request #3367 from weaveworks/issues/3168-ingress-ipblock
Add ipBlock support for Ingress netpol
This commit is contained in:
3 files changed
+35
-3
No files matched your search
+8
-2
@@ -63,6 +63,7 @@ func (ns *ns) analysePolicy(policy *networkingv1.NetworkPolicy) (
|
||||
} else {
|
||||
for _, peer := range ingressRule.From {
|
||||
var srcSelector *selectorSpec
|
||||
var srcRuleHost ruleHost
|
||||
|
||||
// NetworkPolicyPeer describes a peer to allow traffic from.
|
||||
// Exactly one of its fields must be specified.
|
||||
@@ -72,17 +73,22 @@ func (ns *ns) analysePolicy(policy *networkingv1.NetworkPolicy) (
|
||||
return nil, nil, nil, nil, err
|
||||
}
|
||||
addIfNotExist(srcSelector, podSelectors)
|
||||
|
||||
srcRuleHost = srcSelector
|
||||
} else if peer.NamespaceSelector != nil {
|
||||
srcSelector, err = newSelectorSpec(peer.NamespaceSelector, nil, "", ipset.ListSet)
|
||||
if err != nil {
|
||||
return nil, nil, nil, nil, err
|
||||
}
|
||||
nsSelectors[srcSelector.key] = srcSelector
|
||||
srcRuleHost = srcSelector
|
||||
} else if peer.IPBlock != nil {
|
||||
ipBlock := newIPBlockSpec(peer.IPBlock, ns.name)
|
||||
ipBlocks[ipBlock.key] = ipBlock
|
||||
srcRuleHost = ipBlock
|
||||
}
|
||||
|
||||
if allPorts {
|
||||
rule := newRuleSpec(policyTypeIngress, nil, srcSelector, targetSelector, nil)
|
||||
rule := newRuleSpec(policyTypeIngress, nil, srcRuleHost, targetSelector, nil)
|
||||
rules[rule.key] = rule
|
||||
} else {
|
||||
withNormalisedProtoAndPort(ingressRule.Ports, func(proto, port string) {
|
||||
|
||||
@@ -154,7 +154,7 @@ labels. For more information on configuring network policies in
|
||||
Kubernetes see the
|
||||
[walkthrough](https://kubernetes.io/docs/tasks/administer-cluster/declare-network-policy/)
|
||||
and the [NetworkPolicy API object
|
||||
definition](https://v1-7.docs.kubernetes.io/docs/api-reference/v1.7/#networkpolicy-v1-networking)
|
||||
definition](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.11/#networkpolicy-v1-networking-k8s-io)
|
||||
|
||||
**Note:** as of version 1.9 of Weave Net, the Network Policy
|
||||
Controller allows all multicast traffic. Since a single multicast
|
||||
@@ -163,6 +163,11 @@ definition](https://v1-7.docs.kubernetes.io/docs/api-reference/v1.7/#networkpoli
|
||||
all multicast traffic) by adding `--allow-mcast=false` as an
|
||||
argument to `weave-npc` in the YAML configuration.
|
||||
|
||||
**Note:** Since ingress traffic is masqueraded, it makes sense to use
|
||||
`ipBlock` selector in an ingress rule only when limiting access to a Service
|
||||
annotated with `externalTrafficPolicy=Local` or between Pods when `podIP` is used
|
||||
to access a Pod.
|
||||
|
||||
## <a name="troubleshooting"></a> Troubleshooting
|
||||
|
||||
The first thing to check is whether Weave Net is up and
|
||||
|
||||
@@ -255,6 +255,27 @@ assert_raises "$SSH $HOST1 $KUBECTL exec $denyPodName -- curl -s -S -f -m 2 http
|
||||
assert_raises "! $SSH $HOST1 curl -s -S -f -m 2 http://$VIRTUAL_IP/status >/dev/null"
|
||||
assert_raises "! $SSH $HOST1 curl -s -S -f -m 2 http://$HOST2:31138/status >/dev/null"
|
||||
|
||||
# allow access only from weave bridge IP of host1 to test ipBlock
|
||||
run_on $HOST1 "$KUBECTL apply -f -" <<EOF
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: NetworkPolicy
|
||||
metadata:
|
||||
name: allow-via-weave-bridge-of-host1
|
||||
namespace: default
|
||||
spec:
|
||||
podSelector: {}
|
||||
ingress:
|
||||
- from:
|
||||
- ipBlock:
|
||||
cidr: $HOST1EXPIP/32
|
||||
EOF
|
||||
|
||||
sleep 2
|
||||
|
||||
assert_raises "$SSH $HOST1 curl -s -S -f -m 2 http://$VIRTUAL_IP/status >/dev/null"
|
||||
|
||||
run_on $HOST1 "$KUBECTL delete netpol allow-via-weave-bridge-of-host1"
|
||||
|
||||
# allow access from anywhere
|
||||
run_on $HOST1 "$KUBECTL apply -f -" <<EOF
|
||||
apiVersion: networking.k8s.io/v1
|
||||
|
||||
Reference in new issue
Block a user