-
Notifications
You must be signed in to change notification settings - Fork 567
OCPBUGS-84251: fix(azure): detect and replace stale role assignments on cluster re-creation #8322
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,12 +32,14 @@ func NewDestroyIAMCommand() *cobra.Command { | |
| cmd.Flags().StringVar(&opts.Cloud, "cloud", opts.Cloud, util.CloudDescription) | ||
| cmd.Flags().StringVar(&opts.Name, "name", opts.Name, util.NameDescription) | ||
| cmd.Flags().StringVar(&opts.InfraID, "infra-id", opts.InfraID, util.InfraIDDescription) | ||
| cmd.Flags().StringVar(&opts.DNSZoneRG, "dns-zone-rg-name", opts.DNSZoneRG, util.DNSZoneRGNameDestroyDescription) | ||
|
|
||
| _ = cmd.MarkFlagRequired("workload-identities-file") | ||
| _ = cmd.MarkFlagRequired("azure-creds") | ||
| _ = cmd.MarkFlagRequired("resource-group-name") | ||
| _ = cmd.MarkFlagRequired("name") | ||
| _ = cmd.MarkFlagRequired("infra-id") | ||
| _ = cmd.MarkFlagRequired("dns-zone-rg-name") | ||
|
|
||
| l := log.Log | ||
| cmd.RunE = func(cmd *cobra.Command, args []string) error { | ||
|
|
@@ -70,6 +72,7 @@ func BindDestroyIAMProductFlags(opts *DestroyIAMOptions, flags *pflag.FlagSet) { | |
| flags.StringVar(&opts.Cloud, "cloud", opts.Cloud, util.CloudDescription) | ||
| flags.StringVar(&opts.Name, "name", opts.Name, util.NameDescription) | ||
| flags.StringVar(&opts.InfraID, "infra-id", opts.InfraID, util.InfraIDDescription) | ||
| flags.StringVar(&opts.DNSZoneRG, "dns-zone-rg-name", opts.DNSZoneRG, "The resource group name where the DNS zone resides (used to clean up role assignments)") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my previous comment
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. Applied the same change here — AI-assisted response via Claude Code |
||
| } | ||
|
|
||
| // Validate validates the DestroyIAMOptions | ||
|
|
@@ -89,6 +92,9 @@ func (o *DestroyIAMOptions) Validate() error { | |
| if o.InfraID == "" { | ||
| return fmt.Errorf("infra-id is required") | ||
| } | ||
| if o.DNSZoneRG == "" { | ||
| return fmt.Errorf("dns-zone-rg-name is required") | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
|
|
@@ -110,6 +116,19 @@ func (o *DestroyIAMOptions) Run(ctx context.Context, l logr.Logger) error { | |
| "infraID", o.InfraID, | ||
| "resourceGroup", o.ResourceGroupName) | ||
|
|
||
| // Clean up role assignments before destroying identities to avoid orphans. | ||
| // Match the create path resource-group names: {name}-nsg and {name}-vnet. | ||
| nsgRG := o.Name + "-nsg" | ||
| vnetRG := o.Name + "-vnet" | ||
|
|
||
| rbacManager := NewRBACManager(subscriptionID, azureCreds) | ||
| // assignCustomHCPRoles=false is safe: GetServicePrincipalScopes only uses the flag to select | ||
| // the role definition ID, not to modify the scopes list. Cleanup derives role assignment names | ||
| // from infraID + component + scope, so the role ID is irrelevant. | ||
| if err := rbacManager.CleanupRoleAssignments(ctx, l, o.InfraID, o.ResourceGroupName, nsgRG, vnetRG, o.DNSZoneRG, false); err != nil { | ||
| l.Error(err, "Failed to clean up some role assignments, continuing with identity deletion") | ||
| } | ||
|
bryan-cox marked this conversation as resolved.
|
||
|
|
||
| // Create the identity manager | ||
| identityManager := NewIdentityManager(subscriptionID, azureCreds, o.Cloud) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would make this required instead than optional:
Additionally, we should properly document the flag in the existing howto Azure self-managed documentation in
docs/content/how-to/azure/There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Made
--dns-zone-rg-namerequired in all 3 destroy commands (cmd/cluster/azure/destroy.go,cmd/infra/azure/destroy_iam.go,product-cli/cmd/cluster/azure/destroy.go). Updated docs increate-self-managed-azure-cluster.md,create-iam-separately.md, anddeploy-azure-private-clusters.mdto include the flag in all destroy command examples.AI-assisted response via Claude Code