From 366b8c99b75d370f0056c303e0de5c8c020aa769 Mon Sep 17 00:00:00 2001 From: Ashish Tiwari Date: Fri, 22 Mar 2024 12:16:02 +0530 Subject: [PATCH 1/3] feat: Add automatic key generation in docker compose --- README.md | 8 +++++++- compose/apisix_conf/master/config.yaml | 2 +- compose/apisix_conf/release/config.yaml | 2 +- compose/docker-compose-master.yaml | 8 ++++++++ compose/docker-compose-release.yaml | 10 +++++++++- compose/modify_config.sh | 13 +++++++++++++ 6 files changed, 39 insertions(+), 4 deletions(-) create mode 100755 compose/modify_config.sh diff --git a/README.md b/README.md index 2a8284f4..0ef1e8d8 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,12 @@ deployment: allow_admin: - 0.0.0.0/0 # Please set it to the subnet address you obtained. # If not set, by default all IP access is allowed. + admin_key: + - name: "admin" +# Please set this to a random 32 character alphanumeric. This is automatically set while using docker compose. +#If not provided then apisix will autogenerate one and write it here. In that case, make sure that this is the only apisix instance using this config + role: admin + key: '' etcd: host: - "http://etcd:2379" @@ -141,7 +147,7 @@ Check that APISIX is running properly by running the following command on the ho ``` curl "http://127.0.0.1:9180/apisix/admin/services/" \ --H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' +-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' # Replace this key with the one either provided by you, or written by apisix in the config.yaml ``` The response indicates that apisix is running successfully: diff --git a/compose/apisix_conf/master/config.yaml b/compose/apisix_conf/master/config.yaml index ce36035c..5ce381d6 100644 --- a/compose/apisix_conf/master/config.yaml +++ b/compose/apisix_conf/master/config.yaml @@ -26,7 +26,7 @@ deployment: admin_key: - name: "admin" - key: edd1c9f034335f136f87ad84b625c8f1 + key: '' role: admin # admin: manage all configuration data etcd: diff --git a/compose/apisix_conf/release/config.yaml b/compose/apisix_conf/release/config.yaml index ce36035c..5ce381d6 100644 --- a/compose/apisix_conf/release/config.yaml +++ b/compose/apisix_conf/release/config.yaml @@ -26,7 +26,7 @@ deployment: admin_key: - name: "admin" - key: edd1c9f034335f136f87ad84b625c8f1 + key: '' role: admin # admin: manage all configuration data etcd: diff --git a/compose/docker-compose-master.yaml b/compose/docker-compose-master.yaml index 5a2519e5..a335a306 100644 --- a/compose/docker-compose-master.yaml +++ b/compose/docker-compose-master.yaml @@ -25,6 +25,7 @@ services: - ./apisix_conf/master/config.yaml:/usr/local/apisix/conf/config.yaml:ro depends_on: - etcd + - modify_config ports: - "9180:9180/tcp" - "9080:9080/tcp" @@ -33,6 +34,13 @@ services: networks: - apisix + modify_config: # You can remove this service if you already have added your own key for admin api in the config + image: alpine:latest + volumes: + - ./apisix_conf/master/config.yaml:/config.yaml:rw + - ./modify_config.sh:/modify_config.sh:ro + command: ["/bin/sh", "/modify_config.sh"] + etcd: image: bitnami/etcd:3.4.9 user: root diff --git a/compose/docker-compose-release.yaml b/compose/docker-compose-release.yaml index c36474b3..67f89396 100644 --- a/compose/docker-compose-release.yaml +++ b/compose/docker-compose-release.yaml @@ -25,6 +25,7 @@ services: - ./apisix_conf/release/config.yaml:/usr/local/apisix/conf/config.yaml:ro depends_on: - etcd + - modify_config ports: - "9180:9180/tcp" - "9080:9080/tcp" @@ -33,6 +34,13 @@ services: networks: - apisix + modify_config: # You can remove this service if you already have added your own key for admin api in the config + image: alpine:latest + volumes: + - ./apisix_conf/master/config.yaml:/config.yaml:rw + - ./modify_config.sh:/modify_config.sh:ro + command: ["/bin/sh", "/modify_config.sh"] + etcd: image: bitnami/etcd:3.4.9 user: root @@ -52,4 +60,4 @@ services: networks: apisix: - driver: bridge \ No newline at end of file + driver: bridge diff --git a/compose/modify_config.sh b/compose/modify_config.sh new file mode 100755 index 00000000..c3f7afcb --- /dev/null +++ b/compose/modify_config.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +# Generate a random string +random_string=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 32) + +# Perform substitution using sed +sed "s/key: ''/key: $random_string/g" /config.yaml > /tmp/temp_config.yaml + +# Copy the content of the temporary file back to the original file +cat /tmp/temp_config.yaml > /config.yaml + +# Remove the temporary file +rm /tmp/temp_config.yaml From 7a80d037c398cbefca723e7805375f0fc6f67a70 Mon Sep 17 00:00:00 2001 From: Ashish Tiwari Date: Fri, 22 Mar 2024 12:18:02 +0530 Subject: [PATCH 2/3] fix lint --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0ef1e8d8..905ec62e 100644 --- a/README.md +++ b/README.md @@ -118,9 +118,9 @@ deployment: # If not set, by default all IP access is allowed. admin_key: - name: "admin" -# Please set this to a random 32 character alphanumeric. This is automatically set while using docker compose. +# Please set this to a random 32 character alphanumeric. This is automatically set while using docker compose. #If not provided then apisix will autogenerate one and write it here. In that case, make sure that this is the only apisix instance using this config - role: admin + role: admin key: '' etcd: host: From 04766a61d60117ba6be87a71d1b9f5f993b82144 Mon Sep 17 00:00:00 2001 From: Ashish Tiwari Date: Wed, 10 Apr 2024 11:34:04 +0530 Subject: [PATCH 3/3] add libyaml --- all-in-one/apisix-dashboard/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/all-in-one/apisix-dashboard/Dockerfile b/all-in-one/apisix-dashboard/Dockerfile index 7daa82a3..aa3c1c11 100644 --- a/all-in-one/apisix-dashboard/Dockerfile +++ b/all-in-one/apisix-dashboard/Dockerfile @@ -33,6 +33,7 @@ RUN set -x \ automake \ autoconf \ libtool \ + libyaml-dev \ pkgconfig \ cmake \ git \