Skip to content

Commit 7342175

Browse files
committed
feat: install more components to /opt/bin instead of /usr/local/bin
/usr/local/bin is generally read-only on immutable distributions. A profile.d script has been added to ensure /opt/bin is in the PATH.
1 parent 1bf769a commit 7342175

15 files changed

Lines changed: 60 additions & 8 deletions

parts/common/components.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@
842842
},
843843
{
844844
"name": "oras",
845-
"downloadLocation": "/usr/local/bin",
845+
"downloadLocation": "/opt/bin",
846846
"downloadURIs": {
847847
"default": {
848848
"current": {

parts/linux/cloud-init/artifacts/cse_helpers.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ ERR_SECURE_TLS_BOOTSTRAP_START_FAILURE=220 # Error starting the secure TLS boots
139139
ERR_CLOUD_INIT_FAILED=223 # Error indicating that cloud-init returned exit code 1 in cse_cmd.sh
140140
ERR_NVIDIA_DRIVER_INSTALL=224 # Error determining if nvidia driver install should be skipped
141141

142+
# This probably wasn't launched via a login shell, so ensure the PATH is correct.
143+
[ -f /etc/profile.d/path.sh ] && . /etc/profile.d/path.sh
144+
142145
# For both Ubuntu and Mariner, /etc/*-release should exist.
143146
# For unit tests, the OS and OS_VERSION will be set in the unit test script.
144147
# So whether it's if or else actually doesn't matter to our unit test.

parts/linux/cloud-init/artifacts/cse_install.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ CNI_BIN_DIR="/opt/cni/bin"
77
#TODO pull this out of componetns.json too?
88
CNI_DOWNLOADS_DIR="/opt/cni/downloads"
99
CRICTL_DOWNLOAD_DIR="/opt/crictl/downloads"
10-
CRICTL_BIN_DIR="/usr/local/bin"
10+
CRICTL_BIN_DIR="/opt/bin"
1111
CONTAINERD_DOWNLOADS_DIR="/opt/containerd/downloads"
1212
RUNC_DOWNLOADS_DIR="/opt/runc/downloads"
1313
K8S_DOWNLOADS_DIR="/opt/kubernetes/downloads"
@@ -204,7 +204,7 @@ installCredentialProvider() {
204204
# TODO (alburgess) have oras version managed by dependant or Renovate
205205
installOras() {
206206
ORAS_DOWNLOAD_DIR="/opt/oras/downloads"
207-
ORAS_EXTRACTED_DIR=${1} # Use components.json var for /usr/local/bin for linux-vhd-content-test.sh binary file checks.
207+
ORAS_EXTRACTED_DIR=${1} # Use components.json var for /opt/bin for linux-vhd-content-test.sh binary file checks.
208208
ORAS_DOWNLOAD_URL=${2}
209209
ORAS_VERSION=${3}
210210

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
case "${PATH}" in
4+
/opt/bin:*) : ;;
5+
*) PATH=/opt/bin:${PATH} ;;
6+
esac

pkg/agent/utils_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -802,8 +802,8 @@ var _ = Describe("Assert datamodel.CSEStatus can be used to parse output JSON",
802802
var _ = Describe("Test removeComments", func() {
803803

804804
It("Should leave lines without comments unchanged", func() {
805-
input := []byte("#!/bin/bash\n\nCC_SERVICE_IN_TMP=/opt/azure/containers/cc-proxy.service.in\nCC_SOCKET_IN_TMP=/opt/azure/containers/cc-proxy.socket.in\nCNI_CONFIG_DIR=\"/etc/cni/net.d\"\nCNI_BIN_DIR=\"/opt/cni/bin\"\nCNI_DOWNLOADS_DIR=\"/opt/cni/downloads\"\nCRICTL_DOWNLOAD_DIR=\"/opt/crictl/downloads\"\nCRICTL_BIN_DIR=\"/usr/local/bin\"\nCONTAINERD_DOWNLOADS_DIR=\"/opt/containerd/downloads\"\nRUNC_DOWNLOADS_DIR=\"/opt/runc/downloads\"\nK8S_DOWNLOADS_DIR=\"/opt/kubernetes/downloads\"\nUBUNTU_RELEASE=$(lsb_release -r -s)\nSECURE_TLS_BOOTSTRAP_KUBELET_EXEC_PLUGIN_DOWNLOAD_DIR=\"/opt/azure/tlsbootstrap\"\nSECURE_TLS_BOOTSTRAP_KUBELET_EXEC_PLUGIN_VERSION=\"v0.1.0-alpha.2\"\nTELEPORTD_PLUGIN_DOWNLOAD_DIR=\"/opt/teleportd/downloads\"\nTELEPORTD_PLUGIN_BIN_DIR=\"/opt/bin\"\nCONTAINERD_WASM_VERSIONS=\"v0.3.0 v0.5.1 v0.8.0\"\nMANIFEST_FILEPATH=\"/opt/azure/manifest.json\"\nMAN_DB_AUTO_UPDATE_FLAG_FILEPATH=\"/var/lib/man-db/auto-update\"\nCURL_OUTPUT=/tmp/curl_verbose.out")
806-
expected := "#!/bin/bash\n\nCC_SERVICE_IN_TMP=/opt/azure/containers/cc-proxy.service.in\nCC_SOCKET_IN_TMP=/opt/azure/containers/cc-proxy.socket.in\nCNI_CONFIG_DIR=\"/etc/cni/net.d\"\nCNI_BIN_DIR=\"/opt/cni/bin\"\nCNI_DOWNLOADS_DIR=\"/opt/cni/downloads\"\nCRICTL_DOWNLOAD_DIR=\"/opt/crictl/downloads\"\nCRICTL_BIN_DIR=\"/usr/local/bin\"\nCONTAINERD_DOWNLOADS_DIR=\"/opt/containerd/downloads\"\nRUNC_DOWNLOADS_DIR=\"/opt/runc/downloads\"\nK8S_DOWNLOADS_DIR=\"/opt/kubernetes/downloads\"\nUBUNTU_RELEASE=$(lsb_release -r -s)\nSECURE_TLS_BOOTSTRAP_KUBELET_EXEC_PLUGIN_DOWNLOAD_DIR=\"/opt/azure/tlsbootstrap\"\nSECURE_TLS_BOOTSTRAP_KUBELET_EXEC_PLUGIN_VERSION=\"v0.1.0-alpha.2\"\nTELEPORTD_PLUGIN_DOWNLOAD_DIR=\"/opt/teleportd/downloads\"\nTELEPORTD_PLUGIN_BIN_DIR=\"/opt/bin\"\nCONTAINERD_WASM_VERSIONS=\"v0.3.0 v0.5.1 v0.8.0\"\nMANIFEST_FILEPATH=\"/opt/azure/manifest.json\"\nMAN_DB_AUTO_UPDATE_FLAG_FILEPATH=\"/var/lib/man-db/auto-update\"\nCURL_OUTPUT=/tmp/curl_verbose.out"
805+
input := []byte("#!/bin/bash\n\nCC_SERVICE_IN_TMP=/opt/azure/containers/cc-proxy.service.in\nCC_SOCKET_IN_TMP=/opt/azure/containers/cc-proxy.socket.in\nCNI_CONFIG_DIR=\"/etc/cni/net.d\"\nCNI_BIN_DIR=\"/opt/cni/bin\"\nCNI_DOWNLOADS_DIR=\"/opt/cni/downloads\"\nCRICTL_DOWNLOAD_DIR=\"/opt/crictl/downloads\"\nCRICTL_BIN_DIR=\"/opt/bin\"\nCONTAINERD_DOWNLOADS_DIR=\"/opt/containerd/downloads\"\nRUNC_DOWNLOADS_DIR=\"/opt/runc/downloads\"\nK8S_DOWNLOADS_DIR=\"/opt/kubernetes/downloads\"\nUBUNTU_RELEASE=$(lsb_release -r -s)\nSECURE_TLS_BOOTSTRAP_KUBELET_EXEC_PLUGIN_DOWNLOAD_DIR=\"/opt/azure/tlsbootstrap\"\nSECURE_TLS_BOOTSTRAP_KUBELET_EXEC_PLUGIN_VERSION=\"v0.1.0-alpha.2\"\nTELEPORTD_PLUGIN_DOWNLOAD_DIR=\"/opt/teleportd/downloads\"\nTELEPORTD_PLUGIN_BIN_DIR=\"/opt/bin\"\nCONTAINERD_WASM_VERSIONS=\"v0.3.0 v0.5.1 v0.8.0\"\nMANIFEST_FILEPATH=\"/opt/azure/manifest.json\"\nMAN_DB_AUTO_UPDATE_FLAG_FILEPATH=\"/var/lib/man-db/auto-update\"\nCURL_OUTPUT=/tmp/curl_verbose.out")
806+
expected := "#!/bin/bash\n\nCC_SERVICE_IN_TMP=/opt/azure/containers/cc-proxy.service.in\nCC_SOCKET_IN_TMP=/opt/azure/containers/cc-proxy.socket.in\nCNI_CONFIG_DIR=\"/etc/cni/net.d\"\nCNI_BIN_DIR=\"/opt/cni/bin\"\nCNI_DOWNLOADS_DIR=\"/opt/cni/downloads\"\nCRICTL_DOWNLOAD_DIR=\"/opt/crictl/downloads\"\nCRICTL_BIN_DIR=\"/opt/bin\"\nCONTAINERD_DOWNLOADS_DIR=\"/opt/containerd/downloads\"\nRUNC_DOWNLOADS_DIR=\"/opt/runc/downloads\"\nK8S_DOWNLOADS_DIR=\"/opt/kubernetes/downloads\"\nUBUNTU_RELEASE=$(lsb_release -r -s)\nSECURE_TLS_BOOTSTRAP_KUBELET_EXEC_PLUGIN_DOWNLOAD_DIR=\"/opt/azure/tlsbootstrap\"\nSECURE_TLS_BOOTSTRAP_KUBELET_EXEC_PLUGIN_VERSION=\"v0.1.0-alpha.2\"\nTELEPORTD_PLUGIN_DOWNLOAD_DIR=\"/opt/teleportd/downloads\"\nTELEPORTD_PLUGIN_BIN_DIR=\"/opt/bin\"\nCONTAINERD_WASM_VERSIONS=\"v0.3.0 v0.5.1 v0.8.0\"\nMANIFEST_FILEPATH=\"/opt/azure/manifest.json\"\nMAN_DB_AUTO_UPDATE_FLAG_FILEPATH=\"/var/lib/man-db/auto-update\"\nCURL_OUTPUT=/tmp/curl_verbose.out"
807807
result := removeComments(input)
808808
Expect(string(result)).To(Equal(expected))
809809
})

vhdbuilder/packer/packer_source.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ copyPackerFiles() {
2929
PAM_D_SU_DEST=/etc/pam.d/su
3030
PROFILE_D_CIS_SH_SRC=/home/packer/profile-d-cis.sh
3131
PROFILE_D_CIS_SH_DEST=/etc/profile.d/CIS.sh
32+
PROFILE_D_PATH_SH_SRC=/home/packer/profile-d-path.sh
33+
PROFILE_D_PATH_SH_DEST=/etc/profile.d/path.sh
3234
CIS_SRC=/home/packer/cis.sh
3335
CIS_DEST=/opt/azure/containers/provision_cis.sh
3436
APT_PREFERENCES_SRC=/home/packer/apt-preferences
@@ -337,6 +339,7 @@ copyPackerFiles() {
337339
cpAndMode $MODPROBE_CIS_SRC $MODPROBE_CIS_DEST 644
338340
cpAndMode $PWQUALITY_CONF_SRC $PWQUALITY_CONF_DEST 600
339341
cpAndMode $PAM_D_SU_SRC $PAM_D_SU_DEST 644
342+
cpAndMode $PROFILE_D_PATH_SH_SRC $PROFILE_D_PATH_SH_DEST 755
340343
cpAndMode $PROFILE_D_CIS_SH_SRC $PROFILE_D_CIS_SH_DEST 755
341344
cpAndMode $CIS_SRC $CIS_DEST 744
342345
cpAndMode $APT_PREFERENCES_SRC $APT_PREFERENCES_DEST 644

vhdbuilder/packer/test/linux-vhd-content-test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ testPackagesInstalled() {
279279
continue
280280
fi
281281

282-
# if the downloadLocation is /usr/local/bin verify that the package is installed
283-
if [ "$downloadLocation" = "/usr/local/bin" ]; then
282+
# if the downloadLocation is /opt/bin, verify the package is in the PATH
283+
if [ "$downloadLocation" = /opt/bin ]; then
284284
if command -v "$name" >/dev/null 2>&1; then
285285
echo "$name is installed."
286286
continue

vhdbuilder/packer/vhd-image-builder-arm64-gen2.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,11 @@
407407
"source": "parts/linux/cloud-init/artifacts/profile-d-cis.sh",
408408
"destination": "/home/packer/profile-d-cis.sh"
409409
},
410+
{
411+
"type": "file",
412+
"source": "parts/linux/cloud-init/artifacts/profile-d-path.sh",
413+
"destination": "/home/packer/profile-d-path.sh"
414+
},
410415
{
411416
"type": "file",
412417
"source": "parts/linux/cloud-init/artifacts/disk_queue.service",

vhdbuilder/packer/vhd-image-builder-base.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,11 @@
420420
"source": "parts/linux/cloud-init/artifacts/profile-d-cis.sh",
421421
"destination": "/home/packer/profile-d-cis.sh"
422422
},
423+
{
424+
"type": "file",
425+
"source": "parts/linux/cloud-init/artifacts/profile-d-path.sh",
426+
"destination": "/home/packer/profile-d-path.sh"
427+
},
423428
{
424429
"type": "file",
425430
"source": "parts/linux/cloud-init/artifacts/disk_queue.service",

vhdbuilder/packer/vhd-image-builder-cvm.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,11 @@
424424
"source": "parts/linux/cloud-init/artifacts/profile-d-cis.sh",
425425
"destination": "/home/packer/profile-d-cis.sh"
426426
},
427+
{
428+
"type": "file",
429+
"source": "parts/linux/cloud-init/artifacts/profile-d-path.sh",
430+
"destination": "/home/packer/profile-d-path.sh"
431+
},
427432
{
428433
"type": "file",
429434
"source": "parts/linux/cloud-init/artifacts/disk_queue.service",
@@ -729,4 +734,4 @@
729734
]
730735
}
731736
]
732-
}
737+
}

0 commit comments

Comments
 (0)