badmfck-api-server 6.0.2 → 6.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +147 -4
- package/dist/apiServer/APIService.d.ts +1 -0
- package/dist/apiServer/APIService.js +5 -1
- package/dist/apiServer/deployment/ConfigService.d.ts +24 -0
- package/dist/apiServer/deployment/ConfigService.js +15 -0
- package/dist/apiServer/deployment/Deploy.js +18 -0
- package/dist/apiServer/deployment/DeployerService.d.ts +47 -6
- package/dist/apiServer/deployment/DeployerService.js +330 -39
- package/dist/apiServer/deployment/Notifier.d.ts +14 -0
- package/dist/apiServer/deployment/Notifier.js +22 -0
- package/dist/apiServer/deployment/ReviewStore.d.ts +62 -0
- package/dist/apiServer/deployment/ReviewStore.js +186 -0
- package/dist/apiServer/deployment/SecretsInjector.d.ts +21 -0
- package/dist/apiServer/deployment/SecretsInjector.js +188 -0
- package/dist/apiServer/helper/IpAllowList.d.ts +8 -0
- package/dist/apiServer/helper/IpAllowList.js +40 -0
- package/dist/apiServer/monitor/AccessStore.d.ts +2 -0
- package/dist/apiServer/monitor/AccessStore.js +12 -2
- package/dist/apiServer/monitor/Monitor.d.ts +1 -0
- package/dist/apiServer/monitor/Monitor.js +16 -0
- package/dist/apiServer/review/Review.d.ts +23 -0
- package/dist/apiServer/review/Review.js +149 -0
- package/dist/apiServer/review/ReviewAuth.d.ts +56 -0
- package/dist/apiServer/review/ReviewAuth.js +147 -0
- package/dist/apiServer/review/ReviewDiff.d.ts +43 -0
- package/dist/apiServer/review/ReviewDiff.js +175 -0
- package/dist/apiServer/review/index.html +501 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -28,8 +28,9 @@ Node.js 21+ is required.
|
|
|
28
28
|
11. [Deployer and CLI](#deployer-and-cli)
|
|
29
29
|
12. [Blue-green deployments](#blue-green-deployments)
|
|
30
30
|
13. [Backups and restore](#backups-and-restore)
|
|
31
|
-
14. [
|
|
32
|
-
15. [
|
|
31
|
+
14. [Deploy review](#deploy-review)
|
|
32
|
+
15. [Options reference](#options-reference)
|
|
33
|
+
16. [Security](#security)
|
|
33
34
|
|
|
34
35
|
---
|
|
35
36
|
|
|
@@ -306,6 +307,17 @@ monitorAuthDir: "/var/lib/my-service", // where 2FA enrollments are kept
|
|
|
306
307
|
change is ignored and the previous access stays in force. The reason is logged.
|
|
307
308
|
- **Location and permissions.** Keep the file outside the deploy folders and `chmod 600` it. A warning
|
|
308
309
|
is logged if other users can read it.
|
|
310
|
+
- **Restrict by address.** `monitorAllowedIps` in `access` (inline or in `access.json`) limits every
|
|
311
|
+
`sm/*` request to the given IPs and CIDR subnets, the page and sign-in included. A session token
|
|
312
|
+
taken elsewhere is therefore useless outside those addresses too:
|
|
313
|
+
|
|
314
|
+
```jsonc
|
|
315
|
+
{ "monitor": [ … ], "monitorAllowedIps": ["10.8.0.0/24", "203.0.113.7"] }
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
Other addresses get `403`. Changes in `access.json` apply without a restart, and an invalid entry
|
|
319
|
+
rejects the change. Behind nginx, pass `X-Real-IP` (see [`trustedProxies`](#options-reference)),
|
|
320
|
+
otherwise every request appears to come from `127.0.0.1`.
|
|
309
321
|
- **Keep `monitorAuthDir` outside the deploy folders.** Otherwise a deploy wipes the enrollments and
|
|
310
322
|
everyone has to enroll again.
|
|
311
323
|
|
|
@@ -321,6 +333,7 @@ The library protects four things, each in its own way:
|
|
|
321
333
|
| Monitor (`sm/*`) | your operations team | password + mandatory TOTP 2FA, then a session token |
|
|
322
334
|
| Documentation (`doc/*`) | developers and partners | login and password (a static token) |
|
|
323
335
|
| Deployer (`pckg/*`) | CI and developers | deployer user + project token |
|
|
336
|
+
| Deploy review (`review/*`) | reviewers | personal emailed link + login, password and TOTP 2FA |
|
|
324
337
|
|
|
325
338
|
The library doesn't manage the users of your application. That's the job of your interceptor and
|
|
326
339
|
database. The rest of this section is about the built-in consoles.
|
|
@@ -575,6 +588,43 @@ A project config (`projects_path/<name>.json`):
|
|
|
575
588
|
}
|
|
576
589
|
```
|
|
577
590
|
|
|
591
|
+
#### Keeping secrets out of the deployed code
|
|
592
|
+
|
|
593
|
+
By default, `config` values are written into the shipped files in place of `_{{KEY}}_`. That puts
|
|
594
|
+
passwords into the code, into both blue-green slots and into every backup. Add `secrets` to the project
|
|
595
|
+
config to avoid this:
|
|
596
|
+
|
|
597
|
+
```jsonc
|
|
598
|
+
"secrets": {} // uses "secrets_dir" from setup.json
|
|
599
|
+
"secrets": { "dir": "/etc/node-secrets" } // → /etc/node-secrets/<project>[-<slot>].json
|
|
600
|
+
"secrets": { "file": "/etc/node-secrets/my.json" }
|
|
601
|
+
```
|
|
602
|
+
|
|
603
|
+
The deployer writes the values (merged for the slot) into that file, with permissions `600` and
|
|
604
|
+
outside the deploy folder, and rewrites each quoted placeholder in `.js` files as a read of the file:
|
|
605
|
+
|
|
606
|
+
```js
|
|
607
|
+
DB_PASSWORD: "_{{db_password}}_" // in the archive
|
|
608
|
+
DB_PASSWORD: (function(k){ … reads /etc/node-secrets/my-blue.json … })("db_password") // on the server
|
|
609
|
+
```
|
|
610
|
+
|
|
611
|
+
- **No code changes.** The application gets exactly the strings it got before, so `parseInt("_{{port}}_")`
|
|
612
|
+
still works. The file is read once per process.
|
|
613
|
+
- **Restarts.** pm2 restarts, `migrate` and cluster workers keep working, because the file stays in place.
|
|
614
|
+
- **Backups and restore.** Backups and archives contain only the file path. A restored version reads
|
|
615
|
+
the current values instead of the ones from its deploy.
|
|
616
|
+
- **Missing key.** If a key is missing from the file, the start fails with a clear error instead of
|
|
617
|
+
running with a placeholder.
|
|
618
|
+
- **Same user.** The secrets file belongs to the deployer's user and is readable only by it. pm2,
|
|
619
|
+
started by the deployer, runs the app as that same user. A project whose pm2 attributes switch the
|
|
620
|
+
user (`--uid`, `--gid`) is refused before anything changes, since the app couldn't read the file.
|
|
621
|
+
The file is also read back before the app is started.
|
|
622
|
+
- **Start with a blue-green project.** If the new version fails to start, the inactive slot fails and
|
|
623
|
+
traffic stays on the old one until you `activate`.
|
|
624
|
+
- **Fallback to plain substitution.** Values are still written into the file for `.json`, `.env`,
|
|
625
|
+
unquoted placeholders, templates with `${…}`, ES-module projects, and any file that wouldn't compile
|
|
626
|
+
after the rewrite. Each deploy logs which files still hold values.
|
|
627
|
+
|
|
578
628
|
**In your project**, create `deploy.json` or a `deploy/` folder with one or more configs. Keep it out of
|
|
579
629
|
git: it holds credentials.
|
|
580
630
|
|
|
@@ -623,6 +673,8 @@ To pass a config path through npm, use `--`: `npm run deploy -- deploy/prod.json
|
|
|
623
673
|
- Every deploy, switch and restore needs a deployer user and the project token. Both are stored on
|
|
624
674
|
the server only as hashes.
|
|
625
675
|
- `allowed_ips` limits which addresses can reach the deployer at all.
|
|
676
|
+
- With [deploy review](#deploy-review), uploads wait for approval by reviewers who sign in with a
|
|
677
|
+
password and 2FA.
|
|
626
678
|
|
|
627
679
|
---
|
|
628
680
|
|
|
@@ -763,7 +815,98 @@ How a restore works:
|
|
|
763
815
|
Restoring a standby slot changes nothing until you `activate` it.
|
|
764
816
|
|
|
765
817
|
Configuration values are baked in at deploy time. A restored version comes back with the secrets it was
|
|
766
|
-
deployed with.
|
|
818
|
+
deployed with, unless the project uses a [secrets file](#keeping-secrets-out-of-the-deployed-code).
|
|
819
|
+
|
|
820
|
+
---
|
|
821
|
+
|
|
822
|
+
## Deploy review
|
|
823
|
+
|
|
824
|
+
A project can require approval before anything reaches the server. The upload is held, each reviewer
|
|
825
|
+
gets a personal link by email, and the deploy runs only after approval. That way stolen deploy
|
|
826
|
+
credentials alone can't change production.
|
|
827
|
+
|
|
828
|
+
### Setup
|
|
829
|
+
|
|
830
|
+
Reviewers are defined in the deployer's `setup.json`. Their passwords are hashes made with
|
|
831
|
+
`npx badmfck hash-password`, and they set up 2FA at the first sign-in. `review_url` is the address of
|
|
832
|
+
the review page, as reviewers reach it:
|
|
833
|
+
|
|
834
|
+
```jsonc
|
|
835
|
+
{
|
|
836
|
+
"reviewers": [
|
|
837
|
+
{ "login": "lead", "password": "scrypt$16384$8$1$…", "email": "lead@example.com" },
|
|
838
|
+
{ "login": "cto", "password": "scrypt$16384$8$1$…", "email": "cto@example.com" }
|
|
839
|
+
],
|
|
840
|
+
"review_url": "https://deployer.example.com/api/review/html",
|
|
841
|
+
"notifier": { "URL": "…", "KEY": "…" }, // sends the emails
|
|
842
|
+
"allowed_ips": ["10.8.0.0/24"] // the review page is behind it too, e.g. the VPN range
|
|
843
|
+
}
|
|
844
|
+
```
|
|
845
|
+
|
|
846
|
+
A project opts in from its config:
|
|
847
|
+
|
|
848
|
+
```jsonc
|
|
849
|
+
"review": { "reviewers": ["lead", "cto"], "mode": "all", "ttlHours": 24 }
|
|
850
|
+
```
|
|
851
|
+
|
|
852
|
+
- **`mode`.** With `"any"`, one accept is enough; with `"all"`, every reviewer must accept. Either
|
|
853
|
+
way, a single decline rejects the upload.
|
|
854
|
+
- **`ttlHours`.** How long the links stay valid: 1 to 168 hours, 24 by default.
|
|
855
|
+
|
|
856
|
+
If a project's review can't work (an unknown reviewer, no `review_url`, no notifier), the deployer says
|
|
857
|
+
so at startup and refuses that project's uploads until it is fixed.
|
|
858
|
+
|
|
859
|
+
### How it works
|
|
860
|
+
|
|
861
|
+
1. **`badmfck deploy`** uploads as usual. The archive goes through all the usual checks and is then
|
|
862
|
+
held. The CLI prints `WAITING FOR REVIEW`, and production is untouched.
|
|
863
|
+
2. **Each reviewer gets an email** with a personal link. The link alone is not enough: it opens a
|
|
864
|
+
sign-in with login, password and a 2FA code.
|
|
865
|
+
3. **The page shows the changes** compared with the last deployed version: version before and
|
|
866
|
+
after, dependency changes in `package.json`, and added, removed and changed files with a
|
|
867
|
+
line-by-line diff.
|
|
868
|
+
4. **Accept** runs the normal deploy (backup, migrations, pm2, nginx) from the stored archive, after
|
|
869
|
+
checking that its SHA-256 still matches what the reviewers saw. For blue-green, the new version
|
|
870
|
+
lands in the inactive slot, and `badmfck activate` still switches traffic. **Decline** deletes the
|
|
871
|
+
archive.
|
|
872
|
+
5. **A new upload** replaces the pending one. Every old link and every open review session stop
|
|
873
|
+
working, and reviewers get new links.
|
|
874
|
+
|
|
875
|
+
Undecided uploads expire after `ttlHours`, and their archive is removed.
|
|
876
|
+
|
|
877
|
+
### What the diff shows and hides
|
|
878
|
+
|
|
879
|
+
The comparison uses the **raw archives**: the stored archive of the last successful deploy and the
|
|
880
|
+
new one. Deployed folders are never read, because config values (passwords) are substituted there.
|
|
881
|
+
Files such as `.env*`, `*.pem` and `*.key` are listed, but their content is never shown. Binary and
|
|
882
|
+
very large files are listed with their sizes. The first reviewed deploy of a project has nothing to
|
|
883
|
+
compare with, so every file is shown as added.
|
|
884
|
+
|
|
885
|
+
### Security notes
|
|
886
|
+
|
|
887
|
+
- **Personal links.** A link works only for the reviewer it was sent to. The token is in the URL
|
|
888
|
+
fragment (`#…`), which never reaches the server logs, and the page removes it from the address bar.
|
|
889
|
+
- **Sessions.** A session lasts 15 minutes without activity and 1 hour at most. It is bound to one
|
|
890
|
+
upload: a new upload ends it.
|
|
891
|
+
- **Lockout.** 10 failed sign-ins lock the reviewer for 30 minutes.
|
|
892
|
+
- **Mail scanners.** Opening the link changes nothing. Accept and decline need a signed-in click, so
|
|
893
|
+
a mail scanner that "visits" links can't approve anything.
|
|
894
|
+
- **Separation of duties.** Give the review to someone other than the person who deploys. That's
|
|
895
|
+
what change control (for example PCI DSS 6.5) expects.
|
|
896
|
+
|
|
897
|
+
### Audit trail and maintenance
|
|
898
|
+
|
|
899
|
+
All review data lives in `<projects_path>/.review/`, with permissions `600`:
|
|
900
|
+
|
|
901
|
+
| File | Content |
|
|
902
|
+
|---|---|
|
|
903
|
+
| `<project>.history.jsonl` | every upload, decision and result, with IP addresses and the archive SHA-256 |
|
|
904
|
+
| `<project>.pending.*` | the archive waiting for review and its state |
|
|
905
|
+
| `<project>.last.tgz` | the raw archive of the last successful deploy, the "before" of the next diff |
|
|
906
|
+
| `reviewers-2fa.json` | reviewers' 2FA enrollments |
|
|
907
|
+
|
|
908
|
+
To reset a reviewer's 2FA, delete their entry from `reviewers-2fa.json`. It is read at every sign-in,
|
|
909
|
+
so no restart is needed.
|
|
767
910
|
|
|
768
911
|
---
|
|
769
912
|
|
|
@@ -779,7 +922,7 @@ deployed with.
|
|
|
779
922
|
| `isProductionEnvironment` | `false` | production mode |
|
|
780
923
|
| `interceptor` | — | authentication for your endpoints |
|
|
781
924
|
| `preproducer` / `postproducer` | — | hooks before the handler / before the response is sent |
|
|
782
|
-
| `access` | `{}` | `{ monitor, documentation }
|
|
925
|
+
| `access` | `{}` | `{ monitor, documentation, monitorAllowedIps }`, or a path to a JSON file reloaded on change |
|
|
783
926
|
| `monitorAuthDir` / `monitorAuthFile` | in memory | where 2FA enrollments are stored |
|
|
784
927
|
| `metricsDir` | in memory | persist metrics; 10 weeks are kept |
|
|
785
928
|
| `logFiles` | pm2 auto-detected | log files the monitor may tail (for example nginx) |
|
|
@@ -86,6 +86,7 @@ export declare const REQ_WS_SERVER: Req<void, WebSocketServer | null>;
|
|
|
86
86
|
export declare const REQ_INTERNAL_CALL: Req<HTTPRequestVO, IError | any>;
|
|
87
87
|
export declare const REQ_MONITOR_USERS: Req<void, IMonitorUser[]>;
|
|
88
88
|
export declare const REQ_DOC_USERS: Req<void, IDocumentationUser[]>;
|
|
89
|
+
export declare const REQ_MONITOR_ALLOWED_IPS: Req<void, string[]>;
|
|
89
90
|
export declare const S_APP_STARTED: Signal<void>;
|
|
90
91
|
export declare function Initializer(services: IBaseService[]): Promise<void>;
|
|
91
92
|
export declare class APIService<TInterceptorResult = any, TInternalCallParams = any> extends BaseService {
|
|
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.APIService = exports.S_APP_STARTED = exports.REQ_DOC_USERS = exports.REQ_MONITOR_USERS = exports.REQ_INTERNAL_CALL = exports.REQ_WS_SERVER = exports.REQ_HTTP_SERVER = exports.REQ_HTTP_REQUESTS_COUNT = exports.REQ_HTTP_LOG = exports.getDefaultOptions = void 0;
|
|
39
|
+
exports.APIService = exports.S_APP_STARTED = exports.REQ_MONITOR_ALLOWED_IPS = exports.REQ_DOC_USERS = exports.REQ_MONITOR_USERS = exports.REQ_INTERNAL_CALL = exports.REQ_WS_SERVER = exports.REQ_HTTP_SERVER = exports.REQ_HTTP_REQUESTS_COUNT = exports.REQ_HTTP_LOG = exports.getDefaultOptions = void 0;
|
|
40
40
|
exports.Initializer = Initializer;
|
|
41
41
|
const express_1 = __importDefault(require("express"));
|
|
42
42
|
const BaseService_1 = require("./BaseService");
|
|
@@ -66,6 +66,7 @@ const AccessStore_1 = require("./monitor/AccessStore");
|
|
|
66
66
|
const MonitorAuth_1 = require("./monitor/MonitorAuth");
|
|
67
67
|
const ClientIp_1 = require("./helper/ClientIp");
|
|
68
68
|
const Deployer_1 = require("./deployment/Deployer");
|
|
69
|
+
const Review_1 = require("./review/Review");
|
|
69
70
|
const ws_1 = require("ws");
|
|
70
71
|
const WebSocketServer_1 = require("./WebSocketServer");
|
|
71
72
|
let nextLogID = 0;
|
|
@@ -105,6 +106,7 @@ exports.REQ_WS_SERVER = new badmfck_signal_1.Req(undefined, "REQ_WS_SERVER");
|
|
|
105
106
|
exports.REQ_INTERNAL_CALL = new badmfck_signal_1.Req(undefined, "REQ_INTERNAL_CALL");
|
|
106
107
|
exports.REQ_MONITOR_USERS = new badmfck_signal_1.Req(undefined, "REQ_MONITOR_USERS");
|
|
107
108
|
exports.REQ_DOC_USERS = new badmfck_signal_1.Req(undefined, "REQ_DOC_USERS");
|
|
109
|
+
exports.REQ_MONITOR_ALLOWED_IPS = new badmfck_signal_1.Req(undefined, "REQ_MONITOR_ALLOWED_IPS");
|
|
108
110
|
exports.S_APP_STARTED = new badmfck_signal_1.default("S_APP_STARTED");
|
|
109
111
|
const activeServices = [];
|
|
110
112
|
const PACKAGE_VERSION = (() => {
|
|
@@ -185,6 +187,7 @@ class APIService extends BaseService_1.BaseService {
|
|
|
185
187
|
});
|
|
186
188
|
exports.REQ_MONITOR_USERS.listener = async () => access.monitor;
|
|
187
189
|
exports.REQ_DOC_USERS.listener = async () => access.documentation;
|
|
190
|
+
exports.REQ_MONITOR_ALLOWED_IPS.listener = async () => access.monitorAllowedIps;
|
|
188
191
|
this.options.endpoints.push(new Monitor_1.Monitor(this.options));
|
|
189
192
|
this.options.endpoints.push(new Documentation_1.Documentation(this.options));
|
|
190
193
|
this.options.endpoints.push(new ExternalServiceEndpoint_1.ExternalServiceEndpoint());
|
|
@@ -198,6 +201,7 @@ class APIService extends BaseService_1.BaseService {
|
|
|
198
201
|
this.deployer.init();
|
|
199
202
|
this.options.endpoints = [
|
|
200
203
|
new Deployer_1.Deployer(),
|
|
204
|
+
new Review_1.Review(this.deployer, this.options),
|
|
201
205
|
new Documentation_1.Documentation(this.options),
|
|
202
206
|
new Monitor_1.Monitor(this.options),
|
|
203
207
|
];
|
|
@@ -60,6 +60,21 @@ declare const _TConfig: {
|
|
|
60
60
|
readonly $__upstream_name_optional: true;
|
|
61
61
|
};
|
|
62
62
|
readonly $__nginx_optional: true;
|
|
63
|
+
readonly review: {
|
|
64
|
+
readonly reviewers: readonly [""];
|
|
65
|
+
readonly mode: "";
|
|
66
|
+
readonly $__mode_values: readonly ["any", "all"];
|
|
67
|
+
readonly ttlHours: 24;
|
|
68
|
+
readonly $__ttlHours_optional: true;
|
|
69
|
+
};
|
|
70
|
+
readonly $__review_optional: true;
|
|
71
|
+
readonly secrets: {
|
|
72
|
+
readonly dir: "";
|
|
73
|
+
readonly $__dir_optional: true;
|
|
74
|
+
readonly file: "";
|
|
75
|
+
readonly $__file_optional: true;
|
|
76
|
+
};
|
|
77
|
+
readonly $__secrets_optional: true;
|
|
63
78
|
};
|
|
64
79
|
export type IConfig = ValidationModel<typeof _TConfig>;
|
|
65
80
|
export declare const REQ_DEPLOYMENT_CONFIG: Req<void, Map<string, {
|
|
@@ -92,6 +107,15 @@ export declare const REQ_DEPLOYMENT_CONFIG: Req<void, Map<string, {
|
|
|
92
107
|
domain?: string | undefined;
|
|
93
108
|
upstream_name?: string | undefined;
|
|
94
109
|
} | undefined;
|
|
110
|
+
review?: {
|
|
111
|
+
reviewers: string[];
|
|
112
|
+
mode: "all" | "any";
|
|
113
|
+
ttlHours?: number | undefined;
|
|
114
|
+
} | undefined;
|
|
115
|
+
secrets?: {
|
|
116
|
+
dir?: string | undefined;
|
|
117
|
+
file?: string | undefined;
|
|
118
|
+
} | undefined;
|
|
95
119
|
}>>;
|
|
96
120
|
export declare const S_CONFIG_UPDATED: Signal<void>;
|
|
97
121
|
export declare class ConfigService extends BaseService {
|
|
@@ -102,6 +102,21 @@ const _TConfig = {
|
|
|
102
102
|
$__upstream_name_optional: true,
|
|
103
103
|
},
|
|
104
104
|
$__nginx_optional: true,
|
|
105
|
+
review: {
|
|
106
|
+
reviewers: [""],
|
|
107
|
+
mode: "",
|
|
108
|
+
$__mode_values: ["any", "all"],
|
|
109
|
+
ttlHours: 24,
|
|
110
|
+
$__ttlHours_optional: true,
|
|
111
|
+
},
|
|
112
|
+
$__review_optional: true,
|
|
113
|
+
secrets: {
|
|
114
|
+
dir: "",
|
|
115
|
+
$__dir_optional: true,
|
|
116
|
+
file: "",
|
|
117
|
+
$__file_optional: true,
|
|
118
|
+
},
|
|
119
|
+
$__secrets_optional: true,
|
|
105
120
|
};
|
|
106
121
|
exports.REQ_DEPLOYMENT_CONFIG = new badmfck_signal_1.Req();
|
|
107
122
|
exports.S_CONFIG_UPDATED = new badmfck_signal_1.default();
|
|
@@ -274,6 +274,24 @@ async function Deploy(opt) {
|
|
|
274
274
|
}
|
|
275
275
|
const emptyResponse = body === null || body === undefined
|
|
276
276
|
|| (typeof body === "object" && Object.keys(body).length === 0);
|
|
277
|
+
const pending = body?.data?.data;
|
|
278
|
+
if (pending && typeof pending === "object" && pending.pendingReview === true) {
|
|
279
|
+
console.log(yellow(bold("⏳ UPLOADED — WAITING FOR REVIEW (not deployed yet)")));
|
|
280
|
+
console.log(line);
|
|
281
|
+
console.log(` ${dim("project: ")} ${opt.name}`);
|
|
282
|
+
console.log(` ${dim("version: ")} ${oldVersion} ${dim("→")} ${bold(newVersion)}`);
|
|
283
|
+
console.log(` ${dim("reviewers:")} ${(pending.reviewers ?? []).join(", ")} ${dim(pending.mode === "all" ? "(all must accept)" : "(any one can accept)")}`);
|
|
284
|
+
if (Array.isArray(pending.notNotified) && pending.notNotified.length)
|
|
285
|
+
console.log(` ${yellow("⚠ email not delivered to:")} ${pending.notNotified.join(", ")}`);
|
|
286
|
+
if (pending.expiresAt)
|
|
287
|
+
console.log(` ${dim("link valid until:")} ${new Date(pending.expiresAt).toISOString()}`);
|
|
288
|
+
if (pending.replacedPrevious)
|
|
289
|
+
console.log(` ${dim("replaced the previous pending upload — its links no longer work")}`);
|
|
290
|
+
console.log(` ${dim("elapsed: ")} ${elapsedMs}ms`);
|
|
291
|
+
console.log(line);
|
|
292
|
+
console.log("");
|
|
293
|
+
return archiveName;
|
|
294
|
+
}
|
|
277
295
|
if (emptyResponse) {
|
|
278
296
|
console.log(yellow(bold("⚠ DEPLOY LIKELY OK (server returned empty response)")));
|
|
279
297
|
}
|
|
@@ -5,7 +5,7 @@ import { UploadedFile } from "express-fileupload";
|
|
|
5
5
|
import { ValidationModel } from "../..";
|
|
6
6
|
import { IDeploymentNotifier } from "./Notifier";
|
|
7
7
|
import { IError } from "../structures/Interfaces";
|
|
8
|
-
import
|
|
8
|
+
import { IPendingReview, ReviewStore } from "./ReviewStore";
|
|
9
9
|
declare const _TSetup: {
|
|
10
10
|
readonly users: readonly [{
|
|
11
11
|
readonly login: "";
|
|
@@ -22,6 +22,16 @@ declare const _TSetup: {
|
|
|
22
22
|
readonly $__status_url_optional: true;
|
|
23
23
|
readonly allowed_ips: readonly [""];
|
|
24
24
|
readonly $__allowed_ips_optional: true;
|
|
25
|
+
readonly reviewers: readonly [{
|
|
26
|
+
readonly login: "";
|
|
27
|
+
readonly password: "";
|
|
28
|
+
readonly email: "";
|
|
29
|
+
}];
|
|
30
|
+
readonly $__reviewers_optional: true;
|
|
31
|
+
readonly review_url: "";
|
|
32
|
+
readonly $__review_url_optional: true;
|
|
33
|
+
readonly secrets_dir: "";
|
|
34
|
+
readonly $__secrets_dir_optional: true;
|
|
25
35
|
};
|
|
26
36
|
export type TDeployerSetup = ValidationModel<typeof _TSetup>;
|
|
27
37
|
export interface IDeployerServiceOptions {
|
|
@@ -80,10 +90,12 @@ export declare class DeployerService extends BaseService {
|
|
|
80
90
|
setup: TDeployerSetup | null;
|
|
81
91
|
notifier: IDeploymentNotifier | null;
|
|
82
92
|
busy: Map<string, boolean>;
|
|
93
|
+
reviews: ReviewStore;
|
|
83
94
|
private _setupWatchDebounceTimer;
|
|
84
95
|
private _lastSetupHash;
|
|
85
96
|
constructor(options: IDeployerServiceOptions);
|
|
86
97
|
init(): Promise<void>;
|
|
98
|
+
private _checkReviewSetup;
|
|
87
99
|
private _loadSetup;
|
|
88
100
|
private _reloadSetup;
|
|
89
101
|
private _watchSetup;
|
|
@@ -104,7 +116,6 @@ export declare class DeployerService extends BaseService {
|
|
|
104
116
|
};
|
|
105
117
|
data?: undefined;
|
|
106
118
|
} | {
|
|
107
|
-
error?: undefined;
|
|
108
119
|
data: {
|
|
109
120
|
ok: boolean;
|
|
110
121
|
project: string;
|
|
@@ -113,7 +124,29 @@ export declare class DeployerService extends BaseService {
|
|
|
113
124
|
active: "blue" | "green" | null;
|
|
114
125
|
activeThisDeploy: boolean;
|
|
115
126
|
};
|
|
127
|
+
error?: undefined;
|
|
128
|
+
} | {
|
|
129
|
+
error?: undefined;
|
|
130
|
+
data: {
|
|
131
|
+
ok: boolean;
|
|
132
|
+
project: string;
|
|
133
|
+
pendingReview: boolean;
|
|
134
|
+
mode: "all" | "any";
|
|
135
|
+
reviewers: string[];
|
|
136
|
+
notNotified: string[];
|
|
137
|
+
expiresAt: number;
|
|
138
|
+
replacedPrevious: boolean;
|
|
139
|
+
};
|
|
116
140
|
}>;
|
|
141
|
+
private _deploy;
|
|
142
|
+
private _reviewSetup;
|
|
143
|
+
private _queueForReview;
|
|
144
|
+
reviewDecide(project: string, sha256: string, reviewer: string, decision: "accept" | "decline", ip: string | null): Promise<{
|
|
145
|
+
pending?: IPendingReview;
|
|
146
|
+
error?: string;
|
|
147
|
+
}>;
|
|
148
|
+
private _deployApproved;
|
|
149
|
+
private _copyArchive;
|
|
117
150
|
switchSlot(data: {
|
|
118
151
|
auth?: string;
|
|
119
152
|
authLogin?: string;
|
|
@@ -192,10 +225,10 @@ export declare class DeployerService extends BaseService {
|
|
|
192
225
|
}): Promise<{
|
|
193
226
|
data?: undefined;
|
|
194
227
|
error: {
|
|
228
|
+
details?: undefined;
|
|
195
229
|
code: number;
|
|
196
230
|
message: string;
|
|
197
231
|
httpStatus: number;
|
|
198
|
-
details?: undefined;
|
|
199
232
|
};
|
|
200
233
|
} | {
|
|
201
234
|
data?: undefined;
|
|
@@ -246,21 +279,29 @@ export declare class DeployerService extends BaseService {
|
|
|
246
279
|
private _projectByToken;
|
|
247
280
|
tokensMatch(a: string | undefined, b: string | undefined): boolean;
|
|
248
281
|
static buildAllowList(entries: readonly string[] | undefined | null): {
|
|
249
|
-
list: net.BlockList | null;
|
|
282
|
+
list: import("node:net").BlockList | null;
|
|
250
283
|
error?: string;
|
|
251
284
|
};
|
|
285
|
+
isIpAllowed(ip: string | undefined): boolean;
|
|
252
286
|
private _ipAllowed;
|
|
253
287
|
private _warnPlaintextUsers;
|
|
254
288
|
static PLAINTEXT_ERROR: string;
|
|
255
289
|
private _checkUserAuth;
|
|
256
290
|
private static _extractPort;
|
|
257
291
|
private _renderNginx;
|
|
292
|
+
private static _pm2AttributesFor;
|
|
258
293
|
runPM2(found: IConfig, projectState?: IProjectState | null): Promise<IError | null>;
|
|
259
294
|
private _verifyAutorestart;
|
|
260
295
|
private static readonly SKIP_DIRS;
|
|
261
296
|
private static readonly TEMPLATE_EXTENSIONS;
|
|
262
|
-
applyConfig(dir: string, config: Record<string, string
|
|
263
|
-
|
|
297
|
+
applyConfig(dir: string, config: Record<string, string>, ctx?: {
|
|
298
|
+
secretsFile: string | null;
|
|
299
|
+
onDisk: string[];
|
|
300
|
+
}): Promise<void>;
|
|
301
|
+
processFile(filePath: string, config: Record<string, string>, ctx?: {
|
|
302
|
+
secretsFile: string | null;
|
|
303
|
+
onDisk: string[];
|
|
304
|
+
}): Promise<void>;
|
|
264
305
|
private _destinationProblem;
|
|
265
306
|
private static _unsafeArchiveEntry;
|
|
266
307
|
private static _escapingSymlink;
|