From 39feb0ed5d5b1ee19cb8457c9a7d3b1a894bd5a5 Mon Sep 17 00:00:00 2001 From: "Alex Ellis (OpenFaaS Ltd)" Date: Tue, 17 Dec 2024 10:47:33 +0000 Subject: [PATCH] Allow use of localhost registry for limited testing Limited testing is permitted within the EULA using private images so long as they are published to a registry on localhost. Signed-off-by: Alex Ellis (OpenFaaS Ltd) --- pkg/handlers/validate.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pkg/handlers/validate.go b/pkg/handlers/validate.go index 6c439a8c7..13931fd1f 100644 --- a/pkg/handlers/validate.go +++ b/pkg/handlers/validate.go @@ -9,8 +9,10 @@ package handlers import ( "context" "fmt" + "net" "regexp" "strconv" + "strings" "github.com/google/go-containerregistry/pkg/authn" "github.com/google/go-containerregistry/pkg/name" @@ -98,6 +100,10 @@ func validateScalingLabels(request *types.FunctionDeployment) error { return nil } +// OpenFaaS CE license +// This code is licensed under the OpenFaaS Community Edition (CE) EULA +// A license is required to use public images, however a registry on localhost is supported +// for local testing within the terms of the EULA. func isAnonymous(image string) error { // Use context to cancel or timeout requests ctx := context.Background() @@ -111,6 +117,15 @@ func isAnonymous(image string) error { return fmt.Errorf("unable to parse image reference: %s", err.Error()) } + registryServer := ref.Context().Registry.Name() + + if strings.HasPrefix(registryServer, "localhost") { + host, _, err := net.SplitHostPort(registryServer) + if err == nil && host == "localhost" { + return nil + } + } + if _, err := remote.Head(ref, remote.WithAuth(auth), remote.WithContext(ctx)); err != nil { return fmt.Errorf("the Community Edition license agreement only supports public images") }