|
| 1 | +--- |
| 2 | +title: Passwords & access |
| 3 | +description: Gate a Spacefast space with a shared password, identity- and location-aware access rules, or path-scoped Basic Auth — and control exactly who sees what. |
| 4 | +--- |
| 5 | + |
| 6 | +Spacefast gives you three ways to control who can see a space, from simplest to most precise: |
| 7 | + |
| 8 | +- **Space password** — one shared secret over everything. |
| 9 | +- **Access rules** — allow, block, or require sign-in by identity, IP range, country, or path. |
| 10 | +- **`_headers` Basic Auth** — path-scoped, file-based credentials that travel with your publish. |
| 11 | + |
| 12 | +You can combine them. They resolve into a single policy you can inspect at any time with `sf access effective`. |
| 13 | + |
| 14 | +## Space password |
| 15 | + |
| 16 | +A space password protects the whole space, including permanent Version URLs. It works on any claimed space on any plan. |
| 17 | + |
| 18 | +```bash |
| 19 | +sf password set |
| 20 | +printf '%s\n' "$PASSWORD" | sf password set --stdin |
| 21 | +sf password clear |
| 22 | +``` |
| 23 | + |
| 24 | +`sf password set` prompts interactively, or reads from stdin with `--stdin`. The API equivalent is the `password` field on the space `PATCH` route: a string enables or replaces the password, `null` clears it. |
| 25 | + |
| 26 | +Passwords are stored hashed, never in plain text. A visitor who enters the password gets a cookie for the space; changing or clearing the password invalidates every previously issued cookie, so rotating it locks everyone out immediately. |
| 27 | + |
| 28 | +## Access rules |
| 29 | + |
| 30 | +Access rules go beyond a single password: each rule **allows**, **denies**, or **challenges** (requires sign-in) for visitors matching some condition. Rules are evaluated top to bottom, first match wins. |
| 31 | + |
| 32 | +Manage them with `sf access`: |
| 33 | + |
| 34 | +| Command | What it does | |
| 35 | +| -------------------------------------------- | ---------------------------------------------------------------------------- | |
| 36 | +| `sf access effective` (alias `sf access ls`) | Show the resolved policy — every rule with its source and order. Start here. | |
| 37 | +| `sf access show` | Show just the rules you've set on this space. | |
| 38 | +| `sf access grant <audience>` | Require visitors to sign in as that audience to enter. | |
| 39 | +| `sf access ban <audience>` | Prepend a deny to the cloud lane for that audience. | |
| 40 | +| `sf access set <file.json>` | Replace all of your rules from a JSON document (full control). | |
| 41 | +| `sf access rm <index>` | Remove one rule by the `[index]` shown in `sf access show`. | |
| 42 | +| `sf access clear` | Remove all of your rules. | |
| 43 | + |
| 44 | +### Lock a space to an audience |
| 45 | + |
| 46 | +An **audience** is an identity glob, matched against people who sign in to Spacefast. Grant one to require sign-in: |
| 47 | + |
| 48 | +```bash |
| 49 | +sf access grant 'team:team_123:member' # anyone on your team |
| 50 | +sf access grant 'email:*@acme.com' # a signed-in user whose email matches |
| 51 | +``` |
| 52 | + |
| 53 | +Common audience prefixes: `team:<id>:member`, `user:<id>`, `email:` (supports `*` globs against the signed-in user's verified email), and service/external tokens (`svc:`, `ext:`). Visitors are prompted to sign in and are admitted only if their identity matches. Granting by team is the most reliable way to share with named people today. |
| 54 | + |
| 55 | +### Block an audience, an IP range, or a country |
| 56 | + |
| 57 | +`sf access ban` blocks an identity audience by prepending a deny to the cloud lane: |
| 58 | + |
| 59 | +```bash |
| 60 | +sf access ban 'email:*@spammer.example' |
| 61 | +``` |
| 62 | + |
| 63 | +To block by **IP range** or **country**, or to mix conditions, write the rules directly with `sf access set`. A rule is `{ match, effect, auth? }`: |
| 64 | + |
| 65 | +```json |
| 66 | +{ |
| 67 | + "rules": [ |
| 68 | + { "match": { "country": "RU" }, "effect": "deny" }, |
| 69 | + { "match": { "ipCidrs": ["203.0.113.0/24"] }, "effect": "deny" }, |
| 70 | + { |
| 71 | + "match": { "pathPattern": "/admin/*" }, |
| 72 | + "effect": "challenge", |
| 73 | + "auth": { "token": { "requiredGrants": ["team:team_123:member"] } } |
| 74 | + } |
| 75 | + ] |
| 76 | +} |
| 77 | +``` |
| 78 | + |
| 79 | +```bash |
| 80 | +sf access set rules.json |
| 81 | +``` |
| 82 | + |
| 83 | +`match` conditions (all optional, AND-combined): `pathPattern` (glob), `channel`, `ipCidrs`, `country` (ISO-3166 alpha-2), `host`, `agent`, and a single `header`. `effect` is `allow`, `deny`, or `challenge`. A `challenge` rule carries `auth` — either a `token` with `requiredGrants`, or a `password`. |
| 84 | + |
| 85 | +The example above keeps the site public while blocking a country and an IP range, and requiring a team login only under `/admin`. |
| 86 | + |
| 87 | +### Where rules can live |
| 88 | + |
| 89 | +Rules resolve from three sources, in order — **first match wins**: |
| 90 | + |
| 91 | +1. **Platform** — plan-level defaults you can't override (see the note below). |
| 92 | +2. **File** — rules you commit to `access.rules` in [`sf.jsonc`](/configuration), so they version and roll back with your site. |
| 93 | +3. **Cloud** — rules you set with `sf access`, applied live without a republish. |
| 94 | + |
| 95 | +There is no separate ban pre-pass. `sf access ban` assigns the new deny the first |
| 96 | +order inside the cloud lane, so it wins over later cloud allows; platform and |
| 97 | +file rules still have earlier merged order values. Put a file-lane deny before |
| 98 | +file-lane allows when that deny must travel with the version, and confirm the |
| 99 | +actual merged order with `sf access effective`. |
| 100 | + |
| 101 | +File rules use the exact same rule shape as `sf access set` and compile when you publish. An invalid rule fails the publish with a `config_invalid` diagnostic — it is never silently dropped. |
| 102 | + |
| 103 | +```jsonc |
| 104 | +// sf.jsonc |
| 105 | +{ |
| 106 | + "access": { |
| 107 | + "rules": [ |
| 108 | + { "match": { "ipCidrs": ["203.0.113.0/24"] }, "effect": "deny" }, |
| 109 | + { |
| 110 | + "match": { "pathPattern": "/admin/**" }, |
| 111 | + "effect": "challenge", |
| 112 | + "auth": { "token": { "requiredGrants": ["team:team_123:member"] } }, |
| 113 | + }, |
| 114 | + ], |
| 115 | + }, |
| 116 | +} |
| 117 | +``` |
| 118 | + |
| 119 | +Because the rules ship with the publish, `sf rollback` restores the previous version's rules along with its files. Use the cloud lane instead when a rule must change right now, without a republish. |
| 120 | + |
| 121 | +`sf access effective` prints all three merged, each tagged with its `source` and `order`, so you always know which rule decided a request. |
| 122 | + |
| 123 | +:::note |
| 124 | +On the Free plan, Version URLs become login-walled 7 days after they're published; on paid plans they stay open as long as you keep them. Paid plans also unlock `_headers` Basic Auth (below). |
| 125 | +::: |
| 126 | + |
| 127 | +## `_headers` Basic Auth |
| 128 | + |
| 129 | +:::note |
| 130 | +Not available on Free. Available on Personal and Work. |
| 131 | +::: |
| 132 | + |
| 133 | +Use a `Basic-Auth` line in [`_headers`](/headers) to protect matching paths with named credentials. Credentials are one or more space-separated `username:password` pairs. |
| 134 | + |
| 135 | +```text |
| 136 | +/preview/* |
| 137 | + Basic-Auth: editor:preview-password |
| 138 | +
|
| 139 | +/staging/* |
| 140 | + Basic-Auth: alice:one-password bob:another-password |
| 141 | +``` |
| 142 | + |
| 143 | +- Username cannot contain `:` or whitespace. |
| 144 | +- Password cannot contain whitespace and must be non-empty. |
| 145 | +- `Basic-Auth` is never sent in the response, and `! Basic-Auth` is invalid because Basic Auth must be configured with credentials. |
| 146 | + |
| 147 | +Because `_headers` ships with each publish, Basic Auth credentials are versioned |
| 148 | +with your files and roll back with versions. Anyone who can read the repository |
| 149 | +or a retained version may recover historical credentials. Use unique, |
| 150 | +non-reused passwords and rotate them after exposure or access changes. |
| 151 | +Anonymous spaces cannot use it. |
| 152 | + |
| 153 | +## Which one to use |
| 154 | + |
| 155 | +- **Space password** for one shared secret over everything — client previews, unfinished launches, internal docs. Works on every plan, managed from the CLI or API without touching your files. |
| 156 | +- **Access rules** when _who_ or _where_ matters — restrict to a company's email domain or a team, block an abusive IP or country, or require sign-in on just `/admin`. Cloud rules apply live; file rules version with your site. |
| 157 | +- **Basic Auth** for specific paths with multiple named users where you want the credentials to live in your repo and roll back with each publish. |
| 158 | + |
| 159 | +## What visitors see |
| 160 | + |
| 161 | +A password-protected space shows the platform password page, themed to your space; entry is remembered until the password changes. A `challenge` access rule prompts the visitor to sign in and admits them only if their identity matches. A `deny` rule serves the platform access-denied page with a `403` (the `X-Spacefast-Reason` header names the rule's `reasonCode` when set). Basic Auth paths return a `401` challenge with nothing else. |
0 commit comments