firebase-tools 15.30.0 → 15.30.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/lib/commands/ext-export.js +10 -1
- package/lib/commands/ext-migrate.js +11 -5
- package/lib/commands/ext-uninstall.js +40 -1
- package/lib/commands/functions-kits-install.js +4 -1
- package/lib/commands/functions-kits-uninstall.js +2 -1
- package/lib/deploy/functions/build.js +9 -7
- package/lib/deploy/functions/ensure.js +42 -2
- package/lib/deploy/functions/functionsDeployHelper.js +7 -0
- package/lib/deploy/functions/params.js +2 -1
- package/lib/deploy/functions/prepare.js +3 -4
- package/lib/deploy/functions/release/planner.js +2 -4
- package/lib/emulator/downloadableEmulatorInfo.json +7 -7
- package/lib/extensions/export.js +63 -1
- package/lib/extensions/migrate.js +16 -2
- package/lib/functions/env.js +21 -4
- package/lib/functions/kits/install.js +21 -6
- package/lib/gcp/iam.js +8 -17
- package/lib/tsconfig.compile.tsbuildinfo +1 -1
- package/lib/tsconfig.publish.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/templates/init/functions/typescript/tsconfig.json +2 -1
|
@@ -26,6 +26,7 @@ const config_1 = require("../config");
|
|
|
26
26
|
const projectConfig_1 = require("../functions/projectConfig");
|
|
27
27
|
const error_1 = require("../error");
|
|
28
28
|
const experiments = require("../experiments");
|
|
29
|
+
const migrate_1 = require("../extensions/migrate");
|
|
29
30
|
exports.command = new command_1.Command("ext:export")
|
|
30
31
|
.description("export Extension instances installed on a project to a local Firebase directory")
|
|
31
32
|
.option(`--mode <target>`, `experimental: controls the target system of the export (supports "extensions", "functions")`)
|
|
@@ -101,7 +102,7 @@ async function fnHandler(options) {
|
|
|
101
102
|
return;
|
|
102
103
|
}
|
|
103
104
|
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
104
|
-
|
|
105
|
+
let instance = await (0, extensionsApi_1.getInstance)(projectId, options.instance);
|
|
105
106
|
if (typeof instance === "undefined") {
|
|
106
107
|
logger_1.logger.info(`No extension matching instance ID ${options.instance} found`);
|
|
107
108
|
return;
|
|
@@ -109,6 +110,14 @@ async function fnHandler(options) {
|
|
|
109
110
|
if (instance.state !== "ACTIVE" && !options.force) {
|
|
110
111
|
throw new error_1.FirebaseError(`Extension ${options.instance} is in state ${instance.state}. To export a non-ACTIVE extension, use the --force option.`);
|
|
111
112
|
}
|
|
113
|
+
instance = await (0, extensionsHelper_1.ensureInstanceSpec)(instance);
|
|
114
|
+
if (!instance.config?.source?.spec) {
|
|
115
|
+
throw new error_1.FirebaseError(`Could not load extension specification for ${options.instance}. Unable to export configuration.`);
|
|
116
|
+
}
|
|
117
|
+
instance = await (0, migrate_1.ensureInstanceUpToDate)(projectId, instance, {
|
|
118
|
+
nonInteractive: options.nonInteractive,
|
|
119
|
+
force: options.force,
|
|
120
|
+
});
|
|
112
121
|
const instanceId = (0, utils_1.last)(instance.name.split("/")) ?? "";
|
|
113
122
|
if (instanceId !== options.instance) {
|
|
114
123
|
return;
|
|
@@ -5,6 +5,7 @@ const clc = require("colorette");
|
|
|
5
5
|
const checkMinRequiredVersion_1 = require("../checkMinRequiredVersion");
|
|
6
6
|
const command_1 = require("../command");
|
|
7
7
|
const projectUtils_1 = require("../projectUtils");
|
|
8
|
+
const experiments = require("../experiments");
|
|
8
9
|
const extensionsHelper_1 = require("../extensions/extensionsHelper");
|
|
9
10
|
const requirePermissions_1 = require("../requirePermissions");
|
|
10
11
|
const requireConfig_1 = require("../requireConfig");
|
|
@@ -23,6 +24,11 @@ exports.command = new command_1.Command("ext:migrate")
|
|
|
23
24
|
.option("--ext-instance <instanceId>", "extension instance ID to migrate")
|
|
24
25
|
.option("-e, --extension <extensionRef>", "extension reference or name to migrate")
|
|
25
26
|
.option("-f, --force", "force update and migration without prompting")
|
|
27
|
+
.before(() => {
|
|
28
|
+
experiments.assertEnabled("extMigrationFeatures", "migrate an extension instance to a function kit");
|
|
29
|
+
experiments.assertEnabled("kits", "migrate an extension instance to a function kit");
|
|
30
|
+
experiments.assertEnabled("secretEnvParams", "migrate an extension instance to a function kit");
|
|
31
|
+
})
|
|
26
32
|
.before(requireConfig_1.requireConfig)
|
|
27
33
|
.before(requirePermissions_1.requirePermissions, [
|
|
28
34
|
"firebaseextensions.instances.list",
|
|
@@ -48,14 +54,14 @@ exports.command = new command_1.Command("ext:migrate")
|
|
|
48
54
|
force: options.force,
|
|
49
55
|
});
|
|
50
56
|
(0, utils_1.logLabeledBullet)(extensionsHelper_1.logPrefix, `Selected instance ${clc.bold(plan.instanceId)} (${plan.kitPackage}) for migration.`);
|
|
51
|
-
plan.instance = await (0, migrate_1.ensureInstanceUpToDate)(projectId, plan.instance, options);
|
|
52
|
-
if (plan.instance.state !== "ACTIVE") {
|
|
53
|
-
(0, utils_1.logLabeledWarning)(extensionsHelper_1.logPrefix, `Extension instance ${clc.bold(plan.instanceId)} is in state ${plan.instance.state}. Migration may not function as expected.`);
|
|
54
|
-
}
|
|
55
57
|
plan.instance = await (0, extensionsHelper_1.ensureInstanceSpec)(plan.instance);
|
|
56
58
|
if (!plan.instance.config?.source?.spec) {
|
|
57
59
|
throw new error_1.FirebaseError(`Could not load extension specification for ${clc.bold(plan.instanceId)}. Unable to export configuration.`);
|
|
58
60
|
}
|
|
61
|
+
plan.instance = await (0, migrate_1.ensureInstanceUpToDate)(projectId, plan.instance, options);
|
|
62
|
+
if (plan.instance.state !== "ACTIVE") {
|
|
63
|
+
(0, utils_1.logLabeledWarning)(extensionsHelper_1.logPrefix, `Extension instance ${clc.bold(plan.instanceId)} is in state ${plan.instance.state}. Migration may not function as expected.`);
|
|
64
|
+
}
|
|
59
65
|
const exportedEnvs = (0, export_1.functionsEnvFromInstance)(plan.instance);
|
|
60
66
|
await (0, migrate_1.migrateSecrets)(plan.instance, { force: options.force });
|
|
61
67
|
(0, utils_1.logLabeledBullet)(extensionsHelper_1.logPrefix, `Installing kit ${clc.bold(plan.kitPackage)} for instance ${clc.bold(plan.instanceId)}...`);
|
|
@@ -89,7 +95,7 @@ exports.command = new command_1.Command("ext:migrate")
|
|
|
89
95
|
}
|
|
90
96
|
const shouldUninstall = await (0, prompt_1.confirm)({
|
|
91
97
|
message: `Functions kit ${kitInstanceId} successfully deployed. After checking function logs to verify that your backend is performing correctly, you should uninstall extension instance ${plan.instanceId}. Uninstall it now?`,
|
|
92
|
-
default:
|
|
98
|
+
default: false,
|
|
93
99
|
nonInteractive: options.nonInteractive,
|
|
94
100
|
force: options.force,
|
|
95
101
|
});
|
|
@@ -9,10 +9,14 @@ const utils_1 = require("../utils");
|
|
|
9
9
|
const manifest = require("../extensions/manifest");
|
|
10
10
|
const projectUtils_1 = require("../projectUtils");
|
|
11
11
|
const migrate_1 = require("../extensions/migrate");
|
|
12
|
+
const extensionsApi_1 = require("../extensions/extensionsApi");
|
|
13
|
+
const export_1 = require("../extensions/export");
|
|
14
|
+
const error_1 = require("../error");
|
|
15
|
+
const prompt_1 = require("../prompt");
|
|
12
16
|
exports.command = new command_1.Command("ext:uninstall <extensionInstanceId>")
|
|
13
17
|
.description("uninstall an extension that is installed in your Firebase project by instance ID")
|
|
14
18
|
.option("--local", "deprecated")
|
|
15
|
-
.option("--immediate", "immediately destroy GCP resources instead of waiting on next deploy. Can be run outside a firebase project directory.")
|
|
19
|
+
.option("--immediate", "immediately destroy GCP resources instead of waiting on next deploy. Can be run outside a firebase project directory if --project is specified.")
|
|
16
20
|
.withForce()
|
|
17
21
|
.before(requirePermissions_1.requirePermissions, ["firebaseextensions.instances.delete"])
|
|
18
22
|
.before(extensionsHelper_1.ensureExtensionsApiEnabled)
|
|
@@ -24,6 +28,41 @@ exports.command = new command_1.Command("ext:uninstall <extensionInstanceId>")
|
|
|
24
28
|
}
|
|
25
29
|
if (options.immediate) {
|
|
26
30
|
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
31
|
+
let instance;
|
|
32
|
+
try {
|
|
33
|
+
instance = await (0, extensionsApi_1.getInstance)(projectId, instanceId);
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
if (err instanceof error_1.FirebaseError && err.status === 404) {
|
|
37
|
+
(0, utils_1.logLabeledWarning)(extensionsHelper_1.logPrefix, "ext:uninstall called with --immediate, but no deployed GCP resources found for the extension.");
|
|
38
|
+
const config = manifest.loadConfig(options);
|
|
39
|
+
manifest.removeFromManifest(instanceId, config);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
throw new error_1.FirebaseError(`Failed to retrieve extension instance ${instanceId}: ${err instanceof Error ? err.message : String(err)}`, {
|
|
43
|
+
original: err instanceof Error ? err : undefined,
|
|
44
|
+
exit: 1,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
if (!instance) {
|
|
48
|
+
throw new error_1.FirebaseError(`Failed to retrieve extension instance ${instanceId}`);
|
|
49
|
+
}
|
|
50
|
+
instance = await (0, extensionsHelper_1.ensureInstanceSpec)(instance);
|
|
51
|
+
const outstandingSecrets = await (0, export_1.secretsNeedingEjection)(instance);
|
|
52
|
+
if (outstandingSecrets.length > 0) {
|
|
53
|
+
const shouldContinue = await (0, prompt_1.confirm)({
|
|
54
|
+
message: `Extension instance ${instanceId} has secrets with the "firebase-extensions-managed" label:\n${outstandingSecrets.join(", ")}\nContinuing with extension uninstall will permanently destroy these secrets.\nYou can keep these secrets by running ext:export, or by manually removing the label in the Cloud Console.\nContinue?`,
|
|
55
|
+
default: false,
|
|
56
|
+
nonInteractive: options.nonInteractive,
|
|
57
|
+
force: options.force,
|
|
58
|
+
});
|
|
59
|
+
if (!shouldContinue) {
|
|
60
|
+
if (options.nonInteractive && !options.force) {
|
|
61
|
+
throw new error_1.FirebaseError(`Extension instance ${instanceId} has managed secrets that would be permanently destroyed. Re-run with --force in non-interactive mode to confirm deletion.`);
|
|
62
|
+
}
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
27
66
|
await (0, migrate_1.uninstallExtension)(projectId, instanceId, options, false);
|
|
28
67
|
return;
|
|
29
68
|
}
|
|
@@ -9,14 +9,17 @@ const requireAuth_1 = require("../requireAuth");
|
|
|
9
9
|
const requireConfig_1 = require("../requireConfig");
|
|
10
10
|
exports.command = new command_1.Command("functions:kits:install")
|
|
11
11
|
.description("install a function kit into your project")
|
|
12
|
+
.before(() => {
|
|
13
|
+
experiments.assertEnabled("kits", "install a function kit");
|
|
14
|
+
})
|
|
12
15
|
.before(requireConfig_1.requireConfig)
|
|
13
16
|
.before(requireAuth_1.requireAuth)
|
|
17
|
+
.withForce()
|
|
14
18
|
.option("--package <package>", "NPM package name or specifier to install as a function kit")
|
|
15
19
|
.option("--directory <directory>", "path to a local functions codebase directory to install as a function kit")
|
|
16
20
|
.option(`--template <template>`, `template to use for the kit index file (${Object.keys(install_1.TEMPLATES).join("|")})`)
|
|
17
21
|
.option("--no-configure", "skip parameter prompting and configuration during installation")
|
|
18
22
|
.action(async (options) => {
|
|
19
|
-
experiments.assertEnabled("kits", "install a function kit");
|
|
20
23
|
if (!options.config) {
|
|
21
24
|
throw new error_1.FirebaseError("Not in a Firebase project directory (firebase.json not found).");
|
|
22
25
|
}
|
|
@@ -14,11 +14,12 @@ const utils_1 = require("../utils");
|
|
|
14
14
|
const logger_1 = require("../logger");
|
|
15
15
|
const delete_1 = require("../deploy/functions/delete");
|
|
16
16
|
exports.command = new command_1.Command("functions:kits:uninstall")
|
|
17
|
-
.description("uninstall a function kit or kit instance from your project")
|
|
17
|
+
.description("uninstall a function kit or kit instance from your project. Deletes all running resources and the associated managed service account.")
|
|
18
18
|
.before(requireConfig_1.requireConfig)
|
|
19
19
|
.before(requireAuth_1.requireAuth)
|
|
20
20
|
.option("--kit <kitId>", "")
|
|
21
21
|
.option("--instance <instanceId>", "")
|
|
22
|
+
.withForce()
|
|
22
23
|
.action(async (options) => {
|
|
23
24
|
const firebaseConfig = options.config;
|
|
24
25
|
if (options.instance && options.kit) {
|
|
@@ -82,7 +82,15 @@ exports.AllIngressSettings = [
|
|
|
82
82
|
"ALLOW_INTERNAL_AND_GCLB",
|
|
83
83
|
];
|
|
84
84
|
async function resolveBackend(opts) {
|
|
85
|
-
const { paramValues: paramValues, secretRefs: secretRefs } = await params.resolveParams(
|
|
85
|
+
const { paramValues: paramValues, secretRefs: secretRefs } = await params.resolveParams({
|
|
86
|
+
params: opts.build.params,
|
|
87
|
+
firebaseConfig: opts.firebaseConfig,
|
|
88
|
+
userEnvs: envWithTypes(opts.build.params, opts.userEnvs),
|
|
89
|
+
codebase: opts.codebase,
|
|
90
|
+
nonInteractive: opts.nonInteractive,
|
|
91
|
+
force: opts.force,
|
|
92
|
+
isEmulator: opts.isEmulator,
|
|
93
|
+
});
|
|
86
94
|
return { backend: toBackend(opts.build, paramValues), envs: paramValues, secretRefs: secretRefs };
|
|
87
95
|
}
|
|
88
96
|
function envWithTypes(definedParams, rawEnvs) {
|
|
@@ -392,12 +400,6 @@ function applyPrefix(build, prefix) {
|
|
|
392
400
|
throw new error_1.FirebaseError(`Function id '${newId}' is invalid after applying prefix '${prefix}'. Function names must start with a letter and can contain letters, numbers, underscores, and hyphens, with a maximum length of 63 characters.`);
|
|
393
401
|
}
|
|
394
402
|
newEndpoints[newId] = endpoint;
|
|
395
|
-
if (endpoint.secretEnvironmentVariables) {
|
|
396
|
-
endpoint.secretEnvironmentVariables = endpoint.secretEnvironmentVariables.map((secret) => ({
|
|
397
|
-
...secret,
|
|
398
|
-
secret: `${prefix}-${secret.secret}`,
|
|
399
|
-
}));
|
|
400
|
-
}
|
|
401
403
|
}
|
|
402
404
|
build.endpoints = newEndpoints;
|
|
403
405
|
if (build.lifecycleHooks) {
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.REQUIRED_SECURITY_APIS = void 0;
|
|
3
4
|
exports.defaultServiceAccount = defaultServiceAccount;
|
|
4
5
|
exports.cloudBuildEnabled = cloudBuildEnabled;
|
|
5
6
|
exports.secretsAccessDelta = secretsAccessDelta;
|
|
6
7
|
exports.checkSecretAccess = checkSecretAccess;
|
|
7
8
|
exports.grantSecretAccess = grantSecretAccess;
|
|
9
|
+
exports.checkDeclarativeSecurityApisEnabled = checkDeclarativeSecurityApisEnabled;
|
|
8
10
|
const clc = require("colorette");
|
|
9
|
-
const
|
|
11
|
+
const ensureApiEnabled = require("../../ensureApiEnabled");
|
|
10
12
|
const error_1 = require("../../error");
|
|
11
13
|
const utils_1 = require("../../utils");
|
|
12
14
|
const secretManager_1 = require("../../gcp/secretManager");
|
|
@@ -15,6 +17,7 @@ const functional_1 = require("../../functional");
|
|
|
15
17
|
const api_1 = require("../../api");
|
|
16
18
|
const backend = require("./backend");
|
|
17
19
|
const computeEngine_1 = require("../../gcp/computeEngine");
|
|
20
|
+
const logger_1 = require("../../logger");
|
|
18
21
|
const FAQ_URL = "https://firebase.google.com/support/faq#functions-runtime";
|
|
19
22
|
const metadataCallCache = new Map();
|
|
20
23
|
async function defaultServiceAccount(e) {
|
|
@@ -57,7 +60,7 @@ function isPermissionError(e) {
|
|
|
57
60
|
}
|
|
58
61
|
async function cloudBuildEnabled(projectId) {
|
|
59
62
|
try {
|
|
60
|
-
await
|
|
63
|
+
await ensureApiEnabled.ensure(projectId, (0, api_1.cloudbuildOrigin)(), "functions");
|
|
61
64
|
}
|
|
62
65
|
catch (e) {
|
|
63
66
|
if ((0, error_1.isBillingError)(e)) {
|
|
@@ -119,3 +122,40 @@ async function grantSecretAccess(args) {
|
|
|
119
122
|
await (0, secretManager_1.ensureServiceAgentRole)({ name: secret, projectId }, serviceAccounts, "roles/secretmanager.secretAccessor");
|
|
120
123
|
(0, utils_1.logLabeledSuccess)("functions", `ensured ${clc.bold(serviceAccounts.join(", "))} access to ${clc.bold(secret)}.`);
|
|
121
124
|
}
|
|
125
|
+
exports.REQUIRED_SECURITY_APIS = [
|
|
126
|
+
"iam.googleapis.com",
|
|
127
|
+
"cloudresourcemanager.googleapis.com",
|
|
128
|
+
];
|
|
129
|
+
async function checkDeclarativeSecurityApisEnabled(projectId, codebase) {
|
|
130
|
+
const checks = await Promise.all(exports.REQUIRED_SECURITY_APIS.map(async (api) => {
|
|
131
|
+
try {
|
|
132
|
+
return await ensureApiEnabled.check(projectId, api, "functions", true);
|
|
133
|
+
}
|
|
134
|
+
catch (err) {
|
|
135
|
+
const isPermissionDenied = err?.status === 403 ||
|
|
136
|
+
isPermissionError(err);
|
|
137
|
+
if (isPermissionDenied) {
|
|
138
|
+
logger_1.logger.debug(`Silencing permission error checking enablement for API ${api}:`, err);
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
throw err;
|
|
142
|
+
}
|
|
143
|
+
}));
|
|
144
|
+
const disabledApis = exports.REQUIRED_SECURITY_APIS.filter((_, idx) => !checks[idx]);
|
|
145
|
+
if (disabledApis.length > 0) {
|
|
146
|
+
const apiBulletList = disabledApis.map((api) => ` - ${clc.bold(api)}`).join("\n");
|
|
147
|
+
const enableCmd = clc.bold(`gcloud services enable ${disabledApis.join(" ")} --project ${projectId}`);
|
|
148
|
+
const consoleLinks = disabledApis
|
|
149
|
+
.map((api) => ` - ${api}: ${ensureApiEnabled.enableApiURI(projectId, api)}`)
|
|
150
|
+
.join("\n");
|
|
151
|
+
throw new error_1.FirebaseError(`Cannot deploy functions with declarative security in codebase "${codebase}". ` +
|
|
152
|
+
`The following required Google Cloud API(s) are not enabled on project ${clc.bold(projectId)}:\n` +
|
|
153
|
+
apiBulletList +
|
|
154
|
+
`\n\nDeclarative security requires these APIs to provision and configure managed service accounts and IAM roles.\n` +
|
|
155
|
+
`To enable them, run:\n\n` +
|
|
156
|
+
` ${enableCmd}\n\n` +
|
|
157
|
+
`Or ask a project owner to enable them in the Google Cloud Console:\n` +
|
|
158
|
+
consoleLinks +
|
|
159
|
+
`\n`, { exit: 1 });
|
|
160
|
+
}
|
|
161
|
+
}
|
|
@@ -11,6 +11,7 @@ exports.targetCodebases = targetCodebases;
|
|
|
11
11
|
exports.groupEndpointsByCodebase = groupEndpointsByCodebase;
|
|
12
12
|
exports.isCodebaseFiltered = isCodebaseFiltered;
|
|
13
13
|
exports.isEndpointFiltered = isEndpointFiltered;
|
|
14
|
+
exports.isCodebasePartiallyFiltered = isCodebasePartiallyFiltered;
|
|
14
15
|
exports.parseDeleteFilters = parseDeleteFilters;
|
|
15
16
|
exports.detectCodebaseAndIdCollisions = detectCodebaseAndIdCollisions;
|
|
16
17
|
const backend = require("./backend");
|
|
@@ -140,6 +141,12 @@ function isCodebaseFiltered(codebase, filters) {
|
|
|
140
141
|
function isEndpointFiltered(endpoint, filters) {
|
|
141
142
|
return filters.some((filter) => endpointMatchesFilter(endpoint, filter));
|
|
142
143
|
}
|
|
144
|
+
function isCodebasePartiallyFiltered(codebase, filters) {
|
|
145
|
+
if (!filters) {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
return filters.some((f) => (!f.codebase || f.codebase === codebase) && !!f.idChunks && f.idChunks.length > 0);
|
|
149
|
+
}
|
|
143
150
|
function parseDeleteFilters(filters, activeCodebases) {
|
|
144
151
|
const liveCodebasesConfig = activeCodebases.map((codebase) => ({ source: "", codebase }));
|
|
145
152
|
return filters.flatMap((f) => {
|
|
@@ -163,7 +163,8 @@ function canSatisfyParam(param, value) {
|
|
|
163
163
|
}
|
|
164
164
|
(0, functional_1.assertExhaustive)(param);
|
|
165
165
|
}
|
|
166
|
-
async function resolveParams(
|
|
166
|
+
async function resolveParams(opts) {
|
|
167
|
+
const { params, firebaseConfig, userEnvs, codebase, nonInteractive = false, force = false, isEmulator = false, } = opts;
|
|
167
168
|
const paramValues = populateDefaultParams(firebaseConfig);
|
|
168
169
|
const secretRefs = {};
|
|
169
170
|
const [resolved, outstanding] = (0, functional_1.partition)(params, (param) => {
|
|
@@ -57,8 +57,7 @@ async function discoverSecurityDetails(codebase, want, have, projectId, filters)
|
|
|
57
57
|
const requiredRoles = want.requiredRoles;
|
|
58
58
|
const existingManagedSA = backend.findEndpoint(have, (e) => typeof e.serviceAccount === "string" && e.serviceAccount.startsWith("firebase-fn-"))?.serviceAccount ?? undefined;
|
|
59
59
|
const haveRolesEtag = backend.findEndpoint(have, (e) => !!e.labels?.[exports.DECLARATIVE_SECURITY_ETAG_LABEL])?.labels?.[exports.DECLARATIVE_SECURITY_ETAG_LABEL];
|
|
60
|
-
const isPartiallyFiltered =
|
|
61
|
-
filters.some((f) => (!f.codebase || f.codebase === codebase) && f.idChunks && f.idChunks.length > 0));
|
|
60
|
+
const isPartiallyFiltered = (0, functionsDeployHelper_1.isCodebasePartiallyFiltered)(codebase, filters);
|
|
62
61
|
const isEnrolling = !!requiredRoles && !existingManagedSA;
|
|
63
62
|
const isUnenrolling = !requiredRoles && !!existingManagedSA && !!haveRolesEtag;
|
|
64
63
|
if (isPartiallyFiltered && (isEnrolling || isUnenrolling)) {
|
|
@@ -95,13 +94,13 @@ async function discoverSecurityDetails(codebase, want, have, projectId, filters)
|
|
|
95
94
|
existingManagedSA,
|
|
96
95
|
};
|
|
97
96
|
}
|
|
97
|
+
await ensure.checkDeclarativeSecurityApisEnabled(projectId, codebase);
|
|
98
98
|
let managedSA = existingManagedSA;
|
|
99
99
|
if (!managedSA) {
|
|
100
100
|
const saToCreate = await iam.generateManagedServiceAccountName(projectId, "firebase-fn");
|
|
101
101
|
managedSA = `${saToCreate}@${projectId}.iam.gserviceaccount.com`;
|
|
102
102
|
}
|
|
103
|
-
const
|
|
104
|
-
const newEtag = iam.computeRolesEtag(requiredRoles, existingSalt);
|
|
103
|
+
const newEtag = iam.computeRolesEtag(requiredRoles);
|
|
105
104
|
for (const endpoint of backend.allEndpoints(want)) {
|
|
106
105
|
endpoint.serviceAccount = managedSA;
|
|
107
106
|
endpoint.labels = endpoint.labels || {};
|
|
@@ -84,9 +84,7 @@ async function createDeploymentPlan(args) {
|
|
|
84
84
|
let rolesToRemove;
|
|
85
85
|
let serviceAccountToCreate;
|
|
86
86
|
let serviceAccountToDelete;
|
|
87
|
-
const
|
|
88
|
-
filters.some((f) => f.idChunks && f.idChunks.length > 0) &&
|
|
89
|
-
!deleteAll);
|
|
87
|
+
const isPartiallyFiltered = (0, functionsDeployHelper_1.isCodebasePartiallyFiltered)(codebase, filters);
|
|
90
88
|
const hasWantEndpoints = backend.someEndpoint(wantBackend, () => true);
|
|
91
89
|
if (requiredRoles && hasWantEndpoints) {
|
|
92
90
|
rolesToAdd = requiredRoles.filter((r) => !roles.includes(r));
|
|
@@ -95,7 +93,7 @@ async function createDeploymentPlan(args) {
|
|
|
95
93
|
serviceAccountToCreate = managedSA;
|
|
96
94
|
}
|
|
97
95
|
}
|
|
98
|
-
else if (existingManagedSA && !
|
|
96
|
+
else if (existingManagedSA && (!isPartiallyFiltered || deleteAll)) {
|
|
99
97
|
serviceAccountToDelete = existingManagedSA;
|
|
100
98
|
}
|
|
101
99
|
wantBackend = backend.matchingBackend(wantBackend, (endpoint) => {
|
|
@@ -44,13 +44,13 @@
|
|
|
44
44
|
}
|
|
45
45
|
},
|
|
46
46
|
"pubsub": {
|
|
47
|
-
"version": "0.8.
|
|
48
|
-
"expectedSize":
|
|
49
|
-
"expectedChecksum": "
|
|
50
|
-
"expectedChecksumSHA256": "
|
|
51
|
-
"remoteUrl": "https://storage.googleapis.com/firebase-preview-drop/emulator/pubsub-emulator-0.8.
|
|
52
|
-
"downloadPathRelativeToCacheDir": "pubsub-emulator-0.8.
|
|
53
|
-
"binaryPathRelativeToCacheDir": "pubsub-emulator-0.8.
|
|
47
|
+
"version": "0.8.36",
|
|
48
|
+
"expectedSize": 53026271,
|
|
49
|
+
"expectedChecksum": "f62d997f52619f4800f34f42136178ef",
|
|
50
|
+
"expectedChecksumSHA256": "0b3a030b3a92aba50082aeed7ee63008a45b032b7231090d3a1bcd8744e0e2e5",
|
|
51
|
+
"remoteUrl": "https://storage.googleapis.com/firebase-preview-drop/emulator/pubsub-emulator-0.8.36.zip",
|
|
52
|
+
"downloadPathRelativeToCacheDir": "pubsub-emulator-0.8.36.zip",
|
|
53
|
+
"binaryPathRelativeToCacheDir": "pubsub-emulator-0.8.36/pubsub-emulator/bin/cloud-pubsub-emulator"
|
|
54
54
|
},
|
|
55
55
|
"dataconnect": {
|
|
56
56
|
"darwin": {
|
package/lib/extensions/export.js
CHANGED
|
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.parameterizeProject = parameterizeProject;
|
|
4
4
|
exports.setSecretParamsToLatest = setSecretParamsToLatest;
|
|
5
5
|
exports.displayExportInfo = displayExportInfo;
|
|
6
|
+
exports.memoryToMb = memoryToMb;
|
|
7
|
+
exports.parseMemory = parseMemory;
|
|
8
|
+
exports.resolveMigratedMemory = resolveMigratedMemory;
|
|
6
9
|
exports.functionsEnvFromInstance = functionsEnvFromInstance;
|
|
7
10
|
exports.secretsNeedingEjection = secretsNeedingEjection;
|
|
8
11
|
exports.ejectSecretsFromInstance = ejectSecretsFromInstance;
|
|
@@ -66,6 +69,58 @@ function displaySpecs(specs) {
|
|
|
66
69
|
logger_1.logger.info("");
|
|
67
70
|
}
|
|
68
71
|
}
|
|
72
|
+
const GIB_REGEX = /^\d+(?:\.\d+)?(?:Gi|GiB|G|GB)$/i;
|
|
73
|
+
const MIB_REGEX = /^\d+(?:\.\d+)?(?:Mi|MiB|M|MB)?$/i;
|
|
74
|
+
function memoryToMb(memory) {
|
|
75
|
+
if (!memory) {
|
|
76
|
+
return 0;
|
|
77
|
+
}
|
|
78
|
+
const trimmed = memory.trim();
|
|
79
|
+
if (GIB_REGEX.test(trimmed)) {
|
|
80
|
+
return Math.round(parseFloat(trimmed) * 1024);
|
|
81
|
+
}
|
|
82
|
+
if (MIB_REGEX.test(trimmed)) {
|
|
83
|
+
const parsed = parseFloat(trimmed);
|
|
84
|
+
return isNaN(parsed) || parsed < 0 ? 0 : parsed;
|
|
85
|
+
}
|
|
86
|
+
return 0;
|
|
87
|
+
}
|
|
88
|
+
const MB_TO_MEMORY_OPTION = {
|
|
89
|
+
128: "128MiB",
|
|
90
|
+
256: "256MiB",
|
|
91
|
+
512: "512MiB",
|
|
92
|
+
1024: "1GiB",
|
|
93
|
+
2048: "2GiB",
|
|
94
|
+
4096: "4GiB",
|
|
95
|
+
8192: "8GiB",
|
|
96
|
+
16384: "16GiB",
|
|
97
|
+
32768: "32GiB",
|
|
98
|
+
};
|
|
99
|
+
function parseMemory(raw) {
|
|
100
|
+
if (!raw) {
|
|
101
|
+
return undefined;
|
|
102
|
+
}
|
|
103
|
+
const mb = memoryToMb(raw);
|
|
104
|
+
return MB_TO_MEMORY_OPTION[mb];
|
|
105
|
+
}
|
|
106
|
+
const V1_MEMORY_PARAM = "firebaseextensions.v1beta.function/memory";
|
|
107
|
+
const V2_MEMORY_PARAM = "firebaseextensions.v1beta.v2function/memory";
|
|
108
|
+
const MEMORY_PARAMS = new Set([V1_MEMORY_PARAM, V2_MEMORY_PARAM]);
|
|
109
|
+
function resolveMigratedMemory(liveSystemParams = {}, specSystemParams = []) {
|
|
110
|
+
const getParam = (paramName) => {
|
|
111
|
+
if (paramName in liveSystemParams) {
|
|
112
|
+
return liveSystemParams[paramName];
|
|
113
|
+
}
|
|
114
|
+
const defaultVal = specSystemParams.find((p) => p.param === paramName)?.default;
|
|
115
|
+
return defaultVal !== undefined ? String(defaultVal) : undefined;
|
|
116
|
+
};
|
|
117
|
+
const v1 = getParam(V1_MEMORY_PARAM);
|
|
118
|
+
const v2 = getParam(V2_MEMORY_PARAM);
|
|
119
|
+
if (v1 && v2) {
|
|
120
|
+
return memoryToMb(v1) > memoryToMb(v2) ? v1 : v2;
|
|
121
|
+
}
|
|
122
|
+
return v2 ?? v1;
|
|
123
|
+
}
|
|
69
124
|
function functionsEnvFromInstance(instance) {
|
|
70
125
|
const liveParams = instance.config?.params || {};
|
|
71
126
|
const liveSystemParams = instance.config?.systemParams || {};
|
|
@@ -85,6 +140,9 @@ function functionsEnvFromInstance(instance) {
|
|
|
85
140
|
}
|
|
86
141
|
});
|
|
87
142
|
for (const [sysParamName, sysParamValue] of Object.entries(liveSystemParams)) {
|
|
143
|
+
if (MEMORY_PARAMS.has(sysParamName)) {
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
88
146
|
let renamed = sysParamName
|
|
89
147
|
.replace(/^firebaseextensions\.v1beta\.(v2)?function\//, "EXT_MIGRATED_SYSTEM_")
|
|
90
148
|
.toUpperCase();
|
|
@@ -94,7 +152,7 @@ function functionsEnvFromInstance(instance) {
|
|
|
94
152
|
envs[renamed] = sysParamValue;
|
|
95
153
|
}
|
|
96
154
|
for (const specSystemParam of specSystemParams) {
|
|
97
|
-
if (specSystemParam.param in liveSystemParams) {
|
|
155
|
+
if (specSystemParam.param in liveSystemParams || MEMORY_PARAMS.has(specSystemParam.param)) {
|
|
98
156
|
continue;
|
|
99
157
|
}
|
|
100
158
|
if ("default" in specSystemParam) {
|
|
@@ -107,6 +165,10 @@ function functionsEnvFromInstance(instance) {
|
|
|
107
165
|
envs[renamed] = String(specSystemParam.default ?? "");
|
|
108
166
|
}
|
|
109
167
|
}
|
|
168
|
+
const memory = resolveMigratedMemory(liveSystemParams, specSystemParams);
|
|
169
|
+
if (memory) {
|
|
170
|
+
envs["EXT_MIGRATED_SYSTEM_MEMORY"] = parseMemory(memory) ?? memory;
|
|
171
|
+
}
|
|
110
172
|
if (typeof instance.config.allowedEventTypes !== "undefined") {
|
|
111
173
|
envs["EXT_SELECTED_EVENTS"] = instance.config.allowedEventTypes.toString();
|
|
112
174
|
}
|
|
@@ -222,7 +222,11 @@ async function ensureInstanceUpToDate(projectId, instance, options) {
|
|
|
222
222
|
try {
|
|
223
223
|
const parsed = refs.parse(rawRef);
|
|
224
224
|
baseRef = refs.toExtensionRef(parsed);
|
|
225
|
-
currentVersion =
|
|
225
|
+
currentVersion =
|
|
226
|
+
parsed.version ||
|
|
227
|
+
instance.config?.source?.spec?.version ||
|
|
228
|
+
instance.config?.extensionVersion ||
|
|
229
|
+
instance.extensionVersion;
|
|
226
230
|
}
|
|
227
231
|
catch (err) {
|
|
228
232
|
logger_1.logger.debug(`[ensureInstanceUpToDate] Could not parse extension reference '${rawRef}':`, err);
|
|
@@ -245,6 +249,16 @@ async function ensureInstanceUpToDate(projectId, instance, options) {
|
|
|
245
249
|
if (!latestVersion || currentVersion === latestVersion) {
|
|
246
250
|
return instance;
|
|
247
251
|
}
|
|
252
|
+
const shouldUpgrade = await (0, prompt_1.confirm)({
|
|
253
|
+
message: `Extension instance ${clc.bold(instanceId)} is on version ${clc.bold(currentVersion)}, but the latest version is ${clc.bold(latestVersion)}. An upgrade is strongly recommended before migrating to avoid breaking changes. Upgrade it now?`,
|
|
254
|
+
default: true,
|
|
255
|
+
nonInteractive: options?.nonInteractive,
|
|
256
|
+
force: options?.force,
|
|
257
|
+
});
|
|
258
|
+
if (!shouldUpgrade) {
|
|
259
|
+
(0, utils_1.logLabeledWarning)(extensionsHelper_1.logPrefix, `Continuing migration with extension instance ${clc.bold(instanceId)} on outdated version ${clc.bold(currentVersion)}.`);
|
|
260
|
+
return instance;
|
|
261
|
+
}
|
|
248
262
|
(0, utils_1.logLabeledBullet)(extensionsHelper_1.logPrefix, `Upgrading extension instance ${clc.bold(instanceId)} from version ${clc.bold(currentVersion)} to ${clc.bold(latestVersion)} to ensure a smooth migration...`);
|
|
249
263
|
const targetRef = `${baseRef}@${latestVersion}`;
|
|
250
264
|
let finalParams = {
|
|
@@ -290,7 +304,7 @@ async function ensureInstanceUpToDate(projectId, instance, options) {
|
|
|
290
304
|
throw new error_1.FirebaseError(`Failed to automatically upgrade extension instance ${instanceId} to version ${latestVersion}: ${message}. Please upgrade your extension instance manually using 'firebase ext:update ${instanceId}' before attempting migration.`, { original: err instanceof Error ? err : undefined });
|
|
291
305
|
}
|
|
292
306
|
const updatedInstance = await extensionsApi.getInstance(projectId, instanceId);
|
|
293
|
-
return updatedInstance
|
|
307
|
+
return updatedInstance ? await (0, extensionsHelper_1.ensureInstanceSpec)(updatedInstance) : instance;
|
|
294
308
|
}
|
|
295
309
|
async function migrateSecrets(instance, options) {
|
|
296
310
|
const secrets = await (0, export_1.secretsNeedingEjection)(instance);
|
package/lib/functions/env.js
CHANGED
|
@@ -127,12 +127,29 @@ function validateKey(key) {
|
|
|
127
127
|
if (keyConflictsWithReservedPrefixes(key)) {
|
|
128
128
|
throw new KeyValidationError(key, `Key ${key} starts with a reserved prefix (${RESERVED_PREFIXES.join(" ")})`);
|
|
129
129
|
}
|
|
130
|
-
if (RESERVED_PREFIX_ALLOWLIST.some((prefix) => key === prefix)) {
|
|
131
|
-
throw new KeyValidationError(key, `Key ${key} is a known prefix with an empty suffix`);
|
|
132
|
-
}
|
|
133
130
|
}
|
|
134
131
|
function keyConflictsWithReservedPrefixes(key) {
|
|
135
|
-
|
|
132
|
+
if (!RESERVED_PREFIXES.some((prefix) => key.startsWith(prefix))) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
for (const allowedPrefix of RESERVED_PREFIX_ALLOWLIST) {
|
|
136
|
+
if (keyPermittedByKnownPrefix(key, allowedPrefix)) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
function keyPermittedByKnownPrefix(key, prefix) {
|
|
143
|
+
if (!key.startsWith(prefix)) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
if (prefix.endsWith("_") && key === prefix) {
|
|
147
|
+
throw new KeyValidationError(key, `Key ${key} is a known prefix that requires a suffix`);
|
|
148
|
+
}
|
|
149
|
+
if (!prefix.endsWith("_") && key !== prefix) {
|
|
150
|
+
throw new KeyValidationError(key, `Key ${key} conflicts with known key ${prefix} that does not permit a suffix`);
|
|
151
|
+
}
|
|
152
|
+
return true;
|
|
136
153
|
}
|
|
137
154
|
function parseStrict(data) {
|
|
138
155
|
const { envs, errors } = parse(data);
|
|
@@ -235,7 +235,8 @@ async function promptKitId(packageName, existingKitIds, nonInteractive, customKi
|
|
|
235
235
|
}
|
|
236
236
|
return kitId;
|
|
237
237
|
}
|
|
238
|
-
async function promptSecurityConfirmation(
|
|
238
|
+
async function promptSecurityConfirmation(options) {
|
|
239
|
+
const { rawPkgName, packageName, nonInteractive, force } = options;
|
|
239
240
|
const isThirdParty = isThirdPartyPackage(packageName);
|
|
240
241
|
if (isThirdParty) {
|
|
241
242
|
(0, utils_1.logLabeledWarning)("functions", `Package ${clc.bold(packageName)} is a third-party kit (outside the @firebase-function-kits scope).`);
|
|
@@ -259,6 +260,7 @@ async function promptSecurityConfirmation(rawPkgName, packageName, nonInteractiv
|
|
|
259
260
|
message: confirmMessage,
|
|
260
261
|
default: false,
|
|
261
262
|
nonInteractive,
|
|
263
|
+
force,
|
|
262
264
|
});
|
|
263
265
|
if (!confirmInstallation) {
|
|
264
266
|
throw new error_1.FirebaseError("Installation cancelled.");
|
|
@@ -589,7 +591,8 @@ async function discoverKitBuild(options, absSourcePath) {
|
|
|
589
591
|
runtime: supported.latest("nodejs"),
|
|
590
592
|
};
|
|
591
593
|
const runtimeDelegate = await runtimes.getRuntimeDelegate(delegateContext);
|
|
592
|
-
|
|
594
|
+
const firebaseEnvs = functionsEnv.loadFirebaseEnvs({ projectId }, projectId, options.instanceId);
|
|
595
|
+
return runtimeDelegate.discoverBuild({}, firebaseEnvs);
|
|
593
596
|
}
|
|
594
597
|
async function promptAndWriteKitParams(options) {
|
|
595
598
|
if (!options.params || options.params.length === 0) {
|
|
@@ -616,7 +619,14 @@ async function promptAndWriteKitParams(options) {
|
|
|
616
619
|
logger_1.logger.debug(`Could not fetch Firebase config for project ${options.projectId}: ${(0, error_1.getErrMsg)(err)}`);
|
|
617
620
|
}
|
|
618
621
|
const typedUserEnvs = build.envWithTypes(options.params, userEnvs);
|
|
619
|
-
const { paramValues: resolvedEnvs, secretRefs: resolvedSecretRefs } = await params.resolveParams(
|
|
622
|
+
const { paramValues: resolvedEnvs, secretRefs: resolvedSecretRefs } = await params.resolveParams({
|
|
623
|
+
params: options.params,
|
|
624
|
+
firebaseConfig: firebaseConfig,
|
|
625
|
+
userEnvs: typedUserEnvs,
|
|
626
|
+
codebase: options.instanceId,
|
|
627
|
+
nonInteractive: options.nonInteractive,
|
|
628
|
+
force: options.force,
|
|
629
|
+
});
|
|
620
630
|
functionsEnv.writeResolvedParams(resolvedEnvs, userEnvs, userEnvOpt);
|
|
621
631
|
if (experiments.isEnabled("secretEnvParams")) {
|
|
622
632
|
functionsEnv.writeResolvedSecretRefs(resolvedSecretRefs, secretRefs, userEnvOpt);
|
|
@@ -769,7 +779,7 @@ async function addKitInstanceOrConfigureProject(options, existingKit, existingFu
|
|
|
769
779
|
const shouldConfigure = options.configure !== false;
|
|
770
780
|
if (shouldConfigure) {
|
|
771
781
|
try {
|
|
772
|
-
discoveredBuild = await discoverKitBuild(options, absSourcePath);
|
|
782
|
+
discoveredBuild = await discoverKitBuild({ ...options, instanceId }, absSourcePath);
|
|
773
783
|
}
|
|
774
784
|
catch (err) {
|
|
775
785
|
logger_1.logger.debug(`Could not discover kit build for params prompting: ${(0, error_1.getErrMsg)(err)}`);
|
|
@@ -840,7 +850,12 @@ async function resolvePackageSource(options) {
|
|
|
840
850
|
}
|
|
841
851
|
validateNpmPackageName(rawPkgName);
|
|
842
852
|
const { packageName } = parseNpmPackageSpecifier(rawPkgName);
|
|
843
|
-
const isThirdParty = await promptSecurityConfirmation(
|
|
853
|
+
const isThirdParty = await promptSecurityConfirmation({
|
|
854
|
+
rawPkgName,
|
|
855
|
+
packageName,
|
|
856
|
+
nonInteractive: options.nonInteractive,
|
|
857
|
+
force: options.force,
|
|
858
|
+
});
|
|
844
859
|
return {
|
|
845
860
|
defaultKitName: packageName,
|
|
846
861
|
sourcePackageName: packageName,
|
|
@@ -915,7 +930,7 @@ async function installKitOrInstance(options) {
|
|
|
915
930
|
const shouldConfigure = options.configure !== false;
|
|
916
931
|
if (shouldConfigure) {
|
|
917
932
|
try {
|
|
918
|
-
discoveredBuild = await discoverKitBuild(options, absSourcePath);
|
|
933
|
+
discoveredBuild = await discoverKitBuild({ ...options, instanceId }, absSourcePath);
|
|
919
934
|
}
|
|
920
935
|
catch (err) {
|
|
921
936
|
logger_1.logger.debug(`Could not discover kit build for params prompting: ${(0, error_1.getErrMsg)(err)}`);
|