Deploying NeuralUI in production#
NeuralUI has three network paths. All three must be encrypted and authenticated in production:
Path |
Carries |
How |
|---|---|---|
Browser → NeuralUI (HTTPS) |
logins, queries, results |
TLS with a real certificate, on NeuralUI’s own host name |
NeuralUI → Cortex (telepath) |
the service account (a Cortex admin) and every query |
|
Cortex → NeuralUI (telepath, for |
the Storm package |
|
HTTPS on the browser side does not protect the two backend connections. A reverse proxy in front of NeuralUI doesn’t either.
NeuralUI refuses to start with a plain tcp:// address for the Cortex (cortex) or for its own
telepath listener (dmon:listen) unless the address is on the loopback interface. When the Cortex
connection comes up, NeuralUI checks it really is TLS (an aha:// address resolves to some other
transport) and drops it if not. neuralui:insecure: true turns both checks off. It is only for
isolated development; scripts/devstack.py doesn’t need it because it uses loopback.
1. Certificates#
Make a CA and the certificates with Synapse’s easycert (or your own PKI: any CA works, as long as
each cell has the CA certificate and its own certificate and key). The host names here are examples:
use the names the services reach each other by on your private network.
E="python -m synapse.tools.utils.easycert --certdir ./pki"
$E --ca nuica # the CA (keep pki/cas/nuica.key offline)
$E --server --signas nuica cortex.internal # the Cortex's telepath listener
$E --server --signas nuica neuralui.internal # NeuralUI's telepath listener
$E --signas nuica neuralui # NeuralUI's client certificate (= its Cortex user)
$E --signas nuica cortex # the Cortex's client certificate (= its NeuralUI user)
A client certificate’s common name is the user it logs in as. The cell on the other end maps
neuralui to its user neuralui (or, with AHA, neuralui@<aha:network> to neuralui). No password
crosses the network.
Put the files in each cell’s certs/ directory:
cortex/certs/cas/nuica.crt
cortex/certs/hosts/cortex.internal.crt cortex/certs/hosts/cortex.internal.key
cortex/certs/users/cortex.crt cortex/certs/users/cortex.key (to reach NeuralUI)
neuralui/certs/cas/nuica.crt
neuralui/certs/hosts/neuralui.internal.crt neuralui/certs/hosts/neuralui.internal.key
neuralui/certs/users/neuralui.crt neuralui/certs/users/neuralui.key (to reach the Cortex)
The keys stay with the cell that uses them: the Cortex never needs NeuralUI’s keys, and the other way round.
Renewal: issue new certificates with the same names before the old ones expire, replace the files,
and restart the cell (telepath loads certificates when a connection is made). To revoke a client
certificate, use easycert --revokeas nuica <name> and give the CRL to the listening cell (see the
Synapse documentation on certificate revocation), or delete or lock the user it maps to.
2. The Cortex#
Listen for telepath with TLS, requiring client certificates from your CA:
# cortex/cell.yaml
dmon:listen: ssl://0.0.0.0:27492/?hostname=cortex.internal&ca=nuica
Create NeuralUI’s service account. It has to be an admin, but not root: the telepath APIs for
checking passwords and API keys and reading user definitions are admin-only, so there is no smaller
set of permissions that works. It needs no password, because it logs in with its certificate:
storm> $u = $lib.auth.users.add(neuralui) $u.setAdmin($lib.true)
Every query still runs as the person logged in to NeuralUI (impersonation), with their own permissions. Admin rights are used only for logging people in and reading the installed packages.
3. NeuralUI#
# neuralui/cell.yaml
cortex: ssl://cortex.internal:27492/?hostname=cortex.internal&certname=neuralui
dmon:listen: ssl://0.0.0.0:27495/?hostname=neuralui.internal&ca=nuica
https:port: 4443
neuralui:origin: https://neuralui.example.com # the address people use (see section 5)
neuralui:hsts: 31536000 # once it is only ever served over HTTPS
hostname=is the name the peer’s certificate must have (it is checked against the certificate), so connecting by IP address still verifies the right server.ca=on a listener requires client certificates signed by that CA.For the browser side, put a real certificate for the public name in the service directory as
sslcert.pemandsslkey.pem(full chain). Without them Synapse makes a self-signed one, which is fine only for testing.
4. Register the Storm service#
The Cortex only reads the Storm package from NeuralUI, which needs no permissions. Give it a plain
NeuralUI user, not root and not an admin. With NeuralUI running, create the user on NeuralUI’s
telepath listener (as its root, from the NeuralUI host):
python -m synapse.tools.service.moduser --svcurl cell:///path/to/neuralui/svcdir --add cortex
Then register the service. The Cortex presents its cortex certificate and NeuralUI maps it to that
user:
storm> service.add neuralui ssl://neuralui.internal:27495/?hostname=neuralui.internal&certname=cortex
Alternatively, without a Cortex client certificate, give the cortex user a password
(moduser --passwd) and use it over TLS:
ssl://cortex:<password>@neuralui.internal:27495/?hostname=neuralui.internal. The password is then
encrypted in transit, but stored in the Cortex’s service definition. Because the user has no
permissions, that stored password gives nothing beyond the package.
5. The browser side#
Give NeuralUI its own host name (
neuralui.example.com). Browsers isolate cookies by host name, not by port, so another service on the same host name, even on another port, could use the session cookie.Set
neuralui:originto the address people use (scheme, host and port). NeuralUI refuses state-changing requests and WebSockets from any other origin (another port of the same host included), and sends no CORS headers. Without the setting it uses the origin each request was made to, which is right when browsers connect to NeuralUI directly.Behind a reverse proxy, set
neuralui:originto the public address. Proxy WebSockets (/api/neuralui/v1/storm) too. The proxy must connect to NeuralUI over HTTPS: a proxy terminating TLS and forwarding plain HTTP leaves that hop unencrypted.Give NeuralUI the clients’ addresses behind a proxy. The login throttle counts failed logins per client address as well as per user name. Behind a proxy every request comes from the proxy’s address, so a burst of bad logins from anyone would make everyone wait. List the proxy in
neuralui:proxy:trusted(addresses or networks:[10.0.0.5],[10.0.0.0/24]): for a request from it, NeuralUI takes the client’s address fromX-Forwarded-For(the last entry not added by a trusted proxy, so a client can not choose its own). The proxy must append toX-Forwarded-For(nginx:proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;). Leave Synapse’shttps:parse:proxy:remoteipoff: it trusts the header from anyone.A Cortex password policy can lock accounts. If the Cortex sets
auth:passwd:policywithattempts, failed NeuralUI logins count toward it like any others, and the Cortex locks the account at the limit until an admin unlocks it, so someone who knows a user name can lock that user out. NeuralUI’s own throttle only ever delays logins. Weigh that before settingattempts.Cap request bodies at the proxy too (nginx
client_max_body_size), atneuralui:upload:maxsize. NeuralUI reads at most 17 MiB of any other request.Only publish the HTTPS port. The telepath ports (27492, 27495) belong on a private network that only the Cortex and NeuralUI share. Nothing else, browsers included, needs to reach them.
6. With containers#
# docker-compose.yml (sketch)
services:
cortex:
image: vertexproject/synapse-cortex:v2.x.x
volumes: [cortex:/vertex/storage] # cell.yaml and certs/ as in section 2
networks: [backend] # no published ports
neuralui:
image: ghcr.io/gormaniac/neuralui:<version>
volumes: [neuralui:/vertex/storage] # cell.yaml and certs/ as in sections 3 and 5
networks: [backend, frontend]
ports: ["443:4443"] # only HTTPS is published
networks:
backend: {internal: true} # no route out
frontend: {}
volumes: {cortex: {}, neuralui: {}}
The service names must match the certificate host names (cortex.internal, neuralui.internal):
use them as the service names or network aliases. The NeuralUI image sets no telepath listener by
default. Set dmon:listen as in section 3 when the Cortex should register the Storm service.
7. AHA#
With an AHA network, cortex: aha://cortex... works. AHA provisions TLS certificates for the services
it manages, and NeuralUI checks the connection it actually gets is TLS.
Provision NeuralUI with its own user name, so it doesn’t log in to the Cortex as root:
python -m synapse.tools.aha.provision.service --user neuralui neuralui
Without --user, an AHA service connects to others as root@<network>, which every cell on the
network maps to its own root. With it, NeuralUI’s certificate is neuralui@<network>, which the
Cortex maps to its neuralui user: create it as an admin as in section 2.
The same goes the other way: an aha:// URL in service.add makes the Cortex log in to NeuralUI as
its own AHA user, usually root. To avoid that, register the service with an ssl:// URL and the
cortex client certificate as in section 4 (signed by the AHA network’s CA, or by a CA NeuralUI’s
listener accepts).
Checklist#
[ ]
cortexanddmon:listenaressl://(NeuralUI refuses to start otherwise), withhostname=andca=[ ] client certificates (
certname=) instead of passwords on telepath URLs[ ] NeuralUI’s Cortex user is an admin but not
root(--user neuraluiwith AHA); the Cortex’s NeuralUI user (cortex) is a plain user[ ]
neuralui:insecurenot set[ ] a real HTTPS certificate (
sslcert.pem/sslkey.pem) for NeuralUI’s own host name[ ]
neuralui:originset to the public address;neuralui:hstsonce HTTPS is permanent[ ] telepath ports only on the private network; only HTTPS published
[ ] certificate renewal scheduled; keys only on the cell that uses them