Skip to content

Commit cc90dd3

Browse files
authored
Add the CA bundle auto fallback for FROM scratch docker from multicurl to here (#31)
* Add the CA bundle auto fallback for FROM scratch docker from fortio/multicurl#146 here * move to a seperate file and use negative build tag - thx @hhhapz
1 parent 1396d96 commit cc90dd3

5 files changed

Lines changed: 30 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@
1414

1515
# Dependency directories (remove the comment below to include it)
1616
# vendor/
17+
.DS_Store

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,15 @@ Short 'numeric' version (v skipped, useful for docker image tags etc)
130130
% multicurl version
131131
1.10.1
132132
```
133+
134+
### https/tls in FROM scratch docker images
135+
136+
You should always try to use `FROM scratch` Docker images when possible,
137+
it's one of the strength of go.
138+
139+
Using this `fortio.org/cli` as a base makes it work for outcalls to internet valid TLS certs (e.g. https).
140+
It does this by defaulting to the bundle provided by `golang.org/x/crypto/x509roots/fallback` automatically.
141+
142+
See https://github.com/fortio/multicurl for a good example.
143+
144+
If you do not want this behavior, build using `-tag=no_tls_fallback`.

ca_bundle.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Fortio CLI/Main utilities.
2+
//
3+
// (c) 2024 Fortio Authors
4+
// See LICENSE
5+
6+
//go:build !no_tls_fallback
7+
// +build !no_tls_fallback
8+
9+
package cli // import "fortio.org/cli"
10+
11+
// golang.org/x/crypto/x509roots/fallback blank import below is because this is a base for all our main package,
12+
// the CA bundle is needed for FROM scratch images to work with outcalls to internet valid TLS certs (https).
13+
// See https://github.com/fortio/multicurl/pull/146 for instance.
14+
import _ "golang.org/x/crypto/x509roots/fallback" // This is a base for main, see extended comment above.

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.18
55
require (
66
fortio.org/log v1.12.2
77
fortio.org/version v1.0.4
8+
golang.org/x/crypto/x509roots/fallback v0.0.0-20240604170348-d4e7c9cb6cb8
89
)
910

1011
require fortio.org/struct2env v0.4.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ fortio.org/struct2env v0.4.0 h1:k5alSOTf3YHiB3MuacjDHQ3YhVWvNZ95ZP/a6MqvyLo=
44
fortio.org/struct2env v0.4.0/go.mod h1:lENUe70UwA1zDUCX+8AsO663QCFqYaprk5lnPhjD410=
55
fortio.org/version v1.0.4 h1:FWUMpJ+hVTNc4RhvvOJzb0xesrlRmG/a+D6bjbQ4+5U=
66
fortio.org/version v1.0.4/go.mod h1:2JQp9Ax+tm6QKiGuzR5nJY63kFeANcgrZ0osoQFDVm0=
7+
golang.org/x/crypto/x509roots/fallback v0.0.0-20240604170348-d4e7c9cb6cb8 h1:+kWDWI3Eb5cPIOr4cP+R2RLDwK3/dXppL+7XmSOh2LA=
8+
golang.org/x/crypto/x509roots/fallback v0.0.0-20240604170348-d4e7c9cb6cb8/go.mod h1:kNa9WdvYnzFwC79zRpLRMJbdEFlhyM5RPFBBZp/wWH8=

0 commit comments

Comments
 (0)