Commit Graph

1042 Commits

Author SHA1 Message Date
Zach Wasserman
416038a689
Update usage of os.IsNotExist (#1539)
Per [godoc](https://pkg.go.dev/os#IsNotExist), this is the preferred method.
2021-08-03 13:02:15 -07:00
Tomas Touceda
f2837fd4b3
Make decoder completely generic and simplify things (#1542)
* Make decoder completely generic and simplify things

* Add commends and unexport func
2021-08-03 16:56:54 -03:00
Tomas Touceda
7730515be7
Implement team schedules (#1528)
* Implement team schedules

* Improve description
2021-08-03 10:33:27 -03:00
Tomas Touceda
5859db36bb
Move logger up to the HTTP layer and make it generic (#1439)
* Add basic idea

* Implement the new logging strategy everywhere

* Remove unused const

* Add tests and fix error cases

* Fix logging in osquery service

* If there are extras, log info unless force debug

* Change to info

* Fix test

* Make logging context more chainable and force info for sessions
2021-08-02 19:06:27 -03:00
Tomas Touceda
18037ab4bd
Skip match to not add empty searches (#1522) 2021-07-30 16:18:38 -03:00
Benjamin Edwards
c18214be37
add logging settings to config api response (#1467)
- add docker-compose file for locally testing aws dependencies
- update firehose & kinesis configs to optionally supply endpoint url override
- serialize `logging` field in appconfig api response
2021-07-30 11:45:49 -04:00
Tomas Touceda
46b0b7765b
Issue 1435 software to cpe (#1488)
* WIP

* WIP

* Make path optional and fix tests

* Add first generate

* Move to nvd package

* remove replace

* Re-add replace

* It's path, not file name

* Change how db path is set and use etag

* Fix typos

* Make db generation faster

* Remove quotes

* Doesn't like comments

* Samitize etag and save to file

* Refactor some things and improve writing of etagenv

* Compress file and truncate amount of items for faster testing

* Remove quotes

* Try to improve performance

* Ignore truncate error if not exists

* Minor cleanup and make sqlite have cpe prefix

* Simplify code and test sync

* Add VCR for sync test

* Check for nvdRelease nil

* Add test for the actual translation

* Address review comments

* Rename generate command because we'll have a cve one too

* Move to its own dir

* Address review comments
2021-07-29 13:10:34 -03:00
Tomas Touceda
866e8a2961
Fix typo, it's target_count (#1478)
* Fix typo, it's target_count

* Update server/service/service_campaigns.go

Co-authored-by: gillespi314 <73313222+gillespi314@users.noreply.github.com>

Co-authored-by: gillespi314 <73313222+gillespi314@users.noreply.github.com>
2021-07-26 16:12:18 -03:00
Tomas Touceda
8f854144c5
Return email as well in activities (#1466)
* Return email as well in activities

* Add team name
2021-07-23 17:00:26 -03:00
Tomas Touceda
4cd169cad7
Return gravatar whenever available (#1448) 2021-07-22 12:28:42 -03:00
Benjamin Edwards
799243ffb5
Windows friendly changes after walking through getting started guide (#1441)
* update .gitattributes to be explicit about line endings with regards to the test certs
* update building-fleet guide to include python2 dependency on windows
* update configuration to default to OS specific temporary directories
2021-07-21 20:49:44 -04:00
Tomas Touceda
484c6153e3
Issue 1359 fleetctl team transfer (#1413)
* wip

* Add delete user command and translator

* Add host transfer command

* Add changes file

* Undo bad refactor

* Fix copypaste error

* Implement with interfaces instead of assertions

* Ad documentation and simplify implementation further

* Update docs/1-Using-Fleet/3-REST-API.md

Co-authored-by: Zach Wasserman <zach@fleetdm.com>

Co-authored-by: Zach Wasserman <zach@fleetdm.com>
2021-07-21 14:03:10 -03:00
Tomas Touceda
ece05eeaed
Issue 1321 usage statistics (#1415)
* WIP

* Send usage analytics

* Improve loggin of cron tasks and fix test

* Implement appconfig method now that we are checking that as well

* Address review comments
2021-07-20 18:39:50 -03:00
Tomas Touceda
a6cff7ea89
Migrate all mysql tests to the new form (#1408)
* Migrate all mysql tests to the new form

* Only dump sql if MYSQL_TEST is on

* Removing parallel until we get rid of this code

* Move TestMain to an actual _test file

* A little experiment with tmpfs to speed up the db

* Let's make sure the dump.sql file is also in ram
2021-07-19 18:20:31 -03:00
Tomas Touceda
9863b0f4bb
Issue 1361 fleetctl teams (#1405)
* WIP

* Add get user_roles and apply for a user_roles spec to fleetctl

* Uncomment other tests

* Update test to check output

* Update test with the new struct

* Mock token so that it doesn't pick up the one in the local machine

* Address review comments

* Fix printJSON and printYaml

* Fix merge conflict error

* WIP

* wip

* wip

* Finish implementation

* Address review comments

* Fix flaky test
2021-07-19 16:48:49 -03:00
Tomas Touceda
29570bd860
Issue 1278 select leader (#1367)
* Add leader selection

* remove comment

* Address review comments

* Add changes file

* Simplify implementation

* Simplify further

* Whoops, removed a little too much
2021-07-19 15:08:41 -03:00
Tomas Touceda
545b3f396e
Issue 1362 fleetctl user roles (#1397)
* WIP

* Add get user_roles and apply for a user_roles spec to fleetctl

* Uncomment other tests

* Update test to check output

* Update test with the new struct

* Mock token so that it doesn't pick up the one in the local machine

* Address review comments

* Fix printJSON and printYaml

* Fix merge conflict error

* If both roles are specified, fail

* Fix test

* Switch arguments around

* Update test with the new rule

* Fix other tests that fell through the cracks
2021-07-16 15:28:13 -03:00
Tomas Touceda
a38a7f4ad4
Refactor one mysql test to be able to run independently (#1379)
* Refactor one mysql test to be able to run independently

* Initialize schema once

* Address review comments
2021-07-16 13:13:51 -03:00
Tomas Touceda
2d553db2aa
Issue 1231 add global schedule (#1383)
* Add Global Schedule

* Uncomment tests

* Uncomment integration tests

* Add targets for global schedule

* Add host label

* Simplify implementation

* wip

* Fix mock

* Add missing test

* Further simplify the implementation

* Forgot to remove test name

* Update names
2021-07-16 10:15:15 -03:00
Tomas Touceda
804136127e
Remove repository sources from software inventory (#1387) 2021-07-15 10:23:27 -03:00
Tomas Touceda
74fecf0d5b
Remove duplicate enroll secrets (#1388) 2021-07-14 19:05:54 -03:00
Tomas Touceda
82ab0a798e
Add host users (#1334)
* Add host users

* Add changes file and test removing pull_request from the on test

* Remove users and store the removal timestamp

* Improve test yml to allow for PRs from forks
2021-07-13 17:15:38 -03:00
Tomas Touceda
d5e40f329e
Issue 1324 add activity feed (#1343)
* Add activities generation

* Add activities endpoint

* Fix merge error

* Fix indentation issue

* Add changes file

* Address PR review comments

* Add mock activity func

* Address codacy warings

* Set foreign key but on delete set null

* Make user_id set to null if deleted
2021-07-13 16:54:22 -03:00
Tomas Touceda
322ac3c8f6
Make roles for users mandatory (#1338)
* Make roles for users mandatory

* Remove nop migration

* Add missing test for wrong role

* Properly validate global and team roles

* Address codacy issues

* Address codacy review

* No need to check for nil
2021-07-13 16:33:04 -03:00
Zach Wasserman
8723b83039
Fix data race in inmem query results test (#1369)
Missed locking caused a race condition detected with the --race flag:

```
==================
WARNING: DATA RACE
Read at 0x00c0004b2cf0 by goroutine 67:
  runtime.mapaccess2_fast64()
      /usr/local/Cellar/go/1.16.5/libexec/src/runtime/map_fast64.go:52 +0x0
  github.com/fleetdm/fleet/v4/server/pubsub.(*inmemQueryResults).WriteResult()
      /Users/zwass/dev/fleet/server/pubsub/inmem_query_results.go:37 +0x84
  github.com/fleetdm/fleet/v4/server/service.(*Service).ingestDistributedQuery()
      /Users/zwass/dev/fleet/server/service/service_osquery.go:1020 +0x258
  github.com/fleetdm/fleet/v4/server/service.TestIngestDistributedQueryRecordCompletionError()
      /Users/zwass/dev/fleet/server/service/service_osquery_test.go:1499 +0x61c
  testing.tRunner()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1193 +0x202

Previous write at 0x00c0004b2cf0 by goroutine 104:
  runtime.mapassign_fast64()
      /usr/local/Cellar/go/1.16.5/libexec/src/runtime/map_fast64.go:92 +0x0
  github.com/fleetdm/fleet/v4/server/pubsub.(*inmemQueryResults).getChannel()
      /Users/zwass/dev/fleet/server/pubsub/inmem_query_results.go:31 +0x1a4
  github.com/fleetdm/fleet/v4/server/pubsub.(*inmemQueryResults).ReadChannel()
      /Users/zwass/dev/fleet/server/pubsub/inmem_query_results.go:53 +0x64
  github.com/fleetdm/fleet/v4/server/service.TestIngestDistributedQueryRecordCompletionError.func1()
      /Users/zwass/dev/fleet/server/service/service_osquery_test.go:1493 +0x117

Goroutine 67 (running) created at:
  testing.(*T).Run()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1238 +0x5d7
  testing.runTests.func1()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1511 +0xa6
  testing.tRunner()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1193 +0x202
  testing.runTests()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1509 +0x612
  testing.(*M).Run()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1417 +0x3b3
  main.main()
      _testmain.go:303 +0x236

Goroutine 104 (running) created at:
  github.com/fleetdm/fleet/v4/server/service.TestIngestDistributedQueryRecordCompletionError()
      /Users/zwass/dev/fleet/server/service/service_osquery_test.go:1492 +0x558
  testing.tRunner()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1193 +0x202
==================
==================
WARNING: DATA RACE
Read at 0x00c0000ff2d8 by goroutine 67:
  github.com/fleetdm/fleet/v4/server/pubsub.(*inmemQueryResults).WriteResult()
      /Users/zwass/dev/fleet/server/pubsub/inmem_query_results.go:37 +0xa4
  github.com/fleetdm/fleet/v4/server/service.(*Service).ingestDistributedQuery()
      /Users/zwass/dev/fleet/server/service/service_osquery.go:1020 +0x258
  github.com/fleetdm/fleet/v4/server/service.TestIngestDistributedQueryRecordCompletionError()
      /Users/zwass/dev/fleet/server/service/service_osquery_test.go:1499 +0x61c
  testing.tRunner()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1193 +0x202

Previous write at 0x00c0000ff2d8 by goroutine 104:
  github.com/fleetdm/fleet/v4/server/pubsub.(*inmemQueryResults).getChannel()
      /Users/zwass/dev/fleet/server/pubsub/inmem_query_results.go:31 +0x1bc
  github.com/fleetdm/fleet/v4/server/pubsub.(*inmemQueryResults).ReadChannel()
      /Users/zwass/dev/fleet/server/pubsub/inmem_query_results.go:53 +0x64
  github.com/fleetdm/fleet/v4/server/service.TestIngestDistributedQueryRecordCompletionError.func1()
      /Users/zwass/dev/fleet/server/service/service_osquery_test.go:1493 +0x117

Goroutine 67 (running) created at:
  testing.(*T).Run()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1238 +0x5d7
  testing.runTests.func1()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1511 +0xa6
  testing.tRunner()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1193 +0x202
  testing.runTests()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1509 +0x612
  testing.(*M).Run()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1417 +0x3b3
  main.main()
      _testmain.go:303 +0x236

Goroutine 104 (running) created at:
  github.com/fleetdm/fleet/v4/server/service.TestIngestDistributedQueryRecordCompletionError()
      /Users/zwass/dev/fleet/server/service/service_osquery_test.go:1492 +0x558
  testing.tRunner()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1193 +0x202
==================
--- FAIL: TestIngestDistributedQueryRecordCompletionError (0.01s)
    service_osquery_test.go:1502: PASS:	QueryCompletedByHost(string,uint)
    testing.go:1092: race detected during execution of test
==================
WARNING: DATA RACE
Read at 0x00c0000f8570 by goroutine 70:
  runtime.mapaccess2_fast64()
      /usr/local/Cellar/go/1.16.5/libexec/src/runtime/map_fast64.go:52 +0x0
  github.com/fleetdm/fleet/v4/server/pubsub.(*inmemQueryResults).WriteResult()
      /Users/zwass/dev/fleet/server/pubsub/inmem_query_results.go:37 +0x84
  github.com/fleetdm/fleet/v4/server/service.(*Service).ingestDistributedQuery()
      /Users/zwass/dev/fleet/server/service/service_osquery.go:1020 +0x258
  github.com/fleetdm/fleet/v4/server/service.TestIngestDistributedQuery()
      /Users/zwass/dev/fleet/server/service/service_osquery_test.go:1530 +0x5bc
  testing.tRunner()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1193 +0x202

Previous write at 0x00c0000f8570 by goroutine 71:
  runtime.mapassign_fast64()
      /usr/local/Cellar/go/1.16.5/libexec/src/runtime/map_fast64.go:92 +0x0
  github.com/fleetdm/fleet/v4/server/pubsub.(*inmemQueryResults).getChannel()
      /Users/zwass/dev/fleet/server/pubsub/inmem_query_results.go:31 +0x1a4
  github.com/fleetdm/fleet/v4/server/pubsub.(*inmemQueryResults).ReadChannel()
      /Users/zwass/dev/fleet/server/pubsub/inmem_query_results.go:53 +0x64
  github.com/fleetdm/fleet/v4/server/service.TestIngestDistributedQuery.func1()
      /Users/zwass/dev/fleet/server/service/service_osquery_test.go:1524 +0x117

Goroutine 70 (running) created at:
  testing.(*T).Run()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1238 +0x5d7
  testing.runTests.func1()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1511 +0xa6
  testing.tRunner()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1193 +0x202
  testing.runTests()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1509 +0x612
  testing.(*M).Run()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1417 +0x3b3
  main.main()
      _testmain.go:303 +0x236

Goroutine 71 (running) created at:
  github.com/fleetdm/fleet/v4/server/service.TestIngestDistributedQuery()
      /Users/zwass/dev/fleet/server/service/service_osquery_test.go:1523 +0x4f4
  testing.tRunner()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1193 +0x202
==================
==================
WARNING: DATA RACE
Read at 0x00c000c480d8 by goroutine 70:
  github.com/fleetdm/fleet/v4/server/pubsub.(*inmemQueryResults).WriteResult()
      /Users/zwass/dev/fleet/server/pubsub/inmem_query_results.go:37 +0xa4
  github.com/fleetdm/fleet/v4/server/service.(*Service).ingestDistributedQuery()
      /Users/zwass/dev/fleet/server/service/service_osquery.go:1020 +0x258
  github.com/fleetdm/fleet/v4/server/service.TestIngestDistributedQuery()
      /Users/zwass/dev/fleet/server/service/service_osquery_test.go:1530 +0x5bc
  testing.tRunner()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1193 +0x202

Previous write at 0x00c000c480d8 by goroutine 71:
  github.com/fleetdm/fleet/v4/server/pubsub.(*inmemQueryResults).getChannel()
      /Users/zwass/dev/fleet/server/pubsub/inmem_query_results.go:31 +0x1bc
  github.com/fleetdm/fleet/v4/server/pubsub.(*inmemQueryResults).ReadChannel()
      /Users/zwass/dev/fleet/server/pubsub/inmem_query_results.go:53 +0x64
  github.com/fleetdm/fleet/v4/server/service.TestIngestDistributedQuery.func1()
      /Users/zwass/dev/fleet/server/service/service_osquery_test.go:1524 +0x117

Goroutine 70 (running) created at:
  testing.(*T).Run()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1238 +0x5d7
  testing.runTests.func1()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1511 +0xa6
  testing.tRunner()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1193 +0x202
  testing.runTests()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1509 +0x612
  testing.(*M).Run()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1417 +0x3b3
  main.main()
      _testmain.go:303 +0x236

Goroutine 71 (running) created at:
  github.com/fleetdm/fleet/v4/server/service.TestIngestDistributedQuery()
      /Users/zwass/dev/fleet/server/service/service_osquery_test.go:1523 +0x4f4
  testing.tRunner()
      /usr/local/Cellar/go/1.16.5/libexec/src/testing/testing.go:1193 +0x202
==================
--- FAIL: TestIngestDistributedQuery (0.01s)
    service_osquery_test.go:1532: PASS:	QueryCompletedByHost(string,uint)
    testing.go:1092: race detected during execution of test
FAIL
FAIL	github.com/fleetdm/fleet/v4/server/service	42.743s
```
2021-07-13 12:27:41 -07:00
Zach Wasserman
bc1698767e
Fix Kinesis/Firehose error messages (#1316)
Previously we unintentionally logged the *pointer* when we intended to
log the *value* of how many records failed.
2021-07-12 10:18:02 -07:00
Tomas Touceda
f534b8b6fe
When creating a pack store team, host, and label ids provided (#1332)
* When creating a pack store team, host, and label ids provided

* Mock store to test only the service
2021-07-12 10:48:50 -03:00
gillespi314
2d16ad1608
Fix asset url for email template images (#1347) 2021-07-09 18:34:08 -05:00
Tomas Touceda
7d3d84faaf
Make it possible to clear host settings from app config (#1339) 2021-07-09 15:13:11 -03:00
Tomas Touceda
12215bfbbd
Disable user sso_enable if org is disabling sso (#1331)
* Disable user sso_enable if org is disabling sso

* Cleanup test

* Add withTx and use it in SaveConfig
2021-07-09 13:12:21 -03:00
Tomas Touceda
18fa2f6a02
Issue 1009 calculate diff software (#1305)
* First approach to diff

* Refactor things for better readability and testing

* Remove draft comment for algorithm

* Format things a bit better

* Remove unused and simplify code a bit

* Refactor for readability and testing

* Add changes file

* Implement new approach based on review comments

* Make sure to only delete from the current host

* Add single uninstall test and fix code

* Improve code based on review
2021-07-08 13:57:43 -03:00
Tomas Touceda
39034071ca
Issue 1286 improve errors (#1322)
* Refactor error handling for better extensibility and add more scaffolding for specific db errors

* Add integration tests to check errors from mysql are translated properly

* Address review comments

* Add changes file
2021-07-08 12:50:43 -03:00
Zach Wasserman
d790ff7d80
Allow Redis connection with unknown CLUSTER command (#1312)
This improves compatibility with GCP Memorystore Redis.
2021-07-07 15:57:32 -07:00
Tomas Touceda
64f6a2f790
Return a distinct error when the auth header is not available vs when it's bad (#1294) 2021-07-05 10:17:31 -03:00
Tomas Touceda
05ba38ce2f
Fetch all data for a host when listing it (#1293) 2021-07-02 12:59:42 -03:00
Zach Wasserman
8384034e04
Update create user validation and documentation (#1285)
Closes #1272
2021-07-02 08:35:26 -07:00
Zach Wasserman
8be9068c1c
Fix migration for MariaDB compatibility (#1280)
Give unique names to each new foreign key in the migrations.

Fixes #1279
2021-07-01 15:59:31 -07:00
Scott Lampert
fee860bc7a
Fix fleetctl setup requiring https for localhost (#1270)
This fixes a reversion with fleetctl setup that requires https even for localhost connections. This was previously fixed in #489.
2021-06-30 15:31:37 -07:00
Zach Wasserman
e0799bbc59
Include Team names when listing label hosts (#1267)
Fixes #1266
2021-06-30 09:28:45 -07:00
Zach Wasserman
a7461d3ece
Improvements to fleetctl enroll secret specs (#1244)
- Do not render Team ID if null.
- Make request and response schema consistent (breaking change).

Fixes #186
2021-06-29 10:58:15 -07:00
Zach Wasserman
782020c320
Add logging for Teams endpoints (#1254) 2021-06-29 10:36:49 -07:00
Zach Wasserman
959c1fda81
Allow global maintainer to transfer hosts between Teams (#1243)
Reclassify these operations as "host write" to apply the appropriate permissions.

Fixes #1237
2021-06-28 16:57:56 -07:00
Zach Wasserman
c5280c0517
Add v4 suffix in go.mod (#1224) 2021-06-25 21:46:51 -07:00
gillespi314
da6394a6b7
Fix invite email template (#1202) 2021-06-25 14:10:03 -05:00
gillespi314
b02d8c8dd5
Remove unused image file (#1201) 2021-06-24 18:14:25 -05:00
RachelElysia
c5ff275783
Replace invitedbyusername with invitedby (#1200) 2021-06-24 14:52:09 -07:00
RachelElysia
aeb852e168
Remove username from UI (#1168)
* Remove username from UI code
* Remove username from tests
* Remove username from database
* Modify server endpoints for removing username
* Implement backend aspects of removing username
* Update API docs
* Add name to fleetctl
2021-06-24 13:42:29 -07:00
gillespi314
4909c0a4c5
Update email templates (#1175)
* Update email templates

* Update image file locations for email templates
2021-06-24 14:56:26 -05:00
Zach Wasserman
9d5c87ecf2
Fix additional permission error in reset password (#1187) 2021-06-24 08:59:43 -07:00
Zach Wasserman
1417d01407
Make naming of host columns consistent (#1183)
Adding consistency between API and DB helps to make it easier for users
and developers working with the API to correctly order things.

Closes #317
2021-06-23 17:32:19 -07:00
Zach Wasserman
675e551484
Fix authorization check in reset password (#1182)
Improper authorization checks made it so that users could not reset
their password with a reset token.
2021-06-23 15:59:13 -07:00
Zach Wasserman
2b3f968478
Fix forbidden error for password reset (#1171)
Access the app config directly through the data store, skipping the
incorrect permission check on the service method.
2021-06-23 08:45:03 -07:00
Zach Wasserman
0a77f79d22
Backend and fleetctl for usage analytics (#1167)
- Add enable_analytics column to database.
- Allow enable_analytics to be set via API.
- Add messaging in fleetctl setup.

Note that this defaults to off for existing installations, and defaults
on for newly set up installs.

No collection or sending of analytics yet exists, we are strictly
storing the preference at this time.

Part of #454
2021-06-22 18:02:20 -07:00
Zach Wasserman
4800856bf7
Add label ID to get labels response (#1164)
Fixes #1065
2021-06-22 16:41:25 -07:00
Zach Wasserman
b859f7b747
Sort labels for membership update (#1156)
This may help with deadlocks on the `label_membership` table. It is not
clear from MySQL documentation whether the order of the records is
significant for locking within a single query. If it is, this should
help the problem. If it is not, this should have no negative impact.

May fix #1146
2021-06-21 16:10:24 -07:00
Zach Wasserman
19e8da177f
Allow Packs to be targeted to Teams (#1130)
- Add additional target type for packs.
- Refactor pack target datastore.
- Fixes for frontend target selector tier logic on packs page.
2021-06-18 09:43:16 -07:00
Zach Wasserman
2ad557e3b3 Merge branch 'main' into teams 2021-06-18 09:42:20 -07:00
dsbaha
47b423ee29
Add Redis cluster support (#1045)
This should support Redis in both cluster and non-cluster modes.

Updates were made separately to github.com/throttled/throttled to support the slight changes in types.

Co-authored-by: Joseph Macaulay <joseph.macaulay@uber.com>
Co-authored-by: Zach Wasserman <zach@fleetdm.com>
2021-06-18 08:51:47 -07:00
Zach Wasserman
4f8ad2daa0
Return license info after app config modified (#1137) 2021-06-18 08:34:49 -07:00
Martavis Parker
5b2cac31d9
Agent options added to organization settings (#1120)
* #511 refactored update options - new params & ts

* updated server to include agent_options for read and update

* added agent options form to org settings

* #511 finished connecting agent form to server

* #511 fixing api to save/read agent options

* #511 linted

* #511 fixed reading & updating agent options

* #511 api fixes to support agent options

* #511 removed log

* Fix json.RawMessage pointers in tests

Co-authored-by: Zach Wasserman <zach@fleetdm.com>
2021-06-17 13:47:15 -07:00
Zach Wasserman
6b59a40dbc
Add backend and fleetctl support for API-only user (#1119)
- Add api_only to users table.
- Pass api_only values through service.
- Allow setting api_only in `fleetctl user create`.

Backend part of #402
2021-06-16 18:11:28 -07:00
Zach Wasserman
6249beb465
Reorder migrations for pre-4.0 upgrades (#1114)
Reorder migrations from the long-running `teams` branch to ensure that
they can run successfully for deployments upgrading from a pre-4.0
release.

All migrations from the `teams` branch are reordered to take place
_after_ all migrations from the `main` branch, using `20210601` as the
new date, after the latest released `main` branch migration on `20210526`.

Fixes #1058
2021-06-16 11:58:00 -07:00
Zach Wasserman
d78c5fd124
Clean up service and return license errors (#1097)
- Expose license errors instead of permission errors by adding explicit skip authorization.
- Remove pre-Teams authorization checks from service.

Fixes #964
2021-06-16 10:55:41 -07:00
noahtalerman
3fe13be701
Update links to main branch in email templates (#1086)
- Update links to documentation
- Update link to assets by editing `getAssetURL()`
- Prettier did some reformatting of the email template code which is resulting in a larger amount of lines changed
2021-06-15 14:29:20 -04:00
Zach Wasserman
233cce6120
Handle missing server_url in setup (#1093)
Improve error handling to avoid a nil pointer panic in the setup endpoint.
2021-06-15 11:25:52 -07:00
RachelElysia
5e52ba7aea
User Management Page: Edit user's email flash message (#1084)
* Render flash message with sender/receiver information on user's email update
2021-06-15 10:35:28 -04:00
Zach Wasserman
0a99ec751c
Fix targeting Teams in live queries (#1043)
Properly handle the `TargetTeam` type, allowing live queries to
successfully execute against Teams.

Part of #1022
2021-06-09 18:56:57 -07:00
Zach Wasserman
6a18b2a250
Appropriately filter teams returned in targets API (#1042)
Fixes #1021 by adding the appropriate teams filtering.
2021-06-09 18:05:04 -07:00
Zach Wasserman
e8bb0f9eb5
Allow team user to view host details page (#1033)
Fixes #1019
2021-06-09 13:09:43 -07:00
Zach Wasserman
0fd8590605
Add additional logging for label save failures (#1012)
This is intended to help with debugging #744.
2021-06-08 15:29:26 -07:00
Zach Wasserman
6013194c1d
Reduce default session duration to 4 hours (#981) 2021-06-06 18:28:47 -07:00
Zach Wasserman
229a9afed2
Change name of localstorage auth token (#980) 2021-06-06 18:28:37 -07:00
Zach Wasserman
0356115b03
Remove JWT in Fleet session management (#979)
See #978 for motivations for this change.

Closes #978.
2021-06-06 18:10:58 -07:00
Zach Wasserman
db459d3363
Continue to update names in backend code and docs (#976) 2021-06-06 16:58:23 -07:00
Zach Wasserman
fb32f0cf40
Remove kolide types and packages from backend (#974)
Generally renamed `kolide` -> `fleet`
2021-06-06 15:07:29 -07:00
Zach Wasserman
fa01df79d5 Merge branch 'master' into teams 2021-06-05 06:27:38 -07:00
Zach Wasserman
ae1f41638c
Log subject/object/action with authz failures (#972) 2021-06-05 06:22:13 -07:00
Zach Wasserman
08d57b40d1
Remove deprecated kolide names from API routes and configuration (#957)
Closes #260
2021-06-04 16:51:18 -07:00
Zach Wasserman
16a8e13f85
Fix tls_compatibility key in yaml config (#955)
Closes #271
2021-06-04 08:44:36 -07:00
Zach Wasserman
e4358a92bc
Filter hosts and label counts by teams (#949)
- Add TeamFilter to relevant host and label methods.
- Pass appropriate filter in service methods.

The dashboard should now show the appropriate hosts for a user's team membership.
2021-06-03 18:53:43 -07:00
Zach Wasserman
b3bafdce24
Return error messages for authentication errors (#950)
Previously the authorization middleware was masking the error when
authentication failed.
2021-06-03 18:24:23 -07:00
Zach Wasserman
18faa5a06b
Add authorization checks in service (#938)
- Add policy.rego file defining authorization policies.
- Add Go integrations to evaluate Rego policies (via OPA).
- Add middleware to ensure requests without authorization check are rejected (guard against programmer error).
- Add authorization checks to most service endpoints.
2021-06-03 16:24:15 -07:00
Zach Wasserman
6f51bd9cb5
Remove Redis read/write timeouts (#943)
If no results were sent over the pubsub channel, the client would hang
up. This would cause the query to seem "hung".

Closes #911
2021-06-03 10:49:25 -07:00
Zach Wasserman
417ef2c9b6
Refactor teams service methods (#910)
- Move team-related service methods to `ee/server/service`.
- Instantiate different service on startup based on license key.
- Refactor service errors into separate package.
- Add support for running E2E tests in both Core and Basic tiers.
2021-05-31 17:07:51 -07:00
Zach Wasserman
9876dbe6b6
Implement license loading and validation (#908)
- Load license from ES256 signed JWT key.
- Parse license claims into LicenseInfo struct.
- Update contribution documentation with sample license key.

Closes #816.
2021-05-31 11:35:15 -07:00
Zach Wasserman
a5bd03e5d7 Merge branch 'master' into teams 2021-05-31 10:56:50 -07:00
Zach Wasserman
64f2cfc9cd
Refactor enroll secrets to support Teams (#903)
- Add `team_id` field to secrets.
- Remove secret `name` and `active` fields (migration deletes inactive secrets).
- Assign hosts to Team based on secret provided.
- Add API for retrieving secrets by Team.
2021-05-31 09:02:05 -07:00
Zach Wasserman
8ee47f8b23
Add support for Teams in targets and live queries (#880)
- Accept Teams as a searchable target type for the target selection API.
- Accept Teams for targets in running live queries.
- Refactoring to support these changes.
- Update API documentation.
2021-05-27 13:18:00 -07:00
Zach Wasserman
cebd4df0f5
Update live query and targets APIs for Teams (#876)
- Take query_id in live query and target APIs.
- Use query_id to determine observer targets.
- Update documentation.
2021-05-26 20:45:06 -07:00
Zach Wasserman
48c413a254
Split host additional into separate table (#875)
- Move host `additional` into a separate table.
- Join when that data is needed.
- API change: `/api/v1/fleet/hosts` now returns only the requested
  `additional` columns, unless `*` is provided as the sole argument.

Background:

A customer reported that MySQL binlogs grew huge and replication lag
went way up when data was stored in the `additional` column. In this
deployment MySQL was running with ROW replication. This would cause the
entire `additional` data to be copied on each update of the host checkin
time. While switching to STATEMENT or MIXED replication would likely
mitigate the issue, this was not an option in their environment.
2021-05-26 16:24:12 -07:00
Zach Wasserman
a2a7082bd3
Implement add hosts to team by filters API (#866)
- Add hosts to team using label, status, and query filters.
- Documentation (+ docs for regular add hosts to team).
2021-05-25 21:29:52 -07:00
Zach Wasserman
0e9eb920d4
Refactor struct slices for consistent pointer use (#864)
Some datastore and service methods would return slices of structs,
rather than slices to pointers of structs (which most methods used).
Make this more consistent.
2021-05-25 18:53:22 -07:00
Zach Wasserman
76f8d59290
Refactor usage of null values in Teams models (#863)
- Use pointers rather than null package types.
- Use new internal ptr package.
- Improved handling of changing user teams/roles.
2021-05-25 15:46:46 -07:00
Zach Wasserman
fef1ce579e
Fix host count for list teams (#861)
- Add test
2021-05-25 15:30:01 -07:00
WangXiang
c58a77d2a3
Include more detailed error messages in query result stream (#835) 2021-05-25 09:15:39 -07:00
Zach Wasserman
15b81824f5
Filter query page API responses based on team membership (#850)
- Include only hosts that the user has access to in search targets API.
- Add parameter to specify whether `observer` hosts should be included.
- Generate counts based on which hosts user can access.
- Update API doc.
2021-05-24 21:34:08 -07:00
Zach Wasserman
e33391e8d3
Cleanup live query store for orphaned query (#847)
Cleans up a case in which a query could continue to be returned even
after it had been detected orphaned.
2021-05-24 20:36:40 -07:00
Zach Wasserman
8ec938b272
Include null team name in teams response (#824)
When a host does not have a team, return null rather than a missing
team_name attribute.
2021-05-20 15:27:36 -04:00
Zach Wasserman
82fe7c0035
Fix setting observer_can_run in query API (#823)
Previous work in #777 added the datastore and model layers, but didn't
handle setting this value in the service and transport.

Fixes #822
2021-05-20 10:28:55 -07:00
Zach Wasserman
83b7f79699
Stub out licensing API (#810)
- Add config option for license key.
- Define license details data structure.
- Include license details in app config API responses.

Currently any non-empty value for `--license_key` behaves as though the
installation is licensed for `basic`. If the license key is empty,
`core` is returned.

Still to come is the appropriate parsing for the license key.
2021-05-19 17:29:38 -07:00
Noah Talerman
72882e8f9f Merge branch 'master' into teams 2021-05-19 13:16:54 -04:00
Zach Wasserman
1638d5e2da
Update Redigo version and timeouts (#793)
- Use newer version of Redigo that properly handles TLS mismatch.
- Add timeouts for Redis TCP connection.

Fixes #792
2021-05-18 15:04:14 -07:00
Zach Wasserman
ea0c6c8e3f
Include team name in host API responses (#781)
Update model and datastore methods to retrieve team name.
2021-05-17 17:52:59 -07:00
Zach Wasserman
85d9d00096
Add "observer can run" to query objects (#777)
- Database migration.
- Update model and datastore methods.
2021-05-17 12:23:56 -07:00
Zach Wasserman
79138d4b60
Move and refactor host team transfer endpoint (#778)
- Move API endpoint to `/hosts/transfer`.
- Refactor service and datastore methods from teams to hosts.
2021-05-17 12:23:21 -07:00
WangXiang
468754f2b9
Format and clean code (#774)
1. use [staticcheck](https://staticcheck.io/) to check the code, and fix some issues.
2. use `go fmt` to format the code.
3. use `go mod tidy` clean the go mod.
2021-05-17 10:29:50 -07:00
Zach Wasserman
027b12e6c4
Fix foreign key cascade for query stats table (#776)
Introduces the appropriate cascading for foreign keys on the
scheduled_query_stats table to prevent errors when deleting the
associated packs, scheduled queries, and queries.

Fixes #764
Fixes #766
2021-05-17 10:26:01 -07:00
Josh Brower
86745ba2dc
Add ability to duplicate live query results in Redis (#762)
This feature enables a new config option (redis.duplicate_results). When set to true, all Live Query results will be copied to an additional Redis pubsub channel named LQDuplicate

This is useful in a scenario that would involve shipping the Live Query results outside of Fleet, near-realtime.
2021-05-13 16:01:31 -07:00
Zach Wasserman
daa8eeb9d0
Add refetch host API (#767)
This allows the host details to be refetched on the next check in,
rather than waiting for the normal interval to go by. Associated UI
changes are in-progress.

- Migration and service methods for requesting refetch.
- Expose refetch over API.
- Change detail query logic to respect this flag.
2021-05-13 13:09:22 -07:00
Zach Wasserman
1a29a408ce
Add support for bulk transfer of hosts for team (#761)
- Relevant datastore method.
- Expose via API endpoint /teams/:id/hosts.
2021-05-12 19:05:45 -07:00
Zach Wasserman
9de5b720b4
Implement API endpoints for Teams agent options (#757)
- Add agent options endpoint.
- Remove setting agent options from standard modify team endpoint.
2021-05-12 10:38:00 -07:00
Zach Wasserman
9b4976ef8f
Prevent modify user to include global and team roles (#695)
A user should have a global role or roles on some teams, but not both.
This ensures that is set properly and does validation.
2021-05-12 08:31:20 -07:00
Zach Wasserman
b1a98a6e91
Update agent options storage for teams (#754)
- Allow agent options to be set on per-team basis.
- Move global agent options into app configs.
- Update logic for calculating agent options for hosts.
- Updates to relevant testing.
2021-05-11 18:15:16 -07:00
Michael Samuel
fb45806088
Copy log fields into GCP PubSub attributes (#712)
Add a config setting to allow copying message fields and decorations into Google Pub/Sub attributes, making it possible to use these values for subscription filters.
2021-05-08 12:29:52 -07:00
dsbaha
1cb514c460
Add flag to disable HTTP keepalives (#741)
In some environments, disabling keepalives helps prevent buildup of TCP sockets.
2021-05-07 17:29:54 -07:00
Zach Wasserman
56a9e2cf20
Add description to returned query stats (#742)
Gets the description from the associated query.
2021-05-07 12:47:52 -07:00
Zach Wasserman
f788254e61
Implement storage of scheduled query statistics (#735)
Track all data from the osquery_schedule table on a per-host basis. This
data is now returned when retrieving host details in the API.
2021-05-06 21:05:09 -07:00
Zach Wasserman
b2b53ecbbe
Add agent options on a per-team basis (#696)
Solely API implementation. Does not yet handle returning the options
during agent requests.
2021-05-03 09:32:04 -07:00
Zach Wasserman
596e017d44
Fix admin setup (#701)
Fixes a null pointer issue and clarifies setup logic.
2021-05-03 09:31:51 -07:00
Zach Wasserman
a17556b2db Merge branch 'master' into teams 2021-04-30 09:40:10 -07:00
Zach Wasserman
2bdc39390a
Fix handling of MySQL TLS flags (#689)
Incorrect handling of the flags prevented users from setting up TLS
connections to the MySQL server.

Fixes #320
2021-04-28 08:31:19 -07:00
Zach Wasserman
0e0cc44f36
Improved handling for long values in software inventory (#682)
- Increase version length to 255.
- Truncate any values too large.

Fixes #681
2021-04-26 14:01:05 -07:00
Zach Wasserman
e8669818eb
Initial backend software inventory implementation (#678)
- Maintain software inventory with detail queries.
- Associated database migrations.
- Feature flagged off by default (see documentation for details to turn on).
- Documentation.
- New test helper for slice element comparisons skipping ID.
2021-04-26 08:44:22 -07:00
Zach Wasserman
e8f4860d51
Add team user management (#672)
- Add list team users endpoint.
- Add add/delete team users endpoints.
- Update list users to support filter by team.
2021-04-21 20:54:09 -07:00
Zach Wasserman
af802dc15f
Add host and user counts to list teams response (#668) 2021-04-20 13:35:15 -07:00
Zach Wasserman
9ade086448
Add delete teams endpoints (#666)
Tested to work with frontend calls.
2021-04-20 10:20:52 -07:00
Gabriel Hernandez
04712c0426 Merge master into teams 2021-04-14 17:52:15 +01:00
Zach Wasserman
e961cfe0c3
Batch updates to host seen time (#633)
Instead of synchronously updating the seen_time column for a host on an update, batch these updates to be written together every 1 second.

This results in a ~33% reduction in MySQL CPU usage in a local test with 4,000 simulated hosts and MySQL running in Docker.
2021-04-12 16:22:22 -07:00
Zach Wasserman
db11f7b6aa
Fix saving of teams in invitations (#632) 2021-04-12 09:51:05 -07:00
Zach Wasserman
e8cb86231a
Include empty teams array in invites (#623) 2021-04-08 16:59:50 -07:00
Zach Wasserman
2f51493d20
Delete instead of disabling users (#622)
- Migration to delete existing disabled users.
- Remove enabled attribute.
- Add endpoint for user deletion.
2021-04-08 16:53:33 -07:00
Zach Wasserman
9064ef9b59
Clean up Go dependencies (#619)
Removes unused libraries and switches a use of bmizerany/assert to
stretchr/testify/assert.
2021-04-08 16:45:04 -07:00
Zach Wasserman
b12a6cb4c1
Migrate old admin field to new global role (#609)
- Migrate old admins to global admins
- Migrate old non-admins to global maintainers
- Remove old admin column
- Give initial user global admin privilege
- Comment out some tests (to be refactored for new permissions model later)
2021-04-06 18:27:10 -07:00
Zach Wasserman
2d2ebaf634
Add list teams endpoint (#601) 2021-04-06 11:40:14 -07:00
Zach Wasserman
244983fd7a
Add filtering for invites (#600)
Uses the same API as for users and hosts.
2021-04-06 11:09:28 -07:00
Zach Wasserman
598c1e4c1f
Remove invited_by from invite parameters (#591)
Instead, use the value extracted from the viewer context.
2021-04-05 13:28:43 -07:00
Zach Wasserman
08fce719e9
Add role storage to invites APIs (#576)
- Reorder migrations post-rebase
- Fix global_role in user payload
- Add teams/roles to invite entities
- Add teams/roles support to invite datastore methods
- Update tests
- Carry over team information from invite when creating user
2021-04-05 11:15:26 -07:00
Zach Wasserman
505d53b02b
Refactor MySQL tests into package mysql (#586)
Moving the tests into the package allows the coverage tool to function properly.
2021-04-05 11:04:53 -07:00
Zach Wasserman
9f71fcf440
Speed up MySQL tests (#585)
Improves MySQL test time (on my 2020 MBP) to ~18s from ~125s.

- Use separate databases for each test to allow parallelization.
- Run migrations only once at beginning of tests and then reload
  generated schema.
- Add `--innodb-file-per-table=OFF` for ~20% additional speedup.
2021-04-03 11:42:27 -07:00
Zach Wasserman
6df3dfbf6d Save global role for users (#493)
Previously the column existed but was not saved in datastore methods.
2021-03-31 11:49:48 -07:00
Zach Wasserman
a85b18ea38 Fix teams JSON key (#492)
Use lowercase `teams` rather than `Teams`.
2021-03-31 11:49:48 -07:00
Zach Wasserman
3286864d9d Initial work on user team information storage and retrieval (#483)
There are more migrations to come, but this is a foundation for the
DB changes that will be needed for Teams.
2021-03-31 11:49:44 -07:00
Zach Wasserman
6f381de04e Add search for list users endpoint (#490)
Search runs on name and email. Some refactoring to make the
functionality more generic.
2021-03-31 11:48:33 -07:00
Zach Wasserman
a79ad7d312
Improvements to built-in labels (#562)
- Fix issue with built-in labels showing multiple platforms when hosts
  are reinstalled with new platform.
- Add Red Hat Linux built-in label.
- Display more labels by default in target selector.

Fixes #546, #553
2021-03-30 15:37:33 -07:00
Zach Wasserman
2203bd81a2
Add support for IdP-initiated SSO login (#556)
This feature is off by default due to minor potential security concerns
with IdP-initiated SSO (see
https://auth0.com/docs/protocols/saml-protocol/saml-configuration-options/identity-provider-initiated-single-sign-on#risks-of-using-an-identity-provider-initiated-sso-flow).

Closes #478
2021-03-30 12:56:20 -07:00
Zach Wasserman
5b5dd1379b
Prefer IPv4 in Host Details (#548)
- Use a non-loopback, non-link-local IPv4 address if available
- Otherwise use non-loopback, non-link-local IPv6 address if available
- Otherwise use any address

Closes #532
2021-03-26 18:05:49 -07:00
Zach Wasserman
0bd6903b2d
Add version endpoint to API (#549)
Part of #371
2021-03-26 18:03:31 -07:00
Zach Wasserman
12d292164f
Add rate-limiting to login and password reset (#543)
Prevent abuse of these endpoints with rate limiting backed by Redis. The
limits assigned should be appropriate for almost any Fleet deployment.

Closes #530
2021-03-26 11:23:29 -07:00
noahtalerman
ef414153a9
Add "Last fetched" to Hosts page and Host details page (#540)
- Add a "Last fetched" column to the table on the Hosts page. This column uses the `detail_updated_at` property.
- Add a "Last fetched" timestamp to the Host details page.
- Adjust styles on _Host details_ page
2021-03-25 12:47:00 -07:00
Zach Wasserman
fb9706912d
Prevent user enumeration (#533)
- Return same error in all cases for login endpoint.
- Log error details in server logs.
- Make most login errors take ~1s to prevent timing attacks.
- Don't return forgot password errors.
- Log password errors in server logs.
- Make most forgot password requests take ~1s to prevent timing attacks.

Fixes #531
2021-03-24 19:36:30 -07:00
Zach Wasserman
d827a9d6b7
Log all errors regardless of log level (#496)
Modify the loggerDebug function to check whether the error is nil before
choosing the log level.

Fixes #473
2021-03-18 16:06:06 -07:00
Scott Lampert
5c69094571
Remove https check for client connection (#489)
Removes the https requirement for localhost only.
2021-03-18 11:21:36 -07:00
Zach Wasserman
db3c73d619
Test and correct semantics for MySQL withRetryTxx (#488)
- Differentiate retryable vs. non-retryable errors.
- Test functionality against mocked DB.
2021-03-17 11:23:52 -07:00
Zach Wasserman
6a399bc5df
Speed up labels MySQL tests (#486)
This saves a few seconds per test by only creating 10 hosts rather than
1000. The tests required no further changes as they were not using more
than the first few created hosts.
2021-03-17 10:07:22 -07:00
Lars Lehtonen
9b902428ea
server: prune unused constants and functions (#477)
This removes unused `const` variables and functions from `server` and its subpackages.
2021-03-15 17:08:25 -07:00
Lars Lehtonen
677ecf9eaf
server/service: prune dead code (#432) 2021-03-10 07:34:37 -08:00
Zach Wasserman
d1dfba1d68
Fix flapping IP addresses and host additional (#420)
The AuthenticateHost loading of hosts accidentally dropped IP addresses,
which would cause the IP to be dropped on save under certain scenarios.

Also fixes a potential issue with flapping host additional info.

Fixes #358
2021-03-09 09:01:26 -08:00
Zach Wasserman
f90da6a090
Make enrollment cooldown configurable (#418)
The enrollment cooldown period was sometimes causing problems when
osquery (probably unintentionally, see
https://github.com/osquery/osquery/issues/6993) tried to enroll more
than once from the same osqueryd process.

We now set this to default to off and make it configurable. With #417
this feature may be unnecessary for most deployments.
2021-03-08 21:26:09 -08:00
Zach Wasserman
cfba095cda
Make host identifier configurable within Fleet (#417)
Osquery now exposes more information during host enrollment than Fleet
previously handled. We can use this to provide more options to users in
problematic enrollment scenarios.

Users can configure --osquery_host_identifier in Fleet to set which
identifier is used to determine uniqueness of hosts. The
default (provided) replicates existing behavior in Fleet. For many
users, setting this to instance will provide better enrollment
stability.

Closes #373
2021-03-08 18:35:17 -08:00
Lars Lehtonen
9317c81edc
server/service: Remove duplicate log import (#408) 2021-03-08 10:59:39 -08:00
Zach Wasserman
2025afee71
Better handling of config_refresh values from clients (#388)
Since the original logic was implemented, there have been some changes
in the way that config refreshes are configured. This commit reflects
those changes and should be backwards compatible.

Closes #357
2021-03-05 08:25:46 -08:00
Zach Wasserman
f9312df174
Remove flaky log rotation test (#385)
This test has been flaky for years and it's time for it to go.
2021-03-04 16:29:50 -08:00
Zach Wasserman
de0b3324b1
Add AWS Lambda as logging plugin (#347)
This plugin invokes the provided function with each log line as the
payload.

Closes #342
2021-02-24 10:02:26 -08:00
Zach Wasserman
471f25e470
Return denylist parameter with pack configs (#339)
This was previously handled correctly within the Fleet server datastores
and API endpoints, but not returned to the actual osquery client.

Fixes #338
2021-02-21 09:58:36 -08:00
Lars Lehtonen
7e02b7abe3
server/datastore: fix swallowed test error (#337) 2021-02-19 08:19:43 -08:00
Zach Wasserman
c6c5e65a7d
Add support for filtering hosts in label (#335)
Support the same query syntax as the hosts endpoint, here also bounded
by the membership of the label.
2021-02-18 12:52:43 -08:00
Zach Wasserman
cca4802642
Add support for query parameter in list hosts endpoint (#327)
Uses a LIKE clause to search for hosts matching the query against
columns `host_name`, `uuid`, `hardware_serial`, and `primary_ip`.

Introduces the `searchLike` helper to add the appropriate filters to the
SQL query.
2021-02-16 16:53:42 -08:00
Zach Wasserman
6b5019d65e
Add aliases for order keys in API (#329)
Aliases `hostname` (`host_name`) and `memory` (`physical_memory`) when
used as keys for ordering in the API this allows for better consistency
on the frontend.

To be cleaned up further in #317
2021-02-16 15:25:34 -08:00
Zach Wasserman
06d919aa4e
Rename MySQL parameters for CircleCI (#328)
kolide -> fleet where appropriate
2021-02-16 14:40:38 -08:00
Zach Wasserman
b83fbf0ec9
Special case host_name on the backend to enable frontend consistency (#318)
See #317 for followup to this.
2021-02-15 11:58:05 -08:00
Zach Wasserman
d624e099fb
Deprecate environment variable prefix (#301)
- Support both `FLEET_` and `KOLIDE_` prefixes.
- Add logging about deprecated `KOLIDE_` prefix.
- Update documentation and sample configs.
2021-02-11 15:36:58 -08:00
Zach Wasserman
7a68e3de65
Deprecate /api/v1/kolide routes (#297)
- Support both /api/v1/fleet and /api/v1/kolide routes in server.
- Add logging for use of deprecated routes.
- Rename routes in frontend JS.
- Rename routes and add notes in documentation.
2021-02-10 12:13:11 -08:00
Zach Wasserman
e2e7e4707d
Update database migration tooling (#281)
- Use updated github.com/fleetdm/goose that generates templates
  requiring less editing.
- Add `make migration` to Makefile.
- Update documentation.
2021-02-05 09:48:06 -08:00
Zach Wasserman
ddb05cce94
Change default TLS compatibility to intermediate (#270)
In #212 these settings were updated and caused connectivity issues for
users in common environment configurations. The new changes are
aggressive (modern enforces TLS 1.3) and Mozilla indicates that
intermediate is an appropriate default. This will ensure better
compatibility for common deployments while still allowing the option to
use the strictest settings.

Document unintentional mismatched yaml key.

Fixes #269
2021-02-03 11:48:48 -08:00
Zach Wasserman
f68f4238e8
Merge pull request from GHSA-xwh8-9p3f-3x45
- Fix the specific case that caused panic.
- Add panic handler around entire live query results handler. This will
  prevent similar issues from causing crashes in the future.

Note that other endpoints already have panic handling but this one is
special due to the use of websockets.
2021-02-03 08:47:43 -08:00
Zach Wasserman
22d9205d35
Add debug flag to fleetctl (#266)
This flag enables logging of HTTP requests and responses to stderr.

Closes #187
2021-02-02 18:55:16 -08:00
Zach Wasserman
a9c0c472fc
Update Kolide to Fleet as appropriate in documentation (#263) 2021-02-02 12:16:59 -08:00
Zach Wasserman
c3a18ea7d1
Rename prefixed system queries (#253)
Renames live query names that the system uses from `kolide_` to
`fleet_`.
2021-02-01 11:39:53 -08:00
Zach Wasserman
ac9a85ab88
Expose more information for migration status errors (#240)
We saw these errors live today and it would be helpful to have the
additional error context for debugging.
2021-01-28 09:49:06 -08:00
Zach Wasserman
bb124dc2b9
Improvements to fleetctl preview experience (#234)
- Make the preview directory in the default .fleet directory.
- Check for Docker daemon installed but not running.
- Add message for Chrome users on self-signed certs.
- Display login information on later invocations of command.
- Remove "Kolide" from error messages.

Closes #190

Part of #197
2021-01-28 07:57:32 -08:00
Zach Wasserman
87330a9753
Add support for denylist parameter in scheduled queries (#209)
Closes #202
2021-01-25 16:26:14 -08:00
Zach Wasserman
6215acdd1b
Add host details in API responses (#223)
Add label and pack information for the returned hosts in the single-host
API endpoints.

Example:

```
curl -k 'https://localhost:8080/api/v1/kolide/hosts/7' -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzZXNzaW9uX2tleSI6Ii9oNEZ4MUpEVmlvQWhtMC8wNUJKbzZpdldsUDZpMDhjQVBuZXRLeFIvWjNOUGgvMW9VdCsxQnFlNU1CVDVsMlU3ckVGMm5Sb1VxS3ZSUllzSmJJR2lBPT0ifQ.GQQsJgBU3JA1H1o4Y8fPjyfF78F_VY4c9AbrP5k0sCg'
{
  "host": {
    "created_at": "2021-01-16T00:22:33Z",
    "updated_at": "2021-01-16T00:22:51Z",
    "id": 7,
    "detail_updated_at": "1970-01-02T00:00:00Z",
    "label_updated_at": "1970-01-02T00:00:00Z",
    "last_enrolled_at": "2021-01-16T00:22:33Z",
    "seen_time": "2021-01-16T00:22:51Z",
    "hostname": "55d91fc9c303",
    "uuid": "853a4588-0000-0000-a061-7d494d04e9c4",
    "platform": "ubuntu",
    "osquery_version": "4.6.0",
    "os_version": "Ubuntu 20.04.0",
    "build": "",
    "platform_like": "debian",
    "code_name": "",
    "uptime": 0,
    "memory": 16794206208,
    "cpu_type": "x86_64",
    "cpu_subtype": "158",
    "cpu_brand": "Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz\u0000\u0000\u0000\u0000\u0000\u0000\u0000",
    "cpu_physical_cores": 8,
    "cpu_logical_cores": 8,
    "hardware_vendor": "",
    "hardware_model": "",
    "hardware_version": "",
    "hardware_serial": "",
    "computer_name": "55d91fc9c303",
    "primary_ip": "",
    "primary_mac": "",
    "distributed_interval": 10,
    "config_tls_refresh": 0,
    "logger_tls_period": 10,
    "enroll_secret_name": "default",
    "labels": [
      {
        "created_at": "2020-12-22T01:22:47Z",
        "updated_at": "2020-12-22T01:22:47Z",
        "id": 6,
        "name": "All Hosts",
        "description": "All hosts which have enrolled in Fleet",
        "query": "select 1;",
        "label_type": "builtin",
        "label_membership_type": "dynamic"
      }
    ],
    "packs": [
      {
        "created_at": "2021-01-20T16:36:42Z",
        "updated_at": "2021-01-20T16:36:42Z",
        "id": 2,
        "name": "test"
      }
    ],
    "status": "offline",
    "display_text": "55d91fc9c303"
  }
}
```
2021-01-25 13:05:02 -08:00
Zach Wasserman
deaf8880f3
Expose live query error messages via API (#205)
Somewhere around osquery 4.4.0 these messages were added to query
responses. We can now expose them to the API clients rather than using
the placeholder text.

Required for #192
2021-01-19 14:52:29 -08:00
Zach Wasserman
f254a9a343
Make name and secret required for enroll secrets (#207)
Adds a check to prevent users from unintentionally setting empty
secrets.

Fixes #188
2021-01-19 14:49:53 -08:00
Zach Wasserman
44be83eefd
Improved error handling in host enrollment (#203)
This will make it easier to debug issues with the enrollment process,
such as #200.
2021-01-19 14:45:58 -08:00
Zach Wasserman
d13aadb5f1
Fix empty enroll secret before setup. (#182)
On new installations we unintentionally set the enroll secret to empty
string during database migrations. The enroll secret would be reset
during the setup process. This fixes the migration to not create any
enroll secret until the setup process.
2021-01-07 14:12:51 -08:00
CptOfEvilMinions
626429c38e
Added support to read jwt and mysql password from a file (#141)
The current implementation of FleetDM doesn't support Docker secrets for supplying the MySQL password and JWT key. This PR provides the ability for a file path to read in secrets. The goal of this PR is to avoid storing secrets in a static config or in an environment variable. 

Example config for Docker:
```yaml
mysql:
  address: mysql:3306
  database: fleet
  username: fleet
  password_path: /run/secrets/mysql-fleetdm-password
redis:
  address: redis:6379
server:
  address: 0.0.0.0:8080
  cert: /run/secrets/fleetdm-tls-cert
  key: /run/secrets/fleetdm-tls-key
auth:
  jwt_key_path: /run/secrets/fleetdm-jwt-key
filesystem:
  status_log_file: /var/log/osquery/status.log
  result_log_file: /var/log/osquery/result.log
  enable_log_rotation: true
logging:
  json: true
```
2021-01-04 07:58:43 -08:00
Matteo Piano
c89cd370d5
Add AWS S3 as file carving backend (#126)
This adds the option to set up an S3 bucket as the storage backend for file carving (partially solving #111).

It works by using the multipart upload capabilities of S3 to maintain compatibility with the "upload in blocks" protocol that osquery uses. It does this basically replacing the carve_blocks table while still maintaining the metadata in the original place (it would probably be possible to rely completely on S3 by using object tagging at the cost of listing performance). To make this pluggable, I created a new field in the service struct dedicated to the CarveStore which, if no configuration for S3 is set up will be just a reference to the standard datastore, otherwise it will point to the S3 one (effectively this separation will allow in the future to add more backends).
2020-12-16 09:16:55 -08:00
Zach Wasserman
55a2aa2c95
Fix logging for query creation on error (#132) 2020-12-14 18:45:03 -08:00
Zach Wasserman
57812a532e
Merge pull request from GHSA-w3wf-cfx3-6gcx
* Update github.com/russellhaering/goxmldsig

* Update signature validation to include Mattermost XML validator
2020-12-14 18:14:14 -08:00
Zach Wasserman
5b432cccee
Prevent SQLite ATTACH from being used in queries (#129)
Mitigate
[CVE-2020-26273](https://github.com/osquery/osquery/security/advisories/GHSA-4g56-2482-x7q8)
by attempting to prevent users from executing or saving queries that use
the SQLite `ATTACH` command.

Users must still update to osquery 4.6.0 to ensure the functionality is
fully disabled in osquery.
2020-12-14 18:13:34 -08:00
Zach Wasserman
6f6464f206
Migrate remaining URLs to fleetdm.com (#116) 2020-12-10 11:26:00 -08:00
Zach Wasserman
9ff16a370c
Improve MySQL transaction error logging (#113)
Clarify what exactly happened when logging these errors.
2020-12-10 11:05:15 -08:00
Zach Wasserman
beb7e8b965
Add host enrollment cooldown period (#112)
This addresses an issue some users experienced in which performance
problems were encountered when hosts were "competing" for enrollment
using the same osquery host identifier. The issue is addressed by adding
a cooldown period for host enrollment, preventing the same (as judged by
osquery host identifier) host from enrolling more than once per minute.

When users end up in the problematic scenario, they will see quite a bit
of error logs due to this issue. For now that's probably a good thing as
users need to be aware of the lack of visibility. We can explore rate
limiting the logging if that becomes an issue for someone.

Fixes #102
2020-12-10 11:04:58 -08:00
Zach Wasserman
bb921bc973
Allow scheduling same query more than once in UI (#96)
Fixes #88
2020-12-04 09:50:39 -08:00
noahtalerman
51cfb07f64
Implement global colors. Add italic font. (#64)
The goal of this PR was to insert new colors, remove legacy colors, and update only the styles accordingly. The Nunito Sans Italic font was also added.

Later PRs will include layout, copy, and style change to individual components. These later changes will more exactly resemble the current mockups.
2020-11-24 08:59:03 -08:00
noahtalerman
8df16949f5
Add fleet assets including logos, 404 image, and 500 image. (#61)
This is the second PR as part of the Fleet UI Refresh #38.

The goal of this PR was to insert all updated Fleet assets and remove all old assets. More style changes, including the exact sizing and placement of the new images, will occur in a future PR.
2020-11-23 11:22:42 -08:00
noahtalerman
23ce98ec51
Add Nunito Sans font and update global styles. (#59)
This is the first PR as a part of the Fleet UI Refresh #38.

Changes include:

- Add Nunito Sans font files and modify global styles to reflect the font change.
- Modify global font variables to reflect new sizing and weight naming conventions.
-- New sizing and naming conventions:
--- SIZE: xx-small: 12px, x-small: 14px, small: 16px, medium: 20px, large: 24px, x-large: 28px
--- WEIGHT: regular: 400, bold: 700
- Remove the old Oxygen font files.

Changes to other style sheets reflect the changes to the new font sizing and weight naming conventions for global variables. The changes don't necessarily use the correct size (as illustrated by mockups). Those "up to spec" sizing changes are to come.
2020-11-19 16:51:22 -08:00
Zach Wasserman
eea6aa5c64
Fix unexpected print of migration status warning (#50)
Replace the now-deleted migration
server/datastore/mysql/migrations/data/20181119180000_DeleteSoftDeletedEntities.go
with a new migration containing the same timestamp. This allows Fleet to
see the appropriate migration state for users upgrading from previous
versions without actually modifying the DB.

Fixes #48
2020-11-18 11:44:06 -08:00
Zach Wasserman
e7912c2d31
Minor code/comment cleanups (#47)
- Fixes an initialization error panic to a fatal log
2020-11-18 11:10:55 -08:00
Zach Wasserman
0bb9d69ece
Add debug endpoints and associated fleetctl commands (#45)
Adds endpoints and fleetctl commands to retrieve various debug profiles
from the Fleet server.

The best summary is from the help text:

```
fleetctl debug
NAME:
   fleetctl debug - Tools for debugging Fleet

USAGE:
   fleetctl debug command [command options] [arguments...]

COMMANDS:
   profile    Record a CPU profile from the Fleet server.
   cmdline    Get the command line used to invoke the Fleet server.
   heap       Report the allocated memory in the Fleet server.
   goroutine  Get stack traces of all goroutines (threads) in the Fleet server.
   trace      Record an execution trace on the Fleet server.
   archive    Create an archive with the entire suite of debug profiles.

OPTIONS:
   --config value   Path to the Fleet config file (default: "/Users/zwass/.fleet/config") [$CONFIG]
   --context value  Name of Fleet config context to use (default: "default") [$CONTEXT]
   --help, -h       show help
```
2020-11-17 17:12:37 -08:00
Zach Wasserman
ab94d94da0
Fix fleetctl Windows issues (#40)
- Properly set the path for the config file on Windows.
- Check for appropriate settings for TLS config.

Fixes #39
2020-11-17 16:02:14 -08:00
billcobbler
618ba56484
Add host additional info filters (#28)
This change adds the ability to filter additional host info via the list hosts endpoint; a continuation from [here](https://github.com/kolide/fleet/pull/2330), but now filtering is accomplished via SQL. 

Additional object without filter:
```
curl 'https://localhost:8080/api/v1/kolide/hosts'
...
"additional": {
        "macs": [
          {
            "mac": "00:00:00:00:00:00"
          },
          {
            "mac": "02:42:c0:a8:10:05"
          }
        ],
        "time": [
          {
            "day": "13",
            "hour": "3",
            "year": "2020",
            "month": "10",
            "minutes": "43",
            "seconds": "11",
            "weekday": "Tuesday",
            "datetime": "2020-10-13T03:43:11Z",
            "iso_8601": "2020-10-13T03:43:11Z",
            "timezone": "GMT",
            "timestamp": "Tue Oct 13 03:43:11 2020 UTC",
            "unix_time": "1602560591",
            "local_time": "1602560591",
            "local_timezone": "UTC"
          }
},
...
```

Additional object with filter:
```
curl 'https://localhost:8080/api/v1/kolide/hosts?additional_info_filters=macs,notreal'
...
"additional": {
        "macs": [
          {
            "mac": "00:00:00:00:00:00"
          },
          {
            "mac": "02:42:c0:a8:10:05"
          }
        ],
        "notreal": null
},
...
```
2020-11-13 16:33:25 -08:00
Zach Wasserman
8f435a95ba
Allow @ character in usernames (#37)
PR #9 unintentionally exposed the validation that prevented the @
character in usernames. We have decided there is no reason to block this
character.

Fixes #36
2020-11-13 15:52:20 -08:00
Zach Wasserman
6cbd10965c
Add dev infrastructure and docs for Prometheus monitoring (#33)
- Set up a simple example of Prometheus monitoring in the development
  docker-compose.yml.
- Add documentation for configuring Prometheus.
2020-11-12 19:06:56 -08:00
Mike Arpaia
af96e52a00
Update the Go import paths to new repo name (#27) 2020-11-11 09:59:12 -08:00
noahtalerman
ecacbf212b
Changes to additional links for transition to fleetdm (#21) 2020-11-04 21:48:39 -08:00
Zachary Wasserman
a1720db58e
Fix regression creating packs (#17)
This is another error introduced in
https://github.com/kolide/fleet/pull/2327 we did not catch previously
due to insufficient unit test coverage. Test is now added.
2020-11-04 21:18:02 -08:00
Zachary Wasserman
e452cc6a8a
Add file carving support (#15)
- Add endpoints for osquery to register and continue a carve.
- Implement client functionality for retrieving carve details and contents in fleetctl.
- Add documentation on using file carving with Fleet.

Addresses kolide/fleet#1714
2020-11-04 20:45:16 -08:00
Zachary Wasserman
7c923d9d19
Implement fleetctl user create (#9)
- Allow user creation via `fleetctl user create`
- Cleanup and rename existing methods for clarity

Fixes https://github.com/kolide/fleet/issues/2306
2020-11-04 17:06:55 -08:00
Zachary Wasserman
fca44bb032
Make enroll secret and node key validation case-sensitive (#5)
- Modify column collation to make comparisons case-sensitive.
- Add tests for case-sensitivity.

Fixes https://github.com/kolide/fleet/issues/2333
2020-11-04 12:09:00 -08:00
Zachary Wasserman
2e333a4e2e
Fix regression in list hosts (#6)
Changes in https://github.com/kolide/fleet/pull/2327 broke the MySQL
syntax for listing hosts with online status. This was not caught due to
the lack of a unit test for the functionality. This PR adds a unit test
and fixes the regression.
2020-11-04 12:03:06 -08:00
Brendan Shaklovitz
c6b285c56e
Remove soft-deletion pattern (#2327)
* Perform migration to delete any entries with `deleted` set, and
subsequently drop columns `deleted` and `deleted_at`.
* Remove `deleted` and `deleted_at` references.

Closes #2146
2020-10-22 10:51:26 -07:00
Brendan Shaklovitz
8246b4d1f8
fleetctl: allow disabling packs via apply (#2325)
Closes issue #2240
2020-10-21 16:29:27 -07:00
Brendan Shaklovitz
59ba129718
Consistent use of constants in fleetctl (#2320)
Refactor fleetctl get & apply to use constants for spec kinds

Closes #2283
2020-10-08 10:16:07 -07:00
Zachary Wasserman
e8e4bc9879
Fix cleanup of orphaned queries (#2316)
The expiration logic was incorrect leading to queries not being cleaned
up properly. Tests added for the whole subroutine.

Fixes #2302
2020-10-06 09:30:24 -07:00
Zachary Wasserman
50dbdb3db4
Add explicit int64 for parsing physical_memory column (#2315)
Addresses an error when Fleet is compiled for a 32-bit architecture.

May not be comprehensive of all related errors.

Fixes #2314.
2020-10-05 17:03:32 -07:00
Zachary Wasserman
f2d3683d80
Log host identifier in EnrollAgent service logging (#2313)
This can help identify circumstances in which multiple hosts are
providing the same identifier and clobbering the node key for each
other.
2020-10-02 13:23:54 -07:00
Kilian
c61ba759dd
Add redis use_tls cfg (#2311)
Adding config parameter 'redis.use_tls' to enable tls communications with redis e.g. AWS ElastiCache

Closes #2247
2020-10-01 16:25:48 -07:00
Iain Steers
da99617882
Add DeleteHost func to service pkg (#2312) 2020-10-01 16:14:18 -07:00
James Alseth
692171dfdb
Fix string(int) in Kinesis logger for Go 1.15 compatibility (#2309) 2020-09-27 09:44:55 -07:00
Lars Lehtonen
d193ea1717
Remove Support for Deprecated TLSProfileOld (#2142)
Co-authored-by: Zachary Wasserman <zach@dactiv.llc>
2020-09-10 09:31:01 -07:00
James Alseth
3a63dac4a3
Add compression option for filesystem logs when they're rotated (#2292) 2020-09-09 13:33:32 -07:00
billcobbler
20328b0f87
Add stdout and kinesis logger plugins and sts assume role to Firehose (#2282)
Co-authored-by: Brendan Shaklovitz <nyanshak@users.noreply.github.com>
2020-08-19 14:56:44 -07:00
James Alseth
b67cfc479b
Fix string(int) issues for Go 1.15 compatibility (#2286) 2020-08-19 13:36:36 -07:00
Zachary Wasserman
34c4ce4ffb
Fix parsing of integer label_type in yaml (#2276)
Fixes #2273
2020-08-06 16:07:13 -07:00
Stephan Miehe
2ad5205a4b
Add support for conn_max_lifetime (#2270)
This adds support to configure MySQL conn_max_lifetime.
2020-07-30 09:00:42 -07:00
Stephan Miehe
cf4d8ecfee
Add redis database number support (#2269)
Fixes #2268
2020-07-30 08:57:25 -07:00
Zachary Wasserman
1058f57767
Remove noisy User log (#2265)
This log appears to add little value as it is generated by almost any
web UI request.
2020-07-22 09:49:34 -07:00
Zachary Wasserman
7494513400 Clean up and comments before merge. 2020-07-21 14:05:46 -07:00
Zachary Wasserman
96fc090723 Improve server performance for host operations
- Debounce frontend to reduce number of target searches in live query.
- More efficiently calculate label counts in live query and hosts
  dashboard. Instead of using the (slow) CountHostsInTargets function,
  retrieve the host counts while looking up the labels.
- Optimize targets search query. Removing the nested query retrieves the
  same logical result set, but substantially optimizes MySQL CPU usage.
  Testing indicates about a 50% reduction in MySQL CPU usage for the
  frontend targets search API call after applying this change.
2020-07-21 14:05:46 -07:00
Zachary Wasserman
fcb8418b2f Add fleetctl get host capability to get single host with labels
Getting a single host with `fleetctl get host foobar` will look up the
host with the matching hostname, uuid, osquery identifier, or node key,
and provide the full host details along with the labels the host is a
member of.
2020-07-21 14:05:46 -07:00
Zachary Wasserman
7f757d3144 Extract functionName into helper
Cleans up some repetition in tests.
2020-07-21 14:05:46 -07:00
Zachary Wasserman
42bea2a144 Implement manual labels
"Manual" labels can be specified by hostname, allowing users to specify
the membership of a label without having to use a dynamic query. See the
included documentation.
2020-07-21 14:05:46 -07:00
Zachary Wasserman
608772917c Refactor label membership storage
Label membership is now stored in the label_membership table. This is
done in preparation for adding "manual" labels, as previously label
membership was associated directly with label query executions.

Label queries are now all executed at the same time, rather than on
separate intervals. This simplifies the calculation of which distributed
queries need to be run when a host checks in.
2020-07-21 14:05:46 -07:00
Zachary Wasserman
b0595748f1 Implement pagination of hosts in the web UI
This commit takes advantage of the existing pagination APIs in the Fleet
server, and provides additional APIs to support pagination in the web
UI. Doing this dramatically reduces the response sizes for requests from
the UI, and limits the performance impact of UI clients on the Fleet and
MySQL servers.
2020-07-21 14:05:46 -07:00
Zachary Wasserman
0502412e15 Move live query operations from MySQL to Redis
This change optimizes live queries by pushing the computation of query
targets to the creation time of the query, and efficiently caching the
targets in Redis. This results in a huge performance improvement at both
steady-state, and when running live queries.

- Live queries are stored using a bitfield in Redis, and takes
advantage of bitfield operations to be extremely efficient.

- Only run Redis live query test when REDIS_TEST is set in environment

- Ensure that live queries are only sent to hosts when there is a client
listening for results. Addresses an existing issue in Fleet along with
appropriate cleanup for the refactored live query backend.
2020-07-21 14:05:46 -07:00
Zachary Wasserman
ea93843203 Store only primary IP and MAC for hosts
Fleet used significant resources storing the full network interface
information for each host. This data was unused, except to get the
IP and MAC of the primary interface. With these changes, only those
pieces of data are stored.

- Calculate and store primary IP and MAC
- Remove transaction for storing full interfaces
- Update targets search to use new IP and MAC columns
- Update frontend to use new new columns
2020-07-21 14:05:46 -07:00
Zachary Wasserman
fd61dcab67
Clean up unused DB tables, migrations, and code (#2258)
This PR removes unused types, code, DB tables, and associated migrations that are unused since Fleet 2.0.

An existing migration was refactored, and should remain compatible with both existing and new Fleet installations.
2020-07-08 13:02:18 -07:00
Zachary Wasserman
2578466697
Upgrade SockJS JS and Go dependencies (#2256) 2020-07-06 20:04:04 -07:00
Zachary Wasserman
c1aa8355cb
Add support for multiple enroll secrets (#2238)
- Support multiple enroll secrets
- Record name of enroll secret used when host enrolls
- Update fleetctl and UI to support these features
2020-05-29 09:12:39 -07:00
Zachary Wasserman
619e36755c
Add capability to collect "additional" information from hosts (#2236)
Additional information is collected when host details are updated using
the queries specified in the Fleet configuration. This additional
information is then available in the host API responses.
2020-05-21 08:36:00 -07:00
Charlie Gildawie
df93abd722
Reduce verbosity of default logging (#2225)
* Moves much logging from the info level to the debug level
* Tries to retain security/auditing relevant logs at info level
2020-04-22 14:01:34 -07:00
Zachary Wasserman
be8dbb426e
Sanitize column names for order key in MySQL (#2224)
This adds a SQL injection prevention for a case in which we cannot use
parameters in the query.

It is not clear that this was possible to exploit. If it was possible,
it would have required a valid login to the Fleet server.
2020-04-22 13:59:40 -07:00
Lars Lehtonen
04c9acce96
server/service: Fix appConfigResponse.OrgInfo json tag (#2212)
Fixes a typo in the JSON tag.
2020-04-17 09:35:15 -07:00
Zachary Wasserman
bf232e8b68
Make HostResponse an exported type (#2215)
This commit makes it easier to use the client package from outside of
Fleet by exporting the HostResponse type.
2020-03-31 16:14:26 -07:00
Zachary Wasserman
45f6a74740
Allow import of github.com/kolide/fleet (#2213)
Previously a Go package attempting to import Fleet packages would run
into an error like "server/kolide/emails.go:93:23: undefined: Asset".

This commit refactors bindata asset handling to allow importing Fleet as
a library without changing the typical developer experience.
2020-03-29 19:22:04 -07:00
billcobbler
44c40e4255
Retry sqlx transactions (#2203)
- Add exponential backoff method to MySQL datastore
- Refactor queries using transaction to use backup.

Fixes #845
2020-03-10 18:14:02 -07:00
Zachary Wasserman
f6223ca0e4
Add ability to modify host detail update interval (#2200)
This may be desirable for some deployments to reduce server load.
2020-03-02 11:08:08 -08:00
Lars Lehtonen
96cbd10651
server/service: Fix Missing Test Errors (#2196)
This fixes 9 places in the `server/service` tests where err variables were being dropped. No new test failures identified.
2020-02-18 18:11:16 -08:00
Jean M
877cd7e39a
Added support to logging X-Forward-For header (#2133) (#2193)
Allows Fleet to log the actual client address and not just the proxy address when communicating with the osquery endpoints.
2020-02-11 09:16:12 -08:00
Lars Lehtonen
bc7c5704d4
server/datastore: fix missing error checks (#2194)
Fixing these missing checks did not identify any broken tests or code.
2020-02-10 17:32:29 -08:00
Zachary Wasserman
6dbc3bc77a
Implement fleetctl goquery (#2186)
- Update fleet APIs to support necessary operations in goquery
- Implement support for goquery in fleetctl
2020-01-23 21:27:20 -08:00
Zachary Wasserman
ee0a6e9064
Add deprecation warning for "old" TLS compatibility (#2183)
Warn users in advance of removing this in #2142.
2020-01-14 09:36:07 -08:00
Zachary Wasserman
ef1d69c371
Fix bugs in error handling for creation of live queries (#2181)
- Return the correct result type in error cases
- Handle nil values for campaign when logging
2020-01-13 17:35:42 -08:00
billcobbler
a83a26b279 Add ability to disable live queries (#2167)
- Add toggle to disable live queries in advanced settings
- Add new live query status endpoint (checks for disabled via config and Redis health)
- Update QueryPage UI to use new live query status endpoint

Implements #2140
2020-01-13 16:53:04 -08:00
Zachary Wasserman
3b02640334
Update goxmldsig dependency (#2177)
Update the github.com/russellhaering/goxmldsig dependency and apply
the appropriate fixes for the API changes.

This is a preparation for integration with
github.com/AbGuthrie/goquery, which uses a newer version of the
dependency.
2020-01-13 16:15:14 -08:00
Zachary Wasserman
f1b8dbaf86
Fix error initializing Fleet when MySQL EVENT permissions missing (#2176)
Fixes #2174
2020-01-13 16:14:44 -08:00
Christian Barcenas
b3a7fc83e1 Use canonical import path for gopkg.in/guregu/null (#2171)
The `gopkg.in` import path is used in the package's documentation, and
by downstream Linux distro maintainers (e.g. Debian Go Packaging Team).
2020-01-13 09:11:31 -08:00
Max Bigras
b524d813ca Add MysqlConfig protocol option (#2161)
Enables configuring MySQL to run with unix domain sockets.
Closes #2160
2019-12-04 09:48:24 -08:00
thehellajeff
6580fe1c5a Improvements to server logging (#2155)
- Add logging for new campaigns
- Add logging for new query creations/modification/deletion
- Add usernames for logs found in labels, options, packs, osquery options, queries and scheduled queries where something is created, modified or deleted
2019-12-04 09:42:10 -08:00
billcobbler
a856fd5c0b Add fleetctl get/apply config (#2143)
Implements #1953
2019-11-19 21:13:15 -08:00
Austin Burnett
57f65e70b8 Allow host expiry window to be altered (#2121)
Fixes a bug in which the event expiry window would not be properly updated.

Fixes #2122
2019-11-12 14:41:16 -08:00
Lars Lehtonen
0a87bbf496 Fix dropped errors in SSO tests (#2141) 2019-11-11 09:42:31 -08:00
Lars Lehtonen
ed9f890ba0 server/mail: Handle error when write fails (#2132) 2019-11-07 08:34:50 -08:00
Zachary Wasserman
adf87140a7
Add ability to prefix Fleet URLs (#2112)
- Add the server_url_prefix flag for configuring this functionality
- Add prefix handling to the server routes
- Refactor JS to use appropriate paths from modules
- Use JS template to get URL prefix into JS environment
- Update webpack config to support prefixing

Thanks to securityonion.net for sponsoring the development of this feature.

Closes #1661
2019-10-16 16:40:45 -07:00
Austin Burnett
59efb495ca Add automatic host expiration capability (#2117)
When configured, this feature will delete hosts that have not checked in after the specified number of days.

Closes #1860.
2019-10-16 16:35:17 -07:00
Matteo Piano
6439828272 Allow host search by UUID (#2116)
- Update MySQL schema to add fulltext index on UUID
- Support UUID in host search query
2019-10-16 10:12:35 -07:00
William Theaker
a688b5cf5b Allow idp_name to be 4 characters (#2106) 2019-09-25 10:18:30 -07:00
Zachary Wasserman
1eccf9a874
Add warning in query UI when Redis fails (#2086)
- Add warning message when Redis fails
- Disable query button when Redis fails
- Refactor SMTP warning banner into component for reuse

Closes #2073
2019-08-13 09:42:58 -07:00
Zachary Wasserman
363b6157c4
Allow scheduled query shard to be set to empty in frontend (#2093)
Fixes #1452
2019-08-13 09:42:02 -07:00
Zachary Wasserman
fa10dbe0a8
Use Github hosted assets in emails sent by Fleet (#2090)
This change allows the images in Fleet emails to load properly from any
device with connectivity to github.com. Previously, emails might try to
load resources from a Kolide server not accessible from the email
client.

The asset URL will be based on the most recent git tag to accomodate
backwards-compatibility if the assets in the repo change.

Closes #1471
2019-08-02 14:08:42 -07:00
Michael Samuel
969d5f25af Add Google Cloud PubSub logging (#2049)
Adds Google Cloud PubSub logging for status and results.

This also changes the Write interface for logging modules to add a context.Context (only used by pubsub currently).
2019-07-16 15:41:50 -07:00
Zachary Wasserman
c269886389
Fix target search behavior with - and + symbols (#2067)
This PR makes the target search more user-friendly by stripping symbols that
have a special interpretation in MySQL FTS.

Closes #2017
2019-07-03 10:47:43 -07:00
Zachary Wasserman
261b7f916c
Save details provided by host during enrollment (#2066)
When an osqueryd agent sends an enroll request it automatically sends
some details about the system. We now save these details which helps
ensure we send the correct platform config.

Closes #2065
2019-07-01 16:50:04 -07:00
Zachary Wasserman
eb212116dc Merge pull request from GHSA-6g7f-8qm4-f7h8
When LOGIN authentication was used, Fleet would send SMTP credentials
even if the connection the SMTP server was not secured via TLS.

Copying the pattern used in the standard library PlainAuth
implementation, we now only send credentials when the connection is
secure or the server is localhost.
2019-05-30 15:02:17 -04:00
Zachary Wasserman
caae22593f
Add 'id' prefix to generated SAML IDs (#2046)
Though the SAML spec does not specify what the contents of the ID must
be, the Azure IdP implementation prohibits it beginning with a number.
We follow their suggestion to prefix with 'id'.

See https://docs.microsoft.com/en-us/azure/active-directory/develop/single-sign-on-saml-protocol.

Fixes #2044.
2019-05-16 13:51:42 -07:00
Eduardo Lopez
ad12ee4db4 Allow Firehose authentication using sts credentials (#2034) 2019-04-24 16:30:16 -07:00
Zachary Wasserman
75868a7005
Do not panic after error reading config file (#2033)
Fixes #1445
2019-04-23 15:59:02 -07:00
Zachary Wasserman
5b486a1849
Update logic for setting primary NIC (#2032)
- The most active NIC will be picked even if a formerly more active
  interface still exists (previously, a NIC would stay primary as long
  as it existed).
- Ignore link-local and loopback interfaces when choosing the primary.
- Fix bugs in which update status of the primary interface could be
  reported incorrectly.

Fixes #2020
2019-04-23 15:58:45 -07:00
Zachary Wasserman
1f7cffba11
Fix newlines in log output (#2029)
Fixes a regression introduced in 2.1.0 in which separate log lines are
no longer output separated by a newline. Now log lines in both output
plugins will do so.
2019-04-17 15:55:31 -07:00
Zachary Wasserman
955972e1a1
Cleanup incoming hosts that do not complete enrollment (#2026)
Deletes hosts that have enrolled but never updated their details (these
hosts show up as "incoming host" in the UI).

Closes #1438
2019-04-09 11:11:11 -07:00
Zachary Wasserman
1acebec4b6
Close flate writer before base64 encoding SAML authorization request (#2025)
Fixes an issue in which the requests are not able to be read by some SAML
request decoders.

Fixes #2024
2019-04-09 09:23:22 -07:00
Zachary Wasserman
e59714242e
Add Firehose logging capabilities for result and status logs (#2022)
- Refactor configuration for logging to use separate plugins
- Move existing filesystem logging to filesystem plugin
- Create new AWS firehose plugin
- Update documentation around logging
2019-04-08 11:47:15 -07:00
Zachary Wasserman
7153e0043c Update email contents and subjects (#2023)
- Refer to "Kolide" as "Fleet"
- Fix link to documentation
- Remove suggestion to email support@kolide.co
2019-04-04 18:56:15 -04:00
Zachary Wasserman
03c23973ca
Small cleanup in live query code (#2011)
- Additional comments
- Fix some cases where websocket may not be closed appropriately
2019-03-10 13:51:11 -07:00
Zachary Wasserman
c8229cc0d6
Replace uses of the term "Kolide" with "Fleet" (#1999)
Almost two years ago, we began referring to the project as Fleet, but there are
many occurences of the term "Kolide" throughout the UI and documentation. This
PR attempts to clear up those uses where it is easily achievable.

The term "Kolide" is used throughout the code as well, but modifying this would
be more likely to introduce bugs.
2019-01-24 09:39:32 -08:00
Zachary Wasserman
6ec951ab73
Default scheduled query name if not specified (#1995)
Brings the behavior of the server in line with the documentation, by using the
query name if the scheduled query name is not specified in a pack spec.

Closes #1990
2019-01-17 15:59:42 -08:00
James Thomas
5e5e4f3918 Add Support for SMTP LOGIN Authentication Method (#1988)
This PR adds support for the SMTP LOGIN authentication method. Office 365 Exchange removed support for PLAIN authentication some time ago, and only supports LOGIN and an OAuth2 authentication method. This patch has been tested with a licensed O365 account. This method should also be usable with any other email server that advertises LOGIN in its 250-AUTH response.

Note: If using this with O365, the account used must not have MFA enabled.

Closes #1663
2019-01-14 12:35:23 -08:00
blaedj
be85377326
Add 'get hosts' command to fleetctl (#1977)
This commit:
 - adds a new sub-command for fetching hosts to `fleetctl get` command.

Why?
 - this allows for listing of all hosts via the fleetctl interface.
 There may be additional attributes of the host that we'd like to
 display, but this should be a good start.

Closes #1962
2019-01-03 16:19:23 -06:00
Zachary Wasserman
0f99b454a0
Add username support to fleetctl setup (#1971)
Username continues to default to email if not specified in the options.

Closes #1970
2019-01-02 15:27:37 -08:00
Zachary Wasserman
b752073d05
Fix slow return of results in fleetctl query with high host count (#1965)
Prior to this change, the live query status was calculated after each retrieved
result. This was fine at a low host count, but when more hosts are added, doing
this calculation becomes slower.

Now, the status is only calculated every 5 seconds, while results can be
streamed continuously.

Fixes #1895
2018-12-20 17:44:49 -08:00
Zachary Wasserman
0b21a3d42c
Delete soft-deleted entities (#1959)
Avoids potential bugs in which soft-deleted entities are returned from database
queries (soft-deletion is now deprecated), but some records may still exist.

Fixes #1956
2018-11-20 17:41:55 -08:00
Zachary Wasserman
051d3c8b07
Fix errors when trying to retrieve specs with spaces in name (#1957)
We need to properly escape and unescape the name parameter.

Fixes #1948
2018-11-20 17:19:24 -08:00
Blake Atkinson
510ec10769 Documentation: Add mysql conn limits (#1947) 2018-11-01 17:43:24 -04:00
Zachary Wasserman
e6f4dd54bb
Fix loading of network interfaces with high host counts (#1942)
This should fix the loading of the all hosts page in cases where there are many
hosts and it overwhelms the number of parameters allowed in a prepared
statement. May also make that page load slightly quicker as it removes the
constraint from the query, but should return the same number of results.

Fixes #1939
2018-10-16 11:13:55 -07:00
Zachary Wasserman
be6a16959a Fix error messages related to null users as creators of queries. (#1928)
Ensure that the queries page still loads even when users are deleted manually
in the DB.

Fixes #1911
2018-10-11 13:22:43 -07:00
Zachary Wasserman
3fa3fe7fdc
Use errors.Wrapf instead of nested fmt.Sprintf (#1933) 2018-10-02 15:19:50 -07:00
adamenger
a99313533d Added custom CA support to fleetctl client (#1931) 2018-10-01 15:23:46 -07:00
Zachary Wasserman
66e720d34d Reduce port scanning possibilities via SMTP configuration
The SMTP configuration could be used by an admin user to port scan the network
the Fleet server was running on. This commit reduces the information possible
to determine via this technique. A malicious admin can no longer determine
whether any TCP server is listening on a given port/address. They can only
determine ports and addresses where SMTP servers are running.

Thanks to 'quikke' for reporting this vulnerability.
2018-09-18 14:56:25 -04:00
Zachary Wasserman
7e26b915c5 Refactoring and fixes in user authorization
- Simplify/fix logic for authorization
- Rename/refactor for clarity
- Add tests for auth related code
2018-09-18 14:56:25 -04:00
Zachary Wasserman
5cbaa9cb9f Prevent non-admin users from modifying other users
An incorrect authorization check allowed non-admin users to modify the details of other users. We now enforce the appropriate authorization so that unprivileged users can only modify their own details.

Thanks to 'Quikke' for the report.
2018-09-18 14:56:25 -04:00
Zachary Wasserman
21269b1dd8 Prevent escalation of user privileges via ModifyUser method
The ability to modify a users admin and enabled status was erroneously left in
place during development of https://github.com/kolide/fleet/pull/959. To
mitigate a privilege escalation vulnerability we need to ensure those values
can only be modified through the explicit methods.

This patch includes a unit test and fix for the vulnerability.

Thanks to 'Quikke' for submitting this vulnerability.
2018-09-18 14:56:25 -04:00
Zachary Wasserman
e011cfc464
Delete packs that have already been soft-deleted (#1924)
We no longer use soft deletion, so this commit introduces a migration that hard
deletes existing deleted packs.

Fixes #1923
2018-09-12 17:50:30 -07:00
Zachary Wasserman
94f5ee7832
Fix bug preventing rename of queries scheduled in packs (#1921)
Change the foreign key constraint to automatically update the query name as
appropriate.

Fixes #1917
2018-09-12 11:25:35 -07:00
Zachary Wasserman
79b2249e69
Allow update of settings page without enabling SMTP (#1903)
Fixes #1871
2018-09-07 15:37:35 -07:00
Zachary Wasserman
dfac039422
Fix targeting packs to individual hosts (#1897)
Packs can be targeted to individual hosts through the UI. This was supported
previously and was broken with refactoring in Fleet 2.0.

There is currently no support in the fleetctl format for targeting individual
hosts, but this could be added at a later date.

Fixes #1878
2018-08-13 10:07:10 -07:00
Chris Helming
4729789943 Trim whitespace from X509 certificate (#1900) 2018-08-10 12:42:35 -07:00
Zachary Wasserman
293ca56040
Fix error when migrating packs and scheduled query has been deleted. (#1851)
Fixes #1850
2018-06-26 09:54:45 -07:00
Zachary Wasserman
06832697d0
Fix deletion of labels in UI (#1848)
- Add endpoint for deletion of label by ID
- Use ID endpoint from frontend JS

Fixes #1847
2018-06-25 13:56:59 -07:00
Zachary Wasserman
08a2dc73cd
Fix bugs with packs created in UI (#1843)
- Delete duplicate queries in packs created by the UI (because the duplicates
  were causing undefined behavior). Now it is not possible to schedule
  duplicates in the UI (but is in fleetctl).
- Fix bug in which packs created in UI could not be loaded by fleetctl.
2018-06-21 17:06:44 -07:00
Zachary Wasserman
4ade65b4c1
Fix deletion of queries referenced by foreign key (#1842)
- Add cascading deletes for scheduled_queries when queries are deleted
- Also add cascading deletes for scheduled_queries when packs are deleted

Fixes #1837
2018-06-20 17:32:43 -07:00
Zachary Wasserman
6424a029ee
Fix labels UI issues in Fleet 2.0 (#1830)
Replaces the UI endpoints for creating and modifying labels. These were removed
in #1686 because we thought we were killing the UI.

Now labels can be created and edited in the UI again.
2018-06-18 10:09:08 -07:00
Zachary Wasserman
0b7747bef0
Fix pack and query UI issues in Fleet 2.0 (#1829)
Replaces (and appropriately refactors) a number of endpoints that were removed long ago when we decided to kill the UI with the fleetctl release. We turned out not to do this, and now need to restore these missing endpoints.

This is not a straight up replacement of the existing code because of refactoring to the DB schemas that was also done in the migration.

Most of the replaced code was removed in #1670 and #1686.

Fixes #1811, fixes #1810
2018-06-15 10:13:11 -04:00
Zachary Wasserman
6eecaa1019
Update redigo import (#1821)
- Use new repo path (old repo archived)
- Update version to 2.0.0

Closes #1820
2018-06-11 12:14:21 -07:00
Mike Arpaia
c91a031d3e
Attempt 2 at returning a serializable config (#1819) 2018-06-11 11:34:05 -06:00
Zachary Wasserman
f8796bc55b
Fix timezone in MySQL connection string (#1818)
Fixes #1643
2018-06-11 07:31:39 -07:00
Thordur Bjornsson
71217e6c52 server/service, livequery: Check totals Load for nil (#1802)
Matches status, if there are no results (yet) this bombs as the
the interface value is nil.
2018-06-04 09:40:41 -06:00
Alex Flores
56a2b81579 Set allowNativePasswords DSN setting to true (#1805) 2018-06-01 14:29:24 -07:00
Mike Arpaia
1d70b082a5
Add a setup guide for new CLI users (#1798) 2018-05-22 17:57:56 -06:00
Mike Arpaia
abab0d4691
Add fleetctl convert command for migrating packs to Fleet's format (#1790) 2018-05-21 10:26:22 -06:00
Zachary Wasserman
e626d5d060 Add options clients and commands (#1791) 2018-05-21 10:25:58 -06:00
Zachary Wasserman
b80e0a102d
Add fleetctl query command (#1784)
Allow queries targeted by hostname and label name.
2018-05-17 15:54:34 -07:00
Thordur Bjornsson
6a4d50c7a6 ensure email and passwords are set during setup (#1786) 2018-05-17 08:29:04 -06:00
Thordur Bjornsson
929000ba28 server: formatting (#1788) 2018-05-16 23:52:24 -06:00
Thordur Bjornsson
d7e1462d10 Check if the jwtToken is valid in authViewer. (#1785)
Closes #1514
2018-05-16 09:36:35 -06:00
Mike Arpaia
b42e4bacf2
Add name not empty validation for spec types (#1783) 2018-05-14 12:23:38 -06:00
Zachary Wasserman
87331b47e2
Return 404 errors where appropriate in spec endpoints (#1777) 2018-05-09 16:54:42 -07:00
Zachary Wasserman
4dfc1ca25e
Improve client error messages with unexpected server errors (#1776) 2018-05-09 16:54:23 -07:00
Zachary Wasserman
bef7a99160
Add logging middleware for spec endpoints (#1774) 2018-05-09 11:00:48 -07:00
Mike Arpaia
ab23e60a98
Add fleetctl get label, pack, query for individual items by name (#1768)
This PR adds support for getting resources by name.

```
$ fleetctl get queries
no queries found

$ fleetctl apply -f ./query.yaml
[+] applied 1 queries

$ fleetctl get queries
+-----------------+--------------------------------+--------------------------------+
|      NAME       |          DESCRIPTION           |             QUERY              |
+-----------------+--------------------------------+--------------------------------+
| osquery_version | The version of the Launcher    | select launcher.version,       |
|                 | and Osquery process            | osquery.version from           |
|                 |                                | kolide_launcher_info launcher, |
|                 |                                | osquery_info osquery;          |
+-----------------+--------------------------------+--------------------------------+

$ fleetctl get query osquery_version
apiVersion: v1
kind: query
spec:
  description: The version of the Launcher and Osquery process
  name: osquery_version
  query: select launcher.version, osquery.version from kolide_launcher_info launcher,
    osquery_info osquery;
```
2018-05-08 18:10:01 -06:00
Mike Arpaia
2f997b7f22
Merge master 2018-05-07 22:57:08 -06:00
Mike Arpaia
20fb50a7a6
Add fleetctl delete command (#1765) 2018-05-07 20:07:00 -06:00
Zachary Wasserman
d146412364 Implement Get methods for single entities of label, pack and query specs (#1766)
- Datastore methods (where necessary)
- Service methods
- Endpoints/Handlers
2018-05-07 19:54:29 -06:00
Zachary Wasserman
0f00c70606
Fixes in query, pack and label clients (#1763)
- Use authenticated requests
- Don't take a parameter for the Get*Specs methods
2018-05-07 16:30:52 -07:00
Zachary Wasserman
3d1d088be9
Implement clients for labels, packs and queries (#1760)
Go client methods for making get, set and delete requests on label, pack and
query entities.
2018-05-07 12:44:40 -07:00
Zachary Wasserman
8febf3ed96
Fixes + proposed changes to client error handling (#1759)
- Fix places where we accidentally return nil when we should return an error.
- Simplify interfaces/implementation of specialized errors
- Use more specific error messages
- Consistent JSON decoding
2018-05-04 14:55:57 -07:00
Zachary Wasserman
003ad9b5fa
Delete spec entities by name instead of ID (#1755)
With the UI, deleting by ID made sense. With fleetctl, we now want to delete
by name. Transition only the methods used for spec related entities, as others
will be removed soon.
2018-05-04 11:05:55 -07:00
Donovan Schönknecht
12922a89cc Remove default timestamp to fix strict error (#1720) 2018-05-04 11:10:17 -06:00
Mike Arpaia
018e10ea66
Add fleetctl config and auth commands (#1751)
```
$ fleetctl config set address https://localhost:8080
[+] Set the "address" config key to "https://localhost:8080" in the "default" context

$ fleetctl config set ignore_tls true
[+] Set the "ignore_tls" config key to "true" in the "default" context

$ fleetctl setup --email mike@arpaia.co --password "abc123"
[+] Fleet setup successful and context configured!

$ cat ~/.fleet/config
contexts:
  default:
    address: https://localhost:8080
    email: mike@arpaia.co
    ignore_tls: true
    token: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzZXNzaW9uX2tleSI6IlUvdm05Vk9wSG0xUlA4SUtjQnBhb2ovWlo1TXppSEVXcFRCNFNPb2tHQnNLUFpDQXFieVpWWnpJb0UvczQzcWkyd1pHZXJOa29SNFVIQ2hNZUc0K09RPT0ifQ.rHawSN8JvD4jjWAPTYX2Ep9ZpMt3u4mSIQcu920C-_s

$ fleetctl logout
[+] Fleet logout successful and local token cleared!

$ cat ~/.fleet/config
contexts:
  default:
    address: https://localhost:8080
    email: mike@arpaia.co
    ignore_tls: true
    token: ""
```
2018-05-04 10:53:21 -06:00
Zachary Wasserman
c5f0e5a6b4
Add endpoints for apply/get of each spec type (#1752)
- Osquery Options (to be renamed to Options after current Options removed)
- Labels
- Queries
- Packs
2018-05-03 18:01:57 -07:00
Zachary Wasserman
1d9e37b069
Pull decorators from config options (#1749)
Previously decorators were stored in a separate table. Now they are stored
directly with the config so that they can be modified on a per-platform basis.

Delete now unused decorators code.
2018-05-03 10:14:07 -07:00
Zachary Wasserman
a0d05f4e2a Merge branch 'master' into fleetctl 2018-05-01 17:26:32 -07:00
Mike Arpaia
920f4afab6
Scaffold the login command (#1748) 2018-05-01 16:58:53 -06:00
angrylogic
c873833a5f Include RFC822 From header. (#1743)
The DMARC and DKIM email authentication systems both require the RFC822
From header to function.  Kolide currently only includes the configured
sender address as the SMTP Envelop From address (e.g., the MAIL FROM
command).  This patch also includes the configured sender address in the
RFC822 email From header which should allow these emails to pass both
DKIM and DMARC authentication.
2018-04-25 09:02:09 -07:00
Zachary Wasserman
4784eb2322
Fix distributed query status parsing for osquery 3 (#1742)
A change from strings to integers broke the existing code. We now support
either for current and backwards compatibility.
2018-04-24 12:40:11 -07:00
Zachary Wasserman
23a12b2ab0
Add check for Duo SAML vulnerability (not vulnerable) (#1718)
See https://goo.gl/zuku4E.

> The most obvious remediation here is ensuring your SAML library is extracting
  the full text of a given XML element when comments are present.

Our implementation asks for the innerxml of the NameID field, so it returns the
entire text including the comment (See https://goo.gl/KLLXof). By default Go's
XML parsing would return the text not including the comment (but including
further text after the comment). Both of these options prevent the
vulnerability.
2018-03-02 09:44:23 -07:00
Ben Coverston
d28d2cac28 Add FileAccesses to FIM Configuration (#1717)
- Close #1708
- Fix FIM interval not being stored
2018-02-26 12:54:13 -08:00
dso
c017779313 Populate network interfaces on Windows (#1700)
Add support for Windows hosts in addition to macOS and Linux.
2018-02-04 21:16:24 -08:00
Zachary Wasserman
bde7256a09
Update labels interfaces for fleetctl (#1686)
- Remove unnecessary labels code
- Remove unnecessary packs code
- Update tests as appropriate
2018-01-10 11:38:20 -08:00
Zachary Wasserman
26dc30bd25
Update query and pack interfaces for fleetctl (#1670)
- Add new Apply spec methods for queries and packs
- Remove now extraneous datastore/service methods
- Remove import service (unused, and had many dependencies that this breaks)
- Refactor tests as appropriate
2018-01-03 11:18:05 -08:00
Zachary Wasserman
77b16e92e0
Fix missing removed and shard keys in query packs (#1685)
Include the appropriate values for removed and shard when generating config
to return to osqueryd.

Note: This was originally fixed and tested in the fleetctl branch (#1680), and
the fix is being cherry-picked into master without the test.
2018-01-02 19:29:27 -08:00
Zachary Wasserman
d6b4de3874
Refactor osquery options interface (#1674)
After discussion with @groob and @marpaia, we have decided that the service
methods should not be aware of any YAML/JSON definitions, and should work
directly with objects. The new pattern we will use will involve converting YAML
to JSON at the client, and then sending the JSON which will be decoded using
the familiar go-kit mechanisms before being passed to the service methods.
2018-01-02 16:22:45 -08:00
Zachary Wasserman
2d3e5c11cb
Fix missing removed and shard keys in query packs (#1680)
Include the appropriate values for `removed` and `shard` when generating config
to return to osqueryd.
2018-01-02 16:06:50 -08:00
ferhat elmas
657494e504 server/datastore: add missing err check in label creation test (#1683) 2017-12-21 19:07:09 -08:00
ferhat elmas
d2a7e38c85 Fix documentation typos (#1682) 2017-12-21 18:37:32 -08:00
Scott J. Roberts
9c52bed855 Add flags for configuring MySQL connection pooling limits (#1672) 2017-12-19 13:52:52 -08:00
ferhat elmas
1bd622bce7 server/datastore/inmem: fix host removal lock (#1673) 2017-12-18 14:38:33 -08:00
Zachary Wasserman
5e9fe9d5a1
Transition osquery options interfaces for compatibility with fleetctl (#1649)
- Refinements to options yaml definition
- Datastore and service implementations
- Migration to bring existing options into new table format
2017-12-13 18:14:54 -05:00
Victor Vrantchan
6d328ed70c
Write the raw status log to the writer (#1666)
Instead of trying to decode and re-encode status logs, we now write them directly as they come in.
This change prevents future changes to the osquery status log file format (addition and deletion of fields ) from
affecting Fleet. A similar change was implemented in #1636 for result logs.

Closes #1664
2017-12-12 10:43:33 -05:00
ferhat elmas
9e0912e2f3 General simplification in go part (#1658)
* don't check if error is nil, return it
 * don't compare bool to bool, use it
 * don't supply capacity to make for slice when len
   is equal to cap
2017-12-04 09:43:43 -05:00
Victor Vrantchan
0b5c3d4111
log the remote IP of the host making a request (#1653) 2017-11-30 19:52:23 -05:00
Mike Arpaia
edca82eaf2 Revert "add remote ip address to service logs (#1635)" (#1651)
This reverts commit 11707132bd.
2017-11-27 17:56:09 -05:00
Victor Vrantchan
8291119067
use json.RawMessage for result logs (#1636)
Initially fleet decoded the incoming JSON sent to the log endpoint.
Then the log event would be written to a log writer by calling json.Encoder{}.Encode.
Re-encoding logs is lossy; whenever a new field is sent by osqueryd we don't keep up with them.
Instead of caring about the content of the OsqueryResultLog, fleet will now write all log results
exactly as sent to the server by osqueryd.

Closes #1632
Closes #1615
2017-11-18 19:59:32 -05:00
Victor Vrantchan
11707132bd
add remote ip address to service logs (#1635)
Closes #1630
2017-11-18 18:41:23 -05:00
John Murphy
2840caff86 Fixed leaking http client (#1628)
close #1587
2017-11-16 09:53:42 -07:00
Victor Vrantchan
d472d7d4bd
logwriter: stat file before writing (#1617)
If the file was rotated/deleted the data is never written to disk. Calling os.Stat ensures that the file will be re-created.
2017-11-15 12:34:49 -05:00
Victor Vrantchan
6bed7c7cd0
close request bodies (#1613) 2017-11-14 18:06:42 -05:00
Mike Arpaia
04396c4a37
Set decorator names for default decorators (#1590) 2017-10-27 17:52:24 -04:00
Victor Vrantchan
5ad562a952 refactor gRPC endpoints with launcher packages in mind (#1582)
The launcher service implementation is an adapter around the TLS service.
All launcher methods that have an equivalent in TLS pass the business logic to the
TLS API.

Closes #1565
2017-10-24 19:55:32 -04:00
Victor Vrantchan
c496eb8df2 add health package to create reusable healthz checks. (#1583)
Moved the healthz handler and exposed the CheckHealth method so the same healthchecks could be
used by TLS, gRPC and any other APIs.
2017-10-23 14:39:15 -04:00
Mike Arpaia
8425fe2214 Use dep instead of glide (#1564) 2017-10-13 09:00:58 -06:00
Mike Arpaia
1e16b12638 Move cli directory to cmd/fleet (#1560) 2017-10-12 10:42:13 -06:00
Mike Arpaia
9d21cbdb8a removing license code (#1551) 2017-09-01 10:42:46 -06:00
John Murphy
d5f9fcaeb2 Added FIM support (#1548)
This PR adds support for file integrity monitoring. This is done by providing a simplified API that can be used to PATCH/GET FIM configurations. There is also code to build the FIM configuration to send back to osquery. Each PATCH request, if successful, replaces Fleet's existing FIM configuration. For example:

curl -X "PATCH" "https://localhost:8080/api/v1/kolide/fim" \
     -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzZXNzaW9uX2tleSI6IkVhaFhvZWswMGtWSEdaTTNCWndIMnhpYWxkNWZpcVFDR2hEcW1HK2UySmRNOGVFVE1DeTNTaUlFWmhZNUxhdW1ueFZDV2JiR1Bwdm5TKzdyK3NJUzNnPT0ifQ.SDCHAUA1vTuWGjXtcQds2GZLM27HAAiOUhR4WvgvTNY" \
     -H "Content-Type: application/json; charset=utf-8" \
     -d $'{
  "interval": 500,
  "file_paths": {
    "etc": [
      "/etc/%%"
    ],
    "users": [
      "/Users/%/Library/%%",
      "/Users/%/Documents/%%"
    ],
    "usr": [
      "/usr/bin/%%"
    ]
  }
}'
2017-08-18 10:37:33 -05:00
John Murphy
1e92f8fcfd gRPC Server for Launcher (#1544)
Add a gRPC server that will interact with osquery through Launcher. This endpoint will expose the osquery configuration suitable for use via the Launcher plugin, and collect log and query results.
2017-08-17 16:43:02 -05:00
John Murphy
3c2fa3f69c attribute shouldn't appear in request if empty (#1541)
ProtocolBinding is an optional attribute in the SAML spec, and shouldn't appear in the request xml if it is not populated.
2017-08-02 14:02:43 -05:00
John Murphy
d1b37616a0 Fix SSO for ADFS (#1535)
Closes #1533

Since the SAML 2.0 spec doesn't say what characters are valid in an Entity ID and Active Directory doesn't like '=' signs in base64 encoded ID's I added code that generates ID's with a character set that we know works.  Also, removed ProtocolBinding attribute from AuthRequest as is was forcing ADFS to use redirect binding when it should use post binding.
2017-07-31 21:48:42 -05:00
John Murphy
e67157345a Added ability to handle nested signed assertions in SAML response
Closes #1532

Fixes error that was caused because there was a bug in processing nested assertions in a successful SAML response. This was not caught in the initial push of this code because the IDP's we tested against all sign the entire response document as opposed to parts of it.  Thus the existing test cases didn't cover the code that dealt with nested assertions.
2017-07-18 15:28:35 -05:00
Mike Arpaia
018b91ab2c Rename project to Kolide Fleet (#1529) 2017-06-22 15:50:45 -04:00
Zachary Wasserman
ce32498bdf Fix aliased config_tls_refresh processing (#1530)
Changes in osquery 2.4.6 prevented us from correctly retrieving the config
interval. This commit retrieves the new aliased interval.
2017-06-19 20:04:21 -04:00
Mike Arpaia
71abc38c22 Adding comments to the osquery types (#1519) 2017-06-18 12:26:08 -06:00
John Murphy
095aa7df7a Fix issue where empty strings are returned as ints in log results (#1522)
Fix for issue where osquery sends empty strings where we expect integers in detail queries. We handle empty strings in these cases by changing them to "0" and then letting the different conversion functions change the "0" string into the appropriate integer type. This has been tested against running osquery hosts.

Closes #1521
2017-06-08 12:57:12 -05:00
John Murphy
d8ce89f42d Add ability to handle empty set of decorators (#1515)
Normally a Kolide user will always have at least two built in decorators that they can't delete through the UI so a situation with zero decorators should never happen; however, in the event we change this behavior in the future, or a user manually deletes decorators from the database the UI should handle an empty decorator set.
2017-06-01 17:17:37 -05:00
John Murphy
7a8f418d0f Added support for atomic imports and dry run imports (#1510)
Closes issue #1475

The command line tool that uses this endpoint -> https://github.com/kolide/configimporter

* Added support for atomic imports and dry run imports

* Added code so that imports are idempotent
2017-05-30 14:42:00 -05:00
John Murphy
151ce35e8c Front end support for decorator crud ops (#1509)
This PR closes #1448, providing front end CRUD operations for decorators.* Front end support for decorator crud ops.
2017-05-30 13:36:29 -05:00
Zachary Wasserman
e9b07fd1f0 Fix host authentication errors in case of DB failure (#1512)
Closes #1511
2017-05-25 14:10:12 -07:00
John Murphy
019191c36b SSO Login and Configuration Support (#1506)
Closes issue #1456 This PR adds a single sign on option to the login form, exposes single sign on to the end user, and allows an admin user to set single sign on configuration options.
2017-05-17 10:58:40 -05:00
John Murphy
12d2df1f9a Add SSO support to new user activation (#1504)
Closes #1502. This PR adds support for SSO to the new user creation process. An admin now has the option to select SSO when creating a new user.  When the confirmation form is submitted, the user is automatically authenticated with the IDP, and if successful, is redirected to the Kolide home page. Password authentication, password change and password reset are not allowed for an SSO user.
2017-05-10 11:26:05 -05:00
John Murphy
368b9d774c Server Side SSO Support (#1498)
This PR partially addresses #1456, providing SSO SAML support. The flow of the code is as follows.

A Kolide user attempts to access a protected resource and is directed to log in.
If SSO identity providers (IDP) have been configured by an admin, the user is presented with SSO log in.
The user selects SSO, which invokes a call the InitiateSSO passing the URL of the protected resource that the user was originally trying access. Kolide server loads the IDP metadata and caches it along with the URL. We then build an auth request URL for the IDP which is returned to the front end.
The IDP calls the server, invoking CallbackSSO with the auth response.
We extract the original request id from the response and use it to fetch the cached metadata and the URL. We check the signature of the response, and validate the timestamps. If everything passes we get the user id from the IDP response and use it to create a login session. We then build a page which executes some javascript that will write the token to web local storage, and redirect to the original URL.
I've created a test web page in tools/app/authtest.html that can be used to test and debug new IDP's which also illustrates how a front end would interact with the IDP and the server. This page can be loaded by starting Kolide with the environment variable KOLIDE_TEST_PAGE_PATH to the full path of the page and then accessed at https://localhost:8080/test
2017-05-08 19:43:48 -05:00
John Murphy
2945031a86 Fix bug in Osquery import and updated import docs (#1478)
This PR contains a fix for a bug that turned up when I was testing configimporter. If the platform field is not specified, its supposed to default to all per the osquery configuration spec. The default was not properly implemented, and if the platform value was missing from the imported configuration it failed. The PR also added instructions to the api documentation describing how to import an osquery configuration.
2017-04-23 19:41:27 -05:00
Zachary Wasserman
49e4bad88d Do not return deleted packs with query (#1497)
Closes #1476
2017-04-18 12:41:51 -07:00
Zachary Wasserman
22fbb65db3 Re-enable all tests in TestUpdateHostIntervals (#1496) 2017-04-18 11:29:04 -07:00
Zachary Wasserman
dfa2d83855 Update online status calculation to use per-host intervals (#1494)
Replaces the existing calculation that uses a global online interval. This method was lacking due to the fact that different hosts may have different checkin intervals set.

The new calculation uses `min(distributed_interval, config_tls_refresh) + 30` as the interval. This is calculated with the stored values for each host.

Closes #1321
2017-04-18 10:39:50 -07:00
Zachary Wasserman
629a740b45 Require JWT Key to be specified for server startup (#1480)
If server is started without a JWT key, a message like the following is printed:
```
################################################################################
# ERROR:
#   A value must be supplied for --auth_jwt_key. This value is used to create
#   session tokens for users.
#
#   Consider using the following randomly generated key:
#   om3w95gMA2drT5xAdLd2Q5oE8fLw+Miz
################################################################################
```

Closes #1480.
2017-04-12 15:05:56 -07:00
John Murphy
789596a78e SAML Database Support
Partially addresses #1456. This PR provides datastore support for SSO by creating a new entity IdentityProvider. This entity is an abstraction of the SAML IdentityProvider and contains the data needed to perform SAML authentication.
2017-04-12 15:42:10 -05:00
Zachary Wasserman
d3eb3b7272 Remove unused --app_token_key flag (#1479)
Closes #1469
2017-04-11 17:13:38 -07:00
Zachary Wasserman
d7cd91c0e4 Retrieve and store host checkin intervals (#1473)
We now track the `config_tls_refresh`, `distributed_interval` and
`logger_tls_period` flag values for each host. Each value is updated by a
detail query agains the `osquery_flags` table, because they may be specified
outside of Kolide. The flags that can be specified within Kolide are also
updated when a config is returned to the host that changes their value.

This will enable us to do a more accurate per-host online status calculation as
discussed in #1419.
2017-04-06 11:55:24 -07:00
Zachary Wasserman
6a3ea3fc8c Remove remaining uses of golang.org/x/net/context (#1464) 2017-04-05 12:25:34 -07:00
John Murphy
c90368c4af Changed default osquery logging behavior
Made log rotation for osquery results and status logs optional.  This required writing the logwriter package which is a drop in replacement for lumberjack.  We still use lumberjack if the log rotation flag --osquery_enable_log_rotation flag is set. Note that the performance of the default is quite a bit better than lumberjack.


BenchmarkLogger-8       	 2000000	       747 ns/op
BenchmarkLumberjack-8   	 1000000	      1965 ns/op
PASS
BenchmarkLogger-8       	 2000000	       731 ns/op
BenchmarkLumberjack-8   	 1000000	      2040 ns/op
PASS
BenchmarkLogger-8       	 2000000	       741 ns/op
BenchmarkLumberjack-8   	 1000000	      1970 ns/op
PASS
BenchmarkLogger-8       	 2000000	       737 ns/op
BenchmarkLumberjack-8   	 1000000	      1930 ns/op
PASS
2017-04-03 16:48:50 -05:00