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 operator panic when spec.hashiCorpVault.credential.serviceAccount is not set #5180

Merged
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Here is an overview of all new **experimental** features:
- **General**: Add parameter queryParameters to prometheus-scaler ([#4962](https://github.com/kedacore/keda/issues/4962))
- **General**: Support TriggerAuthentication properties from ConfigMap ([#4830](https://github.com/kedacore/keda/issues/4830))
- **Hashicorp Vault**: Add support to get secret that needs write operation (e.g. pki) ([#5067](https://github.com/kedacore/keda/issues/5067))
- **Hashicorp Vault**: Fix operator panic when spec.hashiCorpVault.credential.serviceAccount is not set ([#4964](https://github.com/kedacore/keda/issues/4964))
- **Kafka Scaler**: Ability to set upper bound to the number of partitions with lag ([#3997](https://github.com/kedacore/keda/issues/3997))
- **Kafka Scaler**: Add more logging to check Sarama DescribeTopics method ([#5102](https://github.com/kedacore/keda/issues/5102))
- **Kafka Scaler**: Add support for Kerberos authentication (SASL / GSSAPI) ([#4836](https://github.com/kedacore/keda/issues/4836))
Expand Down
7 changes: 7 additions & 0 deletions pkg/scaling/resolver/hashicorpvault_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ func (vh *HashicorpVaultHandler) token(client *vaultapi.Client) (string, error)
return token, errors.New("k8s role not in config")
}

if vh.vault.Credential == nil {
dttung2905 marked this conversation as resolved.
Show resolved Hide resolved
defaultCred := kedav1alpha1.Credential{
ServiceAccount: "/var/run/secrets/kubernetes.io/serviceaccount/token",
}
vh.vault.Credential = &defaultCred
}

if len(vh.vault.Credential.ServiceAccount) == 0 {
return token, errors.New("k8s SA file not in config")
}
Expand Down
19 changes: 19 additions & 0 deletions pkg/scaling/resolver/hashicorpvault_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,25 @@ func TestHashicorpVaultHandler_ResolveSecret(t *testing.T) {
}
}

func TestHashicorpVaultHandler_DefaultKubernetesVaultRole(t *testing.T) {
defaultServiceAccountPath := "/var/run/secrets/kubernetes.io/serviceaccount/token"
server := mockVault(t)
defer server.Close()

vault := kedav1alpha1.HashiCorpVault{
Address: server.URL,
Authentication: kedav1alpha1.VaultAuthenticationKubernetes,
Mount: "my-mount",
Role: "my-role",
}

vaultHandler := NewHashicorpVaultHandler(&vault)
err := vaultHandler.Initialize(logf.Log.WithName("test"))
defer vaultHandler.Stop()
assert.Errorf(t, err, "open %s : no such file or directory", defaultServiceAccountPath)
assert.Equal(t, vaultHandler.vault.Credential.ServiceAccount, defaultServiceAccountPath)
}

func TestHashicorpVaultHandler_ResolveSecrets_SameCertAndKey(t *testing.T) {
server := mockVault(t)
defer server.Close()
Expand Down