Skip to content

Commit

Permalink
Log types of authentication requests (microsoft#187456)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmarti committed Jul 24, 2023
1 parent dad3c69 commit e6e6cd5
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/vs/workbench/api/node/proxyResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function connectProxyResolver(
const doUseHostProxy = typeof useHostProxy === 'boolean' ? useHostProxy : !initData.remote.isRemote;
const params: ProxyAgentParams = {
resolveProxy: url => extHostWorkspace.resolveProxy(url),
lookupProxyAuthorization: lookupProxyAuthorization.bind(undefined, extHostLogService, configProvider, {}),
lookupProxyAuthorization: lookupProxyAuthorization.bind(undefined, extHostLogService, mainThreadTelemetry, configProvider, {}, initData.remote.isRemote),
getProxyURL: () => configProvider.getConfiguration('http').get('proxy'),
getProxySupport: () => configProvider.getConfiguration('http').get<ProxySupportSetting>('proxySupport') || 'off',
getSystemCertificatesV1: () => certSettingV1(configProvider),
Expand Down Expand Up @@ -119,8 +119,10 @@ function configureModuleLoading(extensionService: ExtHostExtensionService, looku

async function lookupProxyAuthorization(
extHostLogService: ILogService,
mainThreadTelemetry: MainThreadTelemetryShape,
configProvider: ExtHostConfigProvider,
proxyAuthenticateCache: Record<string, string | string[] | undefined>,
isRemote: boolean,
proxyURL: string,
proxyAuthenticate: string | string[] | undefined,
state: { kerberosRequested?: boolean }
Expand All @@ -132,6 +134,7 @@ async function lookupProxyAuthorization(
extHostLogService.trace('ProxyResolver#lookupProxyAuthorization callback', `proxyURL:${proxyURL}`, `proxyAuthenticate:${proxyAuthenticate}`, `proxyAuthenticateCache:${cached}`);
const header = proxyAuthenticate || cached;
const authenticate = Array.isArray(header) ? header : typeof header === 'string' ? [header] : [];
sendTelemetry(mainThreadTelemetry, authenticate, isRemote);
if (authenticate.some(a => /^(Negotiate|Kerberos)( |$)/i.test(a)) && !state.kerberosRequested) {
try {
state.kerberosRequested = true;
Expand All @@ -149,3 +152,29 @@ async function lookupProxyAuthorization(
}
return undefined;
}

type ProxyAuthenticationClassification = {
owner: 'chrmarti';
comment: 'Data about proxy authentication requests';
authenticationType: { classification: 'PublicNonPersonalData'; purpose: 'FeatureInsight'; comment: 'Type of the authentication requested' };
extensionHostType: { classification: 'SystemMetaData'; purpose: 'FeatureInsight'; comment: 'Type of the extension host' };
};

type ProxyAuthenticationEvent = {
authenticationType: string;
extensionHostType: string;
};

let telemetrySent = false;

function sendTelemetry(mainThreadTelemetry: MainThreadTelemetryShape, authenticate: string[], isRemote: boolean) {
if (telemetrySent || !authenticate.length) {
return;
}
telemetrySent = true;

mainThreadTelemetry.$publicLog2<ProxyAuthenticationEvent, ProxyAuthenticationClassification>('proxyAuthenticationRequest', {
authenticationType: authenticate.map(a => a.split(' ')[0]).join(','),
extensionHostType: isRemote ? 'remote' : 'local',
});
}

0 comments on commit e6e6cd5

Please sign in to comment.