CrowdStrike / ansible_collection_falcon

Comprehensive toolkit for streamlining your interactions with the CrowdStrike Falcon platform.
https://galaxy.ansible.com/ui/repo/published/crowdstrike/falcon/
GNU General Public License v3.0
97 stars 60 forks source link

Falcon sensor takes ages to install #563

Closed drjeep closed 1 month ago

drjeep commented 1 month ago

I've been tasked with installing Falcon sensor on all our Linux servers, however it takes ages to install and in some cases times out altogether.

The issue appears to be the Copy Sensor Installation Package to remote host (non-windows) step below

Tuesday 10 September 2024  10:19:49 +0200 (0:00:00.453)       0:12:53.002 ***** 
=============================================================================== 
crowdstrike.falcon.falcon_install : CrowdStrike Falcon | Copy Sensor Installation Package to remote host (non-windows) ------------------------------------------------------------- 658.53s
crowdstrike.falcon.falcon_install : CrowdStrike Falcon | Transfer CrowdStrike Falcon RPM GPG key files ------------------------------------------------------------------------------ 22.39s
crowdstrike.falcon.falcon_configure : CrowdStrike Falcon | Wait for Falcon Sensor to Generate AID ----------------------------------------------------------------------------------- 14.48s
crowdstrike.falcon.falcon_install : CrowdStrike Falcon | Install Falcon Sensor Package (Linux) -------------------------------------------------------------------------------------- 13.03s
crowdstrike.falcon.falcon_install : CrowdStrike Falcon | Download Falcon Sensor Installation Package (local) ------------------------------------------------------------------------ 10.47s
crowdstrike.falcon.falcon_install : CrowdStrike Falcon | Remove tmp install directories ---------------------------------------------------------------------------------------------- 9.12s
crowdstrike.falcon.falcon_install : CrowdStrike Falcon | Import CrowdStrike Falcon RPM GPG key from files ---------------------------------------------------------------------------- 8.09s
crowdstrike.falcon.falcon_install : CrowdStrike Falcon | Verify Falcon Package Is Installed ------------------------------------------------------------------------------------------ 7.78s
Gathering Facts ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- 7.51s
crowdstrike.falcon.falcon_configure : CrowdStrike Falcon | Restart Falcon Sensor on Changes ------------------------------------------------------------------------------------------ 4.46s
crowdstrike.falcon.falcon_configure : CrowdStrike Falcon | Configure Falcon Sensor Options (Linux) ----------------------------------------------------------------------------------- 2.46s
crowdstrike.falcon.falcon_install : CrowdStrike Falcon | Gather tmp install directory objects ---------------------------------------------------------------------------------------- 2.30s
crowdstrike.falcon.falcon_configure : CrowdStrike Falcon | Register Falcon Sensor Options -------------------------------------------------------------------------------------------- 2.29s
crowdstrike.falcon.falcon_install : CrowdStrike Falcon | Verify Temporary Install Directory Exists (non-Windows) --------------------------------------------------------------------- 2.27s
crowdstrike.falcon.falcon_install : CrowdStrike Falcon | Get list of filtered Falcon sensors ----------------------------------------------------------------------------------------- 1.41s
crowdstrike.falcon.falcon_install : CrowdStrike Falcon | Authenticate to CrowdStrike API --------------------------------------------------------------------------------------------- 1.41s
crowdstrike.falcon.falcon_install : CrowdStrike Falcon | Detect Target CID Based on Credentials -------------------------------------------------------------------------------------- 1.24s
crowdstrike.falcon.falcon_configure : ansible.builtin.include_tasks ------------------------------------------------------------------------------------------------------------------ 0.45s
crowdstrike.falcon.falcon_install : CrowdStrike Falcon | Remove Downloaded Sensor Installation Package (local) ----------------------------------------------------------------------- 0.42s
crowdstrike.falcon.falcon_configure : CrowdStrike Falcon | Associate Falcon Sensor with your Provisioning Token (macOS) -------------------------------------------------------------- 0.15s

Does it really download the install package to the ansible client and then copy it to each server? Is there a reason it cannot just download the installation package directly on the remote server or provide a dnf repository for Redhat based distros?

Admittedly I'm a Crowdstrike newbie so maybe I'm missing something, but would appreciate some guidance on a more efficient way to install the agent on multiple (50+) servers.

carlosmmatos commented 1 month ago

@drjeep thanks for opening up an issue and asking a question. The short answer is - yes, the main operation uses localhost to download the sensor. This is because we use FalconPy SDK for our Modules/Plugins so we keep that dependency to one host. Otherwise, you would have to ensure the FalconPy python package is installed on all your endpoints. Also CrowdStrike does not have a package repository - but this doesn't mean that you can't create your own (see below ideas).

A couple of things that may help based on your output - since downloading the sensors seems to be rather quick and without knowing your Ansible environment:

[defaults]
forks = 25
[ssh_connection]
pipelining = true

You could create your own package repository using our modules.

Example: Query and Download installers to a directory

crowdstrike-repo.yml

---
- name: Creates a CrowdStrike package repository
  hosts: localhost
  connection: local
  gather_facts: no
  vars:
    falcon_client_id: "{{ lookup('env', 'FALCON_CLIENT_ID') }}"
    falcon_client_secret: "{{ lookup('env', 'FALCON_CLIENT_SECRET') }}"
    filter_os: '*RHEL*'
    filter_os_version: '*8*'
    filter_os_arch: x86_64
    installer_dest: /some/path/to/store/installers
  tasks:
    - name: CrowdStrike Falcon | Authenticate to CrowdStrike API
      crowdstrike.falcon.auth:
        client_id: "{{ falcon_client_id }}"
        client_secret: "{{ falcon_client_secret }}"
      register: falcon

    - name: Get list of installers to download
      crowdstrike.falcon.sensor_download_info:
        auth: "{{ falcon.auth }}"
        filter: "os:'{{ filter_os }}'+os_version:'{{ filter_os_version }}'+architectures:'{{ filter_os_arch }}'"
        sort: "version|desc"
      register: falcon_api_installer_list

    - name: Download installers to repo destination
      crowdstrike.falcon.sensor_download:
        auth: "{{ falcon.auth }}"
        hash: "{{ item.sha256 }}"
        dest: "{{ installer_dest }}"
      loop: "{{ falcon_api_installer_list.installers }}"

How you decide to make this available to your hosts is up to you 😉

Remember that you have options in the falcon_install role outside of using the API.

drjeep commented 1 month ago

Thanks, for now I've resorted to uploading the current version of the installer to S3 and using falcon_install_method: url which is indeed much faster. I'll look into making this more dynamic using your code above.