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

[CORE-211] Convert disk operations to new Sam permissions model #4822

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from

Conversation

marctalbott
Copy link
Member

@marctalbott marctalbott commented Jan 13, 2025

Jira ticket: https://broadworkbench.atlassian.net/browse/CORE-211

Summary of changes

This PR may be easiest to review by stepping through the commits in order. Each commit contains a single operation authz conversion.

What

  • Rely on new hierarchical permissions model for Leo resources in Sam and only check one permission for each disk operation.

Why

  • Simplify Leo authz process

Testing these changes

What to test

Who tested and where

  • This change is covered by automated tests
    • NB: Rerun automation tests on this PR by commenting jenkins retest or jenkins multi-test.
  • I validated this change
  • Primary reviewer validated this change
  • I validated this change in the dev environment

samResourceId: SamResourceId,
action: RuntimeAction,
userEmail: Option[WorkbenchEmail] = None
object SamUtils {
Copy link
Member Author

Choose a reason for hiding this comment

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

I tried out switching this over to an object instead of a trait to reuse the code in the RuntimeServiceInterp object and found that I slightly prefer it to the trait, but I'm curious to hear what others think! The switchover is in the last commit if you'd like to compare

Copy link
Collaborator

Choose a reason for hiding this comment

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

I like it better too, it makes the code more readable IMO

@marctalbott marctalbott changed the title Mtalbott sam disks [CORE-211] Convert disk operations to new Sam permissions model Jan 13, 2025
Copy link

codecov bot commented Jan 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.62%. Comparing base (dce08ef) to head (814a783).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #4822      +/-   ##
===========================================
- Coverage    74.62%   74.62%   -0.01%     
===========================================
  Files          166      166              
  Lines        14692    14632      -60     
  Branches      1135     1170      +35     
===========================================
- Hits         10964    10919      -45     
+ Misses        3728     3713      -15     
Files with missing lines Coverage Δ
...ute/dsde/workbench/leonardo/dao/sam/SamUtils.scala 100.00% <100.00%> (ø)
...e/workbench/leonardo/db/DiskServiceDbQueries.scala 100.00% <100.00%> (ø)
...rkbench/leonardo/http/AppDependenciesBuilder.scala 97.87% <100.00%> (ø)
...bench/leonardo/http/AzureDependenciesBuilder.scala 97.14% <ø> (-0.16%) ⬇️
...rkbench/leonardo/http/GcpDependenciesBuilder.scala 73.14% <ø> (-0.31%) ⬇️
...ench/leonardo/http/service/DiskServiceInterp.scala 94.83% <100.00%> (+3.08%) ⬆️
...ch/leonardo/http/service/DiskV2ServiceInterp.scala 97.22% <100.00%> (+4.76%) ⬆️
...ch/leonardo/http/service/LeoAppServiceInterp.scala 87.34% <ø> (-0.04%) ⬇️
...workbench/leonardo/http/service/ProxyService.scala 73.55% <100.00%> (+0.12%) ⬆️
...rkbench/leonardo/http/service/RuntimeService.scala 100.00% <ø> (ø)
... and 2 more

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dce08ef...814a783. Read the comment docs.

@marctalbott marctalbott marked this pull request as ready for review January 14, 2025 16:03
@marctalbott marctalbott requested a review from a team as a code owner January 14, 2025 16:03
Copy link
Collaborator

@LizBaldo LizBaldo left a comment

Choose a reason for hiding this comment

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

Looks amazing! I only have a few comments / nits that should not be a blocker for merging. I really appreciate the logical organization by commit, it made it very easy to review, thanks a bunch!

)
_ <- F.raiseWhen(!hasProjectPermission.getOrElse(true))(ForbiddenError(userInfo.userEmail, Some(ctx.traceId)))

samDiskIds <- samService.listResources(userInfo.accessToken.token, SamResourceType.PersistentDisk)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice, so the new behavior is that is a user does not have permission (either on the project or list disk action), sam will return an empty list of IDs, and we won't be leaking any info to the user?

Copy link
Member Author

Choose a reason for hiding this comment

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

Pretty much -- Sam will return all of the disks that the user has access to and then the query will filter out any disks that are in a different project if cloudContext is defined. Sam doesn't do an explicit permissions check on the project, but it will only return disks that the user has permission to see.

paramMap <- F.fromEither(processListParameters(params))
creatorOnly <- F.fromEither(processCreatorOnlyParameter(userInfo.userEmail, params, ctx.traceId))
disks <- DiskServiceDbQueries.listDisks(paramMap._1, paramMap._2, creatorOnly, cloudContext).transaction
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is so nice to see this code being deleted, thank you!

@@ -689,12 +720,22 @@ class DiskServiceInterpTest
.save()
diskSamResource3 <- IO(PersistentDiskSamResourceId(UUID.randomUUID.toString))
disk3 <- makePersistentDisk(Some(DiskName("d3")), cloudContextOpt = Some(cloudContextGcp))
.copy(samResource = diskSamResource1)
.copy(samResource = diskSamResource3)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ouch, good catch, thanks!

@@ -1126,6 +1110,32 @@ object RuntimeServiceInterp {
}
} yield disk

private def checkAttachAction[F[_]](userInfo: UserInfo,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit, would it make sense to move this with the other checkAction function in SamUtils? Might not be in the scope for this PR, but disks can also be attached to apps and so it could make sense to move this logic out of the RuntimeServiceInterp file

@@ -935,7 +949,14 @@ object RuntimeServiceInterp {
disk <- diskOpt match {
case Some(pd) =>
for {
_ <- checkAttachAction(userInfo, samService, pd, cloudContext, req.name, ctx.traceId)
_ <- SamUtils.checkDiskAction(samService,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice, ignore my last comment then (I was reviewing commit by commit and did not see it yet sorry!

samResourceId: SamResourceId,
action: RuntimeAction,
userEmail: Option[WorkbenchEmail] = None
object SamUtils {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I like it better too, it makes the code more readable IMO

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.

3 participants