Skip to content

Commit e79b573

Browse files
committed
storage: change Artifact checksum to SHA256
This changes the format of the Artifact checksum from SHA1 to SHA256 to mitigate chosen-prefix and length extension attacks, and ensures it can be used to secure content against malicious modifications. Source consumers (including our own {kustomize,helm}-controllers) should ensure the SHA256 of a downloaded artifact matches the advertised checksum before making use of it. Signed-off-by: Hidde Beydals <[email protected]>
1 parent f9995ee commit e79b573

8 files changed

+16
-16
lines changed

api/v1beta1/artifact_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type Artifact struct {
3939
// +optional
4040
Revision string `json:"revision"`
4141

42-
// Checksum is the SHA1 checksum of the artifact.
42+
// Checksum is the SHA256 checksum of the artifact.
4343
// +optional
4444
Checksum string `json:"checksum"`
4545

config/crd/bases/source.toolkit.fluxcd.io_buckets.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ spec:
9898
description: Artifact represents the output of the last successful Bucket sync.
9999
properties:
100100
checksum:
101-
description: Checksum is the SHA1 checksum of the artifact.
101+
description: Checksum is the SHA256 checksum of the artifact.
102102
type: string
103103
lastUpdateTime:
104104
description: LastUpdateTime is the timestamp corresponding to the last update of this artifact.

config/crd/bases/source.toolkit.fluxcd.io_gitrepositories.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ spec:
155155
description: Artifact represents the output of the last successful repository sync.
156156
properties:
157157
checksum:
158-
description: Checksum is the SHA1 checksum of the artifact.
158+
description: Checksum is the SHA256 checksum of the artifact.
159159
type: string
160160
lastUpdateTime:
161161
description: LastUpdateTime is the timestamp corresponding to the last update of this artifact.
@@ -224,7 +224,7 @@ spec:
224224
description: Artifact represents the output of a source synchronisation.
225225
properties:
226226
checksum:
227-
description: Checksum is the SHA1 checksum of the artifact.
227+
description: Checksum is the SHA256 checksum of the artifact.
228228
type: string
229229
lastUpdateTime:
230230
description: LastUpdateTime is the timestamp corresponding to the last update of this artifact.

config/crd/bases/source.toolkit.fluxcd.io_helmcharts.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ spec:
109109
description: Artifact represents the output of the last successful chart sync.
110110
properties:
111111
checksum:
112-
description: Checksum is the SHA1 checksum of the artifact.
112+
description: Checksum is the SHA256 checksum of the artifact.
113113
type: string
114114
lastUpdateTime:
115115
description: LastUpdateTime is the timestamp corresponding to the last update of this artifact.

config/crd/bases/source.toolkit.fluxcd.io_helmrepositories.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ spec:
8383
description: Artifact represents the output of the last successful repository sync.
8484
properties:
8585
checksum:
86-
description: Checksum is the SHA1 checksum of the artifact.
86+
description: Checksum is the SHA256 checksum of the artifact.
8787
type: string
8888
lastUpdateTime:
8989
description: LastUpdateTime is the timestamp corresponding to the last update of this artifact.

controllers/gitrepository_controller_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ func TestGitRepositoryReconciler_reconcileArtifact(t *testing.T) {
578578
},
579579
afterFunc: func(t *WithT, obj *sourcev1.GitRepository, artifact sourcev1.Artifact) {
580580
t.Expect(obj.GetArtifact()).ToNot(BeNil())
581-
t.Expect(obj.GetArtifact().Checksum).To(Equal("b1fab897a1a0fb8094ce3ae0e9743a4b72bd7268"))
581+
t.Expect(obj.GetArtifact().Checksum).To(Equal("ef9c34eab0584035ac8b8a4070876954ea46f270250d60648672feef3e943426"))
582582
t.Expect(obj.Status.URL).ToNot(BeEmpty())
583583
},
584584
want: ctrl.Result{RequeueAfter: interval},
@@ -595,7 +595,7 @@ func TestGitRepositoryReconciler_reconcileArtifact(t *testing.T) {
595595
},
596596
afterFunc: func(t *WithT, obj *sourcev1.GitRepository, artifact sourcev1.Artifact) {
597597
t.Expect(obj.GetArtifact()).ToNot(BeNil())
598-
t.Expect(obj.GetArtifact().Checksum).To(Equal("b1fab897a1a0fb8094ce3ae0e9743a4b72bd7268"))
598+
t.Expect(obj.GetArtifact().Checksum).To(Equal("ef9c34eab0584035ac8b8a4070876954ea46f270250d60648672feef3e943426"))
599599
t.Expect(obj.Status.IncludedArtifacts).ToNot(BeEmpty())
600600
t.Expect(obj.Status.URL).ToNot(BeEmpty())
601601
},
@@ -630,7 +630,7 @@ func TestGitRepositoryReconciler_reconcileArtifact(t *testing.T) {
630630
},
631631
afterFunc: func(t *WithT, obj *sourcev1.GitRepository, artifact sourcev1.Artifact) {
632632
t.Expect(obj.GetArtifact()).ToNot(BeNil())
633-
t.Expect(obj.GetArtifact().Checksum).To(Equal("a71f8c076db814bc21c16cecc960c4fcaf970ac5"))
633+
t.Expect(obj.GetArtifact().Checksum).To(Equal("dc95ae14c19d335b693bbba58ae2a562242b0cf33893baffd1b7605ba578e0d6"))
634634
},
635635
want: ctrl.Result{RequeueAfter: interval},
636636
assertConditions: []metav1.Condition{
@@ -646,7 +646,7 @@ func TestGitRepositoryReconciler_reconcileArtifact(t *testing.T) {
646646
},
647647
afterFunc: func(t *WithT, obj *sourcev1.GitRepository, artifact sourcev1.Artifact) {
648648
t.Expect(obj.GetArtifact()).ToNot(BeNil())
649-
t.Expect(obj.GetArtifact().Checksum).To(Equal("b1fab897a1a0fb8094ce3ae0e9743a4b72bd7268"))
649+
t.Expect(obj.GetArtifact().Checksum).To(Equal("ef9c34eab0584035ac8b8a4070876954ea46f270250d60648672feef3e943426"))
650650
t.Expect(obj.Status.URL).ToNot(BeEmpty())
651651
},
652652
want: ctrl.Result{RequeueAfter: interval},
@@ -663,7 +663,7 @@ func TestGitRepositoryReconciler_reconcileArtifact(t *testing.T) {
663663
},
664664
afterFunc: func(t *WithT, obj *sourcev1.GitRepository, artifact sourcev1.Artifact) {
665665
t.Expect(obj.GetArtifact()).ToNot(BeNil())
666-
t.Expect(obj.GetArtifact().Checksum).To(Equal("b1fab897a1a0fb8094ce3ae0e9743a4b72bd7268"))
666+
t.Expect(obj.GetArtifact().Checksum).To(Equal("ef9c34eab0584035ac8b8a4070876954ea46f270250d60648672feef3e943426"))
667667
t.Expect(obj.Status.URL).ToNot(BeEmpty())
668668
},
669669
want: ctrl.Result{RequeueAfter: interval},

controllers/storage.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package controllers
1919
import (
2020
"archive/tar"
2121
"compress/gzip"
22-
"crypto/sha1"
22+
"crypto/sha256"
2323
"fmt"
2424
"hash"
2525
"io"
@@ -425,7 +425,7 @@ func (s *Storage) Symlink(artifact sourcev1.Artifact, linkName string) (string,
425425
return url, nil
426426
}
427427

428-
// Checksum returns the SHA1 checksum for the data of the given io.Reader as a string.
428+
// Checksum returns the SHA256 checksum for the data of the given io.Reader as a string.
429429
func (s *Storage) Checksum(reader io.Reader) string {
430430
h := newHash()
431431
_, _ = io.Copy(h, reader)
@@ -451,7 +451,7 @@ func (s *Storage) LocalPath(artifact sourcev1.Artifact) string {
451451
return path
452452
}
453453

454-
// newHash returns a new SHA1 hash.
454+
// newHash returns a new SHA256 hash.
455455
func newHash() hash.Hash {
456-
return sha1.New()
456+
return sha256.New()
457457
}

docs/api/source.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ string
839839
</td>
840840
<td>
841841
<em>(Optional)</em>
842-
<p>Checksum is the SHA1 checksum of the artifact.</p>
842+
<p>Checksum is the SHA256 checksum of the artifact.</p>
843843
</td>
844844
</tr>
845845
<tr>

0 commit comments

Comments
 (0)