Skip to content

Commit 0317b58

Browse files
authored
Merge pull request #108 from mendix/DES-2719-vw
DES-2719 Vulnerability workarounds
2 parents 1a8514e + a626d96 commit 0317b58

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

Dockerfile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ FROM ${ROOTFS_IMAGE} AS builder
1212
ARG BUILD_PATH=project
1313
ARG DD_API_KEY
1414
# CF buildpack version
15-
ARG CF_BUILDPACK=v4.13.4
15+
ARG CF_BUILDPACK=v4.13.6
16+
# Exclude the logfilter binary by default
17+
ARG EXCLUDE_LOGFILTER=true
1618

1719
# Each comment corresponds to the script line:
1820
# 1. Create all directories needed by scripts
@@ -63,9 +65,18 @@ FROM ${ROOTFS_IMAGE}
6365
LABEL Author="Mendix Digital Ecosystems"
6466
LABEL maintainer="[email protected]"
6567

68+
# Uninstall build-time dependencies to remove potentially vulnerable libraries
69+
ARG UNINSTALL_BUILD_DEPENDENCIES=true
70+
6671
# Allow the root group to modify /etc/passwd so that the startup script can update the non-root uid
6772
RUN chmod g=u /etc/passwd
6873

74+
# Uninstall packages which are only required during build time
75+
RUN if [ "$UNINSTALL_BUILD_DEPENDENCIES" = "true" ] ; then\
76+
DEBIAN_FRONTEND=noninteractive apt-mark manual libfontconfig1 && \
77+
DEBIAN_FRONTEND=noninteractive apt-get remove --purge --auto-remove -q -y wget curl libgdiplus ; \
78+
fi
79+
6980
# Add the buildpack modules
7081
ENV PYTHONPATH "/opt/mendix/buildpack/lib/:/opt/mendix/buildpack/:/opt/mendix/buildpack/lib/python3.6/site-packages/"
7182

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ For build you can provide next arguments:
5555

5656
- **BUILD_PATH** indicates where the application model is located. It is a root directory of an unzipped .MDA or .MPK file. In the latter case, this is the directory where your .MPR file is located. Must be within [build context](https://docs.docker.com/engine/reference/commandline/build/#extended-description). Defaults to `./project`.
5757
- **ROOTFS_IMAGE** is a type of rootfs image. Defaults to `mendix/rootfs:bionic`. To use Ubuntu 14.04, change this to `mendix/rootfs:trusty`. It's also possible to use a custom rootfs image as described in [Advanced feature: full-build](#advanced-feature-full-build).
58-
- **CF_BUILDPACK** is a version of CloudFoundry buildpack. Defaults to `v4.13.4`. For stable pipelines, it's recommended to use a fixed version from **v4.13.4** and later. CloudFoundry buildpack versions below **v4.12.0** are not supported.
58+
- **CF_BUILDPACK** is a version of CloudFoundry buildpack. Defaults to `v4.13.6`. For stable pipelines, it's recommended to use a fixed version from **v4.13.6** and later. CloudFoundry buildpack versions below **v4.12.0** are not supported.
59+
- **EXCLUDE_LOGFILTER** will exclude the `mendix-logfilter` binary from the resulting Docker image if set to `true`. Defaults to `true`. Excluding `mendix-logfilter` will reduce the image size and remove a component that's not commonly used; the `LOG_RATELIMIT` environment variable option will be disabled.
60+
- **UNINSTALL_BUILD_DEPENDENCIES** will uninstall packages which are not needed to launch an app, and are only used during the build phase. Defaults to `true`. This option will remove several libraries which are known to have unpatched CVE vulnerabilities.
5961

6062
### Startup
6163

scripts/compilation

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ def remove_jdk():
4646
if os.path.exists(jdk_path):
4747
shutil.rmtree(jdk_path, ignore_errors=False)
4848

49+
def fix_logfilter():
50+
exclude_logfilter = os.getenv("EXCLUDE_LOGFILTER", "true").lower() == "true"
51+
logfilter_path = "/opt/mendix/build/bin/mendix-logfilter"
52+
if os.path.exists(logfilter_path):
53+
if exclude_logfilter:
54+
logging.info("Removing mendix-logfilter executable")
55+
os.remove(logfilter_path)
56+
else:
57+
os.chmod(logfilter_path, 0o0755)
58+
4959
def make_dependencies_reusable():
5060
logging.info("Making dependencies reusable...")
5161
shutil.move("/opt/mendix/build/runtimes", "/var/mendix/build/")
@@ -67,4 +77,6 @@ if __name__ == '__main__':
6777
if exit_code != 0:
6878
sys.exit(exit_code)
6979
remove_jdk()
80+
fix_logfilter()
7081
make_dependencies_reusable()
82+

scripts/startup

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ def export_encoded_cacertificates():
6161
certificate_authorities = base64.b64decode(certificate_authorities_base64)
6262
os.environ['CERTIFICATE_AUTHORITIES'] = str(certificate_authorities,'utf-8')
6363

64+
def check_logfilter():
65+
log_ratelimit_enabled = os.getenv('LOG_RATELIMIT', None) is not None
66+
logfilter_path = './bin/mendix-logfilter'
67+
if log_ratelimit_enabled and not os.path.exists(logfilter_path):
68+
logging.warn("LOG_RATELIMIT is set, but the mendix-logfilter binary is missing. Rebuild Docker image with EXCLUDE_LOGFILTER=false to enable log filtering")
69+
del os.environ['LOG_RATELIMIT']
70+
6471
def sigchld_handler(_signo, _stack_frame):
6572
# reap zombies
6673
logging.debug("Child process has exited, getting result")
@@ -118,6 +125,7 @@ if __name__ == '__main__':
118125
export_db_endpoint()
119126
export_vcap_variables()
120127
export_k8s_instance()
128+
check_logfilter()
121129

122130
export_encoded_cacertificates()
123131
add_uid()

0 commit comments

Comments
 (0)