Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Hands-On Microservices with Django

You're reading from  Hands-On Microservices with Django

Product type Book
Published in May 2024
Publisher Packt
ISBN-13 9781835468524
Pages 278 pages
Edition 1st Edition
Languages
Author (1):
Tieme Woldman Tieme Woldman
Profile icon Tieme Woldman

Table of Contents (18) Chapters

Preface 1. Part 1:Introducing Microservices and Getting Started
2. Chapter 1: What Is a Microservice? 3. Chapter 2: Introducing the Django Microservices Architecture 4. Chapter 3: Setting Up the Development and Runtime Environment 5. Part 2:Building the Microservices Foundation
6. Chapter 4: Cloud-native Data Processing with MongoDB 7. Chapter 5: Creating RESTful APIs for Microservices 8. Chapter 6: Orchestrating Microservices with Celery and RabbitMQ 9. Chapter 7: Testing Microservices 10. Chapter 8: Deploying Microservices with Docker 11. Part 3:Taking Microservices to the Production Level
12. Chapter 9: Securing Microservices 13. Chapter 10: Improving Microservices Performance with Caching 14. Chapter 11: Best Practices for Microservices 15. Chapter 12: Transforming a Monolithic Web Application into a Microservices Version 16. Index 17. Other Books You May Enjoy

Controlling access to microservices

We can apply north-south security to secure communication between producers (client) and workers (services) and to prevent unauthorized producers from executing our microservices:

Figure 9.3 – Controlling north-south access to microservices

Figure 9.3 – Controlling north-south access to microservices

To see how this works, we’ll set this up for the Django subscription app and the match address worker in our sample application with JWT.

We’ll start by creating a JWT for the Django app. This is a one-time action for which we use a standalone Python script. We could hardcode the generated JWT into the Django app and the match address worker, but that’s unsafe, so we’ll include the tokens as settings in a safe .env file, which we’ll process with the python-dotenv package. Follow the next steps to generate and store the JWT:

  1. Create a file called generate_token.py in the django-microservices directory with this code:
    1 import jwt
    2...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}