mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[Oblt Onboarding][Auto Detect] Filter out httpjson inputs and fix accidental config backup file (#216978)
Closes https://github.com/elastic/kibana/issues/199744 * Adds a separate `sed` commands for Linux and macOS when replacing API key within the Agent config. GNU and BSD versions of `sed` treat `-i` (in-place editing) argument differently, GNU version allows `-i` without a value while BSD version requires a backup file extension even when it's empty 🫠 * Adds filtering of unsupported input types inside the integration policies. For now it only filters out `httpjson`. ## How to test 1. Go through the auto-detect flow 2. Make sure there is no `'elastic-agent.yml='` file in the Agent directory, or any other weird artifacts 3. Inspect individual integration config files, make sure they don't have `httpjson` inputs Co-authored-by: Joe Reuter <johannes.reuter@elastic.co>
This commit is contained in:
parent
07994d2706
commit
ec72d4a880
2 changed files with 27 additions and 4 deletions
|
@ -310,9 +310,14 @@ apply_elastic_agent_config() {
|
|||
# Remove existing config file including `inputs.d` directory
|
||||
rm -rf "$elastic_agent_config_path" "$(dirname "$elastic_agent_config_path")/inputs.d" &&
|
||||
# Extract new config files from downloaded archive
|
||||
tar --extract --file "$elastic_agent_tmp_config_path" --directory "$(dirname "$elastic_agent_config_path")" &&
|
||||
tar --extract --file "$elastic_agent_tmp_config_path" --directory "$(dirname "$elastic_agent_config_path")"
|
||||
# Replace placeholder with the Ingest API key
|
||||
sed -i='' "s/\${API_KEY}/$decoded_ingest_api_key/" "$elastic_agent_config_path"
|
||||
if [ "${OS}" == "Linux" ]; then
|
||||
sed -i "s/\${API_KEY}/$decoded_ingest_api_key/" "$elastic_agent_config_path"
|
||||
else
|
||||
# macOS requires an empty string for the backup extension
|
||||
sed -i '' "s/\${API_KEY}/$decoded_ingest_api_key/" "$elastic_agent_config_path"
|
||||
fi
|
||||
if [ "$?" -eq 0 ]; then
|
||||
printf "\e[32;1m✓\e[0m %s\n" "Config files written to:"
|
||||
while IFS= read -r file; do
|
||||
|
|
|
@ -12,7 +12,7 @@ import {
|
|||
FleetUnauthorizedError,
|
||||
type PackageClient,
|
||||
} from '@kbn/fleet-plugin/server';
|
||||
import { dump } from 'js-yaml';
|
||||
import { load, dump } from 'js-yaml';
|
||||
import { PackageDataStreamTypes, Output } from '@kbn/fleet-plugin/common/types';
|
||||
import { transformOutputToFullPolicyOutput } from '@kbn/fleet-plugin/server/services/output_client';
|
||||
import { OBSERVABILITY_ONBOARDING_TELEMETRY_EVENT } from '../../../common/telemetry_events';
|
||||
|
@ -481,7 +481,10 @@ async function ensureInstalledIntegrations(
|
|||
if (installSource === 'registry') {
|
||||
const installation = await packageClient.ensureInstalledPackage({ pkgName });
|
||||
const pkg = installation.package;
|
||||
const config = await packageClient.getAgentPolicyConfigYAML(pkg.name, pkg.version);
|
||||
const config = filterUnsupportedInputs(
|
||||
await packageClient.getAgentPolicyConfigYAML(pkg.name, pkg.version)
|
||||
);
|
||||
|
||||
const { packageInfo } = await packageClient.getPackage(pkg.name, pkg.version);
|
||||
|
||||
return {
|
||||
|
@ -552,6 +555,21 @@ async function ensureInstalledIntegrations(
|
|||
);
|
||||
}
|
||||
|
||||
function filterUnsupportedInputs(policyYML: string): string {
|
||||
const policy = load(policyYML);
|
||||
|
||||
if (!policy) {
|
||||
return policyYML;
|
||||
}
|
||||
|
||||
return dump({
|
||||
...policy,
|
||||
inputs: (policy.inputs || []).filter((input: any) => {
|
||||
return input.type !== 'httpjson';
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses and validates a TSV (tab-separated values) string of integrations with params.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue