Skip to content

Commit da061f8

Browse files
authored
Refactor Nexus bundle to use KeyVault VM Extension (#3453)
* update firewall * use keyvault vm extension to get nexus ssl * changelog * version
1 parent 617d5bf commit da061f8

13 files changed

Lines changed: 118 additions & 99 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ ENHANCEMENTS:
1010

1111
BUG FIXES:
1212
* AML workspace service fails to install and puts firewall into failed state ([#3448](https://github.com/microsoft/AzureTRE/issues/3448))
13+
* Nexus fails to install due to `az login` and firewall rules ([#3453](https://github.com/microsoft/AzureTRE/issues/3453))
1314

1415
COMPONENTS:
1516

templates/shared_services/firewall/porter.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
schemaVersion: 1.0.0
33
name: tre-shared-service-firewall
4-
version: 1.1.0
4+
version: 1.1.1
55
description: "An Azure TRE Firewall shared service"
66
dockerfile: Dockerfile.tmpl
77
registry: azuretre
@@ -57,7 +57,7 @@ parameters:
5757

5858
mixins:
5959
- terraform:
60-
clientVersion: 1.3.6
60+
clientVersion: 1.4.5
6161

6262
install:
6363
- terraform:

templates/shared_services/firewall/template_schema.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"type": "object",
1818
"required": [
1919
"name",
20-
"action",
2120
"rules"
2221
],
2322
"properties": {

templates/shared_services/firewall/terraform/.terraform.lock.hcl

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/shared_services/firewall/terraform/providers.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ terraform {
33
required_providers {
44
azurerm = {
55
source = "hashicorp/azurerm"
6-
version = "=3.40.0"
6+
version = "=3.53.0"
77
}
88
}
99

templates/shared_services/sonatype-nexus-vm/porter.yaml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
schemaVersion: 1.0.0
33
name: tre-shared-service-sonatype-nexus
4-
version: 2.4.0
4+
version: 2.5.0
55
description: "A Sonatype Nexus shared service"
66
dockerfile: Dockerfile.tmpl
77
registry: azuretre
@@ -58,17 +58,15 @@ outputs:
5858
applyTo:
5959
- install
6060
- upgrade
61-
- name: shared_address_prefixes
61+
- name: private_ip_addresses
6262
applyTo:
6363
- install
6464
- upgrade
6565

6666
mixins:
6767
- exec
6868
- terraform:
69-
clientVersion: 1.3.6
70-
- az:
71-
clientVersion: 2.37.0
69+
clientVersion: 1.4.5
7270

7371
install:
7472
- terraform:
@@ -85,7 +83,7 @@ install:
8583
outputs:
8684
- name: workspace_vm_allowed_fqdns_list
8785
- name: nexus_allowed_fqdns_list
88-
- name: shared_address_prefixes
86+
- name: private_ip_addresses
8987

9088
upgrade:
9189
- terraform:
@@ -102,7 +100,7 @@ upgrade:
102100
outputs:
103101
- name: workspace_vm_allowed_fqdns_list
104102
- name: nexus_allowed_fqdns_list
105-
- name: shared_address_prefixes
103+
- name: private_ip_addresses
106104
uninstall:
107105
- terraform:
108106
description: "Tear down shared service"

templates/shared_services/sonatype-nexus-vm/scripts/configure_nexus_ssl.sh

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,41 @@ set -o pipefail
77
set -o nounset
88
# set -o xtrace
99

10-
# Prepare ssl certificate
11-
az login --identity -u "${MSI_ID}" --allow-no-subscriptions
12-
# -- get cert from kv as secret so it contains private key
13-
echo 'Getting cert and cert password from Keyvault...'
14-
az keyvault secret download --vault-name "${VAULT_NAME}" --name "${SSL_CERT_NAME}" --file temp.pfx --encoding base64
15-
cert_password=$(az keyvault secret show --vault-name "${VAULT_NAME}" \
16-
--name "${SSL_CERT_PASSWORD_NAME}" -o tsv --query value)
17-
# -- az cli strips out password from cert so we re-add by converting to PEM then PFX with pwd
18-
openssl pkcs12 -in temp.pfx -out temp.pem -nodes -password pass:
19-
openssl pkcs12 -export -out nexus-ssl.pfx -in temp.pem -password "pass:$cert_password"
10+
echo "Setting up Nexus SSL..."
2011

2112
# Import ssl cert to keystore within Nexus volume
22-
keystore_timeout=300
13+
keystore_timeout=60
2314
echo 'Checking for nexus-data/keystores directory...'
2415
while [ ! -d /etc/nexus-data/keystores ]; do
2516
# Wait for /keystore dir to be created by container first
2617
if [ $keystore_timeout == 0 ]; then
2718
echo 'ERROR - Timeout while waiting for Nexus to create nexus-data/keystores'
2819
exit 1
2920
fi
30-
sleep 1
21+
sleep 5
3122
((keystore_timeout--))
3223
done
33-
echo 'Directory found. Importing ssl cert into nexus-data/keystores/keystore.jks...'
34-
keytool -v -importkeystore -noprompt -srckeystore nexus-ssl.pfx -srcstoretype PKCS12 \
35-
-destkeystore /etc/nexus-data/keystores/keystore.jks \
36-
-deststoretype JKS -srcstorepass "$cert_password" -deststorepass "$cert_password"
24+
25+
downloaded_cert_path="/var/lib/waagent/Microsoft.Azure.KeyVault.Store/${VAULT_NAME}.${SSL_CERT_NAME}"
26+
cert_timeout=60
27+
echo 'Waiting for cert to be downloaded from KV...'
28+
while [ ! -f "$downloaded_cert_path" ]; do
29+
if [ $cert_timeout == 0 ]; then
30+
echo 'ERROR - Timeout while waiting!'
31+
exit 1
32+
fi
33+
sleep 5
34+
((cert_timeout--))
35+
done
36+
37+
keystore_file_name=ssl.keystore
38+
cert_password=$(openssl rand -base64 32)
39+
rm -f temp.p12
40+
openssl pkcs12 -export -inkey "$downloaded_cert_path" -in "$downloaded_cert_path" -out temp.p12 -password "pass:$cert_password"
41+
rm -f /etc/nexus-data/keystores/"$keystore_file_name"
42+
keytool -v -importkeystore -noprompt -srckeystore temp.p12 -srcstoretype PKCS12 -srcstorepass "$cert_password" \
43+
-destkeystore /etc/nexus-data/keystores/"$keystore_file_name" -deststoretype PKCS12 -deststorepass "$cert_password"
44+
rm -f temp.p12
3745

3846
# Configure Jetty instance within Nexus to consume ssl cert
3947
echo 'Modifying Nexus Jetty configuration to enable ssl...'
@@ -53,10 +61,10 @@ xmlstarlet ed -P --inplace \
5361
# -- then update the location of our keystore
5462
xmlstarlet ed -P --inplace \
5563
-u "/Configure[@id='Server']/New[@id='sslContextFactory']/Set[@name='KeyStorePath']" \
56-
-v /nexus-data/keystores/keystore.jks /etc/nexus-data/etc/jetty/jetty-https.xml
64+
-v /nexus-data/keystores/"$keystore_file_name" /etc/nexus-data/etc/jetty/jetty-https.xml
5765
xmlstarlet ed -P --inplace \
5866
-u "/Configure[@id='Server']/New[@id='sslContextFactory']/Set[@name='TrustStorePath']" \
59-
-v /nexus-data/keystores/keystore.jks /etc/nexus-data/etc/jetty/jetty-https.xml
67+
-v /nexus-data/keystores/"$keystore_file_name" /etc/nexus-data/etc/jetty/jetty-https.xml
6068

6169
# Add jetty configuration and ssl port to Nexus properties
6270
cat >> /etc/nexus-data/etc/nexus.properties <<'EOF'

templates/shared_services/sonatype-nexus-vm/template_schema.json

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@
3333
"arraySubstitutionAction": "replace",
3434
"arrayMatchField": "name",
3535
"value": {
36-
"name": "shared_subnet_sonatype_nexus",
37-
"action": "Allow",
36+
"name": "arc_nexus",
3837
"rules": [
3938
{
4039
"name": "vm-crl",
@@ -50,7 +49,9 @@
5049
}
5150
],
5251
"target_fqdns": "{{ resource.properties.workspace_vm_allowed_fqdns_list }}",
53-
"source_addresses": ["*"]
52+
"source_addresses": [
53+
"*"
54+
]
5455
},
5556
{
5657
"name": "nexus-package-sources",
@@ -66,7 +67,7 @@
6667
}
6768
],
6869
"target_fqdns": "{{ resource.properties.nexus_allowed_fqdns_list }}",
69-
"source_addresses": "{{ resource.properties.shared_address_prefixes }}"
70+
"source_addresses": "{{ resource.properties.private_ip_addresses }}"
7071
}
7172
]
7273
}
@@ -91,7 +92,7 @@
9192
"arraySubstitutionAction": "replace",
9293
"arrayMatchField": "name",
9394
"value": {
94-
"name": "shared_subnet_sonatype_nexus",
95+
"name": "arc_nexus",
9596
"action": "Allow",
9697
"rules": [
9798
{
@@ -108,7 +109,9 @@
108109
}
109110
],
110111
"target_fqdns": "{{ resource.properties.workspace_vm_allowed_fqdns_list }}",
111-
"source_addresses": ["*"]
112+
"source_addresses": [
113+
"*"
114+
]
112115
},
113116
{
114117
"name": "nexus-package-sources",
@@ -124,7 +127,7 @@
124127
}
125128
],
126129
"target_fqdns": "{{ resource.properties.nexus_allowed_fqdns_list }}",
127-
"source_addresses": "{{ resource.properties.shared_address_prefixes }}"
130+
"source_addresses": "{{ resource.properties.private_ip_addresses }}"
128131
}
129132
]
130133
}
@@ -146,7 +149,7 @@
146149
"arraySubstitutionAction": "remove",
147150
"arrayMatchField": "name",
148151
"value": {
149-
"name": "shared_subnet_sonatype_nexus"
152+
"name": "arc_nexus"
150153
}
151154
}
152155
]

templates/shared_services/sonatype-nexus-vm/terraform/.terraform.lock.hcl

Lines changed: 30 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/shared_services/sonatype-nexus-vm/terraform/data.tf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ data "azurerm_key_vault_certificate" "nexus_cert" {
1919
key_vault_id = data.azurerm_key_vault.kv.id
2020
}
2121

22-
data "azurerm_key_vault_secret" "nexus_cert_password" {
23-
name = "${data.azurerm_key_vault_certificate.nexus_cert.name}-password"
24-
key_vault_id = data.azurerm_key_vault.kv.id
25-
}
26-
2722
data "azurerm_storage_account" "nexus" {
2823
name = local.storage_account_name
2924
resource_group_name = local.core_resource_group_name

0 commit comments

Comments
 (0)