Skip to content

DT-1202: Allow creating datasnapshot as a child resource of dataset #1640

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

Merged
merged 8 commits into from
Feb 14, 2025

Conversation

pshapiro4broad
Copy link
Member

@pshapiro4broad pshapiro4broad commented Feb 11, 2025

Jira ticket: https://broadworkbench.atlassian.net/browse/DT-1202

What:

To support inheriting dataset custodian role as steward on a snapshot, we need to allow

  • creating the datasnapshot with a parent resource (create_with_parent)
  • adding a child resource to a dataset (add_child)

Also, we need to specify that dataset custodian or steward are steward on datasnapshot, if the parent resource is set.

Why:

This is support the goal of avoiding adding dataset custodians to every snapshot, to prevent hitting GCP quota limits.

How:

With this change

  • users with snapshot_creator or greater role on dataset can add_child to dataset
  • users with custodian or greater role on dataset can list_children
  • users with steward role can create_with_parent to datasnapshot, and get_parent
  • dataset custodian or greater role are steward on child datasnapshots.

PR checklist

  • I've followed the instructions if I've made any changes to the API, especially if they're breaking changes
  • I've filled out the Security Risk Assessment (requires Broad Internal network access) and attached the result to the JIRA ticket

@pshapiro4broad pshapiro4broad requested a review from a team as a code owner February 11, 2025 18:01
@pshapiro4broad pshapiro4broad changed the title DT:1202: Add support for making datasnapshot a child resource of dataset DT-1202: Add support for making datasnapshot a child resource of dataset Feb 11, 2025
@pshapiro4broad pshapiro4broad changed the title DT-1202: Add support for making datasnapshot a child resource of dataset DT-1202: Allow creating datasnapshot as a child resource of dataset Feb 11, 2025
@@ -1435,11 +1438,14 @@ resourceTypes = {
add_child = {
description = "add a child resource"
}
create_with_parent = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is this action for? I think you probably want set_parent. https://github.com/broadinstitute/sam/blob/develop/README.md#resource-and-policy-management

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 got it from https://github.com/broadinstitute/sam/blob/develop/src/main/scala/org/broadinstitute/dsde/workbench/sam/model/SamModel.scala#L34
which is used by requireCreateWithOptionalParent:

        // parents are allowed for a resource type if the owner role contains the SamResourceActions.setParent or SamResourceActions.createWithParent action
        val parentAllowed = resourceType.roles
          .find(_.roleName == resourceType.ownerRoleName)
          .exists(role => role.actions.contains(SamResourceActions.setParent) || role.actions.contains(SamResourceActions.createWithParent))

Copy link
Member Author

@pshapiro4broad pshapiro4broad Feb 11, 2025

Choose a reason for hiding this comment

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

It looks like when this was added in #1441, the README wasn't updated. I can switch to using set_parent if that's preferred. Relevant slack thread: https://broadinstitute.slack.com/archives/C03GMG4DUSE/p1715026844061349

Copy link
Collaborator

Choose a reason for hiding this comment

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

Interesting. I guess you can keep your create_with_parent. If I had been paying attention, I might have suggested that they use set_parent but not grant remove_child on the parent.

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 might have suggested that they use set_parent but not grant remove_child on the parent.

Well, TDR is the only user of create_with_parent so we could stop doing it if you want us to. I don't have a strong opinion one way or the other.

# Conflicts:
#	src/main/resources/reference.conf
@pshapiro4broad pshapiro4broad requested a review from dvoet February 11, 2025 19:14
Copy link
Collaborator

@dvoet dvoet left a comment

Choose a reason for hiding this comment

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

I don't know if you intend to add parents after creating snapshots or not. If you do intend to add parents after the fact, then you will need set_parent

}
ownerRoleName = "steward"
roles = {
steward = {
roleActions = ["share_policy::steward", "share_policy::custodian", "update_passport_identifier", "view_journal"]
roleActions = ["share_policy::steward", "share_policy::custodian", "update_passport_identifier", "view_journal", "create_with_parent"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

You don't actually need to grant create_with_parent to anyone. The action's existence on the resource type is used only as a flag to allow resources to be created with a parent

Copy link
Member Author

Choose a reason for hiding this comment

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

When I tested this change in a bee, I found that it didn't work until I added create_with_parent as an action on the steward (owner) role.

I also tried adding create_with_parent as an action on custodian, which is included by steward, but that didn't work.

Looking at the Scala code, in SecurityDirectives.requireCreateWithOptionalParent():

        // parents are allowed for a resource type if the owner role contains the SamResourceActions.setParent or SamResourceActions.createWithParent action
        val parentAllowed = resourceType.roles
          .find(_.roleName == resourceType.ownerRoleName)
          .exists(role => role.actions.contains(SamResourceActions.setParent) || role.actions.contains(SamResourceActions.createWithParent))

It appears that this is what the code is requiring -- the action must directly be on the owner role.

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'm wondering if the failure of this to work with included roles is a bug. Looking at the code path for the set_parent operation (ResourceRoutes.setResourceParent()), the code uses SecurityDirectives.requireAction() which looks like it does support included roles.

includedRoles = ["custodian"]
descendantRoles = {
snapshot-builder-request = ["approver"]
}
}
custodian = {
roleActions = ["delete", "edit_datasnapshot", "update_snapshot", "share_policy::reader", "share_policy::aggregate_data_reader", "share_policy::discoverer", "read_policies", "set_public", "update_auth_domain", "lock_resource", "unlock_resource"]
roleActions = ["delete", "edit_datasnapshot", "update_snapshot", "share_policy::reader", "share_policy::aggregate_data_reader", "share_policy::discoverer", "read_policies", "set_public", "update_auth_domain", "lock_resource", "unlock_resource", "get_parent"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need "get_parent"?

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 think we'll need it in the UI, to find out of a snapshot has a parent dataset which is providing steward users to the snapshot. The UI can use this to fetch and show the dataset custodian users as "inherited" stewards in the Roles & Memberships tab.

@pshapiro4broad pshapiro4broad enabled auto-merge (squash) February 14, 2025 21:08
@pshapiro4broad pshapiro4broad merged commit c24b03f into develop Feb 14, 2025
20 checks passed
@pshapiro4broad pshapiro4broad deleted the ps/dt-1202-add-snapshot-parent branch February 14, 2025 21:22
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