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

Support user defined jwt auth and sdk functions #405

Merged

Conversation

jairad26
Copy link
Member

@jairad26 jairad26 commented Oct 1, 2024

Description

This PR adds jwt auth support for the modus runtime. This works by specifying a golang deserializable map of RSA PEMs as environment variables, named MODUS_RSA_PEMS. When available, the runtime will force any incoming api request to be verified by one of the specified RSA keys. Then the claims from the jwt are stored in the environment variables, to be accessed by the user via sdk functions. However, the dev and production flows are different.

Dev Flow

If in Dev mode, and no RSA keys are provided, but a JWT is provided, we will assume the user is attempting to test their jwt claims, without going through the process of verification & refreshing the tokens (however if this turns out to be a problem we can remove this functionality easily). Therefore we will run a ParseUnverified. to retrieve the claims and store.
WARNING: Please do not run your runtime in dev mode in a production environment.

Prod Flow

If in Prod mode, and no RSA keys are provided, no matter what the request will be allowed through, and the JWT will NOT be stored.

SDK Functions

the user is provided with auth.GetJWTClaims<T> as the function to retrieve the claims. It allows the user to pass in structure to deserialize the claims json string into, or just pass string for T to get the raw claims string.

@jairad26 jairad26 requested a review from a team as a code owner October 1, 2024 22:44
Copy link

linear bot commented Oct 1, 2024

@jairad26 jairad26 marked this pull request as draft October 4, 2024 17:05
@mattjohnsonpint mattjohnsonpint added this to the v0.13.0 milestone Oct 8, 2024
runtime/middleware/jwt.go Fixed Show fixed Hide fixed
@jairad26 jairad26 marked this pull request as ready for review October 9, 2024 05:27
@jairad26 jairad26 changed the title read jwt and add to wazero env vars for auth support user defined jwt auth verification and supplementary sdk functions (#405) Oct 9, 2024
@jairad26 jairad26 changed the title support user defined jwt auth verification and supplementary sdk functions (#405) support user defined jwt auth verification and supplementary sdk functions Oct 9, 2024
@jairad26 jairad26 changed the title support user defined jwt auth verification and supplementary sdk functions Support user defined jwt auth and sdk functions Oct 9, 2024
@mattjohnsonpint
Copy link
Member

mattjohnsonpint commented Oct 9, 2024

Just a note about the prod workflow comment:

If in Prod mode, and no RSA keys are provided, no matter what the request will be allowed through ...

That's fine for now, but we'll want to change this soon when we add endpoint configuration to the manifest, such that if an endpoint is configured for authentication, and it's running in a non-dev environment without keys supplied, that we log a fatal error and exit - because such a configuration should not be allowed.

Alternatively, we could not exit, but just not start that endpoint. We'll have to see which makes the most sense.

@mattjohnsonpint
Copy link
Member

Also a note about:

WARNING: Please do not run your runtime in dev mode in a production environment.

Agreed. And this should already be mitigated by #439

runtime/middleware/jwt.go Outdated Show resolved Hide resolved
runtime/middleware/jwt.go Outdated Show resolved Hide resolved
runtime/middleware/jwt.go Outdated Show resolved Hide resolved
runtime/middleware/jwt.go Show resolved Hide resolved
runtime/middleware/jwt.go Outdated Show resolved Hide resolved
sdk/assemblyscript/examples/auth/assembly/index.ts Outdated Show resolved Hide resolved
sdk/assemblyscript/examples/auth/package.json Outdated Show resolved Hide resolved
sdk/assemblyscript/src/assembly/auth.ts Outdated Show resolved Hide resolved
sdk/go/examples/auth/main.go Show resolved Hide resolved
sdk/go/pkg/auth/jwt.go Outdated Show resolved Hide resolved
runtime/middleware/jwt.go Outdated Show resolved Hide resolved
runtime/middleware/jwt.go Outdated Show resolved Hide resolved
runtime/middleware/jwt.go Outdated Show resolved Hide resolved
runtime/middleware/jwt.go Outdated Show resolved Hide resolved
@jairad26 jairad26 enabled auto-merge (squash) October 10, 2024 00:56
runtime/middleware/jwt.go Outdated Show resolved Hide resolved
runtime/middleware/jwt.go Outdated Show resolved Hide resolved
runtime/main.go Outdated Show resolved Hide resolved
runtime/middleware/jwt.go Outdated Show resolved Hide resolved
runtime/middleware/jwt.go Outdated Show resolved Hide resolved
runtime/middleware/jwt.go Show resolved Hide resolved
runtime/middleware/jwt.go Show resolved Hide resolved
runtime/middleware/jwt.go Show resolved Hide resolved
@jairad26 jairad26 merged commit b9356f2 into main Oct 10, 2024
81 checks passed
@jairad26 jairad26 deleted the jai/hyp-2019-pass-jwt-auth-claims-to-functions-via-env-vars branch October 10, 2024 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants