Formats¶
shaar reads two kinds of access input: its own export, and CSV files. It detects the kind from the content of the file, never from its name or extension. A file whose first line is a JSON object with a shaar_export member is an export. Any other file is read as a CSV, which needs a column map or a preset. A CSV given with no map or preset is refused with exit code 3.
The shaar export¶
The export is JSON Lines: one JSON object per line, UTF-8, \n line ends. The PowerShell exporter, shaar collect ad, and shaar collect entra all write it. A file has a header, any number of records, and a trailer.
{"shaar_export":1,"system":"ad","collector":{"name":"Export-ShaarAccess.ps1","version":"0.1.1"},"collected_at":"2026-11-01T22:00:00Z","scope":{"groups":["Finance Admins"]},"domain":"corp.example"}
{"principal":{"id":"S-1-5-21-1000-1000-1000-1102","name":"Avery Example","kind":"user","enabled":true,"email":"avery.example@corp.example","upn":"avery.example@corp.example","manager_id":"S-1-5-21-1000-1000-1000-1101","last_sign_in":"2026-10-30T08:15:00Z","extra":{}}}
{"resource":{"id":"S-1-5-21-1000-1000-1000-2001","name":"Finance Admins","kind":"group","owner_ids":[],"complete":true,"extra":{}}}
{"grant":{"principal_id":"S-1-5-21-1000-1000-1000-1102","resource_id":"S-1-5-21-1000-1000-1000-2001","entitlement":"member","via":[],"extra":{}}}
{"gap":{"what":"managers","reason":"example"}}
{"end":true,"records":4,"sha256":"..."}
Header¶
The first line. It must be valid JSON with "shaar_export": 1 and a system of ad or entra, or the file is refused with exit code 3.
Member |
Meaning |
|---|---|
|
The format version. Always |
|
|
|
The tool that wrote the file: |
|
When the access was read, as ISO 8601 with |
|
Free JSON that says what was asked for. |
|
The domain (AD) or the tenant (Entra). For Entra it is the canonical tenant id, in lower case, from the |
|
Entra only: the national cloud ( |
shaar keeps scope, collector, domain, tenant, and cloud as context. It does not interpret them.
Records¶
Each record line holds exactly one member: principal, resource, grant, or gap. Text members are trimmed. A member of the wrong type is ignored and noted as a problem.
Record |
Members |
|---|---|
|
|
|
|
|
|
|
|
A grant is one principal’s entitlement on one resource. Group membership has the entitlement member. A directory role grant is one scope of one role: the entitlement is whole directory, or the word scope, a space, and the scope id (for example scope /administrativeUnits/ID), and never the role’s name, which is only in the resource’s name. Eligible (PIM) role grants are on the resource ROLE-ID:eligible, and only schedules in force at collected_at are written. Two paths to the same access are one grant: via is a shortest path, and extra.paths lists the routes, joined with a semicolon and a space. For Active Directory these are one shortest route for each direct holding group and each group that nests it, not every route.
A complete of false means the resource’s membership was cut short: a paging failure, a failed range read, access denied, or throttling.
Ids are the raw source ids: a SID for Active Directory, an object id for Entra ID. shaar builds the keys from them.
Trailer¶
The last line: {"end":true,"records":N,"sha256":"HEX"}.
recordscounts the lines between the header and the trailer, blank and unreadable lines included.sha256is the SHA-256 of every byte before the trailer line, header included.
If the trailer is missing, is not last, or has a wrong count or hash, shaar records a problem and treats no resource as complete. Data after the trailer is also a problem and makes the file untrusted.
Limits: a line may be at most 1 MiB and a file at most 512 MiB. A file over the limit is refused. Both limits can be raised with --limit (export-bytes, line-bytes). A line over the limit is skipped, and the loss means no resource is complete.
What shaar does with a damaged export¶
Nothing is thrown away silently. Each of these is a problem in the report:
A line that is not a JSON object, an unknown record type, or a line with more than one member. The affected lines are skipped, and no resource is complete.
A grant with a missing field or a malformed
via. The grant is skipped and only its resource is marked not complete.A duplicate principal or resource id. The first is kept, and a duplicate resource is not complete.
One resource id given as two resources, such as a group and a role. A grant naming that id could belong to either, so it stays with the first record, and neither resource is complete.
A grant whose principal or resource has no record. The grant is kept with a stub record (
extra.stubistrue), because hiding access that exists would be worse than showing it without details. A stub resource is never complete.
What complete means¶
A resource is complete when the whole of its membership was read. shaar counts a resource as complete only if:
the export has a valid trailer (count and hash match), and
no line was lost, and
the resource record says
"complete": true, and no grant of it was dropped, andevery input that mentions the resource says so. If two inputs read the same resource and one read it only in part, it is not complete.
This matters for verification. A removal is verified only when the grant is absent from a later export that read the resource completely. Without that, absence proves nothing: the group may simply have been cut short. A resource that is not complete can still be reviewed in a campaign, and its present grants are still real.
Keys¶
A key identifies a principal, resource, or grant across exports. Matching across inputs uses keys only, never display names, except when a CSV offers nothing else. Keys are lower-case strings of the form system:kind:value.
Key |
Used for |
|---|---|
|
An Active Directory object with a domain SID. The SID is upper-cased, because SIDs ignore case. |
|
A well-known SID that every domain has, such as |
|
An Active Directory object with no readable SID, matched by its case-folded distinguished name. A problem notes the weaker match. |
|
An Entra ID object in one tenant, with both ids in lower case. Without a tenant id the tenant part is |
|
An Entra ID directory role in one tenant, in lower case. |
|
An identifier from a CSV, trimmed and case-folded. The system is the one the map names. |
A grant key is RESOURCE-KEY|PRINCIPAL-KEY|entitlement, with the entitlement trimmed and case-folded. In each part, % is written %25 and | is written %7C, so a | inside a name cannot make two grants share a key.
The same object id in two tenants, or the same well-known SID in two domains, is two different things. A key whose tenant or domain is unknown (?) could stand for any of them, so no resource that holds such a key is treated as complete, and a problem says so. Two exports of the same access give the same grant key. That is what lets verify find a grant again, even when the nesting path changed.
A system name is 1 to 40 characters: lower-case letters, digits, ., _, and -, starting with a letter or digit. ad and entra are reserved for the collectors, except that a CSV map can produce ad or entra keys through id_style.
CSV files¶
A CSV needs a column map, given with --map FILE.toml, a built-in preset with --preset NAME, or both. shaar decodes the file by its byte order mark (UTF-8, UTF-16 little or big endian), else as strict UTF-8. A file that cannot be decoded, or holds NUL characters, is refused. Set encoding in the map for any other encoding. The delimiter is the one of ,, ;, tab, and | that splits the header line most, unless the map sets it. A delimiter under which the header is not valid CSV (as "a","b" is not under ;) is passed over; if the header is valid under none, the file is refused.
A CSV is read as text. Cells that look like formulas are data, and shaar never evaluates them. A row with more cells than the header, or that lacks a needed id, is skipped with a problem, and its resource is then not complete. Quoting is read strictly: a quoted cell may span lines, but a quote that is never closed, or text right after a closing quote, is a problem, and then no resource in the file is complete, because the rows after it may have been swallowed. A file is limited to 256 MiB and 2,000,000 data rows by default; raise csv-bytes or csv-rows with --limit.
The column map¶
A map is a TOML file. All keys are optional unless a rule below says otherwise.
preset = "generic" # a starting point; the map overrides it
system = "ledger" # the system name used in keys
resource = "Ledger" # one fixed resource for the whole file
resource_kind = "application" # group, role, application, or other
encoding = "utf-8" # default: by byte order mark, else strict UTF-8
delimiter = "," # default: sniffed; "tab" is accepted
owner_separator = ";" # splits owner_ids
via_separator = ">" # splits via
complete = true # false: no resource in the file counts as complete
collected_at = "2026-11-01T00:00:00Z" # when the CSV was exported, if known
domain = "corp.example" # with id_style sid: the domain well-known SIDs belong to
tenant = "00000000-0000-4000-8000-000000000000" # with id_style entra: the tenant id
optional = false # true: mapped columns missing from the file are ignored
id_style = "csv" # csv, sid, or entra
[columns] # field = "header in the file"
principal_id = "Email"
principal_name = "Full name"
enabled = "Active"
entitlement = "Role"
[values]
enabled_true = ["true", "yes", "1", "enabled"]
enabled_false = ["false", "no", "0", "disabled"]
[principal_kinds] # header value (case-insensitive) = shaar kind
inetorgperson = "user"
[extra] # columns kept as extra text on a record
principal = ["Department"]
resource = []
grant = []
Key |
Meaning |
|---|---|
|
Start from a built-in map. The |
|
The system name for keys. Needed unless the file has a |
|
One fixed resource for the file, matched by name. The |
|
The kind used when there is no |
|
See above. A delimiter is one character or the word |
|
Must not be empty. Defaults |
|
Default |
|
ISO 8601 with |
|
With |
|
With |
|
When |
|
How an id column becomes a key: |
|
Maps a field to the header text, matched without regard to case. The fields are listed below. A header that appears twice is an error. |
|
|
|
Maps a cell value to one of |
|
Lists of headers whose values are kept as |
An unknown key in the map, or an unknown field in [columns], is an error.
The fields for [columns] are principal_id, principal_name, principal_kind, enabled, email, upn, manager_id, last_sign_in, resource_id, resource_name, resource_kind, owner_ids, entitlement, via, and system.
Rules that apply to every CSV:
The map must name a
principal_idor aprincipal_namecolumn that is in the file. Without an id column, principals are matched by name, which is weaker, and a problem says so.There must be a resource: a fixed
resource, or aresource_idorresource_namecolumn. With aresource_namecolumn and noresource_id, the resource is matched by name, and a problem says so. A fixed resource gives no problem: you name it, and the same name keys it in every export.There must be a system: a
systemcolumn orsystem = ...in the map.A blank entitlement cell means
member. This is the one place a blank is filled in, and it is not a problem.Every row must have exactly as many cells as the header. A shorter row may have been cut off, so it is skipped with a problem and no resource in the file is complete (it is never padded with blanks, which would turn an
Approverinto amember). A file whose last line does not end with a line break is a problem with the same effect: its last row may be cut. Add the final line break once you know the export is whole.A column that the map file lists under
[columns]and the file lacks is a problem whenoptional = true(otherwise it is an error). Forentitlementit also leaves no resource in the file complete. A column that only a preset supplies and the file lacks is not a problem, and neither is a map that names no entitlement column at all, except that an export from which no entitlement column was read cannot show that any entitlement other thanmemberwas removed:shaar verifyreports such a removal asunknown.Text that identifies people and things (ids, names, emails, the reviewer map) is compared after Unicode normalization (NFKC) and case folding, so the same text in a composed or decomposed form, or in full-width letters, is one value. Values are shown and written exactly as read. Letters of different scripts that look alike are different letters.
manager_idand each entry ofowner_idsare written the way principal ids are, so they match principals.A row with a blank id, or with a name that makes an unusable system or key, is skipped with a problem.
Rows are cited by line number, with the header as row 1.
Presets¶
Preset |
For |
Columns |
|---|---|---|
|
A CSV that already uses shaar’s headers. |
|
|
A |
|
|
The Entra portal’s “Download members” file for one group. |
|
All presets are optional-column presets: a column that is not in the file is ignored. A preset has no manager, email, or owner column, so the manager rule cannot place its rows. Add the columns with your own map, or use --reviewers map.
Completeness of a CSV¶
shaar cannot know whether a CSV holds everything. It treats every resource a CSV mentions as complete, unless the map says complete = false, a row was skipped, or the file could not be read to its end. A truncated export or a filtered view therefore looks complete. If your CSV may be partial, set complete = false: reviews still work, but verification can then say only unknown for removals that rest on it.
When a CSV has no id column¶
Without principal_id, shaar matches principals by case-folded name, and with no resource_id it matches the resource by name. Two people with one name become one principal. Prefer a column that holds a stable id or an email address.