SDK API
SDK endpoints are the stable lease protocol between a Portal tunnel process and
a relay. Normal JSON endpoints use the shared envelope from API Reference. GET /sdk/connect is the only SDK endpoint
that upgrades from ordinary HTTP into the reverse transport.
Flow
GET /sdk/domainchecks relay compatibility, hostname namespace and tenant issuance capabilities, optional ENS support, and optional relay-owned Sui x402 control-plane facilitator support.POST /sdk/register/challengecreates a SIWE challenge for the requested identity.- The SDK signs the returned
siwe_message. POST /sdk/registerexchanges the signature for a leaseaccess_tokenand a genericreverse_endpoint.- The SDK keeps the lease alive with
/sdk/renewand opens reverse streams at the returned endpoint using its opaque capability. POST /sdk/unregisterremoves the lease.
A relay that sets TUNNEL_SOURCE_CIDRS answers /sdk/register/challenge, /sdk/register and /sdk/renew from any other network with 403 source_not_allowed, before it spends any pre-auth budget. The SDK treats it
as terminal for that relay.
Endpoints
| Method | Path | Auth | Body | Data |
|---|---|---|---|---|
GET | /sdk/domain | None | none | DomainResponse |
POST | /sdk/register/challenge | None | RegisterChallengeRequest | RegisterChallengeResponse |
POST | /sdk/register | SIWE signature body | RegisterRequest | RegisterResponse |
POST | /sdk/renew | lease token body | RenewRequest | RenewResponse |
POST | /sdk/reverse | lease token body | ReverseEndpointRequest | ReverseEndpoint |
POST | /sdk/unregister | lease token body | UnregisterRequest | {} |
GET | /sdk/connect | reverse capability header or WebSocket subprotocol | none | raw stream or WebSocket/yamux session |
POST | /sdk/cache | lease token header | StaticCacheManifest JSON | StaticCacheStatus |
PUT | /sdk/cache | lease token header | manifest and file bytes as multipart | StaticCacheStatus |
DELETE | /sdk/cache | lease token header | none | StaticCacheStatus |
POST | /v1/tenant-certificate | lease token header | TenantCertificateRequest | TenantCertificateResponse |
Domain
GET /sdk/domain returns:
| Field | Type | Notes |
|---|---|---|
protocol_version | string | default SDK tunnel protocol, currently 10 |
supported_protocol_versions | string[] | optional authoritative protocol list, currently ["10"]; absent or null falls back to the default, an empty list supports nothing |
replicas | boolean | true when opt-in concurrent HTTP leases are supported; absent means unsupported |
release_version | string | relay software release |
namespaces | string[] | optional; includes local-tls-v1 when new canonical Local TLS is supported |
approval_mode | string | effective local publisher admission mode (auto or manual); older relays may omit it |
tenant_certificate_issuance | boolean | optional; whether automatic tenant issuance is enabled; independent of manual Local TLS support. An absent field means an older relay did not report this capability |
cache | StaticCacheLimits | optional; advertised when static caching is enabled |
ens | ENSStatus | gasless ENS status |
x402 | X402FacilitatorInfo | relay-owned Sui x402 control-plane facilitator status |
ENSStatus:
| Field | Type |
|---|---|
enabled, verified | boolean |
provider, address, dnssec_state, ds_record, message, last_error | string |
X402FacilitatorInfo:
| Field | Type |
|---|---|
enabled | boolean |
url, network, network_name, supported_url, pay_to | string |
This object describes the relay’s own optional x402 facilitator for control-plane resources. It is separate from tunnel-owned routed HTTP payments, which are configured locally by the tunnel process.
Register Challenge
RegisterChallengeRequest:
| Field | Type | Required | Notes |
|---|---|---|---|
identity | Identity | yes | name and address |
protocol_version | string | no | selected SDK protocol; omission uses the advertised default, unsupported values return HTTP 426 protocol_incompatible before a challenge is allocated |
namespace | string | no | local-tls-v1 requests the Local TLS canonical; omission grants only a friendly alias. Unknown values are rejected |
replica | boolean | no | join concurrent HTTP leases for this identity; requires replicas: true from /sdk/domain; defaults to exclusive replacement |
metadata | LeaseMetadata | no | public lease metadata |
overlay | boolean | no | prefer an IVNP overlay path when available; defaults to false |
ttl | number | no | Requested seconds; non-positive values use 120, maximum 600. Larger values return HTTP 400. |
udp_enabled | boolean | no | request UDP transport |
tcp_enabled | boolean | no | request dedicated TCP port |
started_at | string | no | Client-reported tunnel start time (RFC 3339). first_seen_at is relay-observed lease continuity: for a lease the relay has not seen, it uses started_at, clamped to no later than registration and no earlier than 7 days before it. A registration that replaces a live lease keeps the earlier first_seen_at. |
cache | boolean | no | Explicitly permit static storage and relay TLS termination; default false |
cache_ttl | number | no | Requested offline seconds; 0 uses relay policy, positive values are clamped |
Cache opt-in is incompatible with raw TCP/UDP leases.
For local-tls-v1, protocol-level cache opt-in still names only the separate
friendly alias. Canonical URLs are never cache eligible. Local TLS and alias caching can be combined.
RegisterChallengeResponse:
| Field | Type |
|---|---|
challenge_id | string |
expires_at | string |
siwe_message | string |
Register
RegisterRequest:
| Field | Type | Required |
|---|---|---|
challenge_id | string | yes |
siwe_message | string | yes |
siwe_signature | string | yes |
reported_ip | string | no |
RegisterResponse:
| Field | Type | Notes |
|---|---|---|
identity | Identity | normalized lease identity |
namespace | string | optional; must match the negotiated request namespace |
hostname | string | granted friendly hostname; may be empty for Local TLS or dedicated TCP/UDP registrations |
canonical_hostname | string | identity-bound Local TLS hostname; empty when no namespace is requested |
alias_epoch | string | optional alias ownership generation shared by replicas; omitted without a friendly alias or on older relays |
expires_at | string | lease expiry |
access_token | string | token for renew, unregister, signer access, and direct datagram backhaul |
reverse_endpoint | ReverseEndpoint | URL, opaque reverse-only capability, and expiry for /sdk/connect |
udp_addr, tcp_addr | string | omitted when transport is disabled |
udp_enabled, tcp_enabled | boolean | active transport flags |
The SDK validates the returned namespace and identity-bound hostname. Both
peers must negotiate local-tls-v1 before using <service>.<40-lowercase-hex-address>.<relay-root>. The service label supports
63 octets; unnamed services use reserved default, and an explicitly named default is rejected only in the new namespace. The canonical does not depend
on acquiring a friendly alias. Its exact-host certificate and TLS endpoint
belong to the tunnel; there is no Keyless or relay cache fallback.
An absent namespace grants only a friendly alias. When no service name or Local
TLS option is supplied for HTTP, Expose fills the service name with a random
ordinary label such as sunny-otter-k7m2q6rt3vx5z4ab. It uses the normal named
registration contract and retains the name across reconnects and listener
recreation. Before first readiness, a hostname conflict selects a fresh name for
all relays, up to four draws. Once any relay is ready, the name is fixed for the
rest of the run; later conflicts fail only the conflicting relay, including
while other relays are offline. Explicit names are never changed. Unnamed
Keyless HTTP replicas are rejected. Replicas must supply
the same explicit name and signing identity to share a service. Negotiating local-tls-v1 adds the independent canonical Local TLS endpoint. Old one-label canonical
URLs and legacy_canonical_hostname / LegacyURL have been removed, without
redirects. SDK v2.7.3 and v2.7.4 require the removed canonical field even when
their caller wants only an alias. They are rejected by protocol negotiation and
need a protocol-10 relay until upgraded. See Upgrading.
RelayStatus.PublicURL is the canonical URL with Local TLS, empty until its
certificate is usable; otherwise it is the granted alias. AliasURL names the
alias separately. An alias collision may leave a Local TLS exposure with only
its canonical URL. Alias-only registrations cannot fall back to a canonical.
Relay static caching requires an explicitly opted-in, currently granted alias. It can coexist with canonical Local TLS, which never serves relay snapshots.
ReverseEndpoint:
| Field | Type | Notes |
|---|---|---|
url | string | HTTPS /sdk/connect endpoint on the ingress relay or its selected gateway |
capability | string | opaque, reverse-only, and bound to this lease instance |
expires_at | string | never later than the owning lease expiry |
overlay | boolean | true when the selected endpoint uses the overlay |
gateway | RelayDescriptor | signed descriptor binding the overlay gateway’s HTTPS address to its relay identity; required when overlay is true |
The reverse capability is not accepted by renew, unregister, signer, or
datagram endpoints. The lease access_token is not accepted by the reverse
endpoint.
The relay preserves the overlay preference for the lease lifetime. By
default it issues the ingress relay’s direct endpoint. When overlay is true,
it prefers an available overlay gateway and falls back to the direct endpoint.
Both modes intentionally preserve the same SDK-facing contract: use the returned url and reverse-only capability to open the stream. Portal owns endpoint
selection, identity, lease policy, and authorization; IVNP owns the network path
between gateway and ingress. The SDK does not choose IVNP routers or receive
their topology, and that topology is not part of leases or discovery state.
For overlay endpoints, the SDK verifies the signed gateway descriptor and
checks that its address matches the returned URL before opening any connection.
Relay-selected gateways may only resolve to public IP addresses; local, private,
and special-purpose addresses are blocked after DNS resolution on every dial.
An explicitly configured direct relay retains local development support.
Browser/WASM clients reject relay-selected alternate gateways because the browser
does not expose resolved addresses for SDK verification. Keep overlay disabled
and use the explicitly configured direct relay in browser applications.
See IVNP-backed overlay networking for the conceptual model and the architecture for the delegated capability and gateway-to-ingress protocol flow.
Renew And Unregister
RenewRequest:
| Field | Type | Required |
|---|---|---|
access_token | string | yes |
ttl | number | no |
reported_ip | string | no |
metadata | LeaseMetadata | no |
repins_chain | boolean | no |
local_tls_not_after | string | no; installed canonical leaf expiry as RFC 3339; absent or zero withdraws material readiness |
Renewal uses the same 120-second default and 600-second maximum as registration. A rejected TTL leaves the existing lease unchanged.
For a Local TLS lease, certificate changes wake the existing authenticated
renewal path. The relay records local_tls_not_after and derives the public
lease’s canonical_ready from it and lease validity. This expires without
waiting for another renewal. ready remains the reverse transport count, so a
usable canonical needs both positive ready and true canonical_ready.
The reported bound is an availability hint from the authenticated service,
not proof of certificate validity or an authorization to change TLS policy.
repins_chain says the SDK re-pins the relay certificate chain by itself. A
renewal without it is answered with lease_not_found and the lease is not
extended when the relay now serves a certificate that the chain pinned at
registration does not verify (a renewal by another intermediate); the SDK then
registers again and pins the current chain. An SDK that only exposes raw TCP or
UDP is asked as well, although it never signs, so it reconnects once after such
a renewal. On a relay with more of these tenants than its pre-auth registration
budget admits per renewal cycle, some registrations are answered with 429 and
wait for their retry time.
RenewResponse:
| Field | Type |
|---|---|
expires_at | string |
access_token | string |
reverse_endpoint | ReverseEndpoint |
POST /sdk/reverse rotates only the reverse endpoint. It does not renew or
replace the lease. The request contains access_token and may include the
generic failed_url; the latter lets the ingress avoid the failed endpoint
when another gateway or the direct path is available.
UnregisterRequest:
| Field | Type | Required |
|---|---|---|
access_token | string | yes |
/sdk/unregister returns {} on success.
Tenant Certificate
POST /v1/tenant-certificate uses X-Portal-Access-Token: <lease access_token> and the normal JSON envelope.
The reverse capability and admin bearer token cannot replace the lease token.
Request: TenantCertificateRequest contains csr_pem, a signed PEM certificate
request with an ECDSA P-256 public key. The request body is limited to 16 KiB.
The CSR must contain exactly the active lease’s canonical DNS SAN. Wildcards,
friendly aliases, sibling services, IP/email/URI identities, and extra
extensions are rejected. A common name, if present, must match that same SAN.
No private key is uploaded.
Success: TenantCertificateResponse contains certificate_pem, the PEM chain
for that CSR. The SDK checks the matching local key, exact hostname, validity,
and trust before activating and persisting it. Tenant trust stays separate from
relay control-plane trust. Issuance does not make a pending canonical URL ready
until usable material is installed and reverse transport is available.
The relay must enable TENANT_CERTIFICATES. Public CA issuance also requires
an explicitly approved service identity and shared durable issuance state;
automatic registration mode alone does not approve issuance. Local development
CA issuance consumes no public quota and is exempt from service approval.
Ownership and lease validity are checked again before returning the chain.
Disabled issuance returns 503 tenant_issuance_disabled; lack of approval
returns 403 tenant_issuance_not_approved. A busy issuer or exhausted order
budget returns 429 rate_limited with Retry-After. Other issuance failures
return 503 feature_unavailable. Existing live-lease authorization failures
use the shared error codes. See issuance admission for durable accounting, limits, and operational constraints.
Static Cache
All /sdk/cache operations require X-Portal-Access-Token: <lease access_token> for an active, cache-opted-in lease.
The reverse capability cannot authorize them. Cache capability is optional;
clients retain the live origin tunnel if admission or upload fails.
StaticCacheLimits (the optional /sdk/domain cache object):
| Field | Type | Meaning |
|---|---|---|
max_exposure_bytes | number | Total file bytes allowed for one snapshot |
max_object_size | number | Maximum bytes for one file |
StaticCacheManifest:
{
"index": "index.html",
"files": [
{ "path": "index.html", "size": 5, "sha256": "<64-character SHA-256 hex digest>" }
]
} Paths must be safe, relative, unique, and sorted, and index must identify a
listed file. Only regular files are eligible. Manifests are limited to 1 MiB
and 2,048 files, in addition to the advertised byte limits.
POST: send the manifest as JSON.presentindicates whether the matching unexpired snapshot exists. A changed manifest invalidates the previous snapshot.PUT: sendmultipart/form-data, with the JSON manifest as the first part (manifest), followed by one binary part (object) per file, in manifest order. Sizes and hashes are validated before atomic publication.DELETE: invalidate this lease’s snapshot; returnspresent: false.
Successful operations return the standard envelope containing StaticCacheStatus: present (boolean) and expires_at (timestamp when a
snapshot is present). Authentication, expiry, capacity, and method failures
must be handled by HTTP status; not every cache error uses the JSON envelope.
See cache configuration for TTL and storage
limits and the TLS boundary.
Reverse Connect
GET /sdk/connect opens a native reverse tunnel stream or establishes the
browser reverse multiplexer.
Requirements:
| Requirement | Value |
|---|---|
| HTTP version | HTTP/1.1 |
| Native authentication | X-Portal-Reverse-Capability: <opaque capability> header |
| Native connection | keep-alive capable connection that supports hijack |
| Browser authentication | portal.reverse.v1 and the opaque capability offered as WebSocket subprotocols |
| Browser connection | WebSocket carrying a yamux session; each logical stream presents the current capability again |
For a native connection, the relay writes HTTP/1.1 101 Switching Protocols and hijacks the TCP connection. There is no JSON response body. For a browser
connection, it completes the WebSocket handshake and accepts reverse
connections as yamux streams. Failures before either upgrade use the standard
JSON error envelope.
The SDK keeps several ready reverse streams open. When an end user connects to the lease hostname, the relay claims one ready stream and bridges encrypted tenant bytes between the browser side and the SDK side.
Waiting for approval
A manual relay verifies the registration signature before accepting an approval request. The request never receives a token or endpoint. A full queue returns 503 approval_queue_full with retry guidance. Pre-auth budgets can independently return 429 rate_limited.
An authenticated retry from a different source IP moves the pending request to that source’s budget only if capacity is available. A rejected retry leaves the existing request and its expiry unchanged.
Denying or banning an identity in either mode removes its existing leases and releases alias and port reservations. Revoking approval does the same in manual mode; in auto mode, revoking approval alone keeps the lease routable.
DNS publication and withdrawal use one maintenance owner. Policy changes record the latest desired state for each hostname without waiting for DNS provider work. Failed work is retried by the maintenance retry timer, not by ordinary wakeups or repeated identical registrations. DNS readiness checks process only the requested hostname. A changed desired state supersedes older work. Hostname ownership is checked before submitting a withdrawal.
| Operation | Response | Publisher behavior |
|---|---|---|
| Register, awaiting manual approval | 503 lease_rejected with Retry-After (5–60 seconds) | Repeat the signed registration exchange after the delay |
| Register, denied or banned in either mode | 403 lease_denied | Terminal refusal before lease allocation |
| Connect or renew a removed lease | Missing or invalid lease | Obtain a fresh registration |
| Reverse connect on a legacy pending lease | 403 lease_rejected | Wait for approval on the existing lease |
Protocol 10 compatibility. The baseline for the following checks is commit 9b249c1. Both mixed-version tests run a single publisher process across approval and request the published HTTP service. The following behavior assumes a compatible SDK tunnel protocol.
| Publisher | Relay | Before and after approval |
|---|---|---|
| Baseline | Updated | The CLI shows connecting. It honors the registration retry delay and becomes ready after approval. The relay holds only a pending request. |
| Updated | Baseline | The CLI reports pending on the existing reverse-connect refusal and becomes ready on the original lease. The baseline relay allocates its usual pending lease. |
| Updated | Updated | The CLI reports pending before receiving a lease. It registers on its next attempt after approval. |
To repeat the mixed-version tests, build ./cmd/portal-tunnel and ./cmd/relay-server from the baseline checkout. Set PORTAL_V10_BASE_CLI and PORTAL_V10_BASE_RELAY to their absolute paths and run go test -v ./e2e -run '^TestManualProtocol10Compatibility$' -count=1 in the updated checkout.
Browser/WASM SDK Runtime
The same sdk.Expose and sdk.RunHTTP lifecycle can run in a Go WebAssembly
application. The application supplies the HTTP handler; the browser runtime is
not a general-purpose bridge to a local port or file.
id, err := identity.Generate("browser-preview")
if err != nil {
return err
}
exposure, err := sdk.Expose(ctx, id, []string{relayURL})
if err != nil {
return err
}
defer exposure.Close()
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, _ = io.WriteString(w, renderCurrentPreview())
})
return sdk.RunHTTP(ctx, exposure, handler, "") Compile the application with GOOS=js GOARCH=wasm. The SDK detects the JS
runtime and uses WebSocket plus yamux for reverse connections; callers do not
select that transport through an option.
A relay exposes the maintained connector and matching Go runtime glue at /api/install/bin/js-wasm and /api/install/bin/wasm-exec. Use the release_version returned by /sdk/domain as their version query parameter
so the relay rejects an incompatible cached artifact.
The maintained connector’s portalTunnel.start(options) resolves to an object
with publicURL (the identity-bound canonical URL, preserving the existing
contract) and aliasURL (the granted short URL, or an empty string when no alias
was granted). Consumers can explicitly choose aliasURL || publicURL for sharing.
Consumers of older connector artifacts should treat a missing aliasURL the
same as an empty value.
Browser runtime limits:
- HTTPS handler exposure only
- no raw TCP or UDP exposure
- no overlay transport
- no native MITM self-probe or
WithMITMProtection(true) - lifetime bound to the page and application context
The repository’s cmd/portal-tunnel/wasm command is the maintained JS interop reference. See Browser reverse transport for the
carrier protocol and Browser/WASM transport for its trust boundary.
HTTP Replicas
Use sdk.WithReplicas() to run independent HTTP tunnel clients with the same
identity key and name through one relay URL. Each client exposes its own local
service. The relay distributes new TLS connections across clients with ready
reverse streams; one HTTP connection can still carry many requests.
exposure, err := sdk.Expose(ctx, serviceIdentity, []string{relayURL}, sdk.WithReplicas())
if err != nil {
log.Fatal(err)
}
defer exposure.Close()
if err := sdk.Proxy(ctx, exposure, "127.0.0.1:3000"); err != nil {
log.Fatal(err)
} The CLI equivalent is:
portal expose http://127.0.0.1:3000 --replica --name web
--identity-path shared-service.json --relays https://relay.example --discovery=false Run this on each service host with the same identity material and name. In an
agent’s [[tunnels]] entry, set replica = true. Identity keys are provisioned
by the operator: every host holding that key has the same service authority,
including the ability to replace all leases through an exclusive registration.
Keep application settings and metadata consistent across replicas.
Each replica has its own token, expiry, reverse pool, and unregister operation.
A relay accepts at most 16 live replicas per identity; further replicas get a
retryable rate_limited error.
Access policy, reputation, and bandwidth limits belong to the shared identity.
The public directory shows one service with aggregate readiness; the admin API
retains separate rows identified by lease_id.
Without replica mode, registration still replaces all leases of that identity
and invalidates their tokens. A replica cannot join a live exclusive lease or a
retained relay cache entry for the same hostname; it gets a retryable replica_conflict error and joins once that lease is gone or the cache entry
expires. A crashed exclusive client holds its lease until expiry. Replica clients reject relays without
the advertised capability before sending any registration request. A replica
challenge must also confirm replica: true before the SDK signs it, so a relay
downgrade between domain lookup and challenge issuance cannot silently switch
the request to exclusive registration.
Dedicated TCP/UDP ports, relay cache, and overlay cannot be combined with replica
mode. Built-in application authentication supports SIWE, credentials and OIDC
when all replicas share the complete identity (including TokenSecret) and
provider settings. SIWE challenges and sessions can be verified by another replica.
The relay returns alias_epoch on registration. RelayStatus.AliasEpoch identifies
continuous alias ownership across replicas and lease replacements. SDK embedders
must pass it as appauth.PublicHost.Epoch for the alias, together with the current
public host list. It supersedes the Since fallback used with older relays. An
alias ownership change invalidates earlier sessions and login state; adding a
replica does not. The canonical host needs no epoch.
The CLI and agent reject email/SAML authentication and paid Nano routes with
replicas: email link redemption, SAML assertion consumption and Nano payment-proof
consumption are local to each gateway. SDK embedders must not compose independent
instances of those gates with WithReplicas(). Custom handlers and upstream
applications own their service-wide session and replay guarantees.
This is connection distribution within one relay, not cross-relay failover. Ready streams indicate tunnel availability, not application health. If no replica is ready, the incoming connection waits for a refilled stream on any live replica until the claim deadline, then fails. Connections already carrying traffic are not migrated or replayed after a client fails.
Go Application Auth
The tables above are the wire protocol. A Go program that embeds the SDK can also
put the sign-in gate of portal expose --auth in front of its own handler.
Package github.com/gosuda/portal-tunnel/v2/sdk/appauth is that gate. It is a
separate package so a program that does not use it, including a browser WASM
build, does not compile the OIDC and SAML dependencies.
id, err := identity.LoadOrCreate("my-app", identityPath, "")
if err != nil {
log.Fatal(err)
}
exposure, err := sdk.Expose(ctx, id, nil, sdk.WithDiscovery(3))
if err != nil {
log.Fatal(err)
}
defer exposure.Close()
cfg := appauth.Config{
Provider: appauth.ProviderOIDC,
EmailList: []string{"alice@example.com", "@example.org"},
OIDCConfig: appauth.OIDCConfig{
OIDCIssuerURL: "https://accounts.google.com",
OIDCClientID: clientID,
OIDCClientSecret: clientSecret,
},
}
cfg.PublicHosts = publicHosts(exposure) // see Hostnames below
gate, err := appauth.New(app, id, cfg)
if err != nil {
log.Fatal(err) // a mistake in cfg
}
if err := appauth.Check(ctx, cfg); err != nil {
log.Printf("sign-in provider: %v", err) // sessions still work; show this in a status
}
if err := sdk.RunHTTP(ctx, exposure, gate, ""); err != nil {
log.Fatal(err)
} The application reads the visitor from the request context, with or without identity headers:
principal, ok := appauth.PrincipalFromContext(r.Context()) | Name | Purpose |
|---|---|
New(next, id, cfg) | Builds the gate. It reads no network, so a provider outage cannot stop a rebuild. It returns an error for a mistake in cfg and for an id without its TokenSecret. |
Check(ctx, cfg) | Tests the provider: the OIDC discovery document and keys, the SAML metadata, or a login at the SMTP server. It sends no mail. Run it at startup and show the result. |
Validate(cfg) | Runs the config checks of New on a Config that is not being built yet. It needs no identity, and it does not ask for PublicHosts. |
Config | The provider, the allowlist, and the provider settings. oidc, saml, and email refuse an empty list. An empty list opens siwe to any wallet, and credential to any credential issued from id. Secrets are plain values: read them from where your program keeps secrets. |
Principal | Provider, Subject, and Email. Subject is the principal the allowlist checks: a wallet address, a credential subject, an email, or a sub: entry. Email is the address oidc, saml, or email vouches for, or empty. An OIDC email counts only with email_verified. |
IssueCredential, CredentialRedeemURL | Create a credential and its sign-in link for the credential provider. |
ProviderTakesEmailList(provider) | Reports whether a provider reads Config.EmailList. The others read Config.Allow. |
types.PathApplicationAuthPrefix | /_portal/auth/. The gate answers its endpoints under this prefix, so serve none of your own routes there. A later release may add endpoints. |
Keeping sessions across a rebuild
A gate built with the same id, including its TokenSecret, accepts the sessions
of an earlier gate when these settings are also the same:
| Provider | Settings |
|---|---|
oidc | issuer and client ID |
saml | metadata source, entity ID, and subject attribute |
email | SMTP server, username, and sender |
siwe, credential | none |
The allowlist is checked again on every request, so a principal you remove loses access at once, and a rebuild does not bring it back. A change to one of these settings ends the sessions that the old settings made.
These do not survive a rebuild:
- The list of SAML assertions already used. An assertion still valid could be presented once more.
- Email links that were mailed and not used: the visitor asks for a new one.
- Sessions on an alias, when
PublicHostsgives itsSince: a new exposure holds the alias anew, and another identity may have held it in between. Sessions onPublicURLare not affected.
SIWE logins in progress survive a rebuild with the same identity. With relay-issued
alias epochs, alias sessions and login state also survive a rebuild while ownership
is continuous. Changing an epoch ends them. Upgrading an alias from the older Since contract to epochs requires signing in again once.
Store an identity with identity.Marshal, not json.Marshal. json.Marshal leaves out the TokenSecret. New refuses an identity without one, but identity.Parse of a document without one creates a random secret, and every
session then ends at the next start without an error.
To replace the application, keep one gate and swap next behind it. Then a
redeploy changes nothing about sign-in, and an in-progress login also survives.
Hostnames
The gate builds a redirect from the host the visitor used, so it works on every host. An identity provider needs a registered URI for each one: the canonical host on each relay, and the alias if you share it. Portal has no setting for one public base URL, because an exposure on several relays has several canonical hosts.
Config.PublicHosts lists the hosts the application holds now. Set it whenever the
gate serves an exposure. The email provider needs it, and New refuses email without one. With it, the gate answers 421 to a request for any other host. A
session or sign-in on a host with an Epoch must carry that epoch. Without one,
the Since cutoff applies, so neither carries over from an earlier hold of an
alias. Credentials are not dated,
because they have to outlive a restart, so issue them for PublicURL. Without PublicHosts, the gate believes the Host of a request:
func publicHosts(exposure *sdk.Exposure) func() []appauth.PublicHost {
return func() []appauth.PublicHost {
var hosts []appauth.PublicHost
for _, relay := range exposure.Relays() {
hosts = append(hosts,
appauth.PublicHost{URL: relay.PublicURL},
appauth.PublicHost{URL: relay.AliasURL, Epoch: relay.AliasEpoch, Since: relay.AliasSince})
}
return hosts
}
} What the gate cannot protect
The gate protects the handler it wraps. portal expose refuses these
combinations, but New cannot see how a program exposes itself, so a program must
not combine them:
sdk.WithStaticRelayCache: the relay serves the cached site without calling your handler.sdk.WithTCPandsdk.WithUDP: connections and datagrams do not pass through anhttp.Handler.sdk.WithReplicaswith email or SAML: their one-time consumption records are instance-local.
A session is also tied to the origin of the application. A request with a session
cookie and an Origin of another origin gets 403 for a protocol upgrade and for
any method other than GET, HEAD, or OPTIONS. A request without Origin, a
request that presents a credential header, and a form post with Origin: null that a browser marks with Sec-Fetch-Site: same-origin are not affected.