-
Notifications
You must be signed in to change notification settings - Fork 0
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
Remix auth #47
Conversation
…able by user + lots of other stuff to make things work and look cleaner
Versions and changed code from `npx create-remix@latest` run in temp dir.
To ignore postgres-data during format had to add ignore in command. See prettier/prettier#11568 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Profile popup doesn't go away when clicked
- Checkboxes on admin page shouldn't apply directly, but after a save
- Can't change password on first admin user?
- Batch checker doesn't work on admin page (with single user)
A super user can be made through the admin page (`/admin/users`) or by being the first registered user. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I accidentily revoked SU rights for the first registered user... that should not be so easy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added confirm dialog in 3821052
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Disabling super user toggle when you are the only super user would be nice, but confirm is good enough.
"typecheck": "tsc" | ||
"typecheck": "tsc", | ||
"setup": "prisma generate && prisma migrate deploy && prisma db seed", | ||
"docker:dev": "docker compose -f docker-compose.dev.yml up", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's nice to have this as an npm run
alias, but if you stop it (ctrl+c) then the containers will linger on my system (docker ps -a ). I'd like to have either the counterpart with docker compose rm
or the docker-compose alternative for docker --rm
(is that --abort-on-container-exit
?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally, a command to clear the database would be super helpful, at least for developer purposes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can add && docker-compose rm -fsv
to script so after you kill the up command the rm command is run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Stores data in `./postgres-data`) | ||
(You can get a psql shell with `npm run psql:dev`) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The database can be initialized with | ||
|
||
```sh | ||
npm run setup |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clearified in a2c50c9
README.md
Outdated
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). |
There was a problem hiding this comment.
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.
README.md
Outdated
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. |
There was a problem hiding this comment.
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:
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 | ||
npm install | ||
cp .env.example .env |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 0cfa352
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good stuff! I found a few things in the docker compose file, further mostly some clarification suggestions. While browsing to remix docs, I noticed that they mostly like cookiesessionstorage because you don't need a database for them. So I was wondering, since we have a database anyway, is this really the most suitable choice for storing session info? Furthermore, it would be nice to have a dedicated error page in the same style as the rest of the app. And it would be helpful to clarify (more explicitly) that bartender should not be setting roles, this is done by the web app
docker-compose.yml
Outdated
- type: bind | ||
source: ./private_key.pem | ||
target: /app/src/private_key.pem |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the web app be the sole owner (and user) of the private key? Bartender should only need the public key to verify the token, right?
- type: bind | |
source: ./private_key.pem | |
target: /app/src/private_key.pem | |
- type: bind | |
source: ./public_key.pem | |
target: /app/src/public_key.pem |
environment: | ||
BARTENDER_API_URL: "http://bartender:8000" | ||
DATABASE_URL: postgresql://postgres:postgres@webappdb:5432/postgres |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DATABASE_URL: postgresql://postgres:postgres@webappdb:5432/postgres | |
DATABASE_URL: postgresql://postgres:postgres@webappdb:5432/postgres | |
BARTENDER_PRIVATE_KEY: /app/src/private_key.pem |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in 6cfcd2e
docker-compose.yml
Outdated
source: ./public_key.pem | ||
target: /app/src/public_key.pem |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the web app need the private key to generate tokens?
source: ./public_key.pem | |
target: /app/src/public_key.pem | |
source: ./private_key.pem | |
target: /app/src/private_key.pem |
app/routes/login.tsx
Outdated
id="password" | ||
name="password" | ||
type="password" | ||
minLength={8} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this min length check on login as well? Since you can't have a password of <8 characters, the password would be wrong anyway. But it's not like this is checking it's valid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, removed length check on server and client in 6cfcd2e
README.md
Outdated
## Setup | ||
|
There was a problem hiding this comment.
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?
app/bartender_token.server.ts
Outdated
// If bartender has been configured with allowed_roles for an application, | ||
// then the a role claim should be in the JWT. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That useful info is a bit hidden 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<input | ||
type="checkbox" | ||
checked={user.isSuperuser} | ||
checked={user.isAdmin} | ||
className="checkbox" | ||
disabled={submitting} | ||
onChange={() => { | ||
const data = new FormData(); | ||
data.set("isSuperuser", user.isSuperuser ? "false" : "true"); | ||
data.set("isAdmin", user.isAdmin ? "false" : "true"); | ||
onUpdate(data); | ||
}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Disable if there's only one admin left?
<td> | ||
<button className="btn-sm btn" disabled> | ||
Change password | ||
</button> | ||
</td> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confusing to have placeholders that are not implemented without explicitly stating so.
<td> | ||
<input type="checkbox" disabled /> | ||
</td> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unclear why this is disabled by default. Remove or explain?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed in fcc7c68
export async function listRoles(accessToken: string) { | ||
const api = buildRolesApi(accessToken); | ||
return await api.listRoles(); | ||
export async function assignExpertiseLevel( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this also upgrade their jwt token?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope expertise level is not in token
Already comparing with bcrypt
The users browser needs to persist something between page loads we are storing the encrypted user id in the cookie just like https://github.com/remix-run/blues-stack/blob/main/app/session.server.ts#L78 . If you would store session id in cookie and session to user mapping as a db table there are more moving parts without much benefit. For errors you already created #22 so will deal with better error pages when fixing that issue. Thanks for reviewing this monster pull request and fixing the deployment error I should have caught. |
Fixes i-VRESSE/bartender#54
Should be merged together with i-VRESSE/bartender#73
TODO
To test: