Skip to content
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

[7.x] [Telemetry] use prod keys (#63263) #63278

Merged
merged 1 commit into from
Apr 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
"@elastic/filesaver": "1.1.2",
"@elastic/good": "8.1.1-kibana2",
"@elastic/numeral": "2.4.0",
"@elastic/request-crypto": "1.1.2",
"@elastic/request-crypto": "1.1.4",
"@elastic/ui-ace": "0.2.3",
"@hapi/good-squeeze": "5.2.1",
"@hapi/wreck": "^15.0.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export const mockEncrypt = jest.fn();
export const createRequestEncryptor = jest.fn().mockResolvedValue({
encrypt: mockEncrypt,
});

jest.doMock('@elastic/request-crypto', () => ({
createRequestEncryptor,
}));
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,9 @@
* specific language governing permissions and limitations
* under the License.
*/

import { createRequestEncryptor, mockEncrypt } from './encrypt.test.mocks';
import { telemetryJWKS } from './telemetry_jwks';
import { encryptTelemetry, getKID } from './encrypt';
import { createRequestEncryptor } from '@elastic/request-crypto';

jest.mock('@elastic/request-crypto', () => ({
createRequestEncryptor: jest.fn().mockResolvedValue({
encrypt: jest.fn(),
}),
}));

describe('getKID', () => {
it(`returns 'kibana_dev' kid for development`, async () => {
Expand All @@ -42,9 +35,25 @@ describe('getKID', () => {
});

describe('encryptTelemetry', () => {
afterEach(() => {
mockEncrypt.mockReset();
});

it('encrypts payload', async () => {
const payload = { some: 'value' };
await encryptTelemetry(payload, true);
await encryptTelemetry(payload, { isProd: true });
expect(createRequestEncryptor).toBeCalledWith(telemetryJWKS);
});

it('uses kibana kid on { isProd: true }', async () => {
const payload = { some: 'value' };
await encryptTelemetry(payload, { isProd: true });
expect(mockEncrypt).toBeCalledWith('kibana', payload);
});

it('uses kibana_dev kid on { isProd: false }', async () => {
const payload = { some: 'value' };
await encryptTelemetry(payload, { isProd: false });
expect(mockEncrypt).toBeCalledWith('kibana_dev', payload);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function getKID(isProd = false): string {
return isProd ? 'kibana' : 'kibana_dev';
}

export async function encryptTelemetry(payload: any, isProd = false): Promise<string[]> {
export async function encryptTelemetry(payload: any, { isProd = false } = {}): Promise<string[]> {
const kid = getKID(isProd);
const encryptor = await createRequestEncryptor(telemetryJWKS);
const clusters = [].concat(payload);
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/telemetry_collection_manager/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export class TelemetryCollectionManagerPlugin
if (config.unencrypted) {
return optInStats;
}
return encryptTelemetry(optInStats, this.isDev);
return encryptTelemetry(optInStats, { isProd: !this.isDev });
}
} catch (err) {
this.logger.debug(`Failed to collect any opt in stats with registered collections.`);
Expand Down Expand Up @@ -205,7 +205,8 @@ export class TelemetryCollectionManagerPlugin
if (config.unencrypted) {
return usageData;
}
return encryptTelemetry(usageData, this.isDev);

return encryptTelemetry(usageData, { isProd: !this.isDev });
}
} catch (err) {
this.logger.debug(
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1353,10 +1353,10 @@
resolved "https://registry.yarnpkg.com/@elastic/numeral/-/numeral-2.4.0.tgz#883197b7f4bf3c2dd994f53b274769ddfa2bf79a"
integrity sha512-uGBKGCNghTgUZPHClji/00v+AKt5nidPTGOIbcT+lbTPVxNB6QPpPLGWtXyrg3QZAxobPM/LAZB1mAqtJeq44Q==

"@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==
"@elastic/request-crypto@1.1.4":
version "1.1.4"
resolved "https://registry.yarnpkg.com/@elastic/request-crypto/-/request-crypto-1.1.4.tgz#2189d5fea65f7afe1de9f5fa3d0dd420e93e3124"
integrity sha512-D5CzSGKkM6BdrVB/HRRTheMsNQOcd2FMUup0O/1hIGUBE8zHh2AYbmSNSpD6LyQAgY39mGkARUi/x+SO0ccVvg==
dependencies:
"@elastic/node-crypto" "1.1.1"
"@types/node-jose" "1.1.0"
Expand Down