firebase-tools 15.24.0 → 15.25.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/api.js +4 -2
- package/lib/appcheck/api.js +42 -0
- package/lib/appcheck/prompts.js +41 -0
- package/lib/appcheck/types.js +2 -0
- package/lib/command.js +11 -3
- package/lib/commands/ailogic-config-get.js +75 -0
- package/lib/commands/ailogic-config-set.js +109 -0
- package/lib/commands/ailogic-providers-disable.js +39 -0
- package/lib/commands/ailogic-providers-enable.js +28 -0
- package/lib/commands/ailogic-providers-list.js +29 -0
- package/lib/commands/appcheck-debugtokens-create.js +95 -0
- package/lib/commands/appcheck-debugtokens-delete.js +48 -0
- package/lib/commands/appcheck-debugtokens-list.js +35 -0
- package/lib/commands/apps-sdkconfig.js +2 -23
- package/lib/commands/database-get.js +1 -1
- package/lib/commands/index.js +15 -0
- package/lib/deploy/functions/build.js +93 -3
- package/lib/deploy/functions/functionsDeployHelper.js +18 -12
- package/lib/deploy/functions/params.js +45 -11
- package/lib/deploy/functions/prepare.js +38 -5
- package/lib/deploy/functions/release/executor.js +51 -8
- package/lib/deploy/functions/release/fabricator.js +34 -5
- package/lib/deploy/functions/runtimes/node/index.js +8 -7
- package/lib/deploy/functions/runtimes/node/versioning.js +8 -3
- package/lib/deploy/functions/validate.js +5 -2
- package/lib/deploy/hosting/uploader.js +2 -1
- package/lib/emulator/controller.js +34 -15
- package/lib/emulator/dataconnect/pgliteServer.js +2 -1
- package/lib/emulator/downloadableEmulatorInfo.json +6 -6
- package/lib/emulator/downloadableEmulators.js +1 -0
- package/lib/emulator/hubExport.js +2 -1
- package/lib/emulator/storage/apis/firebase.js +24 -5
- package/lib/emulator/storage/apis/gcloud.js +16 -6
- package/lib/emulator/storage/rules/runtime.js +45 -33
- package/lib/emulator/storage/server.js +2 -5
- package/lib/emulator/storage/upload.js +1 -0
- package/lib/ensureApiEnabled.js +8 -0
- package/lib/experiments.js +22 -0
- package/lib/extensions/warnings.js +64 -0
- package/lib/functions/env.js +22 -2
- package/lib/functions/projectConfig.js +98 -12
- package/lib/functions/secrets.js +4 -1
- package/lib/gcp/ailogic.js +165 -1
- package/lib/gcp/cloudfunctionsv2.js +7 -0
- package/lib/gcp/firedata.js +5 -1
- package/lib/gcp/serviceusage.js +26 -0
- package/lib/init/features/ailogic/index.js +3 -29
- package/lib/init/features/database.js +1 -1
- package/lib/management/apps.js +16 -5
- package/lib/mcp/onemcp/onemcp_server.js +28 -9
- package/lib/mcp/tools/core/get_security_rules.js +2 -1
- package/lib/profiler.js +1 -1
- package/lib/serve/functions.js +25 -7
- package/lib/streamUtils.js +3 -0
- package/lib/tsconfig.compile.tsbuildinfo +1 -1
- package/lib/tsconfig.publish.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/schema/firebase-config.json +93 -0
|
@@ -11,27 +11,6 @@ const error_1 = require("../error");
|
|
|
11
11
|
const requireAuth_1 = require("../requireAuth");
|
|
12
12
|
const logger_1 = require("../logger");
|
|
13
13
|
const prompt_1 = require("../prompt");
|
|
14
|
-
function checkForApps(apps, appPlatform) {
|
|
15
|
-
if (!apps.length) {
|
|
16
|
-
throw new error_1.FirebaseError(`There are no ${appPlatform === apps_1.AppPlatform.ANY ? "" : appPlatform + " "}apps ` +
|
|
17
|
-
"associated with this Firebase project");
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
async function selectAppInteractively(apps, appPlatform) {
|
|
21
|
-
checkForApps(apps, appPlatform);
|
|
22
|
-
const choices = apps.map((app) => {
|
|
23
|
-
return {
|
|
24
|
-
name: `${app.displayName || app.bundleId || app.packageName}` +
|
|
25
|
-
` - ${app.appId} (${app.platform})`,
|
|
26
|
-
value: app,
|
|
27
|
-
};
|
|
28
|
-
});
|
|
29
|
-
return await (0, prompt_1.select)({
|
|
30
|
-
message: `Select the ${appPlatform === apps_1.AppPlatform.ANY ? "" : appPlatform + " "}` +
|
|
31
|
-
"app to get the configuration data:",
|
|
32
|
-
choices,
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
14
|
exports.command = new command_1.Command("apps:sdkconfig [platform] [appId]")
|
|
36
15
|
.description("print the Google Services config of a Firebase app. " +
|
|
37
16
|
"[platform] can be IOS, ANDROID or WEB (case insensitive)")
|
|
@@ -49,7 +28,7 @@ exports.command = new command_1.Command("apps:sdkconfig [platform] [appId]")
|
|
|
49
28
|
projectId = result.projectId;
|
|
50
29
|
}
|
|
51
30
|
const apps = await (0, apps_1.listFirebaseApps)(projectId, appPlatform);
|
|
52
|
-
checkForApps(apps, appPlatform);
|
|
31
|
+
(0, apps_1.checkForApps)(apps, appPlatform);
|
|
53
32
|
if (apps.length === 1) {
|
|
54
33
|
appId = apps[0].appId;
|
|
55
34
|
appPlatform = apps[0].platform;
|
|
@@ -58,7 +37,7 @@ exports.command = new command_1.Command("apps:sdkconfig [platform] [appId]")
|
|
|
58
37
|
throw new error_1.FirebaseError(`Project ${projectId} has multiple apps, must specify an app id.`);
|
|
59
38
|
}
|
|
60
39
|
else {
|
|
61
|
-
const appMetadata = await selectAppInteractively(apps, appPlatform);
|
|
40
|
+
const appMetadata = await (0, apps_1.selectAppInteractively)(apps, appPlatform);
|
|
62
41
|
appId = appMetadata.appId;
|
|
63
42
|
appPlatform = appMetadata.platform;
|
|
64
43
|
}
|
|
@@ -91,7 +91,7 @@ exports.command = new command_1.Command("database:get <path>")
|
|
|
91
91
|
const fileOut = !!options.output;
|
|
92
92
|
const outStream = fileOut ? fs.createWriteStream(options.output) : process.stdout;
|
|
93
93
|
if (res.status >= 400) {
|
|
94
|
-
const r = await res.
|
|
94
|
+
const r = await utils.streamToString(res.body);
|
|
95
95
|
let d;
|
|
96
96
|
try {
|
|
97
97
|
d = JSON.parse(r);
|
package/lib/commands/index.js
CHANGED
|
@@ -19,6 +19,11 @@ function load(client) {
|
|
|
19
19
|
return runner;
|
|
20
20
|
}
|
|
21
21
|
const t0 = process.hrtime.bigint();
|
|
22
|
+
client.appcheck = {};
|
|
23
|
+
client.appcheck.debugtokens = {};
|
|
24
|
+
client.appcheck.debugtokens.create = loadCommand("appcheck-debugtokens-create");
|
|
25
|
+
client.appcheck.debugtokens.list = loadCommand("appcheck-debugtokens-list");
|
|
26
|
+
client.appcheck.debugtokens.delete = loadCommand("appcheck-debugtokens-delete");
|
|
22
27
|
client.appdistribution = {};
|
|
23
28
|
client.appdistribution.distribute = loadCommand("appdistribution-distribute");
|
|
24
29
|
client.appdistribution.testers = {};
|
|
@@ -214,6 +219,16 @@ function load(client) {
|
|
|
214
219
|
client.apphosting.rollouts.list = loadCommand("apphosting-rollouts-list");
|
|
215
220
|
}
|
|
216
221
|
}
|
|
222
|
+
if (experiments.isEnabled("ailogic")) {
|
|
223
|
+
client.ailogic = {};
|
|
224
|
+
client.ailogic.providers = {};
|
|
225
|
+
client.ailogic.providers.enable = loadCommand("ailogic-providers-enable");
|
|
226
|
+
client.ailogic.providers.disable = loadCommand("ailogic-providers-disable");
|
|
227
|
+
client.ailogic.providers.list = loadCommand("ailogic-providers-list");
|
|
228
|
+
client.ailogic.config = {};
|
|
229
|
+
client.ailogic.config.get = loadCommand("ailogic-config-get");
|
|
230
|
+
client.ailogic.config.set = loadCommand("ailogic-config-set");
|
|
231
|
+
}
|
|
217
232
|
client.login = loadCommand("login");
|
|
218
233
|
client.login.add = loadCommand("login-add");
|
|
219
234
|
client.login.ci = loadCommand("login-ci");
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AllIngressSettings = exports.AllVpcEgressSettings = exports.AllFunctionsPlatforms = exports.REGION_TBD = void 0;
|
|
3
|
+
exports.AllIngressSettings = exports.AllVpcEgressSettings = exports.AllFunctionsPlatforms = exports.SECRET_REF_LONG_RE = exports.SECRET_REF_SHORT_RE = exports.GCP_SECRET_ID_PATTERN = exports.SECRET_REF_PREFIX = exports.REGION_TBD = void 0;
|
|
4
4
|
exports.empty = empty;
|
|
5
5
|
exports.of = of;
|
|
6
6
|
exports.isHttpsTriggered = isHttpsTriggered;
|
|
@@ -14,13 +14,32 @@ exports.resolveBackend = resolveBackend;
|
|
|
14
14
|
exports.envWithTypes = envWithTypes;
|
|
15
15
|
exports.toBackend = toBackend;
|
|
16
16
|
exports.applyPrefix = applyPrefix;
|
|
17
|
+
exports.applyEnvSecretBindings = applyEnvSecretBindings;
|
|
18
|
+
exports.parseSecretRef = parseSecretRef;
|
|
17
19
|
const backend = require("./backend");
|
|
18
20
|
const proto = require("../../gcp/proto");
|
|
19
21
|
const params = require("./params");
|
|
22
|
+
const logger_1 = require("../../logger");
|
|
20
23
|
const error_1 = require("../../error");
|
|
21
24
|
const functional_1 = require("../../functional");
|
|
22
25
|
const cel_1 = require("./cel");
|
|
23
26
|
exports.REGION_TBD = "REGION_TBD";
|
|
27
|
+
exports.SECRET_REF_PREFIX = "FIREBASE_SECRET_REF_";
|
|
28
|
+
const GCP_PROJECT_ID_PATTERN = "([a-z][-a-z0-9]{4,28}[a-z0-9])";
|
|
29
|
+
exports.GCP_SECRET_ID_PATTERN = "([a-zA-Z0-9-_]+)";
|
|
30
|
+
exports.SECRET_REF_SHORT_RE = new RegExp("^" +
|
|
31
|
+
exports.GCP_SECRET_ID_PATTERN +
|
|
32
|
+
"(?:[:#@]" +
|
|
33
|
+
"([a-z0-9-_]+)" +
|
|
34
|
+
")?$");
|
|
35
|
+
exports.SECRET_REF_LONG_RE = new RegExp("^" +
|
|
36
|
+
"projects/" +
|
|
37
|
+
GCP_PROJECT_ID_PATTERN +
|
|
38
|
+
"/secrets/" +
|
|
39
|
+
exports.GCP_SECRET_ID_PATTERN +
|
|
40
|
+
"(?:(?:/versions/|:|#|@)" +
|
|
41
|
+
"([a-z0-9-_]+)" +
|
|
42
|
+
")?$");
|
|
24
43
|
function empty() {
|
|
25
44
|
return {
|
|
26
45
|
requiredAPIs: [],
|
|
@@ -63,8 +82,8 @@ exports.AllIngressSettings = [
|
|
|
63
82
|
"ALLOW_INTERNAL_AND_GCLB",
|
|
64
83
|
];
|
|
65
84
|
async function resolveBackend(opts) {
|
|
66
|
-
const paramValues = await params.resolveParams(opts.build.params, opts.firebaseConfig, envWithTypes(opts.build.params, opts.userEnvs), opts.nonInteractive, opts.isEmulator);
|
|
67
|
-
return { backend: toBackend(opts.build, paramValues), envs: paramValues };
|
|
85
|
+
const { paramValues: paramValues, secretRefs: secretRefs } = await params.resolveParams(opts.build.params, opts.firebaseConfig, envWithTypes(opts.build.params, opts.userEnvs), opts.nonInteractive, opts.force, opts.isEmulator);
|
|
86
|
+
return { backend: toBackend(opts.build, paramValues), envs: paramValues, secretRefs: secretRefs };
|
|
68
87
|
}
|
|
69
88
|
function envWithTypes(definedParams, rawEnvs) {
|
|
70
89
|
const out = {};
|
|
@@ -404,3 +423,74 @@ function applyPrefix(build, prefix) {
|
|
|
404
423
|
}
|
|
405
424
|
}
|
|
406
425
|
}
|
|
426
|
+
function applyEnvSecretBindings(build, envSecrets) {
|
|
427
|
+
if (envSecrets.empty) {
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
logger_1.logger.debug(`Attempting to merge .env secret bindings ${JSON.stringify(envSecrets)} into declared secrets...)}`);
|
|
431
|
+
for (const endpointName of Object.keys(build.endpoints)) {
|
|
432
|
+
logger_1.logger.debug(`${endpointName} declared secrets: ${JSON.stringify(build.endpoints[endpointName].secretEnvironmentVariables)}`);
|
|
433
|
+
}
|
|
434
|
+
for (const key of Object.keys(envSecrets)) {
|
|
435
|
+
const secretRef = envSecrets[key];
|
|
436
|
+
const { projectId, secretId, version } = secretRef;
|
|
437
|
+
for (const param of build.params) {
|
|
438
|
+
if (param.type === "secret" && param.name.toUpperCase() === key) {
|
|
439
|
+
param.resourceId = secretId;
|
|
440
|
+
param.version = version;
|
|
441
|
+
param.inLocalEnvironment = true;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
for (const endpointName of Object.keys(build.endpoints)) {
|
|
445
|
+
const endpoint = build.endpoints[endpointName];
|
|
446
|
+
if (projectId && projectId !== endpoint.project) {
|
|
447
|
+
throw new error_1.FirebaseError(`Secret binding ${key} referenced unsupported cross-project secret in '${projectId}'`);
|
|
448
|
+
}
|
|
449
|
+
let notFound = true;
|
|
450
|
+
for (const envVar of endpoint.secretEnvironmentVariables ?? []) {
|
|
451
|
+
if (envVar.key === key) {
|
|
452
|
+
notFound = false;
|
|
453
|
+
envVar.secret = secretId;
|
|
454
|
+
if (typeof secretRef.version !== "undefined") {
|
|
455
|
+
envVar.version = version;
|
|
456
|
+
envVar.allowVersionPinning = true;
|
|
457
|
+
}
|
|
458
|
+
logger_1.logger.debug(`Merged secret: ${JSON.stringify(envVar)}`);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
if (notFound) {
|
|
462
|
+
logger_1.logger.warn(`.env files contain a secret binding ${key} which has not been configured as a secret param via defineSecret().`);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
function parseSecretRef(ref) {
|
|
468
|
+
const shortMatch = exports.SECRET_REF_SHORT_RE.exec(ref);
|
|
469
|
+
if (shortMatch) {
|
|
470
|
+
const output = {
|
|
471
|
+
secretId: shortMatch[1],
|
|
472
|
+
};
|
|
473
|
+
if (shortMatch[2] !== undefined) {
|
|
474
|
+
output.version = shortMatch[2];
|
|
475
|
+
if (ref.includes("#") || ref.includes("@")) {
|
|
476
|
+
throw new error_1.FirebaseError(`Malformed secret binding '${ref}'; secret versions are specified with ':'`);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
return output;
|
|
480
|
+
}
|
|
481
|
+
const longMatch = exports.SECRET_REF_LONG_RE.exec(ref);
|
|
482
|
+
if (longMatch) {
|
|
483
|
+
const output = {
|
|
484
|
+
projectId: longMatch[1],
|
|
485
|
+
secretId: longMatch[2],
|
|
486
|
+
};
|
|
487
|
+
if (longMatch[3] !== undefined) {
|
|
488
|
+
output.version = longMatch[3];
|
|
489
|
+
if (ref.includes("#") || ref.includes("@")) {
|
|
490
|
+
throw new error_1.FirebaseError(`Malformed secret binding '${ref}'; secret versions are specified with ':'`);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
return output;
|
|
494
|
+
}
|
|
495
|
+
throw new error_1.FirebaseError(`Unknown format for secret binding '${ref}'`);
|
|
496
|
+
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.endpointMatchesAnyFilter = endpointMatchesAnyFilter;
|
|
4
4
|
exports.endpointMatchesFilter = endpointMatchesFilter;
|
|
5
|
+
exports.getCodebasesFromConfig = getCodebasesFromConfig;
|
|
5
6
|
exports.parseFunctionSelector = parseFunctionSelector;
|
|
6
7
|
exports.getEndpointFilters = getEndpointFilters;
|
|
7
8
|
exports.getHumanFriendlyPlatformName = getHumanFriendlyPlatformName;
|
|
@@ -39,13 +40,24 @@ function endpointMatchesFilter(endpoint, filter) {
|
|
|
39
40
|
}
|
|
40
41
|
return true;
|
|
41
42
|
}
|
|
43
|
+
function getCodebasesFromConfig(config) {
|
|
44
|
+
return [
|
|
45
|
+
...new Set(config.flatMap((c) => ((0, projectConfig_1.isKitConfig)(c) ? Object.keys(c.instances) : [c.codebase]))),
|
|
46
|
+
];
|
|
47
|
+
}
|
|
42
48
|
function parseFunctionSelector(selector, config) {
|
|
43
49
|
const fragments = selector.split(":");
|
|
50
|
+
const target = fragments[0];
|
|
51
|
+
const codebaseNames = getCodebasesFromConfig(config);
|
|
52
|
+
if (codebaseNames.includes(target)) {
|
|
53
|
+
return [
|
|
54
|
+
{
|
|
55
|
+
codebase: target,
|
|
56
|
+
...(fragments.length > 1 ? { idChunks: fragments[1].split(/[-.]/) } : {}),
|
|
57
|
+
},
|
|
58
|
+
];
|
|
59
|
+
}
|
|
44
60
|
if (fragments.length < 2) {
|
|
45
|
-
const codebaseNames = config.map((c) => c.codebase);
|
|
46
|
-
if (codebaseNames.includes(fragments[0])) {
|
|
47
|
-
return [{ codebase: fragments[0] }];
|
|
48
|
-
}
|
|
49
61
|
return [{ codebase: projectConfig_1.DEFAULT_CODEBASE, idChunks: fragments[0].split(/[-.]/) }];
|
|
50
62
|
}
|
|
51
63
|
return [
|
|
@@ -94,7 +106,7 @@ function getFunctionLabel(fn) {
|
|
|
94
106
|
return id;
|
|
95
107
|
}
|
|
96
108
|
function targetCodebases(config, filters) {
|
|
97
|
-
const codebasesFromConfig =
|
|
109
|
+
const codebasesFromConfig = getCodebasesFromConfig(config);
|
|
98
110
|
if (!filters) {
|
|
99
111
|
return [...codebasesFromConfig];
|
|
100
112
|
}
|
|
@@ -104,13 +116,7 @@ function targetCodebases(config, filters) {
|
|
|
104
116
|
if (codebasesFromFilters.length === 0) {
|
|
105
117
|
return [...codebasesFromConfig];
|
|
106
118
|
}
|
|
107
|
-
|
|
108
|
-
for (const codebase of codebasesFromConfig) {
|
|
109
|
-
if (codebasesFromFilters.includes(codebase)) {
|
|
110
|
-
intersections.push(codebase);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return intersections;
|
|
119
|
+
return codebasesFromConfig.filter((codebase) => codebasesFromFilters.includes(codebase));
|
|
114
120
|
}
|
|
115
121
|
function groupEndpointsByCodebase(wantBackends, haveEndpoints) {
|
|
116
122
|
const grouped = {};
|
|
@@ -14,11 +14,13 @@ const logger_1 = require("../../logger");
|
|
|
14
14
|
const error_1 = require("../../error");
|
|
15
15
|
const prompt_1 = require("../../prompt");
|
|
16
16
|
const secrets_1 = require("../../functions/secrets");
|
|
17
|
+
const build = require("./build");
|
|
17
18
|
const functional_1 = require("../../functional");
|
|
18
19
|
const secretManager = require("../../gcp/secretManager");
|
|
19
20
|
const storage_1 = require("../../gcp/storage");
|
|
20
21
|
const cel_1 = require("./cel");
|
|
21
22
|
const secretManager_1 = require("../../gcp/secretManager");
|
|
23
|
+
const experiments = require("../../experiments");
|
|
22
24
|
function dependenciesCEL(expr) {
|
|
23
25
|
const deps = [];
|
|
24
26
|
const paramCapture = /{{ params\.(\w+) }}/g;
|
|
@@ -160,8 +162,9 @@ function canSatisfyParam(param, value) {
|
|
|
160
162
|
}
|
|
161
163
|
(0, functional_1.assertExhaustive)(param);
|
|
162
164
|
}
|
|
163
|
-
async function resolveParams(params, firebaseConfig, userEnvs, nonInteractive, isEmulator = false) {
|
|
165
|
+
async function resolveParams(params, firebaseConfig, userEnvs, nonInteractive, force, isEmulator = false) {
|
|
164
166
|
const paramValues = populateDefaultParams(firebaseConfig);
|
|
167
|
+
const secretRefs = {};
|
|
165
168
|
const [resolved, outstanding] = (0, functional_1.partition)(params, (param) => {
|
|
166
169
|
return {}.hasOwnProperty.call(userEnvs, param.name);
|
|
167
170
|
});
|
|
@@ -171,7 +174,7 @@ async function resolveParams(params, firebaseConfig, userEnvs, nonInteractive, i
|
|
|
171
174
|
const [needSecret, needPrompt] = (0, functional_1.partition)(outstanding, (param) => param.type === "secret");
|
|
172
175
|
if (!isEmulator) {
|
|
173
176
|
for (const param of needSecret) {
|
|
174
|
-
await
|
|
177
|
+
secretRefs[param.name] = await ensureSecret(param, firebaseConfig.projectId, nonInteractive, force);
|
|
175
178
|
}
|
|
176
179
|
}
|
|
177
180
|
if (nonInteractive && needPrompt.length > 0) {
|
|
@@ -191,7 +194,7 @@ async function resolveParams(params, firebaseConfig, userEnvs, nonInteractive, i
|
|
|
191
194
|
}
|
|
192
195
|
paramValues[param.name] = await promptParam(param, firebaseConfig.projectId, paramDefault);
|
|
193
196
|
}
|
|
194
|
-
return paramValues;
|
|
197
|
+
return { paramValues: paramValues, secretRefs: secretRefs };
|
|
195
198
|
}
|
|
196
199
|
function populateDefaultParams(config) {
|
|
197
200
|
const defaultParams = {};
|
|
@@ -221,24 +224,45 @@ function populateDefaultParams(config) {
|
|
|
221
224
|
}
|
|
222
225
|
return defaultParams;
|
|
223
226
|
}
|
|
224
|
-
async function
|
|
225
|
-
const
|
|
227
|
+
async function ensureSecret(secretParam, projectId, nonInteractive, force) {
|
|
228
|
+
const resourceId = secretParam.resourceId || secretParam.name;
|
|
229
|
+
const version = secretParam.version || "latest";
|
|
230
|
+
let secretAlreadyExisted = false;
|
|
231
|
+
const metadata = await secretManager.getSecretMetadata(projectId, resourceId, version);
|
|
226
232
|
if (!metadata.secret) {
|
|
227
233
|
if (nonInteractive) {
|
|
228
|
-
throw new error_1.FirebaseError(`In non-interactive mode but have no value for the secret
|
|
234
|
+
throw new error_1.FirebaseError(`In non-interactive mode but have no value for the secret ${secretParam.name}: ${resourceId}\n\n` +
|
|
229
235
|
"Set this secret before deploying:\n" +
|
|
230
|
-
`\tfirebase functions:secrets:set ${
|
|
236
|
+
`\tfirebase functions:secrets:set ${resourceId}${secretParam.format === "json" ? " --format=json --data-file <file.json>" : ""}`);
|
|
231
237
|
}
|
|
232
|
-
|
|
238
|
+
if (experiments.isEnabled("secretEnvParams") && typeof secretParam.resourceId === "undefined") {
|
|
239
|
+
if (force) {
|
|
240
|
+
logger_1.logger.info(`--force: Using default resource ID for secret ${secretParam.name}`);
|
|
241
|
+
secretParam.resourceId = secretParam.name;
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
secretParam.resourceId = await (0, prompt_1.input)({
|
|
245
|
+
default: secretParam.name,
|
|
246
|
+
message: `What resource ID do you want to use for the backing Secret resource for secret param ${secretParam.name}?`,
|
|
247
|
+
validate: (id) => {
|
|
248
|
+
if (new RegExp(`^${build.GCP_SECRET_ID_PATTERN}$`).test(id)) {
|
|
249
|
+
return true;
|
|
250
|
+
}
|
|
251
|
+
return "GCP Secret identifiers must contain only letters, numbers, underscores, and hyphens.";
|
|
252
|
+
},
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
return ensureSecret(secretParam, projectId, nonInteractive, force);
|
|
256
|
+
}
|
|
257
|
+
const promptMessage = `The value for this secret (${secretParam.name}) will be stored in Cloud Secret Manager (https://cloud.google.com/secret-manager/pricing) as ${resourceId}. Enter ${secretParam.format === "json" ? "a JSON value" : "a value"} for ${secretParam.label || secretParam.name}:`;
|
|
233
258
|
const secretValue = await (0, prompt_1.password)({
|
|
234
259
|
message: promptMessage,
|
|
235
260
|
});
|
|
236
261
|
if (secretParam.format === "json") {
|
|
237
262
|
(0, secrets_1.validateJsonSecret)(secretParam.name, secretValue);
|
|
238
263
|
}
|
|
239
|
-
await secretManager.createSecret(projectId,
|
|
240
|
-
await secretManager.addVersion(projectId,
|
|
241
|
-
return;
|
|
264
|
+
await secretManager.createSecret(projectId, resourceId, (0, secretManager_1.labels)());
|
|
265
|
+
await secretManager.addVersion(projectId, resourceId, secretValue);
|
|
242
266
|
}
|
|
243
267
|
else if (!metadata.secretVersion) {
|
|
244
268
|
throw new error_1.FirebaseError(`Cloud Secret Manager has no latest version of the secret defined by param ${secretParam.label || secretParam.name}`);
|
|
@@ -247,6 +271,16 @@ async function handleSecret(secretParam, projectId, nonInteractive) {
|
|
|
247
271
|
metadata.secretVersion.state === "DISABLED") {
|
|
248
272
|
throw new error_1.FirebaseError(`Cloud Secret Manager's latest version of secret '${secretParam.label || secretParam.name} is in illegal state ${metadata.secretVersion.state}`);
|
|
249
273
|
}
|
|
274
|
+
else {
|
|
275
|
+
secretAlreadyExisted = true;
|
|
276
|
+
}
|
|
277
|
+
const secretRefString = typeof version === "undefined" ? resourceId : `${resourceId}:${version}`;
|
|
278
|
+
if (experiments.isEnabled("secretEnvParams")) {
|
|
279
|
+
if (!secretParam.inLocalEnvironment && secretAlreadyExisted) {
|
|
280
|
+
logger_1.logger.info(`Onetime (firebase-tools x.y.z+): storing a reference to existing secret ${secretParam.name}=${secretRefString} in .env files.`);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return secretRefString;
|
|
250
284
|
}
|
|
251
285
|
async function promptParam(param, projectId, resolvedDefault) {
|
|
252
286
|
if (param.type === "string") {
|
|
@@ -12,6 +12,7 @@ exports.resolveDefaultTimeout = resolveDefaultTimeout;
|
|
|
12
12
|
exports.loadCodebases = loadCodebases;
|
|
13
13
|
exports.warnIfNewGenkitFunctionIsMissingSecrets = warnIfNewGenkitFunctionIsMissingSecrets;
|
|
14
14
|
exports.ensureAllRequiredAPIsEnabled = ensureAllRequiredAPIsEnabled;
|
|
15
|
+
exports.partitionUserEnvs = partitionUserEnvs;
|
|
15
16
|
const clc = require("colorette");
|
|
16
17
|
const proto = require("../../gcp/proto");
|
|
17
18
|
const backend = require("./backend");
|
|
@@ -160,7 +161,12 @@ async function prepare(context, options, payload) {
|
|
|
160
161
|
context.firebaseConfig = firebaseConfig;
|
|
161
162
|
context.codebaseDeployEvents = {};
|
|
162
163
|
let runtimeConfig = { firebase: firebaseConfig };
|
|
163
|
-
const targetedCodebaseConfigs = context.config.filter((cfg) =>
|
|
164
|
+
const targetedCodebaseConfigs = context.config.filter((cfg) => {
|
|
165
|
+
if ((0, projectConfig_1.isKitConfig)(cfg)) {
|
|
166
|
+
return cfg.instances && Object.keys(cfg.instances).some((inst) => codebases.includes(inst));
|
|
167
|
+
}
|
|
168
|
+
return cfg.codebase && codebases.includes(cfg.codebase);
|
|
169
|
+
});
|
|
164
170
|
if (checkAPIsEnabled[1] && targetedCodebaseConfigs.some(projectConfig_1.shouldUseRuntimeConfig)) {
|
|
165
171
|
runtimeConfig = { ...runtimeConfig, ...(await (0, prepareFunctionsUpload_1.getFunctionsConfig)(projectId)) };
|
|
166
172
|
}
|
|
@@ -185,21 +191,33 @@ async function prepare(context, options, payload) {
|
|
|
185
191
|
projectId: projectId,
|
|
186
192
|
projectAlias: options.projectAlias,
|
|
187
193
|
};
|
|
188
|
-
|
|
189
|
-
|
|
194
|
+
if ((0, projectConfig_1.isKitConfig)(localCfg) && codebase in localCfg.instances) {
|
|
195
|
+
userEnvOpt.configDir = options.config.path(localCfg.instances[codebase]);
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
proto.convertIfPresent(userEnvOpt, localCfg, "configDir", (cd) => options.config.path(cd));
|
|
199
|
+
}
|
|
200
|
+
const rawUserEnvs = functionsEnv.loadUserEnvs(userEnvOpt);
|
|
201
|
+
const { userEnvs: userEnvs, secretRefs: secretRefs } = partitionUserEnvs(rawUserEnvs);
|
|
190
202
|
const envs = { ...userEnvs, ...firebaseEnvs };
|
|
191
203
|
const relevantEndpoints = backend
|
|
192
204
|
.allEndpoints(existingBackend)
|
|
193
205
|
.filter((e) => e.codebase === codebase || e.codebase === undefined);
|
|
194
206
|
await resolveDefaultRegionsForBuild(wantBuild, backend.of(...relevantEndpoints));
|
|
195
|
-
const
|
|
207
|
+
const parsedSecretRefs = (0, functional_1.mapObject)(secretRefs, (unparsed) => build.parseSecretRef(unparsed));
|
|
208
|
+
build.applyEnvSecretBindings(wantBuild, parsedSecretRefs);
|
|
209
|
+
const { backend: wantBackend, envs: resolvedEnvs, secretRefs: resolvedSecretRefs, } = await build.resolveBackend({
|
|
196
210
|
build: wantBuild,
|
|
197
211
|
firebaseConfig,
|
|
198
212
|
userEnvs,
|
|
199
213
|
nonInteractive: options.nonInteractive,
|
|
214
|
+
force: options.force,
|
|
200
215
|
isEmulator: false,
|
|
201
216
|
});
|
|
202
217
|
functionsEnv.writeResolvedParams(resolvedEnvs, userEnvs, userEnvOpt);
|
|
218
|
+
if (experiments.isEnabled("secretEnvParams")) {
|
|
219
|
+
functionsEnv.writeResolvedSecretRefs(resolvedSecretRefs, secretRefs, userEnvOpt);
|
|
220
|
+
}
|
|
203
221
|
let hasEnvsFromParams = false;
|
|
204
222
|
wantBackend.environmentVariables = envs;
|
|
205
223
|
for (const envName of Object.keys(resolvedEnvs)) {
|
|
@@ -490,7 +508,10 @@ async function loadCodebases(config, options, firebaseConfig, runtimeConfig, fil
|
|
|
490
508
|
GOOGLE_CLOUD_QUOTA_PROJECT: projectId,
|
|
491
509
|
});
|
|
492
510
|
discoveredBuild.runtime = codebaseConfig.runtime;
|
|
493
|
-
|
|
511
|
+
const prefix = (0, projectConfig_1.isKitConfig)(codebaseConfig)
|
|
512
|
+
? (0, projectConfig_1.addKitPrefix)(codebase)
|
|
513
|
+
: codebaseConfig.prefix || "";
|
|
514
|
+
build.applyPrefix(discoveredBuild, prefix);
|
|
494
515
|
wantBuilds[codebase] = discoveredBuild;
|
|
495
516
|
}
|
|
496
517
|
return wantBuilds;
|
|
@@ -586,3 +607,15 @@ async function ensureAllRequiredAPIsEnabled(projectNumber, wantBackend = backend
|
|
|
586
607
|
await ensureApiEnabled.ensure(projectNumber, (0, api_1.secretManagerOrigin)(), "functions", false);
|
|
587
608
|
}
|
|
588
609
|
}
|
|
610
|
+
function partitionUserEnvs(allEnvs) {
|
|
611
|
+
const [secretRefs, userEnvs] = Object.entries(allEnvs).reduce((accumulatedSplit, [k, v]) => {
|
|
612
|
+
if (k.startsWith(build.SECRET_REF_PREFIX)) {
|
|
613
|
+
accumulatedSplit[0][k.replace(build.SECRET_REF_PREFIX, "")] = v;
|
|
614
|
+
}
|
|
615
|
+
else {
|
|
616
|
+
accumulatedSplit[1][k] = v;
|
|
617
|
+
}
|
|
618
|
+
return accumulatedSplit;
|
|
619
|
+
}, [{}, {}]);
|
|
620
|
+
return { userEnvs: userEnvs, secretRefs: secretRefs };
|
|
621
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InlineExecutor = exports.QueueExecutor = exports.
|
|
3
|
+
exports.InlineExecutor = exports.QueueExecutor = exports.isCloudRunResourceExhausted = exports.isServiceAccount404 = exports.isTransientError = exports.isServiceUnavailable = exports.isConflict = exports.isQuotaExhaustion = void 0;
|
|
4
|
+
exports.parseErrorCode = parseErrorCode;
|
|
5
|
+
exports.hasErrorCode = hasErrorCode;
|
|
4
6
|
const queue_1 = require("../../../throttler/queue");
|
|
5
|
-
exports.DEFAULT_RETRY_CODES = [429, 409, 503];
|
|
6
7
|
function parseErrorCode(err) {
|
|
7
8
|
return (err.status ||
|
|
8
9
|
err.code ||
|
|
@@ -10,29 +11,71 @@ function parseErrorCode(err) {
|
|
|
10
11
|
err.original?.code ||
|
|
11
12
|
err.original?.context?.response?.statusCode);
|
|
12
13
|
}
|
|
14
|
+
function hasErrorCode(...codes) {
|
|
15
|
+
return (err) => codes.includes(parseErrorCode(err));
|
|
16
|
+
}
|
|
17
|
+
const isQuotaExhaustion = (err) => parseErrorCode(err) === 429;
|
|
18
|
+
exports.isQuotaExhaustion = isQuotaExhaustion;
|
|
19
|
+
const isConflict = (err) => parseErrorCode(err) === 409;
|
|
20
|
+
exports.isConflict = isConflict;
|
|
21
|
+
const isServiceUnavailable = (err) => parseErrorCode(err) === 503;
|
|
22
|
+
exports.isServiceUnavailable = isServiceUnavailable;
|
|
23
|
+
const isTransientError = (err) => (0, exports.isQuotaExhaustion)(err) || (0, exports.isConflict)(err) || (0, exports.isServiceUnavailable)(err);
|
|
24
|
+
exports.isTransientError = isTransientError;
|
|
25
|
+
const isServiceAccount404 = (err) => {
|
|
26
|
+
if (parseErrorCode(err) !== 404) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
let message = "";
|
|
30
|
+
try {
|
|
31
|
+
message = [
|
|
32
|
+
err?.message,
|
|
33
|
+
err?.original?.message,
|
|
34
|
+
err?.context?.body?.error?.message,
|
|
35
|
+
String(err),
|
|
36
|
+
]
|
|
37
|
+
.filter(Boolean)
|
|
38
|
+
.join(" ")
|
|
39
|
+
.toLowerCase();
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
message = String(err).toLowerCase();
|
|
43
|
+
}
|
|
44
|
+
return (message.includes("serviceaccount") ||
|
|
45
|
+
message.includes("service account") ||
|
|
46
|
+
/\b[a-z0-9._%+-]+@[a-z0-9.-]+\.gserviceaccount\.com\b/i.test(message) ||
|
|
47
|
+
/\bgserviceaccount\.com\b/i.test(message));
|
|
48
|
+
};
|
|
49
|
+
exports.isServiceAccount404 = isServiceAccount404;
|
|
50
|
+
const isCloudRunResourceExhausted = (err) => parseErrorCode(err) === 8;
|
|
51
|
+
exports.isCloudRunResourceExhausted = isCloudRunResourceExhausted;
|
|
13
52
|
async function handler(op) {
|
|
14
53
|
try {
|
|
15
54
|
op.result = await op.func();
|
|
16
55
|
}
|
|
17
56
|
catch (err) {
|
|
18
|
-
const
|
|
19
|
-
if (
|
|
57
|
+
const shouldRetry = op.retryPredicates.some((predicate) => predicate(err));
|
|
58
|
+
if (shouldRetry) {
|
|
20
59
|
throw err;
|
|
21
60
|
}
|
|
22
|
-
err.code =
|
|
61
|
+
err.code = parseErrorCode(err);
|
|
23
62
|
op.error = err;
|
|
24
63
|
}
|
|
25
64
|
return;
|
|
26
65
|
}
|
|
27
66
|
class QueueExecutor {
|
|
28
67
|
constructor(options) {
|
|
29
|
-
|
|
68
|
+
const { defaultRetryPredicates, ...throttlerOptions } = options;
|
|
69
|
+
this.defaultRetryPredicates = defaultRetryPredicates || [exports.isTransientError];
|
|
70
|
+
this.queue = new queue_1.Queue({ ...throttlerOptions, handler });
|
|
30
71
|
}
|
|
31
72
|
async run(func, opts) {
|
|
32
|
-
const
|
|
73
|
+
const retryPredicates = opts?.retryPredicates
|
|
74
|
+
? [...opts.retryPredicates]
|
|
75
|
+
: [...this.defaultRetryPredicates];
|
|
33
76
|
const op = {
|
|
34
77
|
func,
|
|
35
|
-
|
|
78
|
+
retryPredicates,
|
|
36
79
|
};
|
|
37
80
|
await this.queue.run(op);
|
|
38
81
|
if (op.error) {
|
|
@@ -66,11 +66,13 @@ class Fabricator {
|
|
|
66
66
|
this.projectId = args.projectId;
|
|
67
67
|
}
|
|
68
68
|
async grantNewRoles(plan, codebase) {
|
|
69
|
+
let createdSA = false;
|
|
69
70
|
if (plan.serviceAccountToCreate) {
|
|
70
71
|
utils.logLabeledBullet("functions", `Creating managed service account ${plan.serviceAccountToCreate}...`);
|
|
71
72
|
const saName = plan.serviceAccountToCreate.split("@")[0];
|
|
72
73
|
try {
|
|
73
74
|
await iam.createServiceAccount(this.projectId, saName, `Managed by Firebase CLI for codebase ${codebase}`, `Firebase Functions ${codebase}`);
|
|
75
|
+
createdSA = true;
|
|
74
76
|
}
|
|
75
77
|
catch (e) {
|
|
76
78
|
throw new error_1.FirebaseError("Cannot enable declarative security because you do not have permissions necessary to create the service account. Please ask an IAM administrator to perform the next deploy.", { original: e });
|
|
@@ -87,6 +89,14 @@ class Fabricator {
|
|
|
87
89
|
await resourcemanager.addServiceAccountRoles(this.projectId, plan.managedServiceAccount, plan.rolesToAdd, true);
|
|
88
90
|
}
|
|
89
91
|
catch (e) {
|
|
92
|
+
if (createdSA && plan.serviceAccountToCreate) {
|
|
93
|
+
try {
|
|
94
|
+
await iam.deleteServiceAccount(this.projectId, plan.serviceAccountToCreate);
|
|
95
|
+
}
|
|
96
|
+
catch (cleanupErr) {
|
|
97
|
+
logger_1.logger.debug("Failed to clean up newly created service account after role grant error", cleanupErr);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
90
100
|
throw new error_1.FirebaseError("The declarative security roles for this codebase have changed, but you do not have access to see what has changed. Please ask an IAM administrator to perform the next deploy.", { original: e });
|
|
91
101
|
}
|
|
92
102
|
}
|
|
@@ -154,6 +164,7 @@ class Fabricator {
|
|
|
154
164
|
logger_1.logger.debug("Fabricator.applyUpserts returned an unhandled exception.", JSON.stringify(r.reason, null, 2));
|
|
155
165
|
return acc;
|
|
156
166
|
}, []);
|
|
167
|
+
await this.cleanupUnusedServiceAccounts(plan, summary.results);
|
|
157
168
|
const hasFailures = summary.results.some((r) => r.error);
|
|
158
169
|
if (hasFailures) {
|
|
159
170
|
utils.logLabeledWarning("functions", "Deploys failed. Skipping deletes.");
|
|
@@ -183,6 +194,24 @@ class Fabricator {
|
|
|
183
194
|
summary.totalTime = timer.stop();
|
|
184
195
|
return summary;
|
|
185
196
|
}
|
|
197
|
+
async cleanupUnusedServiceAccounts(plan, results) {
|
|
198
|
+
for (const [codebase, codebasePlan] of Object.entries(plan)) {
|
|
199
|
+
if (!codebasePlan.serviceAccountToCreate) {
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
const codebaseSuccesses = results.filter((r) => r.endpoint.codebase === codebase && !r.error);
|
|
203
|
+
if (codebaseSuccesses.length > 0) {
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
utils.logLabeledWarning("functions", `Cleaning up managed service account ${codebasePlan.serviceAccountToCreate} due to 100% deployment failure for codebase ${codebase}.`);
|
|
207
|
+
try {
|
|
208
|
+
await iam.deleteServiceAccount(this.projectId, codebasePlan.serviceAccountToCreate);
|
|
209
|
+
}
|
|
210
|
+
catch (e) {
|
|
211
|
+
logger_1.logger.debug(`Failed to delete managed service account ${codebasePlan.serviceAccountToCreate} during failure cleanup`, e);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
186
215
|
async applyUpserts(changes, scraperV1, scraperV2) {
|
|
187
216
|
const ops = [];
|
|
188
217
|
for (const endpoint of changes.endpointsToCreate) {
|
|
@@ -289,7 +318,7 @@ class Fabricator {
|
|
|
289
318
|
operationResourceName: op.name,
|
|
290
319
|
onPoll: scraper.poller,
|
|
291
320
|
});
|
|
292
|
-
})
|
|
321
|
+
}, { retryPredicates: [executor_1.isTransientError, executor_1.isServiceAccount404] })
|
|
293
322
|
.catch(rethrowAs(endpoint, "create"));
|
|
294
323
|
endpoint.uri = resultFunction?.httpsTrigger?.url;
|
|
295
324
|
if (backend.isHttpsTriggered(endpoint)) {
|
|
@@ -395,7 +424,7 @@ class Fabricator {
|
|
|
395
424
|
operationResourceName: op.name,
|
|
396
425
|
onPoll: scraper.poller,
|
|
397
426
|
});
|
|
398
|
-
})
|
|
427
|
+
}, { retryPredicates: [executor_1.isTransientError, executor_1.isServiceAccount404] })
|
|
399
428
|
.catch(async (err) => {
|
|
400
429
|
scraper.abort();
|
|
401
430
|
if (err.code === CLOUD_RUN_RESOURCE_EXHAUSTED_CODE) {
|
|
@@ -522,7 +551,7 @@ class Fabricator {
|
|
|
522
551
|
operationResourceName: op.name,
|
|
523
552
|
onPoll: scraper.poller,
|
|
524
553
|
});
|
|
525
|
-
}, {
|
|
554
|
+
}, { retryPredicates: [executor_1.isTransientError, executor_1.isCloudRunResourceExhausted, executor_1.isServiceAccount404] })
|
|
526
555
|
.catch((err) => {
|
|
527
556
|
scraper.abort();
|
|
528
557
|
logger_1.logger.error(err.message);
|
|
@@ -592,7 +621,7 @@ class Fabricator {
|
|
|
592
621
|
operationResourceName: op.name,
|
|
593
622
|
};
|
|
594
623
|
await poller.pollOperation(pollerOptions);
|
|
595
|
-
}, {
|
|
624
|
+
}, { retryPredicates: [executor_1.isTransientError, executor_1.isCloudRunResourceExhausted, executor_1.isServiceAccount404] })
|
|
596
625
|
.catch(rethrowAs(endpoint, "delete"));
|
|
597
626
|
}
|
|
598
627
|
async createRunFunction(endpoint) {
|
|
@@ -615,7 +644,7 @@ class Fabricator {
|
|
|
615
644
|
const op = await runV2.createService(endpoint.project, endpoint.region, endpoint.id, service);
|
|
616
645
|
endpoint.uri = op.uri;
|
|
617
646
|
endpoint.runServiceId = endpoint.id;
|
|
618
|
-
})
|
|
647
|
+
}, { retryPredicates: [executor_1.isTransientError, executor_1.isServiceAccount404] })
|
|
619
648
|
.catch(rethrowAs(endpoint, "create"));
|
|
620
649
|
const serviceName = `projects/${endpoint.project}/locations/${endpoint.region}/services/${endpoint.runServiceId}`;
|
|
621
650
|
if (backend.isHttpsTriggered(endpoint)) {
|