Skip to content

Commit 8429708

Browse files
author
Paulo Gomes
committed
Upgrade libgit2 to libgit2-1.3.0-2
Signed-off-by: Paulo Gomes <[email protected]>
1 parent f0d7a6b commit 8429708

File tree

8 files changed

+50
-27
lines changed

8 files changed

+50
-27
lines changed

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ ARG GO_VERSION=1.17
33
ARG XX_VERSION=1.1.0
44

55
ARG LIBGIT2_IMG=ghcr.io/fluxcd/golang-with-libgit2
6-
ARG LIBGIT2_TAG=libgit2-1.1.1-7
6+
ARG LIBGIT2_TAG=libgit2-1.3.0-2
77

88
FROM ${LIBGIT2_IMG}:${LIBGIT2_TAG} AS libgit2-libs
99

Makefile

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ TAG ?= latest
44

55
# Base image used to build the Go binary
66
LIBGIT2_IMG ?= ghcr.io/fluxcd/golang-with-libgit2
7-
LIBGIT2_TAG ?= libgit2-1.1.1-7
7+
LIBGIT2_TAG ?= libgit2-1.3.0-2
88

99
# Allows for defining additional Docker buildx arguments,
1010
# e.g. '--push'.
@@ -136,6 +136,7 @@ tidy: ## Run go mod tidy
136136
fmt: ## Run go fmt against code
137137
go fmt ./...
138138
cd api; go fmt ./...
139+
cd tests/fuzz; go fmt .
139140

140141
vet: $(LIBGIT2) ## Run go vet against code
141142
go vet ./...
@@ -208,6 +209,12 @@ ifneq ($(shell grep -o 'LIBGIT2_IMG ?= \w.*' Makefile | cut -d ' ' -f 3):$(shell
208209
exit 1; \
209210
}
210211
endif
212+
ifneq ($(shell grep -o 'LIBGIT2_TAG ?= \w.*' Makefile | cut -d ' ' -f 3), $(shell grep -o "LIBGIT2_TAG=.*" tests/fuzz/oss_fuzz_build.sh | sed 's;LIBGIT2_TAG="$${LIBGIT2_TAG:-;;g' | sed 's;}";;g'))
213+
@{ \
214+
echo "LIBGIT2_TAG must match in both Makefile and tests/fuzz/oss_fuzz_build.sh"; \
215+
exit 1; \
216+
}
217+
endif
211218
ifneq (, $(shell git status --porcelain --untracked-files=no))
212219
@{ \
213220
echo "working directory is dirty:"; \

hack/install-libraries.sh

-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ function setup_current() {
4545
mkdir -p "./build/libgit2"
4646
if [[ $OSTYPE == 'darwin'* ]]; then
4747
# For MacOS development environments, download the amd64 static libraries released from from golang-with-libgit2.
48-
49-
#TODO: update URL with official URL + TAG:
5048
curl -o output.tar.gz -LO "https://github.com/fluxcd/golang-with-libgit2/releases/download/${TAG}/darwin-libs.tar.gz"
5149

5250
DIR=libgit2-darwin

pkg/git/libgit2/checkout_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ import (
2626
"testing"
2727
"time"
2828

29-
"github.com/fluxcd/pkg/gittestserver"
30-
"github.com/fluxcd/pkg/ssh"
3129
git2go "github.com/libgit2/git2go/v33"
3230
. "github.com/onsi/gomega"
3331
corev1 "k8s.io/api/core/v1"
3432

33+
"github.com/fluxcd/pkg/gittestserver"
34+
"github.com/fluxcd/pkg/ssh"
35+
3536
"github.com/fluxcd/source-controller/pkg/git"
3637
)
3738

pkg/git/libgit2/transport.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func transferProgressCallback(ctx context.Context) git2go.TransferProgressCallba
6868
}
6969
select {
7070
case <-ctx.Done():
71-
return fmt.Errorf("transport close - potentially due to a timeout")
71+
return fmt.Errorf("transport close (potentially due to a timeout)")
7272
default:
7373
return nil
7474
}
@@ -100,7 +100,7 @@ func pushTransferProgressCallback(ctx context.Context) git2go.PushTransferProgre
100100
}
101101
select {
102102
case <-ctx.Done():
103-
return fmt.Errorf("transport close - potentially due to a timeout")
103+
return fmt.Errorf("transport close (potentially due to a timeout)")
104104
default:
105105
return nil
106106
}
@@ -158,7 +158,7 @@ func x509Callback(caBundle []byte) git2go.CertificateCheckCallback {
158158
return func(cert *git2go.Certificate, valid bool, hostname string) error {
159159
roots := x509.NewCertPool()
160160
if ok := roots.AppendCertsFromPEM(caBundle); !ok {
161-
return fmt.Errorf("x509 cert could not be appended")
161+
return fmt.Errorf("PEM CA bundle could not be appended to x509 certificate pool")
162162
}
163163

164164
opts := x509.VerifyOptions{
@@ -167,7 +167,7 @@ func x509Callback(caBundle []byte) git2go.CertificateCheckCallback {
167167
CurrentTime: now(),
168168
}
169169
if _, err := cert.X509.Verify(opts); err != nil {
170-
return fmt.Errorf("x509 cert could not be verified")
170+
return fmt.Errorf("verification failed: %w", err)
171171
}
172172
return nil
173173
}
@@ -200,7 +200,7 @@ func knownHostsCallback(host string, knownHosts []byte) git2go.CertificateCheckC
200200
}
201201

202202
if hostnameWithoutPort != hostWithoutPort {
203-
return fmt.Errorf("host mismatch: %q %q\n", hostWithoutPort, hostnameWithoutPort)
203+
return fmt.Errorf("host mismatch: %q %q", hostWithoutPort, hostnameWithoutPort)
204204
}
205205

206206
// We are now certain that the configured host and the hostname

pkg/git/libgit2/transport_test.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -159,28 +159,28 @@ func Test_x509Callback(t *testing.T) {
159159
certificate: googleLeafWithInvalidHashFixture,
160160
host: "www.google.com",
161161
caBundle: []byte(giag2IntermediateFixture + "\n" + geoTrustRootFixture),
162-
want: fmt.Errorf("x509 cert could not be verified"),
162+
want: fmt.Errorf(`verification failed: x509: certificate signed by unknown authority (possibly because of "x509: cannot verify signature: algorithm unimplemented" while trying to verify candidate authority certificate "Google Internet Authority G2")`),
163163
},
164164
{
165165
name: "Invalid certificate authority bundle",
166166
certificate: googleLeafFixture,
167167
host: "www.google.com",
168168
caBundle: bytes.Trim([]byte(giag2IntermediateFixture+"\n"+geoTrustRootFixture), "-"),
169-
want: fmt.Errorf("x509 cert could not be appended"),
169+
want: fmt.Errorf("PEM CA bundle could not be appended to x509 certificate pool"),
170170
},
171171
{
172172
name: "Missing intermediate in bundle",
173173
certificate: googleLeafFixture,
174174
host: "www.google.com",
175175
caBundle: []byte(geoTrustRootFixture),
176-
want: fmt.Errorf("x509 cert could not be verified"),
176+
want: fmt.Errorf("verification failed: x509: certificate signed by unknown authority"),
177177
},
178178
{
179179
name: "Invalid host",
180180
certificate: googleLeafFixture,
181181
host: "www.google.co",
182182
caBundle: []byte(giag2IntermediateFixture + "\n" + geoTrustRootFixture),
183-
want: fmt.Errorf("x509 cert could not be verified"),
183+
want: fmt.Errorf("verification failed: x509: certificate is valid for www.google.com, not www.google.co"),
184184
},
185185
}
186186
for _, tt := range tests {
@@ -195,11 +195,11 @@ func Test_x509Callback(t *testing.T) {
195195
}
196196

197197
callback := x509Callback(tt.caBundle)
198-
result := g.Expect(callback(cert, false, tt.host))
198+
result := callback(cert, false, tt.host)
199199
if tt.want == nil {
200-
result.To(BeNil())
200+
g.Expect(result).To(BeNil())
201201
} else {
202-
result.To(Equal(tt.want))
202+
g.Expect(result.Error()).To(Equal(tt.want.Error()))
203203
}
204204
})
205205
}
@@ -236,7 +236,7 @@ func Test_knownHostsCallback(t *testing.T) {
236236
knownHosts: []byte(knownHostsFixture),
237237
hostkey: git2go.HostkeyCertificate{Kind: git2go.HostkeySHA1 | git2go.HostkeyMD5, HashSHA1: sha1Fingerprint("v2toJdKXfFEaR1u++4iq1UqSrHM")},
238238
expectedHost: "example.com",
239-
want: fmt.Errorf("host mismatch: %q %q\n", "example.com", "github.com"),
239+
want: fmt.Errorf("host mismatch: %q %q", "example.com", "github.com"),
240240
},
241241
{
242242
name: "Hostkey mismatch",
@@ -399,7 +399,7 @@ func Test_transferProgressCallback(t *testing.T) {
399399
ReceivedObjects: 21,
400400
},
401401
cancelFunc: func(cf context.CancelFunc) { cf() },
402-
wantErr: fmt.Errorf("transport close - potentially due to a timeout"),
402+
wantErr: fmt.Errorf("transport close (potentially due to a timeout)"),
403403
},
404404
}
405405

@@ -497,7 +497,7 @@ func Test_pushTransferProgressCallback(t *testing.T) {
497497
name: "error - context cancelled",
498498
progress: pushProgress{current: 20, total: 25},
499499
cancelFunc: func(cf context.CancelFunc) { cf() },
500-
wantErr: fmt.Errorf("transport close - potentially due to a timeout"),
500+
wantErr: fmt.Errorf("transport close (potentially due to a timeout)"),
501501
},
502502
}
503503

tests/fuzz/gitrepository_fuzzer.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ import (
3838
"time"
3939

4040
fuzz "github.com/AdaLogics/go-fuzz-headers"
41-
"github.com/fluxcd/pkg/gittestserver"
42-
"github.com/fluxcd/pkg/runtime/testenv"
43-
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
44-
"github.com/fluxcd/source-controller/controllers"
4541
"github.com/go-git/go-billy/v5"
4642
"github.com/go-git/go-billy/v5/memfs"
4743
"github.com/go-git/go-git/v5"
@@ -61,6 +57,11 @@ import (
6157
"sigs.k8s.io/controller-runtime/pkg/client"
6258
"sigs.k8s.io/controller-runtime/pkg/envtest"
6359
"sigs.k8s.io/controller-runtime/pkg/manager"
60+
61+
"github.com/fluxcd/pkg/gittestserver"
62+
"github.com/fluxcd/pkg/runtime/testenv"
63+
sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
64+
"github.com/fluxcd/source-controller/controllers"
6465
)
6566

6667
var (

tests/fuzz/oss_fuzz_build.sh

+18-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
set -euxo pipefail
1818

19-
LIBGIT2_TAG="${LIBGIT2_TAG:-libgit2-1.1.1-7}"
19+
LIBGIT2_TAG="${LIBGIT2_TAG:-libgit2-1.3.0-2}"
2020
GOPATH="${GOPATH:-/root/go}"
2121
GO_SRC="${GOPATH}/src"
2222
PROJECT_PATH="github.com/fluxcd/source-controller"
@@ -54,10 +54,25 @@ export PKG_CONFIG_PATH="${TARGET_DIR}/lib/pkgconfig:${TARGET_DIR}/lib64/pkgconfi
5454
export CGO_CFLAGS="-I${TARGET_DIR}/include -I${TARGET_DIR}/include/openssl"
5555
export CGO_LDFLAGS="$(pkg-config --libs --static --cflags libssh2 openssl libgit2)"
5656

57-
go mod tidy -compat=1.17
57+
go mod tidy
58+
59+
# The implementation of libgit2 is sensitive to the versions of git2go.
60+
# Leaving it to its own devices, the minimum version of git2go used may not
61+
# be compatible with the currently implemented version. Hence the modifications
62+
# of the existing go.mod.
63+
sed "s;\./api;$(/bin/pwd)/api;g" go.mod > tests/fuzz/go.mod
64+
sed -i 's;module github.com/fluxcd/source-controller;module github.com/fluxcd/source-controller/tests/fuzz;g' tests/fuzz/go.mod
65+
echo "replace github.com/fluxcd/source-controller => $(/bin/pwd)/" >> tests/fuzz/go.mod
66+
67+
cp go.sum tests/fuzz/go.sum
5868

5969
pushd "tests/fuzz"
6070

71+
go mod download
72+
73+
go get -d github.com/AdaLogics/go-fuzz-headers
74+
go get -d github.com/fluxcd/source-controller
75+
6176
# Setup files to be embedded into controllers_fuzzer.go's testFiles variable.
6277
mkdir -p testdata/crd
6378
cp ../../config/crd/bases/*.yaml testdata/crd/
@@ -89,6 +104,7 @@ go_compile FuzzRandomGitFiles fuzz_gitrepository_fuzzer
89104
go_compile FuzzGitResourceObject fuzz_git_resource_object
90105

91106
# By now testdata is embedded in the binaries and no longer needed.
107+
# Remove the dir given that it will be owned by root otherwise.
92108
rm -rf testdata/
93109

94110
popd

0 commit comments

Comments
 (0)