add swiftDialog to TUF (#11643)

Related to #11534 this is an extract from the code I used to build a
prototype to see if `swiftDialog` would work for us.

This is very similar to the work we did for Nudge previously.
This commit is contained in:
Roberto Dip 2023-05-11 15:01:43 -03:00 committed by GitHub
parent 24389d3e57
commit 4103e77e90
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 54 additions and 0 deletions

1
.gitignore vendored
View file

@ -65,6 +65,7 @@ desktop.app.tar.gz
osqueryd.app.tar.gz
desktop.tar.gz
nudge.app.tar.gz
swiftDialog.app.tar.gz
# residual files when running the cpe command
cmd/cpe/etagenv

View file

@ -360,6 +360,24 @@ endif
tar czf $(out-path)/nudge.app.tar.gz -C $(TMP_DIR)/nudge_pkg_payload_expanded/ Nudge.app
rm -r $(TMP_DIR)
# Generate swiftDialog.app.tar.gz bundle from the swiftDialog repo.
#
# Usage:
# make swift-dialog-app-tar-gz version=2.1.0 build=4148 out-path=.
swift-dialog-app-tar-gz:
ifneq ($(shell uname), Darwin)
@echo "Makefile target swift-dialog-app-tar-gz is only supported on macOS"
@exit 1
endif
$(eval TMP_DIR := $(shell mktemp -d))
curl -L https://github.com/bartreardon/swiftDialog/releases/download/v$(version)/dialog-$(version)-$(build).pkg --output $(TMP_DIR)/swiftDialog-$(version).pkg
pkgutil --expand $(TMP_DIR)/swiftDialog-$(version).pkg $(TMP_DIR)/swiftDialog_pkg_expanded
mkdir -p $(TMP_DIR)/swiftDialog_pkg_payload_expanded
tar xvf $(TMP_DIR)/swiftDialog_pkg_expanded/Payload --directory $(TMP_DIR)/swiftDialog_pkg_payload_expanded
$(TMP_DIR)/swiftDialog_pkg_payload_expanded/usr/local/bin/dialog --version
tar czf $(out-path)/swiftDialog.app.tar.gz -C $(TMP_DIR)/swiftDialog_pkg_payload_expanded/usr/local bin
rm -rf $(TMP_DIR)
# Build and generate desktop.app.tar.gz bundle.
#
# Usage:

View file

@ -44,6 +44,18 @@ func ApplyRenewEnrollmentProfileConfigFetcherMiddleware(fetcher OrbitConfigFetch
// to renew the enrollment profile.
func (h *RenewEnrollmentProfileConfigFetcher) GetConfig() (*fleet.OrbitConfig, error) {
cfg, err := h.Fetcher.GetConfig()
// TODO: download and use swiftDialog following the same patterns we
// use for Nudge.
//
// updaterHasTarget := h.UpdateRunner.HasRunnerOptTarget("swiftDialog")
// runnerHasLocalHash := h.UpdateRunner.HasLocalHash("swiftDialog")
// if !updaterHasTarget || !runnerHasLocalHash {
// log.Info().Msg("refreshing the update runner config with swiftDialog targets and hashes")
// log.Debug().Msgf("updater has target: %t, runner has local hash: %t", updaterHasTarget, runnerHasLocalHash)
// return cfg, h.setTargetsAndHashes()
// }
if err == nil && cfg.Notifications.RenewEnrollmentProfile {
if h.cmdMu.TryLock() {
defer h.cmdMu.Unlock()

View file

@ -88,4 +88,11 @@ var (
TargetFile: "nudge.app.tar.gz",
ExtractedExecSubPath: []string{"Nudge.app", "Contents", "MacOS", "Nudge"},
}
SwiftDialogTarget = TargetInfo{
Platform: "macos",
Channel: "stable",
TargetFile: "swiftDialog.app.tar.gz",
ExtractedExecSubPath: []string{"bin", "dialog"},
}
)

View file

@ -25,6 +25,8 @@ fi
SYSTEMS=${SYSTEMS:-macos linux windows}
NUDGE_VERSION=stable
SWIFT_DIALOG_MACOS_APP_VERSION=2.1.0
SWIFT_DIALOG_MACOS_APP_BUILD_VERSION=4148
if [[ -z "$OSQUERY_VERSION" ]]; then
OSQUERY_VERSION=5.8.1
@ -111,6 +113,20 @@ for system in $SYSTEMS; do
rm nudge.app.tar.gz
fi
# Add swiftDialog on macos (if enabled).
if [[ $system == "macos" && -n "$SWIFT_DIALOG" ]]; then
# For now we always make swiftDialog (until it's uploaded to our TUF repo)
make swift-dialog-app-tar-gz version=$SWIFT_DIALOG_MACOS_APP_VERSION build=$SWIFT_DIALOG_MACOS_APP_BUILD_VERSION out-path=.
./build/fleetctl updates add \
--path $TUF_PATH \
--target swiftDialog.app.tar.gz \
--platform macos \
--name swiftDialog \
--version 42.0.0 -t 42.0 -t 42 -t stable
rm swiftDialog.app.tar.gz
fi
# Add Fleet Desktop application on windows (if enabled).
if [[ $system == "windows" && -n "$FLEET_DESKTOP" ]]; then
FLEET_DESKTOP_VERSION=42.0.0 \