Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GCP PodIdentity not considered with WorkloadIdentity - take 2 #5255

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ Here is an overview of all new **experimental** features:
### Fixes

- **General**: Fix CVE-2023-39325 in golang.org/x/net ([#5122](https://github.com/kedacore/keda/issues/5122))
- **General**: Fix otelgrpc DoS vulnerability ([#5208](https://github.com/kedacore/keda/issues/5208))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please keep only relevant changes here

- **General**: Prevented stuck status due to timeouts during scalers generation ([#5083](https://github.com/kedacore/keda/issues/5083))
- **Azure Pipelines**: No more HTTP 400 errors produced by poolName with spaces ([#5107](https://github.com/kedacore/keda/issues/5107))
- **GCP PubSub**: Fix GCP PodIdentity not considered with WorkloadIdentity ([#5021](https://github.com/kedacore/keda/issues/5021))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not exclusive to GCP PubSup, right? I would use GCP Scalers prefix

- **GCP pubsub scaler**: Missing use of default value of `value` added ([#5093](https://github.com/kedacore/keda/issues/5093))
- **ScaledJobs**: Copy ScaledJob annotations to child Jobs ([#4594](https://github.com/kedacore/keda/issues/4594))

Expand Down
6 changes: 3 additions & 3 deletions pkg/scaling/resolver/scale_resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ func ResolveAuthRefAndPodIdentity(ctx context.Context, client client.Client, log
return authParams, podIdentity, nil
}

authParams, _ := resolveAuthRef(ctx, client, logger, triggerAuthRef, nil, namespace, secretsLister)
return authParams, kedav1alpha1.AuthPodIdentity{Provider: kedav1alpha1.PodIdentityProviderNone}, nil
authParams, podIdentity := resolveAuthRef(ctx, client, logger, triggerAuthRef, nil, namespace, secretsLister)
return authParams, podIdentity, nil
}

// resolveAuthRef provides authentication parameters needed authenticate scaler with the environment.
Expand All @@ -220,7 +220,7 @@ func resolveAuthRef(ctx context.Context, client client.Client, logger logr.Logge
triggerAuthRef *kedav1alpha1.AuthenticationRef, podSpec *corev1.PodSpec,
namespace string, secretsLister corev1listers.SecretLister) (map[string]string, kedav1alpha1.AuthPodIdentity) {
result := make(map[string]string)
var podIdentity kedav1alpha1.AuthPodIdentity
podIdentity := kedav1alpha1.AuthPodIdentity{Provider: kedav1alpha1.PodIdentityProviderNone}

if namespace != "" && triggerAuthRef != nil && triggerAuthRef.Name != "" {
triggerAuthSpec, triggerNamespace, err := getTriggerAuthSpec(ctx, client, triggerAuthRef, namespace)
Expand Down
79 changes: 67 additions & 12 deletions pkg/scaling/resolver/scale_resolvers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,56 @@ func TestResolveNonExistingConfigMapsOrSecretsEnv(t *testing.T) {
}
}

func TestResolveAuthRefAndPodIdentity(t *testing.T) {
if err := corev1.AddToScheme(scheme.Scheme); err != nil {
t.Errorf("Expected Error because: %v", err)
}
if err := kedav1alpha1.AddToScheme(scheme.Scheme); err != nil {
t.Errorf("Expected Error because: %v", err)
}
tests := []struct {
name string
existing []runtime.Object
soar *kedav1alpha1.AuthenticationRef
podTemplateSpec *corev1.PodTemplateSpec
expected map[string]string
expectedPodIdentity kedav1alpha1.AuthPodIdentity
expectedError error
}{
// ensure podIdentity is returned
{
name: "foo",
expected: make(map[string]string),
expectedPodIdentity: kedav1alpha1.AuthPodIdentity{Provider: kedav1alpha1.PodIdentityProviderNone},
},
}
var secretsLister corev1listers.SecretLister
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
ctx := context.Background()
os.Setenv("KEDA_CLUSTER_OBJECT_NAMESPACE", clusterNamespace) // Inject test cluster namespace.
gotMap, gotPodIdentity, err := ResolveAuthRefAndPodIdentity(
ctx,
fake.NewClientBuilder().WithScheme(scheme.Scheme).WithRuntimeObjects(test.existing...).Build(),
logf.Log.WithName("test"),
test.soar,
test.podTemplateSpec,
namespace,
secretsLister)
if diff := cmp.Diff(gotMap, test.expected); diff != "" {
t.Errorf("Returned authParams are different: %s", diff)
}
if gotPodIdentity != test.expectedPodIdentity {
t.Errorf("Unexpected podidentity, wanted: %q got: %q", test.expectedPodIdentity.Provider, gotPodIdentity.Provider)
}
if diff := cmp.Diff(err, test.expectedError); diff != "" {
t.Errorf("Returned error is different: %s", diff)
}
})
}
}

func TestResolveAuthRef(t *testing.T) {
if err := corev1.AddToScheme(scheme.Scheme); err != nil {
t.Errorf("Expected Error because: %v", err)
Expand All @@ -256,18 +306,21 @@ func TestResolveAuthRef(t *testing.T) {
expectedPodIdentity kedav1alpha1.AuthPodIdentity
}{
{
name: "foo",
expected: make(map[string]string),
name: "foo",
expected: make(map[string]string),
expectedPodIdentity: kedav1alpha1.AuthPodIdentity{Provider: kedav1alpha1.PodIdentityProviderNone},
},
{
name: "no triggerauth exists",
soar: &kedav1alpha1.AuthenticationRef{Name: "notthere"},
expected: make(map[string]string),
name: "no triggerauth exists",
soar: &kedav1alpha1.AuthenticationRef{Name: "notthere"},
expected: make(map[string]string),
expectedPodIdentity: kedav1alpha1.AuthPodIdentity{Provider: kedav1alpha1.PodIdentityProviderNone},
},
{
name: "no triggerauth exists",
soar: &kedav1alpha1.AuthenticationRef{Name: "notthere"},
expected: make(map[string]string),
name: "no triggerauth exists",
soar: &kedav1alpha1.AuthenticationRef{Name: "notthere"},
expected: make(map[string]string),
expectedPodIdentity: kedav1alpha1.AuthPodIdentity{Provider: kedav1alpha1.PodIdentityProviderNone},
},
{
name: "triggerauth exists, podidentity nil",
Expand All @@ -288,8 +341,9 @@ func TestResolveAuthRef(t *testing.T) {
},
},
},
soar: &kedav1alpha1.AuthenticationRef{Name: triggerAuthenticationName},
expected: map[string]string{"host": ""},
soar: &kedav1alpha1.AuthenticationRef{Name: triggerAuthenticationName},
expectedPodIdentity: kedav1alpha1.AuthPodIdentity{Provider: kedav1alpha1.PodIdentityProviderNone},
expected: map[string]string{"host": ""},
},
{
name: "triggerauth exists and secret",
Expand Down Expand Up @@ -421,8 +475,9 @@ func TestResolveAuthRef(t *testing.T) {
},
},
},
soar: &kedav1alpha1.AuthenticationRef{Name: triggerAuthenticationName, Kind: "ClusterTriggerAuthentication"},
expected: map[string]string{"host": ""},
soar: &kedav1alpha1.AuthenticationRef{Name: triggerAuthenticationName, Kind: "ClusterTriggerAuthentication"},
expected: map[string]string{"host": ""},
expectedPodIdentity: kedav1alpha1.AuthPodIdentity{Provider: kedav1alpha1.PodIdentityProviderNone},
},
{
name: "clustertriggerauth exists and secret",
Expand Down