Skip to content

Commit a144a07

Browse files
committed
Add page Block Services with ExternalIPs
That uses a VAP to explain how a user may be able to block specific Services with ExternalIPs
1 parent e5c4414 commit a144a07

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
---
2+
reviewers:
3+
- thockin
4+
- danwinship
5+
- aojea
6+
min-kubernetes-server-version: v1.30
7+
title: Block Services with external IPs
8+
content_type: task
9+
---
10+
11+
<!-- overview -->
12+
13+
This document explains a way to control how {{< glossary_tooltip text="Services" term_id="service" >}} with external IP address(es) are managed within your cluster.
14+
15+
The ability to [set an external IP address for a Service](/docs/concepts/services-networking/service/#external-ips) could be musused as a way for an otherwise unprivileged user to intercept traffic associated with that IP address.
16+
17+
See [CVE-2020-8554](https://www.cvedetails.com/cve/CVE-2020-8554/) for more details.
18+
19+
Any user who can create a Service with external IPs could:
20+
21+
- intercept other users' outbound traffic to arbitrary cluster-external IPs.
22+
- (non-deterministically) steal other users' inbound traffic to their own external IPs.
23+
24+
## {{% heading "prerequisites" %}}
25+
26+
{{< include "task-tutorial-prereqs.md" >}}
27+
28+
{{< version-check >}}
29+
30+
<!-- steps -->
31+
32+
## Service external IP address policies for Kubernetes
33+
34+
As a cluster administrator, you can implement policies to control the creation and modification of Services with external IP addresses within the cluster.
35+
This allows for centralized management of the allowed external IP addresses that can be used for Services,
36+
and helps prevent unintended or conflicting configurations.
37+
Kubernetes provides mechanisms such as [ValidatingAdmissionPolicies](/docs/reference/access-authn-authz/validating-admission-policy/) that
38+
you can use to enforce these rules.
39+
40+
## Restrict Service external IP addresses to permitted address ranges
41+
42+
The following example allows an administrator to restrict the allowed IP address range(s) of any new or updated Service:
43+
44+
```yaml
45+
---
46+
apiVersion: admissionregistration.k8s.io/v1
47+
kind: ValidatingAdmissionPolicy
48+
metadata:
49+
name: "allow-specific-externalips"
50+
spec:
51+
failurePolicy: Fail
52+
matchConstraints:
53+
resourceRules:
54+
- apiGroups: [""]
55+
apiVersions: ["v1"]
56+
operations: ["CREATE", "UPDATE"]
57+
resources: ["services"]
58+
variables:
59+
- name: allowed
60+
expression: "['192.0.2.0/24', '2001:db8::/64']" # Change these values to for your use case
61+
validations:
62+
- expression: |
63+
!has(object.spec.externalIPs) ||
64+
object.spec.externalIPs.all(ip, variables.allowed.exists(cidr, cidr(cidr).containsIP(ip)))
65+
message: "All externalIPs must be within the allowed CIDR ranges."
66+
---
67+
apiVersion: admissionregistration.k8s.io/v1
68+
kind: ValidatingAdmissionPolicyBinding
69+
metadata:
70+
name: "allow-specific-externalips-binding"
71+
spec:
72+
policyName: "allow-specific-externalips"
73+
validationActions: [Deny, Audit]
74+
```
75+
76+
## Restrict which users or groups may specify external IP addresses for Services
77+
78+
```yaml
79+
---
80+
apiVersion: admissionregistration.k8s.io/v1
81+
kind: ValidatingAdmissionPolicy
82+
metadata:
83+
name: "allow-specific-users-to-manage-externalips"
84+
spec:
85+
failurePolicy: Fail
86+
matchConstraints:
87+
resourceRules:
88+
- apiGroups: [""]
89+
apiVersions: ["v1"]
90+
operations: ["CREATE", "UPDATE"]
91+
resources: ["services"]
92+
validations:
93+
- expression: |
94+
!has(object.spec.externalIPs) ||
95+
request.userInfo.username == "myuser" ||
96+
request.userInfo.groups.exists(g, g in ["system:masters", "net-admins"])
97+
message: "Only user 'myuser' or members of groups 'system:masters' and 'net-admins' can assign externalIPs."
98+
---
99+
apiVersion: admissionregistration.k8s.io/v1
100+
kind: ValidatingAdmissionPolicyBinding
101+
metadata:
102+
name: "allow-specific-users-binding"
103+
spec:
104+
policyName: "allow-specific-users-to-manage-externalips"
105+
validationActions: [Deny, Audit]
106+
```

0 commit comments

Comments
 (0)