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

[UII] Restrict agentless integrations to deployments with agentless enabled #194885

Merged
merged 27 commits into from
Oct 15, 2024

Conversation

jen-huang
Copy link
Contributor

@jen-huang jen-huang commented Oct 3, 2024

Summary

Resolves #192486. This PR makes it so that on deployments without agentless enabled:

  1. Agentless-only integrations are hidden from the browse integration UI
  2. Agentless-only integrations cannot be installed via API (unless force flag is used)

⚠️ elastic/package-registry#1238 needs to be completed for the below testing steps to work. Currently EPR does not return deployment_modes property which is necessary for Fleet to know which packages are agentless.

How to test

  1. Simulate agentless being available by adding the following to kibana.yml:
xpack.fleet.agentless.enabled: true

# Simulate cloud
xpack.cloud.id: "foo"
xpack.cloud.base_url: "https://cloud.elastic.co"
xpack.cloud.organization_url: "/account/"
xpack.cloud.billing_url: "/billing/"
xpack.cloud.profile_url: "/user/settings/"
  1. Go to Integrations > Browse and enable showing Beta integrations, search for connector and you should see the agentless integrations: Elastic Connectors, GitHub & GitHub Enterprise Server Connector, Google Drive Connector
  2. Install any one of them (they all come from the same package), it should be successful
  3. Uninstall them
  4. Remove config changes to go back to a non-agentless deployment
  5. Refresh Integrations list, the three integrations should no longer appear
  6. Try installing via API, an error should appear
POST kbn:/api/fleet/epm/packages/elastic_connectors/0.0.2
  1. Try installing via API again with force flag, it should be successful:
POST kbn:/api/fleet/epm/packages/elastic_connectors/0.0.2
{
  "force": true
}

Checklist

@jen-huang jen-huang added release_note:skip Skip the PR/issue when compiling release notes Team:Fleet Team label for Observability Data Collection Fleet team backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) labels Oct 3, 2024
@jen-huang jen-huang self-assigned this Oct 3, 2024
@jen-huang jen-huang requested review from a team as code owners October 3, 2024 23:20
@elasticmachine
Copy link
Contributor

Pinging @elastic/fleet (Team:Fleet)

@kibana-ci

This comment was marked as outdated.

Copy link
Contributor

@juliaElastic juliaElastic left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@maxcold maxcold left a comment

Choose a reason for hiding this comment

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

cloud_security_posture owned change lgtm

(policyTemplate) => policyTemplate?.deployment_modes?.agentless.enabled === true
)
) {
if (isAgentlessEnabled && isAgentlessIntegrationFn(packageInfo)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: the fact that the rename was needed shows that probably isAgentlessIntegration in this file does too much. I wonder if it should check isAgentlessEnabled inside. I'd rather move this check to the consumers but I think it's out of the scope of this PR. cc @seanrathier @opauloh

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with @max that isAgentlessIntegration in this hook does not do much, however, I am trying to find another place where the helper function is imported (other than tests) and cannot find one. I think it would be better to keep it on the hook.

@elasticmachine
Copy link
Contributor

elasticmachine commented Oct 15, 2024

💔 Build Failed

Failed CI Steps

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
fleet 1291 1292 +1

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
fleet 1.7MB 1.7MB +716.0B

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
fleet 75 76 +1

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
fleet 171.6KB 171.8KB +173.0B
Unknown metric groups

API count

id before after diff
fleet 1414 1415 +1

ESLint disabled line counts

id before after diff
fleet 47 48 +1

Total ESLint disabled count

id before after diff
fleet 59 60 +1

History

cc @jen-huang

Copy link
Contributor

@seanrathier seanrathier left a comment

Choose a reason for hiding this comment

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

Looks good to me, just a few comments.

(policyTemplate) => policyTemplate?.deployment_modes?.agentless.enabled === true
)
) {
if (isAgentlessEnabled && isAgentlessIntegrationFn(packageInfo)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with @max that isAgentlessIntegration in this hook does not do much, however, I am trying to find another place where the helper function is imported (other than tests) and cannot find one. I think it would be better to keep it on the hook.

@@ -5,6 +5,47 @@
* 2.0.
*/

import type { PackageInfo, RegistryPolicyTemplate } from '../types';

export const isAgentlessIntegration = (
Copy link
Contributor

Choose a reason for hiding this comment

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

It recently came up that we don't have a way to specify which policy template to check. For example, the CSPM integration has multiple policy templates (KSPM, CSPM, CNVM) however only CSPM supports agentless.

Would it be possible to have an optional parameter that we can pass cspm and check individual policy templates?

Copy link
Contributor

Choose a reason for hiding this comment

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

This comment is not for you to fix now but rather something we should discuss. This hook is starting to get complicated. I see the hook being used in many places and we are prop drilling the results from this to components and child components.

We should consider using a React.Context for Agentless and the components and custom extensions can pull this information from the Context.

@jen-huang jen-huang enabled auto-merge (squash) October 15, 2024 21:12
@jen-huang jen-huang merged commit 8cadf88 into elastic:main Oct 15, 2024
30 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x

https://github.com/elastic/kibana/actions/runs/11356233866

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Oct 16, 2024
…nabled (elastic#194885)

## Summary

Resolves elastic#192486. This PR makes it so that on deployments without
agentless enabled:
1. Agentless-only integrations are hidden from the browse integration UI
2. Agentless-only integrations cannot be installed via API (unless force
flag is used)

⚠️ elastic/package-registry#1238 needs to be
completed for the below testing steps to work. Currently EPR does not
return `deployment_modes` property which is necessary for Fleet to know
which packages are agentless.

## How to test

1. Simulate agentless being available by adding the following to
kibana.yml:
```
xpack.fleet.agentless.enabled: true

# Simulate cloud
xpack.cloud.id: "foo"
xpack.cloud.base_url: "https://cloud.elastic.co"
xpack.cloud.organization_url: "/account/"
xpack.cloud.billing_url: "/billing/"
xpack.cloud.profile_url: "/user/settings/"
```
2. Go to `Integrations > Browse` and enable showing Beta integrations,
search for `connector` and you should see the agentless integrations:
Elastic Connectors, GitHub & GitHub Enterprise Server Connector, Google
Drive Connector
3. Install any one of them (they all come from the same package), it
should be successful
4. Uninstall them
5. Remove config changes to go back to a non-agentless deployment
6. Refresh Integrations list, the three integrations should no longer
appear
7. Try installing via API, an error should appear
```
POST kbn:/api/fleet/epm/packages/elastic_connectors/0.0.2
```
8. Try installing via API again with force flag, it should be
successful:
```
POST kbn:/api/fleet/epm/packages/elastic_connectors/0.0.2
{
  "force": true
}
```

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

(cherry picked from commit 8cadf88)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

@jen-huang jen-huang deleted the feat/hide-agentless-integrations branch October 16, 2024 00:44
kibanamachine added a commit that referenced this pull request Oct 16, 2024
…less enabled (#194885) (#196459)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[UII] Restrict agentless integrations to deployments with agentless
enabled (#194885)](#194885)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Jen
Huang","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-15T23:57:32Z","message":"[UII]
Restrict agentless integrations to deployments with agentless enabled
(#194885)\n\n## Summary\r\n\r\nResolves #192486. This PR makes it so
that on deployments without\r\nagentless enabled:\r\n1. Agentless-only
integrations are hidden from the browse integration UI\r\n2.
Agentless-only integrations cannot be installed via API (unless
force\r\nflag is used)\r\n\r\n⚠️
elastic/package-registry#1238 needs to
be\r\ncompleted for the below testing steps to work. Currently EPR does
not\r\nreturn `deployment_modes` property which is necessary for Fleet
to know\r\nwhich packages are agentless.\r\n\r\n## How to test\r\n\r\n1.
Simulate agentless being available by adding the following
to\r\nkibana.yml:\r\n```\r\nxpack.fleet.agentless.enabled: true\r\n\r\n#
Simulate cloud\r\nxpack.cloud.id: \"foo\"\r\nxpack.cloud.base_url:
\"https://cloud.elastic.co\"\r\nxpack.cloud.organization_url:
\"/account/\"\r\nxpack.cloud.billing_url:
\"/billing/\"\r\nxpack.cloud.profile_url:
\"/user/settings/\"\r\n```\r\n2. Go to `Integrations > Browse` and
enable showing Beta integrations,\r\nsearch for `connector` and you
should see the agentless integrations:\r\nElastic Connectors, GitHub &
GitHub Enterprise Server Connector, Google\r\nDrive Connector\r\n3.
Install any one of them (they all come from the same package),
it\r\nshould be successful\r\n4. Uninstall them\r\n5. Remove config
changes to go back to a non-agentless deployment\r\n6. Refresh
Integrations list, the three integrations should no
longer\r\nappear\r\n7. Try installing via API, an error should
appear\r\n```\r\nPOST
kbn:/api/fleet/epm/packages/elastic_connectors/0.0.2\r\n```\r\n8. Try
installing via API again with force flag, it should
be\r\nsuccessful:\r\n```\r\nPOST
kbn:/api/fleet/epm/packages/elastic_connectors/0.0.2\r\n{\r\n \"force\":
true\r\n}\r\n```\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"8cadf88c66a257c073279fa11572b089c32eb643","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Fleet","v9.0.0","backport:prev-minor"],"title":"[UII]
Restrict agentless integrations to deployments with agentless
enabled","number":194885,"url":"https://github.com/elastic/kibana/pull/194885","mergeCommit":{"message":"[UII]
Restrict agentless integrations to deployments with agentless enabled
(#194885)\n\n## Summary\r\n\r\nResolves #192486. This PR makes it so
that on deployments without\r\nagentless enabled:\r\n1. Agentless-only
integrations are hidden from the browse integration UI\r\n2.
Agentless-only integrations cannot be installed via API (unless
force\r\nflag is used)\r\n\r\n⚠️
elastic/package-registry#1238 needs to
be\r\ncompleted for the below testing steps to work. Currently EPR does
not\r\nreturn `deployment_modes` property which is necessary for Fleet
to know\r\nwhich packages are agentless.\r\n\r\n## How to test\r\n\r\n1.
Simulate agentless being available by adding the following
to\r\nkibana.yml:\r\n```\r\nxpack.fleet.agentless.enabled: true\r\n\r\n#
Simulate cloud\r\nxpack.cloud.id: \"foo\"\r\nxpack.cloud.base_url:
\"https://cloud.elastic.co\"\r\nxpack.cloud.organization_url:
\"/account/\"\r\nxpack.cloud.billing_url:
\"/billing/\"\r\nxpack.cloud.profile_url:
\"/user/settings/\"\r\n```\r\n2. Go to `Integrations > Browse` and
enable showing Beta integrations,\r\nsearch for `connector` and you
should see the agentless integrations:\r\nElastic Connectors, GitHub &
GitHub Enterprise Server Connector, Google\r\nDrive Connector\r\n3.
Install any one of them (they all come from the same package),
it\r\nshould be successful\r\n4. Uninstall them\r\n5. Remove config
changes to go back to a non-agentless deployment\r\n6. Refresh
Integrations list, the three integrations should no
longer\r\nappear\r\n7. Try installing via API, an error should
appear\r\n```\r\nPOST
kbn:/api/fleet/epm/packages/elastic_connectors/0.0.2\r\n```\r\n8. Try
installing via API again with force flag, it should
be\r\nsuccessful:\r\n```\r\nPOST
kbn:/api/fleet/epm/packages/elastic_connectors/0.0.2\r\n{\r\n \"force\":
true\r\n}\r\n```\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"8cadf88c66a257c073279fa11572b089c32eb643"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/194885","number":194885,"mergeCommit":{"message":"[UII]
Restrict agentless integrations to deployments with agentless enabled
(#194885)\n\n## Summary\r\n\r\nResolves #192486. This PR makes it so
that on deployments without\r\nagentless enabled:\r\n1. Agentless-only
integrations are hidden from the browse integration UI\r\n2.
Agentless-only integrations cannot be installed via API (unless
force\r\nflag is used)\r\n\r\n⚠️
elastic/package-registry#1238 needs to
be\r\ncompleted for the below testing steps to work. Currently EPR does
not\r\nreturn `deployment_modes` property which is necessary for Fleet
to know\r\nwhich packages are agentless.\r\n\r\n## How to test\r\n\r\n1.
Simulate agentless being available by adding the following
to\r\nkibana.yml:\r\n```\r\nxpack.fleet.agentless.enabled: true\r\n\r\n#
Simulate cloud\r\nxpack.cloud.id: \"foo\"\r\nxpack.cloud.base_url:
\"https://cloud.elastic.co\"\r\nxpack.cloud.organization_url:
\"/account/\"\r\nxpack.cloud.billing_url:
\"/billing/\"\r\nxpack.cloud.profile_url:
\"/user/settings/\"\r\n```\r\n2. Go to `Integrations > Browse` and
enable showing Beta integrations,\r\nsearch for `connector` and you
should see the agentless integrations:\r\nElastic Connectors, GitHub &
GitHub Enterprise Server Connector, Google\r\nDrive Connector\r\n3.
Install any one of them (they all come from the same package),
it\r\nshould be successful\r\n4. Uninstall them\r\n5. Remove config
changes to go back to a non-agentless deployment\r\n6. Refresh
Integrations list, the three integrations should no
longer\r\nappear\r\n7. Try installing via API, an error should
appear\r\n```\r\nPOST
kbn:/api/fleet/epm/packages/elastic_connectors/0.0.2\r\n```\r\n8. Try
installing via API again with force flag, it should
be\r\nsuccessful:\r\n```\r\nPOST
kbn:/api/fleet/epm/packages/elastic_connectors/0.0.2\r\n{\r\n \"force\":
true\r\n}\r\n```\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"8cadf88c66a257c073279fa11572b089c32eb643"}}]}]
BACKPORT-->

Co-authored-by: Jen Huang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) release_note:skip Skip the PR/issue when compiling release notes Team:Fleet Team label for Observability Data Collection Fleet team v8.16.0 v9.0.0
Projects
None yet
7 participants