Skip to content

Commit 59ce8ad

Browse files
authored
feat(container-pull-script): add support for falcon snapshot scanner (#250)
Closes #199 This PR introduces support for downloading/pushing the Falcon Snapshot scanner image.
1 parent 1fcdfca commit 59ce8ad

File tree

2 files changed

+42
-17
lines changed

2 files changed

+42
-17
lines changed

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ To check your version of cURL, run the following command: `curl --version`
3232
- `Sensor Download (read)`
3333
- `Kubernetes Protection (read)`
3434
- For `kpagent` only
35+
- `Snapshot Scanner Image Download (read)`
36+
- For `falcon-snapshot` only
37+
- `Snapshot (read/write)`
38+
- For `falcon-snapshot` only
3539
- If you are using Docker, make sure that Docker is running locally.
3640

3741
## Usage
@@ -49,7 +53,7 @@ Optional Flags:
4953
-c, --copy <REGISTRY/NAMESPACE> registry to copy image e.g. myregistry.com/mynamespace
5054
-v, --version <SENSOR_VERSION> specify sensor version to retrieve from the registry
5155
-p, --platform <SENSOR_PLATFORM> specify sensor platform to retrieve e.g x86_64, aarch64
52-
-t, --type <SENSOR_TYPE> specify which sensor to download [falcon-container|falcon-sensor|falcon-kac|kpagent]
56+
-t, --type <SENSOR_TYPE> specify which sensor to download [falcon-container|falcon-sensor|falcon-kac|falcon-snapshot|kpagent]
5357
Default is falcon-container.
5458
5559
--runtime use a different container runtime [docker, podman, skopeo]. Default is docker.
@@ -75,7 +79,7 @@ Help Options:
7579
| `-c`, `--copy <REGISTRY/NAMESPACE>` | `$COPY` | `None` (Optional) | Registry you want to copy the sensor image to. Example: `myregistry.com/mynamespace` |
7680
| `-v`, `--version <SENSOR_VERSION>` | `$SENSOR_VERSION` | `None` (Optional) | Specify sensor version to retrieve from the registry |
7781
| `-p`, `--platform <SENSOR_PLATFORM>` | `$SENSOR_PLATFORM` | `None` (Optional) | Specify sensor platform to retrieve from the registry |
78-
| `-t`, `--type <SENSOR_TYPE>` | `$SENSOR_TYPE` | `falcon-container` (Optional) | Specify which sensor to download [`falcon-container`, `falcon-sensor`, `falcon-kac`, `kpagent`] ([see more details below](#sensor-types)) |
82+
| `-t`, `--type <SENSOR_TYPE>` | `$SENSOR_TYPE` | `falcon-container` (Optional) | Specify which sensor to download [`falcon-container`, `falcon-sensor`, `falcon-kac`, `falcon-snapshot`, `kpagent`] ([see more details below](#sensor-types)) |
7983
| `--runtime` | `$CONTAINER_TOOL` | `docker` (Optional) | Use a different container runtime [docker, podman, skopeo]. **Default is Docker**. |
8084
| `--dump-credentials` | `$CREDS` | `False` (Optional) | Print registry credentials to stdout to copy/paste into container tools |
8185
| `--get-pull-token` | N/A | `None` | Get the pull token of the selected SENSOR_TYPE for Kubernetes. |
@@ -92,6 +96,7 @@ The following sensor types are available to download:
9296
| `falcon-sensor` | The Falcon sensor for Linux as a DaemonSet deployment |
9397
| `falcon-container` **(default)** | The Falcon Container sensor for Linux |
9498
| `falcon-kac` | The Falcon Kubernetes Admission Controller |
99+
| `falcon-snapshot` | The Falcon Snapshot scanner |
95100
| `kpagent` | The Falcon Kubernetes Protection Agent |
96101

97102
### Examples
@@ -120,6 +125,18 @@ The following example will download the latest version of the Falcon DaemonSet s
120125
--copy myregistry.com/mynamespace
121126
```
122127

128+
#### Example generating a pull token for K8s
129+
130+
The following example will generate a pull token for the Falcon Container sensor for use in Kubernetes.
131+
132+
```shell
133+
./falcon-container-sensor-pull.sh \
134+
--client-id <FALCON_CLIENT_ID> \
135+
--client-secret <FALCON_CLIENT_SECRET> \
136+
--type falcon-container \
137+
--get-pull-token
138+
```
139+
123140
#### Example dumping credentials
124141

125142
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: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Optional Flags:
1919
-c, --copy <REGISTRY/NAMESPACE> registry to copy image e.g. myregistry.com/mynamespace
2020
-v, --version <SENSOR_VERSION> specify sensor version to retrieve from the registry
2121
-p, --platform <SENSOR_PLATFORM> specify sensor platform to retrieve e.g x86_64, aarch64
22-
-t, --type <SENSOR_TYPE> specify which sensor to download [falcon-container|falcon-sensor|falcon-kac|kpagent]
22+
-t, --type <SENSOR_TYPE> specify which sensor to download [falcon-container|falcon-sensor|falcon-kac|falcon-snapshot|kpagent]
2323
Default is falcon-container.
2424
2525
--runtime use a different container runtime [docker, podman, skopeo]. Default is docker.
@@ -222,7 +222,7 @@ format_tags_to_json() {
222222
)
223223
# The output should mimic the same format as the Docker (curl) output
224224
echo "{
225-
\"name\": \"${SENSOR_TYPE}\",
225+
\"name\": \"${IMAGE_NAME}\",
226226
${tags_json}
227227
}"
228228
}
@@ -256,7 +256,7 @@ format_tags() {
256256
# Formats tags and handles sorting for KPA
257257
local all_tags=$1
258258

259-
if [ "${SENSOR_TYPE}" = "kpagent" ]; then
259+
if [ "${SENSOR_TYPE}" = "kpagent" ] || [ "${SENSOR_TYPE}" = "falcon-snapshot" ]; then
260260
echo "$all_tags" |
261261
sed -n 's/.*"tags" : \[\(.*\)\].*/\1/p' |
262262
tr -d '"' | tr ',' '\n' |
@@ -274,7 +274,7 @@ print_formatted_tags() {
274274
local formatted_tags=$1
275275

276276
# Print a JSON object with tags properly formatted
277-
printf "{\n \"name\": \"%s\",\n \"tags\": [\n" "${SENSOR_TYPE}"
277+
printf "{\n \"name\": \"%s\",\n \"tags\": [\n" "${IMAGE_NAME}"
278278
first=true
279279
echo "$formatted_tags" | while IFS= read -r tag; do
280280
if [ "$first" = true ]; then
@@ -291,7 +291,7 @@ list_tags() {
291291
all_tags=$(fetch_tags "${CONTAINER_TOOL}")
292292
formatted_tags=$(format_tags "$all_tags")
293293

294-
print_formatted_tags "$formatted_tags" "${SENSOR_TYPE}"
294+
print_formatted_tags "$formatted_tags"
295295
}
296296

297297
# shellcheck disable=SC2086
@@ -329,10 +329,10 @@ fi
329329

330330
# Check if SENSOR_TYPE is set to a valid value
331331
case "${SENSOR_TYPE}" in
332-
falcon-container | falcon-sensor | falcon-kac | kpagent) ;;
332+
falcon-container | falcon-sensor | falcon-kac | falcon-snapshot | kpagent) ;;
333333
*) die """
334334
Unrecognized sensor type: ${SENSOR_TYPE}
335-
Valid values are [falcon-container|falcon-sensor|falcon-kac|kpagent]""" ;;
335+
Valid values are [falcon-container|falcon-sensor|falcon-kac|falcon-snapshot|kpagent]""" ;;
336336
esac
337337

338338
#Check all mandatory variables set
@@ -410,27 +410,35 @@ if [ ! "$LISTTAGS" ] && [ ! "$PULLTOKEN" ]; then
410410
fi
411411

412412
ART_USERNAME="fc-$cs_falcon_cid"
413-
sensor_name="falcon-sensor"
413+
IMAGE_NAME="falcon-sensor"
414414
repository_name="release/falcon-sensor"
415+
registry_type="container-security"
415416

416417
if [ "${SENSOR_TYPE}" = "falcon-kac" ]; then
417418
# overrides for KAC
418-
sensor_name="falcon-kac"
419+
IMAGE_NAME="falcon-kac"
419420
repository_name="release/falcon-kac"
421+
elif [ "${SENSOR_TYPE}" = "falcon-snapshot" ]; then
422+
# overrides for Snapshot
423+
ART_USERNAME="fs-$cs_falcon_cid"
424+
IMAGE_NAME="cs-snapshotscanner"
425+
repository_name="release/cs-snapshotscanner"
426+
registry_type="snapshots"
420427
elif [ "${SENSOR_TYPE}" = "kpagent" ]; then
421428
# overrides for KPA
422429
ART_USERNAME="kp-$cs_falcon_cid"
423-
sensor_name="kpagent"
430+
IMAGE_NAME="kpagent"
424431
repository_name="kpagent"
432+
registry_type="kubernetes-protection"
425433
registry_opts="kubernetes_protection"
426434
fi
427435

428436
#Set Docker token using the BEARER token captured earlier
429437
if [ "${SENSOR_TYPE}" = "kpagent" ]; then
430-
raw_docker_api_token=$(curl_command "$cs_falcon_oauth_token" "https://$(cs_cloud)/kubernetes-protection/entities/integration/agent/v1?cluster_name=clustername&is_self_managed_cluster=true")
438+
raw_docker_api_token=$(curl_command "$cs_falcon_oauth_token" "https://$(cs_cloud)/$registry_type/entities/integration/agent/v1?cluster_name=clustername&is_self_managed_cluster=true")
431439
docker_api_token=$(echo "$raw_docker_api_token" | awk '/dockerAPIToken:/ {print $2}')
432440
else
433-
raw_docker_api_token=$(curl_command "$cs_falcon_oauth_token" "https://$(cs_cloud)/container-security/entities/image-registry-credentials/v1")
441+
raw_docker_api_token=$(curl_command "$cs_falcon_oauth_token" "https://$(cs_cloud)/$registry_type/entities/image-registry-credentials/v1")
434442
docker_api_token=$(echo "$raw_docker_api_token" | json_value "token")
435443
fi
436444
ART_PASSWORD=$(echo "$docker_api_token" | sed 's/ *$//g' | sed 's/^ *//g')
@@ -456,7 +464,7 @@ $raw_docker_api_token
456464
457465
Ensure the following:
458466
- Credentials are valid.
459-
- Correct API Scopes are assigned (Falcon Images Download [read], Sensor Download [read], Kubernetes Protection [read])
467+
- Correct API Scopes are assigned (Falcon Images Download [read], Sensor Download [read], Snapshot Scanner Image Download [read], Snapshot [read/write], Kubernetes Protection [read])
460468
- Cloud Security is enabled in your tenant."
461469
fi
462470

@@ -497,7 +505,7 @@ else
497505

498506
# For those that don't want to use skopeo to copy
499507
if [ -n "$COPY" ]; then
500-
"$CONTAINER_TOOL" tag "$FULLIMAGEPATH" "$COPY/$sensor_name:$LATESTSENSOR"
501-
"$CONTAINER_TOOL" push "$COPY/$sensor_name:$LATESTSENSOR"
508+
"$CONTAINER_TOOL" tag "$FULLIMAGEPATH" "$COPY/$IMAGE_NAME:$LATESTSENSOR"
509+
"$CONTAINER_TOOL" push "$COPY/$IMAGE_NAME:$LATESTSENSOR"
502510
fi
503511
fi

0 commit comments

Comments
 (0)