Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add debug mode #992

Merged
merged 10 commits into from
Oct 18, 2021
Merged

Add debug mode #992

merged 10 commits into from
Oct 18, 2021

Conversation

taeold
Copy link
Contributor

@taeold taeold commented Oct 14, 2021

Debug mode is intended to be used by the Functions Emulator to enable/disable certain aspect of the Functions SDK. Debug mode allows the Functions SDK to operate in development friendly way without the need to monkey-patch the Functions SDK. For example, auth or App Check token verification can be disabled during development to make Functions SDK compatible with the Auth Emulator.

This feature is intended for internal use-cases and won't expose any public interfaces. No one outside the Firebase team should use it, and if they do, we can't promise any stability or feature support.

@google-cla google-cla bot added the cla: yes label Oct 14, 2021
@taeold taeold requested review from colerogers and inlined October 15, 2021 03:28
Copy link
Contributor

@colerogers colerogers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks cool 😎

Copy link
Contributor

@colerogers colerogers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks cool 😎

src/debug.ts Outdated
// SOFTWARE.

// Do NOT turn on a debug feature in production.
const debugMode = process.env.FIREBASE_DEBUG_MODE === 'true';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we also check that FIREBASE_DEBUG_FEATURES exists? Is having two env vars just used for some security?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I thought extra, repeated step makes it slightly harder to accidentally invoke a debug mode.

Another thing I was trying to do here is to make sure that we minimize the number of environment variable read. Apparently, reading env var is not the cheapest thing in Nodejs, so this guard ensures that we issue env var per request only when the debug mode is turned on.

@taeold taeold marked this pull request as ready for review October 15, 2021 19:35
src/debug.ts Outdated
const debugMode = process.env.FIREBASE_DEBUG_MODE === 'true';

interface DebugFeatures {
skipCallableTokenVerification?: boolean;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we also will have a disableTimeouts, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, but I plan on adding it as needed.

src/debug.ts Outdated
@@ -0,0 +1,52 @@
// The MIT License (MIT)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this should go into src/common since most of the stuff under src/ will go into v1 in the next major change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great call. Moving.

@taeold taeold merged commit ede96e6 into master Oct 18, 2021
@taeold taeold deleted the dl-debug-mode branch October 18, 2021 22:39
taeold added a commit that referenced this pull request Oct 28, 2021
To replace monkey-patching of the Firebase Functions SDK in the Functions Emulator ([code](https://github.com/firebase/firebase-tools/blob/c2feb0836f6f64236e117f2906ef6083840e212b/src/emulator/functionsEmulatorRuntime.ts#L401-L496)), we provide native support for bypassing token verification for `onCall` handlers.

Using the new debug mode introduced in #992, Auth/App Check token included in the request will be decoded but no verified.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants