Skip to content

Commit

Permalink
Pass security flags and check gcc version
Browse files Browse the repository at this point in the history
We were not passing security flags for citus community packages, which
we are for enterprise.

Also this adds the check for gcc version to make sure we are compliant
with security.
  • Loading branch information
SaitTalhaNisanci committed Oct 20, 2020
1 parent 227710f commit 9fcd572
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
13 changes: 12 additions & 1 deletion citus.spec
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,19 @@ commands.
%prep
%setup -q -n %{sname}-%{version}

# Flags taken from: https://liquid.microsoft.com/Web/Object/Read/ms.security/Requirements/Microsoft.Security.SystemsADM.10203#guide
SECURITY_CFLAGS="-fstack-protector-strong -D_FORTIFY_SOURCE=2 -O2 -z noexecstack -fpic -Wl,-z,relro -Wl,-z,now -Wformat -Wformat-security -Werror=format-security"

currentgccver="$(gcc -dumpversion)"
requiredgccver="4.8.2"
if [ "$(printf '%s\n' "$requiredgccver" "$currentgccver" | sort -V | tail -n1)" = "$requiredgccver" ]; then
echo WARNING: Using slower security flags because of outdated compiler
SECURITY_CFLAGS="-fstack-protector-all -D_FORTIFY_SOURCE=2 -O2 -z noexecstack -fpic -Wl,-z,relro -Wl,-z,now -Wformat -Wformat-security -Werror=format-security"
fi
fi

%build
%configure PG_CONFIG=%{pginstdir}/bin/pg_config --with-extra-version="%{?conf_extra_version}"
%configure PG_CONFIG=%{pginstdir}/bin/pg_config --with-extra-version="%{?conf_extra_version}" CC=$(command -v gcc) CFLAGS="$SECURITY_CFLAGS"
make %{?_smp_mflags}

%install
Expand Down
9 changes: 9 additions & 0 deletions debian/check-gcc-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
set -euxo pipefail

currentgccver="$($(pg_config --cc) -dumpversion)"
requiredgccver="4.8.2"
if [ "$(printf '%s\n' "$requiredgccver" "$currentgccver" | sort -V | tail -n1)" = "$requiredgccver" ]; then
echo ERROR: At least GCC version "$requiredgccver" is needed
exit 1
fi
1 change: 1 addition & 0 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ override_dh_auto_test:
# nothing to do here, see debian/tests/* instead

override_dh_auto_configure:
debian/check-gcc-version.sh
+pg_buildext configure build-%v --with-extra-version="$${CONF_EXTRA_VERSION:-}"

override_dh_auto_install:
Expand Down

0 comments on commit 9fcd572

Please sign in to comment.