@crombolo/server 0.69.0 → 0.69.1
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/package.json +14 -14
- package/src/config.ts +2 -2
- package/src/host-token.ts +30 -1
- package/src/server.ts +23 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/server",
|
|
3
|
-
"version": "0.69.
|
|
3
|
+
"version": "0.69.1",
|
|
4
4
|
"description": "Internal to crombolo, with no compatibility promise: use @crombolo/crombolo. The crombolo HTTP server: routing, configuration, media stores and background jobs.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Crombolo",
|
|
@@ -32,19 +32,19 @@
|
|
|
32
32
|
"access": "public"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@crombolo/api-delivery": "0.69.
|
|
36
|
-
"@crombolo/api-management": "0.69.
|
|
37
|
-
"@crombolo/auth": "0.69.
|
|
38
|
-
"@crombolo/backoffice-host": "0.69.
|
|
39
|
-
"@crombolo/common": "0.69.
|
|
40
|
-
"@crombolo/content": "0.69.
|
|
41
|
-
"@crombolo/contracts": "0.69.
|
|
42
|
-
"@crombolo/core": "0.69.
|
|
43
|
-
"@crombolo/data": "0.69.
|
|
44
|
-
"@crombolo/extension": "0.69.
|
|
45
|
-
"@crombolo/render": "0.69.
|
|
46
|
-
"@crombolo/schema": "0.69.
|
|
47
|
-
"@crombolo/transfer": "0.69.
|
|
35
|
+
"@crombolo/api-delivery": "0.69.1",
|
|
36
|
+
"@crombolo/api-management": "0.69.1",
|
|
37
|
+
"@crombolo/auth": "0.69.1",
|
|
38
|
+
"@crombolo/backoffice-host": "0.69.1",
|
|
39
|
+
"@crombolo/common": "0.69.1",
|
|
40
|
+
"@crombolo/content": "0.69.1",
|
|
41
|
+
"@crombolo/contracts": "0.69.1",
|
|
42
|
+
"@crombolo/core": "0.69.1",
|
|
43
|
+
"@crombolo/data": "0.69.1",
|
|
44
|
+
"@crombolo/extension": "0.69.1",
|
|
45
|
+
"@crombolo/render": "0.69.1",
|
|
46
|
+
"@crombolo/schema": "0.69.1",
|
|
47
|
+
"@crombolo/transfer": "0.69.1",
|
|
48
48
|
"@logtape/logtape": "^2.3.8",
|
|
49
49
|
"@opentelemetry/api": "1.10.0",
|
|
50
50
|
"@opentelemetry/context-async-hooks": "3.0.0",
|
package/src/config.ts
CHANGED
|
@@ -1200,7 +1200,7 @@ export function loadConfig(
|
|
|
1200
1200
|
'webhooks.allowPrivateAddresses is now CROMBOLO_ALLOW_PRIVATE_ADDRESSES (allowPrivateAddresses in the config), which covers forms and identity providers too (story 304).',
|
|
1201
1201
|
)
|
|
1202
1202
|
checkApiClient(merged.apiClient)
|
|
1203
|
-
checkHost(merged.host)
|
|
1203
|
+
checkHost(merged.host, merged.backofficeIdentityProviders, merged.lockedIdentityProviders)
|
|
1204
1204
|
// The key itself is refused, so a config left over from before says so rather
|
|
1205
1205
|
// than starting without the feature it asked for.
|
|
1206
1206
|
if ('assistant' in overrides)
|
|
@@ -1314,7 +1314,7 @@ export function describeDatabase(
|
|
|
1314
1314
|
}
|
|
1315
1315
|
}
|
|
1316
1316
|
|
|
1317
|
-
export const VERSION = '0.69.
|
|
1317
|
+
export const VERSION = '0.69.1'
|
|
1318
1318
|
|
|
1319
1319
|
/** A whole number of seconds from the environment; undefined when unset or not one. */
|
|
1320
1320
|
/** A positive number from a setting, else the default. */
|
package/src/host-token.ts
CHANGED
|
@@ -5,6 +5,11 @@
|
|
|
5
5
|
* docs/bundles.md, "Tools a host provides".
|
|
6
6
|
*/
|
|
7
7
|
import { SignJWT } from 'jose'
|
|
8
|
+
import {
|
|
9
|
+
type IdentityProvider,
|
|
10
|
+
type LockedIdentityProviders,
|
|
11
|
+
lockOf,
|
|
12
|
+
} from './identity-providers.ts'
|
|
8
13
|
|
|
9
14
|
/** The installation's host, from `crombolo.config.ts` only. */
|
|
10
15
|
export interface HostConfig {
|
|
@@ -14,13 +19,23 @@ export interface HostConfig {
|
|
|
14
19
|
signingKey: string
|
|
15
20
|
/** Names the key in each token's header, for a host running many installations. */
|
|
16
21
|
keyId: string
|
|
22
|
+
/**
|
|
23
|
+
* The back-office identity provider the host signs people in through (story
|
|
24
|
+
* 372): each token names the person's subject there, as `host_sub` and
|
|
25
|
+
* `host_iss`. It must be locked, so nobody can point it at another issuer.
|
|
26
|
+
*/
|
|
27
|
+
provider?: string
|
|
17
28
|
}
|
|
18
29
|
|
|
19
30
|
/** How long a token lasts, in seconds. */
|
|
20
31
|
export const HOST_TOKEN_SECONDS = 300
|
|
21
32
|
|
|
22
33
|
/** Refuses a `host` that could not be used, naming the field. */
|
|
23
|
-
export function checkHost(
|
|
34
|
+
export function checkHost(
|
|
35
|
+
host: HostConfig | undefined,
|
|
36
|
+
providers: readonly IdentityProvider[] = [],
|
|
37
|
+
locked: LockedIdentityProviders = [],
|
|
38
|
+
): void {
|
|
24
39
|
if (!host) return
|
|
25
40
|
let url: URL | undefined
|
|
26
41
|
try {
|
|
@@ -37,6 +52,17 @@ export function checkHost(host: HostConfig | undefined): void {
|
|
|
37
52
|
throw new Error('host.signingKey must be at least 32 bytes.')
|
|
38
53
|
if (typeof host.keyId !== 'string' || host.keyId.trim() === '')
|
|
39
54
|
throw new Error('host.keyId must name the key.')
|
|
55
|
+
if (host.provider === undefined) return
|
|
56
|
+
const provider = providers.find((p) => p.oidc.id === host.provider)
|
|
57
|
+
if (!provider)
|
|
58
|
+
throw new Error(
|
|
59
|
+
`host.provider is "${host.provider}", which is not one of the back-office identity providers the config declares.`,
|
|
60
|
+
)
|
|
61
|
+
// Story 372: an unlocked provider could be re-pointed at an issuer an administrator controls.
|
|
62
|
+
if (!lockOf(provider, locked))
|
|
63
|
+
throw new Error(
|
|
64
|
+
`host.provider names ${provider.oidc.name}, which must be locked: set locked: true on it, so nobody can point it at another issuer.`,
|
|
65
|
+
)
|
|
40
66
|
}
|
|
41
67
|
|
|
42
68
|
/** Who the token is about, and which site says so. */
|
|
@@ -45,6 +71,8 @@ export interface HostTokenSubject {
|
|
|
45
71
|
groups: readonly string[]
|
|
46
72
|
sections: readonly string[]
|
|
47
73
|
site: { name: string; nodeId: string; url?: string }
|
|
74
|
+
/** Who the person is at the host's provider (story 372), when their link recorded it. */
|
|
75
|
+
host?: { sub: string; iss: string }
|
|
48
76
|
}
|
|
49
77
|
|
|
50
78
|
export async function issueHostToken(
|
|
@@ -58,6 +86,7 @@ export async function issueHostToken(
|
|
|
58
86
|
groups: [...subject.groups],
|
|
59
87
|
sections: [...subject.sections],
|
|
60
88
|
site: { name: subject.site.name, nodeId: subject.site.nodeId },
|
|
89
|
+
...(subject.host ? { host_sub: subject.host.sub, host_iss: subject.host.iss } : {}),
|
|
61
90
|
})
|
|
62
91
|
.setProtectedHeader({ alg: 'HS256', kid: host.keyId, typ: 'JWT' })
|
|
63
92
|
.setSubject(subject.user.key)
|
package/src/server.ts
CHANGED
|
@@ -92,8 +92,10 @@ import {
|
|
|
92
92
|
byActor,
|
|
93
93
|
currentAuditContext,
|
|
94
94
|
type Db,
|
|
95
|
+
ExternalLoginRepository,
|
|
95
96
|
ensureFormLibraryTypes,
|
|
96
97
|
ensureKeyValue,
|
|
98
|
+
externalLoginProvider,
|
|
97
99
|
FormEntryRepository,
|
|
98
100
|
FormWorkflowRepository,
|
|
99
101
|
FormWorkflowSecretRepository,
|
|
@@ -1946,6 +1948,26 @@ export async function createServer(
|
|
|
1946
1948
|
})
|
|
1947
1949
|
}
|
|
1948
1950
|
|
|
1951
|
+
/**
|
|
1952
|
+
* Story 372: who the person is at the host's own provider, as their last
|
|
1953
|
+
* sign-in through it recorded, and only from that provider's issuer.
|
|
1954
|
+
*/
|
|
1955
|
+
async function hostIdentityOf(userKey: string): Promise<{ host?: { sub: string; iss: string } }> {
|
|
1956
|
+
const id = config.host?.provider
|
|
1957
|
+
const provider = id
|
|
1958
|
+
? config.backofficeIdentityProviders.find((p) => p.oidc.id === id)
|
|
1959
|
+
: undefined
|
|
1960
|
+
if (!provider) return {}
|
|
1961
|
+
const issuer = provider.oidc.issuer
|
|
1962
|
+
const link = (await new ExternalLoginRepository(db).forOwner(userKey)).find(
|
|
1963
|
+
(l) => l.loginProvider === externalLoginProvider('user', provider.oidc.id),
|
|
1964
|
+
)
|
|
1965
|
+
const identity = link?.identity
|
|
1966
|
+
return identity && identity.issuer === issuer
|
|
1967
|
+
? { host: { sub: identity.value, iss: issuer } }
|
|
1968
|
+
: {}
|
|
1969
|
+
}
|
|
1970
|
+
|
|
1949
1971
|
/** Story 368: a preview link for a page its person may read, audited as them. */
|
|
1950
1972
|
async function askForPreviewLink(request: Request): Promise<Response> {
|
|
1951
1973
|
if (request.method !== 'POST') return new Response(null, { status: 405 })
|
|
@@ -2748,6 +2770,7 @@ export async function createServer(
|
|
|
2748
2770
|
nodeId: schema.nodeId,
|
|
2749
2771
|
url: config.applicationUrl || undefined,
|
|
2750
2772
|
},
|
|
2773
|
+
...(await hostIdentityOf(principal.id)),
|
|
2751
2774
|
})
|
|
2752
2775
|
log.info('Issued a host token to {user} for {host}', {
|
|
2753
2776
|
user: principal.email,
|