Skip to content
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

Add devops identity as Storage Account Contributor to rpversion SA #4094

Merged
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
17 changes: 17 additions & 0 deletions pkg/deploy/assets/rp-production-global.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
"gatewayServicePrincipalId": {
"type": "string"
},
"globalDevopsServicePrincipalId": {
"type": "string"
},
"rpParentDomainName": {
"type": "string"
},
Expand Down Expand Up @@ -111,6 +114,20 @@
"name": "[parameters('rpVersionStorageAccountName')]",
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2021-09-01"
},
{
"name": "[concat(parameters('rpVersionStorageAccountName'), '/Microsoft.Authorization/', guid(resourceId('Microsoft.Storage/storageAccounts', parameters('rpVersionStorageAccountName'))))]",
"type": "Microsoft.Storage/storageAccounts/providers/roleAssignments",
"properties": {
"scope": "[resourceId('Microsoft.Storage/storageAccounts', parameters('rpVersionStorageAccountName'))]",
"roleDefinitionId": "[subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '17d1049b-9a84-46fb-8f53-869881c3d3ab')]",
"principalId": "[parameters('globalDevopsServicePrincipalId')]",
"principalType": "ServicePrincipal"
},
"apiVersion": "2018-09-01-preview",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this API version correct/desired?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably not, but bumping this would require bumping the singleton apiversion we use for all Microsoft.Authorization resources so it'll be an involved effort.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack. No need to cut deeper than we have to for this specific change.

"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts', parameters('rpVersionStorageAccountName'))]"
]
}
]
}
10 changes: 9 additions & 1 deletion pkg/deploy/generator/resources_rp.go
Original file line number Diff line number Diff line change
Expand Up @@ -1517,14 +1517,22 @@ func (g *generator) rpACRRBAC() []*arm.Resource {
}

func (g *generator) rpVersionStorageAccount() []*arm.Resource {
storageAccountName := "parameters('rpVersionStorageAccountName')"
return []*arm.Resource{
g.storageAccount(
"[parameters('rpVersionStorageAccountName')]",
fmt.Sprintf("[%s]", storageAccountName),
&mgmtstorage.AccountProperties{
AllowBlobPublicAccess: to.BoolPtr(false),
MinimumTLSVersion: mgmtstorage.MinimumTLSVersionTLS12,
},
map[string]*string{},
),
rbac.ResourceRoleAssignmentWithName(
rbac.RoleStorageAccountContributor,
"parameters('globalDevopsServicePrincipalId')",
resourceTypeStorageAccount,
storageAccountName,
fmt.Sprintf("concat(%s, '/Microsoft.Authorization/', guid(resourceId('%s', %s)))", storageAccountName, resourceTypeStorageAccount, storageAccountName),
),
}
}
1 change: 1 addition & 0 deletions pkg/deploy/generator/templates_rp.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ func (g *generator) rpGlobalTemplate() *arm.Template {
"rpParentDomainName",
"rpServicePrincipalId",
"rpVersionStorageAccountName",
"globalDevopsServicePrincipalId",
}

for _, param := range params {
Expand Down
12 changes: 10 additions & 2 deletions pkg/deploy/predeploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,13 @@ func (d *deployer) PreDeploy(ctx context.Context, lbHealthcheckWaitTimeSec int)
return err
}

globalDevopsMSI, err := d.globaluserassignedidentities.Get(ctx, *d.config.Configuration.GlobalResourceGroupName, *d.config.Configuration.GlobalDevopsManagedIdentity)
if err != nil {
return err
}

// deploy ACR RBAC, RP version storage account
err = d.deployRPGlobal(ctx, rpMSI.PrincipalID.String(), gwMSI.PrincipalID.String())
err = d.deployRPGlobal(ctx, rpMSI.PrincipalID.String(), gwMSI.PrincipalID.String(), globalDevopsMSI.PrincipalID.String())
if err != nil {
return err
}
Expand Down Expand Up @@ -157,7 +162,7 @@ func (d *deployer) PreDeploy(ctx context.Context, lbHealthcheckWaitTimeSec int)
return d.configureServiceSecrets(ctx, lbHealthcheckWaitTimeSec)
}

func (d *deployer) deployRPGlobal(ctx context.Context, rpServicePrincipalID, gatewayServicePrincipalID string) error {
func (d *deployer) deployRPGlobal(ctx context.Context, rpServicePrincipalID, gatewayServicePrincipalID, devopsServicePrincipalId string) error {
deploymentName := "rp-global-" + d.config.Location

asset, err := assets.EmbeddedFiles.ReadFile(generator.FileRPProductionGlobal)
Expand All @@ -178,6 +183,9 @@ func (d *deployer) deployRPGlobal(ctx context.Context, rpServicePrincipalID, gat
parameters.Parameters["gatewayServicePrincipalId"] = &arm.ParametersParameter{
Value: gatewayServicePrincipalID,
}
parameters.Parameters["globalDevopsServicePrincipalId"] = &arm.ParametersParameter{
Value: devopsServicePrincipalId,
}

for i := 0; i < 2; i++ {
d.log.Infof("deploying %s", deploymentName)
Expand Down
Loading
Loading