authentication


Authentication examples
The examples in this folder focus on authentication to CrowdStrike's APIs.
Azure Key Vault Authentication - CrowdStrike API authentication leveraging Azure Key Vault for credential storage.
AES Authentication - Leverage AES/CBC to encrypt credentials for use with authentication to the CrowdStrike API.
AES File Crypt - Encrypt arbitrary files with AES/CBC
AWS Parameter Store - CrowdStrike API authentication leveraging AWS Parameter Store for credential storage
Token Authentication - Token Authentication is the original solution for authenticating to a Service Class, and is still fully supported. This example demonstrates how to use Token Authentication to interact with multiple Service Classes.
Azure Key Vault Authentication
This application demonstrates storing CrowdStrike API credentials within the Azure Key Vault service, and retrieving them to access the CrowdStrike API.
Running the program
In order to run this demonstration, you will need access to CrowdStrike API keys with the following scopes:
Hosts
READ
You will also need to ensure you have the following:
An Azure Key Vault
https://docs.microsoft.com/azure/key-vault/quick-create-cli❗ Make note of the Vault URI ❗ You will use this as a command line argument.
Secrets created for your Falcon Client ID and Client Secret
azure-keyvault-secretsandazure-identitylibrariesSet up your environment to use azure-identity's DefaultAzureCredential.
For more information about how to configure the DefaultAzureCredential, refer to https://aka.ms/azsdk/python/identity/docs#azure.identity.DefaultAzureCredential
Command line arguments
This program accepts the following command line arguments.
-h
--help
Display command line help and exit
-k CLIENT_ID_PARAMETER
--client_id_parameter CLIENT_ID_PARAMETER
Name of the Key Vault Secrets parameter storing your API client ID
-s CLIENT_SECRET_PARAMETER
--client_secret_parameter CLIENT_SECRET_PARAMETER
Name of the Key Vault Secrets parameter storing your API client secret
-u VAULT_URI
--vault_uri VAULT_URI
URI of the Azure Key Vault containing the API credentials
Basic usage
You must provide the Vault URI (-u) in order for this application to execute.
If you choose to omit the Client ID parameter (
-k) and Client Secret parameter (-s), the default valuesfalcon-client-idandfalcon-client-secretwill be used.
Example
Perform a simple API demonstration using the credentials retrieved to list hosts by AID.
Example result
Command-line help
Command-line help is available via the -h argument.
Example source code
Source code for this example can be found here.
AES Authentication
Leverage AES/CBC to encrypt credentials for use with authentication to the CrowdStrike API.
⚠️ Please note ⚠️
Cryptographic implementation samples should not be seen as recommendations on which encryption algorithms, modes or methods to use in your environment. These examples focus only on the technical aspects of cryptographic authentication scenarios using Python 3 and are provided here to assist developers with their implementation when interacting with the FalconPy SDK.
Running the program
In order to run this demonstration, you will need access to CrowdStrike API keys with the following scopes:
Hosts
READ
Execution syntax
This demonstration was developed to leverage easy to use command-line arguments.
Command line arguments
This program accepts the following command line arguments.
-h
--help
Display command line help and exit
-t TEXT
--text TEXT
Text to encrypt or decrypt
-k KEY
--key KEY
Key to use for encryption operations
-f KEYFILE
--keyfile KEYFILE
File to save your encrypted credentials to
-g
--generate
Generate a new keyfile using a key you specify
-d
--decrypt
Decrypt the value of TEXT using the key provided in KEY.
-e
--encrypt
Encrypt the value of TEXT using the key provided in KEY.
Basic usage
This program has no required command line arguments, and will prompt you to provide parameters expected for the operation requested. For every operation, your secret key (-k) and the location of your key file (-f) can be passed to the program using command line arguments.
Example
Running without any arguments will attempt to consume a credential file and run the demo. Providing a valid encrypted credential file and the correct secret key at this point will start the procedure. This test retrieves the hostname and AID for all hosts within the tenant.
Example result
Generating a new credential file
Example result
Encrypting arbitrary text
This application can be used to encrypt arbitrary text. This operation does not interact with your credentials.
Arbitrary encryption result
Decrypting arbitrary ciphertext
This application can be used to decrypt ciphertext as long as you have the correct secret key. This operation does not interact with your credentials.
Ciphertext decryption result
Command-line help
Command-line help is available via the -h argument.
Example source code
Source code for this example can be found here.
AES File Crypt
This sample will encrypt and decrypt arbitrary files with AES/CBC using the secret key you provide.
Not exactly useful for most real world scenarios, but I had a lot of fun writing the credential encryption example above and I couldn't stop playing with the code...
Running the program
This application does not require access to the CrowdStrike API.
Execution syntax
This demonstration was developed to leverage easy to use command-line arguments.
Command line arguments
This program accepts the following command line arguments.
-h
--help
Display command line help and exit
-b BUFFER
--buffer BUFFER
Maximum buffer size before the contents in memory are written to the target file.
-c
--checksum
MD5 / SHA256 hash the source / target file and display the result.
-d
--decrypt
Decrypt from the SOURCE to the TARGET.
-e
--encrypt
Encrypt from the SOURCE to the TARGET.
-k KEY
--key KEY
Key to use for encryption and decryption operations.
-s SOURCE
--source SOURCE
Source file to encrypt or decrypt.
-t TARGET
--target TARGET
Target file for the resulting cryptographic operation.
Basic usage
You must provide a key (-k), a source (-s), a target (-t) and an operation (-d or -e) in order for this application to execute.
Example encryption
Encrypting a file can be performed by providing a key, a source and a target file. For our examples, we'll use the following plain text file, plain.txt.
plain.txt
The following command line will encrypt the contents of plain.txt to cipher.txt using the key MySuperSecretKey.
Encryption result
cipher.txt
Example decryption
Decrypting a file can be performed by providing a key, a source and a target file. For our examples, we'll use the cipher text file, cipher.txt we created above.
Encryption result
decrypted.txt
Calculating checksums
You can hash the file when you encrypt or decrypt by passing the -c argument. For encryption operations, this is performed on the source file. For decryption operations this occurs on the target file after the operation has completed.
Checksum on encryption
Checksum result on encryption
Checksum on decryption
Checksum result on decryption
Changing the buffer size
You may change the file buffer size to any value greater than or equal to 32. This alters the buffer pool size used when encrypting the file. This impacts cryptographic performance but does not alter the encryption used or the end result.
Command-line help
Command-line help is available via the -h argument.
Example source code
Source code for this example can be found here.
AWS Parameter store
This application demonstrates storing CrowdStrike API credentials within the AWS Parameter Store service, and retrieving them to access the CrowdStrike API.
Running the program
In order to run this demonstration, you will need access to CrowdStrike API keys. You will also need to set your specific AWS location
Command line arguments
This program accepts the following command line arguments.
-h
--help
Display command line help and exit
-k CLIENT_ID_PARAMETER
--client_id_parameter CLIENT_ID_PARAMETER
Name of the Key Vault Secrets parameter storing your API client ID
-s CLIENT_SECRET_PARAMETER
--client_secret_parameter CLIENT_SECRET_PARAMETER
Name of the Key Vault Secrets parameter storing your API client secret
-d
--debug
Enables debugging functionality
Basic usage
Use this command to test out the sample.
Use this command to activate debugging.
Command-line help
Command-line help is available via the -h argument.
Token Authentication
Token authentication (also referred to as legacy authentication) is the process of authenticating to a FalconPy Service Class by providing a previously assigned bearer token directly to the auth_token keyword when instantiating the Service Class. This is the original method of authentication provided by Service Classes, and while it is frequently eschewed in preference to Direct and Object Authentication, there are multiple scenarios where it is still the best option for the situation.
Token Authentication support will always be maintained within Falconpy.
⚠️ Please note ⚠️
Token Authentication creates an instance of a FalconPy Service Class that cannot reauthenticate itself as it does not have awareness of your API credentials. You will have to regenerate your bearer token before it expires and update the creds dictionary within the Service Class if you are implementing a long running process.
Running the program
This application is only a proof of concept that is intended to be reviewed as source code. Executing the program will initiate a connectivity test to several CrowdStrike APIs. Credentials used for these test are either stored in the environment (FALCON_CLIENT_ID and FALCON_CLIENT_SECRET) or requested by the application when it starts.
In order for the demonstration to test all six API service collections, you will need access to the following scopes:
CloudConnectAWS
READ
Detects
READ
Hosts
READ
IOC
READ
Incidents
READ
Intel
READ
Execution syntax
This application does not accept command line arguments.
Basic usage
This sample only supports singular execution.
Example result
Command-line help
This sample does not implement command line assistance.
Example source code
Source code for this example can be found here.
Last updated
Was this helpful?