@@ -93,22 +93,27 @@ function checkAZWIENVPreReqsAndCreateFiles() {
93
93
echo " AZWI_RESOURCE_GROUP environment variable required - Azure resource group to store required Workload Identity artifacts"
94
94
exit 1
95
95
fi
96
+
96
97
if [ " $( az group exists --name " ${AZWI_RESOURCE_GROUP} " --output tsv) " == ' false' ]; then
97
98
echo " Creating resource group '${AZWI_RESOURCE_GROUP} ' in '${AZWI_LOCATION} '"
98
99
az group create --name " ${AZWI_RESOURCE_GROUP} " --location " ${AZWI_LOCATION} " --output none --only-show-errors --tags creationTimestamp=" ${TIMESTAMP} " jobName=" ${JOB_NAME} " buildProvenance=" ${BUILD_PROVENANCE} "
99
100
fi
101
+
100
102
# Ensure that our connection to storage is inherited from the existing Azure login context
101
103
unset AZURE_STORAGE_KEY
102
104
unset AZURE_STORAGE_ACCOUNT
105
+
103
106
if ! az storage account show --name " ${AZWI_STORAGE_ACCOUNT} " --resource-group " ${AZWI_RESOURCE_GROUP} " > /dev/null 2>&1 ; then
104
107
echo " Creating storage account '${AZWI_STORAGE_ACCOUNT} ' in '${AZWI_RESOURCE_GROUP} '"
105
108
az storage account create --resource-group " ${AZWI_RESOURCE_GROUP} " --name " ${AZWI_STORAGE_ACCOUNT} " --output none --only-show-errors --tags creationTimestamp=" ${TIMESTAMP} " jobName=" ${JOB_NAME} " buildProvenance=" ${BUILD_PROVENANCE} "
106
- az storage blob service-properties update --account-name " ${AZWI_STORAGE_ACCOUNT} " --static-website
109
+ az storage blob service-properties ${ENABLE_AUTH_MODE_LOGIN : + " --auth-mode login " } update --account-name " ${AZWI_STORAGE_ACCOUNT} " --static-website
107
110
fi
111
+
108
112
if ! az storage container show --name " ${AZWI_STORAGE_CONTAINER} " --account-name " ${AZWI_STORAGE_ACCOUNT} " > /dev/null 2>&1 ; then
109
113
echo " Creating storage container '${AZWI_STORAGE_CONTAINER} ' in '${AZWI_STORAGE_ACCOUNT} '"
110
- az storage container create --name " ${AZWI_STORAGE_CONTAINER} " --account-name " ${AZWI_STORAGE_ACCOUNT} " --output none --only-show-errors
114
+ az storage container ${ENABLE_AUTH_MODE_LOGIN : + " --auth-mode login " } create --name " ${AZWI_STORAGE_CONTAINER} " --account-name " ${AZWI_STORAGE_ACCOUNT} " --output none --only-show-errors
111
115
fi
116
+
112
117
SERVICE_ACCOUNT_ISSUER=$( az storage account show --name " ${AZWI_STORAGE_ACCOUNT} " -o json | jq -r .primaryEndpoints.web)
113
118
export SERVICE_ACCOUNT_ISSUER
114
119
AZWI_OPENID_CONFIG_FILEPATH=" ${REPO_ROOT} /openid-configuration.json"
@@ -131,30 +136,37 @@ EOF
131
136
openssl rsa -in " ${SERVICE_ACCOUNT_SIGNING_KEY_FILEPATH} " -pubout -out " ${SERVICE_ACCOUNT_SIGNING_PUB_FILEPATH} "
132
137
AZWI_JWKS_JSON_FILEPATH=" ${REPO_ROOT} /jwks.json"
133
138
" ${AZWI} " jwks --public-keys " ${SERVICE_ACCOUNT_SIGNING_PUB_FILEPATH} " --output-file " ${AZWI_JWKS_JSON_FILEPATH} "
139
+
134
140
echo " Uploading openid-configuration document to '${AZWI_STORAGE_ACCOUNT} ' storage account"
135
141
upload_to_blob " ${AZWI_OPENID_CONFIG_FILEPATH} " " .well-known/openid-configuration"
142
+
136
143
echo " Uploading jwks document to '${AZWI_STORAGE_ACCOUNT} ' storage account"
137
144
upload_to_blob " ${AZWI_JWKS_JSON_FILEPATH} " " openid/v1/jwks"
138
- echo " Removing key access on storage account as no further data writes are required"
139
- az storage account update -n " ${AZWI_STORAGE_ACCOUNT} " -g " ${AZWI_RESOURCE_GROUP} " --subscription " ${AZURE_SUBSCRIPTION_ID} " --allow-shared-key-access=false --output none --only-show-errors
140
145
fi
146
+
141
147
if [ -z " ${AZURE_CLIENT_ID_USER_ASSIGNED_IDENTITY} " ]; then
142
148
if [ -z " ${USER_IDENTITY} " ]; then
143
149
echo " USER_IDENTITY environment variable required if not bringing your own identity via AZURE_CLIENT_ID_USER_ASSIGNED_IDENTITY"
144
150
exit 1
145
151
fi
152
+
146
153
az identity create -n " ${USER_IDENTITY} " -g " ${AZWI_RESOURCE_GROUP} " -l " ${AZWI_LOCATION} " --output none --only-show-errors --tags creationTimestamp=" ${TIMESTAMP} " jobName=" ${JOB_NAME} " buildProvenance=" ${BUILD_PROVENANCE} "
147
154
AZURE_IDENTITY_ID=$( az identity show -n " ${USER_IDENTITY} " -g " ${AZWI_RESOURCE_GROUP} " --query clientId -o tsv)
148
155
AZURE_IDENTITY_ID_PRINCIPAL_ID=$( az identity show -n " ${USER_IDENTITY} " -g " ${AZWI_RESOURCE_GROUP} " --query principalId -o tsv)
156
+
149
157
echo " ${AZURE_IDENTITY_ID} " > " ${AZURE_IDENTITY_ID_FILEPATH} "
150
158
until az role assignment create --assignee-object-id " ${AZURE_IDENTITY_ID_PRINCIPAL_ID} " --role " Owner" --scope " /subscriptions/${AZURE_SUBSCRIPTION_ID} " --assignee-principal-type ServicePrincipal --output none --only-show-errors; do
151
159
sleep 5
152
160
done
161
+
162
+ echo " Creating federated credentials for capz-federated-identity"
153
163
az identity federated-credential create -n " capz-federated-identity" \
154
164
--identity-name " ${USER_IDENTITY} " \
155
165
-g " ${AZWI_RESOURCE_GROUP} " \
156
166
--issuer " ${SERVICE_ACCOUNT_ISSUER} " \
157
167
--subject " system:serviceaccount:capz-system:capz-manager" --output none --only-show-errors
168
+
169
+ echo " Creating federated credentials for aso-federated-identity"
158
170
az identity federated-credential create -n " aso-federated-identity" \
159
171
--identity-name " ${USER_IDENTITY} " \
160
172
-g " ${AZWI_RESOURCE_GROUP} " \
@@ -168,7 +180,7 @@ function upload_to_blob() {
168
180
local blob_name=$2
169
181
170
182
echo " Uploading ${file_path} to '${AZWI_STORAGE_ACCOUNT} ' storage account"
171
- az storage blob upload \
183
+ az storage blob upload ${ENABLE_AUTH_MODE_LOGIN : + " --auth-mode login " } \
172
184
--container-name " ${AZWI_STORAGE_CONTAINER} " \
173
185
--file " ${file_path} " \
174
186
--name " ${blob_name} " \
0 commit comments