mirror of
https://github.com/Security-Onion-Solutions/securityonion.git
synced 2026-12-03 00:56:13 +01:00
Compare commits
32
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dfcfa580e5 | ||
|
|
4fa5b48035 | ||
|
|
ce91c5249b | ||
|
|
7f1d60d366 | ||
|
|
1ce378cc1b | ||
|
|
d6ac9d6989 | ||
|
|
df650478b2 | ||
|
|
8c899ef367 | ||
|
|
ad0c0f454b | ||
|
|
ba3282a963 | ||
|
|
462a5d9cd1 | ||
|
|
7d8edebf0e | ||
|
|
26d503cb1e | ||
|
|
e79b61f7ab | ||
|
|
5c77862e65 | ||
|
|
5c70f097dc | ||
|
|
1b4a9d2a3f | ||
|
|
9a0e88f8d2 | ||
|
|
d37241376a | ||
|
|
3d8e6d0c6e | ||
|
|
ddf168f062 | ||
|
|
693f7917ae | ||
|
|
3682e0fde6 | ||
|
|
161d0d145f | ||
|
|
c04f06af1e | ||
|
|
7b2c44e965 | ||
|
|
9895dfbe7f | ||
|
|
a21d4b5f1b | ||
|
|
f5edb1f6a4 | ||
|
|
708b872583 | ||
|
|
844ca33aed | ||
|
|
45046b946e |
No files matched your search
@@ -10,17 +10,6 @@
|
||||
# NOTE: This script depends on so-common
|
||||
IMAGEREPO=security-onion-solutions
|
||||
STATUS_CONF='/opt/so/conf/so-status/so-status.conf'
|
||||
# PIDs of the current launch_pool children, so the INT/TERM trap can kill them.
|
||||
POOL_PIDS=()
|
||||
_pool_tree=()
|
||||
IMAGE_PARALLEL_JOBS=4
|
||||
IMAGE_INSPECT_TIMEOUT=120
|
||||
IMAGE_RETRIES=5
|
||||
IMAGE_RETRY_DELAY=30
|
||||
# The preflight is a quick check, not a retry budget: one retry at most, and a
|
||||
# definite answer from the registry ends it right away.
|
||||
PREFLIGHT_ATTEMPTS=2
|
||||
PREFLIGHT_RETRY_DELAY=10
|
||||
|
||||
# shellcheck disable=SC2120
|
||||
container_list() {
|
||||
@@ -90,420 +79,6 @@ container_list() {
|
||||
fi
|
||||
}
|
||||
|
||||
registry_host() {
|
||||
if [ -z "$HOSTNAME" ]; then
|
||||
HOSTNAME=$(hostname)
|
||||
fi
|
||||
printf '%s' "$HOSTNAME"
|
||||
}
|
||||
|
||||
manifest_blob_digests() {
|
||||
jq -r '(.config.digest // empty), (.layers[]? | .digest)' "$1"
|
||||
}
|
||||
|
||||
# Registries link blobs per repo and buildx cannot mount across registries, so
|
||||
# pre-link shared layers or every image re-downloads them from ghcr.io.
|
||||
mount_shared_blobs() {
|
||||
local host=$1
|
||||
local target_repo=$2
|
||||
local manifest_file=$3
|
||||
local log_file=$4
|
||||
local -n blob_repo=$5
|
||||
local digest source_repo code
|
||||
while IFS= read -r digest; do
|
||||
if [ -z "$digest" ]; then
|
||||
continue
|
||||
fi
|
||||
source_repo="${blob_repo[$digest]:-}"
|
||||
if [ -z "$source_repo" ] || [ "$source_repo" == "$target_repo" ]; then
|
||||
continue
|
||||
fi
|
||||
code=$(curl -sk --connect-timeout 5 --max-time 30 -o /dev/null -w '%{http_code}' -X POST \
|
||||
"https://${host}:5000/v2/${IMAGEREPO}/${target_repo}/blobs/uploads/?mount=${digest}&from=${IMAGEREPO}/${source_repo}" \
|
||||
2>> "$log_file")
|
||||
if [ "$code" != "201" ]; then
|
||||
echo "Could not pre-link $digest from $source_repo into $target_repo (HTTP ${code:-error}), buildx will download it" >> "$log_file"
|
||||
fi
|
||||
done < <(manifest_blob_digests "$manifest_file")
|
||||
}
|
||||
|
||||
record_shared_blobs() {
|
||||
local target_repo=$1
|
||||
local manifest_file=$2
|
||||
local -n blob_repo=$3
|
||||
local digest
|
||||
while IFS= read -r digest; do
|
||||
if [ -n "$digest" ] && [ -z "${blob_repo[$digest]:-}" ]; then
|
||||
blob_repo["$digest"]=$target_repo
|
||||
fi
|
||||
done < <(manifest_blob_digests "$manifest_file")
|
||||
}
|
||||
|
||||
image_ref() { # image_ref <image:tag> => the full registry reference
|
||||
printf '%s/%s/%s' "$CONTAINER_REGISTRY" "$IMAGEREPO" "$1"
|
||||
}
|
||||
|
||||
# One small function per inspect: retry_cmd logs its attempts on stdout, so the
|
||||
# command's own output is redirected to its file here.
|
||||
fetch_manifest() { # fetch_manifest <ref> <out file>
|
||||
timeout "$IMAGE_INSPECT_TIMEOUT" docker buildx imagetools inspect --raw "$1" >"$2"
|
||||
}
|
||||
|
||||
# buildx's --format output is the contract with the signed .txt, so it stays in
|
||||
# one place that is easy to adjust.
|
||||
fetch_config() { # fetch_config <ref> <out file>
|
||||
timeout "$IMAGE_INSPECT_TIMEOUT" docker buildx imagetools inspect \
|
||||
--format '{{json .Image}}' "$1" >"$2"
|
||||
}
|
||||
|
||||
# The ES image follows the elasticsearch version, everything else the SO
|
||||
# version. Prints "<image>:<tag> <signature url>".
|
||||
resolve_image() { # resolve_image <image>
|
||||
local i=$1
|
||||
local image_version
|
||||
if [[ " ${IMAGES_USING_ES_VERSION[*]} " =~ [[:space:]]${i}[[:space:]] ]]; then
|
||||
# this is an es container so use version defined in elasticsearch defaults.yaml
|
||||
local UPDATE_DIR='/tmp/sogh/securityonion'
|
||||
if [ ! -d "$UPDATE_DIR" ]; then
|
||||
UPDATE_DIR=/securityonion
|
||||
fi
|
||||
local v1=0
|
||||
local v2=0
|
||||
if [[ -f "$UPDATE_DIR/salt/elasticsearch/defaults.yaml" ]]; then
|
||||
v1=$(grep -E " +version: " "$UPDATE_DIR/salt/elasticsearch/defaults.yaml" | awk -F: '{print $2}' | tr -d '[:space:]')
|
||||
fi
|
||||
if [[ -f "$DEFAULT_SALT_DIR/salt/elasticsearch/defaults.yaml" ]]; then
|
||||
v2=$(grep -E " +version: " "$DEFAULT_SALT_DIR/salt/elasticsearch/defaults.yaml" | awk -F: '{print $2}' | tr -d '[:space:]')
|
||||
fi
|
||||
image_version=$(compare_es_versions "$v1" "$v2")
|
||||
printf '%s:%s%s https://sigs.securityonion.net/es-%s/%s:%s%s.sig\n' \
|
||||
"$i" "$image_version" "$IMAGE_TAG_SUFFIX" "$image_version" "$i" "$image_version" "$IMAGE_TAG_SUFFIX"
|
||||
else
|
||||
# this is not an es container so use the so version for the version
|
||||
image_version=$VERSION
|
||||
printf '%s:%s%s https://sigs.securityonion.net/%s/%s:%s%s.sig\n' \
|
||||
"$i" "$image_version" "$IMAGE_TAG_SUFFIX" "$image_version" "$i" "$image_version" "$IMAGE_TAG_SUFFIX"
|
||||
fi
|
||||
}
|
||||
|
||||
verify_trusted_image() {
|
||||
local i=$1
|
||||
local IMAGE_LOG=$SIGNPATH/$i.verify.log
|
||||
|
||||
local image sig_url
|
||||
read -r image sig_url < <(resolve_image "$i")
|
||||
|
||||
local image_name=$i
|
||||
local manifest_file=$SIGNPATH/$image.manifest
|
||||
local config_file=$SIGNPATH/$image.config
|
||||
local REF
|
||||
REF=$(image_ref "$image")
|
||||
local VERIFIED_REF
|
||||
|
||||
local rc=0
|
||||
local digest_re='^sha256:[a-f0-9]{64}$'
|
||||
|
||||
retry_cmd "$IMAGE_RETRIES" "$IMAGE_RETRY_DELAY" fetch_manifest "$REF" "$manifest_file" >>"$IMAGE_LOG" 2>&1 || rc=$?
|
||||
if [ "$rc" -ne 0 ]; then
|
||||
echo "Could not fetch manifest for $image, please ensure connectivity to $CONTAINER_REGISTRY" >>"$IMAGE_LOG" 2>&1
|
||||
echo "Command failed with error $rc" >>"$IMAGE_LOG" 2>&1
|
||||
return 1
|
||||
fi
|
||||
if [ ! -s "$manifest_file" ] || ! jq -e . "$manifest_file" >/dev/null 2>&1; then
|
||||
echo "Unable to read the manifest for $image: empty or not JSON" >>"$IMAGE_LOG" 2>&1
|
||||
return 1
|
||||
fi
|
||||
# The sig covers these exact bytes, so an index would sign the wrong document.
|
||||
if jq -e '.manifests | type == "array"' "$manifest_file" >/dev/null 2>&1; then
|
||||
echo "$image manifest is a multi-platform index, expected a single manifest" >>"$IMAGE_LOG" 2>&1
|
||||
return 1
|
||||
fi
|
||||
|
||||
local manifest_digest
|
||||
manifest_digest=$(sha256sum "$manifest_file" | awk '{print $1}')
|
||||
local config_digest
|
||||
config_digest=$(jq -r '.config.digest // empty' "$manifest_file")
|
||||
if [ -z "$manifest_digest" ] || [ -z "$config_digest" ] || [ "$config_digest" = "null" ]; then
|
||||
echo "Unable to read the manifest for $image: no config digest" >>"$IMAGE_LOG" 2>&1
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Every digest ends up in a URL (blob fetches, blob mounts, the wave
|
||||
# planner), so one malformed digest rejects the whole manifest.
|
||||
if [[ ! $config_digest =~ $digest_re ]]; then
|
||||
echo "Unable to inspect $image: invalid config digest '$config_digest'" >>"$IMAGE_LOG" 2>&1
|
||||
return 1
|
||||
fi
|
||||
local layer_digest
|
||||
while IFS= read -r layer_digest; do
|
||||
if [ -z "$layer_digest" ]; then
|
||||
continue
|
||||
fi
|
||||
if [[ ! $layer_digest =~ $digest_re ]]; then
|
||||
echo "Unable to inspect $image: invalid layer digest '$layer_digest'" >>"$IMAGE_LOG" 2>&1
|
||||
return 1
|
||||
fi
|
||||
done < <(jq -r '.layers[]? | .digest' "$manifest_file")
|
||||
|
||||
rc=0
|
||||
# By digest, not by tag: a tag can be re-pushed between the two calls, and the
|
||||
# .txt must describe the manifest bytes that sha256sum and the sig cover.
|
||||
VERIFIED_REF="${CONTAINER_REGISTRY}/${IMAGEREPO}/${image_name}@sha256:${manifest_digest}"
|
||||
retry_cmd "$IMAGE_RETRIES" "$IMAGE_RETRY_DELAY" fetch_config "$VERIFIED_REF" "$config_file" >>"$IMAGE_LOG" 2>&1 || rc=$?
|
||||
if [ "$rc" -ne 0 ]; then
|
||||
echo "Could not fetch image config for $image, please ensure connectivity to $CONTAINER_REGISTRY" >>"$IMAGE_LOG" 2>&1
|
||||
echo "Command failed with error $rc" >>"$IMAGE_LOG" 2>&1
|
||||
return 1
|
||||
fi
|
||||
if [ ! -s "$config_file" ]; then
|
||||
echo "Unable to read the config for $image" >>"$IMAGE_LOG" 2>&1
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Get signature
|
||||
rc=0
|
||||
curl --fail --connect-timeout 10 --max-time 120 --retry 5 --retry-delay 60 -sSL \
|
||||
-A "$CURLTYPE/$CURRENTVERSION/$OS/$(uname -r)" \
|
||||
--output "$SIGNPATH/$image.sig" "$sig_url" >>"$IMAGE_LOG" 2>&1 || rc=$?
|
||||
if [ "$rc" -ne 0 ]; then
|
||||
echo "Could not pull signature file for $image, please ensure connectivity to https://sigs.securityonion.net " >>"$IMAGE_LOG" 2>&1
|
||||
echo "Command failed with error $rc" >>"$IMAGE_LOG" 2>&1
|
||||
return 1
|
||||
fi
|
||||
|
||||
# .txt layout must stay byte-identical to the old `docker inspect | jq` output
|
||||
# because the gpg signature is verified against it.
|
||||
if ! printf '%s\n' "\"${VERIFIED_REF}\"" >"$SIGNPATH/$image.txt"; then
|
||||
echo "Unable to write the signed ref line for $image" >>"$IMAGE_LOG" 2>&1
|
||||
return 1
|
||||
fi
|
||||
if ! jq ".created, .rootfs.diff_ids" "$config_file" >>"$SIGNPATH/$image.txt"; then
|
||||
echo "Unable to extract created and diff_ids for $image" >>"$IMAGE_LOG" 2>&1
|
||||
return 1
|
||||
fi
|
||||
local GPGTEST
|
||||
if ! GPGTEST=$(gpg --verify "$SIGNPATH/$image.sig" "$SIGNPATH/$image.txt" 2>&1); then
|
||||
echo "Signature verification failed for $image. Details:" >>"$IMAGE_LOG" 2>&1
|
||||
echo "$GPGTEST" >>"$IMAGE_LOG" 2>&1
|
||||
return 1
|
||||
fi
|
||||
|
||||
printf '%s\n%s\n%s\n' "$image" "$VERIFIED_REF" "$manifest_file" >"$SIGNPATH/$i.ref"
|
||||
return 0
|
||||
}
|
||||
|
||||
# retry()/run_check_net_err() eval their command string, so the argv helper is
|
||||
# used for anything that must not be re-parsed by the shell.
|
||||
retry_cmd() {
|
||||
local max_attempts=$1
|
||||
local delay=$2
|
||||
shift 2
|
||||
local attempt=1 rc=0
|
||||
while :; do
|
||||
if "$@"; then
|
||||
return 0
|
||||
else
|
||||
rc=$?
|
||||
fi
|
||||
echo "Command failed with error $rc (attempt $attempt of $max_attempts): $*"
|
||||
if [ "$attempt" -ge "$max_attempts" ]; then
|
||||
return $rc
|
||||
fi
|
||||
attempt=$((attempt + 1))
|
||||
sleep "$delay"
|
||||
done
|
||||
}
|
||||
|
||||
copy_verified_image() {
|
||||
local i=$1
|
||||
local IMAGE_LOG=$SIGNPATH/$i.copy.log
|
||||
local image VERIFIED_REF manifest_file
|
||||
{
|
||||
read -r image
|
||||
read -r VERIFIED_REF
|
||||
read -r manifest_file
|
||||
} <"$SIGNPATH/$i.ref"
|
||||
|
||||
local host
|
||||
host=$(registry_host)
|
||||
mount_shared_blobs "$host" "$i" "$manifest_file" "$IMAGE_LOG" pushed_blob_repo
|
||||
# imagetools create, not docker push: Docker 29's containerd store cannot push a
|
||||
# freshly pulled image. GODEBUG prefix keeps http2client=0 local (#16342).
|
||||
# It reads from ghcr.io, so it gets the same budget as the verify fetches.
|
||||
retry_cmd "$IMAGE_RETRIES" "$IMAGE_RETRY_DELAY" env GODEBUG="${GODEBUG:+${GODEBUG},}http2client=0" \
|
||||
docker buildx imagetools create --tag "${host}:5000/${IMAGEREPO}/${image}" "$VERIFIED_REF" \
|
||||
>>"$IMAGE_LOG" 2>&1 || {
|
||||
echo "Unable to copy $image to embedded registry" >>"$IMAGE_LOG" 2>&1
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
pull_verified_image() {
|
||||
local i=$1
|
||||
local IMAGE_LOG=$SIGNPATH/$i.pull.log
|
||||
local image VERIFIED_REF
|
||||
{
|
||||
read -r image
|
||||
read -r VERIFIED_REF
|
||||
} <"$SIGNPATH/$i.ref"
|
||||
|
||||
local host
|
||||
host=$(registry_host)
|
||||
# Pull by the digest that gpg verified, not by the mutable tag a compromised
|
||||
# grid node could have re-pushed. Keep the tag name visible to `docker images`
|
||||
# and to the salt checks that look for it.
|
||||
local digest=${VERIFIED_REF#*@}
|
||||
local digest_ref="${host}:5000/${IMAGEREPO}/${image%:*}@${digest}"
|
||||
local tag_ref="${host}:5000/${IMAGEREPO}/${image}"
|
||||
retry_cmd 3 10 docker pull "$digest_ref" >>"$IMAGE_LOG" 2>&1 || {
|
||||
echo "Unable to pull $image from embedded registry" >>"$IMAGE_LOG" 2>&1
|
||||
return 1
|
||||
}
|
||||
if ! docker tag "$digest_ref" "$tag_ref" >>"$IMAGE_LOG" 2>&1; then
|
||||
echo "Unable to tag $image" >>"$IMAGE_LOG" 2>&1
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
log_downloading() {
|
||||
echo "Downloading $1" >> "$LOG_FILE" 2>&1
|
||||
}
|
||||
|
||||
# Kill a pool job and everything it spawned: in a non-interactive shell the
|
||||
# background docker/curl children ignore SIGINT, so killing only the subshell
|
||||
# would leave them writing to $SIGNPATH. Only PIDs the pool started are walked.
|
||||
pool_collect_tree() { # pool_collect_tree <pid>; appends to _pool_tree
|
||||
local pid=$1
|
||||
local child
|
||||
_pool_tree+=("$pid")
|
||||
while IFS= read -r child; do
|
||||
if [ -n "$child" ]; then
|
||||
pool_collect_tree "$child"
|
||||
fi
|
||||
done < <(pgrep -P "$pid" 2>/dev/null)
|
||||
}
|
||||
|
||||
_pool_abort() { # _pool_abort <exit code>
|
||||
local code=$1
|
||||
local pid
|
||||
trap '' INT TERM
|
||||
_pool_tree=()
|
||||
# Skipping reaped PIDs matters: their numbers may already belong to an
|
||||
# unrelated process, whose tree would then be killed as root.
|
||||
for pid in "${POOL_PIDS[@]}"; do
|
||||
if kill -0 "$pid" 2>/dev/null; then
|
||||
pool_collect_tree "$pid"
|
||||
fi
|
||||
done
|
||||
for pid in "${_pool_tree[@]}"; do
|
||||
kill -TERM "$pid" 2>/dev/null || true
|
||||
done
|
||||
sleep 2
|
||||
for pid in "${_pool_tree[@]}"; do
|
||||
kill -KILL "$pid" 2>/dev/null || true
|
||||
done
|
||||
exit "$code"
|
||||
}
|
||||
|
||||
# Fail fast: once a finished job of this pool failed, no new job is launched, so
|
||||
# an unreachable registry costs one round of retries instead of one per image.
|
||||
pool_failed() { # pool_failed <phase> <image>...
|
||||
local phase=$1
|
||||
shift
|
||||
local img rc
|
||||
for img in "$@"; do
|
||||
# No .rc yet means the job is still running, so it is not a failure.
|
||||
if rc=$(cat "$SIGNPATH/$img.$phase.rc" 2>/dev/null) && [ "$rc" != "0" ]; then
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
# Append one phase's per-image logs, then name what failed or was skipped.
|
||||
pool_collect() { # pool_collect <phase> <image>...; non-zero if any did not pass
|
||||
local phase=$1
|
||||
shift
|
||||
local img failed=0
|
||||
local -a bad=() skipped=()
|
||||
for img in "$@"; do
|
||||
cat "$SIGNPATH/$img.$phase.log" >> "$LOG_FILE" 2>/dev/null
|
||||
if [ ! -f "$SIGNPATH/$img.$phase.rc" ]; then
|
||||
skipped+=("$img")
|
||||
failed=1
|
||||
elif [ "$(cat "$SIGNPATH/$img.$phase.rc" 2>/dev/null)" != "0" ]; then
|
||||
bad+=("$img")
|
||||
failed=1
|
||||
fi
|
||||
done
|
||||
if [ "$failed" -ne 0 ]; then
|
||||
echo "$phase failed: ${bad[*]:-none}; skipped: ${skipped[*]:-none}" >> "$LOG_FILE" 2>&1
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
launch_pool() {
|
||||
local func=$1
|
||||
local phase=$2
|
||||
local jobs=$3
|
||||
local hook=$4
|
||||
shift 4
|
||||
local -a active=() still=() launched=()
|
||||
local img pid rc
|
||||
local stop=0
|
||||
POOL_PIDS=()
|
||||
local saved_int saved_term
|
||||
saved_int=$(trap -p INT)
|
||||
saved_term=$(trap -p TERM)
|
||||
trap '_pool_abort 130' INT
|
||||
trap '_pool_abort 143' TERM
|
||||
for img in "$@"; do
|
||||
if [ "$stop" -ne 0 ]; then
|
||||
# No .rc is written, so the caller counts this image as failed too.
|
||||
echo "Skipped $img: an earlier image failed" >>"$SIGNPATH/$img.$phase.log" 2>&1
|
||||
continue
|
||||
fi
|
||||
if [ -n "$hook" ]; then
|
||||
"$hook" "$img"
|
||||
fi
|
||||
(
|
||||
("$func" "$img") >>"$SIGNPATH/$img.$phase.log" 2>&1
|
||||
rc=$?
|
||||
# Write then rename: a truncated .rc reads as a failure to pool_failed.
|
||||
echo "$rc" >"$SIGNPATH/$img.$phase.rc.tmp"
|
||||
mv "$SIGNPATH/$img.$phase.rc.tmp" "$SIGNPATH/$img.$phase.rc"
|
||||
) &
|
||||
pid=$!
|
||||
POOL_PIDS+=("$pid")
|
||||
active+=("$pid")
|
||||
launched+=("$img")
|
||||
while [ ${#active[@]} -ge "$jobs" ]; do
|
||||
wait -n "${active[@]}" 2>/dev/null || true
|
||||
still=()
|
||||
for pid in "${active[@]}"; do
|
||||
if kill -0 "$pid" 2>/dev/null; then
|
||||
still+=("$pid")
|
||||
fi
|
||||
done
|
||||
active=("${still[@]}")
|
||||
if [ "$stop" -eq 0 ] && pool_failed "$phase" "${launched[@]}"; then
|
||||
stop=1
|
||||
fi
|
||||
done
|
||||
done
|
||||
# Only wait on PIDs started here: soup may run its own background jobs in this
|
||||
# shell (e.g. the grid highstate), and a bare `wait` would block on those.
|
||||
if [ ${#POOL_PIDS[@]} -gt 0 ]; then
|
||||
wait "${POOL_PIDS[@]}" 2>/dev/null || true
|
||||
fi
|
||||
# Restore whatever the caller had; soup installs its own EXIT/ERR handlers.
|
||||
eval "${saved_int:-trap - INT}"
|
||||
eval "${saved_term:-trap - TERM}"
|
||||
}
|
||||
|
||||
update_docker_containers() {
|
||||
local CURLTYPE=$1
|
||||
local IMAGE_TAG_SUFFIX=$2
|
||||
@@ -555,117 +130,91 @@ update_docker_containers() {
|
||||
grep -q "so-logscan" "$STATUS_CONF" && TRUSTED_CONTAINERS+=("so-logscan")
|
||||
fi
|
||||
|
||||
local -A pushed_blob_repo=()
|
||||
# Download the containers from the interwebs
|
||||
for i in "${TRUSTED_CONTAINERS[@]}"
|
||||
do
|
||||
if [ -z "$PROGRESS_CALLBACK" ]; then
|
||||
echo "Downloading $i" >> "$LOG_FILE" 2>&1
|
||||
else
|
||||
$PROGRESS_CALLBACK $i
|
||||
fi
|
||||
|
||||
local jobs=$IMAGE_PARALLEL_JOBS
|
||||
if [[ " ${IMAGES_USING_ES_VERSION[*]} " =~ [[:space:]]${i}[[:space:]] ]]; then
|
||||
# this is an es container so use version defined in elasticsearch defaults.yaml
|
||||
local UPDATE_DIR='/tmp/sogh/securityonion'
|
||||
if [ ! -d "$UPDATE_DIR" ]; then
|
||||
UPDATE_DIR=/securityonion
|
||||
fi
|
||||
local v1=0
|
||||
local v2=0
|
||||
if [[ -f "$UPDATE_DIR/salt/elasticsearch/defaults.yaml" ]]; then
|
||||
v1=$(egrep " +version: " "$UPDATE_DIR/salt/elasticsearch/defaults.yaml" | awk -F: '{print $2}' | tr -d '[:space:]')
|
||||
fi
|
||||
if [[ -f "$DEFAULT_SALT_DIR/salt/elasticsearch/defaults.yaml" ]]; then
|
||||
v2=$(egrep " +version: " "$DEFAULT_SALT_DIR/salt/elasticsearch/defaults.yaml" | awk -F: '{print $2}' | tr -d '[:space:]')
|
||||
fi
|
||||
local highest_es_version=$(compare_es_versions "$v1" "$v2")
|
||||
local image=$i:$highest_es_version$IMAGE_TAG_SUFFIX
|
||||
local sig_url=https://sigs.securityonion.net/es-$highest_es_version/$image.sig
|
||||
else
|
||||
# this is not an es container so use the so version for the version
|
||||
local image=$i:$VERSION$IMAGE_TAG_SUFFIX
|
||||
local sig_url=https://sigs.securityonion.net/$VERSION/$image.sig
|
||||
fi
|
||||
# Pull down the trusted docker image
|
||||
run_check_net_err \
|
||||
"docker pull $CONTAINER_REGISTRY/$IMAGEREPO/$image" \
|
||||
"Could not pull $image, please ensure connectivity to $CONTAINER_REGISTRY" >> "$LOG_FILE" 2>&1
|
||||
|
||||
# Nothing is copied or pulled unless every image verified (a bad signature
|
||||
# publishes nothing). The hook runs in the parent: it mutates caller globals.
|
||||
local progress_hook
|
||||
if [ -z "$PROGRESS_CALLBACK" ]; then
|
||||
progress_hook=log_downloading
|
||||
else
|
||||
progress_hook=$PROGRESS_CALLBACK
|
||||
fi
|
||||
|
||||
# One preflight before the pool, so every verify job does not spend the long
|
||||
# retry budget in parallel. It is a quick check: a definite answer from the
|
||||
# registry ends it at once, and only an unclear error gets one more try.
|
||||
# Upstream registry, not :5000. --foreground keeps it in this shell's process
|
||||
# group, so Ctrl-C reaches it before launch_pool installs its own trap.
|
||||
if [ ${#TRUSTED_CONTAINERS[@]} -gt 0 ]; then
|
||||
local preflight_image preflight_ref preflight_out
|
||||
local attempt=1 preflight_ok=0 preflight_kind=transient
|
||||
read -r preflight_image _ < <(resolve_image "${TRUSTED_CONTAINERS[0]}")
|
||||
preflight_ref=$(image_ref "$preflight_image")
|
||||
while [ "$attempt" -le "$PREFLIGHT_ATTEMPTS" ]; do
|
||||
if preflight_out=$(timeout --foreground "$IMAGE_INSPECT_TIMEOUT" \
|
||||
docker buildx imagetools inspect --raw "$preflight_ref" 2>&1); then
|
||||
preflight_ok=1
|
||||
break
|
||||
fi
|
||||
# A registry answer never changes on a retry; anything else might.
|
||||
case "$preflight_out" in
|
||||
*"not found"*|*"manifest unknown"*) preflight_kind=notfound ;;
|
||||
*denied*|*unauthorized*) preflight_kind=denied ;;
|
||||
esac
|
||||
if [ "$preflight_kind" != transient ]; then
|
||||
break
|
||||
fi
|
||||
attempt=$((attempt + 1))
|
||||
if [ "$attempt" -le "$PREFLIGHT_ATTEMPTS" ]; then
|
||||
sleep "$PREFLIGHT_RETRY_DELAY"
|
||||
fi
|
||||
done
|
||||
if [ "$preflight_ok" -ne 1 ]; then
|
||||
echo "Could not inspect $preflight_ref on $CONTAINER_REGISTRY" >>"$LOG_FILE" 2>&1
|
||||
case "$preflight_kind" in
|
||||
notfound) echo "The image or tag for $preflight_image was not found" >>"$LOG_FILE" 2>&1 ;;
|
||||
denied) echo "Access to $preflight_ref was denied by $CONTAINER_REGISTRY" >>"$LOG_FILE" 2>&1 ;;
|
||||
*) echo "Check connectivity to $CONTAINER_REGISTRY or the proxy" >>"$LOG_FILE" 2>&1 ;;
|
||||
esac
|
||||
echo "$preflight_out" >>"$LOG_FILE" 2>&1
|
||||
# Get signature
|
||||
run_check_net_err \
|
||||
"curl --retry 5 --retry-delay 60 -A '$CURLTYPE/$CURRENTVERSION/$OS/$(uname -r)' $sig_url --output $SIGNPATH/$image.sig" \
|
||||
"Could not pull signature file for $image, please ensure connectivity to https://sigs.securityonion.net " \
|
||||
noretry >> "$LOG_FILE" 2>&1
|
||||
# Dump our hash values
|
||||
DOCKERINSPECT=$(docker inspect $CONTAINER_REGISTRY/$IMAGEREPO/$image)
|
||||
|
||||
echo "$DOCKERINSPECT" | jq ".[0].RepoDigests[] | select(. | contains(\"$CONTAINER_REGISTRY\"))" > $SIGNPATH/$image.txt
|
||||
echo "$DOCKERINSPECT" | jq ".[0].Created, .[0].RootFS.Layers" >> $SIGNPATH/$image.txt
|
||||
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo "Unable to inspect $image" >> "$LOG_FILE" 2>&1
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
launch_pool verify_trusted_image verify "$jobs" "$progress_hook" "${TRUSTED_CONTAINERS[@]}"
|
||||
|
||||
pool_collect verify "${TRUSTED_CONTAINERS[@]}" || exit 1
|
||||
|
||||
# Verify only from here: no copy and no local pull.
|
||||
if [[ -n "$SKIP_TAGPUSH" ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
local -A ref_manifest=()
|
||||
for i in "${TRUSTED_CONTAINERS[@]}"; do
|
||||
{ read -r _; read -r _; read -r ref_manifest["$i"]; } < "$SIGNPATH/$i.ref"
|
||||
done
|
||||
|
||||
# Copy in waves: a wave's images share no unstored blob, so each layer is
|
||||
# downloaded once. The parent must record the blob map (subshells can't).
|
||||
local -a remaining=("${TRUSTED_CONTAINERS[@]}")
|
||||
local wave_no=0
|
||||
while [ ${#remaining[@]} -gt 0 ]; do
|
||||
wave_no=$((wave_no + 1))
|
||||
local -a wave=() deferred=()
|
||||
local -A claimed=()
|
||||
local img digest conflict
|
||||
for img in "${remaining[@]}"; do
|
||||
conflict=0
|
||||
while IFS= read -r digest; do
|
||||
[ -z "$digest" ] && continue
|
||||
[ -n "${pushed_blob_repo[$digest]:-}" ] && continue
|
||||
if [ -n "${claimed[$digest]:-}" ]; then
|
||||
conflict=1
|
||||
break
|
||||
GPGTEST=$(gpg --verify $SIGNPATH/$image.sig $SIGNPATH/$image.txt 2>&1)
|
||||
if [[ $? -eq 0 ]]; then
|
||||
if [[ -z "$SKIP_TAGPUSH" ]]; then
|
||||
# Tag it with the new registry destination
|
||||
if [ -z "$HOSTNAME" ]; then
|
||||
HOSTNAME=$(hostname)
|
||||
fi
|
||||
done < <(manifest_blob_digests "${ref_manifest[$img]}")
|
||||
if [ "$conflict" -eq 0 ]; then
|
||||
wave+=("$img")
|
||||
while IFS= read -r digest; do
|
||||
[ -n "$digest" ] && claimed["$digest"]=1
|
||||
done < <(manifest_blob_digests "${ref_manifest[$img]}")
|
||||
else
|
||||
deferred+=("$img")
|
||||
docker tag $CONTAINER_REGISTRY/$IMAGEREPO/$image $HOSTNAME:5000/$IMAGEREPO/$image >> "$LOG_FILE" 2>&1 || {
|
||||
echo "Unable to tag $image" >> "$LOG_FILE" 2>&1
|
||||
exit 1
|
||||
}
|
||||
# Push to the embedded registry via a registry-to-registry copy. Avoids
|
||||
# `docker push`, which on Docker 29.x with the containerd image store
|
||||
# represents freshly-pulled images as an index whose layer content
|
||||
# isn't reachable through the push path. The local `docker tag` above
|
||||
# is preserved so so-image-pull's `:5000` existence check still works.
|
||||
# Pin to the digest already gpg-verified above so we copy exactly the
|
||||
# bytes we approved.
|
||||
local VERIFIED_REF
|
||||
VERIFIED_REF=$(echo "$DOCKERINSPECT" | jq -r ".[0].RepoDigests[] | select(. | contains(\"$CONTAINER_REGISTRY\"))" | head -n 1)
|
||||
if [ -z "$VERIFIED_REF" ] || [ "$VERIFIED_REF" = "null" ]; then
|
||||
echo "Unable to determine verified digest for $image" >> "$LOG_FILE" 2>&1
|
||||
exit 1
|
||||
fi
|
||||
docker buildx imagetools create --tag $HOSTNAME:5000/$IMAGEREPO/$image "$VERIFIED_REF" >> "$LOG_FILE" 2>&1 || {
|
||||
echo "Unable to copy $image to embedded registry" >> "$LOG_FILE" 2>&1
|
||||
exit 1
|
||||
}
|
||||
fi
|
||||
done
|
||||
if [ ${#wave[@]} -eq 0 ]; then
|
||||
wave=("${remaining[0]}")
|
||||
deferred=("${remaining[@]:1}")
|
||||
else
|
||||
echo "There is a problem downloading the $image image. Details: " >> "$LOG_FILE" 2>&1
|
||||
echo "" >> "$LOG_FILE" 2>&1
|
||||
echo $GPGTEST >> "$LOG_FILE" 2>&1
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Copying images (batch $wave_no): ${wave[*]}" >> "$LOG_FILE" 2>&1
|
||||
launch_pool copy_verified_image copy "$jobs" "" "${wave[@]}"
|
||||
|
||||
pool_collect copy "${wave[@]}" || exit 1
|
||||
for img in "${wave[@]}"; do
|
||||
record_shared_blobs "$img" "${ref_manifest[$img]}" pushed_blob_repo
|
||||
done
|
||||
remaining=("${deferred[@]}")
|
||||
done
|
||||
|
||||
launch_pool pull_verified_image pull "$jobs" "" "${TRUSTED_CONTAINERS[@]}"
|
||||
pool_collect pull "${TRUSTED_CONTAINERS[@]}" || exit 1
|
||||
}
|
||||
@@ -140,7 +140,23 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"dynamic_templates": [
|
||||
{
|
||||
"event_data_scalars_as_keyword": {
|
||||
"path_match": "event_data.*",
|
||||
"match_mapping_type": [
|
||||
"long",
|
||||
"double",
|
||||
"boolean"
|
||||
],
|
||||
"mapping": {
|
||||
"type": "keyword",
|
||||
"ignore_above": 1024
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"_meta": {
|
||||
|
||||
@@ -8,10 +8,10 @@ influxdb:
|
||||
flux-log-enabled: false
|
||||
hardening-enabled: true
|
||||
http-bind-address: :8086
|
||||
http-idle-timeout: 0
|
||||
http-idle-timeout: 0s
|
||||
http-read-header-timeout: 10s
|
||||
http-read-timeout: 0
|
||||
http-write-timeout: 0
|
||||
http-read-timeout: 0s
|
||||
http-write-timeout: 0s
|
||||
influxql-max-select-buckets: 0
|
||||
influxql-max-select-point: 0
|
||||
influxql-max-select-series: 0
|
||||
|
||||
@@ -42,17 +42,17 @@ influxdb:
|
||||
advanced: True
|
||||
helpLink: influxdb
|
||||
http-idle-timeout:
|
||||
description: Keep-alive timeout while a connection waits for new requests. A value of 0 is the same as no timeout enforced.
|
||||
description: Keep-alive timeout while a connection waits for new requests. A value of 0s is the same as no timeout enforced.
|
||||
global: True
|
||||
advanced: True
|
||||
helpLink: influxdb
|
||||
http-read-header-timeout:
|
||||
description: The duration to wait for a request header before closing the connection. A value of 0 is the same as no timeout enforced.
|
||||
description: The duration to wait for a request header before closing the connection. A value of 0s is the same as no timeout enforced.
|
||||
global: True
|
||||
advanced: True
|
||||
helpLink: influxdb
|
||||
http-read-timeout:
|
||||
description: The duration to wait for the request to be fully read before closing the connection. A value of 0 is the same as no timeout enforced.
|
||||
description: The duration to wait for the request to be fully read before closing the connection. A value of 0s is the same as no timeout enforced.
|
||||
global: True
|
||||
advanced: True
|
||||
helpLink: influxdb
|
||||
|
||||
@@ -128,7 +128,7 @@ lookup_org_id_with_wait() {
|
||||
wait=10
|
||||
while [[ $attempts -lt $max_attempts ]]; do
|
||||
response=$(request orgs?org=Security+Onion)
|
||||
oid=$(echo "$response" | jq -r ".orgs[] | select(.name == \"Security Onion\").id")
|
||||
oid=$(echo "$response" | jq -r ".orgs[]? | select(.name == \"Security Onion\").id")
|
||||
if [[ -z $oid ]]; then
|
||||
attempts=$((attempts+1))
|
||||
log "Server does not appear to be running or fully initialized - will try again in $wait seconds ($attempts / $max_attempts)"
|
||||
|
||||
@@ -1241,6 +1241,8 @@ remove_localrules_portgroup() {
|
||||
post_to_3.5.0() {
|
||||
telegraf_repair
|
||||
|
||||
rollover_index "logs-detections.alerts-so"
|
||||
|
||||
set_postversion 3.5.0
|
||||
}
|
||||
### 3.5.0 End ###
|
||||
|
||||
@@ -18,7 +18,7 @@ include:
|
||||
# Install the registry container
|
||||
so-dockerregistry:
|
||||
docker_container.running:
|
||||
- image: ghcr.io/security-onion-solutions/registry:3.1.1
|
||||
- image: ghcr.io/security-onion-solutions/registry:3.1.2
|
||||
# Intentionally `always`-- registry is critical and must
|
||||
# come back up even if it was manually stopped.
|
||||
- restart_policy: always
|
||||
|
||||
@@ -1638,6 +1638,12 @@ soc:
|
||||
- "user.effective.name"
|
||||
- "weird.name"
|
||||
- "tags"
|
||||
queryNotifications:
|
||||
defaultLimit: 10
|
||||
maxLimit: 50
|
||||
summaryMaxLength: 1000
|
||||
fieldValueMaxLength: 200
|
||||
maxEntries: 25
|
||||
onionconfig:
|
||||
saltstackDir: /opt/so/saltstack
|
||||
bypassEnabled: false
|
||||
@@ -2551,6 +2557,61 @@ soc:
|
||||
grid:
|
||||
maxUploadSize: 26214400
|
||||
staleMetricsMs: 120000
|
||||
recommendedAlarms:
|
||||
- name: Root Disk Usage
|
||||
metric: disk
|
||||
metricKey: disk_used_root
|
||||
operator: gt
|
||||
threshold: '95'
|
||||
durationSeconds: 300
|
||||
severity: critical
|
||||
clearedSeverity: info
|
||||
enabled: true
|
||||
- name: NSM Disk Usage
|
||||
metric: disk
|
||||
metricKey: disk_used_nsm
|
||||
operator: gt
|
||||
threshold: '95'
|
||||
durationSeconds: 300
|
||||
severity: critical
|
||||
clearedSeverity: info
|
||||
enabled: true
|
||||
- name: Low PCAP Retention
|
||||
metric: pcap_retention
|
||||
metricKey: pcap_retention
|
||||
operator: lt
|
||||
threshold: '1'
|
||||
durationSeconds: 300
|
||||
severity: critical
|
||||
clearedSeverity: info
|
||||
enabled: true
|
||||
- name: Suricata Packet Loss
|
||||
metric: loss
|
||||
metricKey: suricata_loss
|
||||
operator: gt
|
||||
threshold: '5'
|
||||
durationSeconds: 300
|
||||
severity: critical
|
||||
clearedSeverity: info
|
||||
enabled: true
|
||||
- name: Zeek Packet Loss
|
||||
metric: loss
|
||||
metricKey: zeek_loss
|
||||
operator: gt
|
||||
threshold: '5'
|
||||
durationSeconds: 300
|
||||
severity: critical
|
||||
clearedSeverity: info
|
||||
enabled: true
|
||||
- name: Low Monitor Traffic
|
||||
metric: net
|
||||
metricKey: traffic_mon_in
|
||||
operator: lt
|
||||
threshold: '5'
|
||||
durationSeconds: 300
|
||||
severity: critical
|
||||
clearedSeverity: info
|
||||
enabled: true
|
||||
cases:
|
||||
advanced: false
|
||||
aggregationActionsEnabled: false
|
||||
|
||||
@@ -1112,6 +1112,32 @@ soc:
|
||||
description: A whitelist of fields to return when OnionAI uses the query_events tool. All other fields are removed. One field per line.
|
||||
global: True
|
||||
multiline: True
|
||||
queryNotifications:
|
||||
defaultLimit:
|
||||
description: Number of notifications Onion AI reads with the query_notifications tool when it doesn't ask for a specific number. Must be greater than 0. Values above maxLimit use maxLimit.
|
||||
global: True
|
||||
advanced: True
|
||||
forcedType: int
|
||||
maxLimit:
|
||||
description: Maximum number of notifications Onion AI may read with one query_notifications call. Must be greater than 0. Higher values put more notification text into the model's context.
|
||||
global: True
|
||||
advanced: True
|
||||
forcedType: int
|
||||
summaryMaxLength:
|
||||
description: Maximum number of characters of each notification summary that query_notifications returns to Onion AI. Must be greater than 0. Longer summaries are shortened.
|
||||
global: True
|
||||
advanced: True
|
||||
forcedType: int
|
||||
fieldValueMaxLength:
|
||||
description: Maximum number of characters of each notification field value that query_notifications returns to Onion AI. Must be greater than 0. Longer values are shortened. Link values are never shortened.
|
||||
global: True
|
||||
advanced: True
|
||||
forcedType: int
|
||||
maxEntries:
|
||||
description: Maximum number of fields, of links, and of attachment names, each counted separately, per notification that query_notifications returns to Onion AI. Must be greater than 0. The result tells Onion AI how many were left out.
|
||||
global: True
|
||||
advanced: True
|
||||
forcedType: int
|
||||
client:
|
||||
assistant:
|
||||
enabled:
|
||||
@@ -1317,6 +1343,69 @@ soc:
|
||||
staleMetricsMs:
|
||||
description: The age in milliseconds of node metrics when they are considered stale. Stale metrics have a faded appearance on the Grid screen.
|
||||
global: True
|
||||
recommendedAlarms:
|
||||
description: Recommended alarms offered on the Grid page's Alarms tab and Options dialog.
|
||||
global: True
|
||||
advanced: True
|
||||
forcedType: "[]{}"
|
||||
syntax: json
|
||||
helpLink: grid
|
||||
uiElements:
|
||||
- field: name
|
||||
label: Name
|
||||
required: True
|
||||
- field: metric
|
||||
label: Metric
|
||||
required: True
|
||||
- field: metricKey
|
||||
label: Metric Key
|
||||
required: False
|
||||
- field: operator
|
||||
label: Operator
|
||||
required: True
|
||||
options:
|
||||
- gt
|
||||
- gte
|
||||
- lt
|
||||
- lte
|
||||
- eq
|
||||
- ne
|
||||
- contains
|
||||
- field: threshold
|
||||
label: Threshold
|
||||
required: True
|
||||
forcedType: string
|
||||
- field: durationSeconds
|
||||
label: Duration Seconds
|
||||
required: False
|
||||
forcedType: int
|
||||
- field: severity
|
||||
label: Severity
|
||||
required: True
|
||||
options:
|
||||
- critical
|
||||
- high
|
||||
- medium
|
||||
- low
|
||||
- info
|
||||
- field: clearedSeverity
|
||||
label: Cleared Severity
|
||||
required: False
|
||||
options:
|
||||
- none
|
||||
- critical
|
||||
- high
|
||||
- medium
|
||||
- low
|
||||
- info
|
||||
- field: enabled
|
||||
label: Enabled
|
||||
required: False
|
||||
forcedType: bool
|
||||
- field: note
|
||||
label: Note
|
||||
required: False
|
||||
multiline: True
|
||||
case:
|
||||
analyzerNodeId:
|
||||
description: The node ID on which analyzers will be executed.
|
||||
|
||||
@@ -24,6 +24,8 @@ so-telegraf:
|
||||
- environment:
|
||||
- HOST_ETC=/host/etc
|
||||
- HOST_SYS=/host/sys
|
||||
- HOST_PROC=/host/proc
|
||||
- HOST_PROC_MOUNTINFO=/proc/1
|
||||
- HOST_MOUNT_PREFIX=/host
|
||||
- GODEBUG=x509ignoreCN=0
|
||||
{% if DOCKERMERGED.containers['so-telegraf'].extra_env %}
|
||||
|
||||
Reference in new issue
Block a user