Skip to content

Commit 8af135f

Browse files
feat(container-pull-script): Add the param to get the correct CID depending 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]>
1 parent 39e7131 commit 8af135f

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

bash/containers/falcon-container-sensor-pull/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ Optional Flags:
5959
--runtime use a different container runtime [docker, podman, skopeo]. Default is docker.
6060
--dump-credentials print registry credentials to stdout to copy/paste into container tools.
6161
--get-pull-token get the pull token of the selected SENSOR_TYPE for Kubernetes.
62+
--get-cid Get the CID assigned to the API Credentials.
6263
--list-tags list all tags available for the selected sensor
6364
--allow-legacy-curl allow the script to run with an older version of curl
6465
@@ -83,6 +84,7 @@ Help Options:
8384
| `--runtime` | `$CONTAINER_TOOL` | `docker` (Optional) | Use a different container runtime [docker, podman, skopeo]. **Default is Docker**. |
8485
| `--dump-credentials` | `$CREDS` | `False` (Optional) | Print registry credentials to stdout to copy/paste into container tools |
8586
| `--get-pull-token` | N/A | `None` | Get the pull token of the selected SENSOR_TYPE for Kubernetes. |
87+
| `--get-cid` | N/A | `None` | Get the CID assigned to the API Credentials. |
8688
| `--list-tags` | `$LISTTAGS` | `False` (Optional) | List all tags available for the selected sensor |
8789
| `--allow-legacy-curl` | `$ALLOW_LEGACY_CURL` | `False` (Optional) | Allow the script to run with an older version of cURL |
8890
| `-h`, `--help` | N/A | `None` | Display help message |
@@ -137,6 +139,18 @@ The following example will generate a pull token for the Falcon Container sensor
137139
--get-pull-token
138140
```
139141

142+
#### Example getting the CID
143+
144+
The following example will get the CID for the Falcon Sensor configuration for kubernetes deployment.
145+
146+
```shell
147+
./falcon-container-sensor-pull.sh \
148+
--client-id <FALCON_CLIENT_ID> \
149+
--client-secret <FALCON_CLIENT_SECRET> \
150+
--type falcon-sensor \
151+
--get-cid
152+
```
153+
140154
#### Example dumping credentials
141155

142156
The following example will dump the credentials to stdout to copy/paste into container tools.

bash/containers/falcon-container-sensor-pull/falcon-container-sensor-pull.sh

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Optional Flags:
2525
--runtime use a different container runtime [docker, podman, skopeo]. Default is docker.
2626
--dump-credentials print registry credentials to stdout to copy/paste into container tools.
2727
--get-pull-token Get the pull token of the selected SENSOR_TYPE for Kubernetes.
28+
--get-cid Get the CID assigned to the API Credentials.
2829
--list-tags list all tags available for the selected sensor type and platform(optional)
2930
--allow-legacy-curl allow the script to run with an older version of curl
3031
@@ -119,6 +120,11 @@ while [ $# != 0 ]; do
119120
PULLTOKEN=true
120121
fi
121122
;;
123+
--get-cid)
124+
if [ -n "${1}" ]; then
125+
GETCID=true
126+
fi
127+
;;
122128
--list-tags)
123129
if [ -n "${1}" ]; then
124130
LISTTAGS=true
@@ -311,7 +317,6 @@ cs_registry="registry.crowdstrike.com"
311317
if [ "${FALCON_CLOUD}" = "us-gov-1" ]; then
312318
cs_registry="registry.laggar.gcw.crowdstrike.com"
313319
fi
314-
FALCON_CID=$(echo "${FALCON_CID}" | cut -d'-' -f1 | tr '[:upper:]' '[:lower:]')
315320
SENSOR_VERSION=$(echo "$SENSOR_VERSION" | tr '[:upper:]' '[:lower:]')
316321
SENSOR_PLATFORM=$(echo "$SENSOR_PLATFORM" | tr '[:upper:]' '[:lower:]')
317322
COPY=$(echo "$COPY" | tr '[:upper:]' '[:lower:]')
@@ -394,16 +399,26 @@ registry_opts=$(
394399
fi
395400
)
396401

397-
cs_falcon_cid=$(
402+
cs_falcon_cid_with_checksum=$(
398403
if [ -n "$FALCON_CID" ]; then
399-
echo "$FALCON_CID" | cut -d'-' -f1 | tr '[:upper:]' '[:lower:]'
404+
echo "$FALCON_CID"
400405
else
401406
cs_target_cid=$(curl_command "$cs_falcon_oauth_token" "https://$(cs_cloud)/sensors/queries/installers/ccid/v1")
402-
echo "$cs_target_cid" | tr -d '\n" ' | awk -F'[][]' '{print $2}' | cut -d'-' -f1 | tr '[:upper:]' '[:lower:]'
407+
echo "$cs_target_cid" | tr -d '\n" ' | awk -F'[][]' '{print $2}'
403408
fi
404409
)
410+
cs_falcon_cid=$(echo "$cs_falcon_cid_with_checksum" | cut -d'-' -f1 | tr '[:upper:]' '[:lower:]')
411+
412+
if [ "$GETCID" ]; then
413+
if [ "${SENSOR_TYPE}" = "kpagent" ]; then
414+
echo "${cs_falcon_cid}"
415+
else
416+
echo "${cs_falcon_cid_with_checksum}"
417+
fi
418+
exit 0
419+
fi
405420

406-
if [ ! "$LISTTAGS" ] && [ ! "$PULLTOKEN" ]; then
421+
if [ ! "$LISTTAGS" ] && [ ! "$PULLTOKEN" ] && [ ! "$GETIMAGEREPOTAG" ]; then
407422
echo "Using the following settings:"
408423
echo "Falcon Region: $(cs_cloud)"
409424
echo "Falcon Registry: ${cs_registry}"

0 commit comments

Comments
 (0)