Use symlink for current orbit binary

This commit is contained in:
Zach Wasserman 2021-03-02 11:24:32 -08:00
parent 643201a8ef
commit bc39118883
6 changed files with 35 additions and 16 deletions

View file

@ -94,6 +94,10 @@ func main() {
}
}
// TODO take these from flags
opt.OrbitChannel = "stable"
opt.OsqueryChannel = "stable"
switch c.String("type") {
case "pkg":
return packaging.BuildPkg(opt)

View file

@ -40,12 +40,13 @@ func BuildDeb(opt Options) error {
updateOpt := update.DefaultOptions
updateOpt.Platform = "linux"
updateOpt.RootDirectory = orbitRoot
updateOpt.OrbitChannel = opt.OrbitChannel
updateOpt.OsqueryChannel = opt.OsqueryChannel
// TODO these should be configurable
updateOpt.ServerURL = "https://tuf.fleetctl.com"
osqueryChannel, orbitChannel := "stable", "stable"
if err := initializeUpdates(updateOpt, osqueryChannel, orbitChannel); err != nil {
if err := initializeUpdates(updateOpt); err != nil {
return errors.Wrap(err, "initialize updates")
}

View file

@ -43,12 +43,13 @@ func BuildPkg(opt Options) error {
updateOpt := update.DefaultOptions
updateOpt.Platform = "macos"
updateOpt.RootDirectory = orbitRoot
updateOpt.OrbitChannel = opt.OrbitChannel
updateOpt.OsqueryChannel = opt.OsqueryChannel
// TODO these should be configurable
updateOpt.ServerURL = "https://tuf.fleetctl.com"
osqueryChannel, orbitChannel := "stable", "stable"
if err := initializeUpdates(updateOpt, osqueryChannel, orbitChannel); err != nil {
if err := initializeUpdates(updateOpt); err != nil {
return errors.Wrap(err, "initialize updates")
}
@ -76,13 +77,15 @@ func BuildPkg(opt Options) error {
return errors.Wrap(err, "write fleet certificate")
}
}
if err := copyFile(
"./orbit",
filepath.Join(orbitRoot, "bin", "orbit", "macos", "current", "orbit"),
0755,
); err != nil {
return errors.Wrap(err, "write orbit")
}
// TODO gate behind a flag and allow copying a local orbit
// if err := copyFile(
// "./orbit",
// filepath.Join(orbitRoot, "bin", "orbit", "macos", "current", "orbit"),
// 0755,
// ); err != nil {
// return errors.Wrap(err, "write orbit")
// }
// Build package
if err := xarBom(opt, tmpDir); err != nil {

View file

@ -33,7 +33,8 @@ var macosDistributionTemplate = template.Must(template.New("").Option("missingke
var macosPostinstallTemplate = template.Must(template.New("").Option("missingkey=error").Parse(
`#!/bin/bash
ln -sf /var/lib/orbit/orbit /usr/local/bin/orbit
ln -sf /var/lib/orbit/bin/orbit/macos/{{.OrbitChannel}}/orbit /var/lib/orbit/bin/orbit/orbit
ln -sf /var/lib/orbit/bin/orbit/orbit /usr/local/bin/orbit
{{ if .StartService -}}
launchctl stop com.fleetdm.orbit
@ -60,7 +61,7 @@ var macosLaunchdTemplate = template.Must(template.New("").Option("missingkey=err
<string>com.fleetdm.orbit</string>
<key>ProgramArguments</key>
<array>
<string>/var/lib/orbit/bin/orbit/macos/current/orbit</string>
<string>/var/lib/orbit/bin/orbit/orbit</string>
</array>
<key>StandardOutPath</key>
<string>/var/log/orbit/orbit.stdout.log</string>

View file

@ -34,6 +34,10 @@ type Options struct {
Notarize bool
// FleetCertificate is a path to a server certificate to include in the package.
FleetCertificate string
// OrbitChannel is the update channel to use for Orbit.
OrbitChannel string
// OsqueryChannel is the update channel to use for Osquery.
OsqueryChannel string
}
func copyFile(srcPath, dstPath string, perm os.FileMode) error {
@ -60,7 +64,7 @@ func copyFile(srcPath, dstPath string, perm os.FileMode) error {
return nil
}
func initializeUpdates(updateOpt update.Options, osqueryChannel, orbitChannel string) error {
func initializeUpdates(updateOpt update.Options) error {
localStore, err := filestore.New(filepath.Join(updateOpt.RootDirectory, "tuf-metadata.json"))
if err != nil {
return errors.Wrap(err, "failed to create local metadata store")
@ -74,13 +78,13 @@ func initializeUpdates(updateOpt update.Options, osqueryChannel, orbitChannel st
if err := updater.UpdateMetadata(); err != nil {
return errors.Wrap(err, "failed to update metadata")
}
osquerydPath, err := updater.Get("osqueryd", osqueryChannel)
osquerydPath, err := updater.Get("osqueryd", updateOpt.OsqueryChannel)
if err != nil {
return errors.Wrap(err, "failed to get osqueryd")
}
log.Debug().Str("path", osquerydPath).Msg("got osqueryd")
orbitPath, err := updater.Get("orbit", orbitChannel)
orbitPath, err := updater.Get("orbit", updateOpt.OrbitChannel)
if err != nil {
return errors.Wrap(err, "failed to get orbit")
}

View file

@ -46,6 +46,10 @@ type Options struct {
// Platform is the target of the platform to update for. In the default
// options this is the current platform.
Platform string
// OrbitChannel is the update channel to use for Orbit.
OrbitChannel string
// OsqueryChannel is the update channel to use for Osquery.
OsqueryChannel string
}
var (
@ -58,6 +62,8 @@ var (
InsecureTransport: false,
Platform: constant.PlatformName,
RootKeys: defaultRootKeys,
OrbitChannel: "stable",
OsqueryChannel: "stable",
}
)