Commit graph

145 commits

Author SHA1 Message Date
Paul Tavares cb60584571
[Fleet] Add new index to fleet for artifacts being served out of fleet-server (#92860)
* Added index definition for artifacts
2021-02-25 16:42:50 -05:00
Rudolf Meijering 3b1ca526a7
v1 migrations: drop fleet-agent-events during a migration (#92188)
* v1 migrations: drop fleet-agent-events during a migration

* Add TODO to fleet to make it clear that fleet-agent-events should not be used

* Fix test
2021-02-23 11:44:43 +01:00
Jen Huang 10b1fddf35
[Fleet] Handle long text in agent details page (#91776)
* Fix #85521

* Set a minimum height for agent logs component #89831

* Truncate long integration names nicely #85404
2021-02-19 08:49:48 -08:00
John Schulz 5bfcc096a6
[Fleet] Don't error on missing package_assets value (#91744)
## Summary
closes https://github.com/elastic/kibana/issues/89111

 * Update TS type to make `package_assets` key in EPM packages saved object optional
 * Update two places in code to deal with optional vs required property

### Checklist

- [ ] [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

#### Manual testing
1. checkout `7.10` branch
   1. **start ES:** `nvm use; yarn kbn bootstrap; yarn es snapshot --version 7.10.3 --license=trial  -E xpack.security.authc.api_key.enabled=true -E path.data=../data`
   1. **start Kibana**: `yarn start --no-base-path`
   1. **run** `curl -X POST -H 'kbn-xsrf: 1234' --user elastic:changeme localhost:5601/api/fleet/setup`
   2. **observe** `{"is_initialized: true}`
1. checkout `7.11` branch
   1. **start ES:** `nvm use; yarn kbn bootstrap; yarn es snapshot --version 7.11.1 --license=trial  -E xpack.security.authc.api_key.enabled=true -E path.data=../data`
   1. **start Kibana**: `yarn start --no-base-path`
   1. **run** `curl -X POST -H 'kbn-xsrf: 1234' --user elastic:changeme localhost:5601/api/fleet/setup`
   1. **observe** `{"is_initialized: true}`
1. checkout `master` branch
   1. **start ES:** `nvm use; yarn kbn bootstrap; yarn es snapshot --version 8.0.0 --license=trial  -E xpack.security.authc.api_key.enabled=true -E path.data=../data`
   1. **start Kibana**: `yarn start --no-base-path`
   1. **run** `curl -X POST -H 'kbn-xsrf: 1234' --user elastic:changeme localhost:5601/api/fleet/setup`
   1. **observe error** {"statusCode":500,"error":"Internal Server Error","message":"Cannot read property 'map' of undefined"}
1. checkout this PR `8911-fleet-startup-error`
   1. **start ES:** `nvm use; yarn kbn bootstrap; yarn es snapshot --version 8.0.0 --license=trial  -E xpack.security.authc.api_key.enabled=true -E path.data=../data`
   1. **start Kibana**: `yarn start --no-base-path`
   1. **run** `curl -X POST -H 'kbn-xsrf: 1234' --user elastic:changeme localhost:5601/api/fleet/setup`
   1. **observe success** `{"is_initialized: true}`

**_Notes_**
 * _you might need to do a `yarn kbn clean` when starting kibana if it fails. There have been some big changes in the tooling recently_
2021-02-19 07:40:16 -05:00
Nicolas Chaulet fe35e0de3b
[Fleet] Install Elastic Agent integration by default during setup (#91676) 2021-02-18 18:45:15 -05:00
Jen Huang 0f804677de
[Fleet] Silently swallow 404 errors when deleting ingest pipelines (#91778)
* Only show transform logs when there are transforms

* Silently swallow 404 errors when deleting ingest pipelines

* Change to IngestManagerError
2021-02-18 13:43:03 -08:00
Zacqary Adam Xeper 0760bfb870
[Fleet] Bootstrap functional test suite (#91898) 2021-02-18 16:34:50 -05:00
Greg Thompson 8126488021
Upgrade EUI to v31.7.0 (#91210)
* eui to 31.6.0

* flyout, collapsible snapshot updates

* initial overlaymask removal

* undo jest

* overlaymask src snapshot updates

* more overlaymask removals

* overlaymask removal xpack test updates

* saved objects modal form

* eui to 31.7.0

* code, codeblock types

* snapshot update

* tooltip

* remove ownFocus from ConfirmModal

* remove fragments
2021-02-16 14:06:25 -06:00
Bohdan Tsymbala e81b5c1e40
[Security Solution][Artifacts] implemented policy specific trusted apps support in the manifest manager (#90991)
* Implemented policy specific trusted apps support in the manifest manager.
2021-02-16 14:31:36 -05:00
Nicolas Chaulet a99ccc27d7
[Fleet] Setup fleet server indices in Kibana without packages (#90658) 2021-02-16 13:54:54 -05:00
Nicolas Chaulet e8fea280bc
[Fleet] Create default Fleet Server policy with fleet server package (#90973) 2021-02-16 10:48:03 -05:00
Sonja Krause-Harder 58849bca38
[Fleet] Escape YAML string values if necessary (#91418)
* Use js-yaml.safeDump() to escape string values.

* Add unit test.

* Explicitly check for YAML special characters.

* Remove unnecessary imports.

* Use RegExp.prototype.test() for speed.
2021-02-16 16:23:53 +01:00
John Schulz 0a5e054fdc
[Fleet] Don't upgrade agent(s) in a managed policy (#91303)
## Summary

 - Make sure any agents requesting to be upgraded, are not enrolled in a managed policy.
 - `force: true` will only bypass agent / kibana version checks. It will not bypass managed policy check. To workaround, the enrolled policy should be changed to unmanaged (`is_managed: false`) as we do with enroll, reassign, etc.
 - Took more efficient approach to bulk actions. One `bulkGet` for N agents/policies vs N `get`s  approach used for bulk reassignment of agents. See discussion in https://github.com/elastic/kibana/pull/88688/files#r568941761
 - [x] API
 - [ ] UI
 - [x] tests

### 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


### Manual tests
#### upgrade one
```
curl --location --request POST 'http://localhost:5601/api/fleet/agents/8d9748e0-6d52-11eb-8cbd-47e38cd1c8de/upgrade' --header 'kbn-xsrf: <string>' --header 'Content-Type: application/json' --header 'Authorization: Basic ZWxhc3RpYzpjaGFuZ2VtZQ==' --data-raw '{
    "version": "8.0.0"
}'
{"statusCode":400,"error":"Bad Request","message":"Cannot upgrade agent 8d9748e0-6d52-11eb-8cbd-47e38cd1c8de in managed policy bf319100-6d50-11eb-8859-15a87f509a99"}
```

```
curl --location --request POST 'http://localhost:5601/api/fleet/agents/8d9748e0-6d52-11eb-8cbd-47e38cd1c8de/upgrade' --header 'kbn-xsrf: <string>' --header 'Content-Type: application/json' --header 'Authorization: Basic ZWxhc3RpYzpjaGFuZ2VtZQ==' --data-raw '{
    "version": "8.0.0", "force": true
}'
{"statusCode":400,"error":"Bad Request","message":"Cannot upgrade agent 8d9748e0-6d52-11eb-8cbd-47e38cd1c8de in managed policy bf319100-6d50-11eb-8859-15a87f509a99"}
```

#### bulk upgrade
```
curl --location --request POST 'http://localhost:5601/api/fleet/agents/bulk_upgrade' --header 'kbn-xsrf: <string>' --header 'Content-Type: application/json' --header 'Authorization: Basic ZWxhc3RpYzpjaGFuZ2VtZQ==' --data-raw '{
    "version": "8.0.0",
    "agents": [
        "8d9748e0-6d52-11eb-8cbd-47e38cd1c8de"
    ]
}'
{}
```

```
curl --location --request POST 'http://localhost:5601/api/fleet/agents/bulk_upgrade' --header 'kbn-xsrf: <string>' --header 'Content-Type: application/json' --header 'Authorization: Basic ZWxhc3RpYzpjaGFuZ2VtZQ==' --data-raw '{
    "version": "8.0.0",
    "agents": [
        "8d9748e0-6d52-11eb-8cbd-47e38cd1c8de"
    ], "force": true
}'
{"statusCode":400,"error":"Bad Request","message":"Cannot update agent in managed policy bf319100-6d50-11eb-8859-15a87f509a99"}```
```
2021-02-15 13:36:39 -05:00
Spencer afed310b82
[ts/build-refs] implement experimental remote cache (#91012)
* [ts/build-refs] implement experimental remote cache

* delete old tests

* add some more tests

* add some docs and a readme

* fix kibanaPackageJson usage

Co-authored-by: spalger <spalger@users.noreply.github.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
2021-02-12 01:56:21 -07:00
Nicolas Chaulet 94ba974adb
[Fleet] Remove aliases from index_template when updating an existing template (#91200) 2021-02-11 16:42:25 -05:00
Jonathan Budzenski c5b5f20baf Revert "[Fleet] Remove aliases from index_template when updating an existing template (#91142)"
This reverts commit c22366e69d.
2021-02-11 13:17:03 -06:00
Nicolas Chaulet c22366e69d
[Fleet] Remove aliases from index_template when updating an existing template (#91142) 2021-02-11 13:55:45 -05:00
Mikhail Shustov a1490d46f4
TS config cleanup (#90492)
* exclude all the plugins from src/plugins

* move all the used fixtures to discover

* remove src/fixtures alias

* remove unused fixtures

* cleanup x-pack/tsconfig.json

* dont compile apm/scripts

* fix tests

* dont include infra in xpack/tsconfig.json

* update list of includes
2021-02-11 12:34:25 -05:00
Sonja Krause-Harder 9870ade971
[Fleet] Reduce permissions. (#90302)
* Reduce permissions.

* Change permissions back.

* Reducing permissions on fleet_enroll role

- 'write', 'create_index' -> 'auto_configure', 'create_doc'

* Remove indices:admin/auto_create from privileges.
2021-02-11 09:33:51 +01:00
John Schulz c92af5a4d5
[Fleet] Restrict integration changes for managed policies (#90675)
## Summary

- [x] Integrations cannot be added ~~, unless with a force flag~~
  - [x] API
  - [x] UI
  - [x] tests
- [x] Integrations cannot be removed ~~, unless with a force flag~~
  - [x] API
  - [x] UI
  - [x] tests

closes https://github.com/elastic/kibana/issues/90445
refs https://github.com/elastic/kibana/issues/89617

### Cannot add integrations to managed policy

<img height="400" alt="Screen Shot 2021-02-08 at 1 56 32 PM" src="https://user-images.githubusercontent.com/57655/107277261-25c48300-6a22-11eb-936a-0a7361667093.png">

### Cannot delete integrations from managed policy

<img  alt="Screen Shot 2021-02-08 at 3 05 16 PM" src="https://user-images.githubusercontent.com/57655/107277318-337a0880-6a22-11eb-836f-fc66b510d257.png">

### 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
2021-02-10 17:04:01 -05:00
Jen Huang c2b41c484b
[Fleet] Revamp integration detail page (#90887)
* Extract integration detail page changes from POC

* Remove unneccessary link wrappers

* Remove unused import

* Fix method name

* Fix linting
2021-02-10 12:03:34 -08:00
Nicolas Chaulet f95bfe83b7
[Fleet] Use Fleet Server indices in the search bar (#90835) 2021-02-10 08:28:22 -05:00
Sonja Krause-Harder 4ee9603801
Use new shortcut links to Fleet discuss forums. (#90786)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
2021-02-10 11:33:17 +01:00
Aleh Zasypkin 03a53b9f39
Do not generate an ephemeral encryption key in production. (#81511) 2021-02-10 11:27:31 +01:00
Nicolas Ruflin 634c0b3424
[Fleet] Use staging registry for snapshot builds (#90327)
The staging registry is used in Kibana builds which are not built of the master branch or release version. This means, any build ending with `-SNAPSHOT` not the master branch will use the staging registry.

Closes https://github.com/elastic/kibana/issues/90131

Co-authored-by: Jen Huang <its.jenetic@gmail.com>
2021-02-10 09:57:09 +01:00
John Schulz 810e4ab8e8
[Fleet] Prevent agents from enrolling in a managed policy (#90458)
## Summary
Add guard to `/agents/enroll` API preventing agents from enrolling in managed policies

closes #90435
- [x] No Agents can be enrolled into this policy by the user.
- [x] The install & enroll commands should print an error to the console if the enroll command fails (due to being a managed policy or any other reason)



#### So how do you associate an agent with a managed policy?
Enroll in an unmanaged policy then set that policy to managed. 

We don't restrict the agent policy, only what other things (agents, integrations) can do if they're associated with a managed policy.

A _force flag_ has been mentioned for some other actions. It might work here as well, but I'd like to handle discussion & implementation of those later.

### Manual testing
<details><summary>Prevent enroll for managed policies</summary>

1. Created a managed agent policy
    ```
    curl --user elastic:changeme -X POST localhost:5601/api/fleet/agent_policies -H 'Content-Type: application/json' -d'{ "name": "User created MANAGED", "namespace": "default", "is_managed": true}' -H 'kbn-xsrf: true'
    {"item":{"id":"3bd07db0-67d0-11eb-b656-21ad68ebfa8a","name":"User created MANAGED","namespace":"default","is_managed":true,"revision":1,"updated_at":"2021-02-05T16:36:01.931Z","updated_by":"elastic"}}
    ```
2. Try `install` command show in the UI
    ```
    sudo ./elastic-agent install -f --kibana-url=http://localhost:5601 --enrollment-token=WmcwTWMzY0IzWlBUUWJJUjZqRDA6UGRZelVlaS1STml1cVdjSUVwSkJRQQ== --insecure
    Password:
    The Elastic Agent is currently in BETA and should not be used in production

    Error: fail to enroll: fail to execute request to Kibana: Status code: 400, Kibana returned an error: Bad Request, message: Cannot enroll in managed policy 3bd07db0-67d0-11eb-b656-21ad68ebfa8a
    Error: enroll command failed with exit code: 1
    ```
3. Observe `Cannot enroll in managed policy 3bd07db0-67d0-11eb-b656-21ad68ebfa8a` error
4. Try `enroll` instead:
    ```
    sudo ./elastic-agent enroll http://localhost:5601 WmcwTWMzY0IzWlBUUWJJUjZqRDA6UGRZelVlaS1STml1cVdjSUVwSkJRQQ== --insecure
    The Elastic Agent is currently in BETA and should not be used in production

    This will replace your current settings. Do you want to continue? [Y/n]:
    Error: fail to enroll: fail to execute request to Kibana: Status code: 400, Kibana returned an error: Bad Request, message: Cannot enroll in managed policy 3bd07db0-67d0-11eb-b656-21ad68ebfa8a
    ```
5. Observe same `Cannot enroll in managed policy 3bd07db0-67d0-11eb-b656-21ad68ebfa8a` error

</details>

<details><summary>Enroll in unmanaged policy, then update it to managed</summary>

Agent policies are `is_managed: false` by default, or we can update the policy to `is_managed: false`, like:

```
curl --user elastic:changeme -X PUT localhost:5601/api/fleet/agent_policies/3bd07db0-67d0-11eb-b656-21ad68ebfa8a -H 'Content-Type: application/json' -d'{ "is_managed": false, "name": "xyz", "namespace": "default" }' -H 'kbn-xsrf: true'
{"item":{"id":"3bd07db0-67d0-11eb-b656-21ad68ebfa8a","name":"xyz","namespace":"default","is_managed":false,"revision":4,"updated_at":"2021-02-05T17:42:05.610Z","updated_by":"elastic","package_policies":[]}}
```

then enroll

```
 sudo ./elastic-agent install -f --kibana-url=http://localhost:5601 --enrollment-token=WmcwTWMzY0IzWlBUUWJJUjZqRDA6UGRZelVlaS1STml1cVdjSUVwSkJRQQ== --insecure
The Elastic Agent is currently in BETA and should not be used in production

Successfully enrolled the Elastic Agent.
Installation was successful and Elastic Agent is running.
```

and set the policy back to managed

```
curl --user elastic:changeme -X PUT localhost:5601/api/fleet/agent_policies/3bd07db0-67d0-11eb-b656-21ad68ebfa8a -H 'Content-Type: application/json' -d'{ "is_managed": true, "name": "xyz", "namespace": "default" }' -H 'kbn-xsrf: true'
{"item":{"id":"3bd07db0-67d0-11eb-b656-21ad68ebfa8a","name":"xyz","namespace":"default","is_managed":true,"revision":5,"updated_at":"2021-02-05T17:44:18.757Z","updated_by":"elastic","package_policies":[]}}
```

with all the restrictions that entails (cannot unenroll, reassign, etc)

```
curl --user elastic:changeme -X PUT 'http://localhost:5601/api/fleet/agents/8169f0a0-67d9-11eb-80f2-73dd45e7318e/reassign'   -X 'PUT'  -H 'kbn-xsrf: abc'  -H 'Content-Type: application/json'   --data-raw '{"policy_id":"729f8440-67cf-11eb-b656-21ad68ebfa8a"}'   
{
  "statusCode": 400,
  "error": "Bad Request",
  "message": "Cannot reassign an agent from managed agent policy 3bd07db0-67d0-11eb-b656-21ad68ebfa8a"
}
```

</details>

### 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
2021-02-09 08:54:51 -05:00
John Schulz af75079a31
[Fleet] Use TS project references (#87574)
## Summary
 * Added references to all dependencies
    6bc6f3459a/x-pack/plugins/fleet/tsconfig.json (L17-L38)
 * `node scripts/check_ts_projects` is successful
 * `node scripts/build_ts_refs` is successful
<details><summary><code>node --max-old-space-size=4096 ./node_modules/.bin/tsc -p tsconfig.json --extendedDiagnostics --noEmit</code></summary>

```
Files:                        1436
Lines:                      267372
Nodes:                     1016769
Identifiers:                361835
Symbols:                    250405
Types:                       31105
Instantiations:              57570
Memory used:               347817K
Assignability cache size:     5597
Identity cache size:          3073
Subtype cache size:           2140
Strict subtype cache size:    1012
I/O Read time:               0.49s
Parse time:                  3.84s
ResolveModule time:          1.59s
ResolveTypeReference time:   0.16s
Program time:                7.46s
Bind time:                   1.87s
Check time:                  4.02s
printTime time:              0.00s
Emit time:                   0.00s
Total time:                 13.35s
```
</details>
2021-02-09 05:54:47 -05:00
Sonja Krause-Harder c306a444f5
[EPM] Conditionally generate ES index pattern name based on dataset_is_prefix (#89870)
* Explicitly generate ES index pattern name.

* Adjust tests.

* Adjust and reenable tests.

* Set template priority based on dataset_is_prefix

* Refactor indexPatternName -> templateIndexPattern

* Add unit tests.

* Use more realistic index pattern in test.

* Fix unit test.

* Add unit test for installTemplate().

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
2021-02-08 18:22:30 +01:00
John Schulz bda7b2816f
[Fleet] Cannot delete a managed agent policy (#90505)
## Summary
Managed policy cannot be deleted via API or UI

closes https://github.com/elastic/kibana/issues/90448

### 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

#### Manual testing
<details><summary>UI screenshot</summary>

<img width="1522" alt="Screen Shot 2021-02-05 at 1 56 13 PM" src="https://user-images.githubusercontent.com/57655/107076955-2ce95800-67ba-11eb-8bd4-d2ba3182e516.png">

</details>

<details><summary>API commands</summary>

```
## Create a managed policy
curl --user elastic:changeme -X POST localhost:5601/api/fleet/agent_policies -H 'Content-Type: application/json' -d'{ "name": "User created MANAGED", "namespace": "default", "is_managed": true}' -H 'kbn-xsrf: true'
{"item":{"id":"17ebd160-67ee-11eb-adb2-f16c6e20580c","name":"User created MANAGED","namespace":"default","is_managed":true,"revision":1,"updated_at":"2021-02-05T20:09:46.614Z","updated_by":"elastic"}}

## Cannot delete it
curl --user elastic:changeme -X POST 'http://localhost:5601/api/fleet/agent_policies/delete'   -H 'kbn-xsrf: abc'  -H 'Content-Type: application/json'   --data-raw '{"agentPolicyId": "17ebd160-67ee-11eb-adb2-f16c6e20580c" }'    
{
  "statusCode": 400,
  "error": "Bad Request",
  "message": "Cannot delete managed policy 17ebd160-67ee-11eb-adb2-f16c6e20580c"
}

## Set policy to unmanaged
curl --user elastic:changeme -X PUT localhost:5601/api/fleet/agent_policies/17ebd160-67ee-11eb-adb2-f16c6e20580c -H 'Content-Type: application/json' -d'{ "name": "User created MANAGED", "namespace": "default", "is_managed": false}' -H 'kbn-xsrf: true' 
{
  "item": {
    "id": "17ebd160-67ee-11eb-adb2-f16c6e20580c",
    "name": "User created MANAGED",
    "namespace": "default",
    "is_managed": false,
    "revision": 3,
    "updated_at": "2021-02-05T20:10:45.383Z",
    "updated_by": "elastic",
    "package_policies": []
  }
}

## Can delete
curl --user elastic:changeme -X POST 'http://localhost:5601/api/fleet/agent_policies/delete'   -H 'kbn-xsrf: abc'  -H 'Content-Type: application/json'   --data-raw '{"agentPolicyId": "17ebd160-67ee-11eb-adb2-f16c6e20580c" }'    
{
  "id": "17ebd160-67ee-11eb-adb2-f16c6e20580c",
  "name": "User created MANAGED"
}


```
</details>
2021-02-08 12:13:55 -05:00
Pierre Gayvallet 3b3327dbc3
Migrate most plugins to synchronous lifecycle (#89562)
* first pass

* migrate more plugins

* migrate yet more plugins

* more oss plugins

* fix test file

* change Plugin signature on the client-side too

* fix test types

* migrate OSS client-side plugins

* migrate OSS client-side test plugins

* migrate xpack client-side plugins

* revert fix attempt on fleet plugin

* fix presentation start signature

* fix yet another signature

* add warnings for server-side async plugins in dev mode

* remove unused import

* fix isPromise

* Add client-side deprecations

* update migration examples

* update generated doc

* fix xpack unit tests

* nit

* (will be reverted) explicitly await for license to be ready in the auth hook

* Revert "(will be reverted) explicitly await for license to be ready in the auth hook"

This reverts commit fdf73feb

* restore await on on promise contracts

* Revert "(will be reverted) explicitly await for license to be ready in the auth hook"

This reverts commit fdf73feb

* Revert "restore await on on promise contracts"

This reverts commit c5f2fe51

* add delay before starting tests in FTR

* update deprecation ts doc

* add explicit contract for monitoring setup

* migrate monitoring plugin to sync

* change plugin timeout to 10sec

* use delay instead of silence
2021-02-08 10:19:54 +01:00
Nicolas Chaulet 91ffe7373a
[Fleet] Support Fleet server system indices (#89372) 2021-02-07 18:57:50 -05:00
Jen Huang f4dc6d0235
[Fleet] Fix incorrect conversion of string to numeric values in agent YAML (#90371)
* Convert user values back to string after yaml template compilation if they were strings originally

* Add better test cases and adjust patch

* Fix when field is undefined

* Handle array of strings too
2021-02-05 14:14:31 -08:00
Jen Huang be53a06925
Fix state sharing between home integration components, prevent full page reload when clicking Fleet link (#90334)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
2021-02-05 09:56:32 -08:00
John Schulz 9e7e1e1708
[Fleet] Managed Agent Policy (#88688)
## Summary
Introduces the concept of a managed agent policy. Resolves most of the acceptance criteria from #76843. Remaining to be done in follow up PRs

- [x] Define hosted Agent Policy concept in Fleet.
    - [x] Flag in policy? **_yes, added `is_managed: boolean`_ in agent policy SO**
    - [x] Should not built only for cloud, an admin should be able to set theses restrictions.
    - [x] We should have an API to configure it _**Can `POST` and `PUT` to  `/api/fleet/agent_policies/{policy_id}`**_
    - [x] Integration should be editable, we expect integration author to do the right thing and limit what can be edited.
- [x] Research if we can ensure the right behavior of Hosted Agent policy and restrict the super user.
- [ ] Capabilities restrictions
  - [ ] An Agent enrolled in an Hosted Agent policy should not be able to be upgraded.
  - [x] An Agent enrolled in an Hosted Agent policy should not be able to be unenrolled.
  - [ ] No Agents cannot be enrolled into this policy by the user.
      - Hide the enrollment key?
      - Need to figure out the workflow.
  - [x] An Agent enrolled in an Hosted Agent policy should not be able to be reassigned to a different configuration.
- [x] As a user I should be prevented to do theses action. _**No user-level checks. Only Agent Policy. No UI changes, but API errors are shown for failed actions like reassigning**_
- [x] As an API user I should receive error messages.
- [x] If making a single "flag" is easier/faster let's do it.  _**Currently single `is_managed` property on agent policy SO.**_

Checks are implemented in service layer (is agent enrolled in a managed policy?)

No UI-specific changes added but UI is affected because HTTP requests (like `api/fleet/agents/{agentId}/reassign`) can fail. See screenshots below.

Tests at service (`yarn test:jest`) and http (`yarn test ftr`) layers for each of create policy, update policy, unenroll agent, and reassign agent

Bulk actions currently filter out restricted items. A follow-up PR will change them to throw an error and cause the request to fail.


## Managed Policy
Can create (`POST`) and update (`PUT`) an agent policy with an `is_managed` property. Each new saved object will have an `is_managed` property (default `false`)

<details><summary>HTTP commands</summary>

#### Create (`is_managed: false` by default)
```
 curl --user elastic:changeme -X POST localhost:5601/api/fleet/agent_policies -H 'Content-Type: application/json' -d'{ "name": "User created policy", "namespace": "default"}' -H 'kbn-xsrf: true'
{"item":{"id":"edc236a0-5cbb-11eb-ab2c-0134aecb4ce8","name":"User created policy","namespace":"default","is_managed":false,"revision":1,"updated_at":"2021-01-22T14:12:58.250Z","updated_by":"elastic"}}
```

#### Create with `is_managed: true`
```
 curl --user elastic:changeme -X POST localhost:5601/api/fleet/agent_policies -H 'Content-Type: application/json' -d'{ "name": "User created policy", "namespace": "default"}' -H 'kbn-xsrf: true'
{"item":{"id":"67c785b0-662e-11eb-bf6b-4790dc0178c0","name":"User created policy","namespace":"default","is_managed":false,"revision":1,"updated_at":"2021-02-03T14:45:06.059Z","updated_by":"elastic"}}
```

#### Update with `is_managed: true`
```
 curl --user elastic:changeme -X PUT  -H 'Content-Type: application/json' -H 'kbn-xsrf: 1234' localhost:5601/api/fleet/agent_policies/67c785b0-662e-11eb-bf6b-4790dc0178c0 -d '{ "name":"User created policy","namespace":"default","is_managed":true }'
{"item":{"id":"67c785b0-662e-11eb-bf6b-4790dc0178c0","name":"User created policy","namespace":"default","is_managed":true,"revision":2,"updated_at":"2021-02-03T14:47:28.471Z","updated_by":"elastic","package_policies":[]}}
```
</details>

## Enroll behavior
is not changed/addressed in this PR. Agents can still be enrolled in managed policies

## Unenroll Agent from managed policy behavior
#### Enrolled in managed agent policy, cannot be unenrolled
```
curl --user elastic:changeme -X POST http://localhost:5601/api/fleet/agents/441d4a40-6710-11eb-8f57-db14e8e41cff/unenroll -H 'kbn-xsrf: 1234' | jq
{
  "statusCode": 400,
  "error": "Bad Request",
  "message": "Cannot unenroll 441d4a40-6710-11eb-8f57-db14e8e41cff from a managed agent policy af9b4970-6701-11eb-b55a-899b78cb64da"
}
```

<details><summary>Screenshots for managed & unmanaged policies</summary>

#### Enrolled in managed agent policy, cannot be unenrolled
<img width="1931" alt="Screen Shot 2021-01-19 at 1 22 53 PM" src="https://user-images.githubusercontent.com/57655/105081614-67d05980-5a60-11eb-8faa-07e4e722a5b5.png">
<img width="1199" alt="Screen Shot 2021-01-19 at 1 30 26 PM" src="https://user-images.githubusercontent.com/57655/105081617-67d05980-5a60-11eb-9099-832dc6e04eca.png">
<img width="1971" alt="Screen Shot 2021-01-19 at 1 30 42 PM" src="https://user-images.githubusercontent.com/57655/105081618-67d05980-5a60-11eb-9a84-b80b6295ba19.png">

#### Enrolled agent policy is not managed, agent can be unenrolled<img width="1917" alt="Screen Shot 2021-01-19 at 1 44 12 PM" src="https://user-images.githubusercontent.com/57655/105081951-e3caa180-5a60-11eb-9308-7741b8986e8e.png">
<img width="2183" alt="Screen Shot 2021-01-19 at 1 44 19 PM" src="https://user-images.githubusercontent.com/57655/105081952-e3caa180-5a60-11eb-9833-1c721be0a107.png">

</details>


## Reassign agent 
#### No agent can be reassigned to a managed policy
```
 curl --user elastic:changeme -X 'PUT'  'http://localhost:5601/api/fleet/agents/482760d0-6710-11eb-8f57-db14e8e41cff/reassign' -H 'kbn-xsrf: xxx' -H 'Content-Type: application/json' -d '{"policy_id":"af9b4970-6701-11eb-b55a-899b78cb64da"}' 
{
  "statusCode": 400,
  "error": "Bad Request",
  "message": "Cannot reassign an agent to managed agent policy 94129590-6707-11eb-b55a-899b78cb64da"
}
```
<details><summary>Screenshots</summary>

<img width="1350" alt="Screen Shot 2021-02-04 at 2 14 51 PM" src="https://user-images.githubusercontent.com/57655/106943490-8044a300-66f3-11eb-9d2c-4b1ceef2e783.png">

</details>

#### Enrolled in managed agent policy, cannot be reassigned
```
 curl --user elastic:changeme -X 'PUT'  'http://localhost:5601/api/fleet/agents/482760d0-6710-11eb-8f57-db14e8e41cff/reassign' -H 'kbn-xsrf: xxx' -H 'Content-Type: application/json' -d '{"policy_id":"af9b4970-6701-11eb-b55a-899b78cb64da"}' 
{
  "statusCode": 400,
  "error": "Bad Request",
  "message": "Cannot reassign an agent from managed agent policy 94129590-6707-11eb-b55a-899b78cb64da"
}
```

<details><summary>Screenshots</summary>
<img width="1364" alt="Screen Shot 2021-01-19 at 2 58 38 PM" src="https://user-images.githubusercontent.com/57655/105086737-72dab800-5a67-11eb-8f5e-93cd7768b914.png">
<img width="1367" alt="Screen Shot 2021-01-19 at 2 58 44 PM" src="https://user-images.githubusercontent.com/57655/105086740-73734e80-5a67-11eb-8ef9-9c7005a0a4ea.png">
<img width="623" alt="Screen Shot 2021-01-19 at 2 59 27 PM" src="https://user-images.githubusercontent.com/57655/105086741-740be500-5a67-11eb-8fc2-721f8b5d178a.png">
</details>

#### Enrolled agent policy is unmanaged, agent can be reassigned to another unmanaged policy

<details><summary>Screenshots</summary>
<img width="1368" alt="Screen Shot 2021-01-19 at 3 00 01 PM" src="https://user-images.githubusercontent.com/57655/105086754-78d09900-5a67-11eb-86a5-9e3ac02d6e1f.png">
<img width="1363" alt="Screen Shot 2021-01-19 at 3 00 08 PM" src="https://user-images.githubusercontent.com/57655/105086761-7a01c600-5a67-11eb-991d-acf994e2a393.png">
<img width="625" alt="Screen Shot 2021-01-19 at 3 00 46 PM" src="https://user-images.githubusercontent.com/57655/105086764-7a9a5c80-5a67-11eb-8290-e79648d01579.png">
</details>

### Checklist

Delete any items that are not applicable to this PR.

- [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/master/packages/kbn-i18n/README.md)
- [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials
- [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
2021-02-04 15:16:45 -05:00
Shaunak Kashyap f3a9c763df
Updating package registry snapshot distribution version (#89776) 2021-02-04 08:40:18 -05:00
Brandon Kobel 4584a8b570
Elastic License 2.0 (#90099)
* Updating everything except the license headers themselves

* Applying ESLint rules

* Manually replacing the stragglers
2021-02-03 18:12:39 -08:00
Nicolas Chaulet 20654388a4
[Fleet] Fix performance issue in agent status endpoint (#90066)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
2021-02-02 20:23:56 -05:00
Jen Huang 19effe2157
[Fleet] Fix duplicate data streams being shown in UI (#89812)
* Add API integration tests for data streams list, including one that is expected to fail due to reliance on number of backing indices

* Use ES data streams API as source of truth for list of data streams, and only query against backing indices afterwards

* Get package name from data stream meta info

* Increate retry timeout

* Move initial info requests inside Promise.all

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
2021-02-02 10:11:15 -08:00
Jen Huang cb16a5c042
[Fleet] Update data streams mappings directly instead of against backing indices (#89660)
* Update data streams mappings directly instead of querying for backing indices, update integration tests to test with multiple namespaces

* Add flag to only update mappings of the current write index

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
2021-02-01 09:24:12 -08:00
Nicolas Ruflin 4f43096c64
[Fleet] Remove comments around experimental registry (#89830)
The experimental registry was used for the 7.8 release but since then was not touched anymore. Because of this it should not show up in the code anymore even if it is commented out.
2021-02-01 10:28:49 +01:00
Nicolas Chaulet da1a4e947a
[Fleet] Install the Fleet Server package during setup (#89224) 2021-01-29 08:41:36 -05:00
Candace Park 074003d4b4
[Security Solution][Endpoint][Admin] Ransomware card (#87945)
* [Security Solution][Endpoint][Admin] Ransomware card, package policy 7.12 migration
2021-01-28 13:35:06 -05:00
Nicolas Chaulet 9b5e41a9c5
[Fleet] Do not defined aliases inside datastream template (#89512)
Co-authored-by: spalger <spalger@users.noreply.github.com>
2021-01-27 20:59:33 -07:00
Nathan L Smith e5588a129b
Move EUI styled components integration to kibana_react (#86065)
...from xpack_legacy.

Remove the duplicated typings from the observability plugin and only use the ones from kibana_react.

Fixes #78248.
2021-01-25 13:48:35 -06:00
Sonja Krause-Harder 77851e8382
Ignore missing asset errors on remove. (#89115) 2021-01-25 15:01:29 +01:00
Thom Heymann aeb6df30d5
Update user management page (#87133)
* Update user management page

* Fixed i18n errors

* Fix linting errors

* Add ids required for accessability

* Added suggestions from code review

* Fix test errors

* Fix types in fleet

* fix translations

* Fix i18n

* Added suggestions from code review

* Fix i18n errors

* Fix linting errors

* Update messaging

* Updated unit tests

* Updated functional tests

* Fixed functional tests

* Fix linting errors

* Fix React warnings

* Added suggestions from code review

* Added tests and renamed routes

* Fix functional tests

* Simplified API integration tests

* Updated copy based on writing suggestions

* Fixed unit tests

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
2021-01-25 13:51:57 +00:00
Kevin Logan 49d95f6fb1
[Fleet] Add updateFleetRoleIfExists() in order to update fleet_enroll permissions if role already exists (#88000)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
2021-01-22 12:12:59 -05:00
Nicolas Chaulet 88be8a7148
[Fleet] Remove support for shared_id during enrollment (#88897) 2021-01-21 13:42:39 -05:00
Nicolas Chaulet 3b728b73cf
[Fleet] Use fleet server indices for enrollment keys and to list agents with a feature flag (#86179) 2021-01-20 19:29:04 -05:00
John Schulz c52339e606
[Fleet][EPM] If proxy url has username & password, add to Node's Agent options (#86807)
## Summary

A user received a `407` response when using a `registryProxyUrl` format like `http://user:pass@host:port`

I believe the issue is we're not including the [`auth` property as described in this issue](https://github.com/TooTallNate/node-https-proxy-agent/issues/12#issuecomment-216098644). 

Add tests to ensure it only adds `auth` if username & password are given.

### Checklist
Delete any items that are not applicable to this PR.
- [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

```
  getProxyAgentOptions
    auth property
      present & correct if given username and password
        ✓ proxy url is http (1 ms)
        ✓ proxy url is https
      missing if not given username and password
        ✓ proxy url is http
        ✓ proxy url is https
```
2021-01-19 07:24:11 -05:00