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

release: adding nupkg cpack build option, updating win deployment script #6262

Merged
merged 1 commit into from
May 25, 2020

Conversation

muffins
Copy link
Contributor

@muffins muffins commented Feb 21, 2020

Summary:
This brings the NuGet packaging option to cpack. We can now produce Chocolatey/NuGet packages as well as MSI packages for Windows.

Test Plan:

Clean install of osquery

PS C:\Users\thor\Desktop\osquery_release_bins\4.2.0> choco install -yf osquery -s . --version 4.2.0 --params='/InstallService'
Chocolatey v0.10.15
Installing the following packages:
osquery
By installing you accept licenses for the packages.

osquery v4.2.0 (forced)
osquery package files install completed. Performing other installation steps.
C:\Program Files\osquery\log
True
osqueryd
PATH environment variable does not have C:\Program Files\osquery in it. Adding...
Environment Vars (like PATH) have changed. Close/reopen your shell to
 see the changes (or in powershell/cmd.exe just type `refreshenv`).
 ShimGen has successfully created a shim for osqueryi.exe
 ShimGen has successfully created a shim for osqueryd.exe
 The install of osquery was successful.
  Software install location not explicitly set, could be in package or
  default install location if installer.

Chocolatey installed 1/1 packages.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

PS C:\Users\thor\Desktop\osquery_release_bins\4.2.0> get-service osqueryd

Status   Name               DisplayName
------   ----               -----------
Running  osqueryd           osqueryd

PS C:\Users\thor\Desktop\osquery_release_bins\4.2.0> ls 'C:\Program Files\osquery\log\'


    Directory: C:\Program Files\osquery\log


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        2/20/2020  10:00 PM            287 osqueryd.INFO.20200220-220024.20600
-a----        2/20/2020  10:00 PM              0 osqueryd.results.log

Upgrade of osquery, installation from upstream choco latest stable version

PS C:\Users\thor\Desktop\osquery_release_bins\4.2.0> choco upgrade -yf -s . osquery --version 4.2.0
Chocolatey v0.10.15
Upgrading the following packages:
osquery
By upgrading you accept licenses for the packages.

You have osquery v4.0.2 installed. Version 4.2.0 is available based on your source(s).
True
True

osquery v4.2.0 (forced)
osquery package files upgrade completed. Performing other installation steps.
True
True
C:\Program Files\osquery\log
True
True
True
True
Environment Vars (like PATH) have changed. Close/reopen your shell to
 see the changes (or in powershell/cmd.exe just type `refreshenv`).
 ShimGen has successfully created a shim for osqueryi.exe
 ShimGen has successfully created a shim for osqueryd.exe
 The upgrade of osquery was successful.
  Software install location not explicitly set, could be in package or
  default install location if installer.

Chocolatey upgraded 1/1 packages.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

PS C:\Users\thor\Desktop\osquery_release_bins\4.2.0> Get-Service osqueryd

Status   Name               DisplayName
------   ----               -----------
Running  osqueryd           osqueryd

PS C:\Users\thor\Desktop\osquery_release_bins\4.2.0> ls 'C:\Program Files\osquery\log\'


    Directory: C:\Program Files\osquery\log


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        2/20/2020  10:11 PM            287 osqueryd.INFO.20200220-221131.16872
-a----        2/20/2020  10:10 PM              0 osqueryd.results.log

Uninstalling osquery from system:

PS C:\Users\thor\Desktop\osquery_release_bins\4.2.0> choco uninstall -yf osquery
Chocolatey v0.10.15
Uninstalling the following packages:
osquery
True
True

osquery v4.2.0 (forced)
@{ReturnValue=0; PSComputerName=}
 Skipping auto uninstaller - No registry snapshot.
 osquery has been successfully uninstalled.
Environment Vars (like PATH) have changed. Close/reopen your shell to
 see the changes (or in powershell/cmd.exe just type `refreshenv`).

Chocolatey uninstalled 1/1 packages.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

@muffins
Copy link
Contributor Author

muffins commented Feb 21, 2020

I'm going to follow-up this PR with some documentation on how to build this package.

@muffins
Copy link
Contributor Author

muffins commented Feb 22, 2020

This addresses #6248

- Check that the file hash of the osqueryd.exe binary is correct:
```
PS C:\\Users\\thor> (Get-FileHash -Algorithm sha256 'C:\\Program Files\\osquery\\osqueryd\\osqueryd.exe').Hash
<Fill in with osqueryd.exe Sha256 before publishing to Chocolatey>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't really like doing it like this, but I'm not sure howe to get the file digest of the osqueryd.exe binary before cpack is invoked. Right now we already need to manually swap out the binaries with the signed versions before calling cpack anyway, so I'm going to say we just manually update the verification.txt, unless someone smarter than I in cmake can tell me how to get the sha256 of osqueryd.exe at this point :)

Copy link
Member

@Smjert Smjert Feb 25, 2020

Choose a reason for hiding this comment

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

You can add a custom command that runs after the build of a target, check this https://cmake.org/cmake/help/v3.16/command/add_custom_command.html and POST_BUILD.

EDIT: It's important to note though that this will run only if the target has not already been built, so for instance if you have a case where this has to be run always before packaging (but on the result of a target), and a previous saved value/result is not correct, this won't work.
If though is possible to create some dependency on some file which if it's not there, then the command has to be launched, then you can use a normal custom command that depends on such file and that runs each time it's missing.
There are also some other ways, depending on the specific behavior you want to obtain.

@muffins muffins force-pushed the cpack-nupkg-release branch 2 times, most recently from aed6295 to a4d0054 Compare February 26, 2020 00:03
file(COPY "${CMAKE_SOURCE_DIR}/tools/wel/osquery.man" DESTINATION "${CMAKE_BINARY_DIR}/package/wix")
install(FILES "${CMAKE_BINARY_DIR}/package/wix/osquery.man" DESTINATION .)
file(WRITE "${CMAKE_BINARY_DIR}/package/${win_packager}/VERIFICATION.txt" "
VERIFICATION
Copy link
Member

Choose a reason for hiding this comment

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

Can you put this file into ./tools (into an appropriate sub folder) and then copy it similar to how CMake is copying other files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could, the issue I was originally having, and why this is here, is I wanted to grab the hashes of the built binaries and have them be included in this file. For now I'll just remove the pre-computed hashes and maybe that can be a follow-up for us, as I don't think it's required.

@directionless
Copy link
Member

Where did we leave this?

@muffins
Copy link
Contributor Author

muffins commented Mar 19, 2020

@directionless thanks for the ping! I didn't have a huge amount of time to get things fixed up, I think there's one or two more small bits that need addressing, I'll take another look tonight but I believe we could get this shipped and maybe cut a follow-up PR/Issue to track the additional bits that might need doing.

@muffins muffins force-pushed the cpack-nupkg-release branch 3 times, most recently from e2bd231 to 056af4b Compare March 20, 2020 18:20
@muffins
Copy link
Contributor Author

muffins commented May 8, 2020

I believe all of the issues with this have been addressed. Any chance I could get another review and we could get this shipped? I'm VERY behind on shipping the osquery 4.3.0 chocolatey packages, and having this landed upstream would be extremely useful for anyone else wishing to build choco packages. Sorry for my delays y'all!

@theopolis theopolis merged commit d1feab7 into osquery:master May 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants