FactoryVPN / DEVELOPERS
Your workflow.
Your client.
Connect your customer admin, service desk or application to FactoryVPN with a custom connector and an HTTP API.
A connector between your systems
The current product and API release is 0.9.0, with version 1.0 being finalized. The HTTP protocol keeps its /api/v1 prefix. Gateway Only is the current network model; Single LAN is planned from version 2.0, which is not yet in design.
Your application keeps its own interface and business workflow. A custom connector translates its users, machines and service requests into FactoryVPN API calls.
- Map your equipment records to provisioned FactoryVPN gateway UUIDs.
- Authenticate a FactoryVPN account with the appropriate permissions and group assignments.
- Request a session, poll its status and show progress in your application.
- Close the session when the service task ends and wait for network cleanup.
The admin API can manage accounts and devices, inspect sessions and retrieve administrative audit events. A service desk connector can store the FactoryVPN session ID against a ticket.
Connectors are custom development. Existing SSO, user mapping and business rules need an explicit integration design. OIDC SSO is available; the Cognito connector is experimental and requires validation on a real User Pool. Webhooks are not included; poll the API for updates.
Prepare the gateway
FactoryVPN supports factory enrollment and manual ZIP setup. Both use an individual gateway identity and the same OpenVPN provisioning system.
Factory enrollment
A trusted production station prepares the device identity with its own API key and an individual initial credential for the gateway. A global administrator reviews the device in the portal and approves its group. Approval can happen before the data SIM is active; missing operational data can arrive months later from the customer site.
When Internet connectivity is available, the gateway uses HTTPS before opening any VPN. It supplies its remaining data, retrieves the approved package, installs it and confirms activation. It then registers with its operational credentials. Activation of a package does not prove that the gateway has registered or that a VPN is open. The fixed VPN address is assigned at registration.
Manual setup and on-site support
An administrator can always create a gateway directly in the portal, including test machines with no factory enrollment. Prepare the package, download the ZIP, activate it, then copy gateway.env and gateway.ovpn to the gateway and start its agent. A global administrator can also take over an incomplete factory enrollment manually, preserving the device identity.
Global administrators can correct the activation mode, SMS number and MAC when no VPN or cleanup is pending. These operational changes revoke the previous credentials and require a replacement package. Inventory updates and changes to the customer LAN or Internet IP do not require another VPN package.
Gateway firmware contracts ship with the source distribution: documentation/gateway/INITIAL_SETUP.md covers initialization and manual setup; documentation/gateway/FACTORY_ENROLLMENT.md describes factory enrollment; documentation/gateway/RUNTIME_PROTOCOL.md specifies activation, heartbeats, leases and gateway firewall behavior. Use the supplied gateway agent or integrate those contracts into the firmware, and validate the station, modem and hardware in the deployment environment. Services on the VPN IP and local firewall settings remain the device’s responsibility.
VPN certificates and later renewals
The VPN uses an offline root CA and an online issuing Sub-CA. HTTPS trust for API access is separate from that VPN hierarchy. Client VPN certificates last 3650 days by default and the OpenVPN server certificate 1825 days; their validity does not grant permanent network access. A live, authorized session is still required.
The supplied gateway agent can renew its OpenVPN key and certificate over HTTPS without opening a technician VPN. The replacement private key is generated on the gateway; its API and SMS credentials stay unchanged. For firmware integrations, documentation/gateway/CERTIFICATE_RENEWAL.md specifies this subsequent renewal protocol. It does not perform initial enrollment or recover revoked credentials. Use the actual certificate expiry and maintain CA revocation lists as described in the installation guide.
Authentication & roles
Use the API origin supplied for your FactoryVPN deployment, for example https://vpn-api.example.com. The public FactoryVPN website is a documentation site, not an API server.
POST /api/v1/auth/login accepts JSON with username and password. For privileged local accounts and technicians who enable email verification, the response contains challenge_required and a challenge_token. Submit that token and the six-digit email code to POST /api/v1/auth/login/verify. Only then use the returned access_token as Authorization: Bearer <token>.
During a mail outage, a server operator can issue a one-time console code for a local account. Supply it as emergency_code alongside username and password to the login endpoint. It replaces the ordinary email-code step for that login, preserves normal access and VPN lifetimes, and does not apply to SSO accounts. In the portal, select the emergency-code login option. SSO administrators must provide signed MFA claims accepted by the deployment policy; a successful provider login alone does not attest MFA.
| Caller | Access |
|---|---|
| Technician | Read inventory in assigned groups and manage their own sessions there. Opening a VPN requires connect; changing devices requires gateways.manage. |
| Delegated administrator | Use users.manage, groups.manage, gateways.manage, sessions.manage or audit.read within assigned groups. Accounts spanning other groups require a global administrator. |
| Global administrator | Manage the entire instance. Gateways must be assigned to a group before anyone can connect. |
Local API bearer tokens expire after 30 minutes by default; this is separate from the portal login and VPN session durations. There is no refresh-token endpoint. Sign in again after expiry. Changes to passwords, account status, global role, permissions or memberships invalidate previously issued JWTs. Password changes, disabling an account and logout also terminate its VPN sessions; removing access terminates affected sessions. GET /api/v1/auth/me returns effective permissions and group IDs. PATCH /api/v1/auth/me updates the display name; changing email uses the verified portal procedure; POST /api/v1/auth/password changes the password after verification; POST /api/v1/auth/logout signs out all account sessions.
The browser portal uses a cookie session lasting 12 hours by default (PORTAL_SESSION_MINUTES=720). POST /api/v1/web/logout closes VPNs opened by that browser session; POST /api/v1/web/logout-all signs out all account sessions. SSO has its own lifetime, capped by provider token expiry and verification requirements. See durations and outage handling.
Keep administrator credentials in your connector’s backend. A browser client needs an explicitly allowed CORS origin. Gateway and worker credentials belong to the machine components and are not used by customer clients.
Request your first session
These shell examples use curl, jq, Python 3 and Bash. Start with an account and a gateway provisioned by your administrator, assigned to the same group, and the connect permission. The gateway’s individual package must be installed through approved factory enrollment or manual setup, and its HTTPS registration completed. Prepare, download and activate your personal OpenVPN profile in the portal before requesting a session. Replace the example API origin with your deployment.
1. Sign in
export FACTORYVPN_API='https://vpn-api.example.com'
read -r -p 'Username: ' FACTORYVPN_USER
read -r -s -p 'Password: ' FACTORYVPN_PASSWORD
printf '\n'
FACTORYVPN_LOGIN=$(
printf '%s' "$FACTORYVPN_PASSWORD" |
jq -Rs --arg username "$FACTORYVPN_USER" \
'{username: $username, password: .}' |
curl --fail-with-body --silent --show-error \
"$FACTORYVPN_API/api/v1/auth/login" \
-H 'Content-Type: application/json' --data-binary @-
)
unset FACTORYVPN_PASSWORD
if printf '%s' "$FACTORYVPN_LOGIN" | jq -e '.challenge_required == true' >/dev/null; then
read -r -s -p 'Email code: ' FACTORYVPN_CODE
printf '\n'
FACTORYVPN_LOGIN=$(
printf '%s\n' "$FACTORYVPN_LOGIN" "\"$FACTORYVPN_CODE\"" |
jq -s '{challenge_token: .[0].challenge_token, code: .[1]}' |
curl --fail-with-body --silent --show-error \
"$FACTORYVPN_API/api/v1/auth/login/verify" \
-H 'Content-Type: application/json' --data-binary @-
)
unset FACTORYVPN_CODE
fi
FACTORYVPN_TOKEN=$(printf '%s' "$FACTORYVPN_LOGIN" | jq -er '.access_token')
unset FACTORYVPN_LOGIN
2. Select a gateway and request access
curl --fail-with-body --silent --show-error \
"$FACTORYVPN_API/api/v1/gateways/" \
-H "Authorization: Bearer $FACTORYVPN_TOKEN"
read -r -p 'Gateway UUID: ' FACTORYVPN_GATEWAY
# Generate once for this request; keep the same key when retrying it.
FACTORYVPN_REQUEST=$(python3 -c 'import uuid; print(uuid.uuid4())')
jq -n --arg id "$FACTORYVPN_GATEWAY" '{gateway_id: $id}' |
curl --fail-with-body --silent --show-error \
"$FACTORYVPN_API/api/v1/sessions/" \
-H "Authorization: Bearer $FACTORYVPN_TOKEN" \
-H "Idempotency-Key: $FACTORYVPN_REQUEST" \
-H 'Content-Type: application/json' --data-binary @-
Provide exactly one of gateway_id or phone_number. Gateway UUIDs work with both activation modes. A phone number can only select a gateway that has one configured.
Keep the request UUID and the exact request body until the outcome is known. After a timeout, repeat only the jq/curl request with the same key and body; do not generate another UUID. Replays return the same session without sending another SMS. Generate a new key for a new assistance session.
{
"session_id": "22222222-2222-4222-8222-222222222222",
"status": "REQUESTED",
"message": "Waiting for gateway Wi-Fi check"
}
This is an illustrative Wi-Fi response. HTTP 200 means the request was handled. Always inspect status: an SMS provider rejection can return FAILED in a successful HTTP response.
3. Check readiness and connect
read -r -p 'Session UUID from the response: ' FACTORYVPN_SESSION
curl --fail-with-body --silent --show-error \
"$FACTORYVPN_API/api/v1/sessions/$FACTORYVPN_SESSION" \
-H "Authorization: Bearer $FACTORYVPN_TOKEN"
# Wait for gateway_ready_at, then start your provisioned
# OpenVPN client. Poll until status is ACTIVE before use.
Poll every few seconds with a bounded timeout; stop on terminal states. Sessions last up to 3 hours from the request by default (VPN_SESSION_MINUTES=180), including connection setup, and may end earlier with the opening browser or SSO session. Use the expires_at deadline returned by the session detail; activity and API retries do not extend it. A live session reserves both the technician and gateway, including while cleanup is pending.
4. Close when the assistance task is finished
curl --fail-with-body --silent --show-error --request DELETE \
"$FACTORYVPN_API/api/v1/sessions/$FACTORYVPN_SESSION" \
-H "Authorization: Bearer $FACTORYVPN_TOKEN"
Run this only after finishing the intervention, then disconnect the technician VPN client. Repeat the status request until cleaned_at is set before opening another session.
Understand the session lifecycle
| State | What your client should do |
|---|---|
| REQUESTED | Wait for gateway_ready_at, then connect the technician VPN. Continue polling. This state can also indicate reconnection is needed. |
| ACTIVE | The worker observed both VPN peers and prepared the blocked network; the API recorded its readiness report. The worker enables the server firewall lease only after that API acknowledgment. Check recent diagnostics and actual service reachability; the stored state alone does not prove current connectivity. |
| CLOSED | The session was explicitly closed. Disconnect the technician VPN. |
| EXPIRED | The session reached its deadline. Disconnect and request a new session only after cleanup. |
| FAILED | Stop connecting. Display error_reason from the session detail where available. |
Readiness and cleanup are separate milestones
sms_sent_at records provider acceptance, not delivery. activation_received_at records verified SMS receipt or the Wi-Fi gateway’s acknowledgment. gateway_ready_at means the gateway has prepared its network; ACTIVE also requires the technician connection.
Deleting a session confirms its state change, not immediate network teardown. Poll the session detail until cleaned_at is set before treating resources as reusable. Closing an already terminal session preserves its existing terminal state.
POST /api/v1/sessions/{session_id}/wake resends the signed activation SMS for a live SMS session, for example after a gateway restart. It does not extend the session deadline. Wi-Fi sessions do not use this endpoint.
Session timestamps and administrative audit events describe the control workflow. They are not a recording of machine traffic or every action performed by a technician.
Gateway Only: services on the VPN IP
FactoryVPN routes the gateway’s fixed VPN IPv4 address. There are no VPN filters on IPv4 ports or protocols between the assigned peers: TCP on any port, UDP and ICMP ping are allowed. Traffic is bidirectional only for that pair while the session authorization and network lease are valid. Customer LANs and other gateways remain inaccessible directly from the PC. Internet, DNS and IPv6 settings remain unchanged; reserve 10.100.0.0/16 for the VPN.
Read the fixed VPN address from the gateway card, the gateway API’s vpn_ip field or the session detail’s gateway_vpn_ip field. This address is separate from the gateway’s mobile or Wi-Fi connection. For example:
ssh gateway_user@10.100.0.2
Open http://10.100.0.2 or https://10.100.0.2 for its web service, or a custom port such as http://10.100.0.2:8080, using the actual assigned address and service port. Services must listen on the VPN IP or all interfaces; local firewalls on the gateway or PC may limit access. Services, Linux accounts and trusted web TLS certificates must be provisioned on the gateway. FactoryVPN does not create SSH accounts or provide an integrated shell. From SSH, use the gateway’s current routes to reach local devices. Changing the LAN requires no new VPN package.
The cable analogy means IP access to the gateway, not an Ethernet bridge or an extension of the customer LAN. Broadcast discovery does not cross this VPN.
The network lease controls traffic in both directions, including output from an existing SSH connection. Closing VPN access does not guarantee that a command already running on the gateway has terminated.
Session durations and temporary outages
These are deployment defaults, not deadlines a connector should hard-code. The source distribution includes an Italian-commented .env.example; bootstrap carries its settings and comments into the generated private .env. The operator can configure the values before deployment. New login and VPN lifetimes apply to new sessions; use each session’s actual expiry.
| Setting | Default | Purpose |
|---|---|---|
VPN_SESSION_MINUTES | 180 minutes | Total assistance time from the request, including setup. No automatic extension. |
PORTAL_SESSION_MINUTES | 720 minutes | Browser login lifetime. Signing out closes its associated VPN sessions. |
SSO_SESSION_MINUTES | 720 minutes | SSO lifetime, also bounded by provider tokens and verification. |
VPN_LEASE_SECONDS | 300 seconds | Maximum firewall authorization from the last successful renewal, configurable from 30 to 900 seconds. |
CONTROL_API_TIMEOUT_SECONDS | 10 seconds | HTTP timeout per phase for gateway heartbeats and worker requests; elapsed time consumes the lease. |
OPENVPN_RESTART_SECONDS | 300 seconds | Client reconnect attempt after no tunnel packets arrive. Separate from API authorization. |
SSO_MAX_STALENESS_SECONDS | 120 seconds | Maximum age of a successful provider check when revocation checking is enabled; this can shorten the network lease. |
Keep the authorization already granted
Gateway and worker normally check every 5 seconds, plus cycle time. A temporary transport error, timeout, HTTP 408/429 or 5xx preserves an existing lease without renewing it. The five-minute window starts at the last successful renewal, not at the first error. Repeated failures never reset the countdown, and opening a new VPN still requires API authorization.
If authorization recovers before expiry, traffic can continue without a deliberate disconnect. At expiry, the firewall blocks traffic, including established SSH connections. A later successful authorization may restore traffic for a still-valid session, but the SSH client or application may already have timed out.
Closure and connectivity remain separate
Explicit rejection, logout and revocation block access when received through the normal control checks. If API connectivity prevents delivery, blocking can wait until the remaining lease expires. VPN, browser and SSO deadlines always bound the lease; provider checks can impose a shorter window.
A physical network outage still stops packets. OpenVPN’s default keepalive sends a ping every 10 seconds when idle and asks clients to reconnect after 300 seconds without packets; the server uses twice that timeout. This does not extend the network lease or guarantee that SSH or remote processes survive. The 30-second freshness threshold in diagnostics describes the age of observations, not the VPN lifetime.
Changing server environment settings requires recreating the affected services. Gateway polling and HTTP/startup timeout values are copied into new gateway.env bundles; changing the server’s .env does not update a file already installed on a gateway. Plan service restarts outside active interventions.
Handle errors & retries
Application errors return a JSON detail field; validation errors return a list in that field. A reverse proxy may return a different body, so check the HTTP status before decoding JSON.
| Status | Meaning |
|---|---|
400 | An account operation was rejected, such as deleting the current account or supplying an incorrect current password. |
401 | Invalid credentials, expired or revoked token, or inactive account. Re-authenticate when appropriate. |
403 | Missing or malformed authorization, insufficient permission, or a rejected portal origin or CSRF check. |
404 | Resource not found or outside the authorized group or session scope. |
409 | Resource conflict, busy technician/gateway, pending cleanup or an incompatible operation. |
412 | The resource changed since it was read. Reload it and use its current revision before saving. |
422 | Invalid fields, malformed UUID or an invalid gateway selector. |
428 | A required precondition is missing, such as an If-Match revision or recent identity confirmation. Complete the required step before retrying. |
429 | A rate limit or resend cooldown was reached. Respect Retry-After when supplied; do not immediately repeat the request. |
503 | A required service or credential configuration is unavailable. |
Back off on temporary network or service failures. Session creation accepts an optional UUID Idempotency-Key. Retry an uncertain request using the same account, key and request body: the API returns the original session with replayed: true, including terminal outcomes, without sending another SMS. Reusing the key with different input returns 409. If no key was sent, reconcile the outcome through GET /api/v1/sessions/ before creating another session. Keep the returned session ID.
Use OpenAPI to build your client
The downloadable OpenAPI 3.1 specification describes customer-facing endpoints, request and response models, bearer and portal-cookie authentication, and documented errors. It is generated from the API code and can be imported into compatible API tools or client generators.
What is included
Authentication, technician sessions, gateway discovery, device operations and administration. Internal worker routes and gateway machine authentication are outside the customer client specification.
Use a generator that supports OpenAPI 3.1 and nullable fields. Configure its base URL to your deployment’s API origin, then supply the bearer token from the login response for endpoints that accept HTTPBearer. Authenticated portal endpoints and backup operations use PortalCookie instead; follow the operation’s cookie, CSRF and recent-authentication requirements. Initial portal login, email verification/resend and SSO start use the configured Origin and X-FactoryVPN-Portal: 1 header. Preserve the login challenge cookie when verifying or resending an email code. SSO reauthentication additionally requires an existing portal session and CSRF token. Do not combine a portal cookie and a bearer token in one request. The reference is read-only; it does not send requests to a production API.
The deployment’s complete schema is also available at /openapi.json and Swagger UI at /docs when the API is reached directly. The standard reverse proxy does not publish these routes.