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 jwt based Team authentication #6

Merged
merged 14 commits into from
Nov 25, 2023
Merged

Conversation

parrothacker1
Copy link
Contributor

About

This PR is mainly focused on the following:

  • To create models for both Team and Participant and adding functionalities to it

Shortcomings

  • The function check_password in the Team model does not implement hash comparison.(is done for debugging)
  • The test cases are lousy written
  • NO Documentation

When fixes

Fixes to the above mentioned problems will be done after getting a go signal for the code and also after discussing with @MrigankaDebnath03 for implementation of the db functions. Test cases will be written after @MrigankaDebnath03's work.

@parrothacker1
Copy link
Contributor Author

Also wanted to mention this that the register_tortoise is throwing errors which I honestly don't understand why but will also be looked into and will come up with a fix soon

val=await team.current_points_fn(get=True)
return {"status":val} # int

@router.get("/members/")
Copy link
Member

Choose a reason for hiding this comment

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

We can simplify the fetching of points and members to be on a single endpoint like /profile which returns a JSON object which contains the points and reg no. of the members.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh ok I'll notify @MrigankaDebnath03

val=await team.members(get=True) # a dict of members with keys ['member1','member2','member3']
return {'status':val}

@router.get("/members/update")
Copy link
Member

Choose a reason for hiding this comment

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

Try to keep each function's URL endpoint to be of a single depth, for eg. updating members can be just /update.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Those are just some endpoints which I've written just for the sake of testing the db. @MrigankaDebnath03 is currently working on the endpoints.

@WizzyGeek
Copy link
Contributor

You might have to rebase after #7

Would you be able to make the same changes after rebasing?

@parrothacker1
Copy link
Contributor Author

Aah I'll do itt .. 👍

Dockerfile Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
docker-compose.yml Outdated Show resolved Hide resolved
src/pwncore/Signup.py Outdated Show resolved Hide resolved
src/pwncore/Signup_updated.py Outdated Show resolved Hide resolved
src/pwncore/Signup_updated.py Outdated Show resolved Hide resolved
src/pwncore/Signup_updated.py Outdated Show resolved Hide resolved
src/pwncore/db/__init__.py Outdated Show resolved Hide resolved
src/pwncore/db/__init__.py Outdated Show resolved Hide resolved
tox.ini Outdated Show resolved Hide resolved
@WizzyGeek
Copy link
Contributor

You can wait till #5 is merged, a lot of the DB stuff and config stuff comes from there

@parrothacker1
Copy link
Contributor Author

Ok .. 👍

@WizzyGeek
Copy link
Contributor

@parrothacker1 this branch needs to rebase, contact me if you need help with that 👐🏼

@parrothacker1
Copy link
Contributor Author

@WizzyGeek how about I rewrite most of the stuff ?? ...the current branch is a whole lot messy ... so gonna start again ...

and it would be helpful if I get a glimpse of what we need .. like in the database part ... i just need to define the model .. and some functions like check_password etc right ? .. also I saw a todo about a function that can do insert and update in a single query .. shall I implement that ?

@WizzyGeek
Copy link
Contributor

models are already defined, so you shouldn't be needing to define new models, only the password verfying method needs to be implemented in User model.

That TODO requires extensive knowledge of the ORM, since it deals with executors... but if you can figure it out and come up with an efficient solution, why not?

@parrothacker1
Copy link
Contributor Author

In the User model ? ... I thought we were storing passwords in the Team model .. ?

@WizzyGeek
Copy link
Contributor

ah yes, my bad

@parrothacker1 parrothacker1 reopened this Nov 22, 2023
@parrothacker1
Copy link
Contributor Author

@WizzyGeek bhaiya i'm done with mostly everything except for the TODO.I'll do a bit more research on it and will make a commit by tomorrow if i can come up with a sol. Please go through it and tell me if any probs ... and i wanted to ask this . In the "routes/team.py" there is a signup_team function (PS: endpoints were made by @MrigankaDebnath03 i just edited it a bit for our project) which only has code to create a team, there was a if-else code to check for no.of members .. but in our new db ... the users have the save function which does the same. So i removed that part and the only part that left is team creation. Should I just leave it like that ?

@MrigankaDebnath03
Copy link

Yup, it's fine

setup.cfg Outdated Show resolved Hide resolved
src/pwncore/routes/ctf/start.py Outdated Show resolved Hide resolved
src/pwncore/models/user.py Outdated Show resolved Hide resolved

# Custom JWT processing (since FastAPI's implentation deals with refresh tokens)
async def get_jwt(*, authorization: str = Header()):
token = authorization.split(" ")[1] # Remove Bearer
Copy link
Contributor

Choose a reason for hiding this comment

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

Unhandled IndexError

also prefer doing authorization[<constant you find>:] over splitting

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 we should prefer splitting, since the expected authorization header should be in format Bearer <token>.
In case the user (frontend) passes the authorization header as just <token>, it would raise an error (I forgot to catch the error).

If we use authorization[7:] to strip the Bearer , it would not lead to an error in the case that Bearer does not exist in the header.

Copy link
Contributor

@WizzyGeek WizzyGeek Nov 24, 2023

Choose a reason for hiding this comment

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

If Bearer does not exist in the token it would lead to an error by splitting too.
str.removeprefix would do the required validation and deletion

Also, I just noticed but this function shouldn't be async, it is doing no IO

src/pwncore/routes/ctf/start.py Outdated Show resolved Hide resolved
src/pwncore/routes/ctf/start.py Outdated Show resolved Hide resolved
@WizzyGeek
Copy link
Contributor

Looks way better, good work @parrothacker1 and @MrigankaDebnath03

@WizzyGeek WizzyGeek changed the title Addition of Team and Paticipants Models to the code Add jwt based Team authentication Nov 24, 2023
tox.ini Outdated Show resolved Hide resolved
@mradigen mradigen mentioned this pull request Nov 25, 2023
3 tasks
mradigen added a commit that referenced this pull request Nov 25, 2023
Hints, Problems and Flag functions

Merging this before #6 since resolving potential conflicts with #6 is easier given it has only 8 commits.
@mradigen mradigen merged commit 9c327f5 into lugvitc:master Nov 25, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants