-
Notifications
You must be signed in to change notification settings - Fork 21
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
marctalbott
wants to merge
10
commits into
develop
Choose a base branch
from
mtalbott-sam-disks
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
08950a1
listDisks
marctalbott 9194755
createDisk
marctalbott d7c68d9
getDiskv1
marctalbott 03e9d12
getDiskv2
marctalbott 9c5918e
deleteDiskv2
marctalbott c61d5a6
deleteDiskv1
marctalbott 154ffcd
updateDisk
marctalbott 06bd6ae
deleteDiskRecords
marctalbott 9a7e442
attachDisk
marctalbott 814a783
switch to object instead of trait
marctalbott File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,16 +4,16 @@ package service | |
|
||
import akka.http.scaladsl.model.StatusCodes | ||
import cats.Parallel | ||
import cats.data.NonEmptyList | ||
import cats.effect.Async | ||
import cats.effect.std.Queue | ||
import cats.mtl.Ask | ||
import cats.syntax.all._ | ||
import com.google.api.services.cloudresourcemanager.model.Ancestor | ||
import org.broadinstitute.dsde.workbench.google.GoogleProjectDAO | ||
import org.broadinstitute.dsde.workbench.google2.{DiskName, GoogleDiskService} | ||
import org.broadinstitute.dsde.workbench.leonardo.JsonCodec._ | ||
import org.broadinstitute.dsde.workbench.leonardo.SamResourceId._ | ||
import org.broadinstitute.dsde.workbench.leonardo.config.PersistentDiskConfig | ||
import org.broadinstitute.dsde.workbench.leonardo.dao.sam.SamService | ||
import org.broadinstitute.dsde.workbench.leonardo.db._ | ||
import org.broadinstitute.dsde.workbench.leonardo.http.service.DiskServiceInterp._ | ||
import org.broadinstitute.dsde.workbench.leonardo.model.SamResourceAction._ | ||
|
@@ -29,9 +29,6 @@ import org.broadinstitute.dsde.workbench.model.{TraceId, UserInfo, WorkbenchEmai | |
|
||
import java.time.Instant | ||
import java.util.UUID | ||
import org.broadinstitute.dsde.workbench.leonardo.SamResourceId._ | ||
import org.broadinstitute.dsde.workbench.leonardo.dao.sam.SamService | ||
|
||
import scala.concurrent.ExecutionContext | ||
|
||
class DiskServiceInterp[F[_]: Parallel](config: PersistentDiskConfig, | ||
|
@@ -207,72 +204,33 @@ class DiskServiceInterp[F[_]: Parallel](config: PersistentDiskConfig, | |
for { | ||
ctx <- as.ask | ||
|
||
// throw 403 if user doesn't have project permission | ||
hasProjectPermission <- cloudContext.traverse(cc => | ||
authProvider.isUserProjectReader( | ||
cc, | ||
userInfo | ||
) | ||
) | ||
_ <- F.raiseWhen(!hasProjectPermission.getOrElse(true))(ForbiddenError(userInfo.userEmail, Some(ctx.traceId))) | ||
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is so nice to see this code being deleted, thank you! |
||
partition = disks.partition(_.cloudContext.isInstanceOf[CloudContext.Gcp]) | ||
_ <- ctx.span.traverse(s => F.delay(s.addAnnotation("Done DB call"))) | ||
|
||
gcpDiskAndProjects = partition._1.map(d => (GoogleProject(d.cloudContext.asString), d.samResource)) | ||
gcpSamVisibleDisksOpt <- NonEmptyList.fromList(gcpDiskAndProjects).traverse { ds => | ||
authProvider | ||
.filterResourceProjectVisible(ds, userInfo) | ||
} | ||
|
||
// TODO: use filterUserVisible (and remove old function) or make filterResourceProjectVisible handle both Azure and GCP | ||
azureDiskAndProjects = partition._2.map(d => (GoogleProject(d.cloudContext.asString), d.samResource)) | ||
azureSamVisibleDisksOpt <- NonEmptyList.fromList(azureDiskAndProjects).traverse { ds => | ||
authProvider | ||
.filterUserVisibleWithProjectFallback(ds, userInfo) | ||
} | ||
|
||
samVisibleDisksOpt = (gcpSamVisibleDisksOpt, azureSamVisibleDisksOpt) match { | ||
case (Some(a), Some(b)) => Some(a ++ b) | ||
case (Some(a), None) => Some(a) | ||
case (None, Some(b)) => Some(b) | ||
case (None, None) => None | ||
} | ||
|
||
_ <- ctx.span.traverse(s => F.delay(s.addAnnotation("Done checking Sam permission"))) | ||
res = samVisibleDisksOpt match { | ||
case None => Vector.empty | ||
case Some(samVisibleDisks) => | ||
val samVisibleDisksSet = samVisibleDisks.toSet | ||
disks | ||
.filter(d => | ||
samVisibleDisksSet.contains( | ||
(GoogleProject(d.cloudContext.asString), d.samResource) | ||
) | ||
) | ||
.map(d => | ||
ListPersistentDiskResponse(d.id, | ||
d.cloudContext, | ||
d.zone, | ||
d.name, | ||
d.status, | ||
d.auditInfo, | ||
d.size, | ||
d.diskType, | ||
d.blockSize, | ||
d.labels.filter(l => paramMap._3.contains(l._1)), | ||
d.workspaceId | ||
) | ||
) | ||
.toVector | ||
} | ||
// We authenticate actions on resources. If there are no visible disks, | ||
// we need to check if user should be able to see the empty list. | ||
_ <- if (res.isEmpty) authProvider.checkUserEnabled(userInfo) else F.unit | ||
} yield res | ||
disks <- DiskServiceDbQueries | ||
.listDisksBySamIds(samDiskIds.map(PersistentDiskSamResourceId), | ||
paramMap._1, | ||
paramMap._2, | ||
creatorOnly, | ||
cloudContext | ||
) | ||
.transaction | ||
} yield disks | ||
.map(d => | ||
ListPersistentDiskResponse(d.id, | ||
d.cloudContext, | ||
d.zone, | ||
d.name, | ||
d.status, | ||
d.auditInfo, | ||
d.size, | ||
d.diskType, | ||
d.blockSize, | ||
d.labels.filter(l => paramMap._3.contains(l._1)), | ||
d.workspaceId | ||
) | ||
) | ||
.toVector | ||
|
||
override def deleteDisk(userInfo: UserInfo, googleProject: GoogleProject, diskName: DiskName)(implicit | ||
as: Ask[F, AppContext] | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.