Skip to content

Merge App Check feature branch #4833

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

Merged
merged 6 commits into from
Apr 27, 2021
Merged

Merge App Check feature branch #4833

merged 6 commits into from
Apr 27, 2021

Conversation

hsubox76
Copy link
Contributor

Merge change that adds App Check package as well as App Check enabled versions of functions, storage, and database.

@changeset-bot
Copy link

changeset-bot bot commented Apr 26, 2021

⚠️ No Changeset found

Latest commit: 770fdf9

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Apr 26, 2021

Binary Size Report

Affected SDKs

  • @firebase/analytics

    Type Base (ba2b11f) Head (c93b1cf) Diff
    esm2017 ? 18.7 kB ? (?)
    main ? 24.2 kB ? (?)
    module ? 23.4 kB ? (?)
  • @firebase/api-documenter

    Type Base (ba2b11f) Head (c93b1cf) Diff
    main ? 3.72 kB ? (?)
  • @firebase/app

    Type Base (ba2b11f) Head (c93b1cf) Diff
    browser ? 10.8 kB ? (?)
    esm2017 ? 9.57 kB ? (?)
    lite ? 8.88 kB ? (?)
    lite-esm2017 ? 7.87 kB ? (?)
    main ? 9.93 kB ? (?)
    module ? 10.8 kB ? (?)
    react-native ? 9.64 kB ? (?)
  • @firebase/auth

    Type Base (ba2b11f) Head (c93b1cf) Diff
    browser ? 181 kB ? (?)
    main ? 181 kB ? (?)
    module ? 181 kB ? (?)
  • @firebase/component

    Type Base (ba2b11f) Head (c93b1cf) Diff
    browser ? 7.24 kB ? (?)
    esm2017 ? 5.55 kB ? (?)
    main ? 7.57 kB ? (?)
    module ? 7.24 kB ? (?)
  • @firebase/database

    Type Base (ba2b11f) Head (c93b1cf) Diff
    browser ? 295 kB ? (?)
    esm2017 ? 264 kB ? (?)
    main ? 298 kB ? (?)
    module ? 295 kB ? (?)
  • @firebase/database-compat

    Type Base (ba2b11f) Head (c93b1cf) Diff
    browser ? 86.3 kB ? (?)
    main ? 102 kB ? (?)
    module ? 86.3 kB ? (?)
  • @firebase/database-exp

    Type Base (ba2b11f) Head (c93b1cf) Diff
    browser ? 245 kB ? (?)
    main ? 277 kB ? (?)
    module ? 245 kB ? (?)
  • @firebase/firestore

    Type Base (ba2b11f) Head (c93b1cf) Diff
    browser ? 283 kB ? (?)
    esm2017 ? 225 kB ? (?)
    main ? 529 kB ? (?)
    module ? 283 kB ? (?)
    react-native ? 225 kB ? (?)
  • @firebase/firestore-compat

    Type Base (ba2b11f) Head (c93b1cf) Diff
    browser ? 28.4 kB ? (?)
    main ? 37.4 kB ? (?)
    module ? 28.4 kB ? (?)
    react-native ? 28.1 kB ? (?)
  • @firebase/firestore-exp

    Type Base (ba2b11f) Head (c93b1cf) Diff
    browser ? 223 kB ? (?)
    main ? 505 kB ? (?)
    module ? 223 kB ? (?)
    react-native ? 223 kB ? (?)
  • @firebase/firestore-lite

    Type Base (ba2b11f) Head (c93b1cf) Diff
    browser ? 71.4 kB ? (?)
    main ? 145 kB ? (?)
    module ? 71.4 kB ? (?)
    react-native ? 71.6 kB ? (?)
  • @firebase/firestore/bundle

    Type Base (ba2b11f) Head (c93b1cf) Diff
    browser ? 289 kB ? (?)
    esm2017 ? 175 kB ? (?)
    main ? 525 kB ? (?)
    module ? 289 kB ? (?)
    react-native ? 175 kB ? (?)
  • @firebase/firestore/memory

    Type Base (ba2b11f) Head (c93b1cf) Diff
    browser ? 215 kB ? (?)
    esm2017 ? 171 kB ? (?)
    main ? 323 kB ? (?)
    module ? 215 kB ? (?)
    react-native ? 171 kB ? (?)
  • @firebase/firestore/memory-bundle

    Type Base (ba2b11f) Head (c93b1cf) Diff
    browser ? 223 kB ? (?)
    esm2017 ? 175 kB ? (?)
    main ? 320 kB ? (?)
    module ? 223 kB ? (?)
    react-native ? 175 kB ? (?)
  • @firebase/functions

    Type Base (ba2b11f) Head (c93b1cf) Diff
    browser ? 10.6 kB ? (?)
    esm2017 ? 8.15 kB ? (?)
    main ? 11.0 kB ? (?)
    module ? 10.6 kB ? (?)
  • @firebase/installations

    Type Base (ba2b11f) Head (c93b1cf) Diff
    esm2017 ? 16.6 kB ? (?)
    main ? 22.2 kB ? (?)
    module ? 21.6 kB ? (?)
  • @firebase/logger

    Type Base (ba2b11f) Head (c93b1cf) Diff
    esm2017 ? 3.25 kB ? (?)
    main ? 5.38 kB ? (?)
    module ? 4.65 kB ? (?)
  • @firebase/messaging

    Type Base (ba2b11f) Head (c93b1cf) Diff
    esm2017 ? 26.2 kB ? (?)
    main ? 34.9 kB ? (?)
    module ? 34.4 kB ? (?)
  • @firebase/performance

    Type Base (ba2b11f) Head (c93b1cf) Diff
    browser ? 27.7 kB ? (?)
    esm2017 ? 25.9 kB ? (?)
    main ? 28.0 kB ? (?)
    module ? 27.7 kB ? (?)
  • @firebase/polyfill

    Type Base (ba2b11f) Head (c93b1cf) Diff
    main ? 747 B ? (?)
    module ? 705 B ? (?)
  • @firebase/remote-config

    Type Base (ba2b11f) Head (c93b1cf) Diff
    browser ? 22.4 kB ? (?)
    esm2017 ? 17.4 kB ? (?)
    main ? 23.0 kB ? (?)
    module ? 22.4 kB ? (?)
  • @firebase/rules-unit-testing

    Type Base (ba2b11f) Head (c93b1cf) Diff
    main ? 12.6 kB ? (?)
  • @firebase/storage

    Type Base (ba2b11f) Head (c93b1cf) Diff
    browser ? 63.4 kB ? (?)
    esm2017 ? 54.6 kB ? (?)
    main ? 63.8 kB ? (?)
    module ? 63.4 kB ? (?)
  • @firebase/storage-compat

    Type Base (ba2b11f) Head (c93b1cf) Diff
    browser ? 10.2 kB ? (?)
    main ? 29.1 kB ? (?)
    module ? 10.2 kB ? (?)
  • @firebase/storage-exp

    Type Base (ba2b11f) Head (c93b1cf) Diff
    browser ? 51.5 kB ? (?)
    main ? 52.6 kB ? (?)
    module ? 51.5 kB ? (?)
  • @firebase/util

    Type Base (ba2b11f) Head (c93b1cf) Diff
    browser ? 20.2 kB ? (?)
    esm2017 ? 19.0 kB ? (?)
    main ? 24.6 kB ? (?)
    module ? 20.2 kB ? (?)
  • @firebase/webchannel-wrapper

    Type Base (ba2b11f) Head (c93b1cf) Diff
    esm2017 ? 39.5 kB ? (?)
    main ? 46.9 kB ? (?)
    module ? 40.8 kB ? (?)
  • firebase

    Click to show 15 binary size changes.
    Type Base (ba2b11f) Head (c93b1cf) Diff
    firebase-analytics.js ? 35.8 kB ? (?)
    firebase-app.js ? 21.2 kB ? (?)
    firebase-auth.js ? 177 kB ? (?)
    firebase-database.js ? 186 kB ? (?)
    firebase-firestore.js ? 328 kB ? (?)
    firebase-firestore.memory.js ? 262 kB ? (?)
    firebase-functions.js ? 10.7 kB ? (?)
    firebase-installations.js ? 19.3 kB ? (?)
    firebase-messaging.js ? 41.0 kB ? (?)
    firebase-performance-standalone.es2017.js ? 72.9 kB ? (?)
    firebase-performance-standalone.js ? 49.2 kB ? (?)
    firebase-performance.js ? 38.3 kB ? (?)
    firebase-remote-config.js ? 36.9 kB ? (?)
    firebase-storage.js ? 41.6 kB ? (?)
    firebase.js ? 873 kB ? (?)

Test Logs

@@ -154,6 +166,12 @@ export class WebSocketConnection implements Transport {
}
};

if (this.nodeAdmin) {
options.headers['Authorization'] = this.authToken || '';
Copy link
Member

Choose a reason for hiding this comment

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

Do we not need the Authorization header if it's the web client?

Copy link
Contributor Author

@hsubox76 hsubox76 Apr 26, 2021

Choose a reason for hiding this comment

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

If I am reading correctly, this entire thing is inside the if (isNodeSdk()) {} block starting on line 159 and this.nodeAdmin means it's the Admin SDK and not the client Node SDK. Which also means, in light of the comment above about App Check not working in Node, maybe the appcheck header doesn't need to be added in this block at all.

Copy link
Member

Choose a reason for hiding this comment

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

Do we not need the header for the client Node SDK?
Should we send the dummy token for AppCheck in Nodejs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will address this in the follow-up PR that also includes Node debug token support.

* limitations under the License.
*/

import '@firebase/app-check';
Copy link
Member

Choose a reason for hiding this comment

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

We should not add AppCheck to the firebase package until we are ready to release.

Copy link
Member

Choose a reason for hiding this comment

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

nvm, I just realized you have another PR to address this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess CI won't pass if this isn't taken care of so will address in this PR.

@@ -104,7 +105,13 @@ export function sharedErrorHandler(
): FirebaseStorageError {
let newErr;
if (xhr.getStatus() === 401) {
newErr = unauthenticated();
if (
xhr.getResponseText().includes('Firebase App Check token is invalid')
Copy link
Member

Choose a reason for hiding this comment

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

Is there a code that we can check against?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could make this string into a local constant but it would have to be manually kept in sync. This is where the string comes from in the backend, we don't have any access to it here. The status code is 401 which is shared with some other errors. https://source.corp.google.com/piper///depot/google3/java/com/google/firebase/storage/authorization/appcheck/AppCheckAuthorizer.java;rcl=369703237;l=26

Copy link
Member

Choose a reason for hiding this comment

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

I was hoping server sends back a json object with a code property that we can check against. The error text is subject to change in nature, so I'm worried we will get out of sync at one point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm. Can you add a comment to the above linked file to state that the text of the error message cannot be changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a comment.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Apr 27, 2021

Size Analysis Report

Affected Products

No changes between base commit (ba2b11f) and head commit (c93b1cf).

Comment on lines 42 to 45
const appCheckProvider =
variant === 'node'
? undefined
: container.getProvider('app-check-internal');
Copy link
Member

Choose a reason for hiding this comment

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

I think in practice it doesn't make any difference because appCheckProvider.get() will not resolve in Nodejs and database will just work without AppCheck. And since it is a shared code, I would actually prefer to not have the special handling for nodejs.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would also prefer that we simplify this again and either call container.getProvider('app-check') directly and rely on the fact that Node will return undefined here or pass a "isNode" boolean into registerDatabase (with different values from index.ts and index.node.ts).

The question is though if the debug AppCheck will ever work in Node. If that is the case then we should just let container decide if AppCheck is available.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted to simple container.getProvider.

Copy link
Member

Choose a reason for hiding this comment

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

Debug AppCheck can work in Node, we just need to read from globalThis ( need a polyfill) instead of self. I think it'll be useful for server side rendering, though it sounds like an abuse of the debug token.
Also custom providers should already be working in Nodejs.

Therefore, I think we should

  1. Read debug token from globalThis. We need to define a polyfill for globalThis, probably in @firebase/util. Here is a reference implementation.
  2. Always pass the AppCheckProvider database

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, will make a separate PR for Node support after merge. Reverting other Node-related change above.

@hsubox76 hsubox76 force-pushed the ch-appcheck-feature branch from 0568ba5 to b15a4ee Compare April 27, 2021 18:43
@hsubox76 hsubox76 merged commit 919413c into master Apr 27, 2021
@hsubox76 hsubox76 deleted the ch-appcheck-feature branch April 27, 2021 23:15
@firebase firebase locked and limited conversation to collaborators May 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants