Skip to content
From the machine: space-env web-portal

From the machine: space-env web-portal

An agent that builds a web service in its machine can put that machine behind a web portal itself, instead of asking you to open Web portals in the console, pick the machine and the port, and paste the address back:

space-env web-portal attach --port 3000

It prints the portal’s address, https://<name>.agent-app.eu (on region lab: https://<name>.polder-vm.eu). The commands:

space-env web-portal
space-env web-portal attach [NAME] [--port N] [--approve vm|open] [--anonymous|--no-anonymous]
space-env web-portal edit [--name NAME] [--port N] [--approve vm|open] [--anonymous|--no-anonymous]
space-env web-portal edit [--brand-color COLOR] [--brand-name TEXT] [--brand-description TEXT]
space-env web-portal edit [--brand-css FILE] [--logo FILE | --remove-logo] [--json]
space-env web-portal edit [--terms-url URL] [--privacy-url URL]
space-env web-portal edit [--languages CODES] [--default-language CODE]
space-env web-portal edit [--agentspaces on|off] [--password on|off] [--magic-link on|off]
space-env web-portal edit [--google off|agentspaces|own] [--google-client-id ID]
space-env web-portal edit [--microsoft off|agentspaces|own] [--microsoft-client-id ID] [--microsoft-tenant TENANT]
space-env web-portal edit [--two-factor off|optional|required] [--signup-domains DOMAINS] [--signups invite|machine|open]
  • attach puts the machine behind the portal of its project named NAME (default: the machine’s name). A portal by that name that is in front of no machine gets this one; with none, a new portal is made (guest port 8080, the machine approves sign-ups, no anonymous access, unless the flags say otherwise). The machine approves through its sign-up endpoint: an app without one refuses every sign-up, so use --approve open until it has one. A portal in front of another machine is refused, and so is a second portal for this machine: change the one it has with edit. Only a regular machine goes behind a portal: an AI agent’s machine and the service machines (git, an agent’s browser) are refused. An agent runs its app on its tools machine and runs attach there.
  • edit changes the settings and branding of the portal this machine is behind, and of no other. An empty --brand-… value clears that field. --terms-url and --privacy-url set the terms of service and privacy policy linked under the sign-in card (https:// or http:// addresses; '' removes the link). The CSS and the logo travel in one message of at most 100 KB: when both don’t fit, send them in two edits. --languages en,nl sets the sign-in pages’ languages (codes of en, nl, de, fr, es, da, pt, sv) and --default-language nl the one a browser asking for none of them gets; it must be one of the languages, and '' makes it automatic again. The sign-in methods take the options of space portals sign-in: --agentspaces (for the organization’s members only), --password and --magic-link on or off; --google and --microsoft off, agentspaces (the AgentSpaces client) or own, with --…-client-id and --microsoft-tenant; --two-factor; --signup-domains (comma separated, '' for any) and --signups. A client secret never travels from a machine, whose messages are kept: set it once with space portals sign-in or in the console, then --google own works here too. Leave at least one way in.
  • show (space-env web-portal) prints the portal’s name, address, port, sign-up approval, anonymous access, languages, default language, branding, terms and privacy links and sign-in methods, and its primary host and custom domains, each with its state and the DNS records it needs. Adding and removing domains is done in the console or with space portals domains.
space-env web-portal
space-env web-portal edit --approve open --brand-name "Shop"
space-env web-portal edit --languages en,nl --default-language nl
space-env web-portal edit --terms-url https://shop.example/terms --privacy-url https://shop.example/privacy
space-env web-portal edit --agentspaces on --password off --google off --microsoft off --magic-link off

A static site in front

Pages that are files can be answered by the portal itself, without resuming the machine and without signing in: publish them to a bucket and serve it (space-env bucket put, space-env bucket serve). Requests the bucket can’t answer still reach your service. See A static site from a bucket.

Webhooks

A service that calls your app (GitLab, a payment provider) needs an address that resumes the machine: make it a webhook, and give it the address printed (only this once):

space-env web-portal webhook add NAME [--path PATH] [--json]
space-env web-portal webhook list [--json]
space-env web-portal webhook revoke ID [--json]

See Webhooks.

Managing the portal’s users

Your service in the machine can manage the accounts of the portal it is behind: invite people, hand out sign-up links, and lock someone out. These commands work on that portal only; a machine behind no portal gets “this machine is behind no web portal”.

space-env web-portal invite EMAIL [--data JSON] [--days N] [--no-mail] [--json]
space-env web-portal signup-link [--data JSON] [--days N] [--json]
space-env web-portal invites [--json]
space-env web-portal revoke ID [--json]
space-env web-portal users [--json]
space-env web-portal disable SUB [--json]
space-env web-portal enable SUB [--json]
space-env web-portal sign-out SUB [--json]
space-env web-portal reset-2fa SUB [--json]
space-env web-portal invite ann@example.com --data '{"team":"sales"}'
space-env web-portal signup-link --days 1
space-env web-portal users
  • invite mails EMAIL a link to sign up, in the portal’s branding, valid --days (1 to 30, default 7) and once. With --no-mail nothing is sent: the link is printed, for you to hand over yourself. An address that already has an account is refused.
  • signup-link prints a link without an address: whoever opens it first signs up, once, with an address of their own.
  • --data, a JSON object of at most 4 KB, comes back to your service with the sign-up (sign-up approval: "invite" or "signup_link", with its id and data), so you know what the person signed up for. Invites and sign-up links always tell your service, also on a portal where anyone may sign up.
  • invites lists the open invites and links (id, kind, expiry, data); revoke makes one stop working.
  • users lists the accounts: each user’s sub (the id in the identity header), whether their address is confirmed, two-factor, disabled, and their last sign-in. No email addresses: your service learns those at sign-up.
  • disable keeps a user out and ends every session of theirs; enable lets them back in. sign-out ends their sessions and API tokens but leaves the account as it is.
  • reset-2fa turns off a user’s two-factor sign-in when they lost their authenticator. They then sign in with their password alone, and set it up again. Do this only when you are sure it is them asking.

From your own code

The commands are clients of the machine’s guest API socket, which any program in the machine can call (the socket reference lists every route):

curl -s --unix-socket /run/space-env/api.sock http://space-env/v1/web-portal/invites \
  -H 'content-type: application/json' \
  -d '{"email": "ann@example.com", "data": {"team": "sales"}, "days": 7}'
Method and pathBodyAnswer
POST /v1/web-portal/invites{"email", "data"?, "days"?, "mail"?}{"id", "expires_at", "link"}
GET /v1/web-portal/invites{"invites": [{"id", "kind", "expires_at", "data"}]}
POST /v1/web-portal/signup-links{"data"?, "days"?}{"id", "expires_at", "link"}
DELETE /v1/web-portal/invites/{id}{}
GET /v1/web-portal/users{"users": [{"sub", "inserted_at", "last_sign_in_at", "disabled", "two_factor", "verified"}]}
POST /v1/web-portal/users/{sub}/disable, /enable, /sign-out, /reset-2fa{}

An error is {"error": {"code", "message", "retry"}} with an HTTP status: 404 not_found (no portal, no such user or invite), 409 already_member, 400 invalid or bad_request, 429 rate_limited and 503 unavailable (try again later). The machine needs no key for any of this: the platform knows which machine calls, and so which portal it is behind.

Who acts

The commands act as the user the machine works for (on_behalf_of in space-env whoami), with that user’s rights: only an owner or admin of the organization can put a machine on the internet or change its portal; a member’s machine gets a refusal. The organization’s audit log records the change as that user’s, with the machine it came from.

No detach

There is no space-env web-portal detach: an agent can put its machine on the internet, but taking it off, deleting the portal or moving it to another machine stays a person’s call, in the console’s Web portals page.

Last updated on