Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add automatic key generation in docker compose #548

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions all-in-one/apisix-dashboard/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ RUN set -x \
automake \
autoconf \
libtool \
libyaml-dev \
pkgconfig \
cmake \
git \
Expand Down
2 changes: 1 addition & 1 deletion compose/apisix_conf/master/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ deployment:

admin_key:
- name: "admin"
key: edd1c9f034335f136f87ad84b625c8f1
key: ''
role: admin # admin: manage all configuration data

etcd:
Expand Down
2 changes: 1 addition & 1 deletion compose/apisix_conf/release/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ deployment:

admin_key:
- name: "admin"
key: edd1c9f034335f136f87ad84b625c8f1
key: ''
role: admin # admin: manage all configuration data

etcd:
Expand Down
8 changes: 8 additions & 0 deletions compose/docker-compose-master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
10 changes: 9 additions & 1 deletion compose/docker-compose-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -52,4 +60,4 @@ services:

networks:
apisix:
driver: bridge
driver: bridge
13 changes: 13 additions & 0 deletions compose/modify_config.sh
Original file line number Diff line number Diff line change
@@ -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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can combine those command into one command.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Directly pushing to config.yaml was giving some errors so i created a temp file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2024-03-30 at 3 57 05 PM

Loading