-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Telemetry] update crypto packages #62469
Changes from 9 commits
fba71d0
4e9c932
5e44e78
b80e13b
19ab24a
2cd9562
4d41db1
bed4eb4
74c17a3
5ef32c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,9 +43,11 @@ export const executeJobFactory: ExecuteJobFactory<ESQueueWorkerExecuteFn< | |
} = job; | ||
|
||
const decryptHeaders = async () => { | ||
let decryptedHeaders; | ||
try { | ||
decryptedHeaders = await crypto.decrypt(headers); | ||
if (typeof headers !== 'string') { | ||
throw new Error('Job headers are missing'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wrap the error message in i18n ? |
||
} | ||
return await crypto.decrypt(headers); | ||
} catch (err) { | ||
logger.error(err); | ||
throw new Error( | ||
|
@@ -58,7 +60,6 @@ export const executeJobFactory: ExecuteJobFactory<ESQueueWorkerExecuteFn< | |
) | ||
); // prettier-ignore | ||
} | ||
return decryptedHeaders; | ||
}; | ||
|
||
const fakeRequest = KibanaRequest.from({ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,7 +58,13 @@ export const executeJobFactory: ExecuteJobFactory<ImmediateExecuteFn< | |
let decryptedHeaders: Record<string, unknown>; | ||
const serializedEncryptedHeaders = job.headers; | ||
try { | ||
decryptedHeaders = await crypto.decrypt(serializedEncryptedHeaders); | ||
if (typeof serializedEncryptedHeaders !== 'string') { | ||
throw new Error('Job headers are missing'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like we'd want this wrapped in i18n.translate too |
||
} | ||
decryptedHeaders = (await crypto.decrypt(serializedEncryptedHeaders)) as Record< | ||
string, | ||
unknown | ||
>; | ||
} catch (err) { | ||
jobLogger.error(err); | ||
throw new Error( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,10 @@ | |
|
||
import nodeCrypto from '@elastic/node-crypto'; | ||
|
||
export function cryptoFactory(encryptionKey: string | undefined) { | ||
export function cryptoFactory(encryptionKey?: string) { | ||
if (typeof encryptionKey !== 'string') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This will type guard the parameter. |
||
throw new Error('Encryption Key required.'); | ||
} | ||
|
||
return nodeCrypto({ encryptionKey }); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,10 +116,6 @@ export interface ConditionalHeadersConditions { | |
basePath: string; | ||
} | ||
|
||
export interface CryptoFactory { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not needed anymore since |
||
decrypt: (headers?: string) => any; | ||
} | ||
|
||
export interface IndexPatternSavedObject { | ||
attributes: { | ||
fieldFormatMap: string; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,7 @@ | |
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
// @ts-ignore | ||
import nodeCrypto from '@elastic/node-crypto'; | ||
import nodeCrypto, { Crypto } from '@elastic/node-crypto'; | ||
import stringify from 'json-stable-stringify'; | ||
import typeDetect from 'type-detect'; | ||
import { Logger } from 'src/core/server'; | ||
|
@@ -49,10 +48,7 @@ export function descriptorToArray(descriptor: SavedObjectDescriptor) { | |
* attributes. | ||
*/ | ||
export class EncryptedSavedObjectsService { | ||
private readonly crypto: Readonly<{ | ||
encrypt<T>(valueToEncrypt: T, aad?: string): Promise<string>; | ||
decrypt<T>(valueToDecrypt: string, aad?: string): Promise<T>; | ||
}>; | ||
private readonly crypto: Readonly<Crypto>; | ||
|
||
/** | ||
* Map of all registered saved object types where the `key` is saved object type and the `value` | ||
|
@@ -229,10 +225,10 @@ export class EncryptedSavedObjectsService { | |
} | ||
|
||
try { | ||
decryptedAttributes[attributeName] = await this.crypto.decrypt( | ||
decryptedAttributes[attributeName] = (await this.crypto.decrypt( | ||
attributeValue, | ||
encryptionAAD | ||
); | ||
)) as string; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Any chance we can update the types for decrypt<T>(valueToDecrypt: string, aad?: string): Promise<T>; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @legrego we actually had a heated discussion about the same in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the explanation @afharo! |
||
} catch (err) { | ||
this.logger.error(`Failed to decrypt "${attributeName}" attribute: ${err.message || err}`); | ||
this.audit.decryptAttributeFailure(attributeName, descriptor); | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1343,27 +1343,22 @@ | |
resolved "https://registry.yarnpkg.com/@elastic/maki/-/maki-6.2.0.tgz#d0a85aa248bdc14dca44e1f9430c0b670f65e489" | ||
integrity sha512-QkmRNpEY4Dy6eqwDimR5X9leMgdPFjdANmpEIwEW1XVUG2U4YtB2BXhDxsnMmNTUrJUjtnjnwgwBUyg0pU0FTg== | ||
|
||
"@elastic/node-crypto@^0.1.2": | ||
version "0.1.2" | ||
resolved "https://registry.yarnpkg.com/@elastic/node-crypto/-/node-crypto-0.1.2.tgz#c18ac282f635e88f041cc1555d806e492ca8f3b1" | ||
integrity sha1-wYrCgvY16I8EHMFVXYBuSSyo87E= | ||
|
||
"@elastic/node-crypto@^1.0.0": | ||
version "1.0.0" | ||
resolved "https://registry.yarnpkg.com/@elastic/node-crypto/-/node-crypto-1.0.0.tgz#4d325df333fe1319556bb4d54214098ada1171d4" | ||
integrity sha512-bbjbEyILPRTRt0xnda18OttLtlkJBPuXx3CjISUSn9jhWqHoFMzfOaZ73D5jxZE2SaFZUrJYfPpqXP6qqPufAQ== | ||
"@elastic/[email protected]": | ||
version "1.1.1" | ||
resolved "https://registry.yarnpkg.com/@elastic/node-crypto/-/node-crypto-1.1.1.tgz#619b70322c9cce4a7ee5fbf8f678b1baa7f06095" | ||
integrity sha512-F6tIk8Txdqjg8Siv60iAvXzO9ZdQI87K3sS/fh5xd2XaWK+T5ZfqeTvsT7srwG6fr6uCBfuQEJV1KBBl+JpLZA== | ||
|
||
"@elastic/[email protected]": | ||
version "2.4.0" | ||
resolved "https://registry.yarnpkg.com/@elastic/numeral/-/numeral-2.4.0.tgz#883197b7f4bf3c2dd994f53b274769ddfa2bf79a" | ||
integrity sha512-uGBKGCNghTgUZPHClji/00v+AKt5nidPTGOIbcT+lbTPVxNB6QPpPLGWtXyrg3QZAxobPM/LAZB1mAqtJeq44Q== | ||
|
||
"@elastic/request-crypto@^1.0.2": | ||
version "1.0.2" | ||
resolved "https://registry.yarnpkg.com/@elastic/request-crypto/-/request-crypto-1.0.2.tgz#bf27bf009227166f3eeb2b5193a108752335ebd3" | ||
integrity sha512-8FtGYl7LebhmJmEDWiGn3MorvNiGWSYPqhvgRlKXjNakEuLoPBBe0DHxbwLkj08CMLWczXcO2ixqBPY7fEhJpA== | ||
"@elastic/request-crypto@1.1.2": | ||
version "1.1.2" | ||
resolved "https://registry.yarnpkg.com/@elastic/request-crypto/-/request-crypto-1.1.2.tgz#2e323550f546f6286994126d462a9ea480a3bfb1" | ||
integrity sha512-i73wjj1Qi8dGJIy170Z8xyJ760mFNjTbdmcp/nEczqWD0miNW6I5wZ5MNrv7M6CXn2m1wMXiT6qzDYd93Hv1Dw== | ||
dependencies: | ||
"@elastic/node-crypto" "^0.1.2" | ||
"@elastic/node-crypto" "1.1.1" | ||
"@types/node-jose" "1.1.0" | ||
node-jose "1.1.0" | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nodeCrypto
will throw an error when callingBuffer.from
if it was not passed a string or a buffer https://github.com/elastic/node-crypto/blob/master/src/crypto.ts#L133This will throw a more readable error and safe-guard the type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this error message should be wrapped in
i18n.translate
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I havent wrapped them in
i18n.translate
because this is the actual error payload and not the error message we are showing to the user.The error message to the user is already i18n wrapped:
'Failed to decrypt report job data. Please ensure that {encryptionKey} is set and re-generate this report. {err}'
.I've wrapped them with
i18n.translation
; just explaining my thought process about that one.