Skip to content

Commit

Permalink
Add the CA bundle auto fallback for FROM scratch docker from multicur…
Browse files Browse the repository at this point in the history
…l 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
  • Loading branch information
ldemailly committed Jun 23, 2024
1 parent 1396d96 commit cc90dd3
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@

# Dependency directories (remove the comment below to include it)
# vendor/
.DS_Store
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,15 @@ Short 'numeric' version (v skipped, useful for docker image tags etc)
% multicurl version
1.10.1
```
### https/tls in FROM scratch docker images
You should always try to use `FROM scratch` Docker images when possible,
it's one of the strength of go.
Using this `fortio.org/cli` as a base makes it work for outcalls to internet valid TLS certs (e.g. https).
It does this by defaulting to the bundle provided by `golang.org/x/crypto/x509roots/fallback` automatically.
See https://github.com/fortio/multicurl for a good example.
If you do not want this behavior, build using `-tag=no_tls_fallback`.
14 changes: 14 additions & 0 deletions ca_bundle.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Fortio CLI/Main utilities.
//
// (c) 2024 Fortio Authors
// See LICENSE

//go:build !no_tls_fallback
// +build !no_tls_fallback

package cli // import "fortio.org/cli"

// golang.org/x/crypto/x509roots/fallback blank import below is because this is a base for all our main package,
// the CA bundle is needed for FROM scratch images to work with outcalls to internet valid TLS certs (https).
// See https://github.com/fortio/multicurl/pull/146 for instance.
import _ "golang.org/x/crypto/x509roots/fallback" // This is a base for main, see extended comment above.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.18
require (
fortio.org/log v1.12.2
fortio.org/version v1.0.4
golang.org/x/crypto/x509roots/fallback v0.0.0-20240604170348-d4e7c9cb6cb8
)

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

0 comments on commit cc90dd3

Please sign in to comment.