Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -102,6 +102,7 @@ To learn more about active deprecations, we recommend checking [GitHub Discussio
- **General**: Fix ScaledObject Ready condition not reflecting HPA status ([#7649](https://github.com/kedacore/keda/issues/7649))
- **General**: Handle paused scaling directly in reconciler ([#7663](https://github.com/kedacore/keda/issues/7663))
- **General**: Honor `stderrthreshold` when `logtostderr` is enabled by updating klog to v2.140.0 ([#7568](https://github.com/kedacore/keda/pull/7568))
- **General**: Limit projected service account token reads during Vault authentication ([#7783](https://github.com/kedacore/keda/issues/7783))
- **General**: Reject ScaledObject creation and update when the name exceeds 63 characters ([#6998](https://github.com/kedacore/keda/issues/6998))
- **AWS Scalers**: Fix TCP connection leak by closing HTTP idle connections on scaler `Close()` for SQS, Kinesis, DynamoDB, DynamoDB Streams, and CloudWatch scalers ([#7756](https://github.com/kedacore/keda/issues/7756))
- **Azure Data Explorer Scaler**: Remove clientSecretFromEnv support ([#7554](https://github.com/kedacore/keda/pull/7554))
Expand Down
2 changes: 1 addition & 1 deletion pkg/scaling/resolver/hashicorpvault_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ var tokenTestDataSet = []tokenTestData{
},
role: "my-role",
mount: "my-mount",
errorMessage: "open random/path: no such file or directory",
errorMessage: "random/path: no such file or directory",
},
{
name: "Wrong Authentication Method",
Expand Down
25 changes: 24 additions & 1 deletion pkg/scaling/resolver/k8s_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resolver

import (
"fmt"
"io"
"os"
"strings"

Expand All @@ -10,11 +11,33 @@ import (

var parser = jwt.NewParser()

const maxProjectedServiceAccountTokenSize = 1 << 20

func readKubernetesServiceAccountProjectedToken(path string) ([]byte, error) {
jwt, err := os.ReadFile(path)
info, err := os.Stat(path)
if err != nil {
return []byte{}, err
}
if !info.Mode().IsRegular() {
return []byte{}, fmt.Errorf("service account token path %s is not a regular file", path)
}
Comment thread
wozniakjan marked this conversation as resolved.
if info.Size() > maxProjectedServiceAccountTokenSize {
return []byte{}, fmt.Errorf("service account token file %s exceeds maximum size of %d bytes", path, maxProjectedServiceAccountTokenSize)
}

file, err := os.Open(path)
Comment thread
zroubalik marked this conversation as resolved.
Outdated
if err != nil {
return []byte{}, err
}
defer file.Close()

jwt, err := io.ReadAll(io.LimitReader(file, maxProjectedServiceAccountTokenSize+1))
if err != nil {
return []byte{}, err
}
if len(jwt) > maxProjectedServiceAccountTokenSize {
return []byte{}, fmt.Errorf("service account token file %s exceeds maximum size of %d bytes", path, maxProjectedServiceAccountTokenSize)
}
if err = validateK8sSAToken(jwt); err != nil {
return []byte{}, err
}
Expand Down
15 changes: 15 additions & 0 deletions pkg/scaling/resolver/k8s_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package resolver

import (
"bytes"
"crypto/rand"
"crypto/rsa"
"os"
Expand Down Expand Up @@ -103,6 +104,20 @@ func TestReadKubernetesServiceAccountProjectedToken(t *testing.T) {
},
expectError: true,
},
{
name: "token file exceeds maximum size",
setupToken: func() string {
return createTempFile(t, bytes.Repeat([]byte("x"), maxProjectedServiceAccountTokenSize+1))
},
expectError: true,
},
{
name: "token path is not a regular file",
setupToken: func() string {
return t.TempDir()
},
expectError: true,
},
}

for _, tt := range tests {
Expand Down
Loading