@sentinelconnector/cli 0.2.0 → 0.4.0
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 +46 -0
- package/dist/api/body.d.ts +7 -0
- package/dist/api/body.js +41 -0
- package/dist/api/body.js.map +1 -0
- package/dist/api/client.d.ts +16 -0
- package/dist/api/client.js +71 -17
- package/dist/api/client.js.map +1 -1
- package/dist/api/errors.d.ts +34 -1
- package/dist/api/errors.js +99 -2
- package/dist/api/errors.js.map +1 -1
- package/dist/auth/deviceFlow.js +4 -1
- package/dist/auth/deviceFlow.js.map +1 -1
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +31 -2
- package/dist/cli.js.map +1 -1
- package/dist/commands/deployTarget.d.ts +22 -0
- package/dist/commands/deployTarget.js +64 -0
- package/dist/commands/deployTarget.js.map +1 -0
- package/dist/commands/routes.js +21 -8
- package/dist/commands/routes.js.map +1 -1
- package/dist/commands/runSelection.d.ts +22 -0
- package/dist/commands/runSelection.js +76 -0
- package/dist/commands/runSelection.js.map +1 -0
- package/dist/journeys/runSelection.d.ts +94 -0
- package/dist/journeys/runSelection.js +192 -0
- package/dist/journeys/runSelection.js.map +1 -0
- package/dist/mcp/main.js +15 -4
- package/dist/mcp/main.js.map +1 -1
- package/dist/mcp/server.d.ts +38 -2
- package/dist/mcp/server.js +90 -10
- package/dist/mcp/server.js.map +1 -1
- package/dist/routes/routes.json +1606 -100
- package/package.json +1 -1
- package/skills/sentinel/SKILL.md +190 -3
package/README.md
CHANGED
|
@@ -50,6 +50,25 @@ days at most.
|
|
|
50
50
|
Credentials are never accepted as arguments and never printed. The keychain
|
|
51
51
|
entries and the config folder are not the admin CLI's.
|
|
52
52
|
|
|
53
|
+
### Approved addresses
|
|
54
|
+
|
|
55
|
+
When Sentinel has address approval on (`CUSTOMER_API_ALLOWLIST_ENABLED`,
|
|
56
|
+
truecms/sentinel#2966), the CLI and MCP reach an organisation only from an
|
|
57
|
+
internet address that organisation approved, after an organisation admin turned
|
|
58
|
+
API access on. Addresses are changed only in the dashboard (Settings, API
|
|
59
|
+
access (CLI and MCP)), never from the CLI.
|
|
60
|
+
|
|
61
|
+
- Cloudflare blocks any other address before Sentinel sees it. The CLI
|
|
62
|
+
recognises the block page, says the address is not approved, and sends no
|
|
63
|
+
credential again until the edge lets the request through.
|
|
64
|
+
- Sentinel itself refuses an organisation that has not approved the address
|
|
65
|
+
(403 `address_not_allowed`) or has access off (403 `api_access_off`). The
|
|
66
|
+
CLI prints the server's sentence with the address Sentinel saw.
|
|
67
|
+
- `sentinel whoami` shows the address and the organisations left out from it,
|
|
68
|
+
when the server reports them.
|
|
69
|
+
- `sentinel logout` works from any address.
|
|
70
|
+
- Exit code 10 for all of these.
|
|
71
|
+
|
|
53
72
|
## Commands
|
|
54
73
|
|
|
55
74
|
Every customer route that has a CLI policy in truecms/sentinel
|
|
@@ -97,6 +116,32 @@ was shown, so a host that changed meanwhile answers 409 `merge_checks_changed`.
|
|
|
97
116
|
The routes leave the served schema while `PATCHING_MERGE_CHECKS_ENABLED` is
|
|
98
117
|
off, and answer 404.
|
|
99
118
|
|
|
119
|
+
### Choose what a manual run updates (truecms/sentinel#2287)
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
sentinel patching candidates <site-uuid> --kind maintenance
|
|
123
|
+
sentinel sites enqueue-site-job <site-uuid> --kind maintenance \
|
|
124
|
+
--only drupal/token --only drupal/pathauto:patch --allow-major drupal/webform
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
`candidates` lists what a security or maintenance run could update: each
|
|
128
|
+
package's steps (patch, minor, a new major) and the steps held back, with the
|
|
129
|
+
reason in words.
|
|
130
|
+
|
|
131
|
+
On the run command, `--only <package>[:patch|minor]` keeps the run to that
|
|
132
|
+
package (no step: the one ticked by default), `--allow-major <package>` lets
|
|
133
|
+
it move to the new major the candidates offer (the CLI fills
|
|
134
|
+
`target_major`, and refuses a package with none), and `--no-libraries` stops
|
|
135
|
+
other Composer libraries moving. Each repeats. The CLI shows the selection
|
|
136
|
+
before asking. Without these options the run is unchanged. A 409
|
|
137
|
+
`selection_not_offered`, `selection_too_many_majors` or
|
|
138
|
+
`selection_core_major` prints the server's reason. New majors are capped per
|
|
139
|
+
run, Drupal core and distributions never take one, and Autopilot never merges
|
|
140
|
+
or deploys a run that took one.
|
|
141
|
+
|
|
142
|
+
The candidates route and `selection` answer 404 while
|
|
143
|
+
`PATCHING_RUN_SELECTION_ENABLED` is off.
|
|
144
|
+
|
|
100
145
|
| Exit code | Meaning |
|
|
101
146
|
| --- | --- |
|
|
102
147
|
| 0 | Done |
|
|
@@ -125,6 +170,7 @@ claude mcp add sentinel --env SENTINEL_TOKEN=snt_pat_… -- sentinel-mcp
|
|
|
125
170
|
| `sentinel_read` | Runs a `read` operation |
|
|
126
171
|
| `sentinel_change` | Runs a `write` operation. The first call only returns what would be sent; `confirm: true` sends it |
|
|
127
172
|
| `patching_merge_checks_read` | A site's required checks and acknowledgement state, with the dashboard link to acknowledge |
|
|
173
|
+
| `patching_run_candidates` | What a manual run on a site could update and what is held back, with how to send a `selection` through `sentinel_change` |
|
|
128
174
|
|
|
129
175
|
`mfa`, `browser` and `dashboard_only` operations are never run: the tool
|
|
130
176
|
returns the dashboard link for the person, and the agent is told never to ask
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Reading a response body with a deadline. No imports: errors.ts and http.ts both use it. */
|
|
2
|
+
/**
|
|
3
|
+
* A response body as text, given up (and the stream cancelled, which ends
|
|
4
|
+
* the request) when it takes longer than `ms` or grows past `max`
|
|
5
|
+
* characters. Undefined when given up or unreadable.
|
|
6
|
+
*/
|
|
7
|
+
export declare function readBounded(response: Response, ms: number, max?: number): Promise<string | undefined>;
|
package/dist/api/body.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** Reading a response body with a deadline. No imports: errors.ts and http.ts both use it. */
|
|
2
|
+
/**
|
|
3
|
+
* A response body as text, given up (and the stream cancelled, which ends
|
|
4
|
+
* the request) when it takes longer than `ms` or grows past `max`
|
|
5
|
+
* characters. Undefined when given up or unreadable.
|
|
6
|
+
*/
|
|
7
|
+
export async function readBounded(response, ms, max = 200_000) {
|
|
8
|
+
if (!response.body)
|
|
9
|
+
return '';
|
|
10
|
+
const reader = response.body.getReader();
|
|
11
|
+
const decoder = new TextDecoder();
|
|
12
|
+
let text = '';
|
|
13
|
+
let timer;
|
|
14
|
+
const late = new Promise((resolve) => {
|
|
15
|
+
timer = setTimeout(() => resolve('late'), ms);
|
|
16
|
+
});
|
|
17
|
+
try {
|
|
18
|
+
for (;;) {
|
|
19
|
+
const next = await Promise.race([reader.read(), late]);
|
|
20
|
+
if (next === 'late') {
|
|
21
|
+
await reader.cancel().catch(() => undefined);
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
if (next.done)
|
|
25
|
+
return text + decoder.decode();
|
|
26
|
+
text += decoder.decode(next.value, { stream: true });
|
|
27
|
+
if (text.length > max) {
|
|
28
|
+
await reader.cancel().catch(() => undefined);
|
|
29
|
+
return text.slice(0, max);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
await reader.cancel().catch(() => undefined);
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
finally {
|
|
38
|
+
clearTimeout(timer);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=body.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"body.js","sourceRoot":"","sources":["../../src/api/body.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAE9F;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,QAAkB,EAAE,EAAU,EAAE,GAAG,GAAG,OAAO;IAC7E,IAAI,CAAC,QAAQ,CAAC,IAAI;QAAE,OAAO,EAAE,CAAC;IAC9B,MAAM,MAAM,GAAG,QAAQ,CAAC,IAAI,CA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AC;QACT,YAAY,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;AACH,CAAC"}
|
package/dist/api/client.d.ts
CHANGED
|
@@ -7,6 +7,10 @@
|
|
|
7
7
|
* when SENTINEL_ENVIRONMENT or the stored sign-in names another one. A 401
|
|
8
8
|
* from a CLI sign-in renews it once and retries. Errors are SentinelApiError,
|
|
9
9
|
* never containing the credential.
|
|
10
|
+
*
|
|
11
|
+
* When Cloudflare blocks the address (an organisation has not approved it,
|
|
12
|
+
* truecms/sentinel#2966), the client sends no credential again until the
|
|
13
|
+
* credential-free environment route shows the block has lifted.
|
|
10
14
|
*/
|
|
11
15
|
import type { Credential } from '../auth/credentials.js';
|
|
12
16
|
import { type Fetch, type HttpOptions } from './http.js';
|
|
@@ -15,6 +19,10 @@ export type SentinelClientName = 'cli' | 'mcp';
|
|
|
15
19
|
export declare const MFA_TOKEN_HEADER = "X-MFA-Token";
|
|
16
20
|
export declare const WHOAMI_PATH = "/api/v1/account/cli/whoami";
|
|
17
21
|
export declare const ENVIRONMENT_PATH = "/api/v1/account/cli/environment";
|
|
22
|
+
/** How long the optional credential-free environment check may take. */
|
|
23
|
+
export declare const PROBE_TIMEOUT_MS = 5000;
|
|
24
|
+
/** Why an organisation is left out of what this credential reaches from this address. */
|
|
25
|
+
export type LeftOutReason = 'plan_feature_unavailable' | 'api_access_off' | 'address_not_allowed';
|
|
18
26
|
export interface Whoami {
|
|
19
27
|
user: {
|
|
20
28
|
id: number;
|
|
@@ -22,6 +30,14 @@ export interface Whoami {
|
|
|
22
30
|
full_name: string | null;
|
|
23
31
|
};
|
|
24
32
|
environment: string;
|
|
33
|
+
/** The address Sentinel saw this request come from (when the server reports it). */
|
|
34
|
+
address?: string | null;
|
|
35
|
+
/** The person's own organisations this credential cannot reach from here, and why. */
|
|
36
|
+
organizations_left_out?: {
|
|
37
|
+
id: number;
|
|
38
|
+
name: string;
|
|
39
|
+
reason: LeftOutReason | string;
|
|
40
|
+
}[] | null;
|
|
25
41
|
credential: {
|
|
26
42
|
kind: 'cli_session' | 'personal_token';
|
|
27
43
|
id: number;
|
package/dist/api/client.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { ENVIRONMENT_ENV } from './config.js';
|
|
2
|
-
import {
|
|
2
|
+
import { readBounded } from './body.js';
|
|
3
|
+
import { EdgeBlockedError, EnvironmentMismatchError, errorFromResponse, mayBeEdgeBlock } from './errors.js';
|
|
3
4
|
import { CLIENT_HEADER, DEFAULT_TIMEOUT_MS, send } from './http.js';
|
|
4
5
|
/** The step-up token from `POST /auth/mfa/step-up`, needed by `mfa` routes. */
|
|
5
6
|
export const MFA_TOKEN_HEADER = 'X-MFA-Token';
|
|
6
7
|
export const WHOAMI_PATH = '/api/v1/account/cli/whoami';
|
|
7
8
|
export const ENVIRONMENT_PATH = '/api/v1/account/cli/environment';
|
|
9
|
+
/** How long the optional credential-free environment check may take. */
|
|
10
|
+
export const PROBE_TIMEOUT_MS = 5_000;
|
|
8
11
|
function queryString(query) {
|
|
9
12
|
if (!query)
|
|
10
13
|
return '';
|
|
@@ -25,12 +28,29 @@ function queryString(query) {
|
|
|
25
28
|
* returns only the name.
|
|
26
29
|
*/
|
|
27
30
|
export async function environmentOf(apiUrl, http) {
|
|
31
|
+
let response;
|
|
28
32
|
try {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
response = await send(new Request(`${apiUrl}${ENVIRONMENT_PATH}`, { headers: { Accept: 'application/json' } }), http);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
// Blocked at the edge: stop here, before any credential is sent.
|
|
39
|
+
if (mayBeEdgeBlock(response)) {
|
|
40
|
+
const error = await errorFromResponse(response);
|
|
41
|
+
if (error instanceof EdgeBlockedError)
|
|
42
|
+
throw error;
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
if (!response.ok) {
|
|
46
|
+
await response.body?.cancel().catch(() => undefined);
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
// The headers came in time; the body must too, or the check is given up.
|
|
50
|
+
const text = await readBounded(response, http.timeoutMs ?? DEFAULT_TIMEOUT_MS, 10_000);
|
|
51
|
+
try {
|
|
52
|
+
const body = text === undefined ? undefined : JSON.parse(text);
|
|
53
|
+
return typeof body?.environment === 'string' ? body.environment : undefined;
|
|
34
54
|
}
|
|
35
55
|
catch {
|
|
36
56
|
return undefined;
|
|
@@ -39,8 +59,42 @@ export async function environmentOf(apiUrl, http) {
|
|
|
39
59
|
export function createSentinelClient(options) {
|
|
40
60
|
const { apiUrl, credential } = options;
|
|
41
61
|
const http = { fetch: options.fetch, timeoutMs: options.timeoutMs ?? DEFAULT_TIMEOUT_MS };
|
|
62
|
+
// The credential-free check is optional: a network that drops it must not hold every command up.
|
|
63
|
+
const probeHttp = { ...http, timeoutMs: Math.min(http.timeoutMs ?? DEFAULT_TIMEOUT_MS, PROBE_TIMEOUT_MS) };
|
|
42
64
|
const env = options.env ?? process.env;
|
|
65
|
+
// Set when Cloudflare refused this address; no credential leaves while it is.
|
|
66
|
+
let blocked;
|
|
67
|
+
// Only Sentinel's own answer (its environment name) lifts it. A failed
|
|
68
|
+
// probe, a challenge, or an error from Cloudflare or a proxy keeps it.
|
|
69
|
+
const stillBlocked = async () => {
|
|
70
|
+
if (!blocked)
|
|
71
|
+
return;
|
|
72
|
+
const named = await watch(() => environmentOf(apiUrl, probeHttp));
|
|
73
|
+
if (!named)
|
|
74
|
+
throw blocked;
|
|
75
|
+
blocked = undefined;
|
|
76
|
+
};
|
|
77
|
+
const watch = async (task) => {
|
|
78
|
+
try {
|
|
79
|
+
return await task();
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
if (error instanceof EdgeBlockedError)
|
|
83
|
+
blocked = error;
|
|
84
|
+
throw error;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const checked = async (response) => {
|
|
88
|
+
if (mayBeEdgeBlock(response)) {
|
|
89
|
+
const error = await errorFromResponse(response);
|
|
90
|
+
if (error instanceof EdgeBlockedError)
|
|
91
|
+
blocked = error;
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
return response;
|
|
95
|
+
};
|
|
43
96
|
const raw = async (method, path, request = {}) => {
|
|
97
|
+
await stillBlocked();
|
|
44
98
|
const build = async () => {
|
|
45
99
|
const headers = new Headers({ Accept: 'application/json', ...request.headers });
|
|
46
100
|
headers.set('Authorization', `Bearer ${await credential.accessToken()}`);
|
|
@@ -52,9 +106,10 @@ export function createSentinelClient(options) {
|
|
|
52
106
|
}
|
|
53
107
|
return new Request(`${apiUrl}${path}${queryString(request.query)}`, { method, headers, body });
|
|
54
108
|
};
|
|
55
|
-
const response = await send(await build
|
|
56
|
-
if (response.status === 401 && (await credential.renew()))
|
|
57
|
-
return send(await build
|
|
109
|
+
const response = await checked(await send(await watch(build), http));
|
|
110
|
+
if (response.status === 401 && (await watch(() => credential.renew()))) {
|
|
111
|
+
return checked(await send(await watch(build), http));
|
|
112
|
+
}
|
|
58
113
|
return response;
|
|
59
114
|
};
|
|
60
115
|
const expectedEnvironment = env[ENVIRONMENT_ENV]?.trim() || credential.environment;
|
|
@@ -69,14 +124,13 @@ export function createSentinelClient(options) {
|
|
|
69
124
|
let me;
|
|
70
125
|
const whoami = () => {
|
|
71
126
|
me ??= (async () => {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
127
|
+
// Before any credential leaves the machine: the server's name, asked
|
|
128
|
+
// without one. It also finds an edge block before a credential is
|
|
129
|
+
// sent, for a personal token too. A server that does not answer it is
|
|
130
|
+
// checked below, after whoami.
|
|
131
|
+
const named = await watch(() => environmentOf(apiUrl, probeHttp));
|
|
132
|
+
if (named && expectedEnvironment)
|
|
133
|
+
check(named);
|
|
80
134
|
const response = await raw('GET', WHOAMI_PATH);
|
|
81
135
|
if (!response.ok)
|
|
82
136
|
throw await errorFromResponse(response);
|
package/dist/api/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC5G,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAgC,IAAI,EAAE,MAAM,WAAW,CAAC;AAGlG,+EAA+E;AAC/E,MAAM,CAAC,MAAM,gBAAgB,GAAG,aAAa,CAAC;AAC9C,MAAM,CAAC,MAAM,WAAW,GAAG,4BAA4B,CAAC;AACxD,MAAM,CAAC,MAAM,gBAAgB,GAAG,iCAAiC,CAAC;AAClE,wEAAwE;AACxE,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,CAAC;AA+CtC,SAAS,WAAW,CAAC,KAA0C;IAC7D,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAC;IACtB,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;IACrC,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAClD,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI;YAAE,SAAS;QACpD,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;YAAE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,C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QAAQ,CAAC,IAAI,EAAE,CAAM,CAAC;YAC9D,OAAO,IAAI,UAAU,CAAC,MAAM,QAAQ,CAAC,WAAW,EAAE,CAAM,CAAC;QAC3D,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/api/errors.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/** Errors the API client raises. Messages never contain a credential. */
|
|
2
1
|
export declare class SentinelError extends Error {
|
|
3
2
|
/** Process exit code the CLI uses for this error. */
|
|
4
3
|
readonly exitCode: number;
|
|
@@ -29,6 +28,40 @@ export declare class EnvironmentMismatchError extends SentinelError {
|
|
|
29
28
|
}
|
|
30
29
|
/** Blank out anything shaped like a Sentinel credential. */
|
|
31
30
|
export declare function redact(text: string): string;
|
|
31
|
+
/** Where an organisation admin approves addresses for the CLI and MCP. */
|
|
32
|
+
export declare const API_ACCESS_SETTINGS = "Settings, API access (CLI and MCP)";
|
|
33
|
+
/** The server's refusals for an address an organisation has not approved (truecms/sentinel#2968). */
|
|
34
|
+
export declare const ADDRESS_NOT_ALLOWED = "address_not_allowed";
|
|
35
|
+
export declare const API_ACCESS_OFF = "api_access_off";
|
|
36
|
+
/** Our own code for Cloudflare's block page in front of the API: the server never saw the request. */
|
|
37
|
+
export declare const EDGE_BLOCKED = "edge_blocked";
|
|
38
|
+
/** The two refusals the server itself sends for the address. */
|
|
39
|
+
export declare const SERVER_ADDRESS_CODES: readonly string[];
|
|
40
|
+
/** Every address refusal, the edge block included. */
|
|
41
|
+
export declare const ADDRESS_CODES: readonly string[];
|
|
42
|
+
/** A public address as text, or undefined: only a real IPv4 or IPv6 address is ever repeated. */
|
|
43
|
+
export declare function addressOf(value: unknown): string | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Cloudflare blocked the request before it reached Sentinel: the API host is
|
|
46
|
+
* open only to addresses an organisation approved. The CLI sends no
|
|
47
|
+
* credential after this (see the client).
|
|
48
|
+
*/
|
|
49
|
+
export declare class EdgeBlockedError extends SentinelApiError {
|
|
50
|
+
readonly address: string | undefined;
|
|
51
|
+
constructor(address: string | undefined);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Whether an answer may be Cloudflare's own block page rather than
|
|
55
|
+
* Sentinel's: a 403 that is not JSON, passed through Cloudflare, and not a
|
|
56
|
+
* challenge (a bot check). The page itself decides (`isBlockPage`).
|
|
57
|
+
*/
|
|
58
|
+
export declare function mayBeEdgeBlock(response: Response): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Cloudflare's block page, not a page the origin sent through Cloudflare:
|
|
61
|
+
* only Cloudflare's own error pages carry its error-details block and Ray ID
|
|
62
|
+
* footer.
|
|
63
|
+
*/
|
|
64
|
+
export declare function isBlockPage(page: string): boolean;
|
|
32
65
|
/** The error a failed response stands for, from FastAPI's `{detail}` shapes. */
|
|
33
66
|
export declare function errorFromResponse(response: Response): Promise<SentinelApiError>;
|
|
34
67
|
export declare function errorFromBody(status: number, body: unknown): SentinelApiError;
|
package/dist/api/errors.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
/** Errors the API client raises. Messages never contain a credential. */
|
|
2
|
+
import { isIP } from 'node:net';
|
|
3
|
+
import { readBounded } from './body.js';
|
|
2
4
|
export class SentinelError extends Error {
|
|
3
5
|
/** Process exit code the CLI uses for this error. */
|
|
4
6
|
exitCode;
|
|
@@ -51,8 +53,74 @@ const SECRET = /snt_(?:cua|cur|pat|adm|cli|clr)_[0-9A-Za-z]{46}/g;
|
|
|
51
53
|
export function redact(text) {
|
|
52
54
|
return text.replace(SECRET, (match) => `${match.slice(0, 8)}…`);
|
|
53
55
|
}
|
|
56
|
+
/** Where an organisation admin approves addresses for the CLI and MCP. */
|
|
57
|
+
export const API_ACCESS_SETTINGS = 'Settings, API access (CLI and MCP)';
|
|
58
|
+
/** The server's refusals for an address an organisation has not approved (truecms/sentinel#2968). */
|
|
59
|
+
export const ADDRESS_NOT_ALLOWED = 'address_not_allowed';
|
|
60
|
+
export const API_ACCESS_OFF = 'api_access_off';
|
|
61
|
+
/** Our own code for Cloudflare's block page in front of the API: the server never saw the request. */
|
|
62
|
+
export const EDGE_BLOCKED = 'edge_blocked';
|
|
63
|
+
/** The two refusals the server itself sends for the address. */
|
|
64
|
+
export const SERVER_ADDRESS_CODES = [ADDRESS_NOT_ALLOWED, API_ACCESS_OFF];
|
|
65
|
+
/** Every address refusal, the edge block included. */
|
|
66
|
+
export const ADDRESS_CODES = [...SERVER_ADDRESS_CODES, EDGE_BLOCKED];
|
|
67
|
+
/** A public address as text, or undefined: only a real IPv4 or IPv6 address is ever repeated. */
|
|
68
|
+
export function addressOf(value) {
|
|
69
|
+
if (typeof value !== 'string')
|
|
70
|
+
return undefined;
|
|
71
|
+
const trimmed = value.trim();
|
|
72
|
+
return trimmed.length <= 45 && isIP(trimmed) ? trimmed : undefined;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Cloudflare blocked the request before it reached Sentinel: the API host is
|
|
76
|
+
* open only to addresses an organisation approved. The CLI sends no
|
|
77
|
+
* credential after this (see the client).
|
|
78
|
+
*/
|
|
79
|
+
export class EdgeBlockedError extends SentinelApiError {
|
|
80
|
+
address;
|
|
81
|
+
constructor(address) {
|
|
82
|
+
super(403, EDGE_BLOCKED, "Sentinel's network blocked this request before it reached Sentinel. This usually means your address" +
|
|
83
|
+
`${address ? ` (${address})` : ''} is not approved for the Sentinel CLI. An organisation admin can add it ` +
|
|
84
|
+
`under ${API_ACCESS_SETTINGS}, or connect from an approved network such as your office VPN. If the address ` +
|
|
85
|
+
'is already approved, create a support ticket with the time of this error.', address ? { address } : undefined);
|
|
86
|
+
this.address = address;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Whether an answer may be Cloudflare's own block page rather than
|
|
91
|
+
* Sentinel's: a 403 that is not JSON, passed through Cloudflare, and not a
|
|
92
|
+
* challenge (a bot check). The page itself decides (`isBlockPage`).
|
|
93
|
+
*/
|
|
94
|
+
export function mayBeEdgeBlock(response) {
|
|
95
|
+
if (response.status !== 403)
|
|
96
|
+
return false;
|
|
97
|
+
if ((response.headers.get('Content-Type') ?? '').includes('json'))
|
|
98
|
+
return false;
|
|
99
|
+
if (/challenge/i.test(response.headers.get('cf-mitigated') ?? ''))
|
|
100
|
+
return false;
|
|
101
|
+
return response.headers.has('cf-ray') || /cloudflare/i.test(response.headers.get('Server') ?? '');
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Cloudflare's block page, not a page the origin sent through Cloudflare:
|
|
105
|
+
* only Cloudflare's own error pages carry its error-details block and Ray ID
|
|
106
|
+
* footer.
|
|
107
|
+
*/
|
|
108
|
+
export function isBlockPage(page) {
|
|
109
|
+
return /cf-error-details|cf-wrapper|Cloudflare Ray ID/i.test(page) && /blocked/i.test(page);
|
|
110
|
+
}
|
|
111
|
+
/** The address Cloudflare's block page shows ("Your IP"), if it shows one. */
|
|
112
|
+
function edgeAddress(page) {
|
|
113
|
+
const match = /id=["']cf-footer-ip["'][^>]*>\s*([0-9A-Fa-f:.]{2,45})\s*</.exec(page);
|
|
114
|
+
return addressOf(match?.[1]);
|
|
115
|
+
}
|
|
116
|
+
/** How long reading a possible block page may take. */
|
|
117
|
+
const PAGE_TIMEOUT_MS = 5_000;
|
|
54
118
|
/** The error a failed response stands for, from FastAPI's `{detail}` shapes. */
|
|
55
119
|
export async function errorFromResponse(response) {
|
|
120
|
+
if (mayBeEdgeBlock(response)) {
|
|
121
|
+
const page = (await readBounded(response, PAGE_TIMEOUT_MS)) ?? '';
|
|
122
|
+
return isBlockPage(page) ? new EdgeBlockedError(edgeAddress(page)) : errorFromBody(response.status, undefined);
|
|
123
|
+
}
|
|
56
124
|
let body;
|
|
57
125
|
try {
|
|
58
126
|
body = await response.json();
|
|
@@ -62,10 +130,35 @@ export async function errorFromResponse(response) {
|
|
|
62
130
|
}
|
|
63
131
|
return errorFromBody(response.status, body);
|
|
64
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* The person-facing sentence for `address_not_allowed` and `api_access_off`:
|
|
135
|
+
* the server's own sentence when it gave one, with the address it saw added
|
|
136
|
+
* when the sentence does not already show it.
|
|
137
|
+
*/
|
|
138
|
+
function addressMessage(code, message, address) {
|
|
139
|
+
let text = message;
|
|
140
|
+
if (!text || text === code) {
|
|
141
|
+
text =
|
|
142
|
+
code === API_ACCESS_OFF
|
|
143
|
+
? `API access is turned off for this organisation. An organisation admin can turn it on under ${API_ACCESS_SETTINGS}.`
|
|
144
|
+
: `This organisation has not approved this address. An organisation admin can add it under ${API_ACCESS_SETTINGS}.`;
|
|
145
|
+
}
|
|
146
|
+
if (!text.includes(API_ACCESS_SETTINGS)) {
|
|
147
|
+
text =
|
|
148
|
+
code === API_ACCESS_OFF
|
|
149
|
+
? `${text} An organisation admin can turn it on under ${API_ACCESS_SETTINGS}.`
|
|
150
|
+
: `${text} An organisation admin can add it under ${API_ACCESS_SETTINGS}.`;
|
|
151
|
+
}
|
|
152
|
+
if (address && !text.includes(address))
|
|
153
|
+
text = `${text} Sentinel saw your address as ${address}.`;
|
|
154
|
+
return text;
|
|
155
|
+
}
|
|
65
156
|
export function errorFromBody(status, body) {
|
|
66
157
|
const detail = body && typeof body === 'object' && 'detail' in body ? body.detail : body;
|
|
67
158
|
let code;
|
|
68
159
|
let message = `HTTP ${status}`;
|
|
160
|
+
let given;
|
|
161
|
+
let address;
|
|
69
162
|
if (typeof detail === 'string') {
|
|
70
163
|
code = /^[a-z][a-z0-9_]*$/.test(detail) ? detail : undefined;
|
|
71
164
|
message = detail;
|
|
@@ -75,18 +168,22 @@ export function errorFromBody(status, body) {
|
|
|
75
168
|
if (typeof fields.code === 'string')
|
|
76
169
|
code = fields.code;
|
|
77
170
|
if (typeof fields.message === 'string')
|
|
78
|
-
message = fields.message;
|
|
171
|
+
message = given = fields.message;
|
|
79
172
|
else if (typeof fields.error_description === 'string')
|
|
80
|
-
message = fields.error_description;
|
|
173
|
+
message = given = fields.error_description;
|
|
81
174
|
if (typeof fields.error === 'string')
|
|
82
175
|
code = fields.error;
|
|
83
176
|
if (message === `HTTP ${status}` && code)
|
|
84
177
|
message = code;
|
|
178
|
+
address = addressOf(fields.address);
|
|
85
179
|
}
|
|
86
180
|
else if (Array.isArray(detail)) {
|
|
87
181
|
code = 'validation_error';
|
|
88
182
|
message = 'The request was not valid.';
|
|
89
183
|
}
|
|
184
|
+
if (code && SERVER_ADDRESS_CODES.includes(code)) {
|
|
185
|
+
message = addressMessage(code, given && printable(given), address);
|
|
186
|
+
}
|
|
90
187
|
return new SentinelApiError(status, code, printable(redact(message)), detail);
|
|
91
188
|
}
|
|
92
189
|
//# sourceMappingURL=errors.js.map
|
package/dist/api/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/api/errors.ts"],"names":[],"mappings":"AAAA,yEAAyE;
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/api/errors.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAEhC,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,MAAM,OAAO,aAAc,SAAQ,KAAK;IACtC,qDAAqD;IAC5C,QAAQ,CAAS;IAE1B,YAAY,OAAe,EAAE,QAAQ,GAAG,CAAC;QACvC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;QAC5B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF;AAED,4GAA4G;AAC5G,MAAM,OAAO,gBAAiB,SAAQ,aAAa;IACxC,MAAM,CAAS;IACxB,iFAAiF;IACxE,IAAI,CAAqB;IAClC,iFAAiF;IACxE,MAAM,CAAU;IAEzB,YAAY,MAAc,EAAE,IAAwB,EAAE,OAAe,EAAE,MAAe;QACpF,KAAK,CAAC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AC;IACrE,CAAC;IACD,OAAO,IAAI,gBAAgB,CAAC,MAAM,EAAE,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AAChF,CAAC"}
|
package/dist/auth/deviceFlow.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* OAuth 2.0 device authorization (RFC 8628) against Sentinel's customer
|
|
3
3
|
* `/api/v1/account/cli` endpoints (truecms/sentinel#1623).
|
|
4
4
|
*/
|
|
5
|
-
import { errorFromResponse, SentinelApiError, SentinelError } from '../api/errors.js';
|
|
5
|
+
import { SERVER_ADDRESS_CODES, errorFromBody, errorFromResponse, SentinelApiError, SentinelError } from '../api/errors.js';
|
|
6
6
|
import { CLIENT_HEADER, NetworkError, postJson, send } from '../api/http.js';
|
|
7
7
|
export const DEVICE_CODE_GRANT = 'urn:ietf:params:oauth:grant-type:device_code';
|
|
8
8
|
const BASE = '/api/v1/account/cli';
|
|
@@ -49,6 +49,9 @@ export async function requestToken(apiUrl, body, options = {}) {
|
|
|
49
49
|
const payload = (await response.json().catch(() => ({})));
|
|
50
50
|
// The server answers RFC 6749 errors at the top level or inside `detail`.
|
|
51
51
|
const fields = (payload.detail && typeof payload.detail === 'object' ? payload.detail : payload);
|
|
52
|
+
// Refused for the address, not the grant: the sign-in stays as it was.
|
|
53
|
+
if (typeof fields.error === 'string' && SERVER_ADDRESS_CODES.includes(fields.error))
|
|
54
|
+
throw errorFromBody(response.status, payload);
|
|
52
55
|
if (typeof fields.error === 'string') {
|
|
53
56
|
throw new GrantError(fields.error, typeof fields.error_description === 'string' ? fields.error_description : '');
|
|
54
57
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deviceFlow.js","sourceRoot":"","sources":["../../src/auth/deviceFlow.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,kBAAkB,C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AK,YAAY,UAAU,CAAC;gBAAE,MAAM,KAAK,CAAC;YAChD,IAAI,KAAK,CAAC,KAAK,KAAK,uBAAuB;gBAAE,SAAS;YACtD,IAAI,KAAK,CAAC,KAAK,KAAK,WAAW,EAAE,CAAC;gBAChC,QAAQ,IAAI,CAAC,CAAC;gBACd,KAAK,GAAG,QAAQ,CAAC;gBACjB,SAAS;YACX,CAAC;YACD,IAAI,KAAK,CAAC,KAAK,KAAK,eAAe;gBAAE,MAAM,IAAI,aAAa,CAAC,0CAA0C,EAAE,CAAC,CAAC,CAAC;YAC5G,IAAI,KAAK,CAAC,KAAK,KAAK,eAAe,EAAE,CAAC;gBACpC,MAAM,IAAI,aAAa,CAAC,uDAAuD,EAAE,CAAC,CAAC,CAAC;YACtF,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/dist/cli.d.ts
CHANGED
|
@@ -5,7 +5,10 @@
|
|
|
5
5
|
* picks another environment than production.
|
|
6
6
|
*/
|
|
7
7
|
import { Command } from 'commander';
|
|
8
|
+
import type { Whoami } from './api/client.js';
|
|
8
9
|
import { type Context } from './context.js';
|
|
9
10
|
export declare function buildProgram(context: Context): Command;
|
|
11
|
+
/** The address Sentinel saw, and the person's organisations it leaves out, when the server says. */
|
|
12
|
+
export declare function addressLines(me: Whoami): string[];
|
|
10
13
|
export declare function exitCodeFor(error: unknown): number;
|
|
11
14
|
export declare function main(argv: string[], context?: Context): Promise<number>;
|
package/dist/cli.js
CHANGED
|
@@ -6,11 +6,12 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { Command, CommanderError, Option } from 'commander';
|
|
8
8
|
import open from 'open';
|
|
9
|
-
import { printable, redact, SentinelError } from './api/errors.js';
|
|
9
|
+
import { addressOf, API_ACCESS_SETTINGS, printable, redact, SentinelError } from './api/errors.js';
|
|
10
10
|
import { NetworkError } from './api/http.js';
|
|
11
11
|
import { openStore } from './auth/store.js';
|
|
12
12
|
import { addMergeChecksCommands } from './commands/mergeChecks.js';
|
|
13
13
|
import { addApiCommand, addRouteCommands, addRoutesCommand } from './commands/routes.js';
|
|
14
|
+
import { addRunSelectionCommands } from './commands/runSelection.js';
|
|
14
15
|
import { canOpenBrowser, login, logout, rememberEmail } from './commands/session.js';
|
|
15
16
|
import { apiUrlOf, clientOf, defaultIo } from './context.js';
|
|
16
17
|
import { addSkillCommands } from './skill.js';
|
|
@@ -75,16 +76,44 @@ export function buildProgram(context) {
|
|
|
75
76
|
const kind = credential.kind === 'cli_session' ? 'CLI sign-in' : 'personal API token';
|
|
76
77
|
context.io.out(`Credential: ${kind} #${credential.id}, scopes ${credential.scopes.join(' ')}, until ${credential.expires_at}`);
|
|
77
78
|
}
|
|
79
|
+
for (const line of addressLines(me))
|
|
80
|
+
context.io.out(line);
|
|
78
81
|
});
|
|
79
82
|
addRoutesCommand(program, context);
|
|
80
83
|
addApiCommand(program, context);
|
|
81
84
|
addSkillCommands(program, context);
|
|
82
85
|
addRouteCommands(program, context);
|
|
83
86
|
const patching = program.commands.find((command) => command.name() === 'patching');
|
|
84
|
-
if (patching)
|
|
87
|
+
if (patching) {
|
|
85
88
|
addMergeChecksCommands(patching, context);
|
|
89
|
+
addRunSelectionCommands(patching, context);
|
|
90
|
+
}
|
|
86
91
|
return program;
|
|
87
92
|
}
|
|
93
|
+
const LEFT_OUT_REASONS = {
|
|
94
|
+
plan_feature_unavailable: 'the plan does not include the CLI and MCP',
|
|
95
|
+
api_access_off: 'API access is turned off',
|
|
96
|
+
address_not_allowed: 'this address is not approved',
|
|
97
|
+
};
|
|
98
|
+
/** The address Sentinel saw, and the person's organisations it leaves out, when the server says. */
|
|
99
|
+
export function addressLines(me) {
|
|
100
|
+
const lines = [];
|
|
101
|
+
const address = addressOf(me.address);
|
|
102
|
+
if (address)
|
|
103
|
+
lines.push(`Address: ${address}`);
|
|
104
|
+
const leftOut = (Array.isArray(me.organizations_left_out) ? me.organizations_left_out : []).filter((org) => Boolean(org) && typeof org === 'object');
|
|
105
|
+
if (leftOut.length === 0)
|
|
106
|
+
return lines;
|
|
107
|
+
lines.push(`Left out from this address (${leftOut.length}):`);
|
|
108
|
+
for (const org of leftOut) {
|
|
109
|
+
const reason = Object.hasOwn(LEFT_OUT_REASONS, org.reason) ? LEFT_OUT_REASONS[org.reason] : 'not reachable from the CLI';
|
|
110
|
+
lines.push(` - ${printable(String(org.name ?? ''))} (#${Number(org.id)}): ${reason}`);
|
|
111
|
+
}
|
|
112
|
+
if (leftOut.some((org) => org.reason === 'address_not_allowed' || org.reason === 'api_access_off')) {
|
|
113
|
+
lines.push(` An organisation admin can change this in the dashboard under ${API_ACCESS_SETTINGS}.`);
|
|
114
|
+
}
|
|
115
|
+
return lines;
|
|
116
|
+
}
|
|
88
117
|
export function exitCodeFor(error) {
|
|
89
118
|
if (error instanceof CommanderError) {
|
|
90
119
|
return error.code === 'commander.helpDisplayed' || error.code === 'commander.version' ? 0 : 2;
|