Skip to content

Commit

Permalink
feat(container-pull-script): Add the param to get the correct CID dep…
Browse files Browse the repository at this point in the history
…ending the agent-type (#252)

* Add the param to get the correct CID depending the agent-type

* update readme

updating readme to trigger a new check

* fixing shell format issue

* chore: remove redundant use of FALCON_CID

* docs: update description

---------

Co-authored-by: Falcon Pioupiou <[email protected]>
Co-authored-by: Carlos Matos <[email protected]>
  • Loading branch information
3 people authored Jan 26, 2024
1 parent 39e7131 commit 8af135f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
14 changes: 14 additions & 0 deletions bash/containers/falcon-container-sensor-pull/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Optional Flags:
--runtime use a different container runtime [docker, podman, skopeo]. Default is docker.
--dump-credentials print registry credentials to stdout to copy/paste into container tools.
--get-pull-token get the pull token of the selected SENSOR_TYPE for Kubernetes.
--get-cid Get the CID assigned to the API Credentials.
--list-tags list all tags available for the selected sensor
--allow-legacy-curl allow the script to run with an older version of curl
Expand All @@ -83,6 +84,7 @@ Help Options:
| `--runtime` | `$CONTAINER_TOOL` | `docker` (Optional) | Use a different container runtime [docker, podman, skopeo]. **Default is Docker**. |
| `--dump-credentials` | `$CREDS` | `False` (Optional) | Print registry credentials to stdout to copy/paste into container tools |
| `--get-pull-token` | N/A | `None` | Get the pull token of the selected SENSOR_TYPE for Kubernetes. |
| `--get-cid` | N/A | `None` | Get the CID assigned to the API Credentials. |
| `--list-tags` | `$LISTTAGS` | `False` (Optional) | List all tags available for the selected sensor |
| `--allow-legacy-curl` | `$ALLOW_LEGACY_CURL` | `False` (Optional) | Allow the script to run with an older version of cURL |
| `-h`, `--help` | N/A | `None` | Display help message |
Expand Down Expand Up @@ -137,6 +139,18 @@ The following example will generate a pull token for the Falcon Container sensor
--get-pull-token
```

#### Example getting the CID

The following example will get the CID for the Falcon Sensor configuration for kubernetes deployment.

```shell
./falcon-container-sensor-pull.sh \
--client-id <FALCON_CLIENT_ID> \
--client-secret <FALCON_CLIENT_SECRET> \
--type falcon-sensor \
--get-cid
```

#### Example dumping credentials

The following example will dump the credentials to stdout to copy/paste into container tools.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Optional Flags:
--runtime use a different container runtime [docker, podman, skopeo]. Default is docker.
--dump-credentials print registry credentials to stdout to copy/paste into container tools.
--get-pull-token Get the pull token of the selected SENSOR_TYPE for Kubernetes.
--get-cid Get the CID assigned to the API Credentials.
--list-tags list all tags available for the selected sensor type and platform(optional)
--allow-legacy-curl allow the script to run with an older version of curl
Expand Down Expand Up @@ -119,6 +120,11 @@ while [ $# != 0 ]; do
PULLTOKEN=true
fi
;;
--get-cid)
if [ -n "${1}" ]; then
GETCID=true
fi
;;
--list-tags)
if [ -n "${1}" ]; then
LISTTAGS=true
Expand Down Expand Up @@ -311,7 +317,6 @@ cs_registry="registry.crowdstrike.com"
if [ "${FALCON_CLOUD}" = "us-gov-1" ]; then
cs_registry="registry.laggar.gcw.crowdstrike.com"
fi
FALCON_CID=$(echo "${FALCON_CID}" | cut -d'-' -f1 | tr '[:upper:]' '[:lower:]')
SENSOR_VERSION=$(echo "$SENSOR_VERSION" | tr '[:upper:]' '[:lower:]')
SENSOR_PLATFORM=$(echo "$SENSOR_PLATFORM" | tr '[:upper:]' '[:lower:]')
COPY=$(echo "$COPY" | tr '[:upper:]' '[:lower:]')
Expand Down Expand Up @@ -394,16 +399,26 @@ registry_opts=$(
fi
)

cs_falcon_cid=$(
cs_falcon_cid_with_checksum=$(
if [ -n "$FALCON_CID" ]; then
echo "$FALCON_CID" | cut -d'-' -f1 | tr '[:upper:]' '[:lower:]'
echo "$FALCON_CID"
else
cs_target_cid=$(curl_command "$cs_falcon_oauth_token" "https://$(cs_cloud)/sensors/queries/installers/ccid/v1")
echo "$cs_target_cid" | tr -d '\n" ' | awk -F'[][]' '{print $2}' | cut -d'-' -f1 | tr '[:upper:]' '[:lower:]'
echo "$cs_target_cid" | tr -d '\n" ' | awk -F'[][]' '{print $2}'
fi
)
cs_falcon_cid=$(echo "$cs_falcon_cid_with_checksum" | cut -d'-' -f1 | tr '[:upper:]' '[:lower:]')

if [ "$GETCID" ]; then
if [ "${SENSOR_TYPE}" = "kpagent" ]; then
echo "${cs_falcon_cid}"
else
echo "${cs_falcon_cid_with_checksum}"
fi
exit 0
fi

if [ ! "$LISTTAGS" ] && [ ! "$PULLTOKEN" ]; then
if [ ! "$LISTTAGS" ] && [ ! "$PULLTOKEN" ] && [ ! "$GETIMAGEREPOTAG" ]; then
echo "Using the following settings:"
echo "Falcon Region: $(cs_cloud)"
echo "Falcon Registry: ${cs_registry}"
Expand Down

0 comments on commit 8af135f

Please sign in to comment.