Skip to content

Commit bb9d6ac

Browse files
Merge pull request #368 from joshbranham/clarify-namespace-promrule-exceptions
OSD-29566: Clarify namespaces that can bypass PrometheusRules webhook
2 parents 530a8a0 + 0656f98 commit bb9d6ac

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Ensure the git branch is current and run `make syncset`. The updated Template wi
3434

3535
Ensure the git branch is current and run `make generate`. The updated lists will be written to [pkg/config/namespaces.go](pkg/config/namespaces.go). [Documentation should also be regenerated](#updating-documentation-files) to ensure the ConfigMaps specified are up-to-date.
3636

37-
## Updating documenation files
37+
## Updating documentation files
3838

3939
Ensure the git branch is current and run `make docs > docs/webhooks.json && make DOCFLAGS=-hideRules docs > docs/webhooks-short.json`.
4040

pkg/config/namespaces.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/webhooks/prometheusrule/prometheusrule.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ var (
4545
},
4646
}
4747
log = logf.Log.WithName(WebhookName)
48+
49+
// These namespaces are partially managed by Red Hat SRE, however we allow customers to define PrometheusRules in them.
50+
privilegedNamespacesAllowed = []string{"openshift-customer-monitoring", "openshift-user-workload-monitoring"}
4851
)
4952

5053
// prometheusruleWebhook validates a prometheusRule change
@@ -80,10 +83,8 @@ func (s *prometheusruleWebhook) authorized(request admissionctl.Request) admissi
8083
return admissionctl.Errored(http.StatusBadRequest, err)
8184
}
8285

83-
if hookconfig.IsPrivilegedNamespace(pr.GetNamespace()) &&
84-
// TODO: [OSD-13680] Remove this exception for openshift-customer-monitoring
85-
pr.GetNamespace() != "openshift-customer-monitoring" &&
86-
pr.GetNamespace() != "openshift-user-workload-monitoring" {
86+
// This block covers the denial flow for PrivilegedNamespaces, excluding some special case namespaces.
87+
if hookconfig.IsPrivilegedNamespace(pr.GetNamespace()) && !slices.Contains(privilegedNamespacesAllowed, pr.GetNamespace()) {
8788
log.Info(fmt.Sprintf("%s operation detected on managed namespace: %s", request.Operation, pr.GetNamespace()))
8889
if isAllowedUser(request) {
8990
ret = admissionctl.Allowed(fmt.Sprintf("User can do operations on PrometheusRules"))

pkg/webhooks/prometheusrule/prometheusrule_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,8 @@ func TestUsers(t *testing.T) {
258258
shouldBeAllowed: true,
259259
},
260260
{
261-
testID: "regular-user-can-create-prometheusrule-in-openshift-user-workload-monitoring",
262-
targetNamespace: "openshift-user-workload-monitoring",
261+
testID: "regular-user-can-create-prometheusrule-in-openshift-customer-monitoring",
262+
targetNamespace: "openshift-customer-monitoring",
263263
targetResource: "prometheusrule",
264264
username: "prometheus-user-workload",
265265
userGroups: []string{"cluster-admins", "system:authenticated", "system:authenticated:oauth"},

0 commit comments

Comments
 (0)