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

Expose policy_templates_behavior and deployment modes for policy templates in search and package endpoints #1244

Merged
merged 7 commits into from
Oct 30, 2024
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

* Add new `discovery` parameter to search and category endpoints. [#1235](https://github.com/elastic/package-registry/pull/1235)
* Expose `policy_templates.*.deployment_modes` field in both search and package endpoints. [#1244](https://github.com/elastic/package-registry/pull/1244)
* Expose `policy_templates_behavior` field in both search and package endpoints. [#1244](https://github.com/elastic/package-registry/pull/1244)

### Deprecated

Expand Down
85 changes: 49 additions & 36 deletions packages/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,44 +61,47 @@ type FileSystemBuilder func(*Package) (PackageFileSystem, error)

// BasePackage is used for the output of the package info in the /search endpoint
type BasePackage struct {
Name string `config:"name" json:"name"`
Title *string `config:"title,omitempty" json:"title,omitempty" yaml:"title,omitempty"`
Version string `config:"version" json:"version"`
Release string `config:"release,omitempty" json:"release,omitempty"`
Source *Source `config:"source,omitempty" json:"source,omitempty" yaml:"source,omitempty"`
Description string `config:"description" json:"description"`
Type string `config:"type" json:"type"`
Download string `json:"download" yaml:"download,omitempty"`
Path string `json:"path" yaml:"path,omitempty"`
Icons []Image `config:"icons,omitempty" json:"icons,omitempty" yaml:"icons,omitempty"`
BasePolicyTemplates []BasePolicyTemplate `json:"policy_templates,omitempty"`
Conditions *Conditions `config:"conditions,omitempty" json:"conditions,omitempty" yaml:"conditions,omitempty"`
Owner *Owner `config:"owner,omitempty" json:"owner,omitempty" yaml:"owner,omitempty"`
Categories []string `config:"categories,omitempty" json:"categories,omitempty" yaml:"categories,omitempty"`
SignaturePath string `config:"signature_path,omitempty" json:"signature_path,omitempty" yaml:"signature_path,omitempty"`
Discovery *Discovery `config:"discovery,omitempty" json:"discovery,omitempty" yaml:"discovery,omitempty"`
Name string `config:"name" json:"name"`
Title *string `config:"title,omitempty" json:"title,omitempty" yaml:"title,omitempty"`
Version string `config:"version" json:"version"`
Release string `config:"release,omitempty" json:"release,omitempty"`
Source *Source `config:"source,omitempty" json:"source,omitempty" yaml:"source,omitempty"`
Description string `config:"description" json:"description"`
Type string `config:"type" json:"type"`
Download string `json:"download" yaml:"download,omitempty"`
Path string `json:"path" yaml:"path,omitempty"`
Icons []Image `config:"icons,omitempty" json:"icons,omitempty" yaml:"icons,omitempty"`
PolicyTemplatesBehavior string `config:"policy_templates_behavior,omitempty" json:"policy_templates_behavior,omitempty" yaml:"policy_templates_behavior,omitempty"`
BasePolicyTemplates []BasePolicyTemplate `json:"policy_templates,omitempty"`
Conditions *Conditions `config:"conditions,omitempty" json:"conditions,omitempty" yaml:"conditions,omitempty"`
Owner *Owner `config:"owner,omitempty" json:"owner,omitempty" yaml:"owner,omitempty"`
Categories []string `config:"categories,omitempty" json:"categories,omitempty" yaml:"categories,omitempty"`
SignaturePath string `config:"signature_path,omitempty" json:"signature_path,omitempty" yaml:"signature_path,omitempty"`
Discovery *Discovery `config:"discovery,omitempty" json:"discovery,omitempty" yaml:"discovery,omitempty"`
}

// BasePolicyTemplate is used for the package policy templates in the /search endpoint
type BasePolicyTemplate struct {
Name string `config:"name" json:"name" validate:"required"`
Title string `config:"title" json:"title" validate:"required"`
Description string `config:"description" json:"description" validate:"required"`
Icons []Image `config:"icons,omitempty" json:"icons,omitempty" yaml:"icons,omitempty"`
Categories []string `config:"categories,omitempty" json:"categories,omitempty" yaml:"categories,omitempty"`
Name string `config:"name" json:"name" validate:"required"`
Title string `config:"title" json:"title" validate:"required"`
Description string `config:"description" json:"description" validate:"required"`
Icons []Image `config:"icons,omitempty" json:"icons,omitempty" yaml:"icons,omitempty"`
Categories []string `config:"categories,omitempty" json:"categories,omitempty" yaml:"categories,omitempty"`
DeploymentModes *DeploymentModes `config:"deployment_modes,omitempty" json:"deployment_modes,omitempty" yaml:"deployment_modes,omitempty"`
}

type PolicyTemplate struct {
Name string `config:"name" json:"name" validate:"required"`
Title string `config:"title" json:"title" validate:"required"`
Description string `config:"description" json:"description" validate:"required"`
DataStreams []string `config:"data_streams,omitempty" json:"data_streams,omitempty" yaml:"data_streams,omitempty"`
Inputs []Input `config:"inputs" json:"inputs,omitempty" yaml:"inputs,omitempty"`
Multiple *bool `config:"multiple" json:"multiple,omitempty" yaml:"multiple,omitempty"`
Icons []Image `config:"icons,omitempty" json:"icons,omitempty" yaml:"icons,omitempty"`
Categories []string `config:"categories,omitempty" json:"categories,omitempty" yaml:"categories,omitempty"`
Screenshots []Image `config:"screenshots,omitempty" json:"screenshots,omitempty" yaml:"screenshots,omitempty"`
Readme *string `config:"readme,omitempty" json:"readme,omitempty" yaml:"readme,omitempty"`
Name string `config:"name" json:"name" validate:"required"`
Title string `config:"title" json:"title" validate:"required"`
Description string `config:"description" json:"description" validate:"required"`
DataStreams []string `config:"data_streams,omitempty" json:"data_streams,omitempty" yaml:"data_streams,omitempty"`
Inputs []Input `config:"inputs" json:"inputs,omitempty" yaml:"inputs,omitempty"`
Multiple *bool `config:"multiple" json:"multiple,omitempty" yaml:"multiple,omitempty"`
Icons []Image `config:"icons,omitempty" json:"icons,omitempty" yaml:"icons,omitempty"`
Categories []string `config:"categories,omitempty" json:"categories,omitempty" yaml:"categories,omitempty"`
Screenshots []Image `config:"screenshots,omitempty" json:"screenshots,omitempty" yaml:"screenshots,omitempty"`
Readme *string `config:"readme,omitempty" json:"readme,omitempty" yaml:"readme,omitempty"`
DeploymentModes *DeploymentModes `config:"deployment_modes,omitempty" json:"deployment_modes,omitempty" yaml:"deployment_modes,omitempty"`

// For purposes of "input packages"
Type string `config:"type,omitempty" json:"type,omitempty" yaml:"type,omitempty"`
Expand Down Expand Up @@ -184,6 +187,15 @@ type Download struct {
Type string `config:"type" json:"type" validate:"required"`
}

type DeploymentModes struct {
Default *DeploymentMode `config:"default,omitempty" json:"default,omitempty" yaml:"default,omitempty"`
Agentless *DeploymentMode `config:"agentless,omitempty" json:"agentless,omitempty" yaml:"agentless,omitempty"`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not added the organization, division and team fields that can also be set under agentless key:

https://github.com/elastic/package-spec/blob/cc5282374a5d062497bf0517d77a449d7176a35e/spec/integration/manifest.spec.yml#L177-L197

Should they be added? Are they necessary for Fleet?

Copy link
Member

Choose a reason for hiding this comment

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

According to the description these fields are only intended to be used internally, when the package is installed: elastic/package-spec#795
So I don't think we need to expose them here. cc @seanrathier just in case.

Copy link

@seanrathier seanrathier Oct 30, 2024

Choose a reason for hiding this comment

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

They need to be added because Kibana will send those fields to the Agentless API and then the Agentless API will tag the agentless agent deployment with that information.

Those fields should only be required if you have a deployment_modes agentless

Does that answer the question?

Copy link
Contributor Author

@mrodm mrodm Oct 30, 2024

Choose a reason for hiding this comment

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

Looking at this comment, I thought those values would be read directly from the manifest in Kibana (Fleet):
elastic/package-spec#795 (comment)

If the package is installed before sending those values to the Agentless API, could those values be read from the package manifest? If that is possible, probably it's not needed to add those fields to the API.

WDYT ? @seanrathier @jsoriano

Choose a reason for hiding this comment

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

If I am misunderstanding this request please let me know.

Are we looking to expose deployment_modes when searching for packages? If so, we don't need to expose the org, division and team in the search.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are we looking to expose deployment_modes when searching for packages? If so, we don't need to expose the org, division and team in the search.

Exactly, I think I didn't give the full context here, sorry. This question was more related to check whether or not those fields should be added in to the search and package API responses from the package registry.

So, I think it's good to proceed as it is the PR now (just exposing if the mode is enabled or not).

Thanks @seanrathier !

}

type DeploymentMode struct {
Enabled bool `config:"enabled" json:"enabled" yaml:"enabled" validate:"required"`
}

func NewDownload(p Package, t string) Download {
return Download{
Path: getDownloadPath(p, t),
Expand Down Expand Up @@ -378,11 +390,12 @@ func (p *Package) setRuntimeFields() error {
func (p *Package) setBasePolicyTemplates() {
for _, t := range p.PolicyTemplates {
baseT := BasePolicyTemplate{
Name: t.Name,
Title: t.Title,
Description: t.Description,
Categories: t.Categories,
Icons: t.Icons,
Name: t.Name,
Title: t.Title,
Description: t.Description,
Categories: t.Categories,
Icons: t.Icons,
DeploymentModes: t.DeploymentModes,
}

p.BasePolicyTemplates = append(p.BasePolicyTemplates, baseT)
Expand Down
118 changes: 118 additions & 0 deletions packages/testdata/marshaler/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,124 @@
"/package/defaultrelease/0.0.1/docs/README.md"
]
},
{
"name": "deployment_modes",
"title": "Deployment Modes",
"version": "0.0.1",
"release": "beta",
"source": {
"license": "Elastic-2.0"
},
"description": "Package containing policy templates with different deployment modes",
"type": "integration",
"download": "/epr/deployment_modes/deployment_modes-0.0.1.zip",
"path": "/package/deployment_modes/0.0.1",
"icons": [
{
"src": "/img/sample-logo.svg",
"path": "/package/deployment_modes/0.0.1/img/sample-logo.svg",
"title": "Sample logo",
"size": "32x32",
"type": "image/svg+xml"
}
],
"policy_templates_behavior": "combined_policy",
"conditions": {
"kibana": {
"version": "^8.15.2"
},
"elastic": {
"subscription": "basic"
}
},
"owner": {
"type": "elastic",
"github": "elastic/integrations"
},
"categories": [
"custom"
],
"format_version": "3.3.0",
"readme": "/package/deployment_modes/0.0.1/docs/README.md",
"license": "basic",
"screenshots": [
{
"src": "/img/sample-screenshot.png",
"path": "/package/deployment_modes/0.0.1/img/sample-screenshot.png",
"title": "Sample screenshot",
"size": "600x600",
"type": "image/png"
}
],
"assets": [
"/package/deployment_modes/0.0.1/LICENSE.txt",
"/package/deployment_modes/0.0.1/changelog.yml",
"/package/deployment_modes/0.0.1/manifest.yml",
"/package/deployment_modes/0.0.1/docs/README.md",
"/package/deployment_modes/0.0.1/img/sample-logo.svg",
"/package/deployment_modes/0.0.1/img/sample-screenshot.png"
],
"policy_templates": [
{
"name": "agentless",
"title": "Sample logs",
"description": "Collect sample logs",
"inputs": [
{
"type": "logfile",
"vars": [
{
"name": "path",
"type": "text",
"multi": false,
"required": false,
"show_user": true
},
{
"name": "tags",
"type": "text",
"multi": true,
"required": false,
"show_user": false
}
],
"title": "Collect sample logs from instances",
"description": "Collecting sample logs"
}
],
"multiple": false,
"deployment_modes": {
"default": {
"enabled": false
},
"agentless": {
"enabled": true
}
}
},
{
"name": "default",
"title": "Sample logs",
"description": "Collect sample logs",
"inputs": [
{
"type": "logfile",
"title": "Collect sample logs from instances",
"description": "Collecting sample logs"
}
],
"multiple": false,
"deployment_modes": {
"default": {
"enabled": true
},
"agentless": {
"enabled": false
}
}
}
]
},
{
"name": "ecs_style_dataset",
"title": "Default pipeline Integration",
Expand Down
2 changes: 1 addition & 1 deletion testdata/generated/categories-experimental.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
{
"id": "custom",
"title": "Custom",
"count": 17
"count": 18
},
{
"id": "datastore",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
{
"id": "custom",
"title": "Custom",
"count": 16
"count": 17
},
{
"id": "datastore",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
{
"id": "custom",
"title": "Custom",
"count": 16
"count": 17
},
{
"id": "datastore",
Expand Down
2 changes: 1 addition & 1 deletion testdata/generated/categories-prerelease.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
{
"id": "custom",
"title": "Custom",
"count": 17
"count": 18
},
{
"id": "datastore",
Expand Down
Loading