Skip to content
Endpoint ManagementMarkdown

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.

  • You hold MODIFY on the realm’s endpoint settings (RealmOwner has 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.

  1. 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 token from the answer.

  2. 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>.deb

    Use dnf install ./<package>.rpm for the rpm. Then start the device client:

    Terminal window
    sudo systemctl enable --now cvyuh-uem

    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.

List the realm’s devices:

Terminal window
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.

SymptomCauseFix
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 anywayRun 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 allThe values weren’t found: on Linux, sudo dropped them; on macOS, the file wasn’t there, or the package was already installedPass 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 installThe installer didn’t run its enrollment, so it didn’t delete the fileRemove it now, sudo rm -f /tmp/cvyuh_envs; it holds the token

Remove the device from the realm, and uninstall the package on the device. See Device removal.