Skip to content

Commit 461999c

Browse files
committed
Unset xtrace while logging into acr via podman to prevent exposing the acr login secret
Reference: https://portal.microsofticm.com/imp/v5/incidents/details/752908291/summary Add unset xtrace while configuring tls certificates * To be extra safe and ensure no certificate details are logged via shell tracing. Add shell check comments, Update function descriptions * Add shellcheck comments for warnings that can be safely ignored. * Improve function readability by formatting them all in the same style. Address shellcheck warnings in bootstrap scripts * Several warnings were unaddressed. Some of them were disabled as they can be safely ignored. * Others were refactored as the warnings were legitimate.
1 parent 5952857 commit 461999c

File tree

9 files changed

+406
-133
lines changed

9 files changed

+406
-133
lines changed

pkg/deploy/assets/gateway-production.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

pkg/deploy/assets/rp-production.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

pkg/deploy/generator/scripts/gatewayVMSS.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,11 @@ RPIMAGE='$rpimage'"
147147
reboot_vm
148148
}
149149

150+
# export AZURE_CLOUD_NAME="${AZURECLOUDNAME:?"Failed to carry over variables"}"
150151
export AZURE_CLOUD_NAME="${AZURECLOUDNAME:?"Failed to carry over variables"}"
151152

153+
# util="util.sh"
154+
#
152155
# util.sh does not exist when deployed to VMSS via VMSS extensions
153156
# Provides shellcheck definitions
154157
util="util.sh"

pkg/deploy/generator/scripts/rpVMSS.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ main() {
88
# transaction attempt retry time in seconds
99
# shellcheck disable=SC2034
1010
local -ri retry_wait_time=30
11-
local -ri pkg_retry_count=60
1211

1312
create_required_dirs
13+
1414
configure_sshd
15+
16+
local -ri pkg_retry_count=60
1517
configure_rpm_repos retry_wait_time \
1618
"$pkg_retry_count"
1719

@@ -53,10 +55,16 @@ main() {
5355
# shellcheck disable=SC2153 disable=SC2034
5456
local -r mdmimage="${RPIMAGE%%/*}/${MDMIMAGE#*/}"
5557
local -r rpimage="$RPIMAGE"
58+
59+
# shellcheck disable=SC2034
5660
local -r miseimage="${RPIMAGE%%/*}/${MISEIMAGE#*/}"
61+
62+
# shellcheck disable=SC2034
5763
local -r otelimage="$OTELIMAGE"
64+
5865
# shellcheck disable=SC2034
5966
local -r fluentbit_image="$FLUENTBITIMAGE"
67+
6068
# shellcheck disable=SC2034
6169
local -rA aro_images=(
6270
["mdm"]="mdmimage"
@@ -218,11 +226,15 @@ MSI_RP_ENDPOINT='$MSIRPENDPOINT'
218226
reboot_vm
219227
}
220228

229+
# export AZURE_CLOUD_NAME="${AZURECLOUDNAME:?"Failed to carry over variables"}"
230+
#
221231
# This variable is used by az-cli
222232
# It's assumed that if this variable hasn't been carried over, that others are also not present, so we fail early by returning an error
223233
# This was mostly helpful when testing on a development VM, but is still applicable
224234
export AZURE_CLOUD_NAME="${AZURECLOUDNAME:?"Failed to carry over variables"}"
225235

236+
# util="util.sh"
237+
#
226238
# util.sh does not exist when deployed to VMSS via VMSS extensions
227239
# Provides shellcheck definitions
228240
util="util.sh"

pkg/deploy/generator/scripts/util-common.sh

Lines changed: 106 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,111 @@
11
#!/bin/bash
22
# Internal Functions and Constants
33

4-
# empty_str - constant; used by functions for optional nameref string arguements
5-
# empty_str=""
4+
# declare -r empty_str=""
5+
#
6+
# empty_str - constant
7+
# * used by functions for optional nameref string arguments
68
# shellcheck disable=SC2034
79
declare -r empty_str=""
810

9-
# role_gateway - constant; Is used to determine which VMSS is being bootstrapped
11+
# declare -r role_gateway="gateway"
12+
#
1013
# this should be referenced by scripts sourcing this file
1114
# role_gateway="gateway"
1215
declare -r role_gateway="gateway"
13-
# role_rp - constant; Is used to determine which VMSS is being bootstrapped
16+
17+
# declare -r role_rp="rp"
18+
#
1419
# this should be referenced by scripts sourcing this file
1520
# role_rp="rp"
1621
declare -r role_rp="rp"
17-
# role_devproxy - constant; Is used to determine which VMSS is being bootstrapped
18-
# role_devproxy="devproxy"
22+
23+
# declare -r role_devproxy="devproxy"
24+
#
25+
# role_devproxy - constant
26+
# * Is used to determine which VMSS is being bootstrapped
1927
declare -r role_devproxy="devproxy"
20-
# us_gov_cloud - constant; Is the name of AZURECLOUDNAME for US government cloud
21-
# us_gov_cloud="AzureUSGovernment"
28+
29+
# declare -r us_gov_cloud="AzureUSGovernment"
30+
#
31+
# us_gov_cloud - constant
32+
# * Is the name of AZURECLOUDNAME for US government cloud
2233
declare -r us_gov_cloud="AzureUSGovernment"
2334

24-
# log is a wrapper for echo that includes the function name
25-
# Args
26-
# 1) msg - string
27-
# 2) stack_level - int; optional, defaults to the function at the bottom of the call stack
35+
# declare -i XTRACE_SET=1
36+
#
37+
# constant value signifying xtrace shell value is/should be set
38+
declare -ir XTRACE_SET=1
39+
40+
# declare -i XTRACE_UNSET=0
41+
#
42+
# constant value signifying xtrace shell value is/should be unset
43+
declare -ir XTRACE_UNSET=0
44+
45+
# xtrace_is_set()
46+
#
47+
# Check if xtrace shell option is enabled/disabled
48+
# * Returns XTRACE_SET value if set
49+
# * Returns XTRACE_UNSET value if unset
50+
xtrace_is_set() {
51+
if [[ $- =~ "x" ]]; then
52+
echo XTRACE_SET
53+
fi
54+
55+
echo XTRACE_UNSET
56+
}
57+
58+
# xtrace_toggle()
59+
#
60+
# set/unset xtrace shell option
61+
# args:
62+
# 1) string - nameref
63+
# * Must be XTRACE_SET or XTRACE_UNSET
64+
xtrace_toggle() {
65+
if ! [[ $1 =~ ("XTRACE_SET"|"XTRACE_UNSET") ]]; then
66+
log "\$1 invalid; \$1 must be XTRACE_SET or XTRACE_UNSET. \$1: $1"
67+
return 1
68+
fi
69+
70+
if (( $1 == XTRACE_SET )); then
71+
set -x
72+
elif
73+
(( $1 == XTRACE_UNSET )); then
74+
set +x
75+
fi
76+
}
77+
78+
# log()
79+
#
80+
# Wrapper for echo that includes the function name
81+
# args:
82+
# 1) msg - string
83+
# 2) stack_level - int
84+
# * optional
85+
# * defaults to the function at the bottom of the call stack
2886
log() {
2987
local -r msg="${1:-"log message is empty"}"
3088
local -r stack_level="${2:-1}"
3189
echo "${FUNCNAME[${stack_level}]}: ${msg}"
3290
}
3391

34-
# abort is a wrapper for log that exits with an error code
92+
# abort()
93+
#
94+
# Wrapper for log that exits with an error code
3595
abort() {
3696
local -ri origin_stacklevel=2
3797
log "${1}" "$origin_stacklevel"
3898
log "Exiting"
3999
exit 1
40100
}
41101

42-
# write_file
43-
# Args
44-
# 1) filename - string
45-
# 2) file_contents - string
46-
# 3) clobber - boolean; optional - defaults to false
102+
# write_file()
103+
#
104+
# args:
105+
# 1) filename - string
106+
# 2) file_contents - string
107+
# 3) clobber - boolean
108+
# * Optional; defaults to false
47109
write_file() {
48110
local -n filename="$1"
49111
local -n file_contents="$2"
@@ -58,11 +120,16 @@ write_file() {
58120
fi
59121
}
60122

61-
# retry Adding retry logic to yum commands in order to avoid stalling out on resource locks
123+
# retry()
124+
#
125+
# Add retry logic to commands in order to avoid stalling out on resource locks
62126
# args:
63-
# 1) cmd_retry - nameref, array; Command and arguement(s) to retry
64-
# 2) wait_time - nameref, integer; Time to wait before retrying command
65-
# 3) retries - integer, optional; Ammount of times to retry command, defaults to 5
127+
# 1) cmd_retry - nameref, array
128+
# * Command and argument(s) to retry
129+
# 2) wait_time - nameref, integer
130+
# * Time to wait before retrying command
131+
# 3) retries - integer, optional
132+
# * Amount of times to retry command, defaults to 5
66133
retry() {
67134
local -n cmd_retry="$1"
68135
local -n wait_time="$2"
@@ -81,9 +148,11 @@ retry() {
81148
abort "${cmd_retry[*]} failed after #$retries attempts"
82149
}
83150

84-
# verify_role
151+
# verify_role()
152+
#
85153
# args:
86-
# 1) test_role - nameref; role being verified
154+
# 1) test_role - nameref
155+
# * role being verified
87156
verify_role() {
88157
local -n test_role="$1"
89158

@@ -95,11 +164,15 @@ verify_role() {
95164
fi
96165
}
97166

98-
# get_keyvault_suffix
167+
# get_keyvault_suffix()
168+
#
99169
# args:
100-
# 1) rl - nameref, string; role to get short role for
101-
# 2) kv_suffix - nameref, string; short role will be assigned to this nameref
102-
# 3) sec_prefix - nameref, string; keyvault certificate prefix will be assigned to this nameref
170+
# 1) rl - nameref, string
171+
# * role to get short role for
172+
# 2) kv_suffix - nameref, string
173+
# * short role will be assigned to this nameref
174+
# 3) sec_prefix - nameref, string
175+
# * keyvault certificate prefix will be assigned to this nameref
103176
get_keyvault_suffix() {
104177
local -n rl="$1"
105178
local -n kv_suffix="$2"
@@ -118,14 +191,16 @@ get_keyvault_suffix() {
118191
sec_prefix="$role_rp"
119192
;;
120193
*)
121-
abort "unkown role $rl"
194+
abort "unknown role $rl"
122195
;;
123196
esac
124197
}
125198

199+
# reboot_vm()
200+
#
126201
# reboot_vm restores calls shutdown -r in a subshell
127-
# Reboots should scheduled after all VM extensions have had time to complete
128-
# Reference: https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/custom-script-linux#tips
202+
# * Reboots should scheduled after all VM extensions have had time to complete
203+
# * Reference: https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/custom-script-linux#tips
129204
reboot_vm() {
130205
log "starting"
131206

pkg/deploy/generator/scripts/util-packages.sh

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/bash
22
# Repository and package management related functions
33

4+
# configure_repo_mariner_extended()
45
configure_repo_mariner_extended() {
56
local -r extended_repo_config="https://packages.microsoft.com/cbl-mariner/2.0/prod/extended/x86_64/config.repo"
67
curl -sSL "$extended_repo_config" -o /etc/yum.repos.d/mariner-extended.repo
@@ -19,21 +20,28 @@ configure_repo_mariner_extended() {
1920
}
2021

2122
# configure_rpm_repos
23+
#
2224
# New repositories should be added in their own functions, and called here
2325
# args:
24-
# 1) wait_time - nameref, integer; Time to wait before retrying command
25-
# 2) retries - integer, optional; Amount of times to retry command, defaults to 5
26+
# 1) wait_time - nameref, integer
27+
# * Time to wait before retrying command
28+
# 2) retries - integer, optional
29+
# * Amount of times to retry command, defaults to 5
2630
configure_rpm_repos() {
2731
log "starting"
2832

2933
configure_repo_mariner_extended "$1" "${2:-1}"
3034
}
3135

3236
# dnf_install_pkgs
37+
#
3338
# args:
34-
# 1) pkgs - nameref, string array; Packages to be installed
35-
# 2) wait_time - nameref, integer; Time to wait before retrying command
36-
# 3) retries - integer, optional; Amount of times to retry command, defaults to 5
39+
# 1) pkgs - nameref, string array
40+
# * Packages to be installed
41+
# 2) wait_time - nameref, integer
42+
# * Time to wait before retrying command
43+
# 3) retries - integer, optional
44+
# * Amount of times to retry command, defaults to 5
3745
dnf_install_pkgs() {
3846
local -n pkgs="$1"
3947
log "starting"
@@ -55,11 +63,15 @@ dnf_install_pkgs() {
5563

5664

5765
# dnf_update_pkgs
66+
#
5867
# args:
59-
# 1) excludes - nameref, string array, optional; Packages to exclude from updating
60-
# Each index must be prefixed with -x
61-
# 2) wait_time - nameref, integer; Time to wait before retrying command
62-
# 3) retries - integer, optional; Ammount of times to retry command, defaults to 5
68+
# 1) excludes - nameref, string array, optional
69+
# * Packages to exclude from updating
70+
# * Each index must be prefixed with -x
71+
# 2) wait_time - nameref, integer
72+
# * Time to wait before retrying command
73+
# 3) retries - integer, optional
74+
# * Amount of times to retry command, defaults to 5
6375
dnf_update_pkgs() {
6476
local -n excludes="${1:-empty_str}"
6577
log "starting"
@@ -87,9 +99,12 @@ dnf_update_pkgs() {
8799
}
88100

89101
# rpm_import_keys
102+
#
90103
# args:
91-
# 1) keys - nameref, string array; rpm keys to be imported
92-
# 2) wait_time - nameref, integer; Time to wait before retrying command
104+
# 1) keys - nameref, string array
105+
# * rpm keys to be imported
106+
# 2) wait_time - nameref, integer
107+
# * Time to wait before retrying command
93108
rpm_import_keys() {
94109
local -n keys="$1"
95110
log "starting"
@@ -112,6 +127,8 @@ rpm_import_keys() {
112127
done
113128
}
114129

130+
# util_common="util-common.sh"
131+
#
115132
# util-common.sh does not exist when deployed to VMSS via VMSS extensions
116133
# Provides shellcheck definitions
117134
util_common="util-common.sh"

0 commit comments

Comments
 (0)