Skip to content

Conversation

teresaromero
Copy link

@teresaromero teresaromero commented Sep 26, 2025

What does this PR do?

Add validation for policy templates template_path.

Depending on the type of package, input or integration, the template_path for the policy_template can be found of different locations.

  • In the case of input type, the template_path field under policy_template is required, so if this is empty and error is thrown. If the value exist, its looked up under /agents/input folder at the root of the package.

  • In the case of integration type, the template_path is under policy_template.inputs. This field is optional at the package manifest.

    • In the case of being not-empty, validation looks for the file under /agents/input folder at the root of the package.
    • In the case of being empty, the validation looks for the assigned stream of the input. Taking the input.type as key, validation looks at all the data streams manifest looking for the stream.input name that matches the input.type. Once there is a match, the template_path of the stream is also not required.
      • In case the template_field is not empty at the stream manifest, validation checks this file exists under /agents/stream folder at the root of the stream folder (data_stream//).
      • In case the template_field is empty, the default file name stream.yml.hbs is checked.

Why is it important?

When Fleet compiles the templates of the policies and the data streams, if the file does not exist or has not been declared at the manifest, it fails. This prevents this error by validating the package before it is installed.

Checklist

  • Added unit tests for the new validation functions.

  • Added spec tests with new testdata packages.

  • I have added test packages to test/packages that prove my change is effective.

  • I have added an entry in spec/changelog.yml.

Related issues

Resolves #703

@teresaromero teresaromero requested a review from a team as a code owner September 26, 2025 09:50
@teresaromero
Copy link
Author

test-integrations

@elastic-vault-github-plugin-prod

Created or updated PR in integrations repository to test this version. Check elastic/integrations#15480

@teresaromero teresaromero force-pushed the 703-stream-yml-hbs-exists branch from 04ef625 to 05904c0 Compare September 29, 2025 13:10
@teresaromero teresaromero force-pushed the 703-stream-yml-hbs-exists branch from 38ba51b to 526c665 Compare September 29, 2025 14:25
@teresaromero teresaromero force-pushed the 703-stream-yml-hbs-exists branch from 0e0ecdb to 364d708 Compare September 30, 2025 08:41
@teresaromero
Copy link
Author

test-integrations

@elastic-vault-github-plugin-prod

Created or updated PR in integrations repository to test this version. Check elastic/integrations#15480

@teresaromero
Copy link
Author

test-integrations

@elastic-vault-github-plugin-prod

Created or updated PR in integrations repository to test this version. Check elastic/integrations#15480

@teresaromero
Copy link
Author

test-integrations

@elastic-vault-github-plugin-prod

Created or updated PR in integrations repository to test this version. Check elastic/integrations#15480

Comment on lines 53 to 55
if input.TemplatePath == "" {
continue // template_path is optional
}
Copy link
Contributor

Choose a reason for hiding this comment

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

So, in this case if there is not template_path defined, does fleet looks for any default input template ?
I was wondering if it should be added some other validation here or not.

Copy link
Author

Choose a reason for hiding this comment

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

from what i have investigated, when an integration has inputs within its policy_template, the template_paths that are not explicitly described there, are taken from the data_streams.

https://github.com/elastic/kibana/blob/main/x-pack/platform/plugins/shared/fleet/server/services/epm/packages/assets.ts#L12

there is some logic i don't fully understand but my guess is that from the assetMap, it takes the data stream name from the package manifest inputs and looks for the data stream associated to it. Perhaps the validation to be done at package spec should be that, this inputs need to have a data_stream associated to be able to "skip" describing the template?

@teresaromero teresaromero requested a review from nchaulet October 16, 2025 12:43
@teresaromero
Copy link
Author

@mrodm @nchaulet I've updated the PR taking into account how fleet handled the template_paths for integrations with inputs.

After some consideration i've realized the entry point is always the policy_template of a manifest, regardless the type of the package. Then there is the difference between inputs and integrations.

I've added the train of thought on the PR description, and updated the code to validate like so.
The test data is failing as probably the packages are not aligned with this, before changing all the packages i would like to confirm this is the way.

I've unified the validation, as i was taking into account the streams where separated from the package manifest policy.. but with this change there should be just one validation rule, as the data_streams templates should be a match with the manifest inputs ???

@teresaromero
Copy link
Author

closing this in favour of #1000
follow up PR coming for integration packages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Linter] Ensure stream.yml.hbs exists if it will be fallen back on

3 participants