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

Added JWT auth + /pyewatercycle endpoint #29

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open

Added JWT auth + /pyewatercycle endpoint #29

wants to merge 28 commits into from

Conversation

sverhoeven
Copy link
Member

@sverhoeven sverhoeven commented Aug 27, 2021

@sverhoeven sverhoeven changed the title Added JWT auth Added JWT auth + /pyewatercycle endpoint Aug 30, 2021
@sverhoeven sverhoeven marked this pull request as ready for review September 1, 2021 08:43
Copy link

@Peter9192 Peter9192 left a comment

Choose a reason for hiding this comment

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

Cleanup always good, ewatercycle notebook generation code looks good as well. Tried running locally but got authentication failure. Tried exporting the generated notebook from test to verify, but didn't succeed so far. Couple of comments.

Comment on lines +182 to +185
lumped:
type: boolean
description: Whether model is lumped or non-lumped model
default: false

Choose a reason for hiding this comment

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

Perhaps instead of a boolean, we could use something like:

model_type:
  type: string
  description: Whether model is lumped or gridded (or ...)
  default: gridded

Copy link
Member Author

Choose a reason for hiding this comment

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

If you can think of a third type then I would switch to an enum. For now boolean is clear enough for me.

Comment on lines +187 to +190
forcing:
type: string
description: Directory name of forcing. Directory should contain `ewatercycle_forcing.yaml` file.
example: marrmot-m01_example_1989-1992_buffalo-river

Choose a reason for hiding this comment

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

This assumes that a (basic) forcing exists for each model instance in our explorer. An alternative would be to add a "generate forcing" cell. Not sure if we should support both, though. For now, compromise on having a short example forcing for each model?

Copy link
Member Author

Choose a reason for hiding this comment

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

It would indeed be nice to generate forcings in notebook, for now I created #30 to add it later.

ewatercycle_experiment_launcher/openapi.yaml Outdated Show resolved Hide resolved
if "forcing" in setup:
forcing = setup["forcing"]
if not forcing.startswith("/"):
forcing = forcing_root_dir + "/" + forcing

Choose a reason for hiding this comment

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

isn't it safer to use pathlib here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep will fix. Dont expect many Windows deployments, but better safe then sorry

from ewatercycle_experiment_launcher.process import process_notebook


def notebook(setup: dict, forcing_root_dir: str) -> NotebookNode:

Choose a reason for hiding this comment

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

why is forcing_root_dir a separate parameter?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because it is set from command line, not from a request body. Also to make testing easier the notebook method is written without any flask globals.

Can be removed once eWaterCycle/ewatercycle#248 is implemented.



def check_auth(username, password, required_scopes=None):
def check_basic_auth(username, password, required_scopes=None):

Choose a reason for hiding this comment

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

required_scopes is not used?

Copy link
Member Author

Choose a reason for hiding this comment

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

timestamp = _current_timestamp()
payload = {
"iss": JWT_ISSUER,
"iat": int(timestamp),

Choose a reason for hiding this comment

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

is already an integer after L19

Copy link
Member Author

Choose a reason for hiding this comment

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

Comment on lines +18 to +19
def _current_timestamp() -> int:
return int(time.time())

Choose a reason for hiding this comment

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

Only used once, perhaps no need for a function?

@@ -84,16 +84,23 @@ To start launcher use
```bash
# JUPYTERHUB_URL is URL where JupyterHub is running. If path like `/jupyter` then origin header is appended.
export JUPYTERHUB_URL=http://172.17.0.1:8000
# JWT_SECRET is secret with which JWT tokens are encoded/decoded

Choose a reason for hiding this comment

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

I think the sudo on L24 is not needed. Might be better to avoid.

Choose a reason for hiding this comment

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

On L54 I get failed authentication (on WSL2)

Copy link
Member Author

Choose a reason for hiding this comment

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

sudo is needed for nodejs installed with apt. Switched to https://github.com/nvm-sh/nvm

Comment on lines +97 to +99
To generate a notebook you need to
1. POST to /auth with Basic authentication to receive a JWT token
2. POST to a notebook path, like /hello, with `Authorization: Bearer <jwt token>` header.

Choose a reason for hiding this comment

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

Getting 401 unauthorized for everything I try (WSL problem?)

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, JH uses the OS user accounts to authenticated against. Which works on my linux box. Not sure how accounts work in WSL. Mabye add user with sudo useradd someone;sudo passwd someone.

Choose a reason for hiding this comment

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

Still no luck

@sonarcloud
Copy link

sonarcloud bot commented Sep 3, 2021

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

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.

2 participants