Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
af1b63d
add helper function to scan telemetry metadata
Hweinstock Oct 11, 2024
5984eda
rename utility function
Hweinstock Oct 11, 2024
0b44e48
fix type signature
Hweinstock Oct 11, 2024
e0cfb3f
support regex
Hweinstock Oct 14, 2024
147b9a1
update docstring
Hweinstock Oct 14, 2024
287afd5
change func signature
Hweinstock Oct 14, 2024
77a5806
support regex in the telemetry matcher
Hweinstock Oct 14, 2024
37266d2
Update packages/core/src/shared/telemetry/telemetryLogger.ts
Hweinstock Oct 14, 2024
6c3ebba
Merge branch 'master' into notInTelemetry
Hweinstock Oct 16, 2024
ce43061
error on missing key
Hweinstock Oct 16, 2024
0999351
skip chmod on windows
Hweinstock Oct 16, 2024
05eabcc
move check into its own function
Hweinstock Oct 16, 2024
f3fff88
add recursive flag
Hweinstock Oct 16, 2024
f31ac88
force wait until sshkey generated
Hweinstock Oct 16, 2024
4f36289
add comment
Hweinstock Oct 16, 2024
ab11aca
add return statement
Hweinstock Oct 16, 2024
7f0698c
dont use waitUntil
Hweinstock Oct 16, 2024
f1619e3
temporarily comment out assertion
Hweinstock Oct 16, 2024
8e50af1
use waitUntil
Hweinstock Oct 16, 2024
1a7c294
decrease timeout and interval
Hweinstock Oct 16, 2024
dfc8ab4
increase key timeout
Hweinstock Oct 16, 2024
6c8ca76
try other tests without uri
Hweinstock Oct 16, 2024
edd559c
use fsPath instead of path
Hweinstock Oct 16, 2024
acd3fb3
remove waitUntil
Hweinstock Oct 16, 2024
ac09f3f
Merge branch 'master' into notInTelemetry
Hweinstock Oct 18, 2024
bc46bdb
cancel key timeout in test
Hweinstock Oct 18, 2024
fb1381b
ignore error if key already deleted
Hweinstock Oct 18, 2024
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
7 changes: 7 additions & 0 deletions packages/core/src/shared/telemetry/telemetryLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,11 @@ export class TelemetryLogger {
public queryFull(query: MetricQuery): MetricDatum[] {
return this._metrics.filter((m) => m.MetricName === query.metricName)
}

/**
* Queries telemetry for metrics with metadata containing a keyword in the key or value
*/
public queryRegex(re: RegExp | string): MetricDatum[] {
return this._metrics.filter((m) => m.Metadata?.some((md) => md.Value?.match(re) || md.Key?.match(re)))
}
}
19 changes: 19 additions & 0 deletions packages/core/src/test/awsService/ec2/model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import { ToolkitError } from '../../../shared/errors'
import { IAM } from 'aws-sdk'
import { SshKeyPair } from '../../../awsService/ec2/sshKeyPair'
import { DefaultIamClient } from '../../../shared/clients/iamClient'
import { assertNoTelemetryMatch, createTestWorkspaceFolder } from '../../testUtil'
import { fs } from '../../../shared'
import path from 'path'

describe('Ec2ConnectClient', function () {
let client: Ec2ConnectionManager
Expand Down Expand Up @@ -144,6 +147,22 @@ describe('Ec2ConnectClient', function () {
sinon.assert.calledWith(sendCommandStub, testSelection.instanceId, 'AWS-RunShellScript')
sinon.restore()
})

it('avoids writing the keys to any telemetry metrics', async function () {
sinon.stub(SsmClient.prototype, 'sendCommandAndWait')

const testSelection = {
instanceId: 'test-id',
region: 'test-region',
}
const keyPath = path.join((await createTestWorkspaceFolder()).uri.path, 'keys')
const keys = await SshKeyPair.getSshKeyPair(keyPath, 30000)
await client.sendSshKeyToInstance(testSelection, keys, 'test-user')
const privKey = await fs.readFileText(keys.getPrivateKeyPath())
assertNoTelemetryMatch(privKey)
sinon.restore()
await keys.delete()
})
})

describe('getRemoteUser', async function () {
Expand Down
7 changes: 7 additions & 0 deletions packages/core/src/test/testUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,13 @@ export function partialDeepCompare<T>(actual: unknown, expected: T, message?: st
const partial = selectFrom(actual, ...keys(expected as object))
assert.deepStrictEqual(partial, expected, message)
}
/**
* Asserts that no metrics metadata (key OR value) matches the given regex.
* @param keyword target substring to search for
*/
export function assertNoTelemetryMatch(re: RegExp | string): void | never {
return assert.ok(globals.telemetry.logger.queryRegex(re).length === 0)
}

/**
* Finds the emitted telemetry metrics with the given `name`, then checks if the metadata fields
Expand Down
Loading