Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#4625 from whites11/role-assignment…
Browse files Browse the repository at this point in the history
…-principal-type

Add principal type to role assignment create parameters
  • Loading branch information
k8s-ci-robot authored and Berk Dehrioglu committed May 22, 2024
1 parent 005b9f8 commit 6cfcd9f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions azure/scope/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"encoding/json"
"strings"

"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/authorization/armauthorization/v2"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -352,6 +353,7 @@ func (m *MachineScope) RoleAssignmentSpecs(principalID *string) []azure.Resource
Scope: m.SystemAssignedIdentityScope(),
RoleDefinitionID: m.SystemAssignedIdentityDefinitionID(),
PrincipalID: principalID,
PrincipalType: armauthorization.PrincipalTypeServicePrincipal,
}
return roles
}
Expand Down
3 changes: 3 additions & 0 deletions azure/scope/machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"testing"

"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/authorization/armauthorization/v2"
azureautorest "github.com/Azure/go-autorest/autorest/azure"
"github.com/Azure/go-autorest/autorest/azure/auth"
"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -477,6 +478,7 @@ func TestMachineScope_RoleAssignmentSpecs(t *testing.T) {
Name: "azure-role-assignment-name",
ResourceGroup: "my-rg",
PrincipalID: ptr.To("fakePrincipalID"),
PrincipalType: armauthorization.PrincipalTypeServicePrincipal,
},
},
},
Expand Down Expand Up @@ -524,6 +526,7 @@ func TestMachineScope_RoleAssignmentSpecs(t *testing.T) {
Scope: "/subscriptions/123/resourceGroups/my-rg",
RoleDefinitionID: "/subscriptions/123/resourceGroups/my-rg/providers/Microsoft.Authorization/roleAssignments/123",
PrincipalID: ptr.To("fakePrincipalID"),
PrincipalType: armauthorization.PrincipalTypeServicePrincipal,
},
},
},
Expand Down
2 changes: 2 additions & 0 deletions azure/scope/machinepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"io"
"strings"

"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/authorization/armauthorization/v2"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -791,6 +792,7 @@ func (m *MachinePoolScope) RoleAssignmentSpecs(principalID *string) []azure.Reso
Scope: m.SystemAssignedIdentityScope(),
RoleDefinitionID: m.SystemAssignedIdentityDefinitionID(),
PrincipalID: principalID,
PrincipalType: armauthorization.PrincipalTypeServicePrincipal,
}
return roles
}
Expand Down
3 changes: 3 additions & 0 deletions azure/scope/machinepool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"testing"

"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/authorization/armauthorization/v2"
azureautorest "github.com/Azure/go-autorest/autorest/azure"
"github.com/Azure/go-autorest/autorest/azure/auth"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -800,6 +801,7 @@ func TestMachinePoolScope_RoleAssignmentSpecs(t *testing.T) {
Name: "role-assignment-name",
ResourceGroup: "my-rg",
PrincipalID: ptr.To("fakePrincipalID"),
PrincipalType: armauthorization.PrincipalTypeServicePrincipal,
},
},
},
Expand Down Expand Up @@ -847,6 +849,7 @@ func TestMachinePoolScope_RoleAssignmentSpecs(t *testing.T) {
Scope: "scope",
RoleDefinitionID: "role-definition-id",
PrincipalID: ptr.To("fakePrincipalID"),
PrincipalType: armauthorization.PrincipalTypeServicePrincipal,
},
},
},
Expand Down
2 changes: 2 additions & 0 deletions azure/services/roleassignments/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type RoleAssignmentSpec struct {
ResourceGroup string
ResourceType string
PrincipalID *string
PrincipalType armauthorization.PrincipalType
RoleDefinitionID string
Scope string
}
Expand Down Expand Up @@ -64,6 +65,7 @@ func (s *RoleAssignmentSpec) Parameters(ctx context.Context, existing interface{
Properties: &armauthorization.RoleAssignmentProperties{
PrincipalID: s.PrincipalID,
RoleDefinitionID: ptr.To(s.RoleDefinitionID),
PrincipalType: ptr.To(s.PrincipalType),
},
}, nil
}

0 comments on commit 6cfcd9f

Please sign in to comment.