Skip to content

Commit 9beb59b

Browse files
authored
Remove storage account keys from deployment (#224)
* Remove storage account keys from table access * pcfuncs don't use keys * Deploy and tests * Contrib * Remove temp * Remove verbosity * Move settings validation to startup check
1 parent 3b1e9f7 commit 9beb59b

File tree

25 files changed

+221
-143
lines changed

25 files changed

+221
-143
lines changed

deployment/README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,27 @@ Container Registry repo where you published your local images:
4040
- `ACR_TILER_REPO`
4141
- `IMAGE_TAG`
4242

43-
__Note:__ Remember to bring down your resources after testing with `terraform destroy`!
43+
**Note:** Remember to bring down your resources after testing with `terraform destroy`!
4444

4545
## Loading configuration data
4646

4747
Configuration data is stored in Azure Storage Tables. Use the `pcapis` command line interface that is installed with the `pccommon` package to load data. For example:
4848

49+
```console
50+
> az login # Use an account that has "Storage Table Data Contributor" on the account
51+
> pcapis load -t collection --account pctapissatyasa --table collectionconfig --file pccommon/tests/data-files/collection_config.json
4952
```
50-
> pcapis load -t collection --sas "${SAS_TOKEN}" --account pctapissatyasa --table collectionconfig --file pccommon/tests/data-files/collection_config.json
51-
```
53+
5254
To dump a single collection config, use:
5355

54-
```
55-
> pcapis dump -t collection --sas "${SAS_TOKEN}" --account pctapissatyasa --table collectionconfig --id naip
56+
```console
57+
> pcapis dump -t collection --account pctapissatyasa --table collectionconfig --id naip
5658
```
5759

5860
For container configs, you must also specify the container account name used as the Partition Key:
5961

60-
```
61-
> pcapis dump -t collection --sas "${SAS_TOKEN}" --account pctapissatyasa --table containerconfig --id naip --container-account naipeuwest
62+
```console
63+
> pcapis dump -t collection --account pctapissatyasa --table containerconfig --id naip --container-account naipeuwest
6264
```
6365

6466
Using the `load` command on a single dump file for either config will update the single row.

deployment/bin/deploy

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,30 @@ while [[ "$#" -gt 0 ]]; do case $1 in
4949
;;
5050
esac done
5151

52+
disable_shared_access_keys() {
53+
echo "Disabling shared access key on storage account..."
54+
az storage account update \
55+
--name ${SAK_STORAGE_ACCOUNT} \
56+
--resource-group ${SAK_RESOURCE_GROUP} \
57+
--allow-shared-key-access false \
58+
--output none
59+
60+
if [ $? -ne 0 ]; then
61+
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
62+
echo "WARNING: Failed to turn off shared key access on the storage account."
63+
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
64+
exit 2
65+
fi
66+
}
67+
68+
# Always disable shared access keys on script exit
69+
trap disable_shared_access_keys EXIT
70+
5271
###################################
5372
# Check and configure environment #
5473
###################################
74+
SAK_STORAGE_ACCOUNT=pctapisstagingsa
75+
SAK_RESOURCE_GROUP=pct-apis-westeurope-staging_rg
5576

5677
if [[ -z ${TERRAFORM_DIR} ]]; then
5778
echo "Must pass in TERRAFORM_DIR with -t"
@@ -91,6 +112,18 @@ if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
91112

92113
if [[ "${SKIP_TF}" != 1 ]]; then
93114
echo "Deploying infrastructure with Terraform..."
115+
116+
echo "Enabling shared key access for storage account..."
117+
# Terraform isn't able to read all resources from a storage account if shared key access is disabled
118+
# so while we're deploying, we need to enable it. Since we haven't run TF yet, we don't have the name of the account
119+
# so they are hardcoded here. This is a temporary workaround until this is resolved
120+
# https://github.com/hashicorp/terraform-provider-azurerm/issues/25218
121+
az storage account update \
122+
--name ${SAK_STORAGE_ACCOUNT} \
123+
--resource-group ${SAK_RESOURCE_GROUP} \
124+
--allow-shared-key-access true \
125+
--output none
126+
94127
terraform init --upgrade
95128

96129
if [ "${PLAN_ONLY}" ]; then
@@ -142,7 +175,8 @@ if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
142175
--kube-context "${KUBE_CONTEXT}" \
143176
--wait \
144177
--timeout 2m0s \
145-
-f ${DEPLOY_VALUES_FILE}
178+
-f ${DEPLOY_VALUES_FILE} \
179+
--debug
146180

147181
echo "================"
148182
echo "==== Tiler ====="
@@ -154,7 +188,8 @@ if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
154188
--kube-context "${KUBE_CONTEXT}" \
155189
--wait \
156190
--timeout 2m0s \
157-
-f ${DEPLOY_VALUES_FILE}
191+
-f ${DEPLOY_VALUES_FILE} \
192+
--debug
158193

159194
echo "=================="
160195
echo "==== Ingress ====="

deployment/bin/kv_add_ip

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
3232
-g ${KEY_VAULT_RESOURCE_GROUP_NAME} \
3333
-n ${KEY_VAULT_NAME} \
3434
--ip-address $cidr \
35-
--subscription ${ARM_SUBSCRIPTION_ID}
35+
--subscription ${ARM_SUBSCRIPTION_ID} \
36+
--output none
3637

3738
fi

deployment/bin/kv_rmv_ip

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
3232
-g ${KEY_VAULT_RESOURCE_GROUP_NAME} \
3333
-n ${KEY_VAULT_NAME} \
3434
--ip-address $cidr \
35-
--subscription ${ARM_SUBSCRIPTION_ID}
35+
--subscription ${ARM_SUBSCRIPTION_ID} \
36+
--output none
3637

3738
fi

deployment/helm/deploy-values.template.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ stac:
4242
replicaCount: "{{ tf.stac_replica_count }}"
4343
podAnnotations:
4444
"pc/gitsha": "{{ env.GIT_COMMIT }}"
45+
useWorkloadIdentity: true
46+
serviceAccount:
47+
annotations:
48+
"azure.workload.identity/client-id": {{ tf.cluster_stac_identity_client_id }}
49+
"azure.workload.identity/tenant-id": {{ tf.tenant_id }}
4550

4651
appRootPath: "/stac"
4752
port: "80"
@@ -86,7 +91,6 @@ tiler:
8691

8792
storage:
8893
account_name: "{{ tf.storage_account_name }}"
89-
account_key: "{{ tf.storage_account_key }}"
9094
collection_config_table_name: "{{ tf.collection_config_table_name }}"
9195
container_config_table_name: "{{ tf.container_config_table_name }}"
9296
ip_exception_config_table_name: "{{ tf.ip_exception_config_table_name }}"

deployment/helm/published/planetary-computer-stac/templates/_helpers.tpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ app.kubernetes.io/instance: {{ .Release.Name }}
4242
Common labels
4343
*/}}
4444
{{- define "pcstac.labels" -}}
45+
azure.workload.identity/use: {{ .Values.stac.deploy.useWorkloadIdentity | quote}}
4546
helm.sh/chart: {{ include "pcstac.chart" . }}
4647
{{ include "pcstac.selectorLabels" . }}
4748
{{- if .Chart.AppVersion }}

deployment/helm/published/planetary-computer-stac/templates/deployment.yaml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ spec:
1919
{{- toYaml . | nindent 8 }}
2020
{{- end }}
2121
labels:
22-
{{- include "pcstac.selectorLabels" . | nindent 8 }}
22+
{{- include "pcstac.labels" . | nindent 8 }}
2323
spec:
2424
{{- with .Values.stac.deploy.imagePullSecrets }}
2525
imagePullSecrets:
@@ -89,20 +89,14 @@ spec:
8989
value: "{{ .Values.stac.debug }}"
9090
- name: "PCAPIS_COLLECTION_CONFIG__ACCOUNT_NAME"
9191
value: "{{ .Values.storage.account_name }}"
92-
- name: "PCAPIS_COLLECTION_CONFIG__ACCOUNT_KEY"
93-
value: "{{ .Values.storage.account_key }}"
9492
- name: "PCAPIS_COLLECTION_CONFIG__TABLE_NAME"
9593
value: "{{ .Values.storage.collection_config_table_name }}"
9694
- name: "PCAPIS_CONTAINER_CONFIG__ACCOUNT_NAME"
9795
value: "{{ .Values.storage.account_name }}"
98-
- name: "PCAPIS_CONTAINER_CONFIG__ACCOUNT_KEY"
99-
value: "{{ .Values.storage.account_key }}"
10096
- name: "PCAPIS_CONTAINER_CONFIG__TABLE_NAME"
10197
value: "{{ .Values.storage.container_config_table_name }}"
10298
- name: "PCAPIS_IP_EXCEPTION_CONFIG__ACCOUNT_NAME"
10399
value: "{{ .Values.storage.account_name }}"
104-
- name: "PCAPIS_IP_EXCEPTION_CONFIG__ACCOUNT_KEY"
105-
value: "{{ .Values.storage.account_key }}"
106100
- name: "PCAPIS_IP_EXCEPTION_CONFIG__TABLE_NAME"
107101
value: "{{ .Values.storage.ip_exception_config_table_name }}"
108102
- name: "PCAPIS_REDIS_HOSTNAME"

deployment/helm/published/planetary-computer-stac/templates/serviceaccount.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ metadata:
66
name: {{ include "pcstac.serviceAccountName" . }}
77
labels:
88
{{- include "pcstac.labels" . | nindent 4 }}
9-
{{- with .Values.serviceAccount.annotations }}
9+
{{- with .Values.stac.deploy.serviceAccount.annotations }}
1010
annotations:
1111
{{- toYaml . | nindent 4 }}
1212
{{- end }}

deployment/helm/published/planetary-computer-stac/values.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ stac:
5656
affinity: {}
5757
autoscaling:
5858
enabled: false
59+
useWorkloadIdentity: false
60+
serviceAccount:
61+
annotations: {}
62+
5963

6064
cert:
6165
privateKeySecretRef: "letsencrypt-staging"

deployment/helm/published/planetary-computer-tiler/templates/deployment.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,20 +85,14 @@ spec:
8585
value: "{{ .Values.tiler.default_max_items_per_tile}}"
8686
- name: "PCAPIS_COLLECTION_CONFIG__ACCOUNT_NAME"
8787
value: "{{ .Values.storage.account_name }}"
88-
- name: "PCAPIS_COLLECTION_CONFIG__ACCOUNT_KEY"
89-
value: "{{ .Values.storage.account_key }}"
9088
- name: "PCAPIS_COLLECTION_CONFIG__TABLE_NAME"
9189
value: "{{ .Values.storage.collection_config_table_name }}"
9290
- name: "PCAPIS_CONTAINER_CONFIG__ACCOUNT_NAME"
9391
value: "{{ .Values.storage.account_name }}"
94-
- name: "PCAPIS_CONTAINER_CONFIG__ACCOUNT_KEY"
95-
value: "{{ .Values.storage.account_key }}"
9692
- name: "PCAPIS_CONTAINER_CONFIG__TABLE_NAME"
9793
value: "{{ .Values.storage.container_config_table_name }}"
9894
- name: "PCAPIS_IP_EXCEPTION_CONFIG__ACCOUNT_NAME"
9995
value: "{{ .Values.storage.account_name }}"
100-
- name: "PCAPIS_IP_EXCEPTION_CONFIG__ACCOUNT_KEY"
101-
value: "{{ .Values.storage.account_key }}"
10296
- name: "PCAPIS_IP_EXCEPTION_CONFIG__TABLE_NAME"
10397
value: "{{ .Values.storage.ip_exception_config_table_name }}"
10498
- name: "PCAPIS_TABLE_VALUE_TTL"

0 commit comments

Comments
 (0)