mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-30 04:06:34 +09:00
The default flavor pinned bare image tags, which are the system variant
on Debian bullseye. Upstream stopped building that variant, so the minors
that fix CVE-2026-116331 (18.7, 17.12, 16.16, 15.20, 14.25) are published
for bookworm and trixie only. The CVE is a type confusion in the min/max
aggregate optimisation that lets a role able to create objects run code
as the operating system user of the server, and tenants hold such roles.
Pin the patched minors on standard-trixie, and move the postgis flavor to
the same minors. The standard variant, because backups go through the
barman-cloud plugin and need none of the barman binaries the system
variant adds. trixie, because the postgis flavor is on it already, so
both image families share one Debian release. PostgreSQL 13 has no
patched release: it keeps 13.22 and moves to trixie with the rest.
For a running default-flavor cluster this changes the Debian release under
the data directory. The init Job rebuilds the indexes that depend on a
collation whose library version changed.
Assisted-by: LLM
Signed-off-by: Andrey Kolkov <androndo@gmail.com>
(cherry picked from commit b40be51a6b)
Signed-off-by: Myasnikov Daniil <myasnikovdaniil2001@gmail.com>
171 lines
6.1 KiB
Bash
Executable File
171 lines
6.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -o errexit
|
|
set -o nounset
|
|
set -o pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
POSTGRES_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
|
|
VALUES_FILE="${POSTGRES_DIR}/values.yaml"
|
|
VERSIONS_FILE="${POSTGRES_DIR}/files/versions.yaml"
|
|
POSTGIS_VERSIONS_FILE="${POSTGRES_DIR}/files/postgis-versions.yaml"
|
|
|
|
# Get supported major versions from GitHub README
|
|
echo "Fetching supported major versions from GitHub..."
|
|
SUPPORTED_MAJOR_VERSIONS=$(curl -sSL 'https://raw.githubusercontent.com/cloudnative-pg/postgres-containers/refs/heads/main/README.md' | sed -n '/# CNPG PostgreSQL Container Images/,/#/p' | awk -F' +| +' '$4 ~ /[0-9]+\-[0-9]+\-[0-9]+/ && $6 ~ /[0-9]+\-[0-9]+\-[0-9]+/ {print $2}' | sort -u | xargs)
|
|
|
|
if [ -z "$SUPPORTED_MAJOR_VERSIONS" ]; then
|
|
echo "Error: Could not fetch supported major versions" >&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "Supported major versions: $SUPPORTED_MAJOR_VERSIONS"
|
|
|
|
# Check if skopeo is installed
|
|
if ! command -v skopeo &> /dev/null; then
|
|
echo "Error: skopeo is not installed. Please install skopeo and try again." >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Check if jq is installed
|
|
if ! command -v jq &> /dev/null; then
|
|
echo "Error: jq is not installed. Please install jq and try again." >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Get available image tags. Only standard-trixie builds count: the chart
|
|
# appends that suffix to the minor it reads from versions.yaml.
|
|
echo "Fetching available image tags from registry..."
|
|
AVAILABLE_TAGS=$(skopeo list-tags docker://ghcr.io/cloudnative-pg/postgresql | jq -r '.Tags[] | select(test("^[0-9]+\\.[0-9]+-standard-trixie$")) | sub("-standard-trixie$"; "")' | sort -V)
|
|
|
|
if [ -z "$AVAILABLE_TAGS" ]; then
|
|
echo "Error: Could not fetch available image tags" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Build versions map: major version -> latest minor version
|
|
declare -A VERSION_MAP
|
|
MAJOR_VERSIONS=()
|
|
|
|
for major_version in $SUPPORTED_MAJOR_VERSIONS; do
|
|
# Extract major version number (e.g., "18" from "18.1")
|
|
major_num=$(echo "$major_version" | cut -d. -f1)
|
|
|
|
# Find all tags that match this major version
|
|
matching_tags=$(echo "$AVAILABLE_TAGS" | grep "^${major_num}\\.")
|
|
|
|
if [ -n "$matching_tags" ]; then
|
|
# Get the latest minor version for this major version
|
|
latest_tag=$(echo "$matching_tags" | tail -n1)
|
|
VERSION_MAP["v${major_num}"]="v${latest_tag}"
|
|
MAJOR_VERSIONS+=("v${major_num}")
|
|
echo "Found version: v${major_num} -> v${latest_tag}"
|
|
fi
|
|
done
|
|
|
|
if [ ${#MAJOR_VERSIONS[@]} -eq 0 ]; then
|
|
echo "Error: No matching versions found" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Sort major versions in descending order (newest first)
|
|
IFS=$'\n' MAJOR_VERSIONS=($(printf '%s\n' "${MAJOR_VERSIONS[@]}" | sort -V -r))
|
|
unset IFS
|
|
|
|
echo "Major versions to add: ${MAJOR_VERSIONS[*]}"
|
|
|
|
# The postgis flavor must stay on the same PostgreSQL minor as the default
|
|
# flavor, so each major is pinned to the newest postgis build of the minor
|
|
# chosen above. standard-trixie: backups go through the barman-cloud plugin,
|
|
# so the operand does not need the deprecated system variant. Postgis images
|
|
# are built after the PostgreSQL ones, so a fresh minor can lack one for a
|
|
# while: stop before touching any map rather than drop that major from the
|
|
# postgis flavor, and rerun once the image is published.
|
|
echo "Fetching available postgis image tags from registry..."
|
|
POSTGIS_TAGS=$(skopeo list-tags docker://ghcr.io/cloudnative-pg/postgis | jq -r '.Tags[] | select(test("^[0-9]+\\.[0-9]+-[0-9]+\\.[0-9]+\\.[0-9]+-standard-trixie$"))' | sort -V)
|
|
|
|
declare -A POSTGIS_MAP
|
|
for major_ver in "${MAJOR_VERSIONS[@]}"; do
|
|
minor="${VERSION_MAP[$major_ver]#v}"
|
|
postgis_tag=$(echo "$POSTGIS_TAGS" | grep "^${minor//./\\.}-" | tail -n1 || true)
|
|
if [ -z "$postgis_tag" ]; then
|
|
echo "Error: no postgis standard-trixie image for PostgreSQL ${minor} (${major_ver}), no file updated" >&2
|
|
exit 1
|
|
fi
|
|
POSTGIS_MAP[$major_ver]="$postgis_tag"
|
|
done
|
|
|
|
# Create/update versions.yaml file
|
|
echo "Updating $VERSIONS_FILE..."
|
|
{
|
|
for major_ver in "${MAJOR_VERSIONS[@]}"; do
|
|
echo "\"${major_ver}\": \"${VERSION_MAP[$major_ver]}\""
|
|
done
|
|
} > "$VERSIONS_FILE"
|
|
|
|
echo "Successfully updated $VERSIONS_FILE"
|
|
|
|
echo "Updating $POSTGIS_VERSIONS_FILE..."
|
|
{
|
|
for major_ver in "${MAJOR_VERSIONS[@]}"; do
|
|
echo "\"${major_ver}\": \"${POSTGIS_MAP[$major_ver]}\""
|
|
done
|
|
} > "$POSTGIS_VERSIONS_FILE"
|
|
|
|
echo "Successfully updated $POSTGIS_VERSIONS_FILE"
|
|
|
|
# Update values.yaml - enum with major versions only
|
|
TEMP_FILE=$(mktemp)
|
|
trap "rm -f $TEMP_FILE" EXIT
|
|
|
|
# Build new version section
|
|
NEW_VERSION_SECTION="## @enum {string} Version"
|
|
for major_ver in "${MAJOR_VERSIONS[@]}"; do
|
|
NEW_VERSION_SECTION="${NEW_VERSION_SECTION}
|
|
## @value $major_ver"
|
|
done
|
|
NEW_VERSION_SECTION="${NEW_VERSION_SECTION}
|
|
|
|
## @param {Version} version - PostgreSQL major version to deploy
|
|
version: ${MAJOR_VERSIONS[0]}"
|
|
|
|
# Check if version section already exists
|
|
if grep -q "^## @enum {string} Version" "$VALUES_FILE"; then
|
|
# Version section exists, update it using awk
|
|
echo "Updating existing version section in $VALUES_FILE..."
|
|
|
|
# Use awk to replace the section from "## @enum {string} Version" to "version: " (inclusive)
|
|
# Delete the old section and insert the new one
|
|
awk -v new_section="$NEW_VERSION_SECTION" '
|
|
/^## @enum {string} Version/ {
|
|
in_section = 1
|
|
print new_section
|
|
next
|
|
}
|
|
in_section && /^version: / {
|
|
in_section = 0
|
|
next
|
|
}
|
|
in_section {
|
|
next
|
|
}
|
|
{ print }
|
|
' "$VALUES_FILE" > "$TEMP_FILE.tmp"
|
|
mv "$TEMP_FILE.tmp" "$VALUES_FILE"
|
|
else
|
|
# Version section doesn't exist, insert it before Application-specific parameters section
|
|
echo "Inserting new version section in $VALUES_FILE..."
|
|
|
|
# Use awk to insert before "## @section Application-specific parameters"
|
|
awk -v new_section="$NEW_VERSION_SECTION" '
|
|
/^## @section Application-specific parameters/ {
|
|
print new_section
|
|
print ""
|
|
}
|
|
{ print }
|
|
' "$VALUES_FILE" > "$TEMP_FILE.tmp"
|
|
mv "$TEMP_FILE.tmp" "$VALUES_FILE"
|
|
fi
|
|
|
|
echo "Successfully updated $VALUES_FILE with major versions: ${MAJOR_VERSIONS[*]}"
|