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: add mfa verification postgres hook #1314

Merged
merged 46 commits into from
Nov 30, 2023
Merged

Conversation

J0
Copy link
Contributor

@J0 J0 commented Nov 20, 2023

What kind of change does this PR introduce?

Proof of concept hook for MFA Verification. With this hook, developers can introduce additional conditions around when to accept/reject an MFA verification (e.g. log a developer out after a certain number of attempts).

We distinguish this from the existing Webhooks implementation via introduction of hooks package which will contain future Hook related structs, constants, and utility methods.

For the most part we leverage existing Postgres capabilities - as far as possible we will return the PostgreSQL error codes for debugging and use Postgres in-built timeouts to ensure hte hook doesn't overrun.

Testing

The MFA Verification Hook test suite does not guarantee accurate status codes - the test setup (to enroll factors and create a challenge after signup) requires some setup. It is reliant on signUpAndVerify which gets the dev to AAL2 and takes time to refactor.

As such, most of the cases were manually tested in addition to the current loose check of checking for the absence of an access token. Further edits will be made in GMT +8 morning to properly check for the http status codes in the tests.

Also, since supabase_auth_admin cannot create functions on the public schema we create the functions on the auth schema for testing. We typically discourage this on the Supabase platform but in theory there should be no issue when dealing with GoTrue (the OSS project). Will spend a short amount of time looking into alternatives tomorrow.

Additional Notes

Response schema checks are left out of this PR as they don't seem to serve as much benefit for this particular extensibility point and will probably bloat the PR a little with the introduction of a new library

internal/api/auth_hooks.go Outdated Show resolved Hide resolved
internal/api/auth_hooks.go Outdated Show resolved Hide resolved
internal/api/auth_hooks.go Outdated Show resolved Hide resolved
internal/api/auth_hooks.go Outdated Show resolved Hide resolved
internal/api/auth_hooks.go Outdated Show resolved Hide resolved
internal/api/mfa.go Outdated Show resolved Hide resolved
internal/api/mfa.go Outdated Show resolved Hide resolved
internal/conf/configuration.go Outdated Show resolved Hide resolved
internal/conf/configuration_test.go Show resolved Hide resolved
internal/conf/configuration_test.go Outdated Show resolved Hide resolved
internal/api/auth_hooks.go Outdated Show resolved Hide resolved
internal/api/auth_hooks.go Outdated Show resolved Hide resolved
internal/api/auth_hooks.go Outdated Show resolved Hide resolved
internal/api/auth_hooks.go Outdated Show resolved Hide resolved
@J0 J0 changed the title [wip]: feat: add mfa verification postgres hook poc feat: add mfa verification postgres hook poc Nov 27, 2023
J0 added a commit that referenced this pull request Nov 28, 2023
## What kind of change does this PR introduce?

The mfa tests are hard to read. There's also a lot of redundant code
which makes testing for hooks quite a bit harder. This PR aims to remove
some of the redundancy so that it's easier to write the tests for #1314

Main changes include
- Splitting out `enrollAndVerify` into `enroll` and `verify` 
-  Using suite specific constants
-  Packaging duplicated setup code

---------

Co-authored-by: joel@joellee.org <joel@joellee.org>
@J0 J0 marked this pull request as ready for review November 29, 2023 17:48
internal/api/mfa.go Outdated Show resolved Hide resolved
internal/api/mfa.go Show resolved Hide resolved
internal/api/mfa.go Outdated Show resolved Hide resolved
internal/conf/configuration.go Outdated Show resolved Hide resolved
internal/conf/configuration.go Outdated Show resolved Hide resolved
internal/api/mfa.go Outdated Show resolved Hide resolved
internal/hooks/auth_hooks.go Outdated Show resolved Hide resolved
internal/hooks/auth_hooks.go Outdated Show resolved Hide resolved
internal/hooks/auth_hooks.go Outdated Show resolved Hide resolved
J0 and others added 5 commits November 30, 2023 09:04
Co-authored-by: Stojan Dimitrovski <sdimitrovski@gmail.com>
Co-authored-by: Stojan Dimitrovski <sdimitrovski@gmail.com>
…e/gotrue into j0/mfa_verification_counter_hook
internal/api/mfa.go Outdated Show resolved Hide resolved
@hf hf changed the title feat: add mfa verification postgres hook poc feat: add mfa verification postgres hook Nov 30, 2023
@J0 J0 merged commit db344d5 into master Nov 30, 2023
2 checks passed
@J0 J0 deleted the j0/mfa_verification_counter_hook branch November 30, 2023 09:43

}

func (mf *MFAVerificationAttemptOutput) IsError() bool {
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 refactor this in the FLUP with password verification hooks

Copy link
Contributor

🎉 This PR is included in version 2.123.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

uxodb pushed a commit to uxodb/auth that referenced this pull request Nov 13, 2024
## What kind of change does this PR introduce?

The mfa tests are hard to read. There's also a lot of redundant code
which makes testing for hooks quite a bit harder. This PR aims to remove
some of the redundancy so that it's easier to write the tests for supabase#1314

Main changes include
- Splitting out `enrollAndVerify` into `enroll` and `verify` 
-  Using suite specific constants
-  Packaging duplicated setup code

---------

Co-authored-by: joel@joellee.org <joel@joellee.org>
uxodb pushed a commit to uxodb/auth that referenced this pull request Nov 13, 2024
## What kind of change does this PR introduce?

Proof of concept hook for MFA Verification. With this hook, developers
can introduce additional conditions around when to accept/reject an MFA
verification (e.g. log a developer out after a certain number of
attempts).

We distinguish this from the existing Webhooks implementation via
introduction of `hooks` package which will contain future Hook related
structs, constants, and utility methods.

For the most part we leverage existing Postgres capabilities - as far as
possible we will return the PostgreSQL error codes for debugging and use
Postgres in-built timeouts to ensure hte hook doesn't overrun.

## Testing

The MFA Verification Hook test suite does not guarantee accurate status
codes - the test setup (to enroll factors and create a challenge after
signup) requires some setup. It is reliant on `signUpAndVerify` which
gets the dev to AAL2 and takes time to refactor.

As such, most of the cases were manually tested in addition to the
current loose check of checking for the absence of an access token.
Further edits will be made in GMT +8 morning to properly check for the
http status codes in the tests.

Also, since `supabase_auth_admin` cannot create functions on the
`public` schema we create the functions on the `auth` schema for
testing. We typically discourage this on the Supabase platform but in
theory there should be no issue when dealing with GoTrue (the OSS
project). Will spend a short amount of time looking into alternatives
tomorrow.


## Additional Notes

Response schema checks are left out of this PR as they don't seem to
serve as much benefit for this particular extensibility point and will
probably bloat the PR a little with the introduction of a new library

---------

Co-authored-by: joel@joellee.org <joel@joellee.org>
Co-authored-by: Stojan Dimitrovski <sdimitrovski@gmail.com>
LashaJini pushed a commit to LashaJini/auth that referenced this pull request Nov 13, 2024
## What kind of change does this PR introduce?

The mfa tests are hard to read. There's also a lot of redundant code
which makes testing for hooks quite a bit harder. This PR aims to remove
some of the redundancy so that it's easier to write the tests for supabase#1314

Main changes include
- Splitting out `enrollAndVerify` into `enroll` and `verify` 
-  Using suite specific constants
-  Packaging duplicated setup code

---------

Co-authored-by: joel@joellee.org <joel@joellee.org>
LashaJini pushed a commit to LashaJini/auth that referenced this pull request Nov 13, 2024
## What kind of change does this PR introduce?

Proof of concept hook for MFA Verification. With this hook, developers
can introduce additional conditions around when to accept/reject an MFA
verification (e.g. log a developer out after a certain number of
attempts).

We distinguish this from the existing Webhooks implementation via
introduction of `hooks` package which will contain future Hook related
structs, constants, and utility methods.

For the most part we leverage existing Postgres capabilities - as far as
possible we will return the PostgreSQL error codes for debugging and use
Postgres in-built timeouts to ensure hte hook doesn't overrun.

## Testing

The MFA Verification Hook test suite does not guarantee accurate status
codes - the test setup (to enroll factors and create a challenge after
signup) requires some setup. It is reliant on `signUpAndVerify` which
gets the dev to AAL2 and takes time to refactor.

As such, most of the cases were manually tested in addition to the
current loose check of checking for the absence of an access token.
Further edits will be made in GMT +8 morning to properly check for the
http status codes in the tests.

Also, since `supabase_auth_admin` cannot create functions on the
`public` schema we create the functions on the `auth` schema for
testing. We typically discourage this on the Supabase platform but in
theory there should be no issue when dealing with GoTrue (the OSS
project). Will spend a short amount of time looking into alternatives
tomorrow.


## Additional Notes

Response schema checks are left out of this PR as they don't seem to
serve as much benefit for this particular extensibility point and will
probably bloat the PR a little with the introduction of a new library

---------

Co-authored-by: joel@joellee.org <joel@joellee.org>
Co-authored-by: Stojan Dimitrovski <sdimitrovski@gmail.com>
LashaJini pushed a commit to LashaJini/auth that referenced this pull request Nov 15, 2024
## What kind of change does this PR introduce?

The mfa tests are hard to read. There's also a lot of redundant code
which makes testing for hooks quite a bit harder. This PR aims to remove
some of the redundancy so that it's easier to write the tests for supabase#1314

Main changes include
- Splitting out `enrollAndVerify` into `enroll` and `verify` 
-  Using suite specific constants
-  Packaging duplicated setup code

---------

Co-authored-by: joel@joellee.org <joel@joellee.org>
LashaJini pushed a commit to LashaJini/auth that referenced this pull request Nov 15, 2024
## What kind of change does this PR introduce?

Proof of concept hook for MFA Verification. With this hook, developers
can introduce additional conditions around when to accept/reject an MFA
verification (e.g. log a developer out after a certain number of
attempts).

We distinguish this from the existing Webhooks implementation via
introduction of `hooks` package which will contain future Hook related
structs, constants, and utility methods.

For the most part we leverage existing Postgres capabilities - as far as
possible we will return the PostgreSQL error codes for debugging and use
Postgres in-built timeouts to ensure hte hook doesn't overrun.

## Testing

The MFA Verification Hook test suite does not guarantee accurate status
codes - the test setup (to enroll factors and create a challenge after
signup) requires some setup. It is reliant on `signUpAndVerify` which
gets the dev to AAL2 and takes time to refactor.

As such, most of the cases were manually tested in addition to the
current loose check of checking for the absence of an access token.
Further edits will be made in GMT +8 morning to properly check for the
http status codes in the tests.

Also, since `supabase_auth_admin` cannot create functions on the
`public` schema we create the functions on the `auth` schema for
testing. We typically discourage this on the Supabase platform but in
theory there should be no issue when dealing with GoTrue (the OSS
project). Will spend a short amount of time looking into alternatives
tomorrow.


## Additional Notes

Response schema checks are left out of this PR as they don't seem to
serve as much benefit for this particular extensibility point and will
probably bloat the PR a little with the introduction of a new library

---------

Co-authored-by: joel@joellee.org <joel@joellee.org>
Co-authored-by: Stojan Dimitrovski <sdimitrovski@gmail.com>
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.

2 participants