Skip to content

Commit 6384e1d

Browse files
blackwoodjprusik
andauthored
Adds flightcheck status command; xtend crypto with reset option (#466)
Co-authored-by: Jonathan Prusik <jprusik@users.noreply.github.com>
1 parent 3327b7d commit 6384e1d

6 files changed

Lines changed: 375 additions & 3 deletions

File tree

.claude/CLAUDE.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,23 @@ npm run test:static:notification
5959
# Single spec file
6060
npm run pretest && NODE_EXTRA_CA_CERTS=ssl.crt npx playwright test tests/static/autofill-forms.spec.ts
6161

62-
# Public (live site) tests
62+
# Public (live site) tests — NEVER run these; they hit real external sites
6363
npm run test:public:debug
6464

6565
# Accessibility tests
6666
npm run test:a11y:browser
6767
npm run test:a11y:web
6868

6969
# Utilities
70+
npm run flightcheck # check environment prerequisites
7071
npm run prettier:fix # format all files
7172
npm run typecheck # typecheck scripts/ and tests/
73+
npm run setup:install # generate and write BW_INSTALLATION_ID / BW_INSTALLATION_KEY
74+
npm run setup:crypto # generate and write crypto values to .env
75+
npm run setup:flags # sync feature flags from REMOTE_VAULT_CONFIG_MATCH into flags.json
7276
npm run setup:vault # create account + seed vault
7377
npm run seed:vault:ciphers # seed vault only (account must exist)
78+
npm run seed:vault:import # import a vault JSON file (requires VAULT_IMPORT_FILE)
7479
```
7580

7681
## Debug Helpers
@@ -82,6 +87,7 @@ npm run seed:vault:ciphers # seed vault only (account must exist)
8287

8388
1. **No real credentials in test data**: All vault passwords are fake (e.g., `"fakeBasicFormPassword"`). Prefix test credential values with `fake`.
8489
2. **No secrets in source**: Crypto material, master password hashes, and API keys live only in `.env` (gitignored). Generated by `npm run setup:crypto` — never set manually.
90+
- `VAULT_EMAIL` is used as a PBKDF2 salt and as a seeding value for generating the install keys — changing it invalidates `MASTER_PASSWORD_HASH` and requires manually removing the generated crypto vars from `.env`, running `npm run setup:crypto`, and starting fresh with a new DB.
8591
3. **Zero-knowledge invariant**: Account creation in `create-account.ts` sends a pre-hashed master password and encrypted key material — never the plaintext password — to the server API.
8692
4. **Downloads disabled**: The browser fixture sets `acceptDownloads: false`.
8793

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,23 @@ As a secondary concern, BIT aspires to track and anticipate feature compatibilit
7373
- Next run `npm run setup:all`, entering your system password when prompted.
7474
- Run static tests with `npm run test:static`.
7575

76+
## Returning Workflow
77+
78+
Run `npm run flightcheck` to check which prerequisites are satisfied and get specific commands for anything that needs attention. Typically you only need to do the initial set up once; after that all that's needed is:
79+
80+
```bash
81+
docker compose up -d --wait # start the vault server
82+
npm run test:static:debug
83+
```
84+
7685
## Setup
7786

7887
- Create an `.env` file in the root directory with values pointing to the vault you want to test against (use `.env.example` as guidance) and populate it with your desired values
7988

8089
> Important! Once you've generated installation and crypto values for your `.env` file, DO NOT CHANGE the seeding values (`VAULT_EMAIL`, `VAULT_PASSWORD`, `KDF_ITERATIONS`). Doing so requires regenerating your installation and crypto secret values and rebuilding/updating server.
8190
91+
> If you do need to change `VAULT_EMAIL` or `VAULT_PASSWORD`, manually remove the generated crypto vars (`KDF_ITERATIONS`, `MASTER_PASSWORD_HASH`, `PROTECTED_SYMMETRIC_KEY`, `GENERATED_RSA_KEY_PAIR_PUBLIC_KEY`, `GENERATED_RSA_KEY_PAIR_PROTECTED_PRIVATE_KEY`) from your `.env`, run `npm run setup:crypto`, then `npm run setup:vault`. Note that changing `VAULT_EMAIL` may also require regenerating install keys (`npm run setup:install`) and rebuilding the vault, depending on what you're trying to do.
92+
8293
- Run `npm run setup:install` to generate and add installation values to your dotfile
8394
- Alternatively, you can generate them at `https://bitwarden.com/host` and add them to your dotfile manually as `BW_INSTALLATION_ID` and `BW_INSTALLATION_KEY`
8495
- Run `npm run setup:crypto` to generate and add crypto values to your dotfile
@@ -113,6 +124,14 @@ Using Docker Compose will set up all the services required by the extension for
113124

114125
Create and start the containers and volumes with `docker compose up -d --build --remove-orphans`, and teardown with `docker compose down -v`
115126

127+
> If the image pull fails with a network error (e.g. `unexpected EOF`), re-run `docker compose pull` and then retry. If it continues to fail, try increasing the timeout: `COMPOSE_HTTP_TIMEOUT=120 docker compose pull`. A common underlying cause is endpoint protection or firewall rules blocking the pull.
128+
129+
> If startup fails with `port is already allocated`, a previous container session is holding the port — often a prior BIT stack (e.g. after updating the image version). Run `npm run flightcheck` to identify which project owns the port and get the exact teardown command.
130+
131+
> Each compose project uses its own database volume. Switching to a different vault image version means a fresh database — re-run `npm run setup:vault` after bringing the new stack up. Old project volumes are not removed automatically. If `npm run flightcheck` detects a wrong-version or missing stack, it will list any BIT volumes from other projects and show the `docker volume rm` commands to clean them up.
132+
133+
> If you have previously seeded a vault, you don't need to run setup again — just start it. This is especially relevant when switching between several environments (for example, different server images or feature flag configurations): each has its own volume, so bringing one back up restores its prior state as-is.
134+
116135
### Seeding Your Vault
117136

118137
> If using Docker Compose to host the server environment (as described in the previous section), you may need to wait for the services within the `bitwarden` container to enter a running state before running any seeding scripts.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"seed:vault:ciphers": "./scripts/seeder.sh",
4444
"seed:vault:ciphers:refresh": "REFRESH=true ./scripts/seeder.sh",
4545
"seed:vault:import": "./scripts/vault-import.sh",
46+
"flightcheck": "./scripts/flightcheck.sh",
4647
"setup:all": "./scripts/first-time-setup.sh",
4748
"setup:extension": "rimraf clients && git clone https://github.com/bitwarden/clients.git clients && cd clients && npm ci",
4849
"setup:install": "ts-node ./scripts/generate-installation.ts",

scripts/create-account.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type AccountCreationResponseData = ResponseData;
2222
let failedAttemptsCount = 0;
2323

2424
async function createAccount() {
25-
if (failedAttemptsCount > 60) {
25+
if (failedAttemptsCount > 25) {
2626
throw new Error("The account was unable to be created.");
2727
}
2828

@@ -72,6 +72,16 @@ async function createAccount() {
7272
}
7373

7474
console.log(`Retrying account creation at ${vaultHost}...`);
75+
if (preCreationResponseData.validationErrors) {
76+
// Validation errors indicate a real misconfiguration — always surface them
77+
if (preCreationResponseData.message) {
78+
console.log(`\x1b[2m ${preCreationResponseData.message}\x1b[0m`);
79+
}
80+
Object.entries(preCreationResponseData.validationErrors).forEach(
81+
([field, msgs]) =>
82+
console.log(`\x1b[2m ${field}: ${msgs.join(", ")}\x1b[0m`),
83+
);
84+
}
7585
failedAttemptsCount++;
7686
setTimeout(createAccount, 3000);
7787
return;

0 commit comments

Comments
 (0)