-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Deleting service default service accounts when creating a new project #4135
Deleting service default service accounts when creating a new project #4135
Comments
#4132, GoogleCloudPlatform/magic-modules#2401 were both an implementation + upstreaming of this, but fell out of date. Once this is picked up, they'll be useful as references. |
I'm a bit confused about what the use case for this is. From what I can tell via https://cloud.google.com/iam/docs/service-accounts, there are a few service accounts that are created when specific APIs are enabled on the project (compute, etc.) that need to stick around, but also aren't created at the same time the project is created. Which service accounts are the ones you're hoping to delete with this issue? |
Hi folks, Please, let me know your considerations. |
I'd actually like to propose we do this in a separate resource instead of coupling it to project creation. |
Ok. Any considerations from the maintainers? |
@morgante: That's so that it can run after service activations, right? I think it's fine if we do that, since we'll catch a good number of default SAs that way. We should note in the resource that specifying the resource does not ensure that all default SAs have been removed- just that Terraform attempted to remove them at some point. |
@morgante Also another question for you, we currently support disable, delete, and deprivilege. Should we support all these three states? |
Right, I also want to avoid adding more logic to
Yes I think so ( |
okay. I'll work on that. Once I have something I'll put in here for discussion. |
Hi folks, I had time to give some thought to it today and this is what I came up with:
This would be the main code for the new resource (of course it is not in terraform format yet). Please, let me know if I can keep following this path. |
This is the pdsa package for your consideration too |
terraforming it:
|
@morgante what's the behaviour we want when the project id or the action is updated? I think we should ignore it since it could perform actions on non-default service accounts, does it make sense? Do you know if is there any way to filter only "defaults" SAs? |
@thiagonache I think we should actually restrict this to only the default service accounts (based on filtering the name): https://cloud.google.com/iam/docs/service-accounts#default If you change the project ID that should be treated as a delete & recreate IMO ("delete" the resource on the old project, "create" it on the new one). Changing the action should be an update. Here's my proposed state changes:
|
I didn't know we could have just two. Honestly, I've never checked that before.
Agreed
Actually, if it is deleted we should do nothing on the destroy. Otherwise, we'll not be able to destroy the resource when the original action is delete. Does it make sense? Thank you!!! |
Technically you could remove it from your state file, but that seems fine too. |
Reactivation would add significant complexity to the resource, right? We'd need to know the list of default SAs and their associated IAM roles, and recreate them + assign those roles (maintenance would be pretty high, too- we'd need to update the resource any time a new default SA is added). In contrast, the initial delete/disable/deprivilege action we can infer based on the project number. I would propose that both the action and project are This leaves one big gap- reactivation. If that would have a significant benefit, we could consider adding that on delete. Do we expect users would want to walk back the disablement of all the accounts often? @morgante: I'd like to avoid cases where users need to edit their state file to remove a resource. |
Always using I do think reactivation is important to include. We've seen a number of support cases where customers were unsure how to reactivate and needed to in order to use certain products. |
yeah... I meant just regarding the service account. on destroy we should always remove from the state. |
I was following this path ^^
|
Yeah... I could figure out by myself but I did this issue when using GKE for the first time. But I agree it would be hard to maintain over time. The roles associated and the number of default services accounts may change. |
We don't necessarily need to restore the roles, but I think reactivating any deactivate accounts is doable. |
sounds good to me. @rileykarson ? (sorry for tagging out, since you already was messaged I'll not remove it) |
Reactivation seems fine to do, then! Specifically enabling a disabled service account, since we can list the service accounts and filter for disabled ones. Restoring roles and undelete would require more information than we'll have available. We don't know the role:sa mapping to reprivelege, and won't know the complete list of SA emails to attempt to undelete. @thiagonache: Something we could consider is a |
I'll submit a draft PR soon. |
hey, Riley. Please, see the PR mentioned. hey, Dana. Looks like you were selected to review the PR. Looking forward to hearing from you. |
Hey guys
Morgante or Riley, I've added support to undelete the service account when it was deleted too. If any of you guys want to take a look and see if I did not forget anything would be helpful. |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks! |
Community Note
Description
When creating a new project, I would like to also delete the default service accounts that are created with it.
Since I will be using custom service accounts for the project, the default ones should be deleted.
It will be very helpful if the google_project resource offers this option. This way, I could avoid to trigger gcloud commands to delete service account after the project creation (and avoid gcloud depencency in the terraform run environment)
New or Affected Resource(s)
Potential Terraform Configuration
I would like to propose a new parameter in
google_project
resource. The new parameter could work as the existingauto_create_network
(that delete auto created default network)References
Pull request:
#4132
The text was updated successfully, but these errors were encountered: