[go: nahoru, domu]

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

feat(appcheck): Add App Check token verification #484

Merged
merged 20 commits into from
Oct 26, 2022

Conversation

bamnet
Copy link
Contributor
@bamnet bamnet commented Feb 6, 2022

Add an appcheck module which provides the ability to verify tokens, closing #483.

Returns a token if valid and error otherwise, similar to the implementation in Node SDK. PTAL and let me know what you think!

Sample usage:

client, err := app.AppCheck(context.Background())
if err != nil {
	log.Fatalf("error getting AppCheck client: %v\n", err)
}

token := "..."
_, err := client.VerifyToken(token)
if err != nil {
	log.Fatalf("error verifying token: %v\n", err)
	return
}

RELEASE NOTE: Added a new app_check.verify_token() API to verify App Check tokens.

Passes very basic tests in a sample app, but needs more work.
The auth token doesn't represent the app check token, particularly the aud[].
All keys are borrowed from the Firebase Admin Node SDK.
Coverage is now ~87% which is pretty good I think.  The remaining code is difficult to test because it overlaps with functionality built in to the JWT package.
@bamnet bamnet changed the title feat: Add App Check token verification (#483) feat: Add App Check token verification Feb 6, 2022
@lahirumaramba lahirumaramba self-requested a review February 8, 2022 19:32
@lahirumaramba lahirumaramba self-assigned this Feb 8, 2022
@bamnet
Copy link
Contributor Author
bamnet commented Feb 9, 2022

Thanks for kicking off those workflows! I fixed up the lint and go1.16 errors.

The go1.12 error is tricky, it looks like I'll need to rewrite the JWKS library, the general purpose one requires crypto/ed25519 which wasn't introduced until 1.13 [ref].

Alternatively, we could bump go.mod from 1.11 => 1.13, but I'm not sure how critical go1.11/1.12 is to this library (perhaps an artifact of supporting all GAE standard platforms).

@MicahParks
Copy link

@bamnet I'd be happy to make a Go 1.12 compatible branch or fork of github.com/MicahParks/keyfunc, if you'd like.

However, there would be at least a couple of drawbacks:

  • The github.com/golang-jwt/jwt project could not be used. Neither the /v3 nor /v4 module support Go 1.12.
    • github.com/form3tech-oss/jwt-go could be used, but that's archived.
  • The exported error types wouldn't be available for unwrapping. (Since that was introduced in 1.13.)

@bamnet
Copy link
Contributor Author
bamnet commented Feb 9, 2022

Thanks for the offer @MicahParks! I am slowly resigning to the fact that the best solution here is likely to roll our own mini-JWT/JWKS implementation here. After locally patching keyfunc I realized the bigger golang-jwt problem dependency problem and, if we're doing out own JWTs, it's not that much work to add some very specific JWKS support.

There's some code I can likely extract from the existing auth package provided here, which already rolls it's own very specific JWT code.

@lahirumaramba
Copy link
Member

Hi @bamnet Thank you so much for your contribution! This is on my radar and I plan to review the code this week. Thank you for fixing the lint errors.

Re: Go 1.12 compatibility: We prefer to stay aligned with the Google Cloud Go clients and it seems like the minimum requirement is still Go 1.11. Let me discuss this with the team and get back to you.

In the meantime, I found this auth0 go module that seems to support jwks. I didn't check to see if it works on 1.11 though.

Writing our own key-fetcher also sounds like a reasonable approach... please refer to the current implementation in auth/token_verifier.go to see if we can reuse/refactor components from there.

We need to get the public API approved (an internal process) before merging this change. I will get that process started.

Thank you for your patience!

@lahirumaramba
Copy link
Member
lahirumaramba commented Mar 4, 2022

@bamnet Thank you for your patience! We have decided to update the minimum Go version to 1.15. See #485.
Once that is merged, we should be able to continue with this PR.

@bamnet
Copy link
Contributor Author
bamnet commented Mar 5, 2022

Woohoo, thanks for the update! I'll stay tuned for the go version bump.

@lahirumaramba
Copy link
Member

Woohoo, thanks for the update! I'll stay tuned for the go version bump.

@bamnet changes are now in the dev branch. I have updated the CI workflows as part of the version bump.
Please rebase this PR with the dev branch and that will trigger the CI tests again. Thank you!

@bamnet
Copy link
Contributor Author
bamnet commented Mar 9, 2022

Done, PTAL / kick off workflows!

@bamnet
Copy link
Contributor Author
bamnet commented Apr 11, 2022

FYI - I've re-based with the latest dev branch to pull in the latest releases.

@lahirumaramba
Copy link
Member

Thank you @bamnet! The next step is to complete the internal review process for the new public API. I will start the process later this week. Please note that this might take a few weeks to complete. Once the API is approved, we can merge this PR. I will track the progress here. Thanks again for your patience.

@bamnet
Copy link
Contributor Author
bamnet commented Jun 14, 2022

Hi @lahirumaramba, I just wanted to check in and see if there's anything I can do to move the API process forward? Happy to help fill out any documentation, etc.

@wesselvanderlinden
Copy link
wesselvanderlinden commented Aug 4, 2022

What is the status of this PR? Can this be merged? We really need this, can I help in any way?

@wesselvanderlinden
Copy link

@lahirumaramba any progress? :)

@bamnet
Copy link
Contributor Author
bamnet commented Oct 21, 2022

FYI - I've rebased with the latest dev branch to pull in all the work from the past 6 months. PTAL.

Copy link
Member
@lahirumaramba lahirumaramba left a comment

Choose a reason for hiding this comment

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

Hey @bamnet Thank you for your contribution and thank you so much for your patience! We just completed the internal review process for this API.

The changes looks good just need a few things to address before we can merge this. I have left a few comments. Let me know if you have any questions. Thanks!

appcheck/appcheck.go Show resolved Hide resolved
appcheck/appcheck.go Outdated Show resolved Hide resolved
appcheck/appcheck.go Outdated Show resolved Hide resolved
appcheck/appcheck.go Outdated Show resolved Hide resolved
// NewClient creates a new App Check client.
func NewClient(ctx context.Context, conf *internal.AppCheckConfig) (*Client, error) {
// TODO: Add support for overriding the HTTP client using the App one.
jwks, err := keyfunc.Get(conf.JWKSUrl, keyfunc.Options{
Copy link
Member

Choose a reason for hiding this comment

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

Do you know if keyfunc supports overriding the http client?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, keyfunc.Options accepts an http.Client. How should we expose that option to developers?

appcheck/appcheck.go Show resolved Hide resolved
firebase.go Outdated Show resolved Hide resolved
appcheck/appcheck.go Outdated Show resolved Hide resolved
@bamnet
Copy link
Contributor Author
bamnet commented Oct 21, 2022

Thanks for all the feedback. Incorporated ~all of it, LMK what I missed.

appcheck/appcheck.go Outdated Show resolved Hide resolved

// DecodedAppCheckToken represents a verified App Check token.
//
// DecodedAppCheckToken provides typed accessors to the common JWT fields such as Audience (aud) // and ExpiresAt (exp).
Copy link
Member

Choose a reason for hiding this comment

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

Looks like we are missing a new line after ... fields such as Audience (aud)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

I also changed DecodedAppCheckToken to use ExpiresAt which matches this documentation and mirrors the IssuedAt instead of the Expires we had earlier. LMK if I should revert back to Expires and fix the docstring.

@lahirumaramba
Copy link
Member

Hi @kevinthecheung could we get a review on the reference docs, please? Thank you!

appcheck/appcheck.go Outdated Show resolved Hide resolved
Co-authored-by: Kevin Cheung <kevinthecheung@users.noreply.github.com>
@bamnet
Copy link
Contributor Author
bamnet commented Oct 26, 2022

Thanks for the review @kevinthecheung!

@lahirumaramba back over to you?

@lahirumaramba
Copy link
Member
lahirumaramba commented Oct 26, 2022

Thank you, @bamnet !
We will include this feature in the next release of Admin Go SDK.

@lahirumaramba lahirumaramba merged commit 606008d into firebase:dev Oct 26, 2022
@lahirumaramba lahirumaramba changed the title feat: Add App Check token verification feat(appcheck): Add App Check token verification Oct 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants