Skip to content

Commit

Permalink
role def update
Browse files Browse the repository at this point in the history
  • Loading branch information
mrWinston committed Jan 21, 2025
1 parent b0bb371 commit ec193cf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ func (c *roleDefinitionsClient) List(ctx context.Context, scope string, filter s
}

func (c *roleDefinitionsClient) CreateOrUpdate(ctx context.Context, scope string, roleDefinitionID string, roleDefinition mgmtauthorization.RoleDefinition) (mgmtauthorization.RoleDefinition, error){
return c.CreateOrUpdate(ctx, scope, roleDefinitionID, roleDefinition)
return c.RoleDefinitionsClient.CreateOrUpdate(ctx, scope, roleDefinitionID, roleDefinition)
}
17 changes: 14 additions & 3 deletions pkg/util/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,19 @@ func (c *Cluster) SetupWorkloadIdentity(ctx context.Context, vnetResourceGroup s
}

func (c *Cluster) workaroundDiskCsiPermissions(ctx context.Context, diskCsiDriverPrincipalID *string) error {
workaroundRole, err := c.roledefinitions.CreateOrUpdate(ctx, fmt.Sprintf("/subscriptions/%s", c.Config.SubscriptionID), diskCsiRoleName, mgmtauthorization.RoleDefinition{
Name: to.StringPtr(diskCsiRoleName),
allRoledefs, err := c.roledefinitions.List(ctx, fmt.Sprintf("/subscriptions/%s", c.Config.SubscriptionID), "")
if err != nil {
return fmt.Errorf("Error getting existing roles: %w", err)
}

roleID := uuid.DefaultGenerator.Generate()
for _, rd := range allRoledefs {
if *rd.RoleName == diskCsiRoleName {
roleID = *rd.Name
}
}

workaroundRole, err := c.roledefinitions.CreateOrUpdate(ctx, fmt.Sprintf("/subscriptions/%s", c.Config.SubscriptionID), roleID, mgmtauthorization.RoleDefinition{
RoleDefinitionProperties: &mgmtauthorization.RoleDefinitionProperties{
RoleName: to.StringPtr(diskCsiRoleName),
Description: to.StringPtr("Tmp disk csi role"),
Expand All @@ -431,7 +442,7 @@ func (c *Cluster) workaroundDiskCsiPermissions(ctx context.Context, diskCsiDrive
},
})
if err != nil {
return fmt.Errorf("Error creating workaround role: %w", err)
return fmt.Errorf("Error creating/updating workaround role: %w", err)
}
_, err = c.roleassignments.Create(
ctx,
Expand Down

0 comments on commit ec193cf

Please sign in to comment.