Welcome back to the Knowledge Portal Video series.
Today we are going to talk about one more way in which you can have a stringent access control on your
files in your web server with the help of whitelisting.
Let's look into how it works.
Now, essentially, if you have a web server on the Internet, the chances are that you might be getting
visitors from all over the world.
Now let's assume this is a example.com web server and you have a slash admin portal.
Now what you want is you do not want everyone to access the slash admin page.
You only might want to allow only certain IP to access that particular page.
Now the way in which you can do that is through whitelisting.
Now, taking this example, there are three clients over here.
Each has a unique IP addresses.
So as a web server, what you can do is you can allow access to a certain resource only if the client
has a particular IP address.
So if we say to a web server to only allow slash admin page to be accessible from 192 168, 10.5 and
deny all.
So essentially that means that only one computer can access the particular admin page and no one else.
Now if you look into the syntax, it is a very simple way of doing it.
So here the location for slash admin.
In this we have allowed director where it is saying allow followed by the IP address and deny all.
So essentially this is a very simple way to say only allow this particular IP address to access the
admin page and deny everyone else.
Now this is a very simple whitelisting based approach, which is very, very helpful.
Let's look into how we can implement it on Nginx.
So I'll minimize this and I'll go to our server.
Now let's go to our favorite web conf and essentially I have a slash admin page over here.
So let's define a root location.
So root will be var dub dub dub website's example.
The index will be index dot HTML and let's include allow director.
Allow 127001.
And I'll specify denial.
Now what this essentially means that only allow localhost to open slash admin page and deny everyone
else.
I'll save this once.
Let me test the configuration.
It is successful and let's reload the nginx.
Now if I do a call on example.com slash admin, essentially nginx will give me a 403 forbidden because
I'm not allowed to access this particular resource.
Now let's allow our IP address as well in the Nginx configuration.
So I'll copy the IP address over here.
I'll open the Nginx configuration and in the allow section, let me specify the IP address once again.
So essentially now we are allowing our IP address over here.
So if I do Nginx reload.
Okay.
Now let let's do a curl again.
So I'll do a curl example.com slash admin and essentially here you see it is showing the secret admin
page.
This is the reason because our IP address is in the whitelist.
Now one more thing that I wanted to show over here is if there are a lot of IP addresses, then essentially
this is not a very optimal way of doing things.
So what we can do over here is I'll take these two directives, I'll copy it and I'll create a new file,
say whitelist, and I'll paste the two directives over here.
Let me save this.
Let's go to the web conf and essentially what I'll do is.
Instead of specifying a directive all the time, I'll just include use the include directive followed
by the path.
The Conf.d White List.
So what this basically will do is it will take the allow directives from this particular file.
So if I save this and let's reload Nginx.
Now, essentially what has happened is Nginx has opened this particular file and it has taken the IP
addresses from the particular file itself.
This is a very proper way of doing things.
Specifically if you have like 1015 IP addresses that you want to mention and mentioning them in the
configuration file is not a very optimal way of doing things.
So this is it about whitelisting?
This is a short video, but whitelisting is something that proves to be very useful in the production
environment.
This is it.
I hope this video has been useful for you and I'd like to thank you for viewing.