Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

cmd/deploy: Handle error due to missing permissions during deploy #2297

Merged
merged 2 commits into from
Feb 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,11 @@ func autofillApimodel(dc *deployCmd) {
log.Warnf("created application with applicationID (%s) and servicePrincipalObjectID (%s).", applicationID, servicePrincipalObjectID)

log.Warnln("apimodel: ServicePrincipalProfile was empty, assigning role to application...")
for {
err = dc.client.CreateRoleAssignmentSimple(dc.resourceGroup, servicePrincipalObjectID)
if err != nil {
log.Debugf("Failed to create role assignment (will retry): %q", err)
time.Sleep(3 * time.Second)
continue
}
break

err = dc.client.CreateRoleAssignmentSimple(dc.resourceGroup, servicePrincipalObjectID)
if err != nil {
log.Fatalf("apimodel: could not create or assign ServicePrincipal: %q", err)

}

dc.containerService.Properties.ServicePrincipalProfile = &api.ServicePrincipalProfile{
Expand Down
11 changes: 9 additions & 2 deletions pkg/armhelpers/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package armhelpers

import (
"fmt"
"time"

"github.com/Azure/azure-sdk-for-go/arm/authorization"
"github.com/Azure/azure-sdk-for-go/arm/graphrbac"
"github.com/Azure/go-autorest/autorest/date"
"github.com/Azure/go-autorest/autorest/to"
"github.com/satori/go.uuid"
log "github.com/sirupsen/logrus"
"regexp"
"time"
)

const (
Expand Down Expand Up @@ -97,13 +97,20 @@ func (az *AzureClient) CreateRoleAssignmentSimple(resourceGroup, servicePrincipa
},
}

re := regexp.MustCompile("(?i)status=(\\d+)")
for {
_, err := az.CreateRoleAssignment(
scope,
roleAssignmentName,
roleAssignmentParameters,
)
if err != nil {
match := re.FindStringSubmatch(err.Error())
if match != nil && (match[1] == "403") {
//insufficient permissions. stop now
log.Debugf("Failed to create role assignment (will abort now): %q", err)
return err
}
log.Debugf("Failed to create role assignment (will retry): %q", err)
time.Sleep(3 * time.Second)
continue
Expand Down