domainconnect

package
v1.5.18 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 21 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package domainconnect holds the install side of the Domain Connect sync flow (ADR 091). It never holds a signing key: the signer service does.

Index

Constants

View Source
const (
	KindApp     = "app"
	KindPreview = "preview"
)

Record kinds a flow can apply.

Variables

View Source
var (
	ErrBlockedAddress = errors.New("domainconnect: address is not allowed")
	ErrTooLarge       = errors.New("domainconnect: response is too large")
	ErrRedirect       = errors.New("domainconnect: redirects are not followed")
	ErrBadURL         = errors.New("domainconnect: url must be https with a host name")
)

Errors returned by the guarded fetcher.

View Source
var (
	ErrBadState     = errors.New("domainconnect: state is not valid")
	ErrStateExpired = errors.New("domainconnect: state has expired")
	ErrStateOrigin  = errors.New("domainconnect: state belongs to another origin")
	ErrReturnURL    = errors.New("domainconnect: return url is not allowed")
)

Errors returned by state and return URL checks.

View Source
var (
	ErrNotSupported = errors.New("domainconnect: no Domain Connect provider found for this domain")
	ErrNotHosted    = errors.New("domainconnect: the provider does not host this zone")
	ErrBadSettings  = errors.New("domainconnect: provider settings are not usable")
	ErrBadInput     = errors.New("domainconnect: invalid input")
)

Errors returned by discovery and input validation.

Functions

func AppendSignature

func AppendSignature(unsigned, sig, key string) string

AppendSignature adds sig and key as the last parameters, as providers require.

func BuildApplyURL

func BuildApplyURL(p ApplyParams) (string, error)

BuildApplyURL returns the unsigned apply URL with a fixed key order: domain, host, redirect_uri, state, groupId, then variables sorted by name.

func BuildSignerURL

func BuildSignerURL(r SignerRequest) (string, error)

BuildSignerURL returns the signer start URL for the browser to open.

func DraftTemplate

func DraftTemplate(serviceID string) (map[string]any, error)

DraftTemplate returns the parsed draft for a service id.

func NewNonce

func NewNonce() (string, error)

NewNonce returns a random single-use value for a new flow.

func NormalizeDomain

func NormalizeDomain(raw string) (string, error)

NormalizeDomain lowercases and validates a public DNS name with at least two labels.

func ParseReturnURL

func ParseReturnURL(raw string) (*url.URL, string, error)

ParseReturnURL accepts an https URL, or http on exactly localhost or 127.0.0.1 with any port, with no credentials. It returns the URL and its origin.

func SignState

func SignState(key []byte, origin, domain, nonce string, ttl time.Duration, now time.Time) (string, error)

SignState returns payload.mac, both base64url, valid until now+ttl.

func SignedPayload

func SignedPayload(unsigned string) string

SignedPayload returns the query string that is signed: everything after the question mark.

func ZoneCandidates

func ZoneCandidates(domain string) ([]string, error)

ZoneCandidates lists the names to try for the zone root, longest first, ending at the registrable domain (public suffix plus one label).

Types

type ApplyParams

type ApplyParams struct {
	URLSyncUX   string
	ProviderID  string
	ServiceID   string
	Domain      string // zone root
	Host        string // below the root, empty for the root
	RedirectURI string
	State       string
	GroupID     string
	Variables   map[string]string
}

ApplyParams are the parts of a sync apply URL before signing.

type Claims

type Claims struct {
	Origin string `json:"o"`
	Domain string `json:"d"`
	Nonce  string `json:"n"`
	Expiry int64  `json:"e"`
}

Claims is what the flow token binds. The key comes from the install's existing derived-key facility (secrets.Manager.DeriveKey with a purpose string), so no new secret store exists.

func VerifyState

func VerifyState(key []byte, token, wantOrigin string, now time.Time) (Claims, error)

VerifyState checks the MAC in constant time, then expiry, then that the token was minted for wantOrigin. The origin is never read from the request.

type Config

type Config struct {
	DiscoveryTimeout time.Duration
	CacheTTL         time.Duration
	MaxResponseBytes int64
}

Config carries the values of the domainconnect.* runtime settings.

type Discoverer

type Discoverer struct {
	// contains filtered or unexported fields
}

Discoverer finds the Domain Connect provider of a domain.

func NewDiscoverer

func NewDiscoverer(cfg Config) (*Discoverer, error)

NewDiscoverer builds a Discoverer from the domainconnect.* setting values.

func (*Discoverer) Discover

func (d *Discoverer) Discover(ctx context.Context, domain string) (*Discovery, error)

Discover finds the provider for domain, walking up to the zone root. Results, including "no sync flow", are cached; errors are not.

type Discovery

type Discovery struct {
	Domain        string `json:"domain"`
	Zone          string `json:"zone"`
	Host          string `json:"host"`
	ProviderID    string `json:"provider_id"`
	ProviderName  string `json:"provider_name"`
	URLSyncUX     string `json:"url_sync_ux"`
	URLAPI        string `json:"url_api"`
	SyncAvailable bool   `json:"sync_available"`
}

Discovery is the answer for one domain. Zone is the root the provider hosts, Host is the part of the domain below it (empty for the root itself).

type Fetcher

type Fetcher struct {
	// contains filtered or unexported fields
}

Fetcher does GET requests that can only reach public addresses.

func NewFetcher

func NewFetcher(timeout time.Duration, maxBytes int64) (*Fetcher, error)

NewFetcher needs both limits from settings; there are no built-in defaults.

func (*Fetcher) Get

func (f *Fetcher) Get(ctx context.Context, raw string) ([]byte, int, error)

Get returns the body and status of an https URL. The name is resolved once before the request and again at dial time, and the dial goes to the checked address, so a name that flips to a private address between the two is refused.

type SignerRequest

type SignerRequest struct {
	SignerURL string
	Domain    string // zone root
	Host      string
	Kind      string // KindApp or KindPreview
	IP        string
	ReturnURL string
	State     string
}

SignerRequest is what the install hands to the signer. It holds no secret.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL