Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bumpversion.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.bumpversion]
current_version = "1.6.0+261123"
current_version = "1.7.0+261123"
parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)\\+(?P<build>\\d+)"
serialize = ["{major}.{minor}.{patch}+{build}"]
search = "{current_version}"
Expand Down
16 changes: 13 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,13 @@ giving callsigns, one phone, the settings and removing a Deploy App. Keep these
connector stops. Nothing else may ever be kept there: no other storage, no cookie. Every sentence it
shows comes from an answer; `app.js` adds labels, headings, the lines of the Add card that say
where Deploy App's button is, that it opens a new tab and what to have at hand, the Remove
dialog's line on what removing changes, and the sentences for a connector that refuses this
browser or does not answer. A tab waits for Deploy App only when Deploy App's button opened it,
dialog's lines on what removing changes and on what ending the Deploy App in its MDM changes
(never how soon: only the MDM's plugin knows that), and the sentences for a connector that
refuses this browser or does not answer. A tab waits for Deploy App only when Deploy App's button opened it,
and a card that holds nothing typed follows a Deploy App added, opened or connected in another
tab. Focus starts in the first field, else on the main button; in the Remove dialog and on the
confirm card for a new Deploy App, on Cancel. The picture of Deploy App's button on the Add card
confirm card for a new Deploy App, on Cancel. Enter on the Remove dialog's box does nothing: only
its button ends a Deploy App. The picture of Deploy App's button on the Add card
is no control: a `span`, hidden from assistive technology. Each card and each dialog is a form whose
main button submits it; a button that cannot act is disabled, not hidden.
- Deploy App's MDM page is the address `App.mdm_page` hands in the state, opened in a new tab with
Expand Down Expand Up @@ -177,6 +179,14 @@ A certificate authority is the exception: it is known by the address it serves,
its teams' phones would enrol into another Deploy App. Fleet keeps an authority while a certificate
template is bound to it (a foreign key without ON DELETE in Fleet 4.90.1's schema).

Ending a Deploy App makes the only two deletions there are, `FleetMdm.delete_certificate` and
`delete_authority`, measured on a live Fleet 4.90.1: deleting a team's certificate template is
answered 2xx, and Fleet's console says of it that it removes the certificate from all hosts of the
team; deleting an authority is answered 2xx once no template is bound to it, and 409 with
"Certificate templates still reference it" while one of any team is. An authority is deleted only
after its address is compared with this Deploy App's, and a team whose template is bound to an
authority of another address is left alone: never loosen either.

## Commands

- Setup: `uv sync`
Expand Down
46 changes: 42 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,16 @@ this computer** on the token's card and press **Connect**; or remove the Deploy
removes it from the keychain. If removing the Deploy App cannot remove it from the keychain, the
page says so: delete the ``odmdm-connector`` item of that Deploy App there by hand.

Once a deployment is over, end it in the MDM as you remove it: in the Remove dialog tick **Also
end it in Fleet**, or your MDM's name in Fleet's place, and press **End and remove**. The MDM takes
this Deploy App's certificate from the group's phones, at their next check-in, and then the
connector removes the Deploy App as Remove does; until then it changes nothing else in the MDM
for that Deploy App. The group, its phones, their names and their apps stay in the MDM, and the
next Deploy App can be connected to that group. It cannot be undone, so end a Deploy App only when
its deployment is over. The box is there while the MDM is connected and can end a Deploy App;
otherwise the dialog says why. If the MDM refuses on the way, nothing is removed from the
connector, the page says what was already taken out, and ending again finishes the rest.

The connector keeps what you set on the page, never the token or the challenge, in
``settings.json`` in its own folder, beside its log: ``%LOCALAPPDATA%\odmdm-connector`` on
Windows, ``~/Library/Application Support/odmdm-connector`` on macOS, ``~/.config/odmdm-connector``
Expand Down Expand Up @@ -333,6 +343,12 @@ Close enrolment once ``phones`` says every phone has its certificate: a request
it closes is refused. The next opening makes a new challenge, so step 2 comes again before the
next batch.

Once the deployment is over, ``end`` takes this Deploy App out of the MDM as the page's **End and
remove** does, but leaves the page's settings as they are, and needs no challenge. Without
``--yes`` it changes nothing and says how many phones in the team would lose the certificate::

odmdm-connector end --yes

A refusal is usually a callsign that is malformed or taken, an enrolment window that has closed,
or an MDM that still has the previous opening's challenge. A callsign is never freed, not even by
removing it in Deploy App: give the phone another. A phone that is renamed after it got its
Expand All @@ -356,6 +372,7 @@ Commands
odmdm-connector name 31=OTTER4 32=OTTER5 # name these phones, and their certificates are asked for
odmdm-connector name --all OTTER # the same for every phone without a name, numbered
odmdm-connector resend [ID ...] # ask again; without ids, every named phone that failed
odmdm-connector end --yes # once the deployment is over, take it out of the MDM; without --yes, only say what would change
odmdm-connector mdms # the MDMs installed: fleet built in, and any plugins

``name --all`` numbers in enrolment order from one above the highest ``OTTER<n>`` among the
Expand Down Expand Up @@ -542,6 +559,20 @@ anything is changed, with both addresses said.
The API token is a global admin's, so whoever runs the connector for one Deploy App can change
every team in that Fleet: share a Fleet only among people who trust each other with it.

When a deployment ends
~~~~~~~~~~~~~~~~~~~~~~

Ending a Deploy App, **End and remove** on the page or ``end --yes``, deletes two things in Fleet:
the team's certificate template, named as ``ODMDM_KEY_ALIAS`` says, and then the certificate
authority that template was bound to. Fleet then has every phone in the team that holds that
certificate remove it at its next check-in, within about 15 minutes. The team, its phones, their names, its
policy, its apps and its launcher stay, and the next Deploy App can be connected to that team.
Fleet keeps an authority while another team's certificate template still uses it: the connector
then says the authority stays. A team whose template is bound to an authority that serves another
address is left as it is, with both addresses said, and so is Fleet when it has no team of that
name. When the team has no such template, as after an ending that stopped half-way, ending again
deletes the authority that serves this Deploy App's address, never one that serves another.

The template
~~~~~~~~~~~~

Expand Down Expand Up @@ -647,8 +678,8 @@ only:
default may hold ``{deployment}``, which the connector fills in with the deployment's name, the
first label of the Deploy App's host: ``{deployment} DeployApp`` is Fleet's team. Without a
host there is no such default, so make that field ``required``.
- ``missing`` holds, for each of ``setup``, ``set_challenge``, ``ask_again`` and ``send_policy``
the MDM cannot do, the sentence the operator reads instead; it is an empty mapping when the MDM
- ``missing`` holds, for each of ``setup``, ``set_challenge``, ``ask_again``, ``send_policy`` and
``end`` the MDM cannot do, the sentence the operator reads instead; it is an empty mapping when the MDM
can do them all. The connector never calls what is listed there; called anyway, it raises
``MdmError`` with that sentence, ``send_policy`` being ``setup`` with ``force``.
- ``__init__(values)`` takes the fields' values by key. It does not call the MDM: on a dry run a
Expand All @@ -663,6 +694,13 @@ only:
takes callsigns by phone id, and ``ask_again(ids)`` phone ids, none meaning every named phone
whose certificate failed or was not asked for. Both answer the lines to show, and raise
``MdmError`` for an id that is not in the group.
- ``end(window)`` takes this Deploy App out of the MDM once its deployment is over: the group's
phones lose its certificate, and the group, its phones, their names and their apps stay, ready
for the group's next Deploy App. ``window`` names the Deploy App by its SCEP URL; its challenge
is not used. It answers the lines to show, what was taken out and what stays, and called again
it takes out what an earlier call left, saying so when nothing was left. A plugin made before
``end`` was in the contract has no ``end`` and does not list it in ``missing``: the connector
says that plugin cannot end a Deploy App, and never calls it.
- It raises only ``MdmError``. One that stops half-way through ``name`` says in ``named`` which
phones it had already named, and in ``lines`` the lines already due to the operator, such as an
old callsign to remove: the command line prints them before the error, the page lists them
Expand All @@ -674,8 +712,8 @@ only:
command, option or button, and never hold the challenge or a secret.

Name the package ``odmdm-connector-<name>``, depending on ``odmdm-connector>=1.4,<2``, the first
release that has everything named above, with the class under the entry point group
``odmdm_connector.mdm``::
release that has everything named above but ``end``, which came in 1.7 (a connector before it
never calls it), with the class under the entry point group ``odmdm_connector.mdm``::

[project.entry-points."odmdm_connector.mdm"]
<name> = "odmdm_connector_<name>:<Name>Mdm"
Expand Down
11 changes: 11 additions & 0 deletions examples/odmdm-connector-demo/src/odmdm_connector_demo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def __init__(self, values: Mapping[str, str], refuse_after: int | None = None) -
"""refuse_after: for tests, the pretend MDM refuses to name more phones than that"""
self.group = values.get("group", "")
self.refuse_after = refuse_after
#: Whether this Deploy App was taken out of the pretend group
self.ended = False
self.found = [
Phone("d1", "", "Pretend Phone 7", "2026-11-01T09:00:00+00:00", State.NEEDS_NAME),
Phone("d2", "", "Pretend Phone 7", "2026-11-01T09:05:00+00:00", State.NEEDS_NAME),
Expand Down Expand Up @@ -81,3 +83,12 @@ def ask_again(self, ids: Sequence[str]) -> list[str]:
for each in again:
self._waiting(each.id, each.callsign)
return [f"Phone {each.id}: certificate asked for again" for each in again]

def end(self, window: Settings) -> list[str]:
"""Take the Deploy App out of the pretend group: its phones lose the certificate and keep their names"""
kept = f"Group {self.group}, its phones, their names and their apps stay"
if self.ended:
return [f"Group {self.group} has nothing of {window.scep_url} left to take out", kept]
self.ended = True
self.found = [replace(each, state=State.NO_REQUEST) for each in self.found]
return [f"Group {self.group} no longer takes certificates from {window.scep_url}", kept]
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "odmdm-connector"
version = "1.6.0+261123"
version = "1.7.0+261123"
description = "Connects an MDM, FleetDM built in, to an OpenDefence deployment's SCEP device enrolment"
authors = [
{ name = "Benjam", email = "benjam@opendefence.fi" },
Expand Down
2 changes: 1 addition & 1 deletion src/odmdm_connector/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Connects an MDM, FleetDM built in, to an OpenDefence deployment's SCEP device enrolment"""

__version__ = "1.6.0+261123" # NOTE Use `bump-my-version` to bump versions correctly
__version__ = "1.7.0+261123" # NOTE Use `bump-my-version` to bump versions correctly
70 changes: 68 additions & 2 deletions src/odmdm_connector/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from urllib.parse import urlsplit

from . import core, plugins, settings, store
from .mdm import ASK_AGAIN, SEND_POLICY, SET_CHALLENGE, SETUP, Field, Mdm, MdmError, Phone, State, Step
from .mdm import ASK_AGAIN, SEND_POLICY, SET_CHALLENGE, SETUP, Field, Mdm, MdmError, Phone, State, Step, cannot_end
from .settings import Settings

LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -183,6 +183,8 @@ class Job(Enum):
ASK_AGAIN = "ask again"
#: Setup again with the policy sent even if unchanged
POLICY = "policy"
#: The Deploy App taken out of its MDM, then removed from the app
END = "end"


@dataclass(frozen=True)
Expand Down Expand Up @@ -423,6 +425,8 @@ def __init__(
#: The steps the setup under way has done so far, as the worker hands them over one by one
self._progress: tuple[Step, ...] = ()
self._pending = dict.fromkeys(Job, 0)
#: The Deploy Apps whose end waits or runs, each its own job: nothing more goes to the MDM for them
self._ending: set[str] = set()
# Say at once why the MDM set up before is not connected: its secrets went with the last run
if not self.status:
self.status = self._take_up()
Expand Down Expand Up @@ -468,6 +472,11 @@ def _drop(self) -> None:
self.mdm = self.mdm_class = self.window = self._passed = None
self.phones, self._listed, self._progress = [], False, ()

def _unended(self, host: str) -> None:
"""Refuse to send anything more to the MDM for a Deploy App whose end waits or runs"""
if host in self._ending:
raise AppError(f"Deploy App {host} is being ended in its MDM, so nothing more is sent to the MDM for it.")

def _say(self, sentence: str, *lines: str) -> str:
"""Say the sentence, with lines under it; what was said, the lines first"""
self.status, self.lines = sentence, lines
Expand Down Expand Up @@ -646,6 +655,7 @@ def connect(self, name: str, values: Mapping[str, str], remember: bool = True) -
chosen = self._class(name)
if not self.saved.active:
raise AppError("Add the Deploy App first: on its MDM page, press Open in the MDM connector.")
self._unended(self.saved.active)
if self.window is None and self.conn.mdm != name:
raise AppError(
f"To set {chosen.title} up, open enrolment on the MDM page of Deploy App {self.saved.active}, "
Expand Down Expand Up @@ -715,6 +725,7 @@ def send_policy(self) -> str:
for capability in (SETUP, SEND_POLICY):
if capability in self.mdm.missing:
raise AppError(self.mdm.missing[capability])
self._unended(self.saved.active)
said = f"Sending the policy again for Deploy App {self.saved.active}."
if self._pending[Job.POLICY] or self._pending[Job.SETUP]:
return self._say(said)
Expand Down Expand Up @@ -780,6 +791,50 @@ def remove(self, host: str) -> str:
)
return self._say(f"Deploy App {host} is removed from this app, and its MDM token from this computer.")

def end_note(self) -> str:
"""Why the active Deploy App cannot be ended in its MDM from here; empty when it can, or has no MDM"""
if not self.conn.mdm:
return ""
if self.mdm is None:
return "The MDM is not connected, so this Deploy App can only be removed from this app."
return cannot_end(self.mdm)

@property
def ending(self) -> bool:
"""Whether the active Deploy App's end waits or runs"""
return self.saved.active in self._ending

@property
def can_end(self) -> bool:
"""Whether the active Deploy App can be ended in its MDM from here"""
return self.mdm is not None and not cannot_end(self.mdm)

def end(self, host: str) -> str:
"""Take the Deploy App out of its MDM on the worker, and once that is done remove it as remove does

It needs the MDM connected, which only the active Deploy App's is. The MDM is handed the
window held, else one made from the host, with no challenge. Ended, the MDM's lines are said
and then remove's sentence; failed, nothing is removed, so that it can be tried again. Asked
again while it waits or runs, nothing more is sent, and nothing else goes to the MDM for that
Deploy App until it is done. Another Deploy App's end is a job of its own.
"""
if host not in self.saved.connections:
raise AppError(f"There is no Deploy App {host} in this app.")
if host != self.saved.active or self.mdm is None:
raise AppError(f"Connect to the MDM of Deploy App {host} first: ending it there needs the MDM connected.")
why = cannot_end(self.mdm)
if why:
raise AppError(why)
said = f"Ending Deploy App {host} in {self.mdm.title}."
if host in self._ending:
return self._say(said)
mdm = self.mdm
window = Settings(self.window.scep_url if self.window else f"https://{host}/scep", "")
self._ending.add(host)
self._submit(Job.END, lambda: Result(Job.END, lines=tuple(mdm.end(window))))
LOGGER.info("Ending Deploy App %s in the MDM", host)
return self._say(said)

# The enrolment window

def paste_settings(self, text: str, now: datetime.datetime, sender: str = "") -> str:
Expand All @@ -791,6 +846,7 @@ def paste_settings(self, text: str, now: datetime.datetime, sender: str = "") ->
pasted by hand; a line sent from a page other than its own Deploy App's is refused.
"""
window, host = _read(text, now, sender)
self._unended(host)
closes = window.closes.isoformat() if window.closes else ""
connection = replace(self.saved.connections.get(host, store.Connection()), closes=closes)
changed = self._activate(host, connection)
Expand Down Expand Up @@ -979,6 +1035,7 @@ def name(self, names: Mapping[str, str]) -> str:
"""Name the phones of the preview that passed last, on the worker"""
if self.mdm is None:
raise AppError("Connect to the MDM first.")
self._unended(self.saved.active)
if self._passed is None or dict(names) != self._passed:
raise AppError("Preview the callsigns first: nothing is named without a preview that passed.")
self._passed = None
Expand All @@ -992,6 +1049,7 @@ def ask_again(self, ids: Sequence[str]) -> str:
raise AppError("Connect to the MDM first.")
if ASK_AGAIN in self.mdm.missing:
raise AppError(self.mdm.missing[ASK_AGAIN])
self._unended(self.saved.active)
if not ids:
mdm = self.mdm
self._submit(Job.ASK_AGAIN, lambda: Result(Job.ASK_AGAIN, lines=tuple(mdm.ask_again([]))))
Expand Down Expand Up @@ -1028,6 +1086,8 @@ def drain(self) -> list[Result]:
except queue.Empty:
return done
self._pending[result.job] -= 1
if result.job is Job.END:
self._ending.discard(result.host)
result = self._scrubbed(result)
self._take(result)
done.append(result)
Expand Down Expand Up @@ -1096,5 +1156,11 @@ def _take(self, result: Result) -> None:
self._say(f"{_count(len(result.named), 'phone')} named.")
elif result.job is Job.ASK_AGAIN:
self._say("Asked again." if result.lines else "No phone needed asking again.")
if result.job in (Job.NAME, Job.ASK_AGAIN):
elif result.job is Job.END:
try:
removed = self.remove(result.host)
except AppError as exc:
removed = str(exc)
self._say(removed, *result.lines)
if result.job in (Job.NAME, Job.ASK_AGAIN, Job.END):
self.lines = result.lines
Loading
Loading