Skip to content

Commit

Permalink
Add sha256 digests to RPM packages (#27103) (#27152)
Browse files Browse the repository at this point in the history
Fixes #23670

(cherry picked from commit be63e87)

Co-authored-by: Andrew Kroh <[email protected]>
  • Loading branch information
mergify[bot] and andrewkroh authored Aug 3, 2021
1 parent 4a22981 commit 0bf2fe7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
5 changes: 4 additions & 1 deletion dev-tools/mage/pkgtypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,10 @@ func runFPM(spec PackageSpec, packageType PackageType) error {
"--architecture", spec.Arch,
)
if packageType == RPM {
args = append(args, "--rpm-rpmbuild-define", "_build_id_links none")
args = append(args,
"--rpm-rpmbuild-define", "_build_id_links none",
"--rpm-digest", "sha256",
)
}
if spec.Version != "" {
args = append(args, "--version", spec.Version)
Expand Down
2 changes: 1 addition & 1 deletion dev-tools/mage/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
)

const (
fpmVersion = "1.11.0"
fpmVersion = "1.13.1"

// Docker images. See https://github.com/elastic/golang-crossbuild.
beatsFPMImage = "docker.elastic.co/beats-dev/fpm"
Expand Down
19 changes: 15 additions & 4 deletions dev-tools/packaging/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func TestDocker(t *testing.T) {
// Sub-tests

func checkRPM(t *testing.T, file string) {
p, err := readRPM(file)
p, rpmPkg, err := readRPM(file)
if err != nil {
t.Error(err)
return
Expand All @@ -127,6 +127,7 @@ func checkRPM(t *testing.T, file string) {
checkLicensesPresent(t, "/usr/share", p)
checkSystemdUnitPermissions(t, p)
ensureNoBuildIDLinks(t, p)
checkRPMDigestTypeSHA256(t, rpmPkg)
}

func checkDeb(t *testing.T, file string, buf *bytes.Buffer) {
Expand Down Expand Up @@ -478,6 +479,16 @@ func ensureNoBuildIDLinks(t *testing.T, p *packageFile) {
})
}

// checkRPMDigestTypeSHA256 verifies that the RPM contains sha256 digests.
// https://github.com/elastic/beats/issues/23670
func checkRPMDigestTypeSHA256(t *testing.T, rpmPkg *rpm.PackageFile) {
t.Run("rpm_digest_type_is_sha256", func(t *testing.T) {
if rpmPkg.ChecksumType() != "sha256" {
t.Errorf("expected SHA256 digest type but got %v", rpmPkg.ChecksumType())
}
})
}

// Helpers

type packageFile struct {
Expand Down Expand Up @@ -507,10 +518,10 @@ func getFiles(t *testing.T, pattern *regexp.Regexp) []string {
return files
}

func readRPM(rpmFile string) (*packageFile, error) {
func readRPM(rpmFile string) (*packageFile, *rpm.PackageFile, error) {
p, err := rpm.OpenPackageFile(rpmFile)
if err != nil {
return nil, err
return nil, nil, err
}

contents := p.Files()
Expand All @@ -529,7 +540,7 @@ func readRPM(rpmFile string) (*packageFile, error) {
pf.Contents[file.Name()] = pe
}

return pf, nil
return pf, p, nil
}

// readDeb reads the data.tar.gz file from the .deb.
Expand Down

0 comments on commit 0bf2fe7

Please sign in to comment.