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

[PF-1681] Add discoverer policy when creating SAM workspace resource #755

Merged
merged 10 commits into from
Aug 10, 2022

Conversation

melissachang
Copy link
Contributor

This PR:

  • Changes WSM to understand SAM discoverer role
  • When a workspace is created, adds empty discoverer policy. (Since policies can only be added when a SAM resource is created.)

Future PRs will modify ListWorkspaces/GetWorkspace to add a request permission for returning discoverer workspaces. For now, ListWorkspaces does not return a workspace if caller is only discoverer.

Manually tested:

  • Created workspace. Can see empty discoverer policy with getRoles.
  • Called grantRole to add second user as discoverer
  • Second user calls GetWorkspace. GetWorkspace returns 403 as expected
  • At first, when second user called ListWorkspaces, discoverer workspace was returned, which was wrong. I made the change to SamService.java. Now when second user calls ListWorkspace, discoverer workspace is not returned.

WorkspaceApiControllerTest.java uses mock bio.terra.workspace.service.iam.SamService. I wanted my tests to use real bio.terra.workspace.service.iam.SamService, so I created WorkspaceApiControllerConnectedTest.java.

@@ -71,7 +72,11 @@ public StepResult doStep(FlightContext flightContext)
newBindings.addAll(currentPolicy.getBindings());
// Add appropriate project-level roles for each WSM IAM role.
workspaceRoleGroupsMap.forEach(
(role, email) -> newBindings.add(bindingForRole(role, email, gcpProjectId)));
(wsmRole, email) -> {
if (CUSTOM_GCP_PROJECT_IAM_ROLES.containsKey(wsmRole)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: now that CUSTOM_GCP_PROJECT_IAM_ROLES is imported, also update line 110?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


@Test
public void getWorkspace_doesNotReturnWorkspaceWithOnlyDiscovererRole() throws Exception {
ApiCreatedWorkspace workspace = createWorkspace();
Copy link
Contributor

Choose a reason for hiding this comment

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

since these are talking to real Sam, these tests will leave workspaces. could you delete them from these tests as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, thanks. I always forget when to have tests delete workspaces, so I added a section to README, PTAL.

Copy link
Contributor

@ddietterich ddietterich left a comment

Choose a reason for hiding this comment

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

The documentation is incorrect and we don't need to sync the discoverer role

@@ -316,3 +316,14 @@ The integration tests live in the `integration` project. Consult the integration

In the early days of the project, there were JUnit-based integration tests. We are in
process of migrating them to Test Runner.

#### Cleaning up workspaces in tests
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this is incorrect. Please double check my understanding @zloery

Janitor just deletes projects, it does not do anything to clean up Sam, so we should never skip in-test cleanup.
Connected tests also use RBS and Janitor. It doesn't have anything to do with WSM being ephemeral, since Janitor is just deleting projects.

Copy link
Contributor

Choose a reason for hiding this comment

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

We can use Janitor in two ways:

  1. the tools RBS instance registers every project it hands out with Janitor to be cleaned up after some time. Since all our connected tests talk to this instance, the GCP projects get cleaned up eventually
  2. After PF-886, you also can register a workspace with Janitor. After some time, Janitor will call WSM to delete the workspaces, which will clean up all of the WSM DB + Sam workspace + GCP project. The CLI tests use this when they run against real WSM environments, like dev.

We can't use the second pattern for WSM connected tests because the instance is ephemeral (so there's nothing for Janitor to call later), but we can and do use the first pattern to make sure the GCP projects get cleaned up. the Sam workspaces will still be around if the test doesn't clean them up, though

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if (highestRole.isPresent()) {
// TODO(PF-1875): Support requesting discoverer workspaces in ListWorkspaces.
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just filter in ListWorkspaces, so you don't have to remember to come back to this code?
You need the filtering there anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the next PR, I updated both here and ListWorkspaces.

@@ -47,6 +47,9 @@ public StepResult doStep(FlightContext flightContext)
workspaceRoleGroupMap.put(
WsmIamRole.READER,
samService.syncWorkspacePolicy(workspaceUuid, WsmIamRole.READER, userRequest));
workspaceRoleGroupMap.put(
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need to sync the discoverer role. That will create Google groups for discoverers. We only need that when we are going to apply that group to a cloud resource ACL; like granting a READER actual read access to a GCS bucket.

I think we only ever enforce discoverer by checking with Sam - never the cloud.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, good point.

README.md Outdated

#### Cleaning up workspaces in tests

For integration tests, don't need to delete workspaces because it's taken care of
Copy link
Contributor

Choose a reason for hiding this comment

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

TestRunner isn't integrated with Janitor so it isn't doing this cleanup (though it could if we were testing against live environments and we built that integration). The cleanup is currently part of the tests (though since it's included in the WorkspaceAllocateTestScriptBase base class, developers don't need to think about it while writing tests)

@melissachang melissachang merged commit 3cd7fc0 into main Aug 10, 2022
@melissachang melissachang deleted the mc/discoverer branch August 10, 2022 19:49
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