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

[Fleet] Make upload and registry package info consistent #126915

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
cf96755
Update docker image + set up initial validation test
kpollich Mar 3, 2022
625f582
Get validation test passing
kpollich Mar 4, 2022
5ff6ee6
Merge branch 'main' into 126695-make-upload-and-registry-package-info…
kibanamachine Mar 4, 2022
c564592
Remove erroneous test load call
kpollich Mar 4, 2022
586c08c
Address PR review + improve comments + rename validation.ts -> parse.ts
kpollich Mar 7, 2022
6a9c1e9
Merge branch 'main' into 126695-make-upload-and-registry-package-info…
kibanamachine Mar 7, 2022
62a45cc
Replace packages in fleet_packages.json
kpollich Mar 7, 2022
cae823e
Add temp debug log to debug CI failures
kpollich Mar 7, 2022
37f60f3
Use a non-colliding package in bundled package tests
kpollich Mar 7, 2022
4212c27
(debug) Add logging output
kpollich Mar 7, 2022
0f779d9
(debug) More logging
kpollich Mar 7, 2022
000f3a1
(debug) Log bundled package dir in module
kpollich Mar 7, 2022
6fdfd1f
Use absolute path for bundled packages
kpollich Mar 8, 2022
8656915
Remove debug logs + use KIBANA_BUILD_LOCATION if it exists
kpollich Mar 8, 2022
29d903c
Add support for developer.bundledPackageLocation config value
kpollich Mar 8, 2022
a316ab1
(debug) Try some more logs
kpollich Mar 8, 2022
0ba1902
(debug) Try some more logs
kpollich Mar 9, 2022
14e7b87
Fix test hopefully 🤞
kpollich Mar 9, 2022
eadab35
Fix other failing tests
kpollich Mar 9, 2022
1da1eba
Merge branch 'main' into 126695-make-upload-and-registry-package-info…
kibanamachine Mar 9, 2022
a1254e7
Merge branch 'main' into 126695-make-upload-and-registry-package-info…
kibanamachine Mar 9, 2022
dadfe20
Move default for bundled package dir to schema definition
kpollich Mar 9, 2022
5d97961
Merge branch 'main' into 126695-make-upload-and-registry-package-info…
kibanamachine Mar 9, 2022
9122a63
Merge branch 'main' into 126695-make-upload-and-registry-package-info…
kibanamachine Mar 9, 2022
bd2e6c2
Fix schema default value for bundledPackageLocation
kpollich Mar 9, 2022
bfffa79
Merge branch '126695-make-upload-and-registry-package-info-consistent…
kpollich Mar 9, 2022
f0e9da1
Fix snapshot
kpollich Mar 9, 2022
29a30e4
Fix regression in bundled packages fetch
kpollich Mar 9, 2022
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
23 changes: 22 additions & 1 deletion fleet_packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,25 @@
in order to verify package integrity.
*/

[]
[
{
"name": "apm",
"version": "8.1.0"
},
{
"name": "elastic_agent",
"version": "1.3.0"
},
{
"name": "endpoint",
"version": "1.5.0"
},
{
"name": "fleet_server",
"version": "1.1.0"
},
{
"name": "synthetics",
"version": "0.9.2"
}
]
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/common/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface FleetConfigType {
developer?: {
disableRegistryVersionCheck?: boolean;
allowAgentUpgradeSourceUri?: boolean;
bundledPackageLocation?: string;
};
}

Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/fleet/common/types/models/epm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ export enum RegistryDataStreamKeys {
}

export interface RegistryDataStream {
[key: string]: any;
[RegistryDataStreamKeys.type]: string;
[RegistryDataStreamKeys.ilm_policy]?: string;
[RegistryDataStreamKeys.hidden]?: boolean;
Expand All @@ -323,6 +324,7 @@ export interface RegistryElasticsearch {
privileges?: RegistryDataStreamPrivileges;
'index_template.settings'?: estypes.IndicesIndexSettings;
'index_template.mappings'?: estypes.MappingTypeMapping;
'ingest_pipeline.name'?: string;
}

export interface RegistryDataStreamPrivileges {
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/common/types/models/package_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,5 @@ export interface PackageSpecScreenshot {
title: string;
size?: string;
type?: string;
path?: string;
}
5 changes: 5 additions & 0 deletions x-pack/plugins/fleet/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* 2.0.
*/

import path from 'path';

import { schema } from '@kbn/config-schema';
import type { TypeOf } from '@kbn/config-schema';
import type { PluginConfigDescriptor, PluginInitializerContext } from 'src/core/server';
Expand Down Expand Up @@ -40,6 +42,8 @@ export type {
} from './types';
export { AgentNotFoundError, FleetUnauthorizedError } from './errors';

const DEFAULT_BUNDLED_PACKAGE_LOCATION = path.join(__dirname, '../target/bundled_packages');

export const config: PluginConfigDescriptor = {
exposeToBrowser: {
epm: true,
Expand Down Expand Up @@ -130,6 +134,7 @@ export const config: PluginConfigDescriptor = {
developer: schema.object({
disableRegistryVersionCheck: schema.boolean({ defaultValue: false }),
allowAgentUpgradeSourceUri: schema.boolean({ defaultValue: false }),
bundledPackageLocation: schema.string({ defaultValue: DEFAULT_BUNDLED_PACKAGE_LOCATION }),
}),
}),
};
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function useDockerRegistry() {

let dockerProcess: ChildProcess | undefined;
async function startDockerRegistryServer() {
const dockerImage = `docker.elastic.co/package-registry/distribution@sha256:8b4ce36ecdf86e6cfdf781d9df8d564a014add9afc9aec21cf2c5a68ff82d3ab`;
const dockerImage = `docker.elastic.co/package-registry/distribution@sha256:b3dfc6a11ff7dce82ba8689ea9eeb54e353c6b4bfd2d28127b20ef72fd8883e9`;

const args = ['run', '--rm', '-p', `${packageRegistryPort}:8080`, dockerImage];

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import path from 'path';
import fs from 'fs/promises';

import JSON5 from 'json5';
import { REPO_ROOT } from '@kbn/utils';

import * as Registry from '../services/epm/registry';
import { generatePackageInfoFromArchiveBuffer } from '../services/epm/archive';

import { createAppContextStartContractMock } from '../mocks';
import { appContextService } from '../services';

import { useDockerRegistry } from './helpers';

describe('validate bundled packages', () => {
const registryUrl = useDockerRegistry();
let mockContract: ReturnType<typeof createAppContextStartContractMock>;

beforeEach(() => {
mockContract = createAppContextStartContractMock({ registryUrl });
appContextService.start(mockContract);
});

async function getBundledPackageEntries() {
const configFilePath = path.resolve(REPO_ROOT, 'fleet_packages.json');
const configFile = await fs.readFile(configFilePath, 'utf8');
const bundledPackages = JSON5.parse(configFile);

return bundledPackages as Array<{ name: string; version: string }>;
}

async function setupPackageObjects() {
const bundledPackages = await getBundledPackageEntries();

const packageObjects = await Promise.all(
bundledPackages.map(async (bundledPackage) => {
const registryPackage = await Registry.getRegistryPackage(
bundledPackage.name,
bundledPackage.version
);

const packageArchive = await Registry.fetchArchiveBuffer(
bundledPackage.name,
bundledPackage.version
);

return { registryPackage, packageArchive };
})
);

return packageObjects;
}

it('generates matching package info objects for uploaded and registry packages', async () => {
const packageObjects = await setupPackageObjects();

for (const packageObject of packageObjects) {
const { registryPackage, packageArchive } = packageObject;

const archivePackageInfo = await generatePackageInfoFromArchiveBuffer(
packageArchive.archiveBuffer,
'application/zip'
);

expect(archivePackageInfo.packageInfo.data_streams).toEqual(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we test more things than the data_streams property here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am taking a look at other properties to place under test here and there don't seem to be any good candidates. policy_templates and vars were my first thoughts, but the current registry logic "fills out" variable values that we infer default for in Fleet, so these fields are unlikely to match for now. I am going to merge this PR for now, and these tests will likely change in #115032

registryPackage.packageInfo.data_streams
);
}
});
});
6 changes: 5 additions & 1 deletion x-pack/plugins/fleet/server/mocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import type { PackagePolicyServiceInterface } from '../services/package_policy';
import type { AgentPolicyServiceInterface } from '../services';
import type { FleetAppContext } from '../plugin';
import { createMockTelemetryEventsSender } from '../telemetry/__mocks__';
import type { FleetConfigType } from '../../common';
import { createFleetAuthzMock } from '../../common';
import { agentServiceMock } from '../services/agents/agent_service.mock';
import type { FleetRequestHandlerContext } from '../types';
Expand All @@ -39,11 +40,14 @@ export interface MockedFleetAppContext extends FleetAppContext {
logger: ReturnType<ReturnType<typeof loggingSystemMock.create>['get']>;
}

export const createAppContextStartContractMock = (): MockedFleetAppContext => {
export const createAppContextStartContractMock = (
configOverrides: Partial<FleetConfigType> = {}
): MockedFleetAppContext => {
const config = {
agents: { enabled: true, elasticsearch: {} },
enabled: true,
agentIdVerificationEnabled: true,
...configOverrides,
};

const config$ = of(config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { getBufferExtractor } from './extract';

export * from './cache';
export { getBufferExtractor, untarBuffer, unzipBuffer } from './extract';
export { parseAndVerifyArchiveBuffer as parseAndVerifyArchiveEntries } from './validation';
export { generatePackageInfoFromArchiveBuffer } from './parse';

export interface ArchiveEntry {
path: string;
Expand Down
Loading