Put a password on a site
$ grim server:auth shop --enable
The site is deployed and nobody outside the team should see it yet: a staging copy, a shop before its launch day, a client preview. grim server:auth puts the browser's own password prompt in front of the whole project, and takes it away again on the day it opens. The app is not involved. The prompt comes from nginx on the host, before a request reaches a container.
Usage
$ grim server:auth shop --enable # user admin, password generated
$ grim server:auth shop --enable --user=client --pass=s3cret # your own pair
$ grim server:auth shop --disable # open to everyone again
$ grim server:auth shop --enable --env=staging # the staging stack onlyRun it from anywhere. The project must be in your ~/.grim/servers.json. Without --env it acts on the project's default environment, the first one you registered. One of --enable and --disable is required; with neither the command stops with Specify --enable or --disable.
Arguments and options
Enable or disable HTTP Basic Auth for a project
Usage
grim server:auth [--enable] [--disable] [--user USER] [--pass PASS] [--env ENV] [--] <project>Arguments
| Argument | Description |
|---|---|
project |
Project name (required) |
Options
| Option | Description |
|---|---|
--enable |
Enable basic auth |
--disable |
Disable basic auth |
--user=USER |
Basic auth username (default: admin) |
--pass=PASS |
Basic auth password |
--env=ENV |
Environment (production, staging, …) — defaults to the project's default environment |
What it actually does
With --enable:
- Settles the password. Without
--passit generates one of twelve characters and prints it. - Writes
.htpasswdinto the stack's directory on the server (/opt/shop,/opt/shop-stagingfor--env=staging). The hash is made there; only the hash is stored. - Rewrites the stack's nginx vhost with the password prompt on everything except
/api/v1/healthcheck, so health checks and monitoring keep working without credentials. The vhost keeps every domain attached with grim server:add-domain and a certificate of your own, if the project has one. - Runs certbot again for the primary domain and every alias to put the HTTPS block back into the rewritten vhost, then reloads nginx. A project with its own certificate skips certbot: the certificate is already in the vhost.
- Records the state in
servers.jsonand printsCredentials: admin / ….
With --disable the vhost is rewritten without the prompt, certbot and the reload run the same way, and .htpasswd is removed.
Pitfalls
The password is shown once
Only its hash reaches the server and nothing is kept on your machine. Copy the Credentials line when it appears. A forgotten password is replaced by running --enable again, which also replaces the user: the file holds one pair at a time.
No certificate at all
Warning: no acme_email recorded; skipping SSL setup. Vhost is HTTP-only. appears on a server set up without an ACME e-mail and without a certificate of its own. It means what it says: the site answers on plain HTTP until grim server:setup records an e-mail and the command runs again.
Adding the project again switches it off
Any later run of grim server:add-project writes the vhost without the prompt. Enable it again afterwards.
After it finishes
Open the site in a private window. The browser asks for the pair before anything loads. API clients and webhooks that call the site from outside are asked too, and they fail with 401 until they send the credentials or the prompt is switched off.
Related spells
grim server:add-project
Give a project a home
Prepare one environment of a project on a production server, with its database, nginx vhost, certificate, compose stack and .env.
grim server:add-domain
Add a second domain
Serve a deployed project on one more domain, with the vhost, the Traefik rule and the certificate widened to cover it.
grim server:remove-project
Tear a project down
Remove one environment of a project from its server, with its containers, volumes, database, vhost, certificate and directory.
grim server:status
Look over a server
List the servers you have registered, or look at one of them: its containers, its disk, Traefik and its projects.