Skip to content

Let Chrome deliver an organization's policy to Harbor, as a JSON string - #114

Open
samuelcole wants to merge 5 commits into
mainfrom
sam/hbr-163-chrome-managed-schema
Open

samuelcole wants to merge 5 commits into
mainfrom
sam/hbr-163-chrome-managed-schema

Conversation

@samuelcole

Copy link
Copy Markdown
Collaborator

Fixes HBR-163

Problem

Harbor reads an organization's policy from the browser's managed storage under the key policy (extension/src/policy/store.ts). Chrome delivers enterprise policy to an extension only if its manifest declares a schema (storage.managed_schema), and manifest.chrome.json didn't, so on Chrome an organization couldn't set a policy. Firefox reads managed storage from policies.json without a schema.

A field-by-field schema isn't possible. Chrome's schema format needs exactly one type per node and has no union types, and Chrome won't load an extension whose schema is invalid. A Harbor rule's action can be a string, an array or an object.

Change

  • extension/managed-schema.json (new). It declares one property, policy, of type string, with a title and description for the admin console. The maintainer's decision: on Chrome the admin sets the policy document as a JSON string.
  • extension/manifest.chrome.json declares storage.managed_schema. extension/build.mjs copies the schema into dist-chrome only; the Firefox and Safari builds are unchanged.
  • policy/store.ts loadManaged accepts the policy value as an object (Firefox) or a JSON string (Chrome). A string that doesn't parse, or isn't a version-2 document, is handled exactly as an invalid object is today: no managed policy.
  • Docs. docs/PERMISSIONS.md's policy-file paragraph and the FAQ "Can my organization centrally manage this?" describe both forms. The FAQ used to name a harbor-managed-policy.json file that Harbor never read.

Testing

  • chrome-managed-schema.test.ts checks that the Chrome manifest declares the schema and that every node has exactly one type, with no additionalProperties. It also checks that policy is a string, and that the guide's example policy, serialized with JSON.stringify, loads through Policy.load().
  • New store tests: the same document loads the same rules as an object or as a JSON string, and a malformed or wrong-version string means no managed policy.
  • Committed red first (e103623; then b1e7310 when the schema was reworked).
  • npx vitest run: 145 files, 1617 tests pass.
  • npm run build:chrome ships managed-schema.json with the manifest key. npm run build (Firefox) has no storage object.
  • tsc has the same errors as the base. Firefox browser tests: 21/21 pass.
  • An independent review found no problems.
  • Not tested: real Chrome. Branded Chrome no longer loads extensions from the command line, and enterprise policy can't be set from a test. Before merging, someone should load dist-chrome unpacked in Chrome and confirm there's no schema error on chrome://extensions. Then set a policy for the extension (on macOS, a managed preferences profile; or Chrome's policy test page) with policy as a JSON string, and confirm the rules appear (for example a deny rule shows in the sidebar's Activity "Why?").

What's left

  • As before this PR, a managed policy that's present but invalid is ignored rather than failing closed. Whether an organization's broken policy should block Harbor is a separate decision.

This PR was opened by an AI agent (Claude Code) working for the maintainer.

🤖 Generated with Claude Code

samuelcole and others added 5 commits November 23, 2026 13:47
Chrome only delivers an enterprise policy into chrome.storage.managed
if the extension's manifest declares storage.managed_schema. Red
first: this test checks the Chrome manifest declares the key, the
named schema file exists, and the schema's "policy" property accepts
a sample PolicyDocument.

Co-Authored-By: Claude Sonnet 5 (Claude Code) <noreply@anthropic.com>
…HBR-163)

Chrome only populates chrome.storage.managed for an extension that
declares storage.managed_schema in its manifest; Harbor's Chrome
manifest didn't, so an organization's enterprise policy for the
`policy` key never reached the extension. Firefox doesn't need this
(policies.json's "3rdparty" key is enough) and is untouched.

- extension/managed-schema.json describes PolicyDocument loosely in
  Chrome's restricted managed-storage schema format. allow/ask/deny/
  preview items are left unconstrained (no "type") because that format
  has no oneOf/anyOf to express "string or typed rule object".
- manifest.chrome.json: storage.managed_schema points at it.
- build.mjs copies managed-schema.json into dist-chrome/ only.
- docs/PERMISSIONS.md: corrected "Chrome needs a storage.managed_schema
  ... which Harbor doesn't declare yet" and the FAQ's stale
  harbor-managed-policy.json filename (the real key is `policy`, set
  through Chrome's enterprise policy for the extension, not a file
  Harbor reads).

Co-Authored-By: Claude Sonnet 5 (Claude Code) <noreply@anthropic.com>
Chrome's storage.managed_schema format requires exactly one type (or
$ref) per node, additionalProperties must be a schema not a boolean
and isn't allowed at the root, and there's no union type — so a
Harbor rule document (action: string | array | object) can't be
described faithfully. The maintainer decided Chrome instead gets
`policy` as a JSON string.

Red first: these tests describe the new schema shape and the string
decoding store.ts doesn't do yet.

- chrome-managed-schema.test.ts: replaces the old ad hoc conformance
  checker with direct checks of Chrome's actual rules (one type/$ref
  per node, no boolean additionalProperties, none at the root,
  `policy` typed string), plus a load test that stringifies a
  PolicyDocument like docs/PERMISSIONS.md's example and expects
  Policy.load() to accept it.
- store.test.ts: a managed policy delivered as a JSON string must
  produce the same rules as the same document delivered as an object;
  malformed or wrong-version strings must behave like an invalid
  object document.

Co-Authored-By: Claude Sonnet 5 (Claude Code) <noreply@anthropic.com>
…(HBR-163)

Chrome's docs for storage.managed_schema say each schema node needs
exactly one type or a $ref and that additionalProperties must itself
be a schema, never a boolean, and never appear at the root; an invalid
schema stops Chrome from loading the extension at all. There's also no
union type, while a Harbor rule's `action` can be a string, an array
or an object, so no Chrome schema can describe a rule document
faithfully. Maintainer's decision (2026-11-23): on Chrome, `policy` is
the policy document serialized as a JSON string.

- extension/managed-schema.json: root {type: object, properties:
  {policy: {type: string}}}. No additionalProperties anywhere, and
  every node has exactly one type.
- store.ts's loadManaged (the `loadManagedPolicy` named in the brief
  doesn't exist under that name) now accepts the managed `policy`
  value as an object (Firefox) or a JSON string (Chrome), parsing the
  string the same way loadUser() already does for the user policy. A
  string that fails JSON.parse is caught by the existing try/catch and
  treated as "no policy", same as any other error; a string that
  parses to a non-version-2 document fails the same `version === 2`
  check an invalid object document already fails. No new error path.
- docs/PERMISSIONS.md: "The policy file" and the "centrally manage"
  FAQ now say Chrome takes `policy` as a JSON string and Firefox takes
  it as an object.

Co-Authored-By: Claude Sonnet 5 (Claude Code) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (Claude Code) <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant