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

Handle a special use-case of user home directory permissions #3586

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

favoretti
Copy link

@favoretti favoretti commented May 16, 2024

Changes

In a special case when one would want to add rights for extra users to either view or edit things in one's home directory - the user's own CAN_MANAGE permission is implicit.

One can specify it explicitly in the resource, however, during deletion that CAN_MANAGE permission can not be removed, resulting in a failed run that can't be fixed without deleting resource from the state (which leaves other permissions hanging).

Hence here's an attempt to ignore or implicitly add it.

This works when permission is supplied with directory_path that matches the user_name, however, this also doesn't work when we specify user_id...

Therefore as WIP for now..

Tests

  • make test run locally
  • relevant change in docs/ folder
  • covered with integration tests in internal/acceptance
  • relevant acceptance tests are passing
  • using Go SDK

@codecov-commenter
Copy link

codecov-commenter commented May 17, 2024

Codecov Report

Attention: Patch coverage is 31.25000% with 11 lines in your changes missing coverage. Please review.

Project coverage is 81.56%. Comparing base (2a9379a) to head (531fd13).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3586      +/-   ##
==========================================
- Coverage   81.60%   81.56%   -0.05%     
==========================================
  Files         196      196              
  Lines       19744    19758      +14     
==========================================
+ Hits        16112    16115       +3     
- Misses       2672     2680       +8     
- Partials      960      963       +3     
Files Coverage Δ
permissions/resource_permissions.go 87.41% <31.25%> (-3.40%) ⬇️

Copy link
Contributor

@alexott alexott left a comment

Choose a reason for hiding this comment

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

We also need to test how it will behave if we'll try to change permissions for user/SP from manage to lower, like, CAN_READ...

@@ -215,6 +215,16 @@ func (a PermissionsAPI) Delete(objectID string) error {
accl.AccessControlList = append(accl.AccessControlList, change)
}
}

// handle special case when we add extra permission to a user home dir
if v, ok := d.GetOk("directory_path"); ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to think how we will handle this for the case when we specify object ID instead of directory path...

Copy link
Author

@favoretti favoretti May 17, 2024

Choose a reason for hiding this comment

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

Yeah, that's a tricky one my brain refused to wrap itself around at 3am.. Directory ID won't match user_name of course, but fetching a user record based on a user name seemed like an overkill. Open for any hints here.

Now that I think about it.. Even if I fetch the user record, user id won't match directory id, so there's no real way for me to correlate.. Maybe fetch directory object based on id and get its path? If that's even an option...

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, it's possible to get the directory path by object iD

@favoretti
Copy link
Author

We also need to test how it will behave if we'll try to change permissions for user/SP from manage to lower, like, CAN_READ...

This particular use-case is only intended for a single corner-case permission: user X to /Users/X, so just this particular user's home dir. That case of CAN_MANAGE is implicit, you can't lower it I believe.

@tanmay-db tanmay-db self-requested a review May 21, 2024 13:24
@favoretti favoretti marked this pull request as ready for review June 14, 2024 11:44
@favoretti favoretti requested review from a team as code owners June 14, 2024 11:44
@alexott alexott requested a review from mgyucht June 14, 2024 15:12
@alexott
Copy link
Contributor

alexott commented Jun 14, 2024

I'm clarifying with the team who is responsible for workspace-level permissions

@@ -215,6 +215,16 @@ func (a PermissionsAPI) Delete(objectID string) error {
accl.AccessControlList = append(accl.AccessControlList, change)
}
}

// handle special case when we add extra permission to a user home dir
if v, ok := d.GetOk("directory_path"); ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

yes, it's possible to get the directory path by object iD

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that we'll need to expand tests to cover this stuff.

@@ -215,6 +215,16 @@ func (a PermissionsAPI) Delete(objectID string) error {
accl.AccessControlList = append(accl.AccessControlList, change)
}
}

// handle special case when we add extra permission to a user home dir
if v, ok := d.GetOk("directory_path"); ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

We may need to disallow changes only for the current user - then we'll need to add a check like if me == accessControl.UserName || me == accessControl.ServicePrincipalName { like below. We also need to handle the case of home directory of the service principal, not only ordinary users.

@alexott
Copy link
Contributor

alexott commented Jun 14, 2024

I got confirmation from the dev team:

Currently, the DirectoryPermissionsHandler prevents users from changing the CAN_MANAGE permissions of a user on its own home folder.

@favoretti favoretti force-pushed the favoretti/special_user_home_permission_case branch from c02fbc4 to 531fd13 Compare June 17, 2024 12:01
@favoretti
Copy link
Author

@alexott So, to summarize what I need to do to get this merged:

  1. Add SPN home directories to the use-case
  2. Handle object_id next to currently implemented directory_path
  3. Write tests

Correct?

@alexott
Copy link
Contributor

alexott commented Jun 17, 2024

yes, it looks like. @mgyucht I think it makes sense to discuss in the next office hours

Copy link
Contributor

@tanmay-db tanmay-db left a comment

Choose a reason for hiding this comment

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

The logic looks good to me overall, I had a concern on checking CAN_MANAGE with first index of the list.


// handle special case when we add extra permission to a user home dir
if v, ok := d.GetOk("directory_path"); ok {
if v.(string) == fmt.Sprintf("/Users/%s", acl.UserName) && acl.AllPermissions[0].PermissionLevel == "CAN_MANAGE" {
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 only compare with the first index of the list? Just to confirm, is it necessar that CAN_MANAGE will always be at 0 index?

Copy link
Author

Choose a reason for hiding this comment

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

@tanmay-db That is... a great question, considering that this PR has been hanging here for a while - I'm not sure... I'm unfortunately not that knee-deep in databricks provider code, would you mind suggesting an alternative?

Copy link
Contributor

Choose a reason for hiding this comment

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

@alexott and me discussed this and we think going ahead with checking all the items in the list would be more safer.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just to check, after this extending this to SPN and adding tests would be left before we can merge this right?

Copy link
Author

Choose a reason for hiding this comment

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

@tanmay-db Something like this?

Copy link
Author

Choose a reason for hiding this comment

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

Just to check, after this extending this to SPN and adding tests would be left before we can merge this right?

Expanding to SPN homedir you mean? Yeah, I'll need to work on that too, although I have no ideas what the format of SPN's home dir is... is it /Users/<spn_id>? If so, which ID is it, Azure Object ID, Azure app ID or Databricks internal ID? :)

As for tests... I'll do my best, but would really appreciate some help, I'm incredibly new to your codebase :)

Copy link
Contributor

Choose a reason for hiding this comment

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

it's SPN's Application ID (UUID)

Copy link
Contributor

Choose a reason for hiding this comment

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

@favoretti, yes, to optimise a little, we can add break in the loop when we find the permission level to CAN_MANAGE.

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.

4 participants