2021-09-09 05:34:12 +00:00
|
|
|
// Package packaging provides tools for building Orbit installation packages.
|
2022-07-25 23:14:20 +00:00
|
|
|
//
|
|
|
|
|
// The functions exported by this package are not safe for concurrent use at
|
|
|
|
|
// the moment.
|
2021-02-08 23:55:36 +00:00
|
|
|
package packaging
|
|
|
|
|
|
2021-02-17 02:05:18 +00:00
|
|
|
import (
|
2021-11-19 01:17:05 +00:00
|
|
|
_ "embed"
|
2022-01-31 13:41:11 +00:00
|
|
|
"encoding/json"
|
2021-11-22 14:13:26 +00:00
|
|
|
"fmt"
|
2021-02-17 02:05:18 +00:00
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
2022-04-11 20:42:36 +00:00
|
|
|
"time"
|
2021-02-17 02:05:18 +00:00
|
|
|
|
2021-08-11 14:02:22 +00:00
|
|
|
"github.com/fleetdm/fleet/v4/orbit/pkg/constant"
|
|
|
|
|
"github.com/fleetdm/fleet/v4/orbit/pkg/update"
|
|
|
|
|
"github.com/fleetdm/fleet/v4/orbit/pkg/update/filestore"
|
2021-11-18 23:06:33 +00:00
|
|
|
"github.com/fleetdm/fleet/v4/pkg/file"
|
2021-08-24 12:50:03 +00:00
|
|
|
"github.com/fleetdm/fleet/v4/pkg/secure"
|
2021-02-25 20:38:21 +00:00
|
|
|
"github.com/rs/zerolog/log"
|
2021-02-17 02:05:18 +00:00
|
|
|
)
|
|
|
|
|
|
2021-02-08 23:55:36 +00:00
|
|
|
// Options are the configurable options provided for the package.
|
|
|
|
|
type Options struct {
|
|
|
|
|
// FleetURL is the URL to the Fleet server.
|
|
|
|
|
FleetURL string
|
|
|
|
|
// EnrollSecret is the enroll secret used to authenticate to the Fleet
|
|
|
|
|
// server.
|
|
|
|
|
EnrollSecret string
|
2021-02-09 03:23:50 +00:00
|
|
|
// Version is the version number for this package.
|
|
|
|
|
Version string
|
|
|
|
|
// Identifier is the identifier (eg. com.fleetdm.orbit) for the package product.
|
|
|
|
|
Identifier string
|
2021-02-08 23:55:36 +00:00
|
|
|
// StartService is a boolean indicating whether to start a system-specific
|
|
|
|
|
// background service.
|
|
|
|
|
StartService bool
|
|
|
|
|
// Insecure enables insecure TLS connections for the generated package.
|
|
|
|
|
Insecure bool
|
2021-02-17 21:25:56 +00:00
|
|
|
// SignIdentity is the codesigning identity to use (only macOS at this time)
|
|
|
|
|
SignIdentity string
|
2021-02-18 00:22:03 +00:00
|
|
|
// Notarize sets whether macOS packages should be Notarized.
|
|
|
|
|
Notarize bool
|
2023-04-27 11:44:39 +00:00
|
|
|
// FleetCertificate is a file path to a Fleet server certificate to include in the package.
|
2021-02-25 20:38:21 +00:00
|
|
|
FleetCertificate string
|
2023-04-27 11:44:39 +00:00
|
|
|
// FleetTLSClientCertificate is a file path to a client certificate to use when
|
|
|
|
|
// connecting to the Fleet server.
|
|
|
|
|
//
|
|
|
|
|
// If set, then FleetTLSClientKey must be set too.
|
|
|
|
|
FleetTLSClientCertificate string
|
|
|
|
|
// FleetTLSClientKey is a file path to a client private key to use when
|
|
|
|
|
// connecting to the Fleet server.
|
|
|
|
|
//
|
|
|
|
|
// If set, then FleetTLSClientCertificate must be set too.
|
|
|
|
|
FleetTLSClientKey string
|
|
|
|
|
// FleetDesktopAlternativeBrowserHost is an alternative host:port to use for Fleet Desktop in the browser.
|
|
|
|
|
//
|
|
|
|
|
// This may be required when using TLS client authentication for connecting to Fleet via a proxy.
|
|
|
|
|
// Otherwise users would need to configure client certificates on their browsers.
|
|
|
|
|
//
|
|
|
|
|
// If not set, then FleetURL is used instead.
|
|
|
|
|
FleetDesktopAlternativeBrowserHost string
|
2022-02-18 18:42:39 +00:00
|
|
|
// DisableUpdates disables auto updates on the generated package.
|
|
|
|
|
DisableUpdates bool
|
2021-03-02 19:24:32 +00:00
|
|
|
// OrbitChannel is the update channel to use for Orbit.
|
|
|
|
|
OrbitChannel string
|
2021-03-10 00:27:35 +00:00
|
|
|
// OsquerydChannel is the update channel to use for Osquery (osqueryd).
|
|
|
|
|
OsquerydChannel string
|
2022-03-21 17:53:53 +00:00
|
|
|
// DesktopChannel is the update channel to use for the Fleet Desktop application.
|
|
|
|
|
DesktopChannel string
|
2021-03-10 22:42:02 +00:00
|
|
|
// UpdateURL is the base URL of the update server (TUF repository).
|
|
|
|
|
UpdateURL string
|
2021-03-23 00:38:32 +00:00
|
|
|
// UpdateRoots is the root JSON metadata for update server (TUF repository).
|
|
|
|
|
UpdateRoots string
|
2023-04-27 11:44:39 +00:00
|
|
|
// UpdateTLSServerCertificate is a file path to an update server certificate to include in the package.
|
|
|
|
|
UpdateTLSServerCertificate string
|
|
|
|
|
// UpdateTLSClientCertificate is a file path to a client certificate to use when
|
|
|
|
|
// connecting to the update server.
|
|
|
|
|
//
|
|
|
|
|
// If set, then UpdateTLSClientKey must be set too.
|
|
|
|
|
UpdateTLSClientCertificate string
|
|
|
|
|
// UpdateTLSClientKey is a file path to a client private key to use when
|
|
|
|
|
// connecting to the update server.
|
|
|
|
|
//
|
|
|
|
|
// If set, then UpdateTLSClientCertificate must be set too.
|
|
|
|
|
UpdateTLSClientKey string
|
2021-11-18 23:06:33 +00:00
|
|
|
// OsqueryFlagfile is the (optional) path to a flagfile to provide to osquery.
|
|
|
|
|
OsqueryFlagfile string
|
2021-03-09 23:22:17 +00:00
|
|
|
// Debug determines whether to enable debug logging for the agent.
|
|
|
|
|
Debug bool
|
2022-03-21 17:53:53 +00:00
|
|
|
// Desktop determines whether to package the Fleet Desktop application.
|
|
|
|
|
Desktop bool
|
2022-04-11 20:42:36 +00:00
|
|
|
// OrbitUpdateInterval is the interval that Orbit will use to check for updates.
|
|
|
|
|
OrbitUpdateInterval time.Duration
|
2022-05-03 19:46:02 +00:00
|
|
|
// LegacyVarLibSymlink indicates whether Orbit is legacy (< 0.0.11),
|
|
|
|
|
// which assumes it is installed under /var/lib.
|
|
|
|
|
LegacyVarLibSymlink bool
|
2022-07-11 12:49:13 +00:00
|
|
|
// Native tooling is used to determine if the package should be built
|
|
|
|
|
// natively instead of via Docker images.
|
|
|
|
|
NativeTooling bool
|
2022-07-25 23:06:10 +00:00
|
|
|
// MacOSDevIDCertificateContent is a string containing a PEM keypair used to
|
|
|
|
|
// sign a macOS package via NativeTooling
|
|
|
|
|
MacOSDevIDCertificateContent string
|
|
|
|
|
// AppStoreConnectAPIKeyID is the Appstore Connect API key provided by Apple
|
|
|
|
|
AppStoreConnectAPIKeyID string
|
|
|
|
|
// AppStoreConnectAPIKeyIssuer is the issuer of App Store API Key
|
|
|
|
|
AppStoreConnectAPIKeyIssuer string
|
|
|
|
|
// AppStoreConnectAPIKeyContent is the content of the App Store API Key
|
|
|
|
|
AppStoreConnectAPIKeyContent string
|
2023-04-05 18:02:18 +00:00
|
|
|
// UseSystemConfiguration tells fleetd to try to read FleetURL and
|
|
|
|
|
// EnrollSecret from a system configuration that's present on the host.
|
|
|
|
|
// Currently only macOS profiles are supported.
|
|
|
|
|
UseSystemConfiguration bool
|
2023-08-30 13:18:34 +00:00
|
|
|
// EnableScripts enables script execution on the agent.
|
|
|
|
|
EnableScripts bool
|
2023-09-22 15:49:01 +00:00
|
|
|
// LocalWixDir uses a Windows machine's local WiX installation instead of a containerized
|
|
|
|
|
// emulation to build an MSI fleetd installer
|
|
|
|
|
LocalWixDir string
|
2023-12-15 18:26:32 +00:00
|
|
|
// HostIdentifier is the host identifier to use in osquery.
|
|
|
|
|
HostIdentifier string
|
2024-07-01 15:49:59 +00:00
|
|
|
// EnableHostIdentifierProperty is a boolean indicating whether to enable END_USER_EMAIL property in Windows MSI package.
|
|
|
|
|
EnableEndUserEmailProperty bool
|
2023-12-21 17:22:59 +00:00
|
|
|
// EndUserEmail is the email address of the end user that uses the host on
|
|
|
|
|
// which the agent is going to be installed.
|
|
|
|
|
EndUserEmail string
|
2024-01-16 12:51:37 +00:00
|
|
|
// DisableKeystore disables the use of the keychain on macOS and Credentials Manager on Windows
|
|
|
|
|
DisableKeystore bool
|
2024-02-05 12:41:06 +00:00
|
|
|
// OsqueryDB is the directory to use for the osquery database.
|
|
|
|
|
// If not set, then the default is `$ORBIT_ROOT_DIR/osquery.db`.
|
|
|
|
|
OsqueryDB string
|
2024-07-17 20:07:59 +00:00
|
|
|
// Architecture that the package is being built for. (amd64, arm64)
|
|
|
|
|
Architecture string
|
2025-04-11 14:18:28 +00:00
|
|
|
// TUF platform name. windows, windows-arm64, linux, linux-arm64, darwin
|
|
|
|
|
NativePlatform string
|
Adding optional parameter outfile to fleetctl package (#29579)
Fixes #29581
# Checklist for submitter
If some of the following don't apply, delete the relevant line.
<!-- Note that API documentation changes are now addressed by the
product design team. -->
- [ ] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files)
for more information.
- [ ] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)
- [ ] Added support on fleet's osquery simulator `cmd/osquery-perf` for
new osquery data ingestion features.
- [ ] If paths of existing endpoints are modified without backwards
compatibility, checked the frontend/CLI for any necessary changes
- [ ] If database migrations are included, checked table schema to
confirm autoupdate
- For new Fleet configuration settings
- [ ] Verified that the setting can be managed via GitOps, or confirmed
that the setting is explicitly being excluded from GitOps. If managing
via Gitops:
- [ ] Verified that the setting is exported via `fleetctl
generate-gitops`
- [ ] Added the setting to [the GitOps
documentation](https://github.com/fleetdm/fleet/blob/main/docs/Configuration/yaml-files.md#L485)
- [ ] Verified that the setting is cleared on the server if it is not
supplied in a YAML file (or that it is documented as being optional)
- [ ] Verified that any relevant UI is disabled when GitOps mode is
enabled
- For database migrations:
- [ ] Checked schema for all modified table for columns that will
auto-update timestamps during migration.
- [ ] Confirmed that updating the timestamps is acceptable, and will not
cause unwanted side effects.
- [ ] Ensured the correct collation is explicitly set for character
columns (`COLLATE utf8mb4_unicode_ci`).
- [ ] Added/updated automated tests
- [ ] Manual QA for all new/changed functionality
- For Orbit and Fleet Desktop changes:
- [ ] Make sure fleetd is compatible with the latest released version of
Fleet (see [Must
rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md)).
- [ ] Orbit runs on macOS, Linux and Windows. Check if the orbit
feature/bugfix should only apply to one platform (`runtime.GOOS`).
- [ ] Manual QA must be performed in the three main OSs, macOS, Windows
and Linux.
- [ ] Auto-update manual QA, from released version of component to new
version (see [tools/tuf/test](../tools/tuf/test/README.md)).
- [ ] For unreleased bug fixes in a release candidate, confirmed that
the fix is not expected to adversely impact load test results or alerted
the release DRI if additional load testing is needed.
2025-06-12 15:25:40 +00:00
|
|
|
// CustomOutfile is the custom output file name for the package.
|
|
|
|
|
CustomOutfile string
|
2025-07-23 17:30:44 +00:00
|
|
|
// FleetManagedHostIdentityCertificate configures fleetd to use TPM-backed key to sign HTTP requests.
|
|
|
|
|
FleetManagedHostIdentityCertificate bool
|
2021-02-08 23:55:36 +00:00
|
|
|
}
|
2021-02-17 02:05:18 +00:00
|
|
|
|
2024-07-17 20:07:59 +00:00
|
|
|
const (
|
|
|
|
|
ArchAmd64 string = "amd64"
|
|
|
|
|
ArchArm64 string = "arm64"
|
|
|
|
|
)
|
|
|
|
|
|
2021-10-27 23:17:41 +00:00
|
|
|
func initializeTempDir() (string, error) {
|
|
|
|
|
// Initialize directories
|
2023-10-27 18:28:54 +00:00
|
|
|
tmpDir, err := os.MkdirTemp("", "orbit-package")
|
2021-10-27 23:17:41 +00:00
|
|
|
if err != nil {
|
2021-11-22 14:13:26 +00:00
|
|
|
return "", fmt.Errorf("failed to create temp dir: %w", err)
|
2021-10-27 23:17:41 +00:00
|
|
|
}
|
|
|
|
|
|
2022-03-21 17:53:53 +00:00
|
|
|
if err := os.Chmod(tmpDir, 0o755); err != nil {
|
2021-10-27 23:17:41 +00:00
|
|
|
_ = os.RemoveAll(tmpDir)
|
2021-11-22 14:13:26 +00:00
|
|
|
return "", fmt.Errorf("change temp directory permissions: %w", err)
|
2021-10-27 23:17:41 +00:00
|
|
|
}
|
|
|
|
|
log.Debug().Str("path", tmpDir).Msg("created temp directory")
|
|
|
|
|
|
|
|
|
|
return tmpDir, nil
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-31 13:41:11 +00:00
|
|
|
type UpdatesData struct {
|
|
|
|
|
OrbitPath string
|
|
|
|
|
OrbitVersion string
|
|
|
|
|
|
|
|
|
|
OsquerydPath string
|
|
|
|
|
OsquerydVersion string
|
2022-03-21 17:53:53 +00:00
|
|
|
|
|
|
|
|
DesktopPath string
|
|
|
|
|
DesktopVersion string
|
2022-01-31 13:41:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (u UpdatesData) String() string {
|
|
|
|
|
return fmt.Sprintf(
|
|
|
|
|
"orbit={%s,%s}, osqueryd={%s,%s}",
|
|
|
|
|
u.OrbitPath, u.OrbitVersion,
|
|
|
|
|
u.OsquerydPath, u.OsquerydVersion,
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func InitializeUpdates(updateOpt update.Options) (*UpdatesData, error) {
|
2025-01-10 17:27:30 +00:00
|
|
|
localStore, err := filestore.New(filepath.Join(updateOpt.RootDirectory, update.MetadataFileName))
|
2021-02-25 20:38:21 +00:00
|
|
|
if err != nil {
|
2022-01-31 13:41:11 +00:00
|
|
|
return nil, fmt.Errorf("failed to create local metadata store: %w", err)
|
2021-02-25 20:38:21 +00:00
|
|
|
}
|
|
|
|
|
updateOpt.LocalStore = localStore
|
|
|
|
|
|
2022-06-01 17:47:04 +00:00
|
|
|
updater, err := update.NewUpdater(updateOpt)
|
2021-02-25 20:38:21 +00:00
|
|
|
if err != nil {
|
2022-01-31 13:41:11 +00:00
|
|
|
return nil, fmt.Errorf("failed to init updater: %w", err)
|
2021-02-25 20:38:21 +00:00
|
|
|
}
|
|
|
|
|
if err := updater.UpdateMetadata(); err != nil {
|
2022-01-31 13:41:11 +00:00
|
|
|
return nil, fmt.Errorf("failed to update metadata: %w", err)
|
2021-02-25 20:38:21 +00:00
|
|
|
}
|
2022-03-21 17:53:53 +00:00
|
|
|
|
2024-10-28 23:40:19 +00:00
|
|
|
osquerydLocalTarget, err := updater.Get(constant.OsqueryTUFTargetName)
|
2021-02-25 20:38:21 +00:00
|
|
|
if err != nil {
|
2024-10-28 23:40:19 +00:00
|
|
|
return nil, fmt.Errorf("failed to get %s: %w", constant.OsqueryTUFTargetName, err)
|
2022-01-31 13:41:11 +00:00
|
|
|
}
|
2022-03-21 17:53:53 +00:00
|
|
|
osquerydPath := osquerydLocalTarget.ExecPath
|
2024-10-28 23:40:19 +00:00
|
|
|
osquerydMeta, err := updater.Lookup(constant.OsqueryTUFTargetName)
|
2022-01-31 13:41:11 +00:00
|
|
|
if err != nil {
|
2024-10-28 23:40:19 +00:00
|
|
|
return nil, fmt.Errorf("failed to get %s metadata: %w", constant.OsqueryTUFTargetName, err)
|
2022-01-31 13:41:11 +00:00
|
|
|
}
|
|
|
|
|
type custom struct {
|
|
|
|
|
Version string `json:"version"`
|
|
|
|
|
}
|
|
|
|
|
var osquerydCustom custom
|
|
|
|
|
if err := json.Unmarshal(*osquerydMeta.Custom, &osquerydCustom); err != nil {
|
2024-10-28 23:40:19 +00:00
|
|
|
return nil, fmt.Errorf("failed to get %s version: %w", constant.OsqueryTUFTargetName, err)
|
2021-02-25 20:38:21 +00:00
|
|
|
}
|
2022-03-21 17:53:53 +00:00
|
|
|
|
2024-10-28 23:40:19 +00:00
|
|
|
orbitLocalTarget, err := updater.Get(constant.OrbitTUFTargetName)
|
2021-02-25 20:38:21 +00:00
|
|
|
if err != nil {
|
2024-10-28 23:40:19 +00:00
|
|
|
return nil, fmt.Errorf("failed to get %s: %w", constant.OrbitTUFTargetName, err)
|
2022-01-31 13:41:11 +00:00
|
|
|
}
|
2022-03-21 17:53:53 +00:00
|
|
|
orbitPath := orbitLocalTarget.ExecPath
|
2024-10-28 23:40:19 +00:00
|
|
|
orbitMeta, err := updater.Lookup(constant.OrbitTUFTargetName)
|
2022-01-31 13:41:11 +00:00
|
|
|
if err != nil {
|
2024-10-28 23:40:19 +00:00
|
|
|
return nil, fmt.Errorf("failed to get %s metadata: %w", constant.OrbitTUFTargetName, err)
|
2022-01-31 13:41:11 +00:00
|
|
|
}
|
|
|
|
|
var orbitCustom custom
|
|
|
|
|
if err := json.Unmarshal(*orbitMeta.Custom, &orbitCustom); err != nil {
|
2024-10-28 23:40:19 +00:00
|
|
|
return nil, fmt.Errorf("failed to get %s version: %w", constant.OrbitTUFTargetName, err)
|
2021-02-25 20:38:21 +00:00
|
|
|
}
|
|
|
|
|
|
2022-03-21 17:53:53 +00:00
|
|
|
var (
|
|
|
|
|
desktopPath string
|
|
|
|
|
desktopCustom custom
|
|
|
|
|
)
|
2024-10-28 23:40:19 +00:00
|
|
|
if _, ok := updateOpt.Targets[constant.DesktopTUFTargetName]; ok {
|
|
|
|
|
desktopLocalTarget, err := updater.Get(constant.DesktopTUFTargetName)
|
2022-03-21 17:53:53 +00:00
|
|
|
if err != nil {
|
2024-10-28 23:40:19 +00:00
|
|
|
return nil, fmt.Errorf("failed to get %s: %w", constant.DesktopTUFTargetName, err)
|
2022-03-21 17:53:53 +00:00
|
|
|
}
|
|
|
|
|
desktopPath = desktopLocalTarget.ExecPath
|
2024-10-28 23:40:19 +00:00
|
|
|
desktopMeta, err := updater.Lookup(constant.DesktopTUFTargetName)
|
2022-03-21 17:53:53 +00:00
|
|
|
if err != nil {
|
2024-10-28 23:40:19 +00:00
|
|
|
return nil, fmt.Errorf("failed to get %s metadata: %w", constant.DesktopTUFTargetName, err)
|
2022-03-21 17:53:53 +00:00
|
|
|
}
|
|
|
|
|
if err := json.Unmarshal(*desktopMeta.Custom, &desktopCustom); err != nil {
|
2024-10-28 23:40:19 +00:00
|
|
|
return nil, fmt.Errorf("failed to get %s version: %w", constant.DesktopTUFTargetName, err)
|
2022-03-21 17:53:53 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-10 17:27:30 +00:00
|
|
|
// Copy the new metadata file to the old location (pre-migration) to
|
|
|
|
|
// support orbit downgrades to 1.37.0 or lower.
|
|
|
|
|
//
|
|
|
|
|
// Once https://tuf.fleetctl.com is brought down (which means downgrades to 1.37.0 or
|
|
|
|
|
// lower won't be possible), we can remove this copy.
|
|
|
|
|
oldMetadataPath := filepath.Join(updateOpt.RootDirectory, update.OldMetadataFileName)
|
|
|
|
|
newMetadataPath := filepath.Join(updateOpt.RootDirectory, update.MetadataFileName)
|
|
|
|
|
if err := file.Copy(newMetadataPath, oldMetadataPath, constant.DefaultFileMode); err != nil {
|
|
|
|
|
return nil, fmt.Errorf("failed to create %s copy: %w", oldMetadataPath, err)
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-31 13:41:11 +00:00
|
|
|
return &UpdatesData{
|
|
|
|
|
OrbitPath: orbitPath,
|
|
|
|
|
OrbitVersion: orbitCustom.Version,
|
|
|
|
|
|
|
|
|
|
OsquerydPath: osquerydPath,
|
|
|
|
|
OsquerydVersion: osquerydCustom.Version,
|
2022-03-21 17:53:53 +00:00
|
|
|
|
|
|
|
|
DesktopPath: desktopPath,
|
|
|
|
|
DesktopVersion: desktopCustom.Version,
|
2022-01-31 13:41:11 +00:00
|
|
|
}, nil
|
2021-02-25 20:38:21 +00:00
|
|
|
}
|
2021-04-17 18:52:37 +00:00
|
|
|
|
2023-04-07 22:34:16 +00:00
|
|
|
// writeSecret writes the orbit enroll secret to the designated file.
|
|
|
|
|
//
|
|
|
|
|
// This implementation is very similar to the one in orbit/cmd/orbit but
|
|
|
|
|
// intentionally kept separate to prevent issues since the writes happen at two
|
|
|
|
|
// completely different circumstances.
|
2021-04-17 18:52:37 +00:00
|
|
|
func writeSecret(opt Options, orbitRoot string) error {
|
2023-04-07 22:34:16 +00:00
|
|
|
path := filepath.Join(orbitRoot, constant.OsqueryEnrollSecretFileName)
|
2021-08-11 14:02:22 +00:00
|
|
|
if err := secure.MkdirAll(filepath.Dir(path), constant.DefaultDirMode); err != nil {
|
2021-11-22 14:13:26 +00:00
|
|
|
return fmt.Errorf("mkdir: %w", err)
|
2021-04-17 18:52:37 +00:00
|
|
|
}
|
|
|
|
|
|
2022-05-02 18:18:59 +00:00
|
|
|
if err := os.WriteFile(path, []byte(opt.EnrollSecret), constant.DefaultFileMode); err != nil {
|
2021-11-22 14:13:26 +00:00
|
|
|
return fmt.Errorf("write file: %w", err)
|
2021-04-17 18:52:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2021-11-18 23:06:33 +00:00
|
|
|
|
|
|
|
|
func writeOsqueryFlagfile(opt Options, orbitRoot string) error {
|
2022-05-02 18:18:59 +00:00
|
|
|
path := filepath.Join(orbitRoot, "osquery.flags")
|
2021-11-18 23:06:33 +00:00
|
|
|
|
|
|
|
|
if opt.OsqueryFlagfile == "" {
|
|
|
|
|
// Write empty flagfile
|
2022-05-02 18:18:59 +00:00
|
|
|
if err := os.WriteFile(path, []byte(""), constant.DefaultFileMode); err != nil {
|
2021-11-22 14:13:26 +00:00
|
|
|
return fmt.Errorf("write empty flagfile: %w", err)
|
2021-11-18 23:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-02 18:18:59 +00:00
|
|
|
if err := file.Copy(opt.OsqueryFlagfile, path, constant.DefaultFileMode); err != nil {
|
2021-11-22 14:13:26 +00:00
|
|
|
return fmt.Errorf("copy flagfile: %w", err)
|
2021-11-18 23:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
2021-11-19 01:17:05 +00:00
|
|
|
|
|
|
|
|
// Embed the certs file that osquery uses so that we can drop it into our installation packages.
|
2024-07-09 17:04:23 +00:00
|
|
|
// This file is generated and updated by .github/workflows/update-certs.yml.
|
2022-09-12 23:32:43 +00:00
|
|
|
//
|
2021-11-19 01:17:05 +00:00
|
|
|
//go:embed certs.pem
|
2024-07-09 17:04:23 +00:00
|
|
|
var OsqueryCerts []byte
|
2021-11-19 01:17:05 +00:00
|
|
|
|
|
|
|
|
func writeOsqueryCertPEM(opt Options, orbitRoot string) error {
|
2022-05-02 18:18:59 +00:00
|
|
|
path := filepath.Join(orbitRoot, "certs.pem")
|
|
|
|
|
if err := secure.MkdirAll(filepath.Dir(path), constant.DefaultDirMode); err != nil {
|
|
|
|
|
return fmt.Errorf("mkdir: %w", err)
|
|
|
|
|
}
|
2021-11-19 01:17:05 +00:00
|
|
|
|
2024-07-09 17:04:23 +00:00
|
|
|
if err := os.WriteFile(path, OsqueryCerts, 0o644); err != nil {
|
2021-11-22 14:13:26 +00:00
|
|
|
return fmt.Errorf("write file: %w", err)
|
2021-11-19 01:17:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|