Skip to content

Commit

Permalink
fix: add SOCI snapshotter hash check
Browse files Browse the repository at this point in the history
Signed-off-by: Austin Vazquez <[email protected]>
  • Loading branch information
austinvazquez committed Jun 5, 2024
1 parent 7fc3104 commit c8d08e8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
18 changes: 16 additions & 2 deletions pkg/config/lima_config_applier.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,24 @@ const (
sociServiceDownloadURLFormat = "https://raw.githubusercontent.com/awslabs/soci-snapshotter/v%s/soci-snapshotter.service"
//nolint:lll // command string
sociInstallationScriptFormat = `%s
#!/bin/bash
if [ ! -f /usr/local/bin/soci ]; then
# download soci
set -e
# pull release tarball
release_tarball="%s"
curl --retry 2 --retry-max-time 120 -OL "%s"
# pull release shasum
release_tarball_shasum="%s"
curl --retry 2 --retry-max-time 120 -OL "%s"
# validate shasum
sha256sum --check --status ${release_tarball_shasum} || (echo "error: shasum verification failed for SOCI release tarball" && exit 1)
# move to usr/local/bin
tar -C /usr/local/bin -xvf %s ./soci ./soci-snapshotter-grpc
tar -C /usr/local/bin -xvf ${release_tarball} ./soci ./soci-snapshotter-grpc
# install as a systemd service
curl --retry 2 --retry-max-time 120 -OL "%s"
Expand Down Expand Up @@ -237,9 +249,11 @@ func (lca *limaConfigApplier) provisionSnapshotters(limaCfg *limayaml.LimaYAML)
func (lca *limaConfigApplier) provisionSociSnapshotter(limaCfg *limayaml.LimaYAML) {
sociFileName := fmt.Sprintf(sociFileNameFormat, sociVersion, lca.systemDeps.Arch())
sociDownloadURL := fmt.Sprintf(sociDownloadURLFormat, sociVersion, sociFileName)
sociShaSumFileName := sociFileName + ".sha256sum"
sociShaSumDownloadURL := fmt.Sprintf(sociDownloadURLFormat, sociVersion, sociShaSumFileName)
sociServiceDownloadURL := fmt.Sprintf(sociServiceDownloadURLFormat, sociVersion)
sociInstallationScript := fmt.Sprintf(sociInstallationScriptFormat, sociInstallationProvisioningScriptHeader,
sociDownloadURL, sociFileName, sociServiceDownloadURL)
sociFileName, sociDownloadURL, sociShaSumFileName, sociShaSumDownloadURL, sociServiceDownloadURL)
limaCfg.Provision = append(limaCfg.Provision, limayaml.Provision{
Mode: "system",
Script: sociInstallationScript,
Expand Down
18 changes: 15 additions & 3 deletions pkg/config/lima_config_applier_darwin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,15 @@ func TestDiskLimaConfigApplier_Apply(t *testing.T) {
postRunCheck: func(t *testing.T, fs afero.Fs) {
sociFileName := fmt.Sprintf(sociFileNameFormat, sociVersion, "")
sociDownloadURL := fmt.Sprintf(sociDownloadURLFormat, sociVersion, sociFileName)
sociShaSumFileName := sociFileName + ".sha256sum"
sociShaSumDownloadURL := fmt.Sprintf(sociDownloadURLFormat, sociVersion, sociShaSumFileName)
sociServiceDownloadURL := fmt.Sprintf(sociServiceDownloadURLFormat, sociVersion)
sociInstallationScript := fmt.Sprintf(sociInstallationScriptFormat,
sociInstallationProvisioningScriptHeader,
sociDownloadURL,
sociFileName,
sociDownloadURL,
sociShaSumFileName,
sociShaSumDownloadURL,
sociServiceDownloadURL)

buf, err := afero.ReadFile(fs, "/override.yaml")
Expand Down Expand Up @@ -262,11 +266,15 @@ func TestDiskLimaConfigApplier_Apply(t *testing.T) {
postRunCheck: func(t *testing.T, fs afero.Fs) {
sociFileName := fmt.Sprintf(sociFileNameFormat, sociVersion, "")
sociDownloadURL := fmt.Sprintf(sociDownloadURLFormat, sociVersion, sociFileName)
sociShaSumFileName := sociFileName + ".sha256sum"
sociShaSumDownloadURL := fmt.Sprintf(sociDownloadURLFormat, sociVersion, sociShaSumFileName)
sociServiceDownloadURL := fmt.Sprintf(sociServiceDownloadURLFormat, sociVersion)
sociInstallationScript := fmt.Sprintf(sociInstallationScriptFormat,
sociInstallationProvisioningScriptHeader,
sociDownloadURL,
sociFileName,
sociDownloadURL,
sociShaSumFileName,
sociShaSumDownloadURL,
sociServiceDownloadURL)

buf, err := afero.ReadFile(fs, "/override.yaml")
Expand Down Expand Up @@ -321,11 +329,15 @@ func TestDiskLimaConfigApplier_Apply(t *testing.T) {
postRunCheck: func(t *testing.T, fs afero.Fs) {
sociFileName := fmt.Sprintf(sociFileNameFormat, sociVersion, "")
sociDownloadURL := fmt.Sprintf(sociDownloadURLFormat, sociVersion, sociFileName)
sociShaSumFileName := sociFileName + ".sha256sum"
sociShaSumDownloadURL := fmt.Sprintf(sociDownloadURLFormat, sociVersion, sociShaSumFileName)
sociServiceDownloadURL := fmt.Sprintf(sociServiceDownloadURLFormat, sociVersion)
sociInstallationScript := fmt.Sprintf(sociInstallationScriptFormat,
sociInstallationProvisioningScriptHeader,
sociDownloadURL,
sociFileName,
sociDownloadURL,
sociShaSumFileName,
sociShaSumDownloadURL,
sociServiceDownloadURL)

buf, err := afero.ReadFile(fs, "/override.yaml")
Expand Down

0 comments on commit c8d08e8

Please sign in to comment.