-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunbound-core
219 lines (184 loc) · 10.6 KB
/
unbound-core
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# built command with check enable
# sudo docker build --build-arg CHECK=1 -t unbound-core -f ./unbound-core .
# sudo podman build --build-arg CHECK=1 -t unbound-core -f ./unbound-core .
# built command without check
# sudo docker build --rm --no-cache --build-arg CHECK=0 -t unbound-core -f ./unbound-core .
# sudo podman build --rm --no-cache --build-arg CHECK=0 -t unbound-core -f ./unbound-core .
# nghttp2 is an implementation of HTTP/2 and its header compression algorithm HPACK in C.
# Support amd64 and arm64 architecture
# Last update: 23/04/2022 11:20:00
# All libraries come from github repository librairies push on my docker account
FROM vpolaris/librairies:hiredis as hiredis
FROM vpolaris/librairies:libexpat as libexpat
FROM vpolaris/librairies:libevent as libevent
FROM vpolaris/librairies:libmnl as libmnl
FROM vpolaris/librairies:libnghttp2 as libnghttp2
FROM vpolaris/librairies:libsodium as libsodium
FROM vpolaris/librairies:openssl-quic as openssl
FROM vpolaris/librairies:protobuf as protobuf
FROM vpolaris/librairies:protobufc as protobufc
FROM vpolaris/librairies:devtools as unbound-dependencies
COPY --from=hiredis / /
COPY --from=libexpat / /
COPY --from=libevent / /
COPY --from=libnghttp2 / /
COPY --from=libsodium / /
COPY --from=openssl / /
COPY --from=protobuf / /
COPY --from=protobufc /usr/local/protobufc/bin/ /usr/bin
COPY --from=protobufc / /
COPY --from=libmnl / /
RUN yum -y install python3 python3-devel systemd-devel \
&& unlink /usr/bin/python \
&& ln -s /usr/bin/python3.7 /usr/bin/python
FROM unbound-dependencies as unbound-download
ARG NAME=unbound
ARG UNBOUND_GPG_KEY="EDFAA3F2CA4E6EB05681AF8E9F6F1C2D7E045F8D"
ARG VERSION=1.15.0
ARG UNBOUND_ARCHIVE=unbound.tar.gz
ARG SRC_DIRECTORY="/tmp/${NAME}"
#Workaround to fix fake path used by buildx for arm64
RUN rm -rf /usr/local/protobufc/bin/ && ln -s /usr/bin /usr/local/protobufc/bin
RUN curl -sSL -o ${UNBOUND_ARCHIVE} "https://www.nlnetlabs.nl/downloads/unbound/unbound-${VERSION}.tar.gz" \
&& curl -sSL -o ${UNBOUND_ARCHIVE}.asc "https://www.nlnetlabs.nl/downloads/unbound/unbound-${VERSION}.tar.gz.asc" \
&& curl -sSL -o ${UNBOUND_ARCHIVE}.sha256 "https://www.nlnetlabs.nl/downloads/unbound/unbound-${VERSION}.tar.gz.sha256" \
&& SUM="$(cat ${UNBOUND_ARCHIVE}.sha256) ${UNBOUND_ARCHIVE}" \
&& if [ "$(sha256sum -c <<< $SUM |cut -d':' -f2|xargs)"=="OK" ];then \
export GNUPGHOME="$(mktemp -d)" \
&& gpg --batch --keyserver hkps://keyserver.ubuntu.com --recv-keys "$UNBOUND_GPG_KEY" \
&& gpg --batch --verify "${UNBOUND_ARCHIVE}.asc" "${UNBOUND_ARCHIVE}" \
&& rm -rf "$GNUPGHOME" "${UNBOUND_ARCHIVE}.asc" "${UNBOUND_ARCHIVE}.sha256"\
&& mkdir -p "${SRC_DIRECTORY}" \
&& tar -xzC "${SRC_DIRECTORY}" --strip-components=1 -f "${UNBOUND_ARCHIVE}" \
&& rm -f "${UNBOUND_ARCHIVE}" \
&& touch "/etc/compiled_versions/${NAME}.${VERSION}" \
;fi
FROM unbound-download as unbound-compile
ARG NAME=unbound
ARG chroot_path="/var/lib/chroot"
ARG unbound_config="/etc/unbound.conf"
ARG SRC_DIRECTORY="/tmp/${NAME}"
ENV PATH=/usr/local/protobufc/bin:$PATH
ARG CHECK=1
RUN mkdir /usr/local/unbound \
&& mkdir -p /unbound/etc/unbound \
&& ldconfig \
&& cd "${SRC_DIRECTORY}" \
&& aclocal && libtoolize --force && autoreconf \
&& ./configure --disable-static --with-pic --with-gnu-ld --enable-pie \
--prefix=/usr/local/unbound \
--with-libevent=/usr/local/libevent --with-libexpat=/usr/local/libexpat\
--enable-dnscrypt --with-libsodium=/usr/local/libsodium \
--enable-dnstap --with-protobuf-c=/usr/local/protobufc \
--enable-cachedb --with-libhiredis=/usr/local/hiredis \
--enable-ipset --with-libmnl=/usr/local/libmnl \
--enable-subnet --enable-tfo-client --enable-tfo-server \
--disable-systemd --with-pythonmodule --enable-ipsecmod \
--with-libnghttp2=/usr/local/libnghttp2 \
--with-conf-file=${chroot_path}${unbound_config} \
--with-chroot-dir=${chroot_path} \
&& make -j "$(nproc)" \
&& if [ ${CHECK} -eq 1 ];then make check -j "$(nproc)"; fi \
&& make install \
&& echo "/usr/local/unbound/lib" | tee /etc/ld.so.conf.d/unbound.conf
FROM unbound-compile as unbound-sysroot
ARG arch="$(uname -m)"
ARG sysroot="/mnt/core"
ARG chroot_path="/var/lib/chroot"
ARG unbound_config="/etc/unbound.conf"
ARG release="2"
ARG flags="--setopt=tsflags=nodocs --releasever=${release}"
RUN unlink /usr/bin/python \
&& ln -s /usr/bin/python2.7 /usr/bin/python
RUN mkdir -p ${sysroot}/etc/ && cp -r /etc/yum* ${sysroot}/etc/
RUN mkdir -p ${sysroot}/etc/unbound \
&& mkdir -p ${sysroot}${chroot_path}/{db,log,etc,share}
# Add exit 0 to resolve arm64 qemu error during buildx processing
RUN yum -y --installroot=${sysroot} ${flags} install glibc setup filesystem libcrypt-nss ca-certificates tar coreutils shadow-utils || exit 0
COPY --from=unbound-compile /usr/local/unbound/sbin/unbound ${sysroot}/sbin/unbound
RUN rm -f /usr/local/unbound/sbin/unbound
COPY --from=unbound-compile /usr/local/unbound/sbin/* ${sysroot}/bin/
RUN rm -rf /usr/local/unbound/sbin/
COPY --from=unbound-compile ${chroot_path}${unbound_config} ${sysroot}${chroot_path}${unbound_config}
COPY --from=unbound-compile /usr/local/*/lib/ ${sysroot}/usr/lib64/
COPY --from=unbound-compile /usr/local/*/bin/ ${sysroot}/usr/bin/
RUN rm ${sysroot}/usr/lib64/*.la
COPY --from=unbound-compile /etc/compiled_versions/ ${sysroot}/etc/compiled_versions/
COPY --from=unbound-compile /lib64/libpython3* $sysroot/lib64
RUN curl -sSL -o ${sysroot}${chroot_path}/named.cache https://www.internic.net/domain/named.cache \
&& curl -sSL -o ${sysroot}${chroot_path}/named.cache.sig https://www.internic.net/domain/named.cache.sig \
&& gpg --batch --keyserver hkps://keyserver.ubuntu.com --recv-keys 937bb869e3a238c5 \
&& gpg --batch --verify ${sysroot}${chroot_path}/named.cache.sig ${sysroot}${chroot_path}/named.cache
RUN yum -y --installroot=${sysroot} ${flags} clean all \
&& rm -rf ${sysroot}/usr/{{lib,share}/locale,{lib,lib64}/gconv,bin/localedef,sbin/build-locale-archive} \
# docs and man pages
&& rm -rf ${sysroot}/usr/share/{man,doc,info,gnome/help} \
# cracklib
&& rm -rf ${sysroot}/usr/share/cracklib \
# i18n
&& rm -rf ${sysroot}/usr/share/i18n \
# yum cache
&& rm -rf ${sysroot}/var/cache/yum \
&& mkdir -p --mode=0755 ${sysroot}/var/cache/yum \
# sln
&& rm -rf ${sysroot}/sbin/sln \
# ldconfig
&& rm -rf ${sysroot}/etc/ld.so.cache ${sysroot}/var/cache/ldconfig \
&& mkdir -p --mode=0755 ${sysroot}/var/cache/ldconfig
FROM scratch as unbound-core
COPY --from=unbound-sysroot /mnt/core /
FROM scratch as unbound-config
ARG arch="$(uname -m)"
ARG sysroot="/mnt/core"
ARG chroot_path="/var/lib/chroot"
ARG unbound_config="/etc/unbound.conf"
ARG release="2"
ARG flags="--setopt=tsflags=nodocs --releasever=${release}"
COPY --from=unbound-core / /
COPY ./unbound-service.sh /
RUN /bin/bash -c "/bin/unbound-control-setup" \
&& /bin/bash -c "/bin/unbound-anchor -a ${chroot_path}/db/root.key || exit 0" \
&& /bin/bash -c "/bin/unbound-control-setup" \
&& if [ -f "/etc/unbound/unbound.conf" ]; then rm /etc/unbound/unbound.conf;fi \
&& /bin/bash -c "ln -s ${chroot_path}${unbound_config} /etc/unbound/unbound.conf" \
&& /bin/bash -c "ln -s ${chroot_path}/etc/unbound_server.pem /etc/unbound/unbound_server.pem" \
&& /bin/bash -c "ln -s ${chroot_path}/etc/unbound_server.key /etc/unbound/unbound_server.key" \
&& /bin/bash -c "ln -s ${chroot_path}/etc/unbound_control.pem /etc/unbound/unbound_control.pem" \
&& /bin/bash -c "ln -s ${chroot_path}/etc/unbound_control.key /etc/unbound/unbound_control.key" \
&& sed -i 's/# do-ip6: yes/ do-ip6: no/' ${chroot_path}${unbound_config} \
&& sed -i 's/# interface: 192.0.2.153$/ interface: 0.0.0.0/' ${chroot_path}${unbound_config} \
&& sed -i 's/# username: \"unbound\"/ username: \"unbound\"/' ${chroot_path}${unbound_config} \
&& sed -i 's/# use-syslog: yes/ use-syslog: no/' ${chroot_path}${unbound_config} \
&& sed -i -e 's@# access-control: 127.* allow$@ access-control: 0.0.0.0/0 allow@' ${chroot_path}${unbound_config}
RUN sed -i 's/# hide-identity: no/ hide-identity: yes/' ${chroot_path}${unbound_config} \
&& sed -i 's/# hide-version: no/ hide-version: yes/' ${chroot_path}${unbound_config} \
&& sed -i 's/# qname-minimisation: yes/ qname-minimisation: yes/' ${chroot_path}${unbound_config} \
&& /bin/bash -c "mkfifo /var/run/unbound.control.pipe" \
&& sed -i 's/# control-enable: no/ control-enable: yes/' ${chroot_path}${unbound_config} \
&& sed -i 's/# control-use-cert: \"yes\"/ control-use-cert: \"yes\"/' ${chroot_path}${unbound_config} \
&& sed -i 's@# control-interface: 127.0.0.1@ control-interface: /var/run/unbound.control.pipe@' ${chroot_path}${unbound_config}
RUN sed -i -e 's@# chroot: \".*\"@ chroot: \"/var/lib/chroot\"@' ${chroot_path}${unbound_config} \
&& sed -i -e 's@# directory: \".*\"@ directory: \"/\"@' ${chroot_path}${unbound_config} \
&& sed -i -e 's@# root-hints: \"\"@ root-hints: \"/named.cache\"@' ${chroot_path}${unbound_config} \
&& sed -i -e 's@# auto-trust-anchor-file: \".*\"@ auto-trust-anchor-file: \"/db/root.key\"@' ${chroot_path}${unbound_config} \
&& sed -i -e 's@# logfile: \"\"@ logfile: \"/log/unbound.log\"@' ${chroot_path}${unbound_config}
RUN printf "\nforward-zone:\n" >> ${chroot_path}${unbound_config} \
&& printf "name: \".\"\n" >> ${chroot_path}${unbound_config} \
&& printf "forward-tls-upstream: yes\n" >> ${chroot_path}${unbound_config} \
&& printf "forward-addr: 9.9.9.9@853\n" >> ${chroot_path}${unbound_config}
RUN unlink /usr/bin/python \
&& ln -s /usr/bin/python2.7 /usr/bin/python
FROM unbound-config as unbound-user
ARG arch="$(uname -m)"
ARG sysroot="/mnt/core"
ARG chroot_path="/var/lib/chroot"
ARG release="2"
ARG flags="--setopt=tsflags=nodocs --releasever=${release}"
# RUN yum -y --installroot= ${flags} install shadow-utils
RUN groupadd -g 274 unbound \
&& useradd --system -M -d ${chroot_path} -c 'unbound daemon' -s /bin/false -g 274 -u 274 unbound \
&& /bin/bash -c "chown unbound: /var/run/unbound.control.pipe" \
RUN chmod u+x /unbound-service.sh \
&& /bin/bash -c "chown -R unbound: /etc/unbound ${chroot_path}/"\
&& /bin/bash -c "chown unbound: /unbound-service.sh /sbin/unbound /bin/unbound*"
# RUN yum -y --installroot= ${flags} remove shadow-utils