@fabrika/provider-cloudflare 0.8.0 → 0.8.2
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fabrika/provider-cloudflare",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -42,15 +42,15 @@
|
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"zod": "^3.25.76",
|
|
45
|
-
"@fabrika/app": "0.8.
|
|
46
|
-
"@fabrika/auth": "0.8.
|
|
47
|
-
"@fabrika/auth-core": "0.8.
|
|
48
|
-
"@fabrika/check": "0.8.
|
|
49
|
-
"@fabrika/email": "0.8.
|
|
50
|
-
"@fabrika/iam-contract": "0.8.
|
|
51
|
-
"@fabrika/installation-init": "0.8.
|
|
52
|
-
"@fabrika/proxy-core": "0.8.
|
|
53
|
-
"@fabrika/provider-contract": "0.8.
|
|
45
|
+
"@fabrika/app": "0.8.2",
|
|
46
|
+
"@fabrika/auth": "0.8.2",
|
|
47
|
+
"@fabrika/auth-core": "0.8.2",
|
|
48
|
+
"@fabrika/check": "0.8.2",
|
|
49
|
+
"@fabrika/email": "0.8.2",
|
|
50
|
+
"@fabrika/iam-contract": "0.8.2",
|
|
51
|
+
"@fabrika/installation-init": "0.8.2",
|
|
52
|
+
"@fabrika/proxy-core": "0.8.2",
|
|
53
|
+
"@fabrika/provider-contract": "0.8.2",
|
|
54
54
|
"oblaka-iac": "^0.0.18"
|
|
55
55
|
}
|
|
56
56
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { builtinEmailProviders } from '@fabrika/email/providers'
|
|
1
|
+
import { builtinEmailProviders, builtinEmailProviderVariables } from '@fabrika/email/providers'
|
|
2
2
|
import { IAM_APP_ID, IAM_APP_SCHEMA } from '@fabrika/iam-contract'
|
|
3
3
|
import type { InstallationCli, InstallationCommand } from '@fabrika/provider-contract/installation'
|
|
4
4
|
import { resolve } from 'node:path'
|
|
@@ -9,9 +9,7 @@ import { defaultReconcileSchema } from '../schema'
|
|
|
9
9
|
import { initCommand } from './init'
|
|
10
10
|
|
|
11
11
|
const EMAIL_PROVIDERS = Object.keys(builtinEmailProviders).join(', ')
|
|
12
|
-
const EMAIL_PROVIDER_VARIABLES =
|
|
13
|
-
.flatMap((provider) => provider.variables.map((variable) => variable.name))
|
|
14
|
-
.join(', ')
|
|
12
|
+
const EMAIL_PROVIDER_VARIABLES = builtinEmailProviderVariables.map((variable) => variable.name).join(', ')
|
|
15
13
|
|
|
16
14
|
const USAGE = `Cloudflare installation
|
|
17
15
|
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* base); `platform.yml` / `README.md` / `.gitignore` are CLI-owned and refreshed every run.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
+
import { builtinEmailProviders, builtinEmailProviderVariables } from '@fabrika/email/providers'
|
|
10
11
|
import {
|
|
11
12
|
INITIAL_SCAFFOLD_COMMIT_MESSAGE,
|
|
12
13
|
type ProtectionOutcome,
|
|
@@ -43,10 +44,36 @@ export interface ScaffoldResult {
|
|
|
43
44
|
branchProtection?: ProtectionOutcome
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* Render a template: replace every `{{ACCOUNT}}` token, and the mail placeholders with the built-in providers, so a
|
|
49
|
+
* provider added to the registry reaches the workflow and the README without a template edit.
|
|
50
|
+
*/
|
|
47
51
|
async function renderTemplate(name: string, account: string): Promise<string> {
|
|
48
52
|
const raw = await Bun.file(resolve(TEMPLATES, name)).text()
|
|
49
|
-
return raw
|
|
53
|
+
return raw
|
|
54
|
+
.replaceAll('{{ACCOUNT}}', () => account)
|
|
55
|
+
.replaceAll('{{EMAIL_PROVIDER_NAMES}}', () => Object.keys(builtinEmailProviders).join('|'))
|
|
56
|
+
.replaceAll(/^\{\{EMAIL_PROVIDER_VARIABLES\}\}$/gm, () => emailProviderVariablesList())
|
|
57
|
+
.replaceAll(/^( *)# \{\{EMAIL_PROVIDER_ENV\}\}$/gm, (_line, indent: string) => emailProviderEnv(indent))
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Each provider's variables, a credential from the Environment's secrets and the rest from its variables. */
|
|
61
|
+
function emailProviderEnv(indent: string): string {
|
|
62
|
+
return builtinEmailProviderVariables
|
|
63
|
+
.map((variable) => `${indent}${variable.name}: \${{ ${variable.secret ? 'secrets' : 'vars'}.${variable.name} }}`)
|
|
64
|
+
.join('\n')
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** The README's list: one line per provider, naming its variables and how each is stored. */
|
|
68
|
+
function emailProviderVariablesList(): string {
|
|
69
|
+
return Object.entries(builtinEmailProviders)
|
|
70
|
+
.map(([name, provider]) => {
|
|
71
|
+
const variables = provider.variables.map((variable) =>
|
|
72
|
+
`\`${variable.name}\` (${variable.secret ? 'secret' : 'variable'}${variable.required ? '' : ', optional'})`
|
|
73
|
+
)
|
|
74
|
+
return `- \`${name}\`: ${variables.join(', ')}`
|
|
75
|
+
})
|
|
76
|
+
.join('\n')
|
|
50
77
|
}
|
|
51
78
|
|
|
52
79
|
/** Write the file at `rel` under `dir` with `content`, creating parent dirs as needed. */
|
|
@@ -42,7 +42,7 @@ Run init with the Cloudflare API token in `CLOUDFLARE_API_TOKEN`:
|
|
|
42
42
|
```sh
|
|
43
43
|
fabrika platform init --provider=cloudflare {{ACCOUNT}} \
|
|
44
44
|
--console-host=<host> --operations-host=<host> --iam-host=<host> \
|
|
45
|
-
--auth-methods=<oidc|password|oidc,password> --email-provider=<none|
|
|
45
|
+
--auth-methods=<oidc|password|oidc,password> --email-provider=<none|{{EMAIL_PROVIDER_NAMES}}>
|
|
46
46
|
```
|
|
47
47
|
|
|
48
48
|
`fabrika platform init --provider=cloudflare --help` lists the optional flags. It creates this repo,
|
|
@@ -59,12 +59,13 @@ To close the escape hatch once IAM grants you admin, set the `{{ACCOUNT}}` Envir
|
|
|
59
59
|
IAM authentication methods are independent Environment switches: `FABRIKA_IAM_OIDC_ENABLED` and
|
|
60
60
|
`FABRIKA_IAM_PASSWORD_ENABLED`. At least one must be `true`. Password enrollment is managed through
|
|
61
61
|
IAM provisioning and its admin surface. Email delivery is optional; `FABRIKA_EMAIL_PROVIDER=none`
|
|
62
|
-
keeps password enrollment and reset admin-driven. A provider
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
keeps password enrollment and reset admin-driven. A provider also needs the sender variable
|
|
63
|
+
`FABRIKA_EMAIL_FROM` (optionally `FABRIKA_EMAIL_FROM_NAME`) and its own Environment secrets and variables:
|
|
64
|
+
|
|
65
|
+
{{EMAIL_PROVIDER_VARIABLES}}
|
|
66
|
+
|
|
67
|
+
To change or rotate them, re-run `fabrika platform init` with the new values; it rewrites this Environment
|
|
68
|
+
and triggers the workflow, which redeploys IAM.
|
|
68
69
|
|
|
69
70
|
Switching provider leaves the old provider's values stored: init writes the new ones and deletes none. IAM
|
|
70
71
|
reads only the selected provider's variables, but delete the old credentials so nothing holds them, for
|
|
@@ -140,17 +140,15 @@ jobs:
|
|
|
140
140
|
FABRIKA_IAM_OIDC_CLIENT_ID: ${{ vars.FABRIKA_IAM_OIDC_CLIENT_ID }}
|
|
141
141
|
FABRIKA_IAM_OIDC_SCOPES: ${{ vars.FABRIKA_IAM_OIDC_SCOPES }}
|
|
142
142
|
FABRIKA_IAM_OIDC_REQUIRE_VERIFIED_EMAIL: ${{ vars.FABRIKA_IAM_OIDC_REQUIRE_VERIFIED_EMAIL }}
|
|
143
|
-
# Every built-in mail provider's variables: IAM reads only the selected provider's, and an unset one is ''.
|
|
144
143
|
FABRIKA_EMAIL_PROVIDER: ${{ vars.FABRIKA_EMAIL_PROVIDER }}
|
|
145
144
|
FABRIKA_EMAIL_FROM: ${{ vars.FABRIKA_EMAIL_FROM }}
|
|
146
145
|
FABRIKA_EMAIL_FROM_NAME: ${{ vars.FABRIKA_EMAIL_FROM_NAME }}
|
|
147
|
-
FABRIKA_EMAIL_SMARTEMAILING_TAG: ${{ vars.FABRIKA_EMAIL_SMARTEMAILING_TAG }}
|
|
148
146
|
FABRIKA_IAM_SIGNING_KEYS: ${{ secrets.FABRIKA_IAM_SIGNING_KEYS }}
|
|
149
147
|
OIDC_CLIENT_SECRET: ${{ secrets.FABRIKA_IAM_OIDC_CLIENT_SECRET }}
|
|
150
|
-
FABRIKA_EMAIL_RESEND_API_KEY: ${{ secrets.FABRIKA_EMAIL_RESEND_API_KEY }}
|
|
151
|
-
FABRIKA_EMAIL_SMARTEMAILING_USERNAME: ${{ secrets.FABRIKA_EMAIL_SMARTEMAILING_USERNAME }}
|
|
152
|
-
FABRIKA_EMAIL_SMARTEMAILING_API_KEY: ${{ secrets.FABRIKA_EMAIL_SMARTEMAILING_API_KEY }}
|
|
153
148
|
FABRIKA_IAM_PROVISIONING_KEY: ${{ secrets.FABRIKA_IAM_PROVISIONING_KEY }}
|
|
149
|
+
# Every built-in mail provider's variables, written by init from the provider registry: IAM reads only the
|
|
150
|
+
# selected provider's, and an unset one is ''.
|
|
151
|
+
# {{EMAIL_PROVIDER_ENV}}
|
|
154
152
|
# `platform deploy`, not `app deploy`: IAM's own Worker is a PLATFORM resource name, and only the
|
|
155
153
|
# platform verb may name one. The single-component form deploys just this config.
|
|
156
154
|
run: fabrika platform deploy --provider=cloudflare --env=prod --component-config=fabrika.config.ts
|
package/src/proxy-worker.ts
CHANGED
|
@@ -184,10 +184,14 @@ function proxyHandler(env: CloudflareProxyEnv, manifest: ProxyManifest, verify:
|
|
|
184
184
|
const value = verification.headers.get(header)
|
|
185
185
|
if (value !== null && value !== '') upstreamHeaders.set(header, value)
|
|
186
186
|
}
|
|
187
|
-
//
|
|
188
|
-
// the
|
|
187
|
+
// A contract app never receives the caller's `px_` key (ADR-0022 rule 3): an anonymous endpoint mints no token and
|
|
188
|
+
// loses the header, a credentialed one gets the minted token in its place, and a webhook the decision marked keeps its own.
|
|
189
189
|
const forwards = verification.headers.get(FORWARD_AUTHORIZATION_HEADER) === '1'
|
|
190
|
-
|
|
190
|
+
const minted = upstreamHeaders.get(PROXY_TOKEN_HEADER)
|
|
191
|
+
if (isApplicationEntry(app) && !forwards) {
|
|
192
|
+
if (minted === null) upstreamHeaders.delete('Authorization')
|
|
193
|
+
else if (upstreamHeaders.has('Authorization')) upstreamHeaders.set('Authorization', `Bearer ${minted}`)
|
|
194
|
+
}
|
|
191
195
|
|
|
192
196
|
let answer: Response
|
|
193
197
|
try {
|