Flag File<\/code><\/strong><\/a>: flags to control initialization, disable\/enable features, and select plugins.<\/li>\n<\/ul>\n\n\n\nOnce the files above are downloaded, copy them to the remote Osquery host.<\/p>\n\n\n\n
For example, in my setup, i have copied the files to home directory of specific user account on my Ubuntu 22.04 server;<\/p>\n\n\n\n
ls ~\/ -1<\/code><\/pre>\n\n\n\nflagfile.txt\nfleet.pem\nsecret.txt<\/code><\/pre>\n\n\n\nNavigate to the directory where the files above are stored on the osquery host, in case it is my users home directory.<\/p>\n\n\n\n
cd ~\/<\/code><\/pre>\n\n\n\nEnroll Osquery host on Fleet manager by running the command below.<\/p>\n\n\n\n
(Before you can run the command below, ensure that the Osquery Fleet manager hostname that you generated the SSL certs from is resolvable from the host<\/strong>)<\/p>\n\n\n\nsudo osqueryd --flagfile=flagfile.txt --verbose<\/code><\/pre>\n\n\n\nYou will some system output.<\/p>\n\n\n\n
I0927 17:55:12.850069 55765 init.cpp:399] osquery initialized [version=5.5.1]\nI0927 17:55:12.850409 55765 extensions.cpp:453] Could not autoload extensions: Cannot open file for reading: \/etc\/osquery\/extensions.load\nI0927 17:55:12.850607 55765 dispatcher.cpp:78] Adding new service: WatcherRunner (0x55ac173b62b8) to thread: 140233538664000 (0x55ac173ae9b0) in process 55765\nI0927 17:55:12.851366 55766 watcher.cpp:680] osqueryd watcher (55765) executing worker (55767)\nI0927 17:55:12.856755 55767 init.cpp:396] osquery worker initialized [watcher=55765]\nI0927 17:55:12.856871 55767 dispatcher.cpp:78] Adding new service: WatcherWatcherRunner (0x55a4664d72b8) to thread: 140054961374784 (0x55a4664d05a0) in process 55767\nI0927 17:55:12.856969 55767 rocksdb.cpp:132] Opening RocksDB handle: \/var\/osquery\/osquery.db\nI0927 17:55:12.913545 55767 dispatcher.cpp:78] Adding new service: ExtensionWatcher (0x55a466620098) to thread: 140054420764224 (0x55a466564bf0) in process 55767\nI0927 17:55:12.913673 55767 dispatcher.cpp:78] Adding new service: ExtensionRunnerCore (0x55a46661f228) to thread: 140054429156928 (0x55a4664f2cb0) in process 55767\nI0927 17:55:12.913722 55896 interface.cpp:299] Extension manager service starting: \/var\/osquery\/osquery.em\nI0927 17:55:12.913940 55767 auto_constructed_tables.cpp:99] Removing stale ATC entries\nI0927 17:55:12.914314 55767 dispatcher.cpp:78] Adding new service: ConfigRefreshRunner (0x55a4665aaf38) to thread: 140054437549632 (0x55a466565e40) in process 55767\nI0927 17:55:12.914551 55767 tls.cpp:255] TLS\/HTTPS POST request to URI: https:\/\/fleet.kifarunix-demo.com:8080\/api\/v1\/osquery\/config\nI0927 17:55:13.929601 55767 tls_enroll.cpp:81] TLSEnrollPlugin requesting a node enroll key from: https:\/\/fleet.kifarunix-demo.com:8080\/api\/osquery\/enroll\nI0927 17:55:13.931106 55767 system.cpp:237] Using host identifier: 2121d69f-6e3d-4204-806a-8e214b47b7cb\nI0927 17:55:13.933938 55767 smbios_tables.cpp:105] Reading SMBIOS from sysfs DMI node\nI0927 17:55:13.936805 55767 smbios_tables.cpp:105] Reading SMBIOS from sysfs DMI node\nI0927 17:55:13.937805 55767 tls.cpp:255] TLS\/HTTPS POST request to URI: https:\/\/fleet.kifarunix-demo.com:8080\/api\/osquery\/enroll\nI0927 17:55:14.005929 55767 tls.cpp:255] TLS\/HTTPS POST request to URI: https:\/\/fleet.kifarunix-demo.com:8080\/api\/v1\/osquery\/config\nW0927 17:55:14.025341 55767 options.cpp:106] The CLI only flag --logger_plugin set via config file will be ignored, please use a flagfile or pass it to the process at startup\nI0927 17:55:14.047302 55767 smbios_tables.cpp:105] Reading SMBIOS from sysfs DMI node\nI0927 17:55:14.048081 55767 smbios_tables.cpp:105] Reading SMBIOS from sysfs DMI node\nI0927 17:55:14.048434 55767 dispatcher.cpp:78] Adding new service: TLSLogForwarder (0x55a46674b188) to thread: 140054840202816 (0x55a466764c90) in process 55767\nI0927 17:55:14.048753 55900 tls.cpp:255] TLS\/HTTPS POST request to URI: https:\/\/fleet.kifarunix-demo.com:8080\/api\/osquery\/log\nI0927 17:55:14.049381 55767 eventfactory.cpp:156] Event publisher not enabled: BPFEventPublisher: Publisher disabled via configuration\nI0927 17:55:14.049559 55767 eventfactory.cpp:156] Event publisher not enabled: auditeventpublisher: Publisher disabled via configuration\nI0927 17:55:14.049754 55767 eventfactory.cpp:156] Event publisher not enabled: inotify: Publisher disabled via configuration\nI0927 17:55:14.049918 55767 eventfactory.cpp:156] Event publisher not enabled: syslog: Publisher disabled via configuration\nI0927 17:55:14.050160 55767 events.cpp:70] Skipping subscriber: apparmor_events: Subscriber disabled via configuration\nI0927 17:55:14.050382 55767 events.cpp:70] Skipping subscriber: process_file_events: Subscriber disabled via configuration\nI0927 17:55:14.050551 55767 events.cpp:70] Skipping subscriber: seccomp_events: Seccomp subscriber disabled via configuration\nI0927 17:55:14.050714 55767 events.cpp:70] Skipping subscriber: selinux_events: Subscriber disabled via configuration\nI0927 17:55:14.050877 55767 events.cpp:70] Skipping subscriber: socket_events: Subscriber disabled via configuration\nI0927 17:55:14.051129 55901 eventfactory.cpp:390] Starting event publisher run loop: udev\nI0927 17:55:14.051138 55767 dispatcher.cpp:78] Adding new service: DistributedRunner (0x55a4666cc178) to thread: 140054815024704 (0x55a4666db480) in process 55767\nI0927 17:55:14.051409 55767 dispatcher.cpp:78] Adding new service: SchedulerRunner (0x55a466620718) to thread: 140054806632000 (0x55a4666f6a20) in process 55767\nI0927 17:55:14.051676 55902 tls.cpp:255] TLS\/HTTPS POST request to URI: https:\/\/fleet.kifarunix-demo.com:8080\/api\/v1\/osquery\/distributed\/read\nI0927 17:55:14.063175 55902 distributed.cpp:151] Executing distributed query: fleet_detail_query_disk_space_unix: \nSELECT (blocks_available * 100 \/ blocks) AS percent_disk_space_available,\n round((blocks_available * blocks_size *10e-10),2) AS gigs_disk_space_available\n...\n<\/code><\/pre>\n\n\n\nThe host now communicates with the Osquery Fleet manager and it should be enrolled.<\/p>\n\n\n\n
Navigate to Osquery Fleet Manager and refresh the web interface. You should be able to see you host enrolled.<\/p>\n\n\n\n
<\/figure>\n\n\n\nRunning Osqueryd as a Service<\/h3>\n\n\n\n
To ensure a constant communication between the Osquery host and the Fleet manager, you need to run osqueryd as a service.<\/p>\n\n\n\n
Therefore, stop the standalone process initiated above by pressing Ctrl+c<\/strong>.<\/p>\n\n\n\nUpdate the osqueryd service unit file configurations as follows.<\/p>\n\n\n\n
First of all, let us move the secret, the certificate and the flag files to \/etc\/osquery<\/strong><\/code> directory;<\/p>\n\n\n\nsudo mv ~\/{flagfile.txt,fleet.pem,secret.txt} \/etc\/osquery<\/code><\/pre>\n\n\n\nNext, update the path to FLAG_FILE environment variable in the osqueryd service defaults file, \/etc\/default\/osqueryd<\/strong><\/code>.<\/p>\n\n\n\nsudo vim \/etc\/default\/osqueryd<\/code><\/pre>\n\n\n\nCheck the highlighted line. Replace the path accordingly.<\/p>\n\n\n\n
FLAG_FILE=\"\/etc\/osquery\/flagfile.txt\"<\/strong>\nCONFIG_FILE=\"\/etc\/osquery\/osquery.conf\"\nLOCAL_PIDFILE=\"\/var\/osquery\/osqueryd.pidfile\"\nPIDFILE=\"\/var\/run\/osqueryd.pidfile\"<\/code><\/pre>\n\n\n\nNext, edit the flagfile.txt<\/code><\/strong> file and update the path to Secret and Certificate file.<\/p>\n\n\n\nsudo vim \/etc\/osquery\/flagfile.txt<\/pre>\n\n\n\n# Server\n--tls_hostname=osquery.kifarunix-demo.com:8080\n--tls_server_certs=\/etc\/osquery\/fleet.pem<\/strong>\n\n# Enrollment\n--host_identifier=instance\n--enroll_secret_path=\/etc\/osquery\/secret.txt<\/strong>\n--enroll_tls_endpoint=\/api\/v1\/osquery\/enroll\n<\/code><\/pre>\n\n\n\nSave and exit the file after making the changes.<\/p>\n\n\n\n
Reload systemd configurations;<\/p>\n\n\n\n
sudo systemctl daemon-reload<\/code><\/pre>\n\n\n\nRestart osqueryd service<\/p>\n\n\n\n
sudo systemctl restart osqueryd.service<\/code><\/pre>\n\n\n\nChecking the status;<\/p>\n\n\n\n
systemctl status osqueryd<\/code><\/pre>\n\n\n\n\u25cf osqueryd.service - The osquery Daemon\n Loaded: loaded (\/lib\/systemd\/system\/osqueryd.service; disabled; vendor preset: enabled)\n Active: active (running) since Tue 2022-09-27 18:00:09 UTC; 5s ago\n Process: 56011 ExecStartPre=\/bin\/sh -c if [ ! -f $FLAG_FILE ]; then touch $FLAG_FILE; fi (code=exited, status=0\/SUCCESS)\n Process: 56012 ExecStartPre=\/bin\/sh -c if [ -f $LOCAL_PIDFILE ]; then mv $LOCAL_PIDFILE $PIDFILE; fi (code=exited, status=0\/SUCCESS)\n Main PID: 56013 (osqueryd)\n Tasks: 17 (limit: 2241)\n Memory: 8.5M\n CPU: 111ms\n CGroup: \/system.slice\/osqueryd.service\n \u251c\u250056013 \/opt\/osquery\/bin\/osqueryd --flagfile \/etc\/osquery\/flagfile.txt --config_path \/etc\/osquery\/osquery.conf\n \u2514\u250056015 \/opt\/osquery\/bin\/osqueryd \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \"\" \">\n\nSep 27 18:00:09 jellyfish systemd[1]: Starting The osquery Daemon...\nSep 27 18:00:09 jellyfish systemd[1]: Started The osquery Daemon.\nSep 27 18:00:09 jellyfish osqueryd[56013]: osqueryd started [version=5.5.1]\n<\/code><\/pre>\n\n\n\nEnable the service to run on system boot;<\/p>\n\n\n\n
sudo systemctl enable osqueryd.service<\/code><\/pre>\n\n\n\nAlso verify that osquery host status is online on the Fleet manager.<\/p>\n\n\n\n
Querying Host from Fleet Osquery Manager<\/h3>\n\n\n\n
You can now query the host by clicking on the hostname<\/strong> of the host and then Query<\/strong><\/p>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\nClick Create custom query<\/strong>.<\/p>\n\n\n\nEnter the SQL query e.g (<\/span>select interface,address,mask from interface_addresses where interface NOT LIKE '%lo%';<\/strong><\/code>)<\/span><\/p>\n\n\n\n
<\/figure>\n\n\n\nYou can either Execute<\/strong> or Save<\/strong> the query for future use if you want.<\/p>\n\n\n\nIf you choose to execute, you will be prompted to select target hosts. Select the hosts to run the query against.<\/p>\n\n\n\n
Run the query<\/p>\n\n\n\n
<\/figure>\n\n\n\nSample results of our query;<\/p>\n\n\n\n
<\/figure>\n\n\n\nVery nice, isn’t it?<\/p>\n\n\n\n
For other custom queries, choose a table you want to query from the right pane. You will see all the available options related to the respective table that can enable you to make specific queries;<\/p>\n\n\n\n
<\/figure>\n\n\n\nYou can add more hosts to the Fleet for easy management and monitoring.<\/p>\n\n\n\n
Other Tutorials;<\/p>\n\n\n\n
Install and Enroll Elastic Agents to Fleet Manager in Linux<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"In this tutorial, you will learn how to add or enroll Osquery hosts on Fleet manager. Fleet is the most widely used open source osquery<\/p>\n","protected":false},"author":1,"featured_media":7987,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[72,121,1065],"tags":[3298,3302,3299,3301,3286,3300,3303,1068],"class_list":["post-8335","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-monitoring","category-howtos","category-osquery","tag-add-hosts-to-osquery-fleet-manager","tag-adding-hosts-to-fleet-manager","tag-enroll-hosts-on-osquery-fleet-manager","tag-enroll-osquery-hosts","tag-fleet-manager-osquery","tag-osquery-enrollment-secret","tag-osquery-flags-file","tag-osqueryd","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/8335"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=8335"}],"version-history":[{"count":10,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/8335\/revisions"}],"predecessor-version":[{"id":21892,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/8335\/revisions\/21892"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/7987"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=8335"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=8335"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=8335"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}