fleet/tools/mdm/apple/setup-test-munki.sh
Lucas Manuel Rodriguez 9191f4ce66
Add Apple MDM functionality (#7940)
* 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>
2022-10-05 19:53:54 -03:00

120 lines
3.7 KiB
Bash
Executable File

#!/bin/bash
#
# Test script to setup a local Munki repository for demo/testing purposes.
# Sets latest Firefox dmg on a client manifest.
#
if [[ -z "$REPO_DIR" ]]; then
echo "Set REPO_DIR to an absolute file path."
exit 1
fi
if [[ $REPO_DIR != /* ]]; then
echo "REPO_DIR must be an absolute file path."
exit 1
fi
if [[ -d "$REPO_DIR" ]]; then
echo -n "REPO_DIR=$REPO_DIR already exists, press any key to delete and continue... "
read
rm -rf $REPO_DIR
fi
mkdir -p $REPO_DIR/catalogs
mkdir $REPO_DIR/icons
mkdir $REPO_DIR/manifests
mkdir $REPO_DIR/pkgs
mkdir $REPO_DIR/pkgsinfo
curl -L "https://download.mozilla.org/?product=firefox-latest-ssl&os=osx&lang=en-US" --output firefox.dmg
curl -L "https://app-updates.agilebits.com/download/OPM7" --output 1password7.pkg
curl -L "https://github.com/macadmins/nudge/releases/download/v1.1.8.81422/Nudge-1.1.8.81422.pkg" --output nudge.pkg
curl -L "https://iterm2.com/downloads/stable/iTerm2-3_4_16.zip" --output iterm2.zip
unzip iterm2.zip
rm iterm2.zip
curl -L "https://central.github.com/deployments/desktop/desktop/latest/darwin" --output github.zip
unzip github.zip
rm github.zip
# No other (non-interactive) way to set the repo url for manifestutil.
defaults write ~/Library/Preferences/com.googlecode.munki.munkiimport.plist "repo_url" "file://$REPO_DIR"
defaults write ~/Library/Preferences/com.googlecode.munki.munkiimport.plist "default_catalog" "testing"
# Add Firefox with "--unattended_install" (dmg).
/usr/local/munki/munkiimport \
--nointeractive \
--subdirectory=apps/mozilla \
--displayname="Mozilla Firefox" \
--description="Fox on fire" \
--category=Internet \
--developer=Mozilla \
--catalog=testing \
--extract_icon \
--unattended_install \
firefox.dmg
# Add 1Password (pkg).
/usr/local/munki/munkiimport \
--nointeractive \
--subdirectory=apps/agilebits \
--displayname="1Password 7" \
--description="P4ssw0rd M4n4g3r" \
--category=Internet \
--developer=AgileBits \
--catalog=testing \
--extract_icon \
1password7.pkg
# Add Nudge with "--unattended_install" (pkg).
/usr/local/munki/munkiimport \
--nointeractive \
--subdirectory=apps/macadmins \
--displayname="Nudge" \
--description="Annoying but effective" \
--category=Internet \
--developer=MacAdmins \
--catalog=testing \
--extract_icon \
--unattended_install \
nudge.pkg
# Add iTerm2 app.
/usr/local/munki/munkiimport \
--nointeractive \
--subdirectory=apps/iterm2 \
--displayname="iTerm2" \
--description="Best terminal in town" \
--category=Console \
--developer=iTerm2 \
--catalog=testing \
--extract_icon \
iTerm.app
# Add Github app.
/usr/local/munki/munkiimport \
--nointeractive \
--subdirectory=apps/github \
--displayname="Github Desktop" \
--description="Github 4 Desktop" \
--category=Development \
--developer=Github \
--catalog=testing \
--extract_icon \
"Github Desktop.app"
/usr/local/munki/makecatalogs
/usr/local/munki/manifestutil new-manifest site_default
/usr/local/munki/manifestutil add-catalog testing --manifest site_default
/usr/local/munki/manifestutil add-pkg Firefox --manifest site_default
/usr/local/munki/manifestutil add-pkg 1password --manifest site_default
/usr/local/munki/manifestutil add-pkg nudge --manifest site_default
/usr/local/munki/manifestutil add-pkg iTerm2 --manifest site_default --section optional_installs
/usr/local/munki/manifestutil add-pkg "GitHub Desktop" --manifest site_default --section featured_items
/usr/local/munki/manifestutil add-pkg "GitHub Desktop" --manifest site_default --section optional_installs
rm -r firefox.dmg nudge.pkg 1password7.pkg iTerm.app "Github Desktop.app"