|
| 1 | +# Motivation |
| 2 | + This set up shows a simple facade implementation with re-authentication. |
| 3 | + |
| 4 | +## Components |
| 5 | +* server |
| 6 | +* nginx |
| 7 | +* client call |
| 8 | + |
| 9 | +# Requirements |
| 10 | +* python (tested with version 3.12.2) |
| 11 | +* nginx (tested with version 1.25.4) |
| 12 | + |
| 13 | +# Server |
| 14 | +1) Create a Virtual Environment for Python |
| 15 | + |
| 16 | +`python3 -m venv venv` |
| 17 | + |
| 18 | +2) Install Flask |
| 19 | + |
| 20 | +`pip3 install flask` |
| 21 | + |
| 22 | +3) Activate the virtual environment for python |
| 23 | + |
| 24 | +`source venv/bin/activate` |
| 25 | + |
| 26 | +4) Create Private Key |
| 27 | + |
| 28 | +`openssl genrsa -aes256 -out server.key 2048` |
| 29 | + |
| 30 | +5) Create Certificate Signing Request |
| 31 | + |
| 32 | +`openssl req -new -key server.key -out server.csr` |
| 33 | + |
| 34 | +6) Create the Certificate |
| 35 | + |
| 36 | +`openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt` |
| 37 | + |
| 38 | +7) Start the server |
| 39 | + |
| 40 | +`python server.py` |
| 41 | + |
| 42 | +8) Test the server |
| 43 | + |
| 44 | +`curl https://127.0.0.1:5000/unsecured --insecure` |
| 45 | + |
| 46 | +9) Test passing an API Key |
| 47 | + |
| 48 | +`curl https://localhost:5000/secured -H "X-API-Key:TEST-API-KEY" --insecure` |
| 49 | + |
| 50 | +# NGINX |
| 51 | +Apply the right configuration, found in this repository in `nginx.conf` |
| 52 | +On MacOS it is located in `/usr/local/etc/nginx` |
| 53 | + |
| 54 | +## Create Certificates and Adjust NGINX Configuration |
| 55 | + |
| 56 | +1) Create Private Key |
| 57 | + |
| 58 | +`openssl genrsa -aes256 -out server.key 2048` |
| 59 | + |
| 60 | +2) Create Certificate Signing Request |
| 61 | + |
| 62 | +`openssl req -new -key nginx.key -out nginx.csr` |
| 63 | + |
| 64 | +3) Create the Certificate |
| 65 | + |
| 66 | +`openssl x509 -req -days 365 -in nginx.csr -signkey nginx.key -out nginx.crt` |
| 67 | + |
| 68 | +4) Adjust paths in nginx.conf |
| 69 | + |
| 70 | + |
| 71 | +5) Start nginx |
| 72 | + |
| 73 | +`nginx` |
| 74 | + |
| 75 | +# Start Testing |
| 76 | + |
| 77 | +Test for forbidden on unsecured endpoint |
| 78 | + |
| 79 | +`curl https://localhost/unsecured --insecure` |
| 80 | + |
| 81 | +Test for successful request on secured endpoint with enriched credentials |
| 82 | + |
| 83 | +`curl https://localhost/secured --insecure` |
| 84 | + |
| 85 | +# Troubleshooting |
| 86 | + |
| 87 | +Beware of the nginx state. Sometimes, a reload via `nginx -s reload` is not enough. If it behaves not as expected, try `nginx -s quit` and restart using `nginx`. |
0 commit comments