@optimuslabs/harness-map-staging 1.5.27 → 1.5.28

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.
@@ -218,6 +218,33 @@ export function codexTenantViolation(approved, signedIn) {
218
218
  (v.allowed ? `Approved: ${v.allowed}. ` : '') +
219
219
  'Run `codex logout`, then sign in to an approved workspace.');
220
220
  }
221
+ /**
222
+ * Whether a personal account's `@<domain>` tenant is on a team domain: an allowlisted domain that
223
+ * someone on an approved team or enterprise tenant signs in with (any vendor's). A subdomain counts.
224
+ */
225
+ export function onTeamDomain(tenant, teamDomains) {
226
+ if (!tenant.startsWith('@') || !teamDomains?.length)
227
+ return false;
228
+ const domain = tenant.slice(1);
229
+ return teamDomains.some((d) => domain === d || domain.endsWith(`.${d}`));
230
+ }
231
+ /**
232
+ * The block message for Cursor's login, else null. A login on a team is checked against the
233
+ * approved teams. A personal account is only checked once its email is on a team domain; then it
234
+ * is blocked unless an admin approved that personal tenant (`@<domain>`).
235
+ */
236
+ export function cursorLoginViolation(approved, signedIn, teamDomains) {
237
+ if (!signedIn)
238
+ return null;
239
+ const checked = signedIn.team_ids.length > 0 || cursorTenants(signedIn).some((t) => onTeamDomain(t, teamDomains));
240
+ return checked ? cursorTeamViolation(approved, signedIn) : null;
241
+ }
242
+ /** The block message for Codex's login, else null; a personal plan is checked as Cursor's is. */
243
+ export function codexLoginViolation(approved, signedIn, teamDomains) {
244
+ const tenants = signedIn ? codexTenants(signedIn) : null;
245
+ const checked = tenants?.some((t) => !t.startsWith('@') || onTeamDomain(t, teamDomains));
246
+ return checked ? codexTenantViolation(approved, signedIn) : null;
247
+ }
221
248
  /**
222
249
  * The org Claude Desktop is signed into now, for its Code tab's prompts, or null when unknown.
223
250
  *
@@ -24,7 +24,7 @@ import { tryResolveHardwareUuid } from './log_config_files/runtime/hardware_uuid
24
24
  import { cursorAutofixDefersInlineVerify, syncRemediations, } from './log_config_files/runtime/remediation_sync.js';
25
25
  import { loadEndpointBase } from './log_config_files/sender/endpoint_config.js';
26
26
  import { formatRemediationChangePreviewForApplied } from './remediation_change_preview.js';
27
- import { agentApprovalViolation, approvedTenantViolation, codexTenantViolation, codexTenants, emailAllowlistViolation, cursorTeamViolation, readClaudeDesktopSignedInTenant, readClaudeSignedInTenant, readCodexSignedIn, readCursorSignedInTeams, } from './approved_tenant_gate.js';
27
+ import { agentApprovalViolation, approvedTenantViolation, codexLoginViolation, emailAllowlistViolation, cursorLoginViolation, readClaudeDesktopSignedInTenant, readClaudeSignedInTenant, readCodexSignedIn, readCursorSignedInTeams, } from './approved_tenant_gate.js';
28
28
  const MANIFEST_STALE_MS = 7 * 24 * 60 * 60 * 1000;
29
29
  /** After verified (or failed verify), push enforcement + session log immediately — do not wait for background runner. */
30
30
  async function flushRemediationOutcomeToServer(complianceLogPath) {
@@ -265,23 +265,18 @@ function loginEmail(agent) {
265
265
  }
266
266
  /** Why this agent's signed-in tenant is not approved, or null when it is (or cannot be read). */
267
267
  function tenantViolation(agent) {
268
- const approved = readRemediationInstructionsFile().approved_tenants;
268
+ const { approved_tenants: approved, team_email_domains: teamDomains } = readRemediationInstructionsFile();
269
269
  if (agent === 'claude')
270
270
  return approvedTenantViolation('claude', approved, readClaudeSignedInTenant());
271
271
  if (agent === 'claude_desktop') {
272
272
  return approvedTenantViolation('claude_desktop', approved, readClaudeDesktopSignedInTenant());
273
273
  }
274
- // A personal account (Cursor on no team, Codex on a personal plan) has no tenant to approve: only
275
- // the email allowlist decides it.
276
- if (agent === 'codex') {
277
- const signedIn = readCodexSignedIn();
278
- const tenants = signedIn ? codexTenants(signedIn) : null;
279
- return tenants?.some((t) => !t.startsWith('@')) ? codexTenantViolation(approved, signedIn) : null;
280
- }
281
- if (agent === 'cursor') {
282
- const signedIn = readCursorSignedInTeams();
283
- return signedIn?.team_ids.length ? cursorTeamViolation(approved, signedIn) : null;
284
- }
274
+ // A personal account (Cursor on no team, Codex on a personal plan) is left to the email allowlist
275
+ // until its domain is a team domain; then it needs its personal tenant approved.
276
+ if (agent === 'codex')
277
+ return codexLoginViolation(approved, readCodexSignedIn(), teamDomains);
278
+ if (agent === 'cursor')
279
+ return cursorLoginViolation(approved, readCursorSignedInTeams(), teamDomains);
285
280
  return null;
286
281
  }
287
282
  /** The block for a login: which check refused it and why, or null when every check passes. */
@@ -133,20 +133,29 @@ export function writeRemediationInstructionsFile(file) {
133
133
  }
134
134
  function writeInstructionsFile(file, remediationsWrittenAt) {
135
135
  // Most callers write `{ remediations }` only; keep the approval lists they didn't pass.
136
- const onDisk = readRemediationInstructionsFile();
137
- const approved_tenants = 'approved_tenants' in file ? file.approved_tenants : onDisk.approved_tenants;
138
- const unapproved_email_domains = 'unapproved_email_domains' in file ? file.unapproved_email_domains : onDisk.unapproved_email_domains;
139
- const allowed_email_domains = 'allowed_email_domains' in file ? file.allowed_email_domains : onDisk.allowed_email_domains;
140
- const approved_agents = 'approved_agents' in file ? file.approved_agents : onDisk.approved_agents;
141
136
  atomicWriteJson(getRemediationInstructionsPath(), {
142
137
  ...file,
143
- ...(approved_tenants === undefined ? {} : { approved_tenants }),
144
- ...(unapproved_email_domains === undefined ? {} : { unapproved_email_domains }),
145
- ...(allowed_email_domains === undefined ? {} : { allowed_email_domains }),
146
- ...(approved_agents === undefined ? {} : { approved_agents }),
138
+ ...keptApprovalLists(file, readRemediationInstructionsFile()),
147
139
  remediations_written_at: remediationsWrittenAt,
148
140
  });
149
141
  }
142
+ const APPROVAL_LISTS = [
143
+ 'approved_tenants',
144
+ 'unapproved_email_domains',
145
+ 'allowed_email_domains',
146
+ 'approved_agents',
147
+ 'team_email_domains',
148
+ ];
149
+ /** Each approval list from `file` when it names one, else the one on disk; absent ones left out. */
150
+ function keptApprovalLists(file, onDisk) {
151
+ const kept = {};
152
+ for (const key of APPROVAL_LISTS) {
153
+ const value = key in file ? file[key] : onDisk[key];
154
+ if (value !== undefined)
155
+ kept[key] = value;
156
+ }
157
+ return kept;
158
+ }
150
159
  /** When the remediations on disk were written: recorded, or for an older file its mtime. */
151
160
  function remediationsWrittenAtOf(onDisk) {
152
161
  if (onDisk.remediations_written_at)
@@ -167,6 +176,10 @@ export function writeUnapprovedEmailDomains(unapproved_email_domains) {
167
176
  export function writeApprovedAgents(approved_agents) {
168
177
  writeApprovalList({ approved_agents });
169
178
  }
179
+ /** Replace only the team email domains, keeping everything else on disk. */
180
+ export function writeTeamEmailDomains(team_email_domains) {
181
+ writeApprovalList({ team_email_domains });
182
+ }
170
183
  /** Replace only the email allowlist, keeping everything else on disk. */
171
184
  export function writeAllowedEmailDomains(allowed_email_domains) {
172
185
  writeApprovalList({ allowed_email_domains });
@@ -4,7 +4,7 @@ import { homedir } from 'node:os';
4
4
  import { executeBody } from '../../endpoint_client/http_transport.js';
5
5
  import { parseJsonWithJsoncFallback, parseTomlText, stringifyToml } from '../readers/file_readers.js';
6
6
  import { complianceRunnerDiag, hookRunLog, logRemediationApplyFailure } from './hook_logger.js';
7
- import { atomicWriteJson, getDeferredVscdbApplyPath, getFileCollectionVscdbContractPath, getRemediationInstructionsPath, readRemediationInstructionsFile, writeApprovedTenants, writeUnapprovedEmailDomains, writeAllowedEmailDomains, writeApprovedAgents, writeRemediationInstructionsFile, } from './management_storage.js';
7
+ import { atomicWriteJson, getDeferredVscdbApplyPath, getFileCollectionVscdbContractPath, getRemediationInstructionsPath, readRemediationInstructionsFile, writeApprovedTenants, writeUnapprovedEmailDomains, writeAllowedEmailDomains, writeTeamEmailDomains, writeApprovedAgents, writeRemediationInstructionsFile, } from './management_storage.js';
8
8
  import { readStoredAuthKey } from '../auth/auth_key_store.js';
9
9
  import { ensureAuthentication } from '../auth/auth_flow.js';
10
10
  import { createSignature } from '../sender/signing.js';
@@ -1653,6 +1653,9 @@ function storeApprovals(syncResult) {
1653
1653
  const allowedDomains = syncResult.allowed_email_domains;
1654
1654
  if (Array.isArray(allowedDomains))
1655
1655
  writeAllowedEmailDomains(lowercaseStrings(allowedDomains));
1656
+ const teamDomains = syncResult.team_email_domains;
1657
+ if (Array.isArray(teamDomains))
1658
+ writeTeamEmailDomains(lowercaseStrings(teamDomains));
1656
1659
  }
1657
1660
  async function reconcileInstructions(endpointBase, machineUuid, want) {
1658
1661
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optimuslabs/harness-map-staging",
3
- "version": "1.5.27",
3
+ "version": "1.5.28",
4
4
  "description": "CLI helpers for logging hardware UUIDs and posting startup payloads to Optimus Security.",
5
5
  "type": "module",
6
6
  "bin": {