nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: osbuild/osbuild-composer
Pull request #1896 (2021-10-08 09:58:32)

composer: Don't dump sensitive fields from config

Gundersanne: vmware tests are still failing; building in vsphere works but not the running. If only the vmware ones are failing I think we should admin-merge.

Patch:
diff --git a/cmd/osbuild-composer/config.go b/cmd/osbuild-composer/config.go
index faa9ab7e6..1b1b955cd 100644
--- a/cmd/osbuild-composer/config.go
+++ b/cmd/osbuild-composer/config.go
@@ -148,6 +148,8 @@ func loadConfigFromEnv(intf interface{}) error {
 	return nil
 }
 
-func DumpConfig(c *ComposerConfigFile, w io.Writer) error {
+func DumpConfig(c ComposerConfigFile, w io.Writer) error {
+	// sensor sensitive fields
+	c.Worker.PGPassword = ""
 	return toml.NewEncoder(w).Encode(c)
 }
diff --git a/cmd/osbuild-composer/main.go b/cmd/osbuild-composer/main.go
index 69c34bdfa..53eb8b425 100644
--- a/cmd/osbuild-composer/main.go
+++ b/cmd/osbuild-composer/main.go
@@ -43,7 +43,7 @@ func main() {
 	}
 
 	logrus.Info("Loaded configuration:")
-	err = DumpConfig(config, logrus.StandardLogger().WriterLevel(logrus.InfoLevel))
+	err = DumpConfig(*config, logrus.StandardLogger().WriterLevel(logrus.InfoLevel))
 	if err != nil {
 		logrus.Fatalf("Error printing configuration: %v", err)
 	}


Test patch:
diff --git a/cmd/osbuild-composer/config_test.go b/cmd/osbuild-composer/config_test.go
index 5e1be1887..5f4c9dc1a 100644
--- a/cmd/osbuild-composer/config_test.go
+++ b/cmd/osbuild-composer/config_test.go
@@ -1,6 +1,7 @@
 package main
 
 import (
+	"bytes"
 	"os"
 	"testing"
 
@@ -94,3 +95,18 @@ func TestWeldrDistrosImageTypeDenyList(t *testing.T) {
 
 	require.Equal(t, expectedWeldrDistrosImageTypeDenyList, config.weldrDistrosImageTypeDenyList())
 }
+
+func TestDumpConfig(t *testing.T) {
+	config := &ComposerConfigFile{
+		Worker: WorkerAPIConfig{
+			PGPassword: "sensitive",
+		},
+	}
+
+	var buf bytes.Buffer
+	require.NoError(t, DumpConfig(*config, &buf))
+	require.Contains(t, buf.String(), "pg_password = \"\"")
+	require.NotContains(t, buf.String(), "sensitive")
+	// DumpConfig takes a copy
+	require.Equal(t, "sensitive", config.Worker.PGPassword)
+}