Skip to content

Commit

Permalink
chore: validate etcd conf strictly
Browse files Browse the repository at this point in the history
Signed-off-by: spacewander <spacewanderlzx@gmail.com>
  • Loading branch information
spacewander committed Jun 13, 2022
1 parent 7188acb commit 4040df9
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 3 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/chaos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ jobs:
- name: Creating minikube cluster
run: |
bash ./t/chaos/utils/setup_chaos_utils.sh start_minikube
wget https://raw.githubusercontent.com/apache/apisix-docker/master/alpine-local/Dockerfile
mkdir logs
docker build -t apache/apisix:alpine-local --build-arg APISIX_PATH=. -f Dockerfile .
docker build -t apache/apisix:alpine-local --build-arg APISIX_PATH=. -f ./t/chaos/utils/Dockerfile .
minikube cache add apache/apisix:alpine-local -v 7 --alsologtostderr
- name: Print cluster information
Expand Down
14 changes: 13 additions & 1 deletion apisix/cli/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,20 @@ local config_schema = {
type = "string",
},
}
},
prefix = {
type = "string",
pattern = [[^/[^/]+$]]
},
host = {
type = "array",
items = {
type = "string",
pattern = [[^https?://]]
}
}
}
},
required = {"prefix", "host"}
},
wasm = {
type = "object",
Expand Down
76 changes: 76 additions & 0 deletions t/chaos/utils/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

ARG ENABLE_PROXY=false

FROM openresty/openresty:1.19.3.2-alpine-fat AS production-stage

ARG ENABLE_PROXY
ARG APISIX_PATH
COPY $APISIX_PATH ./apisix
RUN set -x \
&& (test "${ENABLE_PROXY}" != "true" || /bin/sed -i 's,http://dl-cdn.alpinelinux.org,https://mirrors.aliyun.com,g' /etc/apk/repositories) \
&& apk add --no-cache --virtual .builddeps \
automake \
autoconf \
libtool \
pkgconfig \
cmake \
git \
openldap-dev \
openresty-pcre-dev \
&& cd apisix \
&& git config --global url.https://github.com/.insteadOf git://github.com/ \
&& mkdir -p ~/.luarocks \
&& luarocks config --local variable.PCRE_DIR /usr/local/openresty/pcre/ \
&& make deps \
&& cp -v bin/apisix /usr/bin/ \
&& mv ../apisix /usr/local/apisix \
&& apk del .builddeps build-base make unzip

FROM alpine:3.13 AS last-stage

ARG ENABLE_PROXY
# add runtime for Apache APISIX
RUN set -x \
&& (test "${ENABLE_PROXY}" != "true" || /bin/sed -i 's,http://dl-cdn.alpinelinux.org,https://mirrors.aliyun.com,g' /etc/apk/repositories) \
&& apk add --no-cache \
bash \
curl \
libstdc++ \
openldap \
tzdata

WORKDIR /usr/local/apisix

COPY --from=production-stage /usr/local/openresty/ /usr/local/openresty/
COPY --from=production-stage /usr/local/apisix/ /usr/local/apisix/
COPY --from=production-stage /usr/bin/apisix /usr/bin/apisix

# forward request and error logs to docker log collector
RUN mkdir -p logs && touch logs/access.log && touch logs/error.log \
&& ln -sf /dev/stdout /usr/local/apisix/logs/access.log \
&& ln -sf /dev/stderr /usr/local/apisix/logs/error.log

ENV PATH=$PATH:/usr/local/openresty/luajit/bin:/usr/local/openresty/nginx/sbin:/usr/local/openresty/bin

EXPOSE 9080 9443

CMD ["sh", "-c", "/usr/bin/apisix init && /usr/bin/apisix init_etcd && /usr/local/openresty/bin/openresty -p /usr/local/apisix -g 'daemon off;'"]

STOPSIGNAL SIGQUIT

27 changes: 27 additions & 0 deletions t/cli/test_validate_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,30 @@ if echo "$out" | grep "missing loopback or unspecified in the nginx_config.http.
fi

echo "passed: check the realip configuration for batch-requests"

echo '
etcd:
host:
- 127.0.0.1
' > conf/config.yaml

out=$(make init 2>&1 || true)
if ! echo "$out" | grep 'property "host" validation failed'; then
echo "failed: should check etcd schema during init"
exit 1
fi

echo '
etcd:
prefix: "/apisix/"
host:
- https://127.0.0.1
' > conf/config.yaml

out=$(make init 2>&1 || true)
if ! echo "$out" | grep 'property "prefix" validation failed'; then
echo "failed: should check etcd schema during init"
exit 1
fi

echo "passed: check etcd schema during init"

0 comments on commit 4040df9

Please sign in to comment.