@aidalinfo/m365-mcp 0.6.0 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -1
- package/dist/review/collect.js +36 -9
- package/dist/review/model.js +178 -25
- package/dist/tools/access-review.js +16 -4
- package/dist/tools/security.js +1 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -97,7 +97,19 @@ per site.
|
|
|
97
97
|
- **Comparison**: `compareWith: "latest"` (or a file name from that directory — never a path) lists
|
|
98
98
|
accounts created / deleted / disabled / re-enabled, new guests, entries and exits of groups, teams
|
|
99
99
|
and private channels, new and removed owners, new and removed admins, licences reassigned, new
|
|
100
|
-
applications and newly consented permissions.
|
|
100
|
+
applications and newly consented permissions. Each change depends on named sections in **both**
|
|
101
|
+
snapshots (`users`; `users` + `skus` for licences; `groups`; `groups` + `channels` for entries, exits
|
|
102
|
+
and new owners; `roles`; `applications`): one of them not read on either side makes that change
|
|
103
|
+
*NOT compared* — with the reason — never a list of accounts, groups or admins "created" or "deleted".
|
|
104
|
+
Only exception, `channels`: without it (typically `ChannelMember.Read.All` missing) the entries, exits
|
|
105
|
+
and new owners of groups and teams are still compared; the private/shared channels are left out,
|
|
106
|
+
named (as read in the other snapshot), and the change is *⚠ partial*. Without `groups` they stay
|
|
107
|
+
*NOT compared*.
|
|
108
|
+
A truncated list (10 000 accounts, 2 000 groups, 2 000 role assignments, 300 applications) creates or
|
|
109
|
+
deletes nothing for the objects present on one side only, and the change is *⚠ partial*; a group or
|
|
110
|
+
private channel whose members were cut is left out of entries and exits and named; delegated consents
|
|
111
|
+
not read leave the delegated grants out. The summary says how many changes were *NOT compared*,
|
|
112
|
+
which is never *no change*.
|
|
101
113
|
- **Signals**: Microsoft 365 group or team without owner, guest owner, disabled account still member or
|
|
102
114
|
licensed, account inactive for 90+ days (`inactiveDays`), shared mailbox holding a licence or able
|
|
103
115
|
to sign in, admin without MFA, guest admin.
|
|
@@ -639,6 +651,8 @@ taken without the exchange feature is compared as *not evaluated*, never as "rig
|
|
|
639
651
|
| `⚠ Mailbox list truncated: … ResultSize 1000` | Connector limit: Exchange stopped at 1000 mailboxes | Mailboxes beyond it are not reviewed |
|
|
640
652
|
| `⚠ Permission list truncated (server page budget)` / `⚠ truncated` | Pagination budget (20 pages) reached | That right is partial |
|
|
641
653
|
| Review: *not evaluated — section(s) mailboxAccess failed / not configured*, or *⚠ partial — …* | Section not read, or read in part | The signal / change is not concluded |
|
|
654
|
+
| Changes: *NOT compared — previous snapshot: section users failed (…)* | That section was not read in one of the two reviews | Nothing is known of those changes — never report deletions or creations; compare with another snapshot |
|
|
655
|
+
| Changes: *⚠ partial — private/shared channels NOT compared — … section channels failed (…); N channel(s) left out, as read in the … snapshot: …* | Channel members not read in one of the two reviews (`ChannelMember.Read.All`) | The group and team entries, exits and new owners listed are real; nothing is known of the named channels |
|
|
642
656
|
|
|
643
657
|
### Limits (stated in every answer)
|
|
644
658
|
|
|
@@ -862,6 +876,21 @@ snapshot, signals and comparison end to end.
|
|
|
862
876
|
|
|
863
877
|
## Validation status
|
|
864
878
|
|
|
879
|
+
- 0.6.2 (#153, decision of the reviewer): `channels` not read in one of the two snapshots no longer
|
|
880
|
+
leaves the entries, exits and new owners *NOT compared*: the groups and teams are still compared, the
|
|
881
|
+
private/shared channels are left out, named, and the change is *⚠ partial* — never a channel member
|
|
882
|
+
"joined" or "left". `groups` not read keeps them *NOT compared*. Unit tests on fixtures (channels
|
|
883
|
+
failed on either side and on both, groups not read, end to end through the tool). **No Microsoft
|
|
884
|
+
call was made.**
|
|
885
|
+
|
|
886
|
+
- 0.6.1 (#153): `m365_access_review_snapshot` with `compareWith` no longer turns a section not read
|
|
887
|
+
(failed, not configured, absent from an older snapshot) or truncated into accounts, groups, admin
|
|
888
|
+
roles, members or applications created or deleted, nor a missing `skus` into licence changes (SKU
|
|
889
|
+
name against GUID). The channels are *not read* when the group list is not; the group list cut is
|
|
890
|
+
told apart from members cut on one group; role assignments and delegated consents record their own
|
|
891
|
+
cut. Unit tests on fixtures (every section failed on either side, truncations, `skus`, nominal case
|
|
892
|
+
unchanged). **No Microsoft call was made for #153.**
|
|
893
|
+
|
|
865
894
|
- 0.6.0 (#152, Exchange mailbox audit in readonly): unit tests passing against a fake Exchange —
|
|
866
895
|
registered tools, cmdlets sent, `rbac_denied` / `auth_failed` / `permission_missing` / `not_found`
|
|
867
896
|
told apart, rights `NOT EVALUATED` instead of empty, ResultSize and page-budget cuts, access-review
|
package/dist/review/collect.js
CHANGED
|
@@ -65,14 +65,14 @@ export async function collectSnapshot(ctx, opts = {}) {
|
|
|
65
65
|
const byUpn = new Map(users.filter((u) => u.upn).map((u) => [u.upn.toLowerCase(), u]));
|
|
66
66
|
const groups = (await section(sections, "groups", async () => {
|
|
67
67
|
const { items, truncated } = await collectAll(ctx, "/groups", { $select: "id,displayName,groupTypes,mailEnabled,securityEnabled,visibility,resourceProvisioningOptions" }, { max: MAX_GROUPS });
|
|
68
|
-
let memberTruncated =
|
|
68
|
+
let memberTruncated = 0;
|
|
69
69
|
const list = await mapLimit(items, CONCURRENCY, async (g) => {
|
|
70
70
|
const [owners, members] = await Promise.all([
|
|
71
71
|
collectAll(ctx, `/groups/${g.id}/owners`, { $select: "id" }, { max: 500 }),
|
|
72
72
|
collectAll(ctx, `/groups/${g.id}/members`, { $select: "id" }, { max: MAX_MEMBERS }),
|
|
73
73
|
]);
|
|
74
74
|
if (owners.truncated || members.truncated)
|
|
75
|
-
memberTruncated
|
|
75
|
+
memberTruncated++;
|
|
76
76
|
return {
|
|
77
77
|
id: g.id,
|
|
78
78
|
displayName: g.displayName,
|
|
@@ -85,25 +85,49 @@ export async function collectSnapshot(ctx, opts = {}) {
|
|
|
85
85
|
...(owners.truncated || members.truncated ? { truncated: true } : {}),
|
|
86
86
|
};
|
|
87
87
|
});
|
|
88
|
-
|
|
88
|
+
// `truncated` = the group LIST was cut (groups beyond it unknown); members cut on a group are flagged on that group
|
|
89
|
+
return {
|
|
90
|
+
list,
|
|
91
|
+
truncated,
|
|
92
|
+
note: memberTruncated ? `members or owners truncated on ${memberTruncated} group(s) (caps ${MAX_MEMBERS} members / 500 owners): their entries and exits are not compared` : undefined,
|
|
93
|
+
};
|
|
89
94
|
}))?.list ?? [];
|
|
90
95
|
// private and shared channels: their members are not the team's
|
|
91
96
|
const channels = (await section(sections, "channels", async () => {
|
|
97
|
+
// without the group list the teams are unknown: that is not "no private channel"
|
|
98
|
+
if (!sections.groups?.ok)
|
|
99
|
+
throw new Error("group list not read — the teams and their channels are unknown");
|
|
92
100
|
const teams = groups.filter((g) => g.isTeam);
|
|
101
|
+
let listCut = Boolean(sections.groups?.truncated);
|
|
102
|
+
let memberCut = 0;
|
|
93
103
|
const perTeam = await mapLimit(teams, CONCURRENCY, async (t) => {
|
|
94
|
-
const { items } = await collectAll(ctx, `/teams/${t.id}/channels`, { $select: "id,displayName,membershipType", $filter: "membershipType ne 'standard'" }, { top: false, max: 500 });
|
|
104
|
+
const { items, truncated } = await collectAll(ctx, `/teams/${t.id}/channels`, { $select: "id,displayName,membershipType", $filter: "membershipType ne 'standard'" }, { top: false, max: 500 });
|
|
105
|
+
if (truncated)
|
|
106
|
+
listCut = true;
|
|
95
107
|
return mapLimit(items, CONCURRENCY, async (c) => {
|
|
96
|
-
const { items: m } = await collectAll(ctx, `/teams/${t.id}/channels/${encodeURIComponent(c.id)}/members`, {}, { top: false, max: MAX_MEMBERS });
|
|
108
|
+
const { items: m, truncated: cut } = await collectAll(ctx, `/teams/${t.id}/channels/${encodeURIComponent(c.id)}/members`, {}, { top: false, max: MAX_MEMBERS });
|
|
109
|
+
if (cut)
|
|
110
|
+
memberCut++;
|
|
97
111
|
const ids = (x) => x.map((y) => y.userId).filter((y) => Boolean(y));
|
|
98
|
-
return {
|
|
112
|
+
return {
|
|
113
|
+
teamId: t.id,
|
|
114
|
+
teamName: t.displayName,
|
|
115
|
+
channelId: c.id,
|
|
116
|
+
displayName: c.displayName,
|
|
117
|
+
membershipType: c.membershipType,
|
|
118
|
+
owners: ids(m.filter((y) => y.roles?.includes("owner"))),
|
|
119
|
+
members: ids(m),
|
|
120
|
+
...(cut ? { truncated: true } : {}),
|
|
121
|
+
};
|
|
99
122
|
});
|
|
100
123
|
});
|
|
101
|
-
return { list: perTeam.flat() };
|
|
124
|
+
return { list: perTeam.flat(), truncated: listCut, note: memberCut ? `members truncated on ${memberCut} channel(s) (cap ${MAX_MEMBERS}): their entries and exits are not compared` : undefined };
|
|
102
125
|
}))?.list ?? [];
|
|
103
126
|
// admin roles
|
|
104
127
|
const roles = (await section(sections, "roles", async () => {
|
|
105
|
-
const [names, assignments] = await Promise.all([roleNames(ctx), roleAssignments(ctx)]);
|
|
128
|
+
const [names, { items: assignments, truncated }] = await Promise.all([roleNames(ctx), roleAssignments(ctx)]);
|
|
106
129
|
return {
|
|
130
|
+
truncated,
|
|
107
131
|
list: assignments.map((a) => ({
|
|
108
132
|
role: names.get(a.roleDefinitionId)?.displayName ?? a.roleDefinitionId,
|
|
109
133
|
roleId: a.roleDefinitionId,
|
|
@@ -152,7 +176,10 @@ export async function collectSnapshot(ctx, opts = {}) {
|
|
|
152
176
|
});
|
|
153
177
|
let note;
|
|
154
178
|
try {
|
|
155
|
-
const { items: grants } = await collectAll(ctx, "/oauth2PermissionGrants", {}, { top: false, max: 5000 });
|
|
179
|
+
const { items: grants, truncated: grantsCut } = await collectAll(ctx, "/oauth2PermissionGrants", {}, { top: false, max: 5000 });
|
|
180
|
+
// recorded only when cut (or failed, below): a comparison leaves delegated consents out then
|
|
181
|
+
if (grantsCut)
|
|
182
|
+
sections.delegatedGrants = { ok: true, truncated: true, note: "delegated consents cut at 5000 grants: they are not compared" };
|
|
156
183
|
for (const g of grants) {
|
|
157
184
|
let app = apps.get(g.clientId);
|
|
158
185
|
if (!app) {
|
package/dist/review/model.js
CHANGED
|
@@ -78,6 +78,65 @@ const setDiff = (a, b) => {
|
|
|
78
78
|
const sb = new Set(b);
|
|
79
79
|
return a.filter((x) => !sb.has(x));
|
|
80
80
|
};
|
|
81
|
+
/**
|
|
82
|
+
* Sections each comparison reads, in BOTH snapshots. A section not read on either side makes the entry
|
|
83
|
+
* "not evaluated" — its data was stored as an empty list, which is not "every object deleted / created".
|
|
84
|
+
*/
|
|
85
|
+
export const DIFF_DEPENDS = {
|
|
86
|
+
users_created: ["users"],
|
|
87
|
+
users_deleted: ["users"],
|
|
88
|
+
guests_new: ["users"],
|
|
89
|
+
users_disabled: ["users"],
|
|
90
|
+
users_enabled: ["users"],
|
|
91
|
+
// without skus a licence is its GUID: a name compared with a GUID is not a reassignment
|
|
92
|
+
licenses_changed: ["users", "skus"],
|
|
93
|
+
groups_created: ["groups"],
|
|
94
|
+
groups_deleted: ["groups"],
|
|
95
|
+
// channels are read from the teams of the group list
|
|
96
|
+
members_joined: ["groups", "channels"],
|
|
97
|
+
members_left: ["groups", "channels"],
|
|
98
|
+
owners_new: ["groups", "channels"],
|
|
99
|
+
owners_removed: ["groups"],
|
|
100
|
+
admins_new: ["roles"],
|
|
101
|
+
admins_removed: ["roles"],
|
|
102
|
+
apps_new: ["applications"],
|
|
103
|
+
app_consents_new: ["applications"],
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Among DIFF_DEPENDS, the sections that hold only PART of an entry. One not read on either side leaves that
|
|
107
|
+
* part out — named, the entry "partial" — instead of making the whole entry "not evaluated": without
|
|
108
|
+
* ChannelMember.Read.All the groups and teams are still read, and their entries and exits still compared.
|
|
109
|
+
* The others are needed whole: no group list means no team, hence no channel (collect.ts), and licences
|
|
110
|
+
* without skus are GUIDs on one side. (Delegated consents, read apart, are already left out the same way.)
|
|
111
|
+
*/
|
|
112
|
+
export const DIFF_PARTIAL_DEPENDS = {
|
|
113
|
+
members_joined: ["channels"],
|
|
114
|
+
members_left: ["channels"],
|
|
115
|
+
owners_new: ["channels"],
|
|
116
|
+
};
|
|
117
|
+
const LIST_NOUN = { users: "account", groups: "group", channels: "private/shared channel", roles: "admin role assignment", applications: "application" };
|
|
118
|
+
/** Why a snapshot's sections cannot be compared (failed, not configured, absent), or undefined when all were read. */
|
|
119
|
+
function sectionsUnread(s, which, deps) {
|
|
120
|
+
const reasons = deps.flatMap((n) => {
|
|
121
|
+
const st = s.sections?.[n];
|
|
122
|
+
if (st?.ok)
|
|
123
|
+
return [];
|
|
124
|
+
if (st?.notConfigured)
|
|
125
|
+
return [`section ${n} not configured`];
|
|
126
|
+
if (st)
|
|
127
|
+
return [`section ${n} failed (${(st.error ?? "").slice(0, 160)})`];
|
|
128
|
+
return [`section ${n} not recorded`];
|
|
129
|
+
});
|
|
130
|
+
return reasons.length ? `${which} snapshot: ${reasons.join(", ")}` : undefined;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* What changed between two snapshots. A section not read in either snapshot is never turned into
|
|
134
|
+
* creations or deletions: every entry depending on it (DIFF_DEPENDS) is "not evaluated", with the reason —
|
|
135
|
+
* unless it holds only part of that entry (DIFF_PARTIAL_DEPENDS): that part is left out, named, and the
|
|
136
|
+
* entry is "partial". A truncated list proves nothing about the objects present on one side only: they are
|
|
137
|
+
* left out and the entry is "partial"; a group or channel whose members were cut is left out of entries and
|
|
138
|
+
* exits, and named.
|
|
139
|
+
*/
|
|
81
140
|
export function diff(prev, cur) {
|
|
82
141
|
const users = new Map([...prev.users, ...cur.users].map((u) => [u.id, u]));
|
|
83
142
|
const label = (id) => {
|
|
@@ -87,13 +146,42 @@ export function diff(prev, cur) {
|
|
|
87
146
|
const pu = new Map(prev.users.map((u) => [u.id, u]));
|
|
88
147
|
const cu = new Map(cur.users.map((u) => [u.id, u]));
|
|
89
148
|
const out = [];
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
push(
|
|
96
|
-
|
|
149
|
+
/** Snapshots in which a section's list was cut at its cap. */
|
|
150
|
+
const cutIn = (n) => [prev.sections?.[n]?.truncated ? "previous" : "", cur.sections?.[n]?.truncated ? "current" : ""].filter(Boolean);
|
|
151
|
+
const listCut = (n) => cutIn(n).length > 0;
|
|
152
|
+
/** Why sections were not read, in either snapshot ("" when read in both). */
|
|
153
|
+
const unreadIn = (deps) => [sectionsUnread(prev, "previous", deps), sectionsUnread(cur, "current", deps)].filter(Boolean).join("; ");
|
|
154
|
+
const push = (code, title, compute) => {
|
|
155
|
+
const deps = DIFF_DEPENDS[code];
|
|
156
|
+
const partOnly = DIFF_PARTIAL_DEPENDS[code] ?? [];
|
|
157
|
+
const why = unreadIn(deps.filter((n) => !partOnly.includes(n)));
|
|
158
|
+
if (why)
|
|
159
|
+
return void out.push({ code, title, items: [], notEvaluated: why });
|
|
160
|
+
// a section holding only part of the entry, not read: that part is left out by compute() and said here
|
|
161
|
+
const leftOut = partOnly.flatMap((n) => {
|
|
162
|
+
const w = unreadIn([n]);
|
|
163
|
+
return w ? [`${LIST_NOUN[n] ?? n}s NOT compared — ${w}`] : [];
|
|
164
|
+
});
|
|
165
|
+
const r = compute();
|
|
166
|
+
const { items, partial = [] } = Array.isArray(r) ? { items: r } : r;
|
|
167
|
+
const read = deps.filter((n) => !unreadIn([n]));
|
|
168
|
+
const cut = read.flatMap((n) => (listCut(n) ? [`${LIST_NOUN[n] ?? n} list truncated in the ${cutIn(n).join(" and ")} snapshot — nothing beyond the cap is compared`] : []));
|
|
169
|
+
const text = [...leftOut, ...cut, ...partial].join("; ");
|
|
170
|
+
out.push({ code, title, items, ...(text ? { partial: text } : {}) });
|
|
171
|
+
};
|
|
172
|
+
/** Objects of one snapshot absent from the other — created or deleted, unless that list was truncated: then absence proves nothing. */
|
|
173
|
+
const onlyIn = (xs, other, key, section, where, render) => {
|
|
174
|
+
const found = xs.filter((x) => !other.has(key(x)));
|
|
175
|
+
if (!listCut(section))
|
|
176
|
+
return { items: found.map(render) };
|
|
177
|
+
return { items: [], partial: found.length ? [`${found.length} ${LIST_NOUN[section]}(s) present only in the ${where} snapshot not compared`] : [] };
|
|
178
|
+
};
|
|
179
|
+
push("users_created", "Accounts created", () => onlyIn(cur.users, pu, (u) => u.id, "users", "current", (u) => `${label(u.id)}${u.userType === "Guest" ? " — GUEST" : ""}`));
|
|
180
|
+
push("users_deleted", "Accounts deleted", () => onlyIn(prev.users, cu, (u) => u.id, "users", "previous", (u) => label(u.id)));
|
|
181
|
+
push("guests_new", "New guests", () => onlyIn(cur.users.filter((u) => u.userType === "Guest"), pu, (u) => u.id, "users", "current", (u) => label(u.id)));
|
|
182
|
+
push("users_disabled", "Accounts disabled", () => cur.users.filter((u) => pu.get(u.id)?.accountEnabled === true && u.accountEnabled === false).map((u) => label(u.id)));
|
|
183
|
+
push("users_enabled", "Accounts re-enabled", () => cur.users.filter((u) => pu.get(u.id)?.accountEnabled === false && u.accountEnabled === true).map((u) => label(u.id)));
|
|
184
|
+
push("licenses_changed", "Licences assigned / removed", () => cur.users.flatMap((u) => {
|
|
97
185
|
const p = pu.get(u.id);
|
|
98
186
|
if (!p)
|
|
99
187
|
return [];
|
|
@@ -103,17 +191,25 @@ export function diff(prev, cur) {
|
|
|
103
191
|
}));
|
|
104
192
|
const pg = new Map(prev.groups.map((g) => [g.id, g]));
|
|
105
193
|
const cg = new Map(cur.groups.map((g) => [g.id, g]));
|
|
106
|
-
|
|
107
|
-
push("
|
|
194
|
+
const groupText = (g) => `${g.displayName} (${g.kind}${g.isTeam ? ", team" : ""})`;
|
|
195
|
+
push("groups_created", "Groups / teams created", () => onlyIn(cur.groups, pg, (g) => g.id, "groups", "current", groupText));
|
|
196
|
+
push("groups_deleted", "Groups / teams deleted", () => onlyIn(prev.groups, cg, (g) => g.id, "groups", "previous", groupText));
|
|
197
|
+
// memberships: a group or channel whose members or owners were cut, in either snapshot, is left out and named
|
|
108
198
|
const joined = [];
|
|
109
199
|
const left = [];
|
|
110
200
|
const ownersNew = [];
|
|
111
201
|
const ownersGone = [];
|
|
202
|
+
const cutGroups = [];
|
|
203
|
+
const cutChannels = [];
|
|
112
204
|
for (const g of cur.groups) {
|
|
113
205
|
const p = pg.get(g.id);
|
|
114
206
|
if (!p)
|
|
115
207
|
continue;
|
|
116
208
|
const name = `${g.displayName}${g.isTeam ? " (team)" : ""}`;
|
|
209
|
+
if (g.truncated || p.truncated) {
|
|
210
|
+
cutGroups.push(name);
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
117
213
|
for (const m of setDiff(g.members, p.members))
|
|
118
214
|
joined.push(`${label(m)} → ${name}`);
|
|
119
215
|
for (const m of setDiff(p.members, g.members))
|
|
@@ -123,10 +219,36 @@ export function diff(prev, cur) {
|
|
|
123
219
|
for (const o of setDiff(p.owners, g.owners))
|
|
124
220
|
ownersGone.push(`${label(o)} no longer owns ${name}`);
|
|
125
221
|
}
|
|
222
|
+
const named = (xs) => `${xs.slice(0, 5).join(", ")}${xs.length > 5 ? `, … (${xs.length - 5} more)` : ""}`;
|
|
223
|
+
const channelName = (c) => `${c.teamName ?? c.teamId} › ${c.displayName} (${c.membershipType} channel)`;
|
|
224
|
+
// channels not read in one snapshot or both: left out of entries, exits and new owners (push says why), the ones
|
|
225
|
+
// read on the other side named — the groups and teams above are still compared
|
|
226
|
+
const channelsUnread = Boolean(unreadIn(["channels"]));
|
|
227
|
+
const channelsLeftOut = [];
|
|
228
|
+
if (channelsUnread) {
|
|
229
|
+
const readOn = ["previous", "current"].filter((w) => (w === "previous" ? prev : cur).sections?.channels?.ok);
|
|
230
|
+
if (!readOn.length)
|
|
231
|
+
channelsLeftOut.push("channels read in neither snapshot: which ones are left out is unknown");
|
|
232
|
+
for (const w of readOn) {
|
|
233
|
+
const known = (w === "previous" ? prev : cur).channels;
|
|
234
|
+
channelsLeftOut.push(known.length ? `${known.length} channel(s) left out, as read in the ${w} snapshot: ${named(known.map(channelName))}` : `the ${w} snapshot read no private/shared channel`);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
// a channel missing from the previous snapshot is new (all its members are entries) — unless a list was cut
|
|
238
|
+
const channelListCut = listCut("channels") || listCut("groups");
|
|
239
|
+
let newChannelsSkipped = 0;
|
|
126
240
|
const pc = new Map(prev.channels.map((c) => [c.channelId, c]));
|
|
127
|
-
for (const c of cur.channels) {
|
|
241
|
+
for (const c of channelsUnread ? [] : cur.channels) {
|
|
128
242
|
const p = pc.get(c.channelId);
|
|
129
|
-
const name =
|
|
243
|
+
const name = channelName(c);
|
|
244
|
+
if (!p && channelListCut) {
|
|
245
|
+
newChannelsSkipped++;
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
if (c.truncated || p?.truncated) {
|
|
249
|
+
cutChannels.push(name);
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
130
252
|
for (const m of setDiff(c.members, p?.members ?? []))
|
|
131
253
|
joined.push(`${label(m)} → ${name}`);
|
|
132
254
|
if (p)
|
|
@@ -135,21 +257,49 @@ export function diff(prev, cur) {
|
|
|
135
257
|
for (const o of setDiff(c.owners, p?.owners ?? []))
|
|
136
258
|
ownersNew.push(`${label(o)} owns ${name}`);
|
|
137
259
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
260
|
+
const groupNotes = cutGroups.length ? [`members or owners truncated in ${cutGroups.length} group(s), not compared: ${named(cutGroups)}`] : [];
|
|
261
|
+
const channelNotes = [
|
|
262
|
+
cutChannels.length ? `members truncated in ${cutChannels.length} channel(s), not compared: ${named(cutChannels)}` : "",
|
|
263
|
+
newChannelsSkipped ? `${newChannelsSkipped} private/shared channel(s) present only in the current snapshot not compared` : "",
|
|
264
|
+
].filter(Boolean);
|
|
265
|
+
const memberNotes = [...channelsLeftOut, ...groupNotes, ...channelNotes];
|
|
266
|
+
push("members_joined", "Entries in groups, teams and private/shared channels", () => ({ items: joined, partial: memberNotes }));
|
|
267
|
+
push("members_left", "Exits from groups, teams and private/shared channels", () => ({ items: left, partial: memberNotes }));
|
|
268
|
+
push("owners_new", "New owners", () => ({ items: ownersNew, partial: memberNotes }));
|
|
269
|
+
push("owners_removed", "Owners removed", () => ({ items: ownersGone, partial: groupNotes }));
|
|
142
270
|
const roleKey = (r) => `${r.roleId}|${r.principalId}|${r.scope}`;
|
|
143
271
|
const pr = new Set(prev.roles.map(roleKey));
|
|
144
272
|
const cr = new Set(cur.roles.map(roleKey));
|
|
145
|
-
|
|
146
|
-
push("
|
|
273
|
+
const roleText = (r) => `${r.principalName ?? label(r.principalId)} — ${r.role}`;
|
|
274
|
+
push("admins_new", "New admin role assignments", () => onlyIn(cur.roles, pr, roleKey, "roles", "current", roleText));
|
|
275
|
+
push("admins_removed", "Admin role assignments removed", () => onlyIn(prev.roles, cr, roleKey, "roles", "previous", roleText));
|
|
276
|
+
// delegated consents are read apart (DelegatedPermissionGrant.Read.All): not read on one side, they are left out —
|
|
277
|
+
// with the clients known only through them — rather than turned into new consents
|
|
278
|
+
const grantsUnread = ["previous", "current"].filter((w) => {
|
|
279
|
+
const st = (w === "previous" ? prev : cur).sections?.delegatedGrants;
|
|
280
|
+
return st !== undefined && (!st.ok || st.truncated);
|
|
281
|
+
});
|
|
282
|
+
const grantsNote = grantsUnread.length ? [`delegated consents not read (or truncated) in the ${grantsUnread.join(" and ")} snapshot: delegated grants and the clients known only through them are not compared`] : [];
|
|
147
283
|
const pa = new Map(prev.applications.map((a) => [a.id, a]));
|
|
148
|
-
|
|
149
|
-
push("
|
|
150
|
-
const
|
|
151
|
-
return
|
|
152
|
-
})
|
|
284
|
+
const listed = (a) => (a.appPermissions.length || a.delegatedGrants.length || a.owner === "third party") && !(grantsUnread.length && a.owner === "consented client");
|
|
285
|
+
push("apps_new", "New applications", () => {
|
|
286
|
+
const r = onlyIn(cur.applications.filter(listed), pa, (a) => a.id, "applications", "current", (a) => `${a.displayName} (${a.owner})`);
|
|
287
|
+
return { items: r.items, partial: [...(r.partial ?? []), ...grantsNote] };
|
|
288
|
+
});
|
|
289
|
+
push("app_consents_new", "New permissions consented to applications", () => {
|
|
290
|
+
let skipped = 0;
|
|
291
|
+
const items = cur.applications.flatMap((a) => {
|
|
292
|
+
const p = pa.get(a.id);
|
|
293
|
+
if (!p && listCut("applications")) {
|
|
294
|
+
skipped++;
|
|
295
|
+
return [];
|
|
296
|
+
}
|
|
297
|
+
const app = setDiff(a.appPermissions, p?.appPermissions ?? []).map((x) => `${a.displayName}: application ${x}`);
|
|
298
|
+
const delegated = grantsUnread.length ? [] : setDiff(a.delegatedGrants, p?.delegatedGrants ?? []).map((x) => `${a.displayName}: delegated ${x}`);
|
|
299
|
+
return [...app, ...delegated];
|
|
300
|
+
});
|
|
301
|
+
return { items, partial: [skipped ? `${skipped} application(s) present only in the current snapshot not compared` : "", ...grantsNote].filter(Boolean) };
|
|
302
|
+
});
|
|
153
303
|
out.push(...mailboxDiff(prev, cur));
|
|
154
304
|
return out;
|
|
155
305
|
}
|
|
@@ -209,15 +359,18 @@ function mailboxDiff(prev, cur) {
|
|
|
209
359
|
{ ...GONE, items: setDiff(before, after), ...(partial ? { partial } : {}) },
|
|
210
360
|
];
|
|
211
361
|
}
|
|
362
|
+
/** How an entry not evaluated, or evaluated with no item, reads: signals say "not evaluated" / "none", changes "NOT compared" / "no change". */
|
|
363
|
+
export const SIGNAL_WORDS = { unread: "not evaluated", none: "none" };
|
|
364
|
+
export const CHANGE_WORDS = { unread: "NOT compared", none: "no change" };
|
|
212
365
|
/** Bounded text of a list of signals or diff entries. */
|
|
213
|
-
export function renderEntries(entries, max) {
|
|
366
|
+
export function renderEntries(entries, max, words = SIGNAL_WORDS) {
|
|
214
367
|
return entries
|
|
215
368
|
.map((e) => {
|
|
216
369
|
if (e.notEvaluated)
|
|
217
|
-
return `- **${e.title}**:
|
|
370
|
+
return `- **${e.title}**: ${words.unread} — ${e.notEvaluated}`;
|
|
218
371
|
const partial = e.partial ? ` (⚠ partial — ${e.partial})` : "";
|
|
219
372
|
if (!e.items.length)
|
|
220
|
-
return `- ${e.title}: none${partial}`;
|
|
373
|
+
return `- ${e.title}: ${words.none}${partial}`;
|
|
221
374
|
const shown = e.items.slice(0, max).map((i) => ` - ${i}`);
|
|
222
375
|
return `- **${e.title}: ${e.items.length}**${partial}\n${shown.join("\n")}${e.items.length > max ? `\n - … ${e.items.length - max} more in the snapshot file` : ""}`;
|
|
223
376
|
})
|
|
@@ -3,9 +3,18 @@ import { join } from "node:path";
|
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { M365Error } from "../errors.js";
|
|
5
5
|
import { collectSnapshot } from "../review/collect.js";
|
|
6
|
-
import { diff, renderEntries, signals, SNAPSHOT_SCHEMA } from "../review/model.js";
|
|
6
|
+
import { CHANGE_WORDS, diff, renderEntries, signals, SNAPSHOT_SCHEMA } from "../review/model.js";
|
|
7
7
|
import { errorResult, jsonBlock, sizeText, textResult } from "./common.js";
|
|
8
8
|
const FILE_RE = /^m365-review-[0-9a-f-]{36}-[0-9TZ-]+\.json$/;
|
|
9
|
+
/** Said before the changes: an entry not compared, or compared in part, is not "no change". */
|
|
10
|
+
function changesCaveat(changes) {
|
|
11
|
+
const unread = changes.filter((c) => c.notEvaluated).length;
|
|
12
|
+
const partial = changes.filter((c) => !c.notEvaluated && c.partial).length;
|
|
13
|
+
return [
|
|
14
|
+
unread ? `\n⚠ ${unread} of ${changes.length} change lists NOT compared — a section was not read (failed or not configured) in one of the two snapshots: nothing is known of those changes (not "no change", not deleted)` : "",
|
|
15
|
+
partial ? `\n⚠ ${partial} change list(s) compared in part only (truncated lists, or data not read — e.g. private/shared channels left out of entries, exits and new owners): changes may be missing` : "",
|
|
16
|
+
].join("");
|
|
17
|
+
}
|
|
9
18
|
export const snapshotFileName = (s) => `m365-review-${s.tenantId}-${s.generatedAt.replace(/[:.]/g, "-")}.json`;
|
|
10
19
|
/** A previous snapshot of THIS tenant from M365_SNAPSHOT_DIR: by file name, or the most recent one. */
|
|
11
20
|
async function loadPrevious(dir, tenantId, which) {
|
|
@@ -82,16 +91,19 @@ export function registerAccessReviewTools(server, ctx, serverVersion) {
|
|
|
82
91
|
? `- Shared mailboxes reviewed: ${snap.mailboxAccess.length} (${snap.mailboxAccess.reduce((n, m) => n + m.grants.length, 0)} explicit delegated rights${snap.mailboxAccess.some((m) => m.notEvaluated?.length) ? `; rights NOT evaluated on ${snap.mailboxAccess.filter((m) => m.notEvaluated?.length).length} mailbox(es)` : ""})`
|
|
83
92
|
: `- Shared-mailbox delegations: NOT evaluated (${snap.sections.mailboxAccess?.notConfigured ? "not configured" : "section failed"} — see below)`,
|
|
84
93
|
`- Storage (mailboxes + OneDrive + sites): ${sizeText(storage)}${snap.reportsConcealed ? " — ⚠ report names concealed: storage and mailbox types are not matched to accounts" : ""}`,
|
|
85
|
-
failed.length ? `\n⚠ Sections NOT read (their signals are not evaluated):\n${failed.map(([n, s]) => `- ${n}: ${s.error}`).join("\n")}` : "",
|
|
94
|
+
failed.length ? `\n⚠ Sections NOT read (their signals are not evaluated, the changes that need them are not compared — without channels, group entries, exits and owners are still compared, ⚠ partial):\n${failed.map(([n, s]) => `- ${n}: ${s.error}`).join("\n")}` : "",
|
|
86
95
|
notConfigured.length ? `\nℹ Not covered by this configuration (not evaluated — never "none"):\n${notConfigured.map(([n, s]) => `- ${n}: ${s.error}`).join("\n")}` : "",
|
|
87
96
|
truncated.length ? `\n⚠ Truncated sections (caps reached): ${truncated.join(", ")}` : "",
|
|
88
97
|
Object.entries(snap.sections).filter(([, s]) => s.note).map(([n, s]) => `- note ${n}: ${s.note}`).join("\n"),
|
|
89
98
|
"",
|
|
90
99
|
`## Signals to review`,
|
|
91
100
|
renderEntries(sig, maxItems),
|
|
92
|
-
changes ? `\n## Changes since ${previous.snapshot.generatedAt} (${previous.file})\n${renderEntries(changes, maxItems)}` : "\n_No comparison (pass compareWith: \"latest\" on the next review)._",
|
|
101
|
+
changes ? `\n## Changes since ${previous.snapshot.generatedAt} (${previous.file})${changesCaveat(changes)}\n${renderEntries(changes, maxItems, CHANGE_WORDS)}` : "\n_No comparison (pass compareWith: \"latest\" on the next review)._",
|
|
93
102
|
"",
|
|
94
|
-
jsonBlock({
|
|
103
|
+
jsonBlock({
|
|
104
|
+
signals: Object.fromEntries(sig.map((s) => [s.code, s.notEvaluated ? "not evaluated" : s.partial ? `${s.items.length} (partial)` : s.items.length])),
|
|
105
|
+
...(changes ? { changes: Object.fromEntries(changes.map((c) => [c.code, c.notEvaluated ? "not compared" : c.partial ? `${c.items.length} (partial)` : c.items.length])) } : {}),
|
|
106
|
+
}),
|
|
95
107
|
].filter((l) => l !== "");
|
|
96
108
|
return textResult(lines.join("\n"));
|
|
97
109
|
}
|
package/dist/tools/security.js
CHANGED
|
@@ -10,8 +10,7 @@ export async function roleNames(ctx) {
|
|
|
10
10
|
}
|
|
11
11
|
/** Every active role assignment with its principal expanded. */
|
|
12
12
|
export async function roleAssignments(ctx) {
|
|
13
|
-
|
|
14
|
-
return items;
|
|
13
|
+
return collectAll(ctx, "/roleManagement/directory/roleAssignments", { $expand: "principal" }, { top: false, max: 2000 });
|
|
15
14
|
}
|
|
16
15
|
const METHOD_NAMES = {
|
|
17
16
|
passwordAuthenticationMethod: "password",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aidalinfo/m365-mcp",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "Microsoft 365 MCP server over Microsoft Graph — Entra ID users, groups and applications, licences, Teams, SharePoint, usage reports, service health, roles, MFA, audit, access review, shared mailbox delegation (Exchange Online). Read-only by default; full mode uses separate scoped identities with two-step confirmed, audited writes",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|