The micro-VM for AI agents — light enough to embed on your laptop, elastic enough to power an agentic cloud.
// Copyright 2026 BoxLite AI
// SPDX-License-Identifier: AGPL-3.0
package proxy
import (
"context"
"errors"
"fmt"
"strings"
)
// ErrHostRefused means the registry proxy will not pull from that upstream.
var ErrHostRefused = errors.New("upstream host refused")
// upstreamAllowlist permits anonymous forwarding to operator-selected
// registries. A custom upstream requires a matching organization credential.
type upstreamAllowlist map[string]struct{}
type customRegistryKey struct{}
func isCustomRegistry(ctx context.Context) bool {
return ctx.Value(customRegistryKey{}) != nil
}
func newUpstreamAllowlist(hosts []string) upstreamAllowlist {
allowed := upstreamAllowlist{}
for _, host := range hosts {
host = strings.ToLower(strings.TrimSpace(host))
if host != "" {
allowed[host] = struct{}{}
}
}
return allowed
}
// permit reports whether an anonymous pull may be forwarded to host.
//
// host is the published registry name from the path, not the endpoint it
// resolves to: an operator allows docker.io, which is the name they know, and
// never writes registry-1.docker.io.
func (a upstreamAllowlist) permit(host string) error {
if _, allowed := a[strings.ToLower(host)]; !allowed {
return fmt.Errorf("%w: %s is not a registry this proxy pulls from", ErrHostRefused, host)
}
return nil
}