OpsCrew's agent on the server: live logs for the dashboard
OpsCrew’s hosted dashboard shows your app’s logs, its containers’ state and each deploy’s progress. Without help, each of those reads runs a job in your repository’s GitHub Actions, which connects to the server: correct, but it takes most of a minute. OpsCrew’s agent is a small process next to your app that answers the dashboard in about a second, and sends new log lines as they come.
It runs only when you use the dashboard. A deployment that doesn’t use it never runs an agent, and
npx opscrew logs and npx opscrew status in your terminal (logs and status)
don’t need one.
Where it runs
Section titled “Where it runs”On your app’s server, when it is:
- a server OpsCrew created;
- a server you already have, served publicly or through a Cloudflare Tunnel, including one at home;
- a server shared with another app, where each app has its own agent and token.
Not yet:
- a Portainer you already run, this computer, a hosting account, or a site without a server of its own (Cloudflare’s hosting, GitHub Pages);
- previews;
- a server of its own for a service: the agent offers only the parts of the app on the app’s server.
There, the dashboard keeps reading through GitHub Actions. When the environment has the
dashboard’s token anyway, npx opscrew provision installs nothing and says why.
What it reads, and what it can’t do
Section titled “What it reads, and what it can’t do”The agent only reads:
- the logs of your app’s web process (
app), its workers, its cron jobs (cron) and its services on the app’s server, such asdb; - each of those parts’ state: whether it runs, whether its health check passes, how often it restarted, its memory against its limit, and its image;
- the deploy’s progress: each step on the server (the upload, the release command, the start and the switch), and whether it succeeded or failed;
- the app’s env files, only to mask their values.
It never offers the reverse proxy the server’s apps share, one-off containers such as the release command, other apps’ containers, or itself.
It can’t change anything. It has no shell, and the dashboard has no message that runs a command, starts or stops a container, or writes a file. Someone who took over the dashboard could read your app’s logs, and nothing more.
The read-only Docker proxy
Section titled “The read-only Docker proxy”The agent never touches Docker’s socket. It reads Docker through a small proxy next to it
(opscrew-agent-proxy), which passes only reads:
- Docker’s ping;
- the list of containers: the proxy passes the whole server’s list, other apps’ container names included, and the agent asks only for your app’s, by its Compose project, and checks each answer;
- the details, logs and figures of your app’s own containers, by their names.
The proxy refuses everything else with an error: creating, starting, stopping or removing a
container, running a command in one, and the details, logs and figures of another app’s container.
The proxy has no network at all. The agent (opscrew-agent) runs on a network of its own, apart
from your app’s, as the server’s deploy user, with a read-only file system and no Linux
capability.
What it masks
Section titled “What it masks”Every log line, error and status field passes OpsCrew’s masking on the server, before it is sent. It masks:
- every value of 8 characters or more in your app’s
app.envand in each service’s env file, not only those with a secret’s name, since a framework’s key often has none. The app’s own addresses stay readable (the host lists andAPP_URL), and so does a value under 8 characters; - the agent’s own token;
- anything shaped like a known kind of secret, such as an API token or a private key.
A masked value shows as [REDACTED:<name>]. The agent reads the env files again when a deploy
changes them, and a value it read once stays masked while it runs. A
credential rotation or a
service’s move to another server replaces the files instead, so OpsCrew
starts the agent again after it, and the agent masks the new values. A setting such as production
is masked as well; that is the cost of masking every value.
When the agent can’t read one of the env files, it stops rather than send lines it couldn’t mask.
It never sends any container’s settings or environment values, the content of any file other than masked log lines, or the server’s addresses. Its own log, on the server, says only what it does (connected, refused, reconnecting), never a token or a log line.
A busy app’s lines are held to 200 a second per stream; the dashboard is told how many were left out.
One connection, outbound
Section titled “One connection, outbound”The agent opens one encrypted WebSocket connection (wss://) to the dashboard, and checks the
dashboard’s certificate. Nothing on your server listens for the dashboard and no port is opened, so
it works behind a home router and when only Cloudflare reaches your server.
When the dashboard can’t be reached, the agent tries again, waiting from 1 second up to a minute between tries. When the dashboard refuses its token, it stops trying and says so in its own log, until it is started again, as each deploy starts it.
The token and the address
Section titled “The token and the address”The dashboard sets both, in your repository on GitHub:
- The token: one per app environment, a GitHub secret named as the environment’s other deploy
secrets are:
OPSCREW_AGENT_TOKENfor the first app’s prod,OPSCREW_STAGING_AGENT_TOKENfor its staging, andOPSCREW_<APP>_AGENT_TOKENorOPSCREW_<APP>_<ENV>_AGENT_TOKENfor another app, such asOPSCREW_DOCS_STAGING_AGENT_TOKEN. It is kept in the deploy job’s GitHub environment when it has one, else in the repository. On the dashboard’s side the token names exactly one app environment, so it reads only that environment’s agent. - The address: the repository variable
OPSCREW_AGENT_URL, the dashboard’swss://address (wss://app.opscrew.dev/agent), shared by every app in the repository.
OpsCrew reads only whether the token exists, never its value. Each deploy writes the address and
the token to agent.env in the app’s folder on the server, readable only by the deploy user, and
never into a log.
Who can use the token
Section titled “Who can use the token”Anything with the deploy user’s access on the server can read the token, and send the dashboard false logs with it: false lines, a false state or a false deploy’s progress for that environment. That includes whoever can log in as the deploy user, the deploy workflow, and on a shared server the other apps’ deploys, which run as the same user.
The token gives nothing on the server itself, and the dashboard can’t change the server with it. Whoever has the deploy user’s access can already reach Docker, which is more. Give that access only to people you’d trust with the app.
Adding it and removing it
Section titled “Adding it and removing it”Adding it: once the dashboard has stored the token and the address, run:
npx opscrew provisionIts pull request adds the agent’s script (agent/agent.mjs in the app’s runtime folder, such as
opscrew/runtime/), its proxy’s allow-list (agent/Caddyfile beside it) and the two services to
the app’s Compose file, and says what the agent does. Merge it, and the deploy that follows starts
the agent. The agent’s image is OpsCrew’s pinned Node image, and every later deploy writes
agent.env again and restarts the agent. The agent never fails a deploy: when its image can’t be
pulled or it doesn’t start, the deploy says so, and the app’s new version serves.
When the environment has the token but the repository has no valid OPSCREW_AGENT_URL,
provision installs no agent and says what to set. Without the token it installs none and says
nothing, since the address serves every app in the repository.
npx opscrew status then shows OpsCrew's agent for the dashboard: running under the app’s
containers, or stopped with what to do.
Removing it: delete the token, from the dashboard or from GitHub, then run
npx opscrew provision again. Its pull request removes the two services and the agent’s files
(agent/ in the runtime folder), and the deploy after it removes the agent’s containers and
deletes its files on the server: agent.env, the deploy’s progress and the agent/ folder.
npx opscrew destroy, and the removal of an app from a server you own or a shared server, remove
the agent with the app’s containers and delete agent.env, even when the data is kept. Destroy
also deletes the environment’s token on GitHub with its other deploy secrets. The repository
variable OPSCREW_AGENT_URL stays, since every app shares it.
What it costs
Section titled “What it costs”At most 96 MB of the server’s memory: 64 MB for the agent and 32 MB for its proxy, each a hard
limit. On a server that holds other OpsCrew apps, npx opscrew provision counts them when it
checks that everything fits, and the other apps’ agents too. While the dashboard is unreachable,
it costs nothing more.