@@ -60,7 +60,7 @@ func InitiateAzureOIDCFlow(ctx context.Context, sc *SetUpCmd, s spinner.Spinner)
6060 return err
6161 }
6262
63- if err := sc .assignSpRoles (ctx ); err != nil {
63+ if err := sc .assignSpRole (ctx ); err != nil {
6464 return err
6565 }
6666
@@ -164,28 +164,17 @@ func (sc *SetUpCmd) CreateServicePrincipal() error {
164164 return nil
165165}
166166
167- func (sc * SetUpCmd ) assignSpRoles (ctx context.Context ) error {
168- var spRoles = []string {
169- "b24988ac-6180-42a0-ab88-20f7382dd24c" , // Contributor role ID
170- "5af6afb3-c06c-4fa4-8848-71a8aee05683" , // Azure Kubernetes Fleet Manager RBAC Writer role ID
171- }
172- for _ , role := range spRoles {
173- if err := sc .assignRole (ctx , role ); err != nil {
174- return err
175- }
176- }
177- log .Debug ("Roles assigned successfully!" )
178- return nil
179- }
167+ func (sc * SetUpCmd ) assignSpRole (ctx context.Context ) error {
168+ log .Debug ("Assigning contributor role to service principal..." )
180169
181- func (sc * SetUpCmd ) assignRole (ctx context.Context , roleId string ) error {
182170 roleAssignClient , err := createRoleAssignmentClient (sc .SubscriptionID )
183171 if err != nil {
184172 return fmt .Errorf ("creating role assignment client: %w" , err )
185173 }
186174
187175 scope := fmt .Sprintf ("/subscriptions/%s/resourceGroups/%s" , sc .SubscriptionID , sc .ResourceGroupName )
188176 objectID := sc .spObjectId
177+ roleId := "b24988ac-6180-42a0-ab88-20f7382dd24c" // Contributor role ID
189178 raUid := uuid .New ().String ()
190179
191180 fullAssignmentId := fmt .Sprintf ("/%s/providers/Microsoft.Authorization/roleAssignments/%s" , scope , raUid )
@@ -205,6 +194,7 @@ func (sc *SetUpCmd) assignRole(ctx context.Context, roleId string) error {
205194 return fmt .Errorf ("creating role assignment: %w" , err )
206195 }
207196
197+ log .Debug ("Role assigned successfully!" )
208198 return nil
209199}
210200
0 commit comments