feat: detect and install permission drift if boolean is set - #48
feat: detect and install permission drift if boolean is set#48zaheersufi wants to merge 6 commits into
Conversation
|
I'm wondering if there is a way to change how this behaves. I don't think we want to delete and then create, as like you said that will change installation ID which seems error prone. I know the API itself lets you just re-install in place to update the permission list, but i'm not quite sure how that would map to the terraform world. I'm wondering if terraform is the right tool for the job, or if we would be better served with a separate permission drift detection job. The issue i see is we really should have the permissions as part of the IaC, so its explicit to approver what has chnaged. The problem is that implies the org owner can choose which permissions to apply to the installation, which isn't how the permission model works. |
To my knowledge this isn't the case. You could achieve this by getting rid of the
I agree. I think as long as there isn't a clear API to accept the permissions (without creating a brittle API to access the Web UI endpoint in a browser to click Accept), the best way might be to handle the drift out of terraform. |
0f1031f to
5c72834
Compare
|
Turns out instead of worrying about deletion -> reinstallation, we can just call the installation. This would accept the new permissions in place, not having to worry about generating a new |
c044dee to
81f2c75
Compare
Fixes #45
Summary
This PR adds an optional boolean attribute
auto_accept_permission_drift(defaulting tofalse) to thegh-app-unofficial_installationresource. This attribute allows operators to configure how Terraform responds when a GitHub App definition updates its requested permissions on GitHub.Default Behavior (
auto_accept_permission_drift = false)Read()tracks active installed permissions in the target organization.installation_id: Terraform will not automatically accept permission changes upon drift.Opt-In Behavior (
auto_accept_permission_drift = true)ModifyPlan()queries the GitHub App definition endpoint (GET /apps/{app_slug}) to compare requested permissions against active installed permissions.terraform apply, Terraform executesInstallAppto auto-accept updated permissions directly on GitHub, followed byUpdateAppInstallationRepositoriesto ensure repository access lists remain in sync.installation_id: Unlike resource replacement, in-place update preserves the existinginstallation_id, avoiding outages or broken references in downstream systems (such as Vault, Kubernetes secrets, or CI/CD pipelines).Important Tradeoffs & Considerations
auto_accept_permission_drift = trueautomatically consents to permission escalations requested by the GitHub App definition duringterraform apply.Key Changes
auto_accept_permission_driftboolean attribute to the resource schema ininternal/provider/installation_resource.go.ModifyPlan()to queryclient.Apps.Get(ctx, appSlug)and markpermissions,events, andupdated_atasknown after applywhen drift is detected and auto-acceptance is enabled.Update()to executeInstallApp(auto-accepting permissions) andUpdateAppInstallationRepositories(syncing repository selection).auto_accept_permission_drift = truecombined with repository updates ininternal/provider/installation_resource_test.go.docs/resources/installation.md.