Skip to content

Commit 1324aac

Browse files
authored
Limit permissions needed by the service principal to run actions (#44)
* use NGINX cli to do configuration updates This change enables the use of "az nginx deployment" cli to do configuration updates. This helps limit the permissions needed by the service principal to do config updates. * change deploy certificate to use az nginx cli move from using ARM deployment templates to `az nginx deployment certificate update`. This change prevents the need for contributor level permissions on the resource group of the NGINXaaS deployment. * update README to change the version to 0.4.1
1 parent e02950b commit 1324aac

File tree

6 files changed

+29
-161
lines changed

6 files changed

+29
-161
lines changed

github-action/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
creds: ${{ secrets.AZURE_CREDENTIALS }}
3535

3636
- name: 'Sync the NGINX configuration from the GitHub repository to the NGINXaaS for Azure deployment'
37-
uses: nginxinc/nginx-for-azure-deploy-action/[email protected].0
37+
uses: nginxinc/nginx-for-azure-deploy-action/[email protected].1
3838
with:
3939
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
4040
resource-group-name: ${{ secrets.AZURE_RESOURCE_GROUP_NAME }}
@@ -77,7 +77,7 @@ jobs:
7777
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
7878

7979
- name: 'Sync the NGINX configuration from the GitHub repository to the NGINXaaS for Azure deployment'
80-
uses: nginxinc/nginx-for-azure-deploy-action/[email protected].0
80+
uses: nginxinc/nginx-for-azure-deploy-action/[email protected].1
8181
with:
8282
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
8383
resource-group-name: ${{ secrets.AZURE_RESOURCE_GROUP_NAME }}
@@ -106,7 +106,7 @@ To use this action to sync the configuration files from this example, the direct
106106

107107
```yaml
108108
- name: 'Sync the NGINX configuration from the GitHub repository to the NGINXaaS for Azure deployment'
109-
uses: nginxinc/nginx-for-azure-deploy-action/[email protected].0
109+
uses: nginxinc/nginx-for-azure-deploy-action/[email protected].1
110110
with:
111111
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
112112
resource-group-name: ${{ secrets.AZURE_RESOURCE_GROUP_NAME }}
@@ -139,7 +139,7 @@ The action supports an optional input `transformed-nginx-config-directory-path`
139139

140140
```yaml
141141
- name: 'Sync the NGINX configuration from the Git repository to the NGINXaaS for Azure deployment'
142-
uses: nginxinc/nginx-for-azure-deploy-action/[email protected].0
142+
uses: nginxinc/nginx-for-azure-deploy-action/[email protected].1
143143
with:
144144
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
145145
resource-group-name: ${{ secrets.AZURE_RESOURCE_GROUP_NAME }}
@@ -172,7 +172,7 @@ See the example below
172172

173173
```yaml
174174
- name: "Sync NGINX certificates to NGINXaaS for Azure"
175-
uses: nginxinc/nginx-for-azure-deploy-action/[email protected].0
175+
uses: nginxinc/nginx-for-azure-deploy-action/[email protected].1
176176
with:
177177
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
178178
resource-group-name: ${{ secrets.AZURE_RESOURCE_GROUP_NAME }}
@@ -186,7 +186,7 @@ See the example below
186186

187187
```yaml
188188
- name: "Sync NGINX configuration- multi file and certificate to NGINXaaS for Azure"
189-
uses: nginxinc/nginx-for-azure-deploy-action/[email protected].0
189+
uses: nginxinc/nginx-for-azure-deploy-action/[email protected].1
190190
with:
191191
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
192192
resource-group-name: ${{ secrets.AZURE_RESOURCE_GROUP_NAME }}

github-action/action.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ inputs:
1010
nginx-deployment-name:
1111
description: "The name of the NGINXaaS for Azure deployment."
1212
required: true
13-
nginx-deployment-location:
14-
description: "The location where the NGINX deployment is located. Example westcentralus"
15-
required: false
16-
deprecationMessage: "This field is not in use and will be removed in a future release. Consider dropping it from your Github Action configuration."
1713
nginx-config-directory-path:
1814
description: 'The NGINX configuration directory path relative to the root of the Git repository, example: "config/".'
1915
required: false
@@ -40,8 +36,8 @@ runs:
4036
using: "composite"
4137
steps:
4238
- name: "Synchronize NGINX certificate(s) from the Git repository to an NGINXaaS for Azure deployment"
43-
run: ${{github.action_path}}/src/deploy-certificate.sh --subscription_id=${{ inputs.subscription-id }} --resource_group_name=${{ inputs.resource-group-name }} --nginx_deployment_name=${{ inputs.nginx-deployment-name }} --nginx_resource_location=${{ inputs.nginx-deployment-location }} --certificates=${{ toJSON(inputs.nginx-certificates) }} --debug=${{ inputs.debug }}
44-
if: ${{ inputs.nginx-deployment-location != '' && inputs.nginx-certificates != '' }}
39+
run: ${{github.action_path}}/src/deploy-certificate.sh --subscription_id=${{ inputs.subscription-id }} --resource_group_name=${{ inputs.resource-group-name }} --nginx_deployment_name=${{ inputs.nginx-deployment-name }} --certificates=${{ toJSON(inputs.nginx-certificates) }} --debug=${{ inputs.debug }}
40+
if: ${{ inputs.nginx-certificates != '' }}
4541
shell: bash
4642
- name: "Synchronize NGINX configuration from the Git repository to an NGINXaaS for Azure deployment"
4743
run: ${{github.action_path}}/src/deploy-config.sh --subscription_id=${{ inputs.subscription-id }} --resource_group_name=${{ inputs.resource-group-name }} --nginx_deployment_name=${{ inputs.nginx-deployment-name }} --config_dir_path=${{ inputs.nginx-config-directory-path }} --root_config_file=${{ inputs.nginx-root-config-file }} --transformed_config_dir_path=${{ inputs.transformed-nginx-config-directory-path }} --debug=${{ inputs.debug }}

github-action/src/deploy-certificate.sh

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ case $i in
1717
nginx_deployment_name="${i#*=}"
1818
shift
1919
;;
20-
--nginx_resource_location=*)
21-
nginx_resource_location="${i#*=}"
22-
shift
23-
;;
2420
--certificates=*)
2521
certificates="${i#*=}"
2622
shift
@@ -51,26 +47,12 @@ then
5147
echo "Please set 'nginx-deployment-name' ..."
5248
exit 1
5349
fi
54-
if [[ ! -v nginx_resource_location ]];
55-
then
56-
echo "Please set 'nginx-resource-location' ..."
57-
exit 1
58-
fi
5950
if [[ ! -v certificates ]];
6051
then
6152
echo "Please set 'nginx-certificates' ..."
6253
exit 1
6354
fi
6455

65-
arm_template_file="nginx-for-azure-certificate-template.json"
66-
67-
#get the ARM template file
68-
wget -O "$arm_template_file" https://raw.githubusercontent.com/nginxinc/nginx-for-azure-deploy-action/a69d33feaa1a8a012ec44c138ca78c6ec4db9f29/src/nginx-for-azure-certificate-template.json
69-
echo "Downloaded the ARM template for synchronizing NGINX certificate."
70-
71-
cat "$arm_template_file"
72-
echo ""
73-
7456
az account set -s "$subscription_id" --verbose
7557

7658
count=$(echo "$certificates" | jq '. | length')
@@ -104,41 +86,33 @@ do
10486
do_nginx_arm_deployment=0
10587
fi
10688

107-
uuid="$(cat /proc/sys/kernel/random/uuid)"
108-
template_file="template-$uuid.json"
109-
template_deployment_name="${nginx_deployment_name:0:20}-$uuid"
110-
111-
cp "$arm_template_file" "$template_file"
112-
11389
echo "Synchronizing NGINX certificate"
11490
echo "Subscription ID: $subscription_id"
11591
echo "Resource group name: $resource_group_name"
11692
echo "NGINXaaS for Azure deployment name: $nginx_deployment_name"
117-
echo "NGINXaaS for Azure Location: $nginx_resource_location"
118-
echo "ARM template deployment name: $template_deployment_name"
11993
echo ""
12094
echo "NGINXaaS for Azure cert name: $nginx_cert_name"
12195
echo "NGINXaaS for Azure cert file location: $nginx_cert_file"
12296
echo "NGINXaaS for Azure key file location: $nginx_key_file"
12397
echo ""
12498

99+
echo "Installing the az nginx extension if not already installed."
100+
az extension add --name nginx --allow-preview true
101+
125102
if [ $do_nginx_arm_deployment -eq 1 ]
126103
then
127104
az_cmd=(
128105
"az"
106+
"nginx"
129107
"deployment"
130-
"group"
108+
"certificate"
131109
"create"
132-
"--name" "$template_deployment_name"
133110
"--resource-group" "$resource_group_name"
134-
"--template-file" "$template_file"
135-
"--parameters"
136-
"name=$nginx_cert_name"
137-
"location=$nginx_resource_location"
138-
"nginxDeploymentName=$nginx_deployment_name"
139-
"certificateVirtualPath=$nginx_cert_file"
140-
"keyVirtualPath=$nginx_key_file"
141-
"keyVaultSecretID=$keyvault_secret"
111+
"--certificate-name" "$nginx_cert_name"
112+
"--deployment-name" "$nginx_deployment_name"
113+
"--certificate-path" "$nginx_cert_file"
114+
"--key-path" "$nginx_key_file"
115+
"--key-vault-secret-id" "$keyvault_secret"
142116
"--verbose"
143117
)
144118
if [[ "$debug" == true ]]; then

github-action/src/deploy-config.sh

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ echo "Successfully created the tarball from the NGINX configuration directory."
132132
echo "Listing the NGINX configuration file paths in the tarball."
133133
tar -tf "$config_tarball"
134134

135-
encoded_config_tarball=$(base64 "$config_tarball")
135+
encoded_config_tarball=$(base64 "$config_tarball" -w 0)
136136

137137
if [[ "$debug" == true ]]; then
138138
echo "The base64 encoded NGINX configuration tarball"
@@ -142,36 +142,28 @@ echo ""
142142

143143
# Synchronize the NGINX configuration tarball to the NGINXaaS for Azure deployment.
144144

145-
uuid="$(cat /proc/sys/kernel/random/uuid)"
146-
template_file="template-$uuid.json"
147-
template_deployment_name="${nginx_deployment_name:0:20}-$uuid"
148-
149-
wget -O "$template_file" https://raw.githubusercontent.com/nginxinc/nginx-for-azure-deploy-action/487d1394d6115d4f42ece6200cbd20859595557d/src/nginx-for-azure-configuration-template.json
150-
echo "Downloaded the ARM template for synchronizing NGINX configuration."
151-
cat "$template_file"
152-
echo ""
153-
154145
echo "Synchronizing NGINX configuration"
155146
echo "Subscription ID: $subscription_id"
156147
echo "Resource group name: $resource_group_name"
157148
echo "NGINXaaS for Azure deployment name: $nginx_deployment_name"
158-
echo "ARM template deployment name: $template_deployment_name"
159149
echo ""
160150

161151
az account set -s "$subscription_id" --verbose
162152

153+
echo "Installing the az nginx extension if not already installed."
154+
az extension add --name nginx --allow-preview true
155+
163156
az_cmd=(
164157
"az"
158+
"nginx"
165159
"deployment"
166-
"group"
167-
"create"
168-
"--name" "$template_deployment_name"
160+
"configuration"
161+
"update"
162+
"--name" "default"
163+
"--deployment-name" "$nginx_deployment_name"
169164
"--resource-group" "$resource_group_name"
170-
"--template-file" "$template_file"
171-
"--parameters"
172-
"nginxDeploymentName=$nginx_deployment_name"
173-
"rootFile=$transformed_root_config_file_path"
174-
"tarball=$encoded_config_tarball"
165+
"--root-file" "$transformed_root_config_file_path"
166+
"--package" "data=$encoded_config_tarball"
175167
"--verbose"
176168
)
177169

github-action/src/nginx-for-azure-certificate-template.json

Lines changed: 0 additions & 55 deletions
This file was deleted.

github-action/src/nginx-for-azure-configuration-template.json

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)