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

chore: Grant ownership common use cases #3356

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from

Conversation

sfc-gh-jcieslak
Copy link
Collaborator

@sfc-gh-jcieslak sfc-gh-jcieslak commented Jan 23, 2025

Changes

  • write and test common grant ownership use cases
  • link examples from grant ownership doc and grant ownership overview

@sfc-gh-jcieslak sfc-gh-jcieslak changed the base branch from main to dev January 23, 2025 13:51
Copy link

Integration tests cancelled for 4c89d0a93e47895f8b07a382c7c7cc097a892325

Copy link

Integration tests failure for 5d33cca65a684439272fb81723230d3765091121

Copy link

Integration tests cancelled for e59a4285e5bde19bf5137da17746793fcf3ed5d7

@sfc-gh-jcieslak sfc-gh-jcieslak marked this pull request as ready for review January 24, 2025 09:47
Copy link

Integration tests cancelled for 0a9c6cae80505eae1ea47b0c1b4414f5f999b9e3


### Granting ownership with a less privileged role (granting MANAGED ACCESS)

This example shows how less privileged can be used to transfer ownership of the objects they currently own.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This example shows how a less privileged role can...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Corrected

- Ownership of the created above database.
- MANAGE GRANTS privilege on the currently used role.

Once the ownership is taken away, you still must be able to take the ownership away, so that
Copy link
Collaborator

Choose a reason for hiding this comment

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

Once the ownership is taken away, you still must be able to take the ownership away

This is not clear. Did you mean taking it back to the original role?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, changed a bit. Lmk if that's enough.


This happened, because now, you don't own this database, and your current role cannot perform any actions on it.
To let the current role modify the database it doesn't own you possibly have a few choices. One of the possible options
is to grant the currently used role with necessary privilege (we chose this one in the examples below).
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: unordered list of the possibilities.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added numbering

@@ -21,6 +21,8 @@ description: |-
{{ if .HasExample -}}
## Example Usage

For more examples, head over to our usage guide where we present how to use the grant_ownership resource in [common use cases](https://registry.terraform.io/providers/Snowflake-Labs/snowflake/latest/docs/guides/grant_ownership_common_use_cases).
Copy link
Collaborator

Choose a reason for hiding this comment

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

Relative link pls

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

---
# Grant ownership - common use cases

This guide is a follow-up for the [grant_ownership resource overview](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/docs/technical-documentation/grant_ownership_resource_overview.md) document.
Copy link
Collaborator

Choose a reason for hiding this comment

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

permalink pls

Copy link
Collaborator Author

@sfc-gh-jcieslak sfc-gh-jcieslak Jan 29, 2025

Choose a reason for hiding this comment

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

Done

# Grant ownership - common use cases

This guide is a follow-up for the [grant_ownership resource overview](https://github.com/Snowflake-Labs/terraform-provider-snowflake/blob/main/docs/technical-documentation/grant_ownership_resource_overview.md) document.
Those examples should help you to work with difficulties imposed by Snowflake role management and Terraform.
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's maybe phrase it without the "difficulties" part: These examples should guide you through Snowflake role management and TF (or something similar)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Rephrased

- [Granting ownership with a less privileged role (granting MANAGED ACCESS)](#granting-ownership-with-a-less-privileged-role-granting-managed-access)
- [Modifying objects you don't own after transferring the ownership](#modifying-objects-you-dont-own-after-transferring-the-ownership)

If other common problematic cases arise, we will add them to this list.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This list may be further extended with more cases; please approach us through GH issue (link) if you would like to see any others or contribute (permalink to guidelines).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

If other common problematic cases arise, we will add them to this list.

### Basic RBAC example
Here's an easy example of using RBAC (Role-based Access Control). Of course, there are many ways to perform RBAC, and here, we are not proposing any
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's suggest here that they may discuss the possibilities with their account managers and that usual route should be:

  1. come up with the proper rbac for their use case
  2. implement this use case in tf

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

Once the ownership is taken away, you still must be able to take the ownership away, so that
the Terraform is able to perform successful delete operation once the resource is removed from the configuration.
That being said, granting ownership would be still possible without MANAGE GRANTS, but you wouldn't be able to grant
the ownership back to the original role. This is a common mistake when dealing with ownership transfers. With Terraform, you have to think
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we link the error that appears in such a setup as an example?

Copy link
Collaborator Author

@sfc-gh-jcieslak sfc-gh-jcieslak Jan 30, 2025

Choose a reason for hiding this comment

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

I couldn't find anything useful, so I created a simple example showing what would happen.

@@ -0,0 +1,294 @@
---
page_title: "Grant ownership - common use cases"
Copy link
Collaborator

Choose a reason for hiding this comment

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

general thought: let's link this guide also from our FAQ in the repo, wdyt?

Copy link
Collaborator Author

@sfc-gh-jcieslak sfc-gh-jcieslak Jan 30, 2025

Choose a reason for hiding this comment

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

Good point, added


### Modifying objects you don't own after transferring the ownership

By transferring ownership of an object to another role, you are limiting currently used role's access control on this object.
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's add here this context about why managing ownership in tf is not aligned well with tf idealogy

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added

There are possibly more paths that lead to the same place, but to keep it simple, we focus on less extreme cases.

Also, keep in mind that the currently used role has MANAGE GRANTS privilege which makes it easier.
For less privileged roles, your options are very limited, and it would be easier to grant ownership back for a second,
Copy link
Collaborator

Choose a reason for hiding this comment

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

this would be a much better example (it was the one we discussed several times to include). Let's add this which requires granting back.
Do not remove the one already present.


Also, keep in mind that the currently used role has MANAGE GRANTS privilege which makes it easier.
For less privileged roles, your options are very limited, and it would be easier to grant ownership back for a second,
perform the necessary action and grant the ownership back. For a less invasive approach, you could perform grants manually and import
Copy link
Collaborator

Choose a reason for hiding this comment

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

add this one too. The idea behind these examples were to show possibilities for non-trivial/non-fully-automatic options.

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