Commit 18495ae
pkg/cvo/metrics: Authorize using CN verification
In OpenShift, core operators SHOULD support local authorization and
SHOULD allow the well-known metrics scraping identity
(system:serviceaccount:openshift-monitoring:prometheus-k8s) to access
the /metrics endpoint. They MAY support delegated authorization check
via SubjectAccessReviews. [1]
The well-known metrics scraping identity's client certificate is issued
for the system:serviceaccount:openshift-monitoring:prometheus-k8s
Common Name (CN) and signed by the kubernetes.io/kube-apiserver-client
signer. [2]
Thus, the commit utilizes this fact to check the client's certificate
for this specific CN value. This is also done by the hardcodedauthorizer
package utilized by other OpenShift operators for the metrics
endpoint [3].
We could utilize the existing bearer token authorization as a fallback.
However, I would like to minimize the attack surface. Especially for
security things that we are implementing and testing, rather than
importing from well-established modules.
The commit implements a user information extraction from a
certificate to minimize the needed dependencies.
[1]: https://github.com/openshift/enhancements/blob/master/CONVENTIONS.md#metrics
[2]: https://rhobs-handbook.netlify.app/products/openshiftmonitoring/collecting_metrics.md/#exposing-metrics-for-prometheus
[3]: https://pkg.go.dev/github.com/openshift/library-go/pkg/authorization/hardcodedauthorizer
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>1 parent 81f3bb5 commit 18495ae
2 files changed
Lines changed: 50 additions & 160 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | 10 | | |
12 | 11 | | |
13 | 12 | | |
14 | 13 | | |
15 | | - | |
16 | 14 | | |
17 | 15 | | |
18 | | - | |
19 | 16 | | |
20 | 17 | | |
21 | 18 | | |
22 | 19 | | |
23 | | - | |
24 | 20 | | |
25 | 21 | | |
26 | 22 | | |
| |||
127 | 123 | | |
128 | 124 | | |
129 | 125 | | |
130 | | - | |
| 126 | + | |
131 | 127 | | |
132 | 128 | | |
133 | 129 | | |
| |||
137 | 133 | | |
138 | 134 | | |
139 | 135 | | |
140 | | - | |
| 136 | + | |
141 | 137 | | |
142 | 138 | | |
143 | 139 | | |
| |||
146 | 142 | | |
147 | 143 | | |
148 | 144 | | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | 145 | | |
154 | 146 | | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | 147 | | |
178 | 148 | | |
179 | 149 | | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
192 | 153 | | |
193 | 154 | | |
194 | 155 | | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
203 | 167 | | |
204 | 168 | | |
| 169 | + | |
| 170 | + | |
205 | 171 | | |
206 | 172 | | |
207 | 173 | | |
| |||
288 | 254 | | |
289 | 255 | | |
290 | 256 | | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | 257 | | |
297 | 258 | | |
298 | 259 | | |
| |||
325 | 286 | | |
326 | 287 | | |
327 | 288 | | |
328 | | - | |
| 289 | + | |
329 | 290 | | |
330 | 291 | | |
331 | 292 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
5 | 7 | | |
6 | 8 | | |
7 | | - | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
19 | | - | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
1019 | 1019 | | |
1020 | 1020 | | |
1021 | 1021 | | |
1022 | | - | |
1023 | | - | |
1024 | | - | |
1025 | | - | |
1026 | | - | |
1027 | | - | |
1028 | | - | |
1029 | | - | |
1030 | | - | |
1031 | | - | |
1032 | | - | |
1033 | | - | |
1034 | | - | |
1035 | | - | |
1036 | | - | |
1037 | | - | |
1038 | | - | |
1039 | | - | |
1040 | | - | |
1041 | | - | |
1042 | | - | |
1043 | 1022 | | |
1044 | 1023 | | |
1045 | 1024 | | |
| |||
1051 | 1030 | | |
1052 | 1031 | | |
1053 | 1032 | | |
1054 | | - | |
1055 | | - | |
1056 | | - | |
1057 | | - | |
| 1033 | + | |
| 1034 | + | |
1058 | 1035 | | |
1059 | 1036 | | |
1060 | 1037 | | |
1061 | 1038 | | |
1062 | | - | |
| 1039 | + | |
1063 | 1040 | | |
1064 | | - | |
1065 | 1041 | | |
1066 | | - | |
1067 | 1042 | | |
1068 | | - | |
1069 | | - | |
1070 | | - | |
| 1043 | + | |
| 1044 | + | |
1071 | 1045 | | |
1072 | 1046 | | |
1073 | 1047 | | |
1074 | 1048 | | |
1075 | | - | |
1076 | | - | |
1077 | | - | |
1078 | | - | |
1079 | | - | |
1080 | | - | |
1081 | | - | |
1082 | | - | |
1083 | | - | |
1084 | | - | |
1085 | | - | |
1086 | | - | |
1087 | | - | |
1088 | | - | |
1089 | | - | |
1090 | | - | |
1091 | | - | |
1092 | | - | |
1093 | | - | |
1094 | | - | |
1095 | | - | |
1096 | | - | |
1097 | | - | |
1098 | | - | |
1099 | | - | |
1100 | | - | |
1101 | | - | |
| 1049 | + | |
1102 | 1050 | | |
1103 | | - | |
1104 | 1051 | | |
1105 | | - | |
1106 | 1052 | | |
1107 | | - | |
1108 | | - | |
1109 | | - | |
1110 | | - | |
1111 | | - | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
1112 | 1057 | | |
1113 | 1058 | | |
1114 | | - | |
| 1059 | + | |
1115 | 1060 | | |
1116 | | - | |
1117 | 1061 | | |
1118 | | - | |
1119 | 1062 | | |
1120 | | - | |
1121 | | - | |
1122 | | - | |
1123 | | - | |
1124 | | - | |
1125 | | - | |
1126 | | - | |
1127 | | - | |
1128 | | - | |
1129 | | - | |
1130 | | - | |
1131 | | - | |
1132 | | - | |
1133 | | - | |
1134 | | - | |
1135 | | - | |
1136 | | - | |
1137 | | - | |
1138 | | - | |
1139 | | - | |
1140 | | - | |
1141 | | - | |
1142 | | - | |
1143 | | - | |
1144 | | - | |
1145 | | - | |
1146 | | - | |
1147 | | - | |
1148 | | - | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
1149 | 1066 | | |
1150 | 1067 | | |
1151 | 1068 | | |
1152 | 1069 | | |
1153 | 1070 | | |
1154 | 1071 | | |
1155 | | - | |
| 1072 | + | |
1156 | 1073 | | |
1157 | 1074 | | |
1158 | 1075 | | |
1159 | | - | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
1160 | 1089 | | |
1161 | 1090 | | |
1162 | 1091 | | |
| |||
0 commit comments