Skip to content

Commit 0248bcf

Browse files
authored
Enable anonymous access in Nexus configuration script (#4387)
* Enable anonymous access in Nexus configuration script * Add role assignment for Storage Account Contributor in bootstrap script * Enhance role assignment check in bootstrap script to verify both "Storage Blob Data Contributor" and "Storage Account Contributor" roles are assigned * Refactor role assignment check to validate both "Storage Blob Data Contributor" and "Storage Account Contributor" roles * Remove unused script source from bootstrap.sh * Refactor role assignment check to use local variables for clarity * Update CHANGELOG and add role assignment for Storage Account Contributor in bootstrap.sh * Refactor role assignment check to use counts for validation and streamline script execution * Refactor role assignment check to use non-empty value validation and enhance storage container creation with retry logic * revert bootstrap * CR changes * Refactor role assignment check to verify access via storage container list * Implement retry logic for role assignment checks in bootstrap script * Refactor check_terraform_role_assignments function to simplify error handling and remove unnecessary output * Enhance error message in check_terraform_role_assignments function to indicate retry mechanism on unexpected output * Remove unnecessary echo statement from retry_with_backoff function in bootstrap script * Add validation for required environment variables in bootstrap script * Refactor bootstrap script to streamline Terraform initialization and backend configuration * Add shellcheck disable comments for unbound variable warnings in bootstrap script * Update terraform_wrapper invocation and add blank line for readability in bootstrap script * Bump version to 0.12.7 in version.txt * Refactor bootstrap script to move backend configuration inline and remove redundant function * Remove redundant function call for writing bootstrap Terraform backend * Update show_output.sh to use current directory and improve terraform_wrapper.sh usage documentation * Remove TODO comments from Terraform command output in bootstrap script * Bump version to 0.12.8 in version.txt * Bump version to 0.12.7 * Bump version to 0.12.7 in version.txt * Fix: simplify anonymous access configuration in Nexus repository script * Refactor bootstrap script to inline backend configuration and improve error handling * fix: update condition for Azure and ACR login to check for 'make bootstrap' * fix: resolve CI issue with Azure login steps for branches containing 'bootstrap' * refactor: move Terraform backend configuration to a dedicated section in bootstrap.sh * fix: update role assignment to use Storage Blob Data Contributor in bootstrap.sh * fix: refine role assignment query in bootstrap.sh to check only for Storage Blob Data Contributor * fix: update role check in bootstrap.sh to return status instead of echoing * fix: update comment for granting Storage Blob Data Contributor role in bootstrap.sh * fix: update comment for granting Storage Blob Data Contributor permissions in bootstrap.sh * fix: update Sonatype Nexus version and enhance repository configuration script with retry logic * fix: downgrade Sonatype Nexus version from 3.3.5 to 3.3.3 in porter.yaml * chore: update CHANGELOG.md to include enhancements and bug fixes for Nexus access and retry logic * fix: remove VS Code extensions proxy configuration from Nexus setup script * fix: update comment formatting in bootstrap.sh for clarity * refactor: rename functions for clarity in configure_nexus_repos.sh
1 parent c2925cd commit 0248bcf

File tree

3 files changed

+77
-42
lines changed

3 files changed

+77
-42
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44

55
ENHANCEMENTS:
66
* Deny public access to TRE management storage account, and add private endpoint for TRE core [#4353](https://github.com/microsoft/AzureTRE/issues/4353)
7+
* Added anonymous access enablement for Nexus by default issue. [#4387](https://github.com/microsoft/AzureTRE/pull/4387)
78

89
BUG FIXES:
910
* Fix the management storage access error while executing `make show-core-output` command, and remove redundant error messages from `mgmtstorage_enable_public_access.sh` script ([#4404](https://github.com/microsoft/AzureTRE/issues/4404))
1011
* Fix retry loop in devcontainer action and override commands.sh [#4409](https://github.com/microsoft/AzureTRE/pull/4409)
1112
* Fix terraform output command by adding working directory parameterPR ([#4413](https://github.com/microsoft/AzureTRE/pull/4413)) [#4412](https://github.com/microsoft/AzureTRE/issues/4412)
1213
* Fix CI issue where branch names containing 'bootstrap' would incorrectly skip Azure login steps [#4416](https://github.com/microsoft/AzureTRE/issues/4416) ([#4417](https://github.com/microsoft/AzureTRE/pull/4417))
1314
* Fix 403 storage account error when creating a new TRE environment ([#4405](https://github.com/microsoft/AzureTRE/issues/4405)) in PR [#4406](https://github.com/microsoft/AzureTRE/pull/4406)
15+
* Bug Fix: Approaching Nexus when it wasn’t fully available is now handled via a retry with exponential backoff [#4387](https://github.com/microsoft/AzureTRE/pull/4387)
1416

1517
## 0.21.0
1618

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

+1-1
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: 3.3.2
4+
version: 3.3.3
55
description: "A Sonatype Nexus shared service"
66
dockerfile: Dockerfile.tmpl
77
registry: azuretre

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

+74-41
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,97 @@ set -o pipefail
33
set -o nounset
44
# set -o xtrace
55

6-
if [ -z "$1" ]
7-
then
8-
echo 'Nexus password needs to be passed as argument'
6+
if [ -z "$1" ]; then
7+
echo 'Nexus password needs to be passed as argument'
8+
exit 1
99
fi
1010

11-
timeout=300
11+
retry_with_backoff() {
12+
local func="$1"
13+
shift
14+
local sleep_time=10
15+
local max_sleep=180
16+
17+
while [ "$sleep_time" -lt "$max_sleep" ]; do
18+
if "$func" "$@"; then
19+
return 0
20+
fi
21+
sleep "$sleep_time"
22+
sleep_time=$((sleep_time * 2))
23+
done
24+
return 1
25+
}
26+
27+
check_repos_config() {
28+
[ -d "$(dirname "${BASH_SOURCE[0]}")/nexus_repos_config" ]
29+
}
30+
1231
echo 'Checking for ./nexus_repos_config directory...'
13-
while [ ! -d "$(dirname "${BASH_SOURCE[0]}")"/nexus_repos_config ]; do
14-
# Wait for ./nexus_repos_config with json config files to be copied into vm
15-
if [ $timeout == 0 ]; then
16-
echo 'ERROR - Timeout while waiting for nexus_repos_config directory'
32+
if ! retry_with_backoff check_repos_config; then
33+
echo 'ERROR - Timeout while waiting for nexus_repos_config directory'
34+
exit 1
35+
fi
36+
37+
nexus_ready() {
38+
curl -s http://localhost/service/rest/v1/status -k > /dev/null
39+
}
40+
41+
echo 'Waiting for Nexus service to be fully available...'
42+
if ! retry_with_backoff nexus_ready; then
43+
echo 'ERROR - Timeout while waiting for Nexus to be available'
44+
exit 1
45+
fi
46+
47+
echo "Getting current anonymous settings in Nexus..."
48+
current_anon_json=$(curl -iu admin:"$1" -X GET \
49+
'http://localhost/service/rest/v1/security/anonymous' \
50+
-H 'accept: application/json' \
51+
-k -s)
52+
echo "Current anonymous settings: $current_anon_json"
53+
54+
echo "Enabling anonymous access in Nexus..."
55+
anon_status_code=$(curl -iu admin:"$1" -X PUT \
56+
'http://localhost/service/rest/v1/security/anonymous' \
57+
-H 'accept: application/json' \
58+
-H 'Content-Type: application/json' \
59+
-d '{"enabled": true}' \
60+
-k -s -w "%{http_code}" -o /dev/null)
61+
echo "Response received from Nexus for enabling anonymous access: $anon_status_code"
62+
if [ "$anon_status_code" -ne 200 ]; then
63+
echo "ERROR - Failed to enable anonymous access."
1764
exit 1
18-
fi
19-
sleep 1
20-
((timeout--))
21-
done
65+
fi
2266

67+
echo "Configuring Nexus repositories..."
2368
# Create proxy for each .json file
2469
for filename in "$(dirname "${BASH_SOURCE[0]}")"/nexus_repos_config/*.json; do
2570
echo "Found config file: $filename. Sending to Nexus..."
26-
# Check if apt proxy
2771
base_type=$( jq .baseType "$filename" | sed 's/"//g')
2872
repo_type=$( jq .repoType "$filename" | sed 's/"//g')
29-
repo_name=$(jq .name "$filename" | sed 's/"//g')
30-
base_url=http://localhost/service/rest/v1/repositories/$base_type/$repo_type
73+
repo_name=$( jq .name "$filename" | sed 's/"//g')
74+
base_url="http://localhost/service/rest/v1/repositories/$base_type/$repo_type"
3175

32-
config_timeout=300
33-
status_code=1
34-
while [ "$status_code" != 201 ]; do
35-
status_code=$(curl -iu admin:"$1" -XPOST \
36-
"$base_url" \
76+
configure_repo() {
77+
local file="$1"
78+
local url="$2"
79+
local pass="$3"
80+
local code
81+
code=$(curl -iu admin:"$pass" -XPOST \
82+
"$url" \
3783
-H 'accept: application/json' \
3884
-H 'Content-Type: application/json' \
39-
-d @"$filename" \
85+
-d @"$file" \
4086
-k -s -w "%{http_code}" -o /dev/null)
41-
echo "Response received from Nexus: $status_code"
87+
echo "Response received from Nexus: $code"
88+
[ "$code" -eq 201 ]
89+
}
4290

43-
if [ $config_timeout == 0 ]; then
44-
echo "ERROR - Timeout while trying to configure $repo_name"
45-
exit 1
46-
elif [ "$status_code" != 201 ]; then
47-
sleep 1
48-
((config_timeout--))
49-
fi
50-
done
91+
if ! retry_with_backoff configure_repo "$filename" "$base_url" "$1"; then
92+
echo "ERROR - Timeout while trying to configure $repo_name"
93+
exit 1
94+
fi
5195
done
5296

53-
# Configure realms required for repo authentication
5497
echo 'Configuring realms...'
5598
status_code=$(curl -iu admin:"$1" -XPUT \
5699
'http://localhost/service/rest/v1/security/realms/active' \
@@ -59,13 +102,3 @@ status_code=$(curl -iu admin:"$1" -XPUT \
59102
-d @"$(dirname "${BASH_SOURCE[0]}")"/nexus_realms_config.json \
60103
-k -s -w "%{http_code}" -o /dev/null)
61104
echo "Response received from Nexus: $status_code"
62-
63-
# Add a new section to handle the VS Code extensions configuration
64-
echo 'Configuring VS Code extensions proxy...'
65-
status_code=$(curl -iu admin:"$1" -XPOST \
66-
'http://localhost/service/rest/v1/repositories/raw/proxy' \
67-
-H 'accept: application/json' \
68-
-H 'Content-Type: application/json' \
69-
-d @"$(dirname "${BASH_SOURCE[0]}")"/nexus_repos_config/vscode_extensions_proxy_conf.json \
70-
-k -s -w "%{http_code}" -o /dev/null)
71-
echo "Response received from Nexus: $status_code"

0 commit comments

Comments
 (0)