Skip to content

Commit 3a0f4bd

Browse files
authored
Add devops identity as Storage Blob Data Contributor to rpversion SA (#4094)
1 parent 570ee26 commit 3a0f4bd

File tree

6 files changed

+118
-40
lines changed

6 files changed

+118
-40
lines changed

pkg/deploy/assets/rp-production-global.json

+17
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
"gatewayServicePrincipalId": {
1919
"type": "string"
2020
},
21+
"globalDevopsServicePrincipalId": {
22+
"type": "string"
23+
},
2124
"rpParentDomainName": {
2225
"type": "string"
2326
},
@@ -111,6 +114,20 @@
111114
"name": "[parameters('rpVersionStorageAccountName')]",
112115
"type": "Microsoft.Storage/storageAccounts",
113116
"apiVersion": "2021-09-01"
117+
},
118+
{
119+
"name": "[concat(parameters('rpVersionStorageAccountName'), '/Microsoft.Authorization/', guid(resourceId('Microsoft.Storage/storageAccounts', parameters('rpVersionStorageAccountName'))))]",
120+
"type": "Microsoft.Storage/storageAccounts/providers/roleAssignments",
121+
"properties": {
122+
"scope": "[resourceId('Microsoft.Storage/storageAccounts', parameters('rpVersionStorageAccountName'))]",
123+
"roleDefinitionId": "[subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '17d1049b-9a84-46fb-8f53-869881c3d3ab')]",
124+
"principalId": "[parameters('globalDevopsServicePrincipalId')]",
125+
"principalType": "ServicePrincipal"
126+
},
127+
"apiVersion": "2018-09-01-preview",
128+
"dependsOn": [
129+
"[resourceId('Microsoft.Storage/storageAccounts', parameters('rpVersionStorageAccountName'))]"
130+
]
114131
}
115132
]
116133
}

pkg/deploy/generator/resources_rp.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -1517,14 +1517,22 @@ func (g *generator) rpACRRBAC() []*arm.Resource {
15171517
}
15181518

15191519
func (g *generator) rpVersionStorageAccount() []*arm.Resource {
1520+
storageAccountName := "parameters('rpVersionStorageAccountName')"
15201521
return []*arm.Resource{
15211522
g.storageAccount(
1522-
"[parameters('rpVersionStorageAccountName')]",
1523+
fmt.Sprintf("[%s]", storageAccountName),
15231524
&mgmtstorage.AccountProperties{
15241525
AllowBlobPublicAccess: to.BoolPtr(false),
15251526
MinimumTLSVersion: mgmtstorage.MinimumTLSVersionTLS12,
15261527
},
15271528
map[string]*string{},
15281529
),
1530+
rbac.ResourceRoleAssignmentWithName(
1531+
rbac.RoleStorageAccountContributor,
1532+
"parameters('globalDevopsServicePrincipalId')",
1533+
resourceTypeStorageAccount,
1534+
storageAccountName,
1535+
fmt.Sprintf("concat(%s, '/Microsoft.Authorization/', guid(resourceId('%s', %s)))", storageAccountName, resourceTypeStorageAccount, storageAccountName),
1536+
),
15291537
}
15301538
}

pkg/deploy/generator/templates_rp.go

+1
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ func (g *generator) rpGlobalTemplate() *arm.Template {
193193
"rpParentDomainName",
194194
"rpServicePrincipalId",
195195
"rpVersionStorageAccountName",
196+
"globalDevopsServicePrincipalId",
196197
}
197198

198199
for _, param := range params {

pkg/deploy/predeploy.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,13 @@ func (d *deployer) PreDeploy(ctx context.Context, lbHealthcheckWaitTimeSec int)
108108
return err
109109
}
110110

111+
globalDevopsMSI, err := d.globaluserassignedidentities.Get(ctx, *d.config.Configuration.GlobalResourceGroupName, *d.config.Configuration.GlobalDevopsManagedIdentity)
112+
if err != nil {
113+
return err
114+
}
115+
111116
// deploy ACR RBAC, RP version storage account
112-
err = d.deployRPGlobal(ctx, rpMSI.PrincipalID.String(), gwMSI.PrincipalID.String())
117+
err = d.deployRPGlobal(ctx, rpMSI.PrincipalID.String(), gwMSI.PrincipalID.String(), globalDevopsMSI.PrincipalID.String())
113118
if err != nil {
114119
return err
115120
}
@@ -158,7 +163,7 @@ func (d *deployer) PreDeploy(ctx context.Context, lbHealthcheckWaitTimeSec int)
158163
return d.configureServiceSecrets(ctx, lbHealthcheckWaitTimeSec)
159164
}
160165

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

164169
asset, err := assets.EmbeddedFiles.ReadFile(generator.FileRPProductionGlobal)
@@ -179,6 +184,9 @@ func (d *deployer) deployRPGlobal(ctx context.Context, rpServicePrincipalID, gat
179184
parameters.Parameters["gatewayServicePrincipalId"] = &arm.ParametersParameter{
180185
Value: gatewayServicePrincipalID,
181186
}
187+
parameters.Parameters["globalDevopsServicePrincipalId"] = &arm.ParametersParameter{
188+
Value: devopsServicePrincipalId,
189+
}
182190

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

0 commit comments

Comments
 (0)