Allow fallback across default ports

When no port is specified, allow falling back from 443 to 80 when
http is specified along with a TLS configuration.

Signed-off-by: Derek McGowan <derek@mcg.dev>
This commit is contained in:
Derek McGowan
2024-05-30 15:57:56 -07:00
parent d4148d94cc
commit 02b6c6939f
4 changed files with 61 additions and 15 deletions

View File

@@ -25,8 +25,15 @@ import (
"net"
"net/http"
"net/url"
"os"
"path"
"strings"
"syscall"
"github.com/containerd/errdefs"
"github.com/containerd/log"
"github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/containerd/containerd/v2/core/images"
"github.com/containerd/containerd/v2/core/remotes"
@@ -35,10 +42,6 @@ import (
"github.com/containerd/containerd/v2/pkg/reference"
"github.com/containerd/containerd/v2/pkg/tracing"
"github.com/containerd/containerd/v2/version"
"github.com/containerd/errdefs"
"github.com/containerd/log"
"github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)
var (
@@ -732,7 +735,7 @@ func (f *httpFallback) RoundTrip(r *http.Request) (*http.Response, error) {
// only fall back if the same host had previously fell back
if f.host != r.URL.Host {
resp, err := f.super.RoundTrip(r)
if !isTLSError(err) {
if !isTLSError(err) && !isPortError(err, r.URL.Host) {
return resp, err
}
}
@@ -773,3 +776,15 @@ func isTLSError(err error) bool {
return false
}
func isPortError(err error, host string) bool {
if errors.Is(err, syscall.ECONNREFUSED) || os.IsTimeout(err) {
if _, port, _ := net.SplitHostPort(host); port != "" {
// Port is specified, will not retry on different port with scheme change
return false
}
return true
}
return false
}