Skip to content

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

Closed
marctalbott wants to merge 11 commits intodevelopfrom
mtalbott-sam-disks
Closed

[CORE-211] Convert disk operations to new Sam permissions model#4822
marctalbott wants to merge 11 commits intodevelopfrom
mtalbott-sam-disks

Conversation

@marctalbott
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
@codecov
Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

samDiskIds <- samService.listResources(userInfo.accessToken.token, SamResourceType.PersistentDisk)
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
Copy Markdown
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!

diskSamResource3 <- IO(PersistentDiskSamResourceId(UUID.randomUUID.toString))
disk3 <- makePersistentDisk(Some(DiskName("d3")), cloudContextOpt = Some(cloudContextGcp))
.copy(samResource = diskSamResource1)
.copy(samResource = diskSamResource3)
Copy link
Copy Markdown
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!

}
} yield disk

private def checkAttachAction[F[_]](userInfo: UserInfo,
Copy link
Copy Markdown
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

case Some(pd) =>
for {
_ <- checkAttachAction(userInfo, samService, pd, cloudContext, req.name, ctx.traceId)
_ <- SamUtils.checkDiskAction(samService,
Copy link
Copy Markdown
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
Copy Markdown
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

@LizBaldo LizBaldo changed the base branch from develop to revert-4823-mtalbott-revert-listRuntimes February 12, 2025 17:16
@LizBaldo LizBaldo changed the base branch from revert-4823-mtalbott-revert-listRuntimes to develop February 12, 2025 17:17
@LizBaldo
Copy link
Copy Markdown
Collaborator

Arg, develop had the revert from the runtime changes so I messed this PR a bit sorry! Will likely open a new one to make things clearer, building on top of #4827

@LizBaldo LizBaldo mentioned this pull request Feb 14, 2025
4 tasks
@LizBaldo
Copy link
Copy Markdown
Collaborator

Closing this as I moved over the changes to this PR instead: #4828

@LizBaldo LizBaldo closed this Feb 14, 2025
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