firebase-tools 15.32.1 → 15.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/lib/api.js +4 -2
- package/lib/apphosting/backend.js +1 -1
- package/lib/checkValidTargetFilters.js +1 -0
- package/lib/command.js +30 -23
- package/lib/commands/apps-create.js +34 -3
- package/lib/commands/crashlytics-heapdumps-disable.js +26 -0
- package/lib/commands/crashlytics-heapdumps-enable.js +54 -0
- package/lib/commands/crashlytics-heapdumps-status.js +32 -0
- package/lib/commands/deploy.js +3 -0
- package/lib/commands/functions-kits-uninstall.js +43 -21
- package/lib/commands/functions-lifecycle-list.js +5 -6
- package/lib/commands/hosting-channel-deploy.js +3 -3
- package/lib/commands/hosting-clone.js +102 -31
- package/lib/commands/hosting-disable.js +5 -1
- package/lib/commands/index.js +9 -0
- package/lib/commands/init.js +7 -0
- package/lib/commands/run-services-update.js +16 -0
- package/lib/crashlytics/onboarding.js +17 -2
- package/lib/crashlytics/profilingManager.js +195 -0
- package/lib/deploy/apphosting/prepare.js +1 -0
- package/lib/deploy/auth/deploy.js +1 -1
- package/lib/deploy/auth/prepare.js +6 -7
- package/lib/deploy/firestore/prepare.js +5 -5
- package/lib/deploy/functions/build.js +3 -0
- package/lib/deploy/functions/cel.js +89 -58
- package/lib/deploy/functions/functionsDeployHelper.js +10 -0
- package/lib/deploy/functions/prepare.js +25 -8
- package/lib/deploy/functions/release/executor.js +7 -3
- package/lib/deploy/functions/release/fabricator.js +42 -14
- package/lib/deploy/functions/release/planner.js +3 -2
- package/lib/deploy/functions/release/sourceTokenScraper.js +1 -1
- package/lib/deploy/functions/validate.js +16 -0
- package/lib/deploy/hosting/prepare.js +1 -1
- package/lib/deploy/hosting/release.js +2 -2
- package/lib/deploy/index.js +5 -0
- package/lib/deploy/run/args.js +2 -0
- package/lib/deploy/run/buildEnv.js +72 -0
- package/lib/deploy/run/deploy.js +214 -0
- package/lib/deploy/run/index.js +23 -0
- package/lib/deploy/run/prepare.js +47 -0
- package/lib/deploy/run/prereqs.js +32 -0
- package/lib/deploy/run/release.js +9 -0
- package/lib/deploy/run/update.js +50 -0
- package/lib/deploy/run/util.js +73 -0
- package/lib/emulator/apphosting/serve.js +1 -1
- package/lib/emulator/auth/utils.js +1 -1
- package/lib/emulator/commandUtils.js +7 -3
- package/lib/emulator/dataconnect/pgliteServer.js +1 -1
- package/lib/emulator/dataconnectEmulator.js +1 -1
- package/lib/emulator/download.js +1 -1
- package/lib/emulator/downloadableEmulatorInfo.json +31 -31
- package/lib/emulator/downloadableEmulators.js +1 -3
- package/lib/emulator/eventarcEmulator.js +1 -1
- package/lib/emulator/functionsEmulatorShared.js +1 -41
- package/lib/experiments.js +12 -11
- package/lib/firestore/validator.js +1 -1
- package/lib/frameworks/next/constants.js +20 -12
- package/lib/frameworks/next/index.js +3 -0
- package/lib/functions/env.js +4 -2
- package/lib/functions/projectConfig.js +10 -5
- package/lib/gcp/artifactregistry.js +20 -0
- package/lib/gcp/cloudsql/permissions.js +21 -32
- package/lib/gcp/cloudsql/permissionsSetup.js +6 -6
- package/lib/gcp/cloudtasks.js +14 -0
- package/lib/gcp/cloudtrace.js +38 -0
- package/lib/gcp/run.js +5 -0
- package/lib/gcp/runv2.js +32 -11
- package/lib/gcp/storage.js +9 -5
- package/lib/hosting/api.js +15 -15
- package/lib/hosting/runTags.js +1 -1
- package/lib/init/features/auth.js +46 -8
- package/lib/init/features/index.js +4 -1
- package/lib/init/features/run.js +159 -0
- package/lib/init/index.js +6 -0
- package/lib/mcp/tools/firestore/converter.js +2 -2
- package/lib/mcp/util.js +11 -10
- package/lib/profileReport.js +12 -9
- package/lib/throttler/throttler.js +1 -0
- package/lib/tsconfig.compile.tsbuildinfo +1 -1
- package/lib/tsconfig.publish.tsbuildinfo +1 -1
- package/package.json +2 -8
- package/schema/firebaserc.json +133 -0
- package/lib/mcp/resources/guides/init_data_connect.js +0 -30
- package/lib/mcp/resources/guides/init_rtdb.js +0 -30
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.EVENTARC_SOURCE_ENV = void 0;
|
|
4
4
|
exports.getEventTenantId = getEventTenantId;
|
|
5
5
|
exports.eventServiceImplemented = eventServiceImplemented;
|
|
6
6
|
exports.prepareEndpoints = prepareEndpoints;
|
|
7
7
|
exports.emulatedFunctionsFromEndpoints = emulatedFunctionsFromEndpoints;
|
|
8
8
|
exports.emulatedFunctionsByRegion = emulatedFunctionsByRegion;
|
|
9
|
-
exports.getEmulatedTriggersFromDefinitions = getEmulatedTriggersFromDefinitions;
|
|
10
9
|
exports.getTemporarySocketPath = getTemporarySocketPath;
|
|
11
10
|
exports.getFunctionService = getFunctionService;
|
|
12
11
|
exports.getServiceFromEventType = getServiceFromEventType;
|
|
13
|
-
exports.waitForBody = waitForBody;
|
|
14
12
|
exports.findModuleRoot = findModuleRoot;
|
|
15
13
|
exports.formatHost = formatHost;
|
|
16
14
|
exports.getSignatureType = getSignatureType;
|
|
@@ -20,7 +18,6 @@ const os = require("os");
|
|
|
20
18
|
const path = require("path");
|
|
21
19
|
const fs = require("fs");
|
|
22
20
|
const crypto_1 = require("crypto");
|
|
23
|
-
const _ = require("lodash");
|
|
24
21
|
const backend = require("../deploy/functions/backend");
|
|
25
22
|
const build = require("../deploy/functions/build");
|
|
26
23
|
const constants_1 = require("./constants");
|
|
@@ -49,26 +46,6 @@ function getEventTenantId(eventPayload) {
|
|
|
49
46
|
return undefined;
|
|
50
47
|
}
|
|
51
48
|
exports.EVENTARC_SOURCE_ENV = "EVENTARC_CLOUD_EVENT_SOURCE";
|
|
52
|
-
class EmulatedTrigger {
|
|
53
|
-
constructor(definition, module) {
|
|
54
|
-
this.definition = definition;
|
|
55
|
-
this.module = module;
|
|
56
|
-
}
|
|
57
|
-
get memoryLimitBytes() {
|
|
58
|
-
return (this.definition.availableMemoryMb || 128) * 1024 * 1024;
|
|
59
|
-
}
|
|
60
|
-
get timeoutMs() {
|
|
61
|
-
return (this.definition.timeoutSeconds || 60) * 1000;
|
|
62
|
-
}
|
|
63
|
-
getRawFunction() {
|
|
64
|
-
if (!this.module) {
|
|
65
|
-
throw new Error("EmulatedTrigger has not been provided a module.");
|
|
66
|
-
}
|
|
67
|
-
const func = _.get(this.module, this.definition.entryPoint);
|
|
68
|
-
return func.__emulator_func || func;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
exports.EmulatedTrigger = EmulatedTrigger;
|
|
72
49
|
function eventServiceImplemented(eventType) {
|
|
73
50
|
return V2_EVENTS.includes(eventType);
|
|
74
51
|
}
|
|
@@ -191,12 +168,6 @@ function emulatedFunctionsByRegion(definitions, secretEnvVariables = []) {
|
|
|
191
168
|
}
|
|
192
169
|
return regionDefinitions;
|
|
193
170
|
}
|
|
194
|
-
function getEmulatedTriggersFromDefinitions(definitions, module) {
|
|
195
|
-
return definitions.reduce((obj, definition) => {
|
|
196
|
-
obj[definition.id] = new EmulatedTrigger(definition, module);
|
|
197
|
-
return obj;
|
|
198
|
-
}, {});
|
|
199
|
-
}
|
|
200
171
|
function getTemporarySocketPath() {
|
|
201
172
|
const rand = (0, crypto_1.randomBytes)(8).toString("hex");
|
|
202
173
|
if (process.platform === "win32") {
|
|
@@ -257,17 +228,6 @@ function getServiceFromEventType(eventType) {
|
|
|
257
228
|
}
|
|
258
229
|
return "";
|
|
259
230
|
}
|
|
260
|
-
function waitForBody(req) {
|
|
261
|
-
let data = "";
|
|
262
|
-
return new Promise((resolve) => {
|
|
263
|
-
req.on("data", (chunk) => {
|
|
264
|
-
data += chunk;
|
|
265
|
-
});
|
|
266
|
-
req.on("end", () => {
|
|
267
|
-
resolve(data);
|
|
268
|
-
});
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
231
|
function findModuleRoot(moduleName, filepath) {
|
|
272
232
|
const hierarchy = filepath.split(path.sep);
|
|
273
233
|
for (let i = 0; i < hierarchy.length; i++) {
|
package/lib/experiments.js
CHANGED
|
@@ -53,10 +53,6 @@ exports.ALL_EXPERIMENTS = experiments({
|
|
|
53
53
|
default: false,
|
|
54
54
|
public: true,
|
|
55
55
|
},
|
|
56
|
-
runfunctions: {
|
|
57
|
-
shortDescription: "Functions created using the V2 API target Cloud Run Functions (not production ready)",
|
|
58
|
-
public: false,
|
|
59
|
-
},
|
|
60
56
|
functionsiac: {
|
|
61
57
|
shortDescription: "Exports functions IaC code",
|
|
62
58
|
public: false,
|
|
@@ -87,10 +83,6 @@ exports.ALL_EXPERIMENTS = experiments({
|
|
|
87
83
|
emulatoruisnapshot: {
|
|
88
84
|
shortDescription: "Load pre-release versions of the emulator UI",
|
|
89
85
|
},
|
|
90
|
-
emulatorapphosting: {
|
|
91
|
-
shortDescription: "App Hosting emulator",
|
|
92
|
-
public: false,
|
|
93
|
-
},
|
|
94
86
|
webframeworks: {
|
|
95
87
|
shortDescription: "Native support for popular web frameworks",
|
|
96
88
|
fullDescription: "Adds support for popular web frameworks such as Next.js " +
|
|
@@ -112,9 +104,6 @@ exports.ALL_EXPERIMENTS = experiments({
|
|
|
112
104
|
public: true,
|
|
113
105
|
default: true,
|
|
114
106
|
},
|
|
115
|
-
crossservicerules: {
|
|
116
|
-
shortDescription: "Allow Firebase Rules to reference resources in other services",
|
|
117
|
-
},
|
|
118
107
|
internaltesting: {
|
|
119
108
|
shortDescription: "Exposes Firebase CLI commands intended for internal testing purposes.",
|
|
120
109
|
fullDescription: "Exposes Firebase CLI commands intended for internal testing purposes. " +
|
|
@@ -150,6 +139,13 @@ exports.ALL_EXPERIMENTS = experiments({
|
|
|
150
139
|
default: true,
|
|
151
140
|
public: true,
|
|
152
141
|
},
|
|
142
|
+
directcloudrun: {
|
|
143
|
+
shortDescription: "Build and deploy web apps directly to Cloud Run services",
|
|
144
|
+
fullDescription: "Enables `firebase init run`, `firebase deploy --only run`, and the " +
|
|
145
|
+
"`firebase run:services:update` command. " +
|
|
146
|
+
"These are in preview and may change.",
|
|
147
|
+
public: false,
|
|
148
|
+
},
|
|
153
149
|
dataconnect: {
|
|
154
150
|
shortDescription: "Deprecated. Previosuly, enabled SQL Connect related features.",
|
|
155
151
|
fullDescription: "Deprecated. Previously, enabled SQL Connect related features.",
|
|
@@ -211,6 +207,11 @@ exports.ALL_EXPERIMENTS = experiments({
|
|
|
211
207
|
default: false,
|
|
212
208
|
public: false,
|
|
213
209
|
},
|
|
210
|
+
crashlyticsWebBreadcrumbs: {
|
|
211
|
+
shortDescription: "Enable provisioning Cloud Trace storage during web app onboarding.",
|
|
212
|
+
default: false,
|
|
213
|
+
public: false,
|
|
214
|
+
},
|
|
214
215
|
secretEnvParams: {
|
|
215
216
|
shortDescription: "Enable reading the backing resource binding for a Functions secret param from .env",
|
|
216
217
|
default: true,
|
|
@@ -26,7 +26,7 @@ function assertHasOneOf(obj, props) {
|
|
|
26
26
|
}
|
|
27
27
|
function assertEnum(obj, prop, valid) {
|
|
28
28
|
const objString = clc.cyan(JSON.stringify(obj));
|
|
29
|
-
if (valid.
|
|
29
|
+
if (!valid.includes(obj[prop])) {
|
|
30
30
|
throw new error_1.FirebaseError(`Field "${prop}" must be one of ${valid.join(", ")}: ${objString}`);
|
|
31
31
|
}
|
|
32
32
|
}
|
|
@@ -23,34 +23,42 @@ const WEBPACK_LAYERS_NAMES = {
|
|
|
23
23
|
reactServerComponents: "rsc",
|
|
24
24
|
serverSideRendering: "ssr",
|
|
25
25
|
actionBrowser: "action-browser",
|
|
26
|
-
|
|
26
|
+
apiNode: "api-node",
|
|
27
|
+
apiEdge: "api-edge",
|
|
27
28
|
middleware: "middleware",
|
|
29
|
+
instrument: "instrument",
|
|
28
30
|
edgeAsset: "edge-asset",
|
|
29
31
|
appPagesBrowser: "app-pages-browser",
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
pagesDirBrowser: "pages-dir-browser",
|
|
33
|
+
pagesDirEdge: "pages-dir-edge",
|
|
34
|
+
pagesDirNode: "pages-dir-node",
|
|
32
35
|
};
|
|
33
36
|
exports.WEBPACK_LAYERS = {
|
|
34
37
|
...WEBPACK_LAYERS_NAMES,
|
|
35
38
|
GROUP: {
|
|
36
|
-
|
|
39
|
+
builtinReact: [WEBPACK_LAYERS_NAMES.reactServerComponents, WEBPACK_LAYERS_NAMES.actionBrowser],
|
|
40
|
+
serverOnly: [
|
|
37
41
|
WEBPACK_LAYERS_NAMES.reactServerComponents,
|
|
38
42
|
WEBPACK_LAYERS_NAMES.actionBrowser,
|
|
39
|
-
WEBPACK_LAYERS_NAMES.
|
|
40
|
-
WEBPACK_LAYERS_NAMES.appRouteHandler,
|
|
41
|
-
],
|
|
42
|
-
nonClientServerTarget: [
|
|
43
|
+
WEBPACK_LAYERS_NAMES.instrument,
|
|
43
44
|
WEBPACK_LAYERS_NAMES.middleware,
|
|
44
|
-
WEBPACK_LAYERS_NAMES.api,
|
|
45
45
|
],
|
|
46
|
-
|
|
46
|
+
neutralTarget: [WEBPACK_LAYERS_NAMES.apiNode, WEBPACK_LAYERS_NAMES.apiEdge],
|
|
47
|
+
clientOnly: [WEBPACK_LAYERS_NAMES.serverSideRendering, WEBPACK_LAYERS_NAMES.appPagesBrowser],
|
|
48
|
+
bundled: [
|
|
47
49
|
WEBPACK_LAYERS_NAMES.reactServerComponents,
|
|
48
50
|
WEBPACK_LAYERS_NAMES.actionBrowser,
|
|
49
|
-
WEBPACK_LAYERS_NAMES.appMetadataRoute,
|
|
50
|
-
WEBPACK_LAYERS_NAMES.appRouteHandler,
|
|
51
51
|
WEBPACK_LAYERS_NAMES.serverSideRendering,
|
|
52
52
|
WEBPACK_LAYERS_NAMES.appPagesBrowser,
|
|
53
53
|
WEBPACK_LAYERS_NAMES.shared,
|
|
54
|
+
WEBPACK_LAYERS_NAMES.instrument,
|
|
55
|
+
WEBPACK_LAYERS_NAMES.middleware,
|
|
56
|
+
],
|
|
57
|
+
appPages: [
|
|
58
|
+
WEBPACK_LAYERS_NAMES.reactServerComponents,
|
|
59
|
+
WEBPACK_LAYERS_NAMES.serverSideRendering,
|
|
60
|
+
WEBPACK_LAYERS_NAMES.appPagesBrowser,
|
|
61
|
+
WEBPACK_LAYERS_NAMES.actionBrowser,
|
|
54
62
|
],
|
|
55
63
|
},
|
|
56
64
|
};
|
|
@@ -290,9 +290,12 @@ async function ɵcodegenPublicDirectory(sourceDir, destDir, _, context) {
|
|
|
290
290
|
{
|
|
291
291
|
srcRoute: null,
|
|
292
292
|
initialRevalidateSeconds: false,
|
|
293
|
+
initialExpireSeconds: undefined,
|
|
293
294
|
dataRoute: "",
|
|
294
295
|
experimentalPPR: false,
|
|
296
|
+
renderingMode: undefined,
|
|
295
297
|
prefetchDataRoute: "",
|
|
298
|
+
allowHeader: [],
|
|
296
299
|
},
|
|
297
300
|
];
|
|
298
301
|
}));
|
package/lib/functions/env.js
CHANGED
|
@@ -240,9 +240,11 @@ function writeUserEnvs(toWrite, envOpts) {
|
|
|
240
240
|
}
|
|
241
241
|
function checkForDuplicateKeys(isEmulator, keys, fullEnv, envsWithoutLocal) {
|
|
242
242
|
for (const key of keys) {
|
|
243
|
-
const definedInEnv =
|
|
243
|
+
const definedInEnv = Object.prototype.hasOwnProperty.call(fullEnv, key);
|
|
244
244
|
if (definedInEnv) {
|
|
245
|
-
if (envsWithoutLocal &&
|
|
245
|
+
if (envsWithoutLocal &&
|
|
246
|
+
isEmulator &&
|
|
247
|
+
Object.prototype.hasOwnProperty.call(envsWithoutLocal, key)) {
|
|
246
248
|
(0, utils_1.logWarning)(clc.cyan(clc.yellow("functions: ")) +
|
|
247
249
|
`Writing parameter ${key} to emulator-specific config .env.local. This will overwrite your existing definition only when emulating.`);
|
|
248
250
|
continue;
|
|
@@ -145,11 +145,16 @@ function assertUniqueSourcePrefixPair(config) {
|
|
|
145
145
|
else {
|
|
146
146
|
continue;
|
|
147
147
|
}
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
148
|
+
const prefixes = isKitConfig(c)
|
|
149
|
+
? Object.keys(c.instances).map((instanceId) => addKitPrefix(instanceId))
|
|
150
|
+
: [c.prefix || ""];
|
|
151
|
+
for (const prefix of prefixes) {
|
|
152
|
+
const key = JSON.stringify({ source: sourceIdentifier, prefix });
|
|
153
|
+
if (sourcePrefixPairs.has(key)) {
|
|
154
|
+
throw new error_1.FirebaseError(`More than one functions config specifies the same ${sourceDescription} and prefix ('${prefix}'). Please use kits with a unique instance ID to resolve this conflict.`);
|
|
155
|
+
}
|
|
156
|
+
sourcePrefixPairs.add(key);
|
|
151
157
|
}
|
|
152
|
-
sourcePrefixPairs.add(key);
|
|
153
158
|
}
|
|
154
159
|
}
|
|
155
160
|
function validateKitInstanceId(instanceId) {
|
|
@@ -194,8 +199,8 @@ function validate(config) {
|
|
|
194
199
|
const validated = config.map((cfg) => validateSingle(cfg));
|
|
195
200
|
assertUnique(validated, "codebase");
|
|
196
201
|
assertUnique(validated, "kit");
|
|
197
|
-
assertUniqueSourcePrefixPair(validated);
|
|
198
202
|
assertUniqueKitInstancesAndCodebases(validated);
|
|
203
|
+
assertUniqueSourcePrefixPair(validated);
|
|
199
204
|
return validated;
|
|
200
205
|
}
|
|
201
206
|
function normalizeAndValidate(config) {
|
|
@@ -5,11 +5,14 @@ exports.ensureApiEnabled = ensureApiEnabled;
|
|
|
5
5
|
exports.deletePackage = deletePackage;
|
|
6
6
|
exports.getRepository = getRepository;
|
|
7
7
|
exports.updateRepository = updateRepository;
|
|
8
|
+
exports.ensureDockerRepository = ensureDockerRepository;
|
|
8
9
|
const apiv2_1 = require("../apiv2");
|
|
9
10
|
const api_1 = require("../api");
|
|
10
11
|
const metaprogramming_1 = require("../metaprogramming");
|
|
11
12
|
const api = require("../ensureApiEnabled");
|
|
12
13
|
const proto = require("./proto");
|
|
14
|
+
const error_1 = require("../error");
|
|
15
|
+
const operation_poller_1 = require("../operation-poller");
|
|
13
16
|
exports.API_VERSION = "v1";
|
|
14
17
|
const client = new apiv2_1.Client({
|
|
15
18
|
urlPrefix: (0, api_1.artifactRegistryDomain)(),
|
|
@@ -39,3 +42,20 @@ async function updateRepository(repo) {
|
|
|
39
42
|
});
|
|
40
43
|
return res.body;
|
|
41
44
|
}
|
|
45
|
+
async function ensureDockerRepository(projectId, location, repositoryId) {
|
|
46
|
+
try {
|
|
47
|
+
await getRepository(`projects/${projectId}/locations/${location}/repositories/${repositoryId}`);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
if ((0, error_1.getErrStatus)(err) !== 404) {
|
|
52
|
+
throw err;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const res = await client.post(`/projects/${projectId}/locations/${location}/repositories`, { format: "DOCKER" }, { queryParams: { repositoryId } });
|
|
56
|
+
await (0, operation_poller_1.pollOperation)({
|
|
57
|
+
apiOrigin: (0, api_1.artifactRegistryDomain)(),
|
|
58
|
+
apiVersion: exports.API_VERSION,
|
|
59
|
+
operationResourceName: res.body.name,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
@@ -20,20 +20,27 @@ function firebasereader(databaseId, schema = exports.DEFAULT_SCHEMA) {
|
|
|
20
20
|
function firebasewriter(databaseId, schema = exports.DEFAULT_SCHEMA) {
|
|
21
21
|
return `firebasewriter_${databaseId}_${schema}`;
|
|
22
22
|
}
|
|
23
|
-
function
|
|
24
|
-
|
|
25
|
-
return [
|
|
26
|
-
`do
|
|
23
|
+
function createRoleBypassRLS(role, superuser) {
|
|
24
|
+
return `do
|
|
27
25
|
$$
|
|
28
26
|
begin
|
|
29
27
|
if not exists (select FROM pg_catalog.pg_roles
|
|
30
|
-
WHERE rolname = '${
|
|
31
|
-
CREATE ROLE "${
|
|
28
|
+
WHERE rolname = '${role}') then
|
|
29
|
+
CREATE ROLE "${role}" WITH ADMIN "${superuser}" BYPASSRLS;
|
|
30
|
+
else
|
|
31
|
+
ALTER ROLE "${role}" BYPASSRLS;
|
|
32
32
|
end if;
|
|
33
33
|
end
|
|
34
34
|
$$
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
;`;
|
|
36
|
+
}
|
|
37
|
+
function ownerRolePermissions(databaseId, superuser, schema) {
|
|
38
|
+
const firebaseOwnerRole = firebaseowner(databaseId, schema);
|
|
39
|
+
return [
|
|
40
|
+
createRoleBypassRLS(firebaseOwnerRole, superuser),
|
|
41
|
+
`REVOKE "${firebaseOwnerRole}" FROM "${exports.CLOUDSQL_SUPER_USER}"`,
|
|
42
|
+
`GRANT "${exports.CLOUDSQL_SUPER_USER}" TO "${firebaseOwnerRole}"`,
|
|
43
|
+
`CREATE SCHEMA IF NOT EXISTS "${schema}" AUTHORIZATION "${firebaseOwnerRole}"`,
|
|
37
44
|
`ALTER SCHEMA "${schema}" OWNER TO "${firebaseOwnerRole}"`,
|
|
38
45
|
`GRANT USAGE ON SCHEMA "${schema}" TO "${firebaseOwnerRole}"`,
|
|
39
46
|
`GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA "${schema}" TO "${firebaseOwnerRole}"`,
|
|
@@ -43,19 +50,10 @@ function ownerRolePermissions(databaseId, superuser, schema) {
|
|
|
43
50
|
function writerRolePermissions(databaseId, superuser, schema) {
|
|
44
51
|
const firebaseWriterRole = firebasewriter(databaseId, schema);
|
|
45
52
|
return [
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
begin
|
|
49
|
-
if not exists (select FROM pg_catalog.pg_roles
|
|
50
|
-
WHERE rolname = '${firebaseWriterRole}') then
|
|
51
|
-
CREATE ROLE "${firebaseWriterRole}" WITH ADMIN "${superuser}";
|
|
52
|
-
end if;
|
|
53
|
-
end
|
|
54
|
-
$$
|
|
55
|
-
;`,
|
|
56
|
-
`GRANT "${firebaseWriterRole}" TO "cloudsqlsuperuser"`,
|
|
53
|
+
createRoleBypassRLS(firebaseWriterRole, superuser),
|
|
54
|
+
`GRANT "${firebaseWriterRole}" TO "${exports.CLOUDSQL_SUPER_USER}"`,
|
|
57
55
|
`GRANT USAGE ON SCHEMA "${schema}" TO "${firebaseWriterRole}"`,
|
|
58
|
-
`GRANT SELECT, INSERT, UPDATE, DELETE
|
|
56
|
+
`GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA "${schema}" TO "${firebaseWriterRole}"`,
|
|
59
57
|
`GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA "${schema}" TO "${firebaseWriterRole}"`,
|
|
60
58
|
`GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA "${schema}" TO "${firebaseWriterRole}"`,
|
|
61
59
|
];
|
|
@@ -63,17 +61,8 @@ function writerRolePermissions(databaseId, superuser, schema) {
|
|
|
63
61
|
function readerRolePermissions(databaseId, superuser, schema) {
|
|
64
62
|
const firebaseReaderRole = firebasereader(databaseId, schema);
|
|
65
63
|
return [
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
begin
|
|
69
|
-
if not exists (select FROM pg_catalog.pg_roles
|
|
70
|
-
WHERE rolname = '${firebaseReaderRole}') then
|
|
71
|
-
CREATE ROLE "${firebaseReaderRole}" WITH ADMIN "${superuser}";
|
|
72
|
-
end if;
|
|
73
|
-
end
|
|
74
|
-
$$
|
|
75
|
-
;`,
|
|
76
|
-
`GRANT "${firebaseReaderRole}" TO "cloudsqlsuperuser"`,
|
|
64
|
+
createRoleBypassRLS(firebaseReaderRole, superuser),
|
|
65
|
+
`GRANT "${firebaseReaderRole}" TO "${exports.CLOUDSQL_SUPER_USER}"`,
|
|
77
66
|
`GRANT USAGE ON SCHEMA "${schema}" TO "${firebaseReaderRole}"`,
|
|
78
67
|
`GRANT SELECT ON ALL TABLES IN SCHEMA "${schema}" TO "${firebaseReaderRole}"`,
|
|
79
68
|
`GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA "${schema}" TO "${firebaseReaderRole}"`,
|
|
@@ -87,7 +76,7 @@ function defaultPermissions(databaseId, schema, ownerRole) {
|
|
|
87
76
|
`ALTER DEFAULT PRIVILEGES
|
|
88
77
|
FOR ROLE "${ownerRole}"
|
|
89
78
|
IN SCHEMA "${schema}"
|
|
90
|
-
GRANT SELECT, INSERT, UPDATE, DELETE
|
|
79
|
+
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO "${firebaseWriterRole}";`,
|
|
91
80
|
`ALTER DEFAULT PRIVILEGES
|
|
92
81
|
FOR ROLE "${ownerRole}"
|
|
93
82
|
IN SCHEMA "${schema}"
|
|
@@ -124,15 +124,10 @@ async function setupSQLPermissions(instanceId, databaseId, schemaInfo, options,
|
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
async function greenFieldSchemaSetup(instanceId, databaseId, schema, options) {
|
|
127
|
-
const revokes = [];
|
|
128
|
-
if (await checkSQLRoleIsGranted(options, instanceId, databaseId, "cloudsqlsuperuser", (0, permissions_1.firebaseowner)(databaseId, schema))) {
|
|
129
|
-
logger_1.logger.warn("Detected cloudsqlsuperuser was previously given to firebase owner, revoking to improve database security.");
|
|
130
|
-
revokes.push(`REVOKE "cloudsqlsuperuser" FROM "${(0, permissions_1.firebaseowner)(databaseId, schema)}"`);
|
|
131
|
-
}
|
|
132
127
|
const user = (await (0, connect_1.getIAMUser)(options)).user;
|
|
133
128
|
const projectNumber = await (0, projectUtils_1.needProjectNumber)(options);
|
|
134
129
|
const { user: fdcP4SAUser } = (0, connect_2.toDatabaseUser)((0, connect_2.getDataConnectP4SA)(projectNumber));
|
|
135
|
-
const sqlRoleSetupCmds = (0, lodash_1.concat)(
|
|
130
|
+
const sqlRoleSetupCmds = (0, lodash_1.concat)([`CREATE SCHEMA IF NOT EXISTS "${schema}"`], (0, permissions_1.ownerRolePermissions)(databaseId, permissions_1.FIREBASE_SUPER_USER, schema), (0, permissions_1.writerRolePermissions)(databaseId, permissions_1.FIREBASE_SUPER_USER, schema), (0, permissions_1.readerRolePermissions)(databaseId, permissions_1.FIREBASE_SUPER_USER, schema), `GRANT "${(0, permissions_1.firebaseowner)(databaseId, schema)}" TO "${user}"`, `REVOKE "${(0, permissions_1.firebaseowner)(databaseId, schema)}" FROM "${fdcP4SAUser}"`, `GRANT "${(0, permissions_1.firebasewriter)(databaseId, schema)}" TO "${fdcP4SAUser}"`, (0, permissions_1.defaultPermissions)(databaseId, schema, (0, permissions_1.firebaseowner)(databaseId, schema)));
|
|
136
131
|
return sqlRoleSetupCmds;
|
|
137
132
|
}
|
|
138
133
|
async function getSchemaMetadata(instanceId, databaseId, schema, options) {
|
|
@@ -224,7 +219,12 @@ async function brownfieldSqlSetup(instanceId, databaseId, schemaInfo, options, s
|
|
|
224
219
|
}
|
|
225
220
|
async function grantRoleTo(options, instanceId, databaseId, role, email, schema = permissions_1.DEFAULT_SCHEMA) {
|
|
226
221
|
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
222
|
+
const projectNumber = await (0, projectUtils_1.needProjectNumber)(options);
|
|
227
223
|
const { user, mode } = (0, connect_2.toDatabaseUser)(email);
|
|
224
|
+
const { user: fdcP4SAUser } = (0, connect_2.toDatabaseUser)((0, connect_2.getDataConnectP4SA)(String(projectNumber)));
|
|
225
|
+
if (role === "owner" && user === fdcP4SAUser) {
|
|
226
|
+
throw new error_1.FirebaseError(`Cannot grant the "owner" role to the Data Connect service agent (${email}). The service agent must only hold data-plane roles (writer/reader).`);
|
|
227
|
+
}
|
|
228
228
|
await cloudSqlAdminClient.createUser(projectId, instanceId, mode, user);
|
|
229
229
|
const fdcSqlRole = exports.fdcSqlRoleMap[role](databaseId, schema);
|
|
230
230
|
await (0, connect_1.executeSqlCmdsAsSuperUser)(options, instanceId, databaseId, [`GRANT "${fdcSqlRole}" TO "${user}"`], false);
|
package/lib/gcp/cloudtasks.js
CHANGED
|
@@ -5,6 +5,7 @@ exports.createQueue = createQueue;
|
|
|
5
5
|
exports.getQueue = getQueue;
|
|
6
6
|
exports.updateQueue = updateQueue;
|
|
7
7
|
exports.upsertQueue = upsertQueue;
|
|
8
|
+
exports.disableQueue = disableQueue;
|
|
8
9
|
exports.purgeQueue = purgeQueue;
|
|
9
10
|
exports.deleteQueue = deleteQueue;
|
|
10
11
|
exports.enqueueTask = enqueueTask;
|
|
@@ -72,6 +73,19 @@ async function upsertQueue(queue) {
|
|
|
72
73
|
throw err;
|
|
73
74
|
}
|
|
74
75
|
}
|
|
76
|
+
async function disableQueue(name) {
|
|
77
|
+
try {
|
|
78
|
+
await module.exports.getQueue(name);
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
const responseError = err;
|
|
82
|
+
if (responseError.context?.response?.statusCode === 404) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
throw err;
|
|
86
|
+
}
|
|
87
|
+
await module.exports.updateQueue({ name, state: "DISABLED" });
|
|
88
|
+
}
|
|
75
89
|
async function purgeQueue(name) {
|
|
76
90
|
await client.post(`${name}:purge`);
|
|
77
91
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.provisionTraceStorage = provisionTraceStorage;
|
|
4
|
+
const api_1 = require("../api");
|
|
5
|
+
const apiv2_1 = require("../apiv2");
|
|
6
|
+
const error_1 = require("../error");
|
|
7
|
+
const API_VERSION = "v2";
|
|
8
|
+
const getTraceClient = () => new apiv2_1.Client({
|
|
9
|
+
urlPrefix: (0, api_1.cloudTraceOrigin)(),
|
|
10
|
+
auth: true,
|
|
11
|
+
apiVersion: API_VERSION,
|
|
12
|
+
});
|
|
13
|
+
async function provisionTraceStorage(projectId) {
|
|
14
|
+
const TRACE_ID = "33fc0d8c45bb4e5cebb29f047931270d";
|
|
15
|
+
const SPAN_ID = "f8fde40b437488e5";
|
|
16
|
+
const now = new Date();
|
|
17
|
+
const later = new Date(now.getTime() + 1000);
|
|
18
|
+
const payload = {
|
|
19
|
+
name: `projects/${projectId}`,
|
|
20
|
+
spans: [
|
|
21
|
+
{
|
|
22
|
+
name: `projects/${projectId}/traces/${TRACE_ID}/spans/${SPAN_ID}`,
|
|
23
|
+
spanId: SPAN_ID,
|
|
24
|
+
displayName: { value: "/welcome" },
|
|
25
|
+
startTime: now.toISOString(),
|
|
26
|
+
endTime: later.toISOString(),
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
};
|
|
30
|
+
try {
|
|
31
|
+
await getTraceClient().post(`/projects/${projectId}/traces:batchWrite`, payload);
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
throw new error_1.FirebaseError(`Failed to provision trace storage for project ${projectId}: ${(0, error_1.getErrMsg)(err)}`, {
|
|
35
|
+
original: (0, error_1.getError)(err),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
package/lib/gcp/run.js
CHANGED
|
@@ -11,6 +11,7 @@ exports.getIamPolicy = getIamPolicy;
|
|
|
11
11
|
exports.setInvokerCreate = setInvokerCreate;
|
|
12
12
|
exports.setInvokerUpdate = setInvokerUpdate;
|
|
13
13
|
exports.fetchServiceLogs = fetchServiceLogs;
|
|
14
|
+
exports.listLocations = listLocations;
|
|
14
15
|
const apiv2_1 = require("../apiv2");
|
|
15
16
|
const error_1 = require("../error");
|
|
16
17
|
const api_1 = require("../api");
|
|
@@ -166,3 +167,7 @@ async function fetchServiceLogs(projectId, serviceId) {
|
|
|
166
167
|
});
|
|
167
168
|
}
|
|
168
169
|
}
|
|
170
|
+
async function listLocations(projectId) {
|
|
171
|
+
const res = await client.get(`/projects/${projectId}/locations`);
|
|
172
|
+
return res.body?.locations?.map((l) => l.locationId) ?? [];
|
|
173
|
+
}
|
package/lib/gcp/runv2.js
CHANGED
|
@@ -28,33 +28,52 @@ const client = new apiv2_1.Client({
|
|
|
28
28
|
apiVersion: exports.API_VERSION,
|
|
29
29
|
});
|
|
30
30
|
(0, metaprogramming_1.assertImplements)();
|
|
31
|
+
const PENDING_BUILD_STATUSES = ["STATUS_UNKNOWN", "PENDING", "QUEUED", "WORKING"];
|
|
31
32
|
async function submitBuild(projectId, location, build) {
|
|
32
|
-
const res = await client.post(`/projects/${projectId}/locations/${location}/builds`, build);
|
|
33
|
-
if (res.
|
|
34
|
-
|
|
33
|
+
const res = await client.post(`/projects/${projectId}/locations/${location}/builds:submit`, build);
|
|
34
|
+
if (res.body?.baseImageWarning) {
|
|
35
|
+
logger_1.logger.warn(res.body.baseImageWarning);
|
|
35
36
|
}
|
|
37
|
+
const cloudBuild = res.body?.buildOperation?.metadata?.build;
|
|
38
|
+
if (!cloudBuild) {
|
|
39
|
+
throw new error_1.FirebaseError("Failed to submit build: no build was returned.");
|
|
40
|
+
}
|
|
41
|
+
let status;
|
|
36
42
|
await (0, operation_poller_1.pollOperation)({
|
|
37
43
|
apiOrigin: (0, api_1.cloudbuildOrigin)(),
|
|
38
44
|
apiVersion: "v1",
|
|
39
|
-
operationResourceName:
|
|
45
|
+
operationResourceName: cloudBuild.name,
|
|
46
|
+
masterTimeout: 30 * 60 * 1000,
|
|
47
|
+
maxBackoff: 10000,
|
|
48
|
+
doneFn: (b) => {
|
|
49
|
+
status = b?.status;
|
|
50
|
+
return !b?.status || !PENDING_BUILD_STATUSES.includes(b.status);
|
|
51
|
+
},
|
|
40
52
|
});
|
|
53
|
+
if (status !== "SUCCESS") {
|
|
54
|
+
throw new error_1.FirebaseError(`Cloud Build failed with status ${status ?? "UNKNOWN"}. View the build logs at ${cloudBuild.logUrl ?? ""}`);
|
|
55
|
+
}
|
|
41
56
|
}
|
|
42
|
-
async function updateService(service) {
|
|
43
|
-
|
|
44
|
-
|
|
57
|
+
async function updateService(service, opts = {}) {
|
|
58
|
+
let updateMask = opts.updateMask;
|
|
59
|
+
if (!updateMask) {
|
|
60
|
+
updateMask = proto.fieldMasks(service, "labels", "annotations", "tags");
|
|
61
|
+
updateMask.push("template.revision");
|
|
62
|
+
}
|
|
45
63
|
const res = await client.patch(service.name, service, {
|
|
46
64
|
queryParams: {
|
|
47
|
-
updateMask:
|
|
65
|
+
updateMask: updateMask.join(","),
|
|
48
66
|
},
|
|
49
67
|
});
|
|
50
68
|
const svc = await (0, operation_poller_1.pollOperation)({
|
|
51
69
|
apiOrigin: (0, api_1.runOrigin)(),
|
|
52
70
|
apiVersion: exports.API_VERSION,
|
|
53
71
|
operationResourceName: res.body.name,
|
|
72
|
+
masterTimeout: opts.pollTimeoutMs,
|
|
54
73
|
});
|
|
55
74
|
return svc;
|
|
56
75
|
}
|
|
57
|
-
async function createService(projectId, location, serviceId, service) {
|
|
76
|
+
async function createService(projectId, location, serviceId, service, opts = {}) {
|
|
58
77
|
const { name, ...serviceBody } = service;
|
|
59
78
|
const res = await client.post(`/projects/${projectId}/locations/${location}/services`, serviceBody, {
|
|
60
79
|
queryParams: {
|
|
@@ -65,6 +84,7 @@ async function createService(projectId, location, serviceId, service) {
|
|
|
65
84
|
apiOrigin: (0, api_1.runOrigin)(),
|
|
66
85
|
apiVersion: exports.API_VERSION,
|
|
67
86
|
operationResourceName: res.body.name,
|
|
87
|
+
masterTimeout: opts.pollTimeoutMs,
|
|
68
88
|
});
|
|
69
89
|
return svc;
|
|
70
90
|
}
|
|
@@ -82,7 +102,7 @@ async function getService(projectId, location, serviceId) {
|
|
|
82
102
|
const res = await client.get(name);
|
|
83
103
|
return res.body;
|
|
84
104
|
}
|
|
85
|
-
async function listServices(projectId) {
|
|
105
|
+
async function listServices(projectId, functionsOnly = true) {
|
|
86
106
|
const allServices = [];
|
|
87
107
|
let pageToken = undefined;
|
|
88
108
|
do {
|
|
@@ -98,7 +118,8 @@ async function listServices(projectId) {
|
|
|
98
118
|
}
|
|
99
119
|
if (res.body.services) {
|
|
100
120
|
for (const service of res.body.services) {
|
|
101
|
-
if (
|
|
121
|
+
if (!functionsOnly ||
|
|
122
|
+
service.labels?.[exports.CLIENT_NAME_LABEL] === "cloud-functions" ||
|
|
102
123
|
service.labels?.[exports.CLIENT_NAME_LABEL] === "cloudfunctions" ||
|
|
103
124
|
service.labels?.[exports.CLIENT_NAME_LABEL] === "firebase-functions") {
|
|
104
125
|
allServices.push(service);
|
package/lib/gcp/storage.js
CHANGED
|
@@ -118,9 +118,11 @@ async function getBucket(bucketName) {
|
|
|
118
118
|
return result.body;
|
|
119
119
|
}
|
|
120
120
|
catch (err) {
|
|
121
|
-
|
|
121
|
+
const error = (0, error_1.getError)(err);
|
|
122
|
+
logger_1.logger.debug(error);
|
|
122
123
|
throw new error_1.FirebaseError("Failed to obtain the storage bucket", {
|
|
123
|
-
original:
|
|
124
|
+
original: error,
|
|
125
|
+
status: (0, error_1.getErrStatus)(err),
|
|
124
126
|
});
|
|
125
127
|
}
|
|
126
128
|
}
|
|
@@ -147,14 +149,16 @@ async function createBucket(projectId, req, projectPrivate) {
|
|
|
147
149
|
async function patchBucket(bucketName, metadata) {
|
|
148
150
|
try {
|
|
149
151
|
const localAPIClient = new apiv2_1.Client({ urlPrefix: (0, api_1.storageOrigin)() });
|
|
150
|
-
const mask = (0, proto_1.fieldMasks)(metadata, "labels", "acl", "defaultObjectAcl", "lifecycle");
|
|
152
|
+
const mask = (0, proto_1.fieldMasks)(metadata, "labels", "acl", "defaultObjectAcl", "lifecycle", "cors");
|
|
151
153
|
const result = await localAPIClient.patch(`/storage/v1/b/${bucketName}`, metadata, { queryParams: { updateMask: mask.join(",") } });
|
|
152
154
|
return result.body;
|
|
153
155
|
}
|
|
154
156
|
catch (err) {
|
|
155
|
-
|
|
157
|
+
const error = (0, error_1.getError)(err);
|
|
158
|
+
logger_1.logger.debug(error);
|
|
156
159
|
throw new error_1.FirebaseError("Failed to patch the storage bucket", {
|
|
157
|
-
original:
|
|
160
|
+
original: error,
|
|
161
|
+
status: (0, error_1.getErrStatus)(err),
|
|
158
162
|
});
|
|
159
163
|
}
|
|
160
164
|
}
|