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

Remix auth #47

Merged
merged 45 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
61a6f61
Use remix-auth for local user
sverhoeven Jun 30, 2023
0a7a3b6
A todo list
sverhoeven Jun 30, 2023
369d7be
Able to login with dummy check
sverhoeven Jul 19, 2023
b01d85a
Trying to to do all things
sverhoeven Jul 19, 2023
e3af0d0
type fix
sverhoeven Jul 25, 2023
03dee09
Got GH login to work + bartender token generation in theory
sverhoeven Jul 25, 2023
1f49596
Fix lint
sverhoeven Jul 25, 2023
ddb9d99
Make user more haddock3 specific
sverhoeven Jul 28, 2023
b0b471e
Make login button easier to see
sverhoeven Jul 28, 2023
c836fba
Regenerate client
sverhoeven Jul 28, 2023
aa50570
Store bartender token in db + make preferred expertise level configur…
sverhoeven Jul 28, 2023
4b7f6f2
Use verified email from GH account
sverhoeven Jul 28, 2023
a76ac00
Added untested EGI and Orcid auth strategies
sverhoeven Jul 28, 2023
3c47a56
Make offering to the lint gods
sverhoeven Jul 28, 2023
8408972
Move social login docs from bartender to here
sverhoeven Aug 7, 2023
5ae665d
Tested orcid sandbox, orcid, egi development social logins
sverhoeven Aug 8, 2023
e47528d
Run formatter
sverhoeven Aug 8, 2023
1493771
TODO has been moved to https://github.com/i-VRESSE/bartended-haddock3…
sverhoeven Aug 8, 2023
07cf174
Upgrade to latest remix
sverhoeven Aug 9, 2023
e37c357
Use validot on register form + Write down tech choices
sverhoeven Aug 9, 2023
b68e0c7
Switched to remix v2 route file naming + switched to postgresql + doc…
sverhoeven Aug 9, 2023
e5b166e
Format
sverhoeven Aug 9, 2023
13eff96
More format
sverhoeven Aug 9, 2023
631959a
fix todo
sverhoeven Aug 9, 2023
177bec2
Remove console.log
sverhoeven Aug 9, 2023
335c13d
Remove console.log
sverhoeven Aug 9, 2023
b9563c0
Add validation to login form
sverhoeven Aug 9, 2023
b5ffdf4
Go over todos
sverhoeven Aug 9, 2023
ed7aead
Install packages we import
sverhoeven Aug 9, 2023
bfa4ed1
generate svg from email as gravatar
sverhoeven Aug 10, 2023
4a73c29
Redirect messes up type of actionData so specify type instead of infe…
sverhoeven Aug 10, 2023
c2d6ad2
Format
sverhoeven Aug 10, 2023
ab34407
Orcid & EGI lack profile.photos, fallback to generate photo
sverhoeven Aug 14, 2023
fcc7c68
Remove unimplemented batch and action columns
sverhoeven Aug 21, 2023
3821052
Add confirmation when toggling admin
sverhoeven Aug 21, 2023
466663e
Bind keys to right service
sverhoeven Aug 21, 2023
a477c35
Use same postgres image
sverhoeven Aug 21, 2023
441c87d
Haddock3 web app is issuer
sverhoeven Aug 21, 2023
055807a
Improve docs
sverhoeven Aug 21, 2023
0cfa352
Added secret generate command
sverhoeven Aug 21, 2023
a2c50c9
Add prune
sverhoeven Aug 21, 2023
5627bb4
Move useful info to docs
sverhoeven Aug 21, 2023
6cfcd2e
Remove password length check during login
sverhoeven Aug 21, 2023
78ec595
When password was never set then locallogin always fails
sverhoeven Aug 21, 2023
b63c372
Format
sverhoeven Aug 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/postgres-data
/node_modules
/public/build
.git
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DATABASE_URL="postgresql://postgres:postgres@localhost:5433/postgres"
SESSION_SECRET=<please replace with a better secret>
# For social login see docs/auth.md
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** @type {import('@types/eslint').Linter.BaseConfig} */
/** @type {import('eslint').Linter.Config} */
module.exports = {
root: true,
extends: [
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ jobs:
cache: "npm"
- run: npm ci
- run: npm run build --if-present
- name: Generate RSA key pair
run: |
openssl genpkey -algorithm RSA -out private_key.pem \
-pkeyopt rsa_keygen_bits:2048
openssl rsa -pubout -in private_key.pem -out public_key.pem
- run: npm test -- --coverage
- run: npm run typecheck
- run: npx prettier --check .
Expand Down
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,12 @@ node_modules

/sessions
/coverage

/prisma/dev.db

/private_key.pem
/public_key.pem

Caddyfile

postgres-data
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ FROM base as deps

WORKDIR /myapp

ADD package.json ./
ADD package.json package-lock.json tsconfig.json ./
RUN npm install --production=false

# Setup production node_modules
Expand All @@ -18,8 +18,8 @@ FROM base as production-deps
WORKDIR /myapp

COPY --from=deps /myapp/node_modules /myapp/node_modules
ADD package.json ./
RUN npm prune --production
ADD package.json package-lock.json ./
RUN npm prune --production

# Build the app
FROM base as build
Expand All @@ -29,6 +29,7 @@ WORKDIR /myapp
COPY --from=deps /myapp/node_modules /myapp/node_modules

ADD . .
RUN npx prisma generate
RUN npm run build

# Finally, build the production image with minimal footprint
Expand All @@ -43,6 +44,7 @@ WORKDIR /myapp

COPY --from=production-deps /myapp/node_modules /myapp/node_modules

COPY --from=build /myapp/node_modules/.prisma /myapp/node_modules/.prisma
COPY --from=build /myapp/build /myapp/build
COPY --from=build /myapp/public /myapp/public
COPY --from=build /myapp/package.json /myapp/package.json
Expand Down
95 changes: 54 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

Uses

- [bartender](https://github.com/i-VRESSE/bartender) for user and job management.
- [bartender](https://github.com/i-VRESSE/bartender) for job execution.
- [workflow-builder](https://github.com/i-VRESSE/workflow-builder) to construct a Haddock3 workflow config file.
- [haddock3](https://github.com/haddocking/haddock3) to compute

```mermaid
sequenceDiagram
Web app->>+Bartender: Login
Web app->>+Web app: Login
Web app->>+Builder: Construct workflow config
Builder->>+Bartender: Submit job
Bartender->>+haddock3: Run
Expand All @@ -22,8 +22,34 @@ sequenceDiagram

- [Remix Docs](https://remix.run/docs)

## Setup

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe start with a note that you need to have a running instance of bartender setup before starting this? And point to the section below on how to set it up?

```shell
npm install
cp .env.example .env
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a note/guideline on changing the secret?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done in 0cfa352

# Create rsa key pair for signing & verifying JWT tokens for bartender web service
openssl genpkey -algorithm RSA -out private_key.pem \
-pkeyopt rsa_keygen_bits:2048
openssl rsa -pubout -in private_key.pem -out public_key.pem
```

## Development

You need to have a Postgres database running. The easiest way is to use Docker:

```sh
npm run docker:dev
```

(Stores data in `./postgres-data`)
(You can get a psql shell with `npm run psql:dev`)
Comment on lines +64 to +65
Copy link
Contributor

Choose a reason for hiding this comment

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

Add here how to clear the database? And remove the container?

Copy link
Member Author

Choose a reason for hiding this comment

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

Add clear command in 0cfa352 and a2c50c9 to remove container


The database can be initialized with

```sh
npm run setup
Copy link
Contributor

Choose a reason for hiding this comment

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

What about migrations? Do I need to run this command always?

Copy link
Member Author

Choose a reason for hiding this comment

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

Clearified in a2c50c9

```

From your terminal:

```sh
Expand Down Expand Up @@ -88,13 +114,16 @@ Make sure to deploy the output of `remix build`

### Docker

The web application can be run inside a Docker container.
The web application can be run inside a Docker container together with all its dependent containers.

Requirements:

1. [bartender repo](https://github.com/i-VRESSE/bartender) to be cloned in `../bartender` directory.
2. bartender repo should have [.env file](https://github.com/i-VRESSE/bartender/blob/main/docs/configuration.md#environment-variables)
3. bartender repo should have a [config.yaml file](https://github.com/i-VRESSE/bartender/blob/main/docs/configuration.md#configuration-file)
1. Private key `./private_key.pem` and public key `./public_key.pem`.
2. `./.env` file for haddock3 web application.
3. [bartender repo](https://github.com/i-VRESSE/bartender) to be cloned in `../bartender` directory.
4. bartender repo should have [.env file](https://github.com/i-VRESSE/bartender/blob/main/docs/configuration.md#environment-variables)
5. bartender repo should have a [config.yaml file](https://github.com/i-VRESSE/bartender/blob/main/docs/configuration.md#configuration-file)
1. The `job_root_dir` key should be set to `/tmp/jobs`

Build with

Expand All @@ -110,20 +139,9 @@ docker compose up

Web application running at http://localhost:8080 .

Create super user with
## Authentication & authorization

```sh
# First register user in web application
docker compose exec bartender bartender super <email>
```

## Sessions

Making the login session secure requires a session secret.
The session secret can be configured by setting the `SESSION_SECRET` environment variable.
If not set, a hardcoded secret is used, which should not be used in production.

The data of the login sessions in stored in the `./sessions` directory.
See [docs/auth.md](docs/auth.md).
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be good to say here already that the first user is automatically admin.


## Bartender web service client

Expand All @@ -139,28 +157,27 @@ npm run generate-client

## Bartender web service configuration

### Bartender

The web application needs to know where the [Bartender web service](https://github.com/i-VRESSE/bartender) is running.
The haddock3 web application needs to know where the [Bartender web service](https://github.com/i-VRESSE/bartender) is running.
Configure bartender location with `BARTENDER_API_URL` environment variable.

```sh
export BARTENDER_API_URL='http://127.0.0.1:8000'
npm start
BARTENDER_API_URL=http://localhost:8000
```

### Social login

To enable GitHub or Orcid or EGI Check-in login the bartender web service needs following environment variables.
The haddock3 web application must be trusted by the bartender web service using a JWT token.
An RSA private key is used by the haddock3 web application to sign the JWT token.
To tell the haddock3 web application where to find the private key, use the `BARTENDER_PRIVATE_KEY` environment variable.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this explananation is a bit confusing. What about:

Suggested change
The haddock3 web application must be trusted by the bartender web service using a JWT token.
An RSA private key is used by the haddock3 web application to sign the JWT token.
To tell the haddock3 web application where to find the private key, use the `BARTENDER_PRIVATE_KEY` environment variable.
The haddock3 web application can prove its identity to the bartender web service using a JWT token.
An RSA private key is used by the haddock3 web application to sign the JWT token.
To tell the haddock3 web application where to find the private key, use the `BARTENDER_PRIVATE_KEY` environment variable.


```shell
BARTENDER_GITHUB_REDIRECT_URL="http://localhost:3000/auth/github/callback"
BARTENDER_ORCIDSANDBOX_REDIRECT_URL="http://localhost:3000/auth/orcidsandbox/callback"
BARTENDER_ORCID_REDIRECT_URL="http://localhost:3000/auth/orcid/callback"
BARTENDER_EGI_REDIRECT_URL="http://localhost:3000/auth/egi/callback"
```sh
BARTENDER_PRIVATE_KEY=private_key.pem
```

Where `http://localhost:3000` is the URL where the Remix run app is running.
An RSA public key is used by the bartender web service to verify the JWT token.
To tell the bartender web service where to find the public key, use the `BARTENDER_PUBLIC_KEY` environment variable.

```sh
BARTENDER_PUBLIC_KEY=public_key.pem
```

## Haddock3 application

Expand All @@ -171,18 +188,10 @@ applications:
haddock3:
command: haddock3 $config
config: workflow.cfg
allowed_roles:
- easy
- expert
- guru
```

This allows the archive generated with the workflow builder to be submitted.
Copy link
Contributor

Choose a reason for hiding this comment

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

Add an explicit note here that you shouldn't be using bartender's "allowed_roles" settings?


The user can only submit jobs when he/she has any of these allowed roles.
A super user should assign a role to the user at http://localhost:3000/admin/users.
A super user can be made through the admin page or by running `bartender super <email>` on the server

## Catalogs

This repo has a copy (`./app/catalogs/*.yaml`) of the [haddock3 workflow build catalogs](https://github.com/i-VRESSE/workflow-builder/tree/main/packages/haddock3_catalog/public/catalog).
Expand All @@ -192,3 +201,7 @@ To fetch the latest catalogs run
```shell
npm run catalogs
```

## Stack

The tech stack is explained in [docs/stack.md](docs/stack.md).
Loading