Skip to content

authz v2 subject roles#16281

Draft
SaumonDesMers wants to merge 2 commits intodevfrom
sga/authz_v2_subject_roles
Draft

authz v2 subject roles#16281
SaumonDesMers wants to merge 2 commits intodevfrom
sga/authz_v2_subject_roles

Conversation

@SaumonDesMers
Copy link
Copy Markdown
Contributor

I started migrating user_roles to subject_roles, but I'm a bit lost and the test views::authz::tests::whoami_authorization_disabled fail (roles are empty instead of Admin).

I would love a review if possible.

@SaumonDesMers SaumonDesMers requested a review from leovalais April 15, 2026 14:02
@github-actions github-actions bot added the area:editoast Work on Editoast Service label Apr 15, 2026
@SaumonDesMers SaumonDesMers moved this to In Progress in Board PI 19 Apr 16, 2026
@SaumonDesMers SaumonDesMers self-assigned this Apr 16, 2026
Comment on lines +57 to +59
// pub async fn user_roles(&self) -> Result<HashSet<Role>, Error<S::Error>> {
// self.regulator.user_roles(&User(self.user_id)).await
// }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can leave this function, you don't have to make changes in parts of the code that'll go away soon. If you can remove them now, good, but if you need to adapt some part's that'll be removed later, it's not worth it.

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 removed the Authentication.user_roles because it was unused.
I removed the Authorizer.user_roles because it was unused (although this time the compiler didn't see it).
I didn't removed the Regulator.user_roles because it was used in other Regulator methods.

Comment thread editoast/src/client/roles.rs Outdated
Comment thread editoast/src/client/roles.rs Outdated
let roles = match system.authorize(subject_roles).await?.access().await? {
Ok(roles) => roles,
Err(Rejection::NoSuchUser(_)) | Err(Rejection::NoSuchGroup(_)) => {
unreachable!("checked by parse_and_fetch_subject")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No the function only parses the argument, it does not always check the subjects exist in the database.

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.

Done 74748c4.

Comment thread editoast/src/views/authz.rs Outdated
Comment on lines +281 to +283
Err(Rejection::NoSuchUser(_)) | Err(Rejection::NoSuchGroup(_)) => {
unreachable!("checked by parse_and_fetch_subject")
},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

wrong paste

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.

Done 74748c4.

Comment on lines 397 to 409
assert_eq!(
regulator()
.group_roles(&Group(i64::MAX))
// regulator()
// .group_roles(&Group(i64::MAX))
// .await
// .expect("should query roles successfully"),
v2::subject_roles(Subject::Group(model::Group(i64::MAX)))
.authorize(&special_authorizers::Authorize(regulator().openfga()))
.await
.expect("should query roles successfully"),
HashSet::new()
.expect("should query group roles successfully")
.unwrap_authorized()
.await,
Vec::<Role>::new()
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks like this is the last part of the test that needed porting. Let's just rewrite the test without the old Regulator and Authorizer in v2.rs.

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.

The old Authorizer is still used for check_roles (which I don't see yet on dev), and the regulator is used for ensure_user and ensure_group (which I have no idea what they do).

Comment on lines 119 to 124
Ok(Json(WhoamiResponse {
// TODO: don't return -1 and a hardcoded name, return a different schema instead, requires frontend changes
id: auth.user_id()?.unwrap_or(-1),
name: auth.user_name()?.unwrap_or_else(|| "OSRD user".to_string()),
roles: auth.user_roles().await?.into_iter().collect(),
roles: roles,
}))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Best to get the Authentication as well and match on it to return the right roles (unauthenticated = 401, skip = admin, otherwise it's roles).

You should rebase on top of e2fda96 to get the last fix (should be merged soon).

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 don't understand.

Signed-off-by: Simon <sim.gaubert.sg@gmail.com>
@SaumonDesMers SaumonDesMers force-pushed the sga/authz_v2_subject_roles branch from d8210aa to 74748c4 Compare April 17, 2026 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:editoast Work on Editoast Service

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

2 participants