Skip to content

Commit b718747

Browse files
authored
[FlowAggregator] Clean up RBAC (#7125)
* most permissions can be limited to a single Namespace (flow-aggregator Namespace) and the rules can be moved to a Role instead of a ClusterRole. * the rule allowing create / get / list / watch for all ConfigMaps in all Namespaces was not necessary. * binding to the system:auth-delegator ClusterRole is necessary for the FlowAggregator apiserver to delegate auth to the K8s apiserver. Note that today we typically only access the API locally (using the loopback token, which is privileged) so the missing permissions have not been an issue so far. Still, the RBAC permissions didn't match the apiserver configuration. * we can bind to the extension-apiserver-authentication-reader Role instead of replicating its RBAC rules, now that we require K8s 1.19 or above. * add antreaNamespace value to the flow-aggregator Helm chart, to avoid hardcoding kube-system in flow-exporter-role-binding (which binds a Role to the antrea-agent ServiceAccount). Signed-off-by: Antonin Bas <[email protected]>
1 parent 4b377ab commit b718747

File tree

11 files changed

+210
-113
lines changed

11 files changed

+210
-113
lines changed

build/charts/flow-aggregator/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Kubernetes: `>= 1.19.0-0`
2020
|-----|------|---------|-------------|
2121
| activeFlowRecordTimeout | string | `"60s"` | Provide the active flow record timeout as a duration string. Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h". |
2222
| aggregatorTransportProtocol | string | `"tls"` | Provide the transport protocol for the flow aggregator collecting process, which is tls, tcp or udp. |
23+
| antreaNamespace | string | `"kube-system"` | Namespace in which Antrea was installed. |
2324
| apiServer.apiPort | int | `10348` | The port for the Flow Aggregator APIServer to serve on. |
2425
| apiServer.tlsCipherSuites | string | `""` | Comma-separated list of cipher suites that will be used by the Flow Aggregator APIservers. If empty, the default Go Cipher Suites will be used. |
2526
| apiServer.tlsMinVersion | string | `""` | TLS min version from: VersionTLS10, VersionTLS11, VersionTLS12, VersionTLS13. |

build/charts/flow-aggregator/templates/clusterrole.yaml

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,6 @@ metadata:
55
app: flow-aggregator
66
name: flow-aggregator-role
77
rules:
8-
- apiGroups: [""]
9-
resources: ["configmaps"]
10-
resourceNames: ["flow-aggregator-ca"]
11-
verbs: ["get", "update"]
128
- apiGroups: [""]
139
resources: ["pods"]
1410
verbs: ["get", "list", "watch"]
15-
- apiGroups: [""]
16-
resources: ["configmaps"]
17-
verbs: ["create", "get", "list", "watch"]
18-
# This is the content of built-in role kube-system/extension-apiserver-authentication-reader.
19-
# But it doesn't have list/watch permission before K8s v1.17.0 so the extension apiserver (antrea-agent) will
20-
# have permission issue after bumping up apiserver library to a version that supports dynamic authentication.
21-
# See https://github.com/kubernetes/kubernetes/pull/85375
22-
# To support K8s clusters older than v1.17.0, we grant the required permissions directly instead of relying on
23-
# the extension-apiserver-authentication role.
24-
- apiGroups: [""]
25-
resourceNames: ["extension-apiserver-authentication"]
26-
resources: ["configmaps"]
27-
verbs: ["get", "list", "watch"]
28-
- apiGroups: [""]
29-
resources: ["secrets"]
30-
resourceNames: ["flow-aggregator-client-tls"]
31-
verbs: ["get", "update"]
32-
- apiGroups: [""]
33-
resources: ["secrets"]
34-
verbs: ["create"]
35-
- apiGroups: [ "" ]
36-
resources: [ "configmaps" ]
37-
resourceNames: [ "flow-aggregator-configmap" ]
38-
verbs: [ "update" ]

build/charts/flow-aggregator/templates/clusterrolebinding.yaml

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
kind: ClusterRoleBinding
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
metadata:
4+
labels:
5+
app: flow-aggregator
6+
name: flow-aggregator-cluster-role-binding
7+
subjects:
8+
- kind: ServiceAccount
9+
name: flow-aggregator
10+
namespace: {{ .Release.Namespace }}
11+
roleRef:
12+
kind: ClusterRole
13+
name: flow-aggregator-role
14+
apiGroup: rbac.authorization.k8s.io
15+
---
16+
# For auth delegation to apiserver
17+
kind: ClusterRoleBinding
18+
apiVersion: rbac.authorization.k8s.io/v1
19+
metadata:
20+
labels:
21+
app: flow-aggregator
22+
name: flow-aggregator-auth-delegator-cluster-role-binding
23+
subjects:
24+
- kind: ServiceAccount
25+
name: flow-aggregator
26+
namespace: {{ .Release.Namespace }}
27+
roleRef:
28+
kind: ClusterRole
29+
name: system:auth-delegator
30+
apiGroup: rbac.authorization.k8s.io

build/charts/flow-aggregator/templates/role.yaml

Lines changed: 0 additions & 16 deletions
This file was deleted.

build/charts/flow-aggregator/templates/rolebinding.yaml

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
kind: RoleBinding
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
metadata:
4+
labels:
5+
app: flow-aggregator
6+
name: flow-exporter-role-binding
7+
namespace: {{ .Release.Namespace }}
8+
subjects:
9+
- kind: ServiceAccount
10+
name: antrea-agent
11+
namespace: {{ .Values.antreaNamespace }}
12+
roleRef:
13+
kind: Role
14+
name: flow-exporter-role
15+
apiGroup: rbac.authorization.k8s.io
16+
---
17+
kind: RoleBinding
18+
apiVersion: rbac.authorization.k8s.io/v1
19+
metadata:
20+
labels:
21+
app: flow-aggregator
22+
name: flow-aggregator-role-binding
23+
namespace: {{ .Release.Namespace }}
24+
subjects:
25+
- kind: ServiceAccount
26+
name: flow-aggregator
27+
namespace: {{ .Release.Namespace }}
28+
roleRef:
29+
kind: Role
30+
name: flow-aggregator-role
31+
apiGroup: rbac.authorization.k8s.io
32+
---
33+
# For auth delegation to apiserver
34+
kind: RoleBinding
35+
apiVersion: rbac.authorization.k8s.io/v1
36+
metadata:
37+
labels:
38+
app: flow-aggregator
39+
name: flow-aggregator-extension-apiserver-authentication-reader-role-binding
40+
namespace: kube-system
41+
subjects:
42+
- kind: ServiceAccount
43+
name: flow-aggregator
44+
namespace: {{ .Release.Namespace }}
45+
roleRef:
46+
kind: Role
47+
name: extension-apiserver-authentication-reader
48+
apiGroup: rbac.authorization.k8s.io
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
kind: Role
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
metadata:
4+
labels:
5+
app: flow-aggregator
6+
name: flow-exporter-role
7+
namespace: {{ .Release.Namespace }}
8+
rules:
9+
- apiGroups: [""]
10+
resources: ["configmaps"]
11+
resourceNames: ["flow-aggregator-ca"]
12+
verbs: ["get"]
13+
- apiGroups: [""]
14+
resources: ["secrets"]
15+
resourceNames: ["flow-aggregator-client-tls"]
16+
verbs: ["get"]
17+
---
18+
kind: Role
19+
apiVersion: rbac.authorization.k8s.io/v1
20+
metadata:
21+
labels:
22+
app: flow-aggregator
23+
name: flow-aggregator-role
24+
namespace: {{ .Release.Namespace }}
25+
rules:
26+
# RBAC to create / update / get flow-aggregator-ca ConfigMap
27+
- apiGroups: [""]
28+
resources: ["configmaps"]
29+
verbs: ["create"]
30+
- apiGroups: [""]
31+
resources: ["configmaps"]
32+
resourceNames: ["flow-aggregator-ca"]
33+
verbs: ["get", "update"]
34+
# RBAC to create / update / get flow-aggregator-client-tls Secret
35+
- apiGroups: [""]
36+
resources: ["secrets"]
37+
verbs: ["create"]
38+
- apiGroups: [""]
39+
resources: ["secrets"]
40+
resourceNames: ["flow-aggregator-client-tls"]
41+
verbs: ["get", "update"]
42+
# RBAC to get / update flow-aggregator-configmap ConfigMap (required by antctl)
43+
- apiGroups: [""]
44+
resources: ["configmaps"]
45+
resourceNames: ["flow-aggregator-configmap"]
46+
verbs: ["get", "update"]

build/charts/flow-aggregator/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,5 @@ testing:
142142
coverage: false
143143
# -- Log verbosity switch for Flow Aggregator.
144144
logVerbosity: 0
145+
# -- Namespace in which Antrea was installed.
146+
antreaNamespace: "kube-system"

0 commit comments

Comments
 (0)