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] Fix release fallback logic in Fleet package archive code #133626

Merged
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 x-pack/plugins/fleet/common/types/models/epm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ interface RegistryOverridePropertyValue {
screenshots?: RegistryImage[];
}

export type RegistryRelease = PackageSpecManifest['release'];
export type RegistryRelease = NonNullable<PackageSpecManifest['release']>;
export interface RegistryImage extends PackageSpecIcon {
path: string;
}
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/fleet/common/types/models/package_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface PackageSpecManifest {
version: string;
license?: 'basic';
type?: 'integration';
release: 'experimental' | 'beta' | 'ga';
release?: 'experimental' | 'beta' | 'ga';
categories?: Array<PackageSpecCategory | undefined>;
conditions?: PackageSpecConditions;
icons?: PackageSpecIcon[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { FLEET_APM_PACKAGE } from '../../../../common/constants';
function findReplacementsForEprPackage(
replacements: CustomIntegration[],
packageName: string,
release: 'beta' | 'experimental' | 'ga'
release?: 'beta' | 'experimental' | 'ga'
): CustomIntegration[] {
if (release === 'ga') {
return [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const mapToCard = (
let release: 'ga' | 'beta' | 'experimental' | undefined;
if ('release' in item) {
release = item.release;
} else if (item.isBeta === true) {
} else if ((item as CustomIntegration).isBeta === true) {
release = 'beta';
}

Expand Down
12 changes: 11 additions & 1 deletion x-pack/plugins/fleet/server/services/epm/archive/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import { merge } from '@kbn/std';
import yaml from 'js-yaml';
import { pick, uniq } from 'lodash';
import semverMajor from 'semver/functions/major';
import semverPrerelease from 'semver/functions/prerelease';

import type {
ArchivePackage,
Expand Down Expand Up @@ -93,7 +95,6 @@ const requiredArchivePackageProps: readonly RequiredPackageProp[] = [
'description',
'title',
'format_version',
'release',
'owner',
] as const;

Expand All @@ -108,6 +109,7 @@ const optionalArchivePackageProps: readonly OptionalPackageProp[] = [
'screenshots',
'icons',
'policy_templates',
'release',
] as const;

const registryInputProps = Object.values(RegistryInputKeys);
Expand Down Expand Up @@ -206,6 +208,14 @@ function parseAndVerifyArchive(paths: string[]): ArchivePackage {
parsed.readme = readme;
}

// If no `release` is specified, fall back to a value based on the `version` of the integration
// to maintain backwards comptability. This is a temporary measure until the `release` field is
// completely deprecated elsewhere in Fleet/Agent. See https://github.com/elastic/package-spec/issues/225
if (!parsed.release) {
parsed.release =
semverPrerelease(parsed.version) || semverMajor(parsed.version) < 1 ? 'beta' : 'ga';
}

return parsed;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export default function (providerContext: FtrProviderContext) {
.send(buf)
.expect(400);
expect(res.error.text).to.equal(
'{"statusCode":400,"error":"Bad Request","message":"Invalid top-level package manifest: one or more fields missing of name, version, description, title, format_version, release, owner"}'
'{"statusCode":400,"error":"Bad Request","message":"Invalid top-level package manifest: one or more fields missing of name, version, description, title, format_version, owner"}'
);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
paths:
{{#each paths as |path i|}}
- {{path}}
{{/each}}
exclude_files: [".gz$"]
processors:
- add_fields:
target: ''
fields:
ecs.version: 1.5.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
---
description: "Pipeline for parsing Apache HTTP Server access logs. Requires the geoip and user_agent plugins."

processors:
- grok:
field: message
patterns:
- '%{IPORHOST:destination.domain} %{IPORHOST:source.ip} - %{DATA:user.name} \[%{HTTPDATE:apache.access.time}\]
"(?:%{WORD:http.request.method} %{DATA:url.original} HTTP/%{NUMBER:http.version}|-)?"
%{NUMBER:http.response.status_code:long} (?:%{NUMBER:http.response.body.bytes:long}|-)(
"%{DATA:http.request.referrer}")?( "%{DATA:user_agent.original}")?'
- '%{IPORHOST:source.address} - %{DATA:user.name} \[%{HTTPDATE:apache.access.time}\]
"(?:%{WORD:http.request.method} %{DATA:url.original} HTTP/%{NUMBER:http.version}|-)?"
%{NUMBER:http.response.status_code:long} (?:%{NUMBER:http.response.body.bytes:long}|-)(
"%{DATA:http.request.referrer}")?( "%{DATA:user_agent.original}")?'
- '%{IPORHOST:source.address} - %{DATA:user.name} \[%{HTTPDATE:apache.access.time}\]
"-" %{NUMBER:http.response.status_code:long} -'
- \[%{HTTPDATE:apache.access.time}\] %{IPORHOST:source.address} %{DATA:apache.access.ssl.protocol}
%{DATA:apache.access.ssl.cipher} "%{WORD:http.request.method} %{DATA:url.original}
HTTP/%{NUMBER:http.version}" (-|%{NUMBER:http.response.body.bytes:long})
ignore_missing: true
- remove:
field: message
- set:
field: event.kind
value: event
- set:
field: event.category
value: web
- set:
field: event.outcome
value: success
if: "ctx?.http?.response?.status_code != null && ctx.http.response.status_code < 400"
- set:
field: event.outcome
value: failure
if: "ctx?.http?.response?.status_code != null && ctx.http.response.status_code > 399"
- grok:
field: source.address
ignore_missing: true
patterns:
- ^(%{IP:source.ip}|%{HOSTNAME:source.domain})$
- rename:
field: '@timestamp'
target_field: event.created
- date:
field: apache.access.time
target_field: '@timestamp'
formats:
- dd/MMM/yyyy:H:m:s Z
ignore_failure: true
- remove:
field: apache.access.time
ignore_failure: true
- user_agent:
field: user_agent.original
ignore_failure: true
- geoip:
field: source.ip
target_field: source.geo
ignore_missing: true
- geoip:
database_file: GeoLite2-ASN.mmdb
field: source.ip
target_field: source.as
properties:
- asn
- organization_name
ignore_missing: true
- rename:
field: source.as.asn
target_field: source.as.number
ignore_missing: true
- rename:
field: source.as.organization_name
target_field: source.as.organization.name
ignore_missing: true
- set:
field: tls.cipher
value: '{{apache.access.ssl.cipher}}'
if: ctx?.apache?.access?.ssl?.cipher != null

- script:
lang: painless
if: ctx?.apache?.access?.ssl?.protocol != null
source: >-
def parts = ctx.apache.access.ssl.protocol.toLowerCase().splitOnToken("v");
if (parts.length != 2) {
return;
}
if (parts[1].contains(".")) {
ctx.tls.version = parts[1];
} else {
ctx.tls.version = parts[1] + ".0";
}
ctx.tls.version_protocol = parts[0];

on_failure:
- set:
field: error.message
value: '{{ _ingest.on_failure_message }}'
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
- name: data_stream.type
type: constant_keyword
description: Data stream type.
- name: data_stream.dataset
type: constant_keyword
description: Data stream dataset.
- name: data_stream.namespace
type: constant_keyword
description: Data stream namespace.
- name: '@timestamp'
type: date
description: Event timestamp.

Loading