Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle RPM upgrade in %postun script #14379

Merged
merged 3 commits into from
Oct 27, 2023
Merged

Handle RPM upgrade in %postun script #14379

merged 3 commits into from
Oct 27, 2023

Conversation

edwardsb
Copy link
Contributor

@edwardsb edwardsb commented Oct 9, 2023

This pull request addresses a key aspect of the RPM upgrade process - handling of scripts during upgrades vice pure deletion events.

An RPM upgrade operation consists of both an Install and an Uninstall operation, meaning that during an upgrade, our %postun script is run and previously, it was causing the accidental deletion of binaries needed for the upgrade.

To prevent this unwanted removal during upgrade scenarios, the %postun script now checks for the execution scenario in which it finds itself.

Checklist for submitter

If some of the following don't apply, delete the relevant line.

  • Changes file added for user-visible changes in changes/ or orbit/changes/.
    See Changes files for more information.
  • Manual QA for all new/changed functionality
    • For Orbit and Fleet Desktop changes:
      • Manual QA must be performed in the three main OSs, macOS, Windows and Linux.

@edwardsb
Copy link
Contributor Author

edwardsb commented Oct 9, 2023

relates to #14380

@edwardsb edwardsb temporarily deployed to Docker Hub October 9, 2023 15:53 — with GitHub Actions Inactive
@edwardsb edwardsb temporarily deployed to Docker Hub October 9, 2023 15:53 — with GitHub Actions Inactive
rfairburn
rfairburn previously approved these changes Oct 9, 2023
@edwardsb edwardsb marked this pull request as ready for review October 9, 2023 15:57
@edwardsb edwardsb requested a review from a team as a code owner October 9, 2023 15:57
@codecov
Copy link

codecov bot commented Oct 9, 2023

Codecov Report

Attention: 5 lines in your changes are missing coverage. Please review.

Comparison is base (ae669e1) 58.87% compared to head (916e2e5) 58.87%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #14379   +/-   ##
=======================================
  Coverage   58.87%   58.87%           
=======================================
  Files         925      925           
  Lines       77319    77333   +14     
  Branches     2222     2222           
=======================================
+ Hits        45521    45531   +10     
- Misses      28186    28190    +4     
  Partials     3612     3612           
Flag Coverage Δ
backend 59.57% <0.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
orbit/pkg/packaging/linux_shared.go 0.00% <0.00%> (ø)

... and 2 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines 367 to 371
if [ "$1" = 0 ]; then
rm -rf /var/lib/orbit /var/log/orbit /usr/local/bin/orbit /etc/default/orbit /usr/lib/systemd/system/orbit.service /opt/orbit
fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too familiar with this part of the code, can you point me to where this script is being called?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mostlikelee hey this is used as a template file for the RPM/DEB package post run script.

We use https://github.com/goreleaser/nfpm to create RPM/DEB installers of fleetd so this is getting used during fleetctl package -type=rpm

This particular script is executed during the %postun phase of a RPM upgrade/uninstall.

The problem here is that when upgrading, I think the %postun phase is executed and will remove the binary files. This conditional checks to see if we are actually doing a real uninstall before removing the files.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for that! do we need to change where this script is called to pass the new argument, or is that handled natively by the installer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The system package manager is handling passing the args, yum, rpm, etc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mostlikelee I added some details in the issue #14380

mostlikelee
mostlikelee previously approved these changes Oct 9, 2023
@lucasmrod
Copy link
Member

lucasmrod commented Oct 12, 2023

Have we checked that with deb packages this works the same way? (code is shared for rpm/deb)

@lucasmrod
Copy link
Member

it was causing the accidental deletion of binaries needed for the upgrade.

What binaries were needed for the upgrade? The new package should have all binaries that it needs. Maybe I'm missing some scenario.

Copy link
Member

@lucasmrod lucasmrod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few questions

@edwardsb
Copy link
Contributor Author

it was causing the accidental deletion of binaries needed for the upgrade.

What binaries were needed for the upgrade? The new package should have all binaries that it needs. Maybe I'm missing some scenario.

All of them. The script is run on upgrade and all of the binaries listed in the script are removed.

@edwardsb
Copy link
Contributor Author

Have we checked that with deb packages this works the same way? (code is shared for rpm/deb)

I tested RPM but still need to test DEB.

@lucasmrod
Copy link
Member

All of them. The script is run on upgrade and all of the binaries listed in the script are removed.

Gotcha, but why is that an issue?

@lucasmrod
Copy link
Member

I tested RPM but still need to test DEB.

OK, let me know if you need a hand (I have an Ubuntu VM.)

@edwardsb
Copy link
Contributor Author

All of them. The script is run on upgrade and all of the binaries listed in the script are removed.

Gotcha, but why is that an issue?

Because it runs as the final step of the upgrade, thus removing the files it just got finished upgrading. When the service attempts to start, the files don't exist.

@lucasmrod
Copy link
Member

All of them. The script is run on upgrade and all of the binaries listed in the script are removed.

Gotcha, but why is that an issue?

Because it runs as the final step of the upgrade, thus removing the files it just got finished upgrading. When the service attempts to start, the files don't exist.

Oh! I missed the fact that this is the "post" part.

Thanks for the clarification.

@ksatter
Copy link
Member

ksatter commented Oct 16, 2023

@edwardsb Do you need a hand getting this tested for deb?

@edwardsb
Copy link
Contributor Author

@edwardsb Do you need a hand getting this tested for deb?

Yes please

Copy link
Member

@lucasmrod lucasmrod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

…n during RPM upgrade. The check ensures that files and directories are only removed during a full uninstall ( equals 0), safeguarding necessary files from unintended deletion during an upgrade.
📝 docs(linux_shared.go): add comments to clarify the difference between RPM and Debian uninstallation conditions
@edwardsb edwardsb force-pushed the edwardsb-rpm-upgrades branch from b946591 to 916e2e5 Compare October 27, 2023 04:09
@edwardsb edwardsb temporarily deployed to Docker Hub October 27, 2023 04:09 — with GitHub Actions Inactive
@edwardsb
Copy link
Contributor Author

@lucasmrod when you have a moment can you retest on debian?

@lucasmrod
Copy link
Member

@lucasmrod when you have a moment can you retest on debian?

Works now! (Haven't tested with dnf)

I've tested the following on Ubuntu 22.04:

  • Installing and uninstalling a deb package via sudo dpkg --install fleet-osquery_1.17.0_amd64.deb and sudo apt remove fleet-osquery -y works as expected.
  • Installing sudo dpkg --install fleet-osquery_1.16.0_amd64.deb and then installing sudo dpkg --install fleet-osquery_1.17.0_amd64.deb works as expected.

On my CentOS 7:

  • Installing and uninstalling a rpm package via sudo rpm --install fleet-osquery-1.16.0.x86_64.rpm and sudo yum remove fleet-osquery works as expected.
  • Installing sudo rpm --install fleet-osquery-1.16.0.x86_64.rpm and then installing sudo dpkg --install fleet-osquery-1.17.0.x86_64.rpm doesn't work, probably not supported by rpm (same behavior on main so nothing to do here).

@edwardsb edwardsb merged commit 71709e5 into main Oct 27, 2023
27 checks passed
@edwardsb edwardsb deleted the edwardsb-rpm-upgrades branch October 27, 2023 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants