Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ the schema's nested
> (`managedSettings.ts` `normalizeExtraKnownMarketplaces`; `IExtraKnownMarketplaceEntry`
> in `base/common/managedSettings.ts` only types `github`/`git`).
>
> Note every **structured** key — `enabledPlugins`, `extraKnownMarketplaces`,
> Note every purely **structured** key — `enabledPlugins`, `extraKnownMarketplaces`,
> `strictKnownMarketplaces` — is declared on its policy as **`{ type: 'string' }`**: the
> object/array value is carried as a JSON string in the bag and parsed back on read (see
> [Structured settings](#structured-objectarray-settings)). The *setting's* own `type` is
Expand All @@ -108,7 +108,10 @@ the schema's nested
> `'string' | 'number' | 'boolean'`, so omitting it or declaring `'object'` / `'array'` is a
> *compile* error; declaring `'number'` / `'boolean'` compiles but then fails projection
> validation at *runtime* (the JSON-string bag value flunks `typeof value === type`), so the key
> is dropped and silently never applies.
> is dropped and silently never applies. A hybrid schema field that accepts both a scalar and a
> structured value declares the transported scalar union instead, for example
> `{ type: ['boolean', 'string'] }`; its normalizer preserves booleans and carries the structured
> form as canonical JSON.

Note the schema's `x-composition` describes the **server/runtime** layering across
enterprise/org/user. Inside VS Code the bag has already been collapsed to a single
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
"@vscode/iconv-lite-umd": "0.7.1",
"@vscode/native-watchdog": "^1.4.6",
"@vscode/os-proxy-resolver": "^0.3.0",
"@vscode/policy-watcher": "^1.4.0",
"@vscode/policy-watcher": "^1.5.0",
"@vscode/proxy-agent": "^0.44.0",
"@vscode/ripgrep-universal": "^1.18.0",
"@vscode/sandbox-runtime": "0.0.1",
Expand Down Expand Up @@ -313,7 +313,7 @@
"@vscode/native-watchdog@1.4.6": true,
"@vscode/ripgrep@1.17.1": true,
"@vscode/deviceid@0.1.5": true,
"@vscode/policy-watcher@1.4.0": true,
"@vscode/policy-watcher@1.5.0": true,
"@vscode/spdlog@0.15.8": true,
"@vscode/sqlite3@5.1.12-vscode": true,
"@vscode/windows-registry@1.2.0": true,
Expand Down
4 changes: 3 additions & 1 deletion src/vs/base/common/policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ export type PolicyValue = string | number | boolean;
export type ManagedSettingValue = PolicyValue;
export type ManagedSettingsData = Readonly<Record<string, ManagedSettingValue>>;

export type ManagedSettingType = 'string' | 'number' | 'boolean';

export interface IManagedSettingPolicyDefinition {
readonly type: 'string' | 'number' | 'boolean';
readonly type: ManagedSettingType | readonly ManagedSettingType[];
Comment thread
Copilot marked this conversation as resolved.
Outdated
}

export type IManagedSettingsPolicyDefinitions = Readonly<Record<string, IManagedSettingPolicyDefinition>>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,14 @@ suite('PolicyConfiguration', () => {
assert.deepStrictEqual(acutal.getValue('policy.booleanSetting'), true);
});

test('initialize: parses a structured internal value for a boolean policy-backed setting', async () => {
await fileService.writeFile(policyFile, VSBuffer.fromString(JSON.stringify({ 'PolicyBooleanSetting': '["mcp"]' })));

await testObject.initialize();

assert.deepStrictEqual(testObject.configurationModel.getValue('policy.booleanSetting'), ['mcp']);
});

test('initialize: with object type policy ignores policy if value is not valid', async () => {
await fileService.writeFile(policyFile, VSBuffer.fromString(JSON.stringify({ 'PolicyObjectSetting': '{"a": "b", "hello": }' })));

Expand Down
46 changes: 44 additions & 2 deletions src/vs/platform/policy/common/copilotManagedSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ export const COPILOT_DENIED_MCP_SERVERS_KEY = 'deniedMcpServers';
/** Managed-settings key that blocks standalone user/workspace customizations. */
export const COPILOT_STRICT_PLUGIN_ONLY_CUSTOMIZATION_KEY = 'strictPluginOnlyCustomization';

export const STRICT_PLUGIN_ONLY_CUSTOMIZATION_SELECTORS = ['skills', 'agents', 'hooks', 'mcp'] as const;

export type StrictPluginOnlyCustomizationSelector = typeof STRICT_PLUGIN_ONLY_CUSTOMIZATION_SELECTORS[number];

export function isStrictPluginOnlyCustomizationSelectorArray(value: unknown): value is readonly StrictPluginOnlyCustomizationSelector[] {
return Array.isArray(value) && value.every(selector => isString(selector) && STRICT_PLUGIN_ONLY_CUSTOMIZATION_SELECTORS.includes(selector as StrictPluginOnlyCustomizationSelector));
}

/** Managed-settings key that makes the enterprise MCP allowlist authoritative. */
export const COPILOT_ALLOW_MANAGED_MCP_SERVERS_ONLY_KEY = 'allowManagedMcpServersOnly';

Expand Down Expand Up @@ -150,6 +158,22 @@ export function managedSettingValue(key: string): (policyData: IPolicyData) => M
return callback;
}

export function strictPluginOnlyCustomizationValue(policyData: IPolicyData): ManagedSettingValue | undefined {
const value = policyData.managedSettings?.[COPILOT_STRICT_PLUGIN_ONLY_CUSTOMIZATION_KEY];
if (typeof value !== 'string') {
return value;
}
try {
const parsed: unknown = JSON.parse(value);
if (typeof parsed === 'boolean') {
return parsed;
}
return isStrictPluginOnlyCustomizationSelectorArray(parsed) ? value : true;
} catch {
return true;
}
}

/**
* Resolves the startup refresh control with native MDM taking precedence over the cached server
* response. A malformed native value is treated as absent, matching the managed-settings schema.
Expand Down Expand Up @@ -317,10 +341,11 @@ export function projectManagedSettings(values: ManagedSettingsData, definitions:
if (value === undefined) {
continue;
}
if (typeof value === definitions[key].type) {
const expectedTypes = definitions[key].type;
if (Array.isArray(expectedTypes) ? expectedTypes.includes(typeof value as 'string' | 'number' | 'boolean') : typeof value === expectedTypes) {
projected[key] = value;
} else {
onWarn?.(`Ignoring managed setting "${key}": expected ${definitions[key].type}, got ${typeof value}`);
onWarn?.(`Ignoring managed setting "${key}": expected ${Array.isArray(expectedTypes) ? expectedTypes.join(' or ') : expectedTypes}, got ${typeof value}`);
}
}
return projected;
Expand Down Expand Up @@ -616,11 +641,28 @@ export function normalizeManagedSettings(parsed: Record<string, unknown>, onWarn
// `__proto__` key, matching a destructuring rest. Structured keys may be nested (e.g.
// `telemetry.resourceAttributes`), so removal clones only the touched path.
let scalarRest: Record<string, unknown> = { ...parsed };
scalarRest = withNestedManagedKeyDeleted(scalarRest, COPILOT_STRICT_PLUGIN_ONLY_CUSTOMIZATION_KEY);
for (const setting of STRUCTURED_MANAGED_SETTINGS) {
scalarRest = withNestedManagedKeyDeleted(scalarRest, setting.key);
}

const result: Record<string, ManagedSettingValue> = { ...flattenManagedSettings(scalarRest) };
const strictPluginOnlyCustomization = parsed[COPILOT_STRICT_PLUGIN_ONLY_CUSTOMIZATION_KEY];
if (strictPluginOnlyCustomization !== undefined) {
if (typeof strictPluginOnlyCustomization === 'boolean') {
result[COPILOT_STRICT_PLUGIN_ONLY_CUSTOMIZATION_KEY] = strictPluginOnlyCustomization;
} else if (Array.isArray(strictPluginOnlyCustomization)) {
if (isStrictPluginOnlyCustomizationSelectorArray(strictPluginOnlyCustomization)) {
result[COPILOT_STRICT_PLUGIN_ONLY_CUSTOMIZATION_KEY] = JSON.stringify(strictPluginOnlyCustomization);
} else {
onWarn?.(`Managed setting "${COPILOT_STRICT_PLUGIN_ONLY_CUSTOMIZATION_KEY}" contains an invalid selector and will fail closed`);
result[COPILOT_STRICT_PLUGIN_ONLY_CUSTOMIZATION_KEY] = true;
}
} else {
onWarn?.(`Managed setting "${COPILOT_STRICT_PLUGIN_ONLY_CUSTOMIZATION_KEY}" has an invalid value and will fail closed`);
result[COPILOT_STRICT_PLUGIN_ONLY_CUSTOMIZATION_KEY] = true;
}
}

for (const setting of STRUCTURED_MANAGED_SETTINGS) {
const encoded = setting.encode(readNestedManagedKey(parsed, setting.key), onWarn);
Expand Down
16 changes: 9 additions & 7 deletions src/vs/platform/policy/node/nativeManagedSettingsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { IStringDictionary } from '../../../base/common/collections.js';
import { Emitter } from '../../../base/common/event.js';
import { Disposable, MutableDisposable } from '../../../base/common/lifecycle.js';
import { equals } from '../../../base/common/objects.js';
import { IManagedSettingsPolicyDefinitions, ManagedSettingsData } from '../../../base/common/policy.js';
import { IManagedSettingPolicyDefinition, IManagedSettingsPolicyDefinitions, ManagedSettingsData } from '../../../base/common/policy.js';
import { ILogService } from '../../log/common/log.js';
import { collectManagedSettingsDefinitions, INativeManagedSettingsService, MANAGED_SETTINGS_CONTROL_DEFINITIONS } from '../common/copilotManagedSettings.js';
import { PolicyDefinition, PolicyValue } from '../common/policy.js';
Expand All @@ -20,7 +20,7 @@ export interface INativePolicyWatcherOptions {

export type NativePolicyWatcherFactory = (
productName: string,
policies: Record<string, { type: 'string' | 'number' | 'boolean' }>,
policies: Record<string, IManagedSettingPolicyDefinition>,
onDidChange: (update: Record<string, PolicyValue | undefined>) => void,
options?: INativePolicyWatcherOptions,
) => Watcher;
Expand Down Expand Up @@ -87,7 +87,7 @@ export class NativeManagedSettingsService extends Disposable implements INativeM

private async updateWatcherAndTrack(version: number): Promise<void> {
try {
await this.updateWatcher();
await this.updateWatcher(version);
} catch (error) {
if (this.initializationVersion === version) {
this.initializationPromise = undefined;
Expand All @@ -107,7 +107,7 @@ export class NativeManagedSettingsService extends Disposable implements INativeM
return changed;
}

private async updateWatcher(): Promise<void> {
private async updateWatcher(version: number): Promise<void> {
const managedSettingDefinitions = this.getManagedSettingDefinitions();
this.logService.trace(`NativeManagedSettingsService#updateWatcher - Found ${Object.keys(managedSettingDefinitions).length} managed-settings definitions`);
if (Object.keys(managedSettingDefinitions).length === 0) {
Expand All @@ -125,7 +125,9 @@ export class NativeManagedSettingsService extends Disposable implements INativeM
try {
this.logService.trace(`Creating native managed-settings watcher for productName ${this.productName}`);
this.watcher.value = createWatcher(this.productName, managedSettingDefinitions, update => {
this._onDidManagedSettingsChange(update as Record<string, PolicyValue | undefined>);
if (this.initializationVersion === version) {
this._onDidManagedSettingsChange(update as Record<string, PolicyValue | undefined>);
}
Comment thread
digitarald marked this conversation as resolved.
Outdated
c();
}, this.watcherOptions);
} catch (err) {
Expand All @@ -142,8 +144,8 @@ export class NativeManagedSettingsService extends Disposable implements INativeM
* watcher our internal state: it decouples the two shapes so a future field on
* `IManagedSettingPolicyDefinition` cannot silently leak across the native boundary.
*/
private getManagedSettingDefinitions(): Record<string, { type: 'string' | 'number' | 'boolean' }> {
const definitions: Record<string, { type: 'string' | 'number' | 'boolean' }> = {};
private getManagedSettingDefinitions(): Record<string, IManagedSettingPolicyDefinition> {
const definitions: Record<string, IManagedSettingPolicyDefinition> = {};
for (const key in this.watchedSettings) {
definitions[key] = { type: this.watchedSettings[key].type };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import assert from 'assert';
import { IStringDictionary } from '../../../../base/common/collections.js';
import { IPolicyData } from '../../../../base/common/defaultAccount.js';
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../base/test/common/utils.js';
import { collectManagedSettingsDefinitions, COPILOT_FORCE_REMOTE_SETTINGS_REFRESH_KEY, COPILOT_MODEL_KEY, COPILOT_TOP_LEVEL_MODEL_KEY, hasManagedSettingsDefinitions, managedModelValue, managedSettingValue, projectManagedSettings, pickManagedSettings, shouldForceRemoteSettingsRefresh } from '../../common/copilotManagedSettings.js';
import { collectManagedSettingsDefinitions, COPILOT_FORCE_REMOTE_SETTINGS_REFRESH_KEY, COPILOT_MODEL_KEY, COPILOT_STRICT_PLUGIN_ONLY_CUSTOMIZATION_KEY, COPILOT_TOP_LEVEL_MODEL_KEY, hasManagedSettingsDefinitions, managedModelValue, managedSettingValue, projectManagedSettings, pickManagedSettings, shouldForceRemoteSettingsRefresh, strictPluginOnlyCustomizationValue } from '../../common/copilotManagedSettings.js';
import { PolicyDefinition } from '../../common/policy.js';

suite('Copilot managed settings projection', () => {
Expand Down Expand Up @@ -146,6 +146,45 @@ suite('Copilot managed settings projection', () => {
);
});

test('projectManagedSettings accepts any declared scalar type', () => {
assert.deepStrictEqual({
boolean: projectManagedSettings(
{ [COPILOT_STRICT_PLUGIN_ONLY_CUSTOMIZATION_KEY]: true },
{ [COPILOT_STRICT_PLUGIN_ONLY_CUSTOMIZATION_KEY]: { type: ['boolean', 'string'] } },
),
string: projectManagedSettings(
{ [COPILOT_STRICT_PLUGIN_ONLY_CUSTOMIZATION_KEY]: '["mcp"]' },
{ [COPILOT_STRICT_PLUGIN_ONLY_CUSTOMIZATION_KEY]: { type: ['boolean', 'string'] } },
),
}, {
boolean: { [COPILOT_STRICT_PLUGIN_ONLY_CUSTOMIZATION_KEY]: true },
string: { [COPILOT_STRICT_PLUGIN_ONLY_CUSTOMIZATION_KEY]: '["mcp"]' },
});
});

test('strictPluginOnlyCustomizationValue validates structured policy values', () => {
const read = (value: string | boolean | undefined) => strictPluginOnlyCustomizationValue({
managedSettings: value === undefined ? {} : { [COPILOT_STRICT_PLUGIN_ONLY_CUSTOMIZATION_KEY]: value },
} as IPolicyData);
assert.deepStrictEqual([
read(undefined),
read(false),
read(true),
read('false'),
read('["skills","mcp"]'),
read('["skills","unknown"]'),
read('{'),
], [
undefined,
false,
true,
false,
'["skills","mcp"]',
true,
true,
]);
});

test('projectManagedSettings warns once per type mismatch', () => {
const warnings: string[] = [];
projectManagedSettings(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,18 @@ suite('normalizeManagedSettings', () => {
});
});

test('drops a non-boolean strictPluginOnlyCustomization value', () => {
assert.deepStrictEqual(normalizeManagedSettings({
[COPILOT_STRICT_PLUGIN_ONLY_CUSTOMIZATION_KEY]: ['skills', 'unknown'],
}), {});
test('normalizes selective and malformed strictPluginOnlyCustomization values', () => {
const warnings: string[] = [];
assert.deepStrictEqual([
normalizeManagedSettings({ [COPILOT_STRICT_PLUGIN_ONLY_CUSTOMIZATION_KEY]: ['skills'] }, warning => warnings.push(warning)),
normalizeManagedSettings({ [COPILOT_STRICT_PLUGIN_ONLY_CUSTOMIZATION_KEY]: ['skills', 'unknown'] }, warning => warnings.push(warning)),
normalizeManagedSettings({ [COPILOT_STRICT_PLUGIN_ONLY_CUSTOMIZATION_KEY]: null }, warning => warnings.push(warning)),
], [
{ [COPILOT_STRICT_PLUGIN_ONLY_CUSTOMIZATION_KEY]: '["skills"]' },
{ [COPILOT_STRICT_PLUGIN_ONLY_CUSTOMIZATION_KEY]: true },
{ [COPILOT_STRICT_PLUGIN_ONLY_CUSTOMIZATION_KEY]: true },
]);
assert.strictEqual(warnings.length, 2);
});

test('normalizes extraKnownMarketplaces from schema format to config dict', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import assert from 'assert';
import { Emitter, Event } from '../../../../base/common/event.js';
import { Disposable } from '../../../../base/common/lifecycle.js';
import { ManagedSettingsData } from '../../../../base/common/policy.js';
import { IManagedSettingsPolicyDefinitions, ManagedSettingsData } from '../../../../base/common/policy.js';
import { IChannel } from '../../../../base/parts/ipc/common/ipc.js';
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../base/test/common/utils.js';
import { NullLogService } from '../../../log/common/log.js';
Expand All @@ -28,6 +28,7 @@ suite('NativeManagedSettingsService', () => {
[COPILOT_FORCE_REMOTE_SETTINGS_REFRESH_KEY]: { type: 'boolean' },
[COPILOT_SANDBOX_ENABLED_KEY]: { type: 'boolean' },
});

onDidChange = callback;
callback({});
return Disposable.None;
Expand All @@ -50,8 +51,56 @@ suite('NativeManagedSettingsService', () => {
assert.deepStrictEqual(service.managedSettings, { [COPILOT_DISABLE_BYPASS_PERMISSIONS_MODE_KEY]: 'enable' });
});

test('passes scalar union definitions to the native watcher', async () => {
let watchedSettings: IManagedSettingsPolicyDefinitions = {};
const watcherFactory: NativePolicyWatcherFactory = (_productName, policies, callback) => {
watchedSettings = policies;
callback({});
return Disposable.None;
};

const service = disposables.add(new NativeManagedSettingsService(new NullLogService(), 'com.github.copilot', undefined, watcherFactory));
await service.updatePolicyDefinitions({
[policyName]: {
type: 'boolean',
managedSettings: {
strictPluginOnlyCustomization: { type: ['boolean', 'string'] },
},
},
});

assert.deepStrictEqual(watchedSettings.strictPluginOnlyCustomization, { type: ['boolean', 'string'] });
});

test('ignores callbacks from a replaced watcher', async () => {
const callbacks: Array<(update: Record<string, PolicyValue | undefined>) => void> = [];
const watcherFactory: NativePolicyWatcherFactory = (_productName, _policies, callback) => {
callbacks.push(callback);
callback({});
return Disposable.None;
};

const service = disposables.add(new NativeManagedSettingsService(new NullLogService(), 'com.github.copilot', undefined, watcherFactory));
await service.updatePolicyDefinitions({
[policyName]: {
type: 'boolean',
managedSettings: { first: { type: 'boolean' } },
},
});
await service.updatePolicyDefinitions({
[policyName]: {
type: 'boolean',
managedSettings: { second: { type: 'boolean' } },
},
});

callbacks[0]({ first: true });
callbacks[1]({ second: true });
assert.deepStrictEqual(service.managedSettings, { second: true });
});

test('watches transport controls without a managed-settings policy definition', async () => {
let watchedSettings: Record<string, { type: 'string' | 'number' | 'boolean' }> = {};
let watchedSettings: IManagedSettingsPolicyDefinitions = {};
const watcherFactory: NativePolicyWatcherFactory = (_productName, policies, callback) => {
watchedSettings = policies;
callback({ [COPILOT_FORCE_REMOTE_SETTINGS_REFRESH_KEY]: true });
Expand Down
Loading
Loading