CrowdStrike / falcon-scripts

Scripts to streamline the deployment and use of the CrowdStrike Falcon sensor
The Unlicense
142 stars 83 forks source link

Pulling falcon-sensor using the -v flag doesn't accept the values returned by --list-tags #340

Closed penicaudm closed 1 month ago

penicaudm commented 1 month ago

When running the falcon bash pull script, the script requires [major.minor] version format for the -v flag.

This will work:

sudo ./falcon-container-sensor-pull.sh -u $FALCON_CLIENT_ID -s $FALCON_CLIENT_SECRET -t falcon-sensor -v 7.18 -c myregistry

But this doesn't:

sudo ./falcon-container-sensor-pull.sh -u $FALCON_CLIENT_ID -s $FALCON_CLIENT_SECRET -t falcon-sensor -v 7.18.0-17106-1.falcon-linux.Release.US-1

However, I'd like to use it with the following style of script:


VERSIONS=$(./falcon-container-sensor-pull.sh -u $FALCON_CLIENT_ID -s $FALCON_CLIENT_SECRET -t $image_name --list-tags | awk -v RS=" " '{print}' | grep "$SENSOR_VERSION" | grep -o "[0-9a-zA-Z_\.\-]*")

# Get the latest and n-1 versions
LATEST_VERSION=$(echo "$VERSIONS" | tail -1)

STABLE_VERSION=$(echo "$VERSIONS" | tail -2 | head -1)

This would make sense because the versions are returned like this:

{
  "name": "falcon-sensor",
  "repository": "registry.crowdstrike.com/falcon-sensor/us-1/release/falcon-sensor",
  "tags": [
     "7.17.0-17005-1.falcon-linux.Release.US-1",
     "7.18.0-17106-1.falcon-linux.Release.US-1"
  ]
}

Would it make sense for the script to accept the full version of the releases for falcon sensor for the -v parameter?

I have worked around it with this:

    local pull_version=$version
    if [ "$image_name" = "falcon-sensor" ]; then
        pull_version=$(echo "$version" | cut -d'.' -f1,2)
    fi

However I believe this would be slightly easier for automation to accept the tags of the entire versions.

Regards,

carlosmmatos commented 1 month ago

@penicaudm Thanks for opening this issue up and apologies for the delay. I've fixed the issue to address not being able to pass in the full version in #347 .

As for getting the latest and n-1, I would use jq if you have the ability to use it. It would make your ability to get certain versions easier. For example:

VERSIONS=$(./falcon-container-sensor-pull.sh -u $FALCON_CLIENT_ID -s $FALCON_CLIENT_SECRET -t $image_name --list-tags)

# Get the latest and n-1 versions
LATEST_VERSION=$(echo "$VERSIONS" | jq '.tags | .[-1]')

STABLE_VERSION=$(echo "$VERSIONS" | jq '.tags | .[-2]')