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(controller): Corrects the logic of comparing sha256 has. Fixes #3519 #3520

Merged
merged 1 commit into from
Apr 10, 2024
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
9 changes: 7 additions & 2 deletions utils/plugin/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,17 @@ func checkPluginExists(pluginLocation string) error {
}

func checkShaOfPlugin(pluginLocation string, expectedSha256 string) (bool, error) {
hasher := sha256.New()
fileBytes, err := os.ReadFile(pluginLocation)
if err != nil {
return false, fmt.Errorf("failed to read file %s: %w", pluginLocation, err)
}
fileSha256 := fmt.Sprintf("%x", hasher.Sum(fileBytes))
var fileSha256 string
if len(expectedSha256) == 64 {
fileSha256 = fmt.Sprintf("%x", sha256.Sum256(fileBytes))
} else {
hasher := sha256.New()
fileSha256 = fmt.Sprintf("%x", hasher.Sum(fileBytes))
}
match := fileSha256 == expectedSha256
if !match {
log.Printf("expected sha256: %s, actual sha256: %s, of downloaded metric plugin (%s)", expectedSha256, fileSha256, pluginLocation)
Expand Down
2 changes: 1 addition & 1 deletion utils/plugin/downloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestPlugin(t *testing.T) {
Name: "argo-rollouts-config",
Namespace: "argo-rollouts",
},
Data: map[string]string{"metricProviderPlugins": "\n - name: argoproj-labs/http\n location: https://test/plugin\n - name: argoproj-labs/http-sha\n location: https://test/plugin\n sha256: 74657374e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"},
Data: map[string]string{"metricProviderPlugins": "\n - name: argoproj-labs/http\n location: https://test/plugin\n - name: argoproj-labs/http-sha\n location: https://test/plugin\n sha256: 74657374e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\n - name: argoproj-labs/http-sha-correct\n location: https://test/plugin\n sha256: 9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"},
}
client := fake.NewSimpleClientset(cm)

Expand Down
Loading