Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functionality to bash scripts to use a pre-generated auth token to authenticate with the Crowdstrike API #283

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion bash/install/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,43 @@ Ensure the following API scopes are enabled:

## Configuration

**Export the required environment variables:**
### Setting up Authentication

#### Using Client ID and Client Secret

Export the required environment variables:

```bash
export FALCON_CLIENT_ID="XXXXXXX"
export FALCON_CLIENT_SECRET="YYYYYYYYY"
```

#### Using an Access Token

You can also specify a Falcon access token if doing a batch install across multiple machines to prevent the need to call the token endpoint multiple times. If using an access token to authenticate, you ***MUST*** also provide `FALCON_CLOUD`:

```bash
export FALCON_ACCESS_TOKEN="XXXXXXXX"
export FALCON_CLOUD="us-1"
```

> [!NOTE]
> If you need to retrieve an access token, run the script with the `GET_ACCESS_TOKEN` environment variable set to `true`. The Falcon sensor will NOT be installed while this variable is set.
>
> ```bash
> export FALCON_CLIENT_ID="XXXXXXX"
> export FALCON_CLIENT_SECRET="YYYYYYYYY"
> export GET_ACCESS_TOKEN="true"
> ```
>
> The script will output the access token to the console.

#### Using AWS SSM

The installer is AWS SSM aware, if `FALCON_CLIENT_ID` and `FALCON_CLIENT_SECRET` are not provided AND the script is running on an AWS instance, the script will try to get API credentials from the SSM store of the region.

### Additional Configuration

Optional environment variables that can be exported:

```terminal
Expand All @@ -51,6 +79,8 @@ FALCON_BILLING (default: default) possible values: [default|m
FALCON_BACKEND (default: auto) possible values: [auto|bpf|kernel]
FALCON_TRACE (default: none) possible values: [none|err|warn|info|debug]
ALLOW_LEGACY_CURL (default: false)
GET_ACCESS_TOKEN (default: false) possible values: [true|false]
FALCON_REMOVE_HOST (default: true)
```

**Run the script**:
Expand Down
79 changes: 50 additions & 29 deletions bash/install/falcon-linux-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ CrowdStrike API credentials are needed to download Falcon sensor. The script rec

- FALCON_CLIENT_ID
- FALCON_CLIENT_SECRET
or
- FALCON_ACCESS_TOKEN (default: unset)
- FALCON_CLOUD (default: auto)

Optional:
- FALCON_CID (default: auto)
- FALCON_CLOUD (default: auto)
- FALCON_SENSOR_VERSION_DECREMENT (default: 0 [latest])
- FALCON_PROVISIONING_TOKEN (default: unset)
- FALCON_SENSOR_UPDATE_POLICY_NAME (default: unset)
Expand All @@ -25,6 +27,7 @@ Optional:
- FALCON_UNINSTALL (default: false)
- FALCON_INSTALL_ONLY (default: false)
- ALLOW_LEGACY_CURL (default: false)
- GET_ACCESS_TOKEN (default: false) possible values: [true|false]
EOF
}

Expand All @@ -33,6 +36,12 @@ main() {
print_usage
exit 1
fi

if [ "$GET_ACCESS_TOKEN" = "true" ]; then
echo "$cs_falcon_oauth_token"
exit 1
fi

echo -n 'Check if Falcon Sensor is running ... '
cs_sensor_is_running
echo '[ Not present ]'
Expand Down Expand Up @@ -621,25 +630,31 @@ aws_instance=$(
fi
)

cs_falcon_client_id=$(
if [ -n "$FALCON_CLIENT_ID" ]; then
echo "$FALCON_CLIENT_ID"
elif [ -n "$aws_instance" ]; then
aws_ssm_parameter "FALCON_CLIENT_ID" | json_value Value 1
else
die "Missing FALCON_CLIENT_ID environment variable. Please provide your OAuth2 API Client ID for authentication with CrowdStrike Falcon platform. Establishing and retrieving OAuth2 API credentials can be performed at https://falcon.crowdstrike.com/support/api-clients-and-keys."
fi
)
if [ -z "$FALCON_ACCESS_TOKEN" ]; then
cs_falcon_client_id=$(
if [ -n "$FALCON_CLIENT_ID" ]; then
echo "$FALCON_CLIENT_ID"
elif [ -n "$aws_instance" ]; then
aws_ssm_parameter "FALCON_CLIENT_ID" | json_value Value 1
else
die "Missing FALCON_CLIENT_ID environment variable. Please provide your OAuth2 API Client ID for authentication with CrowdStrike Falcon platform. Establishing and retrieving OAuth2 API credentials can be performed at https://falcon.crowdstrike.com/support/api-clients-and-keys."
fi
)

cs_falcon_client_secret=$(
if [ -n "$FALCON_CLIENT_SECRET" ]; then
echo "$FALCON_CLIENT_SECRET"
elif [ -n "$aws_instance" ]; then
aws_ssm_parameter "FALCON_CLIENT_SECRET" | json_value Value 1
else
die "Missing FALCON_CLIENT_SECRET environment variable. Please provide your OAuth2 API Client Secret for authentication with CrowdStrike Falcon platform. Establishing and retrieving OAuth2 API credentials can be performed at https://falcon.crowdstrike.com/support/api-clients-and-keys."
cs_falcon_client_secret=$(
if [ -n "$FALCON_CLIENT_SECRET" ]; then
echo "$FALCON_CLIENT_SECRET"
elif [ -n "$aws_instance" ]; then
aws_ssm_parameter "FALCON_CLIENT_SECRET" | json_value Value 1
else
die "Missing FALCON_CLIENT_SECRET environment variable. Please provide your OAuth2 API Client Secret for authentication with CrowdStrike Falcon platform. Establishing and retrieving OAuth2 API credentials can be performed at https://falcon.crowdstrike.com/support/api-clients-and-keys."
fi
)
else
if [ -z "$FALCON_CLOUD" ]; then
die "If setting the FALCON_ACCESS_TOKEN manually, you must also specify the FALCON_CLOUD"
fi
)
fi

cs_falcon_token=$(
if [ -n "$FALCON_PROVISIONING_TOKEN" ]; then
Expand Down Expand Up @@ -701,18 +716,22 @@ proxy=$(
)

cs_falcon_oauth_token=$(
token_result=$(echo "client_id=$cs_falcon_client_id&client_secret=$cs_falcon_client_secret" |
curl -X POST -s -x "$proxy" -L "https://$(cs_cloud)/oauth2/token" \
-H 'Content-Type: application/x-www-form-urlencoded; charset=utf-8' \
-H 'User-Agent: crowdstrike-falcon-scripts/1.3.3' \
--dump-header "${response_headers}" \
--data @-)
if [ -n "$FALCON_ACCESS_TOKEN" ]; then
token=$FALCON_ACCESS_TOKEN
else
token_result=$(echo "client_id=$cs_falcon_client_id&client_secret=$cs_falcon_client_secret" |
curl -X POST -s -x "$proxy" -L "https://$(cs_cloud)/oauth2/token" \
-H 'Content-Type: application/x-www-form-urlencoded; charset=utf-8' \
-H 'User-Agent: crowdstrike-falcon-scripts/1.3.3' \
--dump-header "${response_headers}" \
--data @-)

handle_curl_error $?
handle_curl_error $?

token=$(echo "$token_result" | json_value "access_token" | sed 's/ *$//g' | sed 's/^ *//g')
if [ -z "$token" ]; then
die "Unable to obtain CrowdStrike Falcon OAuth Token. Response was $token_result"
token=$(echo "$token_result" | json_value "access_token" | sed 's/ *$//g' | sed 's/^ *//g')
if [ -z "$token" ]; then
die "Unable to obtain CrowdStrike Falcon OAuth Token. Response was $token_result"
fi
fi
echo "$token"
)
Expand All @@ -726,7 +745,9 @@ if [ -z "${FALCON_CLOUD}" ]; then
fi
cs_falcon_cloud="${region_hint}"
else
if [ "x${FALCON_CLOUD}" != "x${region_hint}" ]; then
if [ -n "$FALCON_ACCESS_TOKEN" ]; then
:
elif [ "x${FALCON_CLOUD}" != "x${region_hint}" ]; then
echo "WARNING: FALCON_CLOUD='${FALCON_CLOUD}' environment variable specified while credentials only exists in '${region_hint}'" >&2
fi
fi
Expand Down
Loading