Skip to content

How to restrict external access to Redis instance installed in a docker image

Solved Configure
8 3 3.4k 1
  • Hello, I’m receiving an email, about my server that has a docker image of redis installed and uses port 6379, saying that it is open to external connections.

    Redis listens for traffic from everywhere on port 6379, and you can validate this report by attempting to connect to your Redis on 6379 via a simple telnet command:

    telnet 111.111.111.111 6379 
    

    This is a part of the email, (I masked the IP to put the message here on the forum) I also did the test to see if the port is really open to external connections on the website, https://www.yougetsignal.com /tools/open-ports/ , and it actually shows that my server’s ip port 6379 is open. And the email says to do the following

    Remediation of this issue will take just a few minutes and is relatively straightforward. You will need to open /etc/redis/redis.conf and uncomment (remove the ā€œ#ā€) or modify the line beginning with:

    #bind 127.0.0.1 ::1  
    

    Afterwards, restart redis with:

    sudo systemctl restart redis  
    

    I would like to know if someone can help me, since I can’t access the redis.config file inside the server, because redis is in a docker image, or at least I don’t know how to access it. Is there any way to block external access to my redis installed by a docker image?

  • @phenomlab
    Sorry to delay in responding, yes as i mentioned above, i had to remove my redis from docker and reinstall a new image with this command

    docker run --name=redis -p 127.0.0.1:6379:6379 -d -t redis:alpine
    

    and now when i test my ip and port on
    https://www.yougetsignal.com/tools/open-ports/

    the status of my redis port is closed. I think which to configure firewall in droplet digital ocean is a good idea too, and i will configure soon.
    Thanks for the help!

  • Hello, I’m receiving an email, about my server that has a docker image of redis installed and uses port 6379, saying that it is open to external connections.

    Redis listens for traffic from everywhere on port 6379, and you can validate this report by attempting to connect to your Redis on 6379 via a simple telnet command:

    telnet 111.111.111.111 6379 
    

    This is a part of the email, (I masked the IP to put the message here on the forum) I also did the test to see if the port is really open to external connections on the website, https://www.yougetsignal.com /tools/open-ports/ , and it actually shows that my server’s ip port 6379 is open. And the email says to do the following

    Remediation of this issue will take just a few minutes and is relatively straightforward. You will need to open /etc/redis/redis.conf and uncomment (remove the ā€œ#ā€) or modify the line beginning with:

    #bind 127.0.0.1 ::1  
    

    Afterwards, restart redis with:

    sudo systemctl restart redis  
    

    I would like to know if someone can help me, since I can’t access the redis.config file inside the server, because redis is in a docker image, or at least I don’t know how to access it. Is there any way to block external access to my redis installed by a docker image?

    @WesleyMoura Hi, and welcome to Sudonix. Even with Redis installed in a docker image, you will still have a config file, and should still be able to reach it.

    Can you provide more detail about the docket image ? You are right - by default, Redis will listen on all addresses, and will be exposed to the internet. Another way around this is to block access at firewall level and only permit the hosts you actually want.

  • @WesleyMoura Hi, and welcome to Sudonix. Even with Redis installed in a docker image, you will still have a config file, and should still be able to reach it.

    Can you provide more detail about the docket image ? You are right - by default, Redis will listen on all addresses, and will be exposed to the internet. Another way around this is to block access at firewall level and only permit the hosts you actually want.

    @phenomlab Hello, i have installed my redis on docker with this comand,
    docker run --name redis -p 6379:6379 -d -t redis:alpine
    And i don’t know how to access the redis.conf on docker image to make this step cited in email.
    Do you know how to do?
    I’m trying to search on documentation but i still can’t find it.

  • @phenomlab Hello, i have installed my redis on docker with this comand,
    docker run --name redis -p 6379:6379 -d -t redis:alpine
    And i don’t know how to access the redis.conf on docker image to make this step cited in email.
    Do you know how to do?
    I’m trying to search on documentation but i still can’t find it.

    @WesleyMoura Is it located in /usr/local/etc/redis/redis.conf ?

    Also, have a look at this

    https://hub.docker.com/_/redis

  • 6a81d494-bcc6-404d-8f2a-bef1e530314d-image.png

    Hello Wesley, i am doing great thanks for asking.

    actually, i am using digital ocean droplet with Plesk + Redis with docker

    i followed this guide and it solved the issue https://talk.plesk.com/threads/plesk-docker-redis-plesk-firewall-open-port-issue.352324/

    we need to install Redis docker using Plesk store BUT should run it using a specific command that limits its access to the local host only. (in your case you will install redis using command)

    Start the docker with,

    docker run --name=redis -p 127.0.0.1:6379:6379 redis
    

    d488b58b-e427-4c4e-9003-55ee1e1b35f9-image.png

    not sure this helps you or not but play with above command šŸ˜„

  • @phenomlab Hello, i have installed my redis on docker with this comand,
    docker run --name redis -p 6379:6379 -d -t redis:alpine
    And i don’t know how to access the redis.conf on docker image to make this step cited in email.
    Do you know how to do?
    I’m trying to search on documentation but i still can’t find it.

    @WesleyMoura any update ?

  • 6a81d494-bcc6-404d-8f2a-bef1e530314d-image.png

    Hello Wesley, i am doing great thanks for asking.

    actually, i am using digital ocean droplet with Plesk + Redis with docker

    i followed this guide and it solved the issue https://talk.plesk.com/threads/plesk-docker-redis-plesk-firewall-open-port-issue.352324/

    we need to install Redis docker using Plesk store BUT should run it using a specific command that limits its access to the local host only. (in your case you will install redis using command)

    Start the docker with,

    docker run --name=redis -p 127.0.0.1:6379:6379 redis
    

    d488b58b-e427-4c4e-9003-55ee1e1b35f9-image.png

    not sure this helps you or not but play with above command šŸ˜„

    @Hari said in How to restrict external access to Redis instance installed in a docker image:

    Hello Hari, sorry my delay in responding, but i already solved this problem, using exactly this command that you mentioned, docker run --name=redis -p 127.0.0.1:6379:6379 -d -t redis:alpine, in my case. But as i already had one image of redis, i had to remove the current redis from my docker and reinstall using this comand. Now when i test the port on https://www.yougetsignal.com/tools/open-ports/ with my ip and port of redis, the status of port is closed now. And now i just have to configure my firewall wich i will soon.
    So thanks to answer me and sorry again to delay in responding.

  • @phenomlab
    Sorry to delay in responding, yes as i mentioned above, i had to remove my redis from docker and reinstall a new image with this command

    docker run --name=redis -p 127.0.0.1:6379:6379 -d -t redis:alpine
    

    and now when i test my ip and port on
    https://www.yougetsignal.com/tools/open-ports/

    the status of my redis port is closed. I think which to configure firewall in droplet digital ocean is a good idea too, and i will configure soon.
    Thanks for the help!

  • phenomlabundefined phenomlab has marked this topic as solved on

Did this solution help you?
Did you find the suggested solution useful? Support šŸ’— Sudonix with a coffee ā˜•
If your organisation needs deeper expertise around infrastructure, security, or technology leadership, learn more about Phenomlab Ltd. Many of the deeper technical guides behind Sudonix are published there.

Related Topics
  • Bad information security advice

    Security linkedin security advice
    1
    1
    1 Votes
    1 Posts
    541 Views
    No one has replied
  • 12 Votes
    8 Posts
    2k Views
    @crazycells good question. Gmail being provided by Google is going to be one of the more secure by default out of the box, although you have to bear in mind that you can have the best security in the world, but that is easily diluted by user decision. Obviously, it makes sense to secure all cloud based services with at least 2fa protection, or better still, biometric if available, but email still remains vastly unprotected (unless enforced in the sense of 2fa, which I know Sendgrid do) because of user choice (in the sense that users will always go for the path of least resistance when it comes to security to make their lives easier). The ultimate side effect of taking this route is being vulnerable to credentials theft via phishing attacks and social engineering. The same principle would easily apply to Proton Mail, who also (from memory) do not enforce 2fa. Based on this fact, neither product is more secure than the other without one form of additional authentication at least being imposed. In terms of direct attack on the servers holding mail accounts themselves, this is a far less common type of attack these days as tricking the user is so much simpler than brute forcing a server where you are very likely to be detected by perimeter security (IDS / IPS etc).
  • www. Infront stops website access?

    Solved Configure nodebb
    10
    1 Votes
    10 Posts
    1k Views
    @Panda because there is no match for the DNS entry specified. The receiving web server parses the headers looking for a destination hostname to match, and anything the web server is unable to resolve will be sent back to the root.
  • NodeBB 3.0 alpha1 : Error on install

    Solved Configure nodebb version 3 install error
    19
    2 Votes
    19 Posts
    3k Views
    @phenomlab Work now
  • 19 Votes
    30 Posts
    4k Views
    @phenomlab 100%.
  • Do i need more RAM? Plesk

    Solved Performance plesk digitalocean
    3
    1
    1 Votes
    3 Posts
    852 Views
    @Hari welcome to Grafana, the most confusing stats package there is ! According to the guidelines, you certainly have enough RAM at 4gb https://www.plesk.com/blog/various/plesk-requirements-hardware-software/
  • Securing javascript -> PHP mysql calls on Website

    Solved Security php mysql security
    2
    1 Votes
    2 Posts
    1k Views
    @mike-jones Hi Mike, There are multiple answers to this, so I’m going to provide some of the most important ones here JS is a client side library, so you shouldn’t rely on it solely for validation. Any values collected by JS will need to be passed back to the PHP backend for processing, and will need to be fully sanitised first to ensure that your database is not exposed to SQL injection. In order to pass back those values into PHP, you’ll need to use something like <script> var myvalue = $('#id').val(); $(document).ready(function() { $.ajax({ type: "POST", url: "https://myserver/myfile.php?id=" + myvalue, success: function() { $("#targetdiv").load('myfile.php?id=myvalue #targetdiv', function() {}); }, //error: ajaxError }); return false; }); </script> Then collect that with PHP via a POST / GET request such as <?php $myvalue= $_GET['id']; echo "The value is " . $myvalue; ?> Of course, the above is a basic example, but is fully functional. Here, the risk level is low in the sense that you are not attempting to manipulate data, but simply request it. However, this in itself would still be vulnerable to SQL injection attack if the request is not sent as OOP (Object Orientated Programming). Here’s an example of how to get the data safely <?php function getid($theid) { global $db; $stmt = $db->prepare("SELECT *FROM data where id = ?"); $stmt->execute([$theid]); while ($result= $stmt->fetch(PDO::FETCH_ASSOC)){ $name = $result['name']; $address = $result['address']; $zip = $result['zip']; } return array( 'name' => $name, 'address' => $address, 'zip' => $zip ); } ?> Essentially, using the OOP method, we send placeholders rather than actual values. The job of the function is to check the request and automatically sanitise it to ensure we only return what is being asked for, and nothing else. This prevents typical injections such as ā€œAND 1=1ā€ which of course would land up returning everything which isn’t what you want at all for security reasons. When calling the function, you’d simply use <?php echo getid($myvalue); ?> @mike-jones said in Securing javascript -> PHP mysql calls on Website: i am pretty sure the user could just use the path to the php file and just type a web address into the search bar This is correct, although with no parameters, no data would be returned. You can actually prevent the PHP script from being called directly using something like <?php if(!defined('MyConst')) { die('Direct access not permitted'); } ?> then on the pages that you need to include it <?php define('MyConst', TRUE); ?> Obviously, access requests coming directly are not going via your chosen route, therefore, the connection will die because MyConst does not equal TRUE @mike-jones said in Securing javascript -> PHP mysql calls on Website: Would it be enough to just check if the number are a number 1-100 and if the drop down is one of the 5 specific words and then just not run the rest of the code if it doesn’t fit one of those perameters? In my view, no, as this will expose the PHP file to SQL injection attack without any server side checking. Hope this is of some use to start with. Happy to elaborate if you’d like.
  • 0 Votes
    1 Posts
    573 Views
    No one has replied