Skip to content

Commit 4e374f0

Browse files
committed
Permission check fixed for the serviceaccount of the target allocator
1 parent 22e8c06 commit 4e374f0

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
2+
change_type: bug_fix
3+
4+
# The name of the component, or a single word describing the area of concern, (e.g. collector, target allocator, auto-instrumentation, opamp, github action)
5+
component: target allocator
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: "Permission check fixed for the serviceaccount of the target allocator"
9+
10+
# One or more tracking issues related to the change
11+
issues: [3380]
12+
13+
# (Optional) One or more lines of additional information to render under the primary note.
14+
# These lines will be padded with 2 spaces and then inserted directly into the document.
15+
# Use pipe (|) for multiline entries.
16+
subtext:

apis/v1alpha1/targetallocator_webhook.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func (w TargetAllocatorWebhook) validate(ctx context.Context, ta *TargetAllocato
119119

120120
// if the prometheusCR is enabled, it needs a suite of permissions to function
121121
if ta.Spec.PrometheusCR.Enabled {
122-
warnings, err := v1beta1.CheckTargetAllocatorPrometheusCRPolicyRules(ctx, w.reviewer, ta.Spec.ServiceAccount, ta.GetNamespace())
122+
warnings, err := v1beta1.CheckTargetAllocatorPrometheusCRPolicyRules(ctx, w.reviewer, ta.GetNamespace(), ta.Spec.ServiceAccount)
123123
if err != nil || len(warnings) > 0 {
124124
return warnings, err
125125
}

apis/v1beta1/collector_webhook.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/open-telemetry/opentelemetry-operator/internal/config"
3030
"github.com/open-telemetry/opentelemetry-operator/internal/fips"
3131
ta "github.com/open-telemetry/opentelemetry-operator/internal/manifests/targetallocator/adapters"
32+
"github.com/open-telemetry/opentelemetry-operator/internal/naming"
3233
"github.com/open-telemetry/opentelemetry-operator/internal/rbac"
3334
"github.com/open-telemetry/opentelemetry-operator/pkg/featuregate"
3435
)
@@ -341,8 +342,12 @@ func (c CollectorWebhook) validateTargetAllocatorConfig(ctx context.Context, r *
341342
}
342343
// if the prometheusCR is enabled, it needs a suite of permissions to function
343344
if r.Spec.TargetAllocator.PrometheusCR.Enabled {
345+
saname := r.Spec.TargetAllocator.ServiceAccount
346+
if len(r.Spec.TargetAllocator.ServiceAccount) == 0 {
347+
saname = naming.TargetAllocatorServiceAccount(r.Name)
348+
}
344349
warnings, err := CheckTargetAllocatorPrometheusCRPolicyRules(
345-
ctx, c.reviewer, r.Spec.TargetAllocator.ServiceAccount, r.GetNamespace())
350+
ctx, c.reviewer, r.GetNamespace(), saname)
346351
if err != nil || len(warnings) > 0 {
347352
return warnings, err
348353
}

apis/v1beta1/targetallocator_rbac.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ func CheckTargetAllocatorPrometheusCRPolicyRules(
6161
serviceAccountName string) (warnings []string, err error) {
6262
subjectAccessReviews, err := reviewer.CheckPolicyRules(
6363
ctx,
64-
namespace,
6564
serviceAccountName,
65+
namespace,
6666
targetAllocatorCRPolicyRules...,
6767
)
6868
if err != nil {

0 commit comments

Comments
 (0)