Home United States dc3 United States software in english pdf CockroachDB With Django and MIT Kerberos

CockroachDB With Django and MIT Kerberos

269
0
SHARE

In this post of the CockroachDB and Kerberos series, we are going to talk about the means of using Django with a kerberized CockroachDB and what that entails.
Join the DZone community and get the full member experience. Today, I’m going to talk about the means of using Django with a kerberized CockroachDB and what that entails. This is not uncommon in a production use case and expecting enterprise-grade access to development frameworks is table stakes for some of our customers. I find the topic of Kerberos very interesting and my colleagues commonly refer to me for help with this complex topic. I am by no means an expert at Kerberos, I am however familiar enough with it to be dangerous. That said, I’ve written multiple articles on the topic which you may find below: Today, I’m going to demonstrate how to leverage CockroachDB with MIT Kerberos and the Django project. We have a lot of customers using us for their Python database needs and you can view some of the options on our docs site. For today’s setup, I have a multi-node CockroachDB cluster, a Django container called web, a load balancer container, and a Kerberos KDC container. You can find the code for this example in my repo. My example is a slight modification of the one you can find from Docker. As I said, my version is a bit different from the one on the Docker website, as I’m adding a Kerberos Distribution Center, a load balancer, and a three-node CockroachDB cluster. Otherwise pretty much everything else is the same. What does not work is creating a project via the container like in the Docker quickstart. So docker-compose run web django-admin startproject composeexample. won’t work as I have an additional entry point in my Django container to kinit to the KDC. This is a small price to pay so instead, we’re going to run this manually. a) Install Django locally. Django 2.2 is the current long-term release but this setup works with Django 3.0 and 3.1 as well and I’ll cover that in a bit. b) Create a project. In the root of the docker-compose directory, initialize a new Django project. Now you should see a directory called example and a file called manage.py. Edit the example/settings.py with the following properties: This is not much different from the standard Django properties except for the following subtle differences. ENGINE is our CockroachDB native driver for Django, NAME is the database name, USER is a user in our Kerberos KDC, HOST points to our load balancer instance, please review the previous articles if you need further context on that. We also include sslmode and sslrootcert to verify the authenticity of our clients and nodes. Uncomment the desired versions of Django and CockroachDB driver. We can see the server is up, we can navigate to the Django portal from your host. I had a customer ask how to pass a custom SPN to a Django project. It was not documented and not that intuitive but after some trial and error, the following was achieved by adding krbsrvname to the example/settings.py file. Tear down the environment with a helper script called./down.sh and restart it with./up.sh. Let’s apply those migrations! There are many reasons to upgrade Django. Let’s do that with our project. We need to edit our django/requirements.txt file to match the target version of Django, in our case 3.1. Tear down the environment with down.sh and start it up again with up.sh. Navigate to the Django portal and you will see the new version. And just so there are no doubts, let’s connect to the web container and see whether a connection has been made with Kerberos. That’s it for today, hope you enjoyed this tour of Django with Kerberos. Published at DZone with permission of Artem Ervits. See the original article here. Opinions expressed by DZone contributors are their own.