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

refactor: only use permit to check project permissions #1721

Merged
merged 2 commits into from
Apr 4, 2024
Merged
Changes from all commits
Commits
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
47 changes: 14 additions & 33 deletions gateway/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,39 +82,20 @@ where

let RouterState { service, .. } = RouterState::from_ref(state);

let has_bypass = user.claim.is_admin() || user.claim.is_deployer();

let allowed = has_bypass
|| {
let projects: Vec<_> = service.iter_user_projects(&user.id).await?.collect();
let internal_allowed = projects.contains(&scope);

let permit_allowed = service
.permit_client
.allowed(
&user.id,
&service.find_project_by_name(&scope).await?.id,
"develop", // TODO?: make this configurable per endpoint?
)
.await
.map_err(|_| {
error!("failed to check Permit permission");
// Error::from_kind(ErrorKind::Internal)
})
.unwrap_or_default();

if internal_allowed != permit_allowed {
error!(
"PERMIT: Permissions for user {} project {} did not match internal permissions. Internal: {}, Permit: {}",
user.id,
scope,
internal_allowed,
permit_allowed
);
}

internal_allowed
};
let allowed = user.claim.is_admin()
|| user.claim.is_deployer()
|| service
.permit_client
.allowed(
&user.id,
&service.find_project_by_name(&scope).await?.id,
"develop", // TODO: make this configurable per endpoint?
)
.await
.map_err(|_| {
error!("failed to check Permit permission");
Error::from_kind(ErrorKind::Internal)
})?;

if allowed {
Ok(Self { user, scope })
Expand Down