Enroll a device at install
Hand the enrollment token to the package installer, so a device installs and enrolls in one step from your provisioning script.
API
Ben’s new laptop is being set up by your provisioning script, and you want it to come out of setup already enrolled
into your realm, with no one typing an enroll command. The package’s installer enrolls the device itself when it
finds the token and addresses it needs.
Before you start
Section titled “Before you start”- You hold
MODIFYon the realm’s endpoint settings (RealmOwnerhas it; see Who can call), with your session in$CVYUH_SESSION(Call the API). - The device runs Linux or macOS, the script installs as root, and the package isn’t installed on it yet.
- You have the package for the device’s platform and the device address (a host and port), both from whoever runs your deployment.
The variables are named for your deployment: these steps use CVYUH_, and the device client cvyuh-uem.
Enroll it at install
Section titled “Enroll it at install”-
Make one token per device. A token enrolls one device, so the script asks for one for each machine it sets up:
Terminal window curl https://foobar.cvyuh.com/api/v0/endpoint/ppm/v1/enrolment-tokens \-H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \-H "Content-Type: application/json" \-d '{"ttlHours": 2}'Take
tokenfrom the answer. -
Install with the values where the installer reads them. Name the device with
CVYUH_NAME, or leave it out for the host name:The installer reads the values from its environment:
Terminal window sudo CVYUH_SERVER=<device address> CVYUH_TOKEN=<enrollment token> \CVYUH_ISSUER=https://foobar.cvyuh.com/oauth2 CVYUH_NAME=ben-laptop \apt install ./<package>.debUse
dnf install ./<package>.rpmfor the rpm. Then start the device client:Terminal window sudo systemctl enable --now cvyuh-uemThe installer reads the values from the file
/tmp/cvyuh_envs, then deletes it. Because/tmpis shared by every user of the Mac, write the file so that only root can read or change it: refuse if the file is already there, create it empty, owned by root with mode0600, check that, and only then write the token into it. Fill in the values, then run:Terminal window sudo sh -s <<'SCRIPT' && sudo installer -pkg ./<package>.pkg -target /set -euf=/tmp/cvyuh_envsif [ -e "$f" ] || [ -L "$f" ]; thenecho "$f already exists: not writing the token. Find out who made it." >&2exit 1fiumask 077set -C: > "$f"if [ ! -f "$f" ] || [ -L "$f" ] || [ "$(stat -f '%Su %Lp' "$f")" != "root 600" ]; thenecho "$f isn't root's own with mode 600: not writing the token." >&2exit 1ficat >> "$f" <<'EOF'export CVYUH_SERVER=<device address>export CVYUH_TOKEN=<enrollment token>export CVYUH_ISSUER=https://foobar.cvyuh.com/oauth2export CVYUH_NAME=ben-laptopEOFSCRIPTThe package is installed only if the file was written. The installer starts the device client.
The installer prints
Enrolling with the site..., then the name the device was enrolled as and the date to enroll it again before. On macOS these lines go to the installer’s log,/var/log/install.log.
Check it worked
Section titled “Check it worked”List the realm’s devices:
curl https://foobar.cvyuh.com/api/v0/endpoint/ppm/v1 \ -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"ben-laptop is there with status active and connected true. On macOS, check that /tmp/cvyuh_envs is gone:
ls /tmp/cvyuh_envs should find nothing.
If it didn’t work
Section titled “If it didn’t work”| Symptom | Cause | Fix |
|---|---|---|
The installer prints Error: enrolment failed; run ... enroll by hand. | The realm refused the token, or the device couldn’t reach it; the installer finishes installing anyway | Run enroll by hand, as in Device enrollment, and read its reason in If enrollment fails. The token is still good unless it was spent or expired |
No Enrolling line at all | The values weren’t found: on Linux, sudo dropped them; on macOS, the file wasn’t there, or the package was already installed | Pass the variables on the same sudo line as the install. On a Mac that already has the package, the installer doesn’t enroll: run enroll by hand |
/tmp/cvyuh_envs is still there after install | The installer didn’t run its enrollment, so it didn’t delete the file | Remove it now, sudo rm -f /tmp/cvyuh_envs; it holds the token |
Undo it
Section titled “Undo it”Remove the device from the realm, and uninstall the package on the device. See Device removal.
Related
Section titled “Related”- Get started with Endpoint Management: enroll one device by hand, and see it report in.
- Device enrollment: how a token and a certificate work, and every
enrolloption. - Device limits: how many devices the realm may have.