Commit graph

2346 commits

Author SHA1 Message Date
Tim Lee
74f55f2388
Bugfix: 18843 fix policy host counts (#18846) 2024-05-08 11:23:58 -06:00
Victor Lyuboslavsky
abf4837eff
Broke apart the hourly host_software count query to reduce the individual query runtime (#18773)
#18221
Broke apart the hourly host_software count query to reduce the
individual query runtime. This fixes timeouts seen when host_software
table has over 25 million records.

I recommend hiding whitespace during review:
<img width="240" alt="image"
src="https://github.com/fleetdm/fleet/assets/2685025/6da9b643-8582-4d2f-bf32-8a1cc38f1032">


# Checklist for submitter

<!-- Note that API documentation changes are now addressed by the
product design team. -->

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [x] Added/updated tests
- [x] Manual QA for all new/changed functionality
2024-05-08 09:27:17 -05:00
Tim Lee
24696a6f1b bugfix: 18703 policies filter (#18706)
#18703
2024-05-07 15:44:48 -04:00
Tim Lee
270db29328 17744 policies count backend (#18567)
#17744 

This adds the `merged_inherited` query param to
`/teams/:id/policies/count` related to
https://github.com/fleetdm/fleet/pull/18564

- [ ] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [X] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)
- [X] Added/updated tests
- [X] Manual QA for all new/changed functionality

---------

Co-authored-by: RachelElysia <rachel@fleetdm.com>
2024-05-07 15:44:17 -04:00
Tim Lee
56d02eae2d 17744 policies backend (#18564)
#17744 

This change implements a new query parameter on `/teams/%d/policies` to
merge inherited policies into the policies array instead of listing them
separately. The frontend will key off the existing `team_id` field to
mark policies as "inherited" in theUI.

I opted for an additive approach in adding a datastore method rather
than modifying the existing ListTeamPolicies to avoid a large test
refactor.

- [ ] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [X] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)
- [X] Added/updated tests
- [X] Manual QA for all new/changed functionality

---------

Co-authored-by: RachelElysia <rachel@fleetdm.com>
2024-05-07 15:43:26 -04:00
Tim Lee
2c45ccb0a1 17745 queries backend (#18582)
#17745 

implement `merge_inherited` on the list queries endpoint to combine team
and inherited queries.

- [ ] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [X] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)
- [X] Added/updated tests
- [X] Manual QA for all new/changed functionality

---------

Co-authored-by: RachelElysia <rachel@fleetdm.com>
2024-05-07 15:43:10 -04:00
RachelElysia
e92e76aee3
Revert "Feature: 15605 merge inherited queries and policies" 2024-05-07 13:30:39 -04:00
RachelElysia
9e66ef6b34
Feature: 15605 merge inherited queries and policies (#18801)
## Issue
Feature branch including all frontend and backend of #15605
2024-05-07 13:07:54 -04:00
RachelElysia
4ea5ea9f00
Revert "Feature: 15605 merge inherited queries and policies" (#18800)
Reverts fleetdm/fleet#18771

(Because of accidental squash and merge of feature dev by 3 of us only has my name on it)
2024-05-07 12:47:12 -04:00
George Karr
db5d553545
Initial fleetctl api command works with GETS and fields (#17971) 2024-05-07 11:22:05 -05:00
RachelElysia
434239e5f9
Feature: 15605 merge inherited queries and policies (#18771) 2024-05-07 12:10:06 -04:00
Victor Lyuboslavsky
9a6b2f655e
Fixed MySQL sort buffer overflow when fetching activities. (#18782)
#12619

Fixed MySQL sort buffer overflow when fetching activities. This issue
happened when activities contained very large details, such as large SQL
queries.

# Checklist for submitter
<!-- Note that API documentation changes are now addressed by the
product design team. -->

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [ ] Added/updated tests
  - Existing tests provide sufficient coverage
- [x] Manual QA for all new/changed functionality
2024-05-07 10:53:24 -05:00
George Karr
0b9ec5e322
Adding cli improvements for run-scripts (#18010) 2024-05-07 10:10:22 -05:00
Tim Lee
eb7ac35071 bugfix: 18703 policies filter (#18706)
#18703
2024-05-06 12:27:06 -04:00
Tim Lee
511f9bdbdb 17744 policies count backend (#18567)
#17744 

This adds the `merged_inherited` query param to
`/teams/:id/policies/count` related to
https://github.com/fleetdm/fleet/pull/18564

- [ ] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [X] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)
- [X] Added/updated tests
- [X] Manual QA for all new/changed functionality

---------

Co-authored-by: RachelElysia <rachel@fleetdm.com>
2024-05-06 12:26:10 -04:00
Tim Lee
37ac878ce7 17744 policies backend (#18564)
#17744 

This change implements a new query parameter on `/teams/%d/policies` to
merge inherited policies into the policies array instead of listing them
separately. The frontend will key off the existing `team_id` field to
mark policies as "inherited" in theUI.

I opted for an additive approach in adding a datastore method rather
than modifying the existing ListTeamPolicies to avoid a large test
refactor.

- [ ] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [X] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)
- [X] Added/updated tests
- [X] Manual QA for all new/changed functionality

---------

Co-authored-by: RachelElysia <rachel@fleetdm.com>
2024-05-06 12:26:10 -04:00
Tim Lee
84f45e54d0 17745 queries backend (#18582)
#17745 

implement `merge_inherited` on the list queries endpoint to combine team
and inherited queries.

- [ ] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [X] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)
- [X] Added/updated tests
- [X] Manual QA for all new/changed functionality

---------

Co-authored-by: RachelElysia <rachel@fleetdm.com>
2024-05-06 12:26:10 -04:00
Victor Lyuboslavsky
9c714c544d
Optimized policy_stats updates to NOT lock the policy_membership table (#18720)
#16562

Optimized policy_stats updates to NOT lock the policy_membership table.
This should improve deployment performance with many global policies and
team hosts.

The original implementation that used INSERT ... SELECT (SELECT
COUNT(*)) ... caused performance issues. Given 50 global policies, 10
teams, and 10,000 hosts per team, the INSERT query took 30-60 seconds to
complete. Since it was an INSERT query, it blocked other hosts from
updating their policy results in policy_membership.

Now, we separate the INSERT from the SELECT, since SELECT by itself does
not block other hosts from updating their policy results. In addition,
we process one global policy at a time, which reduces the time to
complete the SELECT query to <2 seconds, and limits the memory usage. We
are not using a transaction to reduce locks. This means that INSERT may
fail if the policy was deleted by a parallel process. Also, the INSERT
may overwrite a clearing of the stats. This is acceptable, since these
are very rare cases. We log and proceed in that case.


# Checklist for submitter

If some of the following don't apply, delete the relevant line.

<!-- Note that API documentation changes are now addressed by the
product design team. -->

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [x] Added/updated tests
- [x] Manual QA for all new/changed functionality
2024-05-06 09:48:37 -05:00
Lucas Manuel Rodriguez
4a739fba8a
Cleanup query results after host is transferred to another team (#18712)
#18079

- [X] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [X] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)
- ~[ ] Added support on fleet's osquery simulator `cmd/osquery-perf` for
new osquery data ingestion features.~
- [X] Added/updated tests
- [X] If database migrations are included, checked table schema to
confirm autoupdate
- For database migrations:
- ~[ ] Checked schema for all modified table for columns that will
auto-update timestamps during migration.~
- ~[ ] Confirmed that updating the timestamps is acceptable, and will
not cause unwanted side effects.~
- ~[ ] Ensured the correct collation is explicitly set for character
columns (`COLLATE utf8mb4_unicode_ci`).~
- [X] Manual QA for all new/changed functionality
  - ~For Orbit and Fleet Desktop changes:~
- ~[ ] Manual QA must be performed in the three main OSs, macOS, Windows
and Linux.~
- ~[ ] Auto-update manual QA, from released version of component to new
version (see [tools/tuf/test](../tools/tuf/test/README.md)).~
2024-05-03 17:37:55 -03:00
Victor Lyuboslavsky
a3d94c8324
AI generated policy description/resolution (#18713)
Merging feature branch. Each commit into feature branch has already been
reviewed.
2024-05-03 15:23:27 -05:00
Victor Lyuboslavsky
8b9cef80bd
Fixed ingestion of private IPv6 address from agent. (#18738)
#18039 
Fixed ingestion of private IPv6 address from agent. Host details page
can now display private IPv6 address if private IPv4 does not exist.

How to set up an IPv6-only host:
https://www.loom.com/share/5e205549b6484df88702c27a5aa5a3ee

# Checklist for submitter
- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [x] Added/updated tests
- [x] Manual QA for all new/changed functionality
2024-05-03 15:07:09 -05:00
Victor Lyuboslavsky
4f4800be19
GitOps remove teams (#18640)
#16677 

Improvements to `fleetctl gitops` command:
- Added the ability to pass multiple files, like `fleetctl gitops -f
file1 -f file2`, where the first file must be the global configuration
- Added the ability to remove teams that were not specified in team
configs using the switch `--delete-other-teams`
- When passing a global config and team config during initial
configuration, the `org_settings.mdm.apple_bm_default_team` value can be
set to match the team that will be created by the provided team config.

After these changes are released to prod, we can update
https://github.com/fleetdm/fleet-gitops to use the new switches: #18692

# Checklist for submitter

If some of the following don't apply, delete the relevant line.

<!-- Note that API documentation changes are now addressed by the
product design team. -->

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [x] Added/updated tests
- [x] Manual QA for all new/changed functionality
2024-05-03 08:03:00 -05:00
Victor Lyuboslavsky
c0dbe78766
Per Figma, using default policy description/resolution if either is missing. (#18714)
#18187 
Per Figma, use the default policy description/resolution if either is
missing.
2024-05-02 15:11:54 -05:00
Tim Lee
536ccc91c0
18601 add ubuntu sources (#18602) 2024-05-02 13:20:00 -06:00
Victor Lyuboslavsky
e92b4628ff
Updated datastore mock. 2024-05-02 12:14:09 -05:00
Victor Lyuboslavsky
4946c96e77
AI-generated calendar backend changes (#18571)
#18464

Added `/fleet/autofill/policy` endpoint to get autogenerated policy
description and resolution for a given SQL query.

Added `server_settings.ai_features_disabled` setting to disable the
above endpoint.

For Google calendar integration,
- changed the event title to: "💻 🚫 Scheduled maintenance"
- updated event description to include policy description and resolution
if only one policy is failing

# Checklist for submitter

If some of the following don't apply, delete the relevant line.

<!-- Note that API documentation changes are now addressed by the
product design team. -->

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [x] Added/updated tests
- [x] Manual QA for all new/changed functionality

---------

Co-authored-by: Luke Heath <luke@fleetdm.com>
2024-05-02 11:56:54 -05:00
Tim Lee
648628d3be
Update Windows OS Version Reporting (#17682) 2024-05-01 12:02:16 -06:00
Tim Lee
aa3176f1b8
Use compiled regex for common pack delimiter parsing (#17595) 2024-05-01 09:42:03 -06:00
Dante Catalfamo
2c6e7c71a8
Zsh script support (#18411)
#17321
2024-04-30 14:38:56 -04:00
Roberto Dip
05719633a1
add consistent MDM host lifecycle management (#18510)
The mantra for MDM lifecycle events is:

> - Noah: When MDM is turned on, install fleetd, bootstrap package (if
DEP),
> and profiles. Don't clear host vitals (everything you see on the Host
>      details page)
>    - Noah: On re-enrollment, don't clear host vitals.
>    - Noah: On lock and wipe, don't clear host vitals.
>    - Noah: On delete, clear host vitals.

This addresses issues:

- https://github.com/fleetdm/fleet/issues/17243
- https://github.com/fleetdm/fleet/issues/17481
- https://github.com/fleetdm/fleet/issues/17292
- https://github.com/fleetdm/fleet/issues/18030
- https://github.com/fleetdm/fleet/issues/18031
2024-04-29 16:43:15 -03:00
Victor Lyuboslavsky
fa9373a68f
Updated host_operating_system INSERT. (#18556)
#16562 

Updated MySQL host_operating_system insert statement to reduce table
lock time.

# Checklist for submitter

If some of the following don't apply, delete the relevant line.

<!-- Note that API documentation changes are now addressed by the
product design team. -->

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [ ] Added/updated tests
  - Existing tests provide full coverage of the changes.
- [x] Manual QA for all new/changed functionality
2024-04-29 10:54:50 -05:00
Victor Lyuboslavsky
d0f0d3d017
When updating a policy's 'platform' field, the aggregated policy stats are now cleared. (#18415)
#18157
When updating a policy's 'platform' field, the aggregated policy stats
are now cleared.

# Checklist for submitter
- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [x] Added/updated tests
- [x] Manual QA for all new/changed functionality
2024-04-29 10:20:59 -05:00
Martin Angers
26b83de925
Fix sending of "install Fleetd" commands repeatedly on Azure-enrolled Windows devices (#18453) 2024-04-29 08:48:54 -04:00
Lucas Manuel Rodriguez
3e5f7d5cf5
Fix users query for linux devices (#18454)
#18424

I believe the hosts users for linux broke when we added Chrome support
(https://github.com/fleetdm/fleet/pull/10281/files).

- [X] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- ~[ ] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)~
- ~[ ] Added support on fleet's osquery simulator `cmd/osquery-perf` for
new osquery data ingestion features.~
- [x] Added/updated tests
- ~[ ] If database migrations are included, checked table schema to
confirm autoupdate~
- ~For database migrations:~
- ~[ ] Checked schema for all modified table for columns that will
auto-update timestamps during migration.~
- ~[ ] Confirmed that updating the timestamps is acceptable, and will
not cause unwanted side effects.~
- ~[ ] Ensured the correct collation is explicitly set for character
columns (`COLLATE utf8mb4_unicode_ci`).~
- [X] Manual QA for all new/changed functionality
  - ~For Orbit and Fleet Desktop changes:~
- ~[ ] Manual QA must be performed in the three main OSs, macOS, Windows
and Linux.~
- ~[ ] Auto-update manual QA, from released version of component to new
version (see [tools/tuf/test](../tools/tuf/test/README.md)).~
2024-04-26 15:05:34 -03:00
Roberto Dip
08b5e1c7b5
fixed a bug causing servers with Windows MDM only to crash (#18568) 2024-04-26 10:09:01 -05:00
Lucas Manuel Rodriguez
1b26129465
Delete expired activities in cleanup cron (#18441)
#16989

API draft PR: #17809.
UI draft PR: #18243.

- [X] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [X] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)
- ~[ ] Added support on fleet's osquery simulator `cmd/osquery-perf` for
new osquery data ingestion features.~
- [X] Added/updated tests
- ~[ ] If database migrations are included, checked table schema to
confirm autoupdate~
- ~For database migrations:~
- ~[ ] Checked schema for all modified table for columns that will
auto-update timestamps during migration.~
- ~[ ] Confirmed that updating the timestamps is acceptable, and will
not cause unwanted side effects.~
- ~[ ] Ensured the correct collation is explicitly set for character
columns (`COLLATE utf8mb4_unicode_ci`).~
- [X] Manual QA for all new/changed functionality
  - ~For Orbit and Fleet Desktop changes:~
- ~[ ] Manual QA must be performed in the three main OSs, macOS, Windows
and Linux.~
- ~[ ] Auto-update manual QA, from released version of component to new
version (see [tools/tuf/test](../tools/tuf/test/README.md)).~
2024-04-26 07:22:31 -03:00
Gabriel Hernandez
c423f415a6
Fix uploading signed apple mobileconfig profiles (#18482)
relates to #18389

This fixes an issue with some signed apple mobileconfig profiles were
not able to be uploaded.

<!-- Note that API documentation changes are now addressed by the
product design team. -->

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [x] Manual QA for all new/changed functionality
2024-04-25 17:09:53 +01:00
Victor Lyuboslavsky
edf290bf54
Adding logging level to frequent server log messages. (#18486) 2024-04-24 20:52:31 -05:00
Jacob Shandling
d7821685a8
Migrate logic from nvdtools into Fleet (#18244)
## Addresses #15999

- [x] Added/updated tests
- [ ] Manual QA for all new/changed functionality

---------

Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2024-04-24 15:25:59 -07:00
Dante Catalfamo
086e2464c2
Check macos version with semver for nudge disabling (#18485)
Fixes a bug where macos versions are incorrectly parsed for nudge
requirements
2024-04-23 10:09:47 -04:00
Martin Angers
f21aad446e
Fix creation of manual label that allowed overriding existing one (#18474) 2024-04-22 16:51:50 -04:00
Tim Lee
9e1878e01c
18439 Vulncheck data processing bug (#18440) 2024-04-22 09:36:20 -06:00
Lucas Manuel Rodriguez
74a9683637
Remove fmt.Println (#18426)
If this is for debugging let's add a comment :)
2024-04-19 14:39:07 -03:00
Roberto Dip
e39f5bce3b
implement logic to sign apple profiles (#16490)
#10418
2024-04-18 18:01:37 -03:00
Victor Lyuboslavsky
72cc82f60d
Ignoring Valve Corporation's Steam client's vulnerabilities on Windows and macOS (#18380)
#18126
Ignoring Valve Corporation's Steam client's vulnerabilities on Windows
and macOS
- On Windows and macOS, the true version of the Steam client (like
2021-04-10) cannot be retrieved by standard methods used on other
software. We would need to create custom logic to retrieve the version
of the Steam client.
- Steam client automatically updates itself, so security risk is
somewhat mitigated.

QA note: Items from software_cve table are cleared after 2 hours.

# Checklist for submitter

<!-- Note that API documentation changes are now addressed by the
product design team. -->

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [ ] Added/updated tests
- [x] Manual QA for all new/changed functionality
2024-04-18 10:12:49 -05:00
Martin Angers
d08d715e89
Fix the TestIntegrationsMDM/TestDEPProfileAssignment test. (#18367) 2024-04-17 11:06:13 -04:00
Victor Lyuboslavsky
a5c107e082
For calendar integration, calendar event no longer created when policy has an invalid SQL query. (#18352)
For calendar integration, calendar event no longer created when policy
has an invalid SQL query.
#18350 

# Checklist for submitter
- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [x] Added/updated tests
- [x] Manual QA for all new/changed functionality
2024-04-16 16:50:22 -05:00
Lucas Manuel Rodriguez
4a38135ea5
Fix TestIntegrations/TestUsers flaky test (#18251)
```
--- FAIL: TestIntegrations (47.44s)
    --- FAIL: TestIntegrations/TestUsers (1.42s)
        integration_core_test.go:4198:
            	Error Trace:	/Users/tim/workspace/fleet/server/service/integration_core_test.go:4198
            	Error:      	Not equal:
            	            	expected: 0x2
            	            	actual  : 0x1
            	Test:       	TestIntegrations/TestUsers
```
2024-04-16 18:40:29 -03:00
Sarah Gillespie
3ea7a4ba63
Merge branch 'main' into feat-macos-software-updates 2024-04-16 11:30:02 -05:00
Gabriel Hernandez
2fc4e520b8
add ability to create manual labels (#18303)
relates to #17031

Adds functionality to create manual labels in fleet.

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [x] Added/updated tests
- [x] M0anual QA for all new/changed functionality

---------

Co-authored-by: Martin Angers <martin.n.angers@gmail.com>
2024-04-16 17:22:08 +01:00