Skip to content

Commit bdb750d

Browse files
author
Sheyla Trudo
committed
fixup! User Service Connections
1 parent 042000a commit bdb750d

File tree

3 files changed

+29
-46
lines changed

3 files changed

+29
-46
lines changed

.pipelines/run-pipeline.yaml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ stages:
2323
dependsOn: pre_build
2424
variables:
2525
ACN_DIR: $(Build.SourcesDirectory)
26-
SYSTEM_DEBUG: $[ coalesce(variables.SYSTEM_DEBUG, 'False') ]
2726
jobs:
2827
- job: env
2928
displayName: Setup
@@ -53,7 +52,7 @@ stages:
5352
displayName: "Set environmental variables"
5453
5554
- job: resources
56-
displayName: "[Infra] Configure Artifact Resources"
55+
displayName: "[Infra] Configure Build Resources"
5756
variables:
5857
ACNCI_BUILDUSER_ROLE_NAME: "ACN CI/CD Build Environment Owner"
5958
ACNCI_MANAGEDIDENTITY_PREFIX: acnci-builds-
@@ -184,7 +183,6 @@ stages:
184183
- test
185184
variables:
186185
ACN_DIR: $(Build.SourcesDirectory)
187-
SYSTEM_DEBUG: $[ coalesce(variables.SYSTEM_DEBUG, 'False') ]
188186
jobs:
189187
- job: containerize_amd64
190188
displayName: Build Images
@@ -346,7 +344,6 @@ stages:
346344
variables:
347345
Packaging.EnableSBOMSigning: false
348346
ACN_DIR: $(Build.SourcesDirectory)
349-
SYSTEM_DEBUG: $[ coalesce(variables.SYSTEM_DEBUG, 'False') ]
350347
jobs:
351348
- job: manifest
352349
displayName: Compile Manifests
@@ -553,7 +550,6 @@ stages:
553550
variables:
554551
ACN_DIR: $(Build.SourcesDirectory)
555552
commitID: $[ stagedependencies.setup.env.outputs['EnvironmentalVariables.commitID'] ]
556-
SYSTEM_DEBUG: $[ coalesce(variables.SYSTEM_DEBUG, 'False') ]
557553
jobs:
558554
- job: delete
559555
displayName: Delete Cluster

.pipelines/templates/create-or-update-resource.steps.yaml

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,15 @@ steps:
112112
#[[ -n $SYSTEM_DEBUG ]] && [[ $SYSTEM_DEBUG =~ $IS_TRUE ]] && set -x || set +x
113113
az upgrade -y
114114
115-
echo "az storage account create --name "$STORAGEACCOUNT_NAME" --location "$STORAGEACCOUNT_LOCATION" --resource-group "$RESOURCEGROUP_NAME" --allow-blob-public-access false --allow-shared-key-access false --tags "$BUILDTAG_DEFINITIONID"="$SYSTEM_DEFINITIONID" "$BUILDTAG_CREATEDBYBUILDID"="$BUILD_BUILDID" "$BUILDTAG_CREATEDBYAPPID"="$servicePrincipalId""
116-
az storage account create --name "$STORAGEACCOUNT_NAME" --location "$STORAGEACCOUNT_LOCATION" --resource-group "$RESOURCEGROUP_NAME" --allow-blob-public-access false --allow-shared-key-access false --tags "$BUILDTAG_DEFINITIONID"="$SYSTEM_DEFINITIONID" "$BUILDTAG_CREATEDBYBUILDID"="$BUILD_BUILDID" "$BUILDTAG_CREATEDBYAPPID"="$servicePrincipalId"
115+
az storage account create \
116+
--name "$STORAGEACCOUNT_NAME" \
117+
--location "$STORAGEACCOUNT_LOCATION" \
118+
--resource-group "$RESOURCEGROUP_NAME" \
119+
--allow-blob-public-access false \
120+
--allow-shared-key-access false \
121+
--tags "$BUILDTAG_DEFINITIONID"="$SYSTEM_DEFINITIONID" \
122+
"$BUILDTAG_CREATEDBYBUILDID"="$BUILD_BUILDID" \
123+
"$BUILDTAG_CREATEDBYAPPID"="$servicePrincipalId"
117124
118125
${{ elseif eq(parameters.resourceType, 'roledefinition') }}:
119126
inlineScript: |
@@ -134,30 +141,6 @@ steps:
134141
--tags "$ACNCI_BUILDTAG_DEFINITIONID"="$SYSTEM_DEFINITIONID" \
135142
"$ACNCI_BUILDTAG_CREATEDBYBUILDID"="$BUILD_BUILDID" \
136143
"$ACNCI_BUILDTAG_CREATEDBYAPPID"="$servicePrincipalId"
137-
138-
${{ elseif eq(parameters.resourceType, 'serviceconnection') }}:
139-
inlineScript: |
140-
set -e
141-
[[ -n $SYSTEM_DEBUG ]] && [[ $SYSTEM_DEBUG =~ $IS_TRUE ]] && set -x || set +x
142-
143-
## Requires manual creation
144-
145-
#az config set extension.use_dynamic_install=yes_without_prompt
146-
##az devops login --identity "$SERVICECONNECTION_PRINCIPALID"
147-
#az config set extension.dynamic_install_allow_preview=true
148-
##jq '.requiredResourceAccess = "$STORAGECONTAINER_ID"'
149-
##jq '.appId = "$MANAGEDIDENTITY_APPID"'
150-
##jq '.tags["$BUILDTAG_APPID"] = "$APPID"'
151-
##jq '.tags["$BUILDTAG_DEFINITIONID"] = "$SYSTEM_DEFINITIONID"'
152-
#az devops login
153-
#az devops service-endpoint azurerm create \
154-
#--org "https://dev.azure.com/msazure/" \
155-
#--azure-rm-service-principal-id "$SERVICECONNECTION_PRINCIPALID" \
156-
#--azure-rm-subscription-id "$SUBSCRIPTION_ID" \
157-
#--azure-rm-subscription-name "$SUBSCRIPTION_NAME" \
158-
#--azure-rm-tenant-id "$SERVICECONNECTION_TENANT_ID"\
159-
#--name "$SERVICECONNECTION_NAME" \
160-
#--project "One" --debug
161144
162145
163146
@@ -222,6 +205,14 @@ steps:
222205
set -e
223206
[[ -n $SYSTEM_DEBUG ]] && [[ $SYSTEM_DEBUG =~ $IS_TRUE ]] && set -x || set +x
224207
208+
echo "$ROLEASSIGNMENTS_LIST" | \
209+
jq -rc \
210+
--arg RA_NAME "$RA_NAME" \
211+
--arg RA_PRINCIPAL_ID "$RA_PRINCIPAL_ID" \
212+
--arg RA_SCOPE "$RA_SCOPE" \
213+
'. | select(.roleDefinitionName == $RA_NAME && .principalId == $RA_PRINCIPAL_ID && .scope == $RA_SCOPE)'
214+
215+
225216
${{ elseif eq(parameters.resourceType, 'storageaccounts') }}:
226217
inlineScript: |
227218
set -e
@@ -240,7 +231,8 @@ steps:
240231
CONDITION="(@Resource[Microsoft.Storage/storageAccounts/blobServices/containers:Name] stringEquals '$STORAGECONTAINER_NAME' AND (!(ActionMatches{'Microsoft.Storage/storageAccounts/blobServices/containers/blobs/read'} AND NOT SubOperationMatches{'Blob.List'}) OR @Resource[Microsoft.Storage/storageAccounts/blobServices/containers/blobs/tags:'$BUILDTAG_BUILDUSER_APPID'<\$key_case_sensitive\$>] StringEquals '$MANAGEDIDENTITY_APPID'))"
241232
az role assignment update \
242233
--role "$ROLE_NAME" \
243-
--assignee "$MANAGEDIDENTITY_NAME" \
234+
--assignee-object-id "$SERVICEPRINCIPAL_CLIENTID" \
235+
--assignee-principl-type "ServicePrincipal" \
244236
--scope "$RESOURCEGROUP_ID" \
245237
--description "Enable access to build user blobs." \
246238
--condition "$CONDITION" \

.pipelines/templates/get-resources.steps.yaml

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -161,25 +161,20 @@ steps:
161161
echo >&2 "##vso[task.setvariable variable=${VAR_NAME}_LENGTH;]$R_LIST_LENGTH"
162162

163163

164-
${{ elseif eq(parameters.resourceType, 'managedidentity') }}:
164+
${{ elseif eq(parameters.resourceType, 'roleassignments') }}:
165165
inlineScript: |
166166
set -e
167167
[[ -n $SYSTEM_DEBUG ]] && [[ $SYSTEM_DEBUG =~ $IS_TRUE ]] && set -x || set +x
168168
169-
R_QUERY="[? tags.\""$BUILDTAG_DEFINITIONID"\" && tags.\""$BUILDTAG_CREATEDBYAPPID"\"]"
170-
MI_LIST=$(az identity list \
171-
--resource-group "$RESOURCEGROUP_NAME" \
172-
--query "$R_QUERY" -o json | \
173-
jq -rc \
174-
--arg BUILDTAG_CREATEDBYAPPID "$BUILDTAG_CREATEDBYAPPID" \
175-
--arg APPID "$servicePrincipalId" \
176-
--arg BUILDTAG_DEFINITIONID "$BUILDTAG_DEFINITIONID" \
177-
--arg DEFINITIONID "$SYSTEM_DEFINITIONID" \
178-
'[ .[] | select(.tags[$BUILDTAG_DEFINITIONID] == $DEFINITIONID ) | select( .tags[$BUILDTAG_CREATEDBYAPPID] == $APPID) ]')
179-
MI_LIST_LENGTH=$(echo "$MI_LIST" | jq length)
169+
RA_LIST=$(az role assignment list \
170+
--assignee "$ASSIGNEE_ID" \
171+
--include-groups \
172+
--include-inherited)
173+
174+
RA_LIST_LENGTH=$(echo "$RA_LIST" | jq length)
180175

181-
echo >&2 "##vso[task.setvariable variable=${VAR_NAME};]$MI_LIST"
182-
echo >&2 "##vso[task.setvariable variable=${VAR_NAME}_LENGTH;]$MI_LIST_LENGTH"
176+
echo >&2 "##vso[task.setvariable variable=${VAR_NAME};]$RA_LIST"
177+
echo >&2 "##vso[task.setvariable variable=${VAR_NAME}_LENGTH;]$RA_LIST_LENGTH"
183178

184179
${{ elseif eq(parameters.resourceType, 'serviceconnection') }}:
185180
inlineScript: |

0 commit comments

Comments
 (0)