Repository: osbuild/osbuild-composer
Pull request #3793 (2023-11-12 23:46:40)

Fix RHEL-16242 CheckGPG flag bug
This pull request includes:

- [x] adequate testing for the new functionality or fixed issue
- [x] adequate documentation informing people about the change such as
  - [ ] submit a PR for the [guides](https://github.com/osbuild/guides) repository if this PR changed any behavior described there: https://www.osbuild.org/guides/


bcl: This also need a commit to pull in a new version of images' rhel-9.3.0 branch (which needs a new release, see https://github.com/osbuild/images/issues/251)

Patch:
diff --git a/cmd/osbuild-pipeline/main.go b/cmd/osbuild-pipeline/main.go
index be231721a..f3cdc25a6 100644
--- a/cmd/osbuild-pipeline/main.go
+++ b/cmd/osbuild-pipeline/main.go
@@ -157,7 +157,7 @@ func main() {
 		if repo.GPGKey != "" {
 			keys = []string{repo.GPGKey}
 		}
-
+		checkGPG := repo.CheckGPG
 		repos[i] = rpmmd.RepoConfig{
 			Id:           repoId,
 			Name:         repoName,
@@ -165,7 +165,7 @@ func main() {
 			Metalink:     repo.Metalink,
 			MirrorList:   repo.MirrorList,
 			GPGKeys:      keys,
-			CheckGPG:     &repo.CheckGPG,
+			CheckGPG:     &checkGPG,
 			CheckRepoGPG: common.ToPtr(false),
 			IgnoreSSL:    common.ToPtr(false),
 			PackageSets:  repo.PackageSets,
diff --git a/go.mod b/go.mod
index 050fdbd3c..56eadb64b 100644
--- a/go.mod
+++ b/go.mod
@@ -31,7 +31,7 @@ require (
 	github.com/labstack/gommon v0.4.0
 	github.com/openshift-online/ocm-sdk-go v0.1.362
 	github.com/oracle/oci-go-sdk/v54 v54.0.0
-	github.com/osbuild/images v0.3.0-r9.3.3
+	github.com/osbuild/images v0.3.0-r9.3.4
 	github.com/prometheus/client_golang v1.16.0
 	github.com/segmentio/ksuid v1.0.4
 	github.com/sirupsen/logrus v1.9.3
diff --git a/go.sum b/go.sum
index 6de120ffa..58c956b8d 100644
--- a/go.sum
+++ b/go.sum
@@ -581,8 +581,8 @@ github.com/openshift-online/ocm-sdk-go v0.1.362 h1:MoaSMCSzcr8nSK9DBqKmZ9c5e4Cp8
 github.com/openshift-online/ocm-sdk-go v0.1.362/go.mod h1:KYOw8kAKAHyPrJcQoVR82CneQ4ofC02Na4cXXaTq4Nw=
 github.com/oracle/oci-go-sdk/v54 v54.0.0 h1:CDLjeSejv2aDpElAJrhKpi6zvT/zhZCZuXchUUZ+LS4=
 github.com/oracle/oci-go-sdk/v54 v54.0.0/go.mod h1:+t+yvcFGVp+3ZnztnyxqXfQDsMlq8U25faBLa+mqCMc=
-github.com/osbuild/images v0.3.0-r9.3.3 h1:SODY0LH3cnPAulOV4GwKB6/rhV5mTtm7XT3nS6ZQPmw=
-github.com/osbuild/images v0.3.0-r9.3.3/go.mod h1:lZsi8oJNfk57VRv5zhdrSLmn0z8YPcQzZBxzdHNfZls=
+github.com/osbuild/images v0.3.0-r9.3.4 h1:6ODBirIEzDNnfV81omqOEYTzMXpwdBI7KcpFWOWR1Ps=
+github.com/osbuild/images v0.3.0-r9.3.4/go.mod h1:lZsi8oJNfk57VRv5zhdrSLmn0z8YPcQzZBxzdHNfZls=
 github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE=
 github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 h1:KoWmjvw+nsYOo29YJK9vDA65RGE3NrOnUtO7a+RF9HU=
 github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
diff --git a/internal/blueprint/customizations.go b/internal/blueprint/customizations.go
index b142fa9bf..5ecae8451 100644
--- a/internal/blueprint/customizations.go
+++ b/internal/blueprint/customizations.go
@@ -211,10 +211,11 @@ func (c *Customizations) GetUsers() []UserCustomization {
 
 	// prepend sshkey for backwards compat (overridden by users)
 	if len(c.SSHKey) > 0 {
-		for _, c := range c.SSHKey {
+		for _, k := range c.SSHKey {
+			key := k.Key
 			users = append(users, UserCustomization{
-				Name: c.User,
-				Key:  &c.Key,
+				Name: k.User,
+				Key:  &key,
 			})
 		}
 	}
diff --git a/internal/store/store.go b/internal/store/store.go
index c1525e16a..db32842d7 100644
--- a/internal/store/store.go
+++ b/internal/store/store.go
@@ -624,9 +624,9 @@ func (s *SourceConfig) RepoConfig(name string) rpmmd.RepoConfig {
 
 	repo.Name = name
 	repo.IgnoreSSL = common.ToPtr(!s.CheckSSL)
-	repo.CheckGPG = &s.CheckGPG
+	repo.CheckGPG = common.ToPtr(s.CheckGPG)
 	repo.RHSM = s.RHSM
-	repo.CheckRepoGPG = &s.CheckRepoGPG
+	repo.CheckRepoGPG = common.ToPtr(s.CheckRepoGPG)
 	repo.GPGKeys = s.GPGKeys
 
 	var urls []string
diff --git a/vendor/github.com/osbuild/images/pkg/blueprint/customizations.go b/vendor/github.com/osbuild/images/pkg/blueprint/customizations.go
index b142fa9bf..0fea93545 100644
--- a/vendor/github.com/osbuild/images/pkg/blueprint/customizations.go
+++ b/vendor/github.com/osbuild/images/pkg/blueprint/customizations.go
@@ -211,10 +211,11 @@ func (c *Customizations) GetUsers() []UserCustomization {
 
 	// prepend sshkey for backwards compat (overridden by users)
 	if len(c.SSHKey) > 0 {
-		for _, c := range c.SSHKey {
+		for idx := range c.SSHKey {
+			keyc := c.SSHKey[idx]
 			users = append(users, UserCustomization{
-				Name: c.User,
-				Key:  &c.Key,
+				Name: keyc.User,
+				Key:  &keyc.Key,
 			})
 		}
 	}
diff --git a/vendor/github.com/osbuild/images/pkg/rpmmd/repository.go b/vendor/github.com/osbuild/images/pkg/rpmmd/repository.go
index 03992cc95..6c879ac9b 100644
--- a/vendor/github.com/osbuild/images/pkg/rpmmd/repository.go
+++ b/vendor/github.com/osbuild/images/pkg/rpmmd/repository.go
@@ -245,7 +245,8 @@ func loadRepositoriesFromFile(filename string) (map[string][]RepoConfig, error)
 	}
 
 	for arch, repos := range reposMap {
-		for _, repo := range repos {
+		for idx := range repos {
+			repo := repos[idx]
 			var urls []string
 			if repo.BaseURL != "" {
 				urls = []string{repo.BaseURL}
diff --git a/vendor/modules.txt b/vendor/modules.txt
index ff9c77a1d..fe70574f5 100644
--- a/vendor/modules.txt
+++ b/vendor/modules.txt
@@ -645,7 +645,7 @@ github.com/oracle/oci-go-sdk/v54/identity
 github.com/oracle/oci-go-sdk/v54/objectstorage
 github.com/oracle/oci-go-sdk/v54/objectstorage/transfer
 github.com/oracle/oci-go-sdk/v54/workrequests
-# github.com/osbuild/images v0.3.0-r9.3.3
+# github.com/osbuild/images v0.3.0-r9.3.4
 ## explicit; go 1.19
 github.com/osbuild/images/internal/common
 github.com/osbuild/images/internal/dnfjson


Test patch:
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index 8623ad314..cc80e41f0 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -60,6 +60,8 @@ jobs:
         ports:
           - 5432:5432
     steps:
+    - name: Apt update
+      run: sudo apt-get update
       # gpgme-devel is needed for container upload dependencies
     - name: Install test dependencies
       run: sudo apt-get install -y libgpgme-dev
@@ -117,6 +119,9 @@ jobs:
         with:
           ref: ${{ github.event.pull_request.head.sha }}
 
+      - name: Apt update
+        run: sudo apt-get update
+
       # This is needed to lint internal/upload/koji package
       - name: Install kerberos devel package
         run: sudo apt-get install -y libkrb5-dev
diff --git a/internal/cloudapi/v2/v2_internal_test.go b/internal/cloudapi/v2/v2_internal_test.go
index 9bde9d10a..be52bab60 100644
--- a/internal/cloudapi/v2/v2_internal_test.go
+++ b/internal/cloudapi/v2/v2_internal_test.go
@@ -186,9 +186,10 @@ func TestRepoConfigConversion(t *testing.T) {
 	}
 
 	for idx, tc := range testCases {
+		repoConfig := tc.repoConfig
 		rc, err := genRepoConfig(tc.repo)
 		assert.NoError(err)
-		assert.Equal(&tc.repoConfig, rc, "mismatch in test case %d", idx)
+		assert.Equal(&repoConfig, rc, "mismatch in test case %d", idx)
 	}
 
 	errorTestCases := []struct {
diff --git a/internal/store/store_test.go b/internal/store/store_test.go
index 7f3127dc4..d88d87905 100644
--- a/internal/store/store_test.go
+++ b/internal/store/store_test.go
@@ -489,6 +489,46 @@ func (suite *storeTest) TestRepoConfigMirrorlist() {
 	suite.Equal(expectedRepo, actualRepo)
 }
 
+// Test multiple SourceConfigs with different CheckGPG and CheckRepoGPG settings
+func (suite *storeTest) TestSourceConfigGPGKeysTrueFalse() {
+	// We only care about the GPG bools
+	sources := []SourceConfig{
+		{Name: "source-with-true", CheckGPG: true, CheckRepoGPG: true},
+		{Name: "source-with-false", CheckGPG: false, CheckRepoGPG: false},
+	}
+
+	// source is reused inside the loop, which can result in unexpected changes in go < 1.22
+	// https://go.dev/blog/loopvar-preview
+	var repos []rpmmd.RepoConfig
+	for _, source := range sources {
+		repos = append(repos, source.RepoConfig(source.Name))
+	}
+
+	// First repo should be true, second should be false
+	suite.True(*repos[0].CheckGPG)
+	suite.True(*repos[0].CheckRepoGPG)
+	suite.False(*repos[1].CheckGPG)
+	suite.False(*repos[1].CheckRepoGPG)
+
+	// We only care about the GPG bools
+	// Test with false then true
+	sources = []SourceConfig{
+		{Name: "source-with-false", CheckGPG: false, CheckRepoGPG: false},
+		{Name: "source-with-true", CheckGPG: true, CheckRepoGPG: true},
+	}
+
+	repos = []rpmmd.RepoConfig{}
+	for _, source := range sources {
+		repos = append(repos, source.RepoConfig(source.Name))
+	}
+
+	// First repo should be false, second should be true
+	suite.False(*repos[0].CheckGPG)
+	suite.False(*repos[0].CheckRepoGPG)
+	suite.True(*repos[1].CheckGPG)
+	suite.True(*repos[1].CheckRepoGPG)
+}
+
 func TestStore(t *testing.T) {
 	suite.Run(t, new(storeTest))
 }