mirror of
https://github.com/fleetdm/fleet
synced 2026-05-06 06:48:54 +00:00
* WIP * Adding DEP functionality to Fleet * Better organize additional MDM code * Add cmdr.py and amend API paths * Fix lint * Add demo file * Fix demo.md * go mod tidy * Add munki setup to Fleet * Add diagram to demo.md * Add fixes * Update TODOs and demo.md * Fix cmdr.py and add TODO * Add endpoints to demo.md * Add more Munki PoC/demo stuff * WIP * Remove proposals from PoC * Replace prepare commands with fleetctl commands * Update demo.md with current state * Remove config field * Amend demo * Remove Munki setup from MVP-Dogfood * Update demo.md * Add apple mdm commands (#7769) * fleetctl enqueue mdm command * fix deps * Fix build Co-authored-by: Lucas Rodriguez <lucas@fleetdm.com> * Add command to upload installers * go mod tidy * fix subcommands help There is a bug in urfave/cli where help text is not generated properly when subcommands are nested too deep. * Add support for installing apps * Add a way to list enrolled devices * Add dep listing * Rearrange endpoints * Move DEP routine to schedule * Define paths globally * Add a way to list enrollments and installers * Parse device-ids as comma-separated string * Remove unused types * Add simple commands and nest under enqueue-command * Fix simple commands * Add help to enqueue-command * merge apple_mdm database * Fix commands * update nanomdm * Split nanomdm and nanodep schemas * Set 512 MB in memory for upload * Remove empty file * Amend profile * Add sample commands * Add delete installers and fix bug in DEP profile assigning * Add dogfood.md deployment guide * Update schema.sql * Dump schema with MySQL 5 * Set default value for authenticate_at * add tokens to enrollment profiles When a device downloads an MDM enrollment profile, verify the token passed as a query parameter. This ensures untrusted devices don't enroll with our MDM server. - Rename enrollments to enrollment profiles. Enrollments is used by nano to refer to devices that are enrolled with MDM - Rename endpoint /api/<version>/fleet/mdm/apple/enrollments to ../enrollmentprofiles - Generate a token for authentication when creating an enrollment profile - Return unauthorized if token is invalid when downloading an enrollment profile from /api/mdm/apple/enroll?token= * remove mdm apple server url * update docs * make dump-test-schema * Update nanomdm with missing prefix table * Add docs and simplify changes * Add changes file * Add method docs * Fix compile and revert prepare.go changes * Revert migration status check change * Amend comments * Add more docs * Clarify storage of installers * Remove TODO * Remove unused * update dogfood.md * remove cmdr.py * Add authorization tests * Add TODO comment * use kitlog for nano logging * Add yaml tags * Remove unused flag * Remove changes file * Only run DEP routine if MDM is enabled * Add docs to all new exported types * Add docs * more nano logging changes * Fix unintentional removal * more nano logging changes * Fix compile test * Use string for configs and fix config test * Add docs and amend changes * revert changes to basicAuthHandler * remove exported BasicAuthHandler * rename rego authz type * Add more information to dep list * add db tag * update deps * Fix schema * Remove unimplemented Co-authored-by: Michal Nicpon <39177923+michalnicp@users.noreply.github.com> Co-authored-by: Michal Nicpon <michal@fleetdm.com>
101 lines
2.6 KiB
Go
101 lines
2.6 KiB
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"io"
|
|
"io/fs"
|
|
"math/rand"
|
|
"os"
|
|
"path"
|
|
"runtime"
|
|
"time"
|
|
|
|
eefleetctl "github.com/fleetdm/fleet/v4/ee/fleetctl"
|
|
"github.com/kolide/kit/version"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
const (
|
|
defaultFileMode = 0o600
|
|
)
|
|
|
|
func init() {
|
|
rand.Seed(time.Now().UnixNano())
|
|
}
|
|
|
|
func main() {
|
|
app := createApp(os.Stdin, os.Stdout, exitErrHandler)
|
|
app.Run(os.Args)
|
|
}
|
|
|
|
// exitErrHandler implements cli.ExitErrHandlerFunc. If there is an error, prints it to stderr and exits with status 1.
|
|
func exitErrHandler(c *cli.Context, err error) {
|
|
if err == nil {
|
|
return
|
|
}
|
|
|
|
fmt.Fprintf(c.App.ErrWriter, "Error: %+v\n", err)
|
|
|
|
if errors.Is(err, fs.ErrPermission) {
|
|
switch runtime.GOOS {
|
|
case "darwin", "linux":
|
|
fmt.Fprintf(c.App.ErrWriter, "\nThis error can usually be resolved by fixing the permissions on the %s directory, or re-running this command with sudo.\n", path.Dir(c.String("config")))
|
|
case "windows":
|
|
fmt.Fprintf(c.App.ErrWriter, "\nThis error can usually be resolved by fixing the permissions on the %s directory, or re-running this command with 'Run as administrator'.\n", path.Dir(c.String("config")))
|
|
}
|
|
}
|
|
cli.OsExiter(1)
|
|
}
|
|
|
|
func createApp(reader io.Reader, writer io.Writer, exitErrHandler cli.ExitErrHandlerFunc) *cli.App {
|
|
app := cli.NewApp()
|
|
app.Name = "fleetctl"
|
|
app.Usage = "CLI for operating Fleet"
|
|
app.Version = version.Version().Version
|
|
app.ExitErrHandler = exitErrHandler
|
|
cli.VersionPrinter = func(c *cli.Context) {
|
|
version.PrintFull()
|
|
}
|
|
app.Reader = reader
|
|
app.Writer = writer
|
|
app.ErrWriter = writer
|
|
|
|
app.Commands = []*cli.Command{
|
|
applyCommand(),
|
|
deleteCommand(),
|
|
setupCommand(),
|
|
loginCommand(),
|
|
logoutCommand(),
|
|
queryCommand(),
|
|
getCommand(),
|
|
{
|
|
Name: "config",
|
|
Usage: "Modify Fleet server connection settings",
|
|
Subcommands: []*cli.Command{
|
|
configSetCommand(),
|
|
configGetCommand(),
|
|
},
|
|
},
|
|
convertCommand(),
|
|
goqueryCommand(),
|
|
userCommand(),
|
|
debugCommand(),
|
|
previewCommand(),
|
|
eefleetctl.UpdatesCommand(),
|
|
hostsCommand(),
|
|
vulnerabilityDataStreamCommand(),
|
|
packageCommand(),
|
|
appleMDMCommand(),
|
|
{
|
|
// It's become common for folks to unintentionally install fleetctl when they actually
|
|
// need the Fleet server. This is hopefully a more helpful error message.
|
|
Name: "prepare",
|
|
Usage: "This is not the binary you're looking for. Please use the fleet server binary for prepare commands.",
|
|
Action: func(c *cli.Context) error {
|
|
return errors.New("This is not the binary you're looking for. Please use the fleet server binary for prepare commands.")
|
|
},
|
|
},
|
|
}
|
|
return app
|
|
}
|