Add --role-assignments flag to clean unattached RAs#22
Conversation
21f23a1 to
edeaf96
Compare
jackfrancis
left a comment
There was a problem hiding this comment.
/lgtm
thank you @mboersma!
edeaf96 to
507bf44
Compare
|
I updated this to include the Bicep changes for the |
|
I've pushed a few changes to fix an issue where the delay was only running for 1 min, this means the code to run the role assignments was never running. This happened because there was a bunch of stale RG that built up and it took longer than 1 min to delete them all. The code to clean up the role assignments is still not executing. I don't know why, it works locally. For now I've run it manually to clear out the stale assignments. |
|
I deployed the current version as v0.4.3, but we're getting this in the Logic App logs: Yet in a cloud shell I can log in to the same subscription and run the core shell command, and it returns several IDs. |
|
I wonder if there might be an RBAC thing going on? On the surface it seems like it has enough permissions now, but I'll try in my sub with a fresh identity with only the same perms as the rg-cleanup identity and see if I can repro. Regardless it may be worth adding a guard in the script to make sure we handle the case where there are no role assignments to be deleted. I think the |
|
@mboersma indeed Maybe for further debugging we can output that command before we wrap it in |
|
I can see when I only have the perms of the rg-cleanup identity, I get no role assignments and this in the debug output: Whereas with my regular user I do see role assignments and So we must need to give rg-cleanup those additional permissions, but last I looked I don't think I could find an obvious way to do that. |
|
Running |
I was observing the same, but from two different machines with different credentials/permissions, the list including the query for empty principal names was returning different results. So I'm reasonably confident it's a permissions issue. |
|
From what I could find, I think the graph API has a mostly orthogonal authorization mechanism to the regular Azure RBAC. I tried roughly following these to try to set this up in my sub but was hitting issues:
I think the errors were something to the effect of "your managed identity's app ID doesn't exist" which probably makes sense because I don't think I "registered" my managed identity as an app properly. I couldn't find any docs for how to do that specifically (if I even need to?). My user account obviously has permissions to do what the CLI is doing, but at https://entra.microsoft.com/ I can't see where I'm granted any permissions that I could map to a managed identity. It might be easier to set up if rg-cleanup authenticates with a Service Principal + federated credential vs. managed identity, but I didn't get far enough to try that yet. Even then I started getting the sense that some of this might require some tenant-level admin to set up. |
|
I may have figured out the auth piece here. I think it boils down to adding an app role assignment to the managed identity we use for the cleanup job. That has to be done by an Entra admin. I think this is what that would look like with the CLI: where the @jsturtevant Who can I reach out to to get this set up in the CNCF sub? |
3b3638a to
2836d23
Compare
|
I wasn't able to get the And it seems to be working |
a450766 to
7479641
Compare
|
/lgtm Could we add some docs to the readme that point this out as a requirement? #22 (comment) |
7479641 to
5a9bdaa
Compare

Adds an optional
--role-assignmentsflag to the container that will clean up unattached role assignments.I tried to implement this all in the Go binary, but replicating the
az role assignments listlogic in go using the Graph API never quite worked, so instead I changed the container to run a shell script with theazcommand itself.