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

Add validation rule to ensure security capability depending on security-rule assets #820

Merged
merged 9 commits into from
Oct 23, 2024

Conversation

mrodm
Copy link
Contributor

@mrodm mrodm commented Oct 17, 2024

What does this PR do?

Add a new validation rule to ensure that security capability is added in the manifest if there is any security-rule asset (in Kibana folder).

Additional changes:

  • Update junit plugin up to 2.5.0, so skipped tests can be notified too.
  • Ensure each junit step reports using the required files.

Why is it important?

Currently, there are just two packages using security-rule assets. Both packages have defined the security capability.

This PR ensures that packages containing this kind of security-rule assets are not listed as available to be installed in Observability Serverless projects.

Checklist

Related issues

mrodm added 2 commits October 17, 2024 15:39
This validation rule checks if there is any security-rule asset in
kibana folder. If there is any, then security capability must be
defined as part of the package manifest.
@mrodm mrodm self-assigned this Oct 17, 2024
@mrodm mrodm changed the title Add security rule validation check Add validation rule to ensure security capability depending on security-rule assets Oct 17, 2024
@mrodm
Copy link
Contributor Author

mrodm commented Oct 17, 2024

test integrations

@elastic-vault-github-plugin-prod

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

@mrodm
Copy link
Contributor Author

mrodm commented Oct 17, 2024

/test

- junit-annotate#v2.4.1:
artifacts: "*.xml"
- junit-annotate#v2.5.0:
artifacts: "build/test-results/*.xml"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ensures that this step just downloads and process the XML files from the unit test steps (linux and windows).

Comment on lines 41 to 45
if !slices.Contains(capabilities, "security") {
return specerrors.ValidationErrors{
specerrors.NewStructuredErrorf("found security rule assets in package but security capability is missing in package manifest"),
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we check that none of the observability capabilities are defined too?https://github.com/elastic/kibana/blob/77102c1854bba7253da5363168e8aafb66a34579/config/serverless.oblt.yml#L145

As this validation is defined now, it just enforces to be present security capability.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Something like:

	if slices.Contains(capabilities, "observability") || slices.Contains(capabilities, "apm") || slices.Contains(capabilities, "uptime") {
		return specerrors.ValidationErrors{
			specerrors.NewStructuredErrorf("found security rule assets in package but observability capabilities are defined in package manifest"),
		}
	}

The issue here is if those capabilities are modified in Kibana or a new one is added.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or maybe ensure that just one capability is defined, and that one is "security" ?
Currently, it is just allowed "security":
https://github.com/elastic/kibana/blob/6f4346e4e6f61cf67db50fbe7ce0836c0317cc09/config/serverless.security.yml#L77

That would need to update good_v2 and good_v3 packages (manifests) to just have security capability.

Copy link
Member

Choose a reason for hiding this comment

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

It would be enough with checking that it contains the security capability. If the package has security assets and the deployment has the security capability, it doesn't matter if it also has the observability capability.
If there were a type of project with both capabilities, a package with the security capability should work there, as well as a package with both capabilities.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perfect, I agree with that too. Thanks!

@mrodm mrodm marked this pull request as ready for review October 17, 2024 15:45
@mrodm mrodm requested a review from a team as a code owner October 17, 2024 15:45
@mrodm
Copy link
Contributor Author

mrodm commented Oct 17, 2024

/test

Comment on lines 41 to 45
if !slices.Contains(capabilities, "security") {
return specerrors.ValidationErrors{
specerrors.NewStructuredErrorf("found security rule assets in package but security capability is missing in package manifest"),
}
}
Copy link
Member

Choose a reason for hiding this comment

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

It would be enough with checking that it contains the security capability. If the package has security assets and the deployment has the security capability, it doesn't matter if it also has the observability capability.
If there were a type of project with both capabilities, a package with the security capability should work there, as well as a package with both capabilities.

@@ -212,6 +212,7 @@ func (s Spec) rules(pkgType string, rootSpec spectypes.ItemSpec) validationRules
{fn: semantic.ValidateKibanaFilterPresent, since: semver.MustParse("3.0.0")},
{fn: semantic.ValidateKibanaNoLegacyVisualizations, types: []string{"integration"}, since: semver.MustParse("3.0.0")},
{fn: semantic.ValidateDimensionsPresent, types: []string{"integration"}, since: semver.MustParse("3.0.1")},
{fn: semantic.ValidateCapabilitiesRequired, since: semver.MustParse("2.10.0")}, // capabilities definition was added in spec version 2.10.0
Copy link
Member

Choose a reason for hiding this comment

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

Using the version where capabilities were introduced looks good to me, but we don't necessarily have to use this version, we could introduce the check on a later version. I guess it will depend if there are packages currently failing with this check.

Copy link
Contributor Author

@mrodm mrodm Oct 21, 2024

Choose a reason for hiding this comment

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

I set that version to ensure that the expected capabilities are added into the manifest since the first version were those fields were introduced into the manifest (2.10.0).

We could also start testing this validation from 3.0.0. That spec was the minimum one set for Serverless projects. For instance, for observability:
https://github.com/elastic/kibana/blob/68b3267ca2f76d8de4fedef622608d8685e7eceb/config/serverless.security.yml#L78

The current packages defining security-rule assets are:

  • security_detection_engine: defines spec version 3.0.0
  • tychon: defines spec version 3.2.2

Currently, there are no other packages failing in integrations because of that.
Do you think it would be better to set since: 3.0.0 to match with versioning used in Serverless rather than 2.10.0?

@@ -772,6 +769,53 @@ func TestValidateForbiddenDataStreamName(t *testing.T) {
}
}

func TestValidateCapabilitiesRequried(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Would it be possible to make this work as part of TestValidateFile? This could be reported as a failure int the manifest.yml file, as the problem would be a missing capability there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure!
I've added the file manifest path into the message error to show that the manifest is invalid. That allows me to move the test for the capabilities to "TestValidateFile".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in d16f9fd

@mrodm
Copy link
Contributor Author

mrodm commented Oct 21, 2024

test integrations

@elastic-vault-github-plugin-prod

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

@elasticmachine
Copy link

💚 Build Succeeded

History

cc @mrodm

@mrodm mrodm requested a review from jsoriano October 21, 2024 13:36
@mrodm mrodm merged commit 4d60460 into elastic:main Oct 23, 2024
3 checks passed
@mrodm mrodm deleted the add_security_rule_validation_check branch October 23, 2024 09:20
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.

[Enhancement] Add a new validation rule to ensure capability security is defined
3 participants