Skip to content

Add Multi-User Functionality#238

Open
thomasb202 wants to merge 29 commits into
smarr:masterfrom
thomasb202:master
Open

Add Multi-User Functionality#238
thomasb202 wants to merge 29 commits into
smarr:masterfrom
thomasb202:master

Conversation

@thomasb202
Copy link
Copy Markdown
Contributor

  • Added/Changed Database tables (user and project-membership tables, rls-policies, new DB-Role)
  • Changed Backend (jwt, Route protection)
  • Minimal Login/Registration page
  • Tests

thomasb202 and others added 29 commits March 23, 2026 17:09
Signed-off-by: Stefan Marr <git@stefan-marr.de>
Added ProjectMembership table
Added RLS policies
Added new rdb_app role
Added ProjectMembership table
Added RLS policies
Added new rdb_app role
Implementation of withUserContext (Setting the role in the db to rdb_app for RLS-policies to fire)
# Conflicts:
#	src/backend/auth/auth-middleware.ts
#	src/backend/auth/auth-routes.ts
#	src/backend/db/db.sql
#	src/index.ts
Adding multi-user functionality
Copy link
Copy Markdown
Owner

@smarr smarr left a comment

Choose a reason for hiding this comment

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

Thanks! Overall this looks pretty good!
Added some initial thoughts for our discussion.

import { Next, ParameterizedContext } from 'koa';
import jwt from 'jsonwebtoken';

const JWT_SECRET = process.env.JWT_SECRET || '';
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

It would be good if we do not scatter accesses to process.env throughout the codebase.

I'd prefer if we could make it part of the siteConfig, I think:
https://github.com/smarr/ReBenchDB/blob/master/src/backend/util.ts#L103

This isn't super principled at the moment, some things are just exported properties. But appId and githubPrivateKey data go into it, so it seems as if this would be a good fit.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is a good idea, I will implement it like this.

Comment thread src/backend/auth/auth-db.ts
Comment on lines +21 to +22
const JWT_SECRET = process.env.JWT_SECRET || '';
const BCRYPT_ROUNDS = 12;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Both of these, I think should be in the siteConfig

return;
}

if (typeof password !== 'string' || password.length < 8) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Since you use bcrypt, we should also check for the largest supported passwords. It's 72 bytes according to https://en.wikipedia.org/wiki/Bcrypt

const token = jwt.sign(
{ sub: user.id, username: user.username },
JWT_SECRET,
{ expiresIn: '24h' }
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Ok, I think that's probably a useful default.
Though, I think we had a discussion of how we may want to handle submitting data from benchmark servers. There we probably want a token that is valid for a long time, possibly until it is revoked. I believe you said you want to use the same approach? I wonder whether this require some extra support here, or whether that's going to be handled separately.

-- ============================================================

-- Project: direct membership check
CREATE POLICY project_access ON Project
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

camelCase also for the various other names please, for consistency

@@ -0,0 +1,89 @@
BEGIN;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

hm, why do you have multiple migration scripts here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I had a first script that does not enforce RLS-policies to not completely break the application while implementing. But would be good now to combine them into one script.

Comment thread src/backend/db/db.sql
foreign key (criterion) references Criterion (id)
);

-- ============================================================
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Please use a style that matches the rest of the file, so no ==...== lines, just plain -- comment comments. And camelCase for consistency please.

Not sure whether there's a linter and/or code formatter, but would be nice to also use whitespace consistent with the existing code.

Comment thread src/backend/db/db.ts
* check in policies — use only for internal/background operations).
*/
public abstract withUserContext<T>(
userId: number | null,
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

hm, why do you allow null for userId? Isn't that against the idea?

Comment on lines +281 to +287

public async withUserContext<T>(
_userId: number | null,
fn: () => Promise<T>
): Promise<T> {
return fn();
}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Hm, doesn't this mean that we do not test the security stuff?

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