Restrict outside access to dockerSteps for limiting outside connections to docker container with iptables?iptables port forwardingiptables REDIRECT scopeiptables - quick safety eval & limit max conns over timeHelp With IPTables: Traffic Forced To Specific NIC?RHEL 6 Having issues forwarding port 80 to port 8080Connect AWS and Azure via OpenVPNCan't access docker bind port from public IPopenvpn: can't manage to control client-to-client connections with iptables(dnat|redirect) with masquerade doesn't workIPtables blocking SSH only if using conntrack

Which big number is bigger?

Constructions of PRF (Pseudo Random Function)

Like totally amazing interchangeable sister outfits II: The Revenge

How do I reattach a shelf to the wall when it ripped out of the wall?

What happens in the secondary winding if there's no spark plug connected?

Implications of cigar-shaped bodies having rings?

Check if a string is entirely made of the same substring

"You've called the wrong number" or "You called the wrong number"

On The Origin of Dissonant Chords

Alignment of various blocks in tikz

How can I print the prosodic symbols in LaTeX?

How to write a column outside the braces in a matrix?

How to have a sharp product image?

How exactly does Hawking radiation decrease the mass of black holes?

What term is being referred to with "reflected-sound-of-underground-spirits"?

Minor Revision with suggestion of an alternative proof by reviewer

'It addicted me, with one taste.' Can 'addict' be used transitively?

Does tea made with boiling water cool faster than tea made with boiled (but still hot) water?

How to pronounce 'c++' in Spanish

Can an Area of Effect spell cast outside a Prismatic Wall extend inside it?

Why did C use the -> operator instead of reusing the . operator?

How can the Githyanki Supreme Commander move while insubstantial?

Why do games have consumables?

"Hidden" theta-term in Hamiltonian formulation of Yang-Mills theory



Restrict outside access to docker


Steps for limiting outside connections to docker container with iptables?iptables port forwardingiptables REDIRECT scopeiptables - quick safety eval & limit max conns over timeHelp With IPTables: Traffic Forced To Specific NIC?RHEL 6 Having issues forwarding port 80 to port 8080Connect AWS and Azure via OpenVPNCan't access docker bind port from public IPopenvpn: can't manage to control client-to-client connections with iptables(dnat|redirect) with masquerade doesn't workIPtables blocking SSH only if using conntrack






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have some difficulties figuring out how to correctly restrict outside access to docker containers.



So far I was using multiple user-defined bridges and exposed HTTP/HTTPS ports.



For example I had:



docker-net-1:
0.0.0.0:9080->80/tcp, 0.0.0.0:9443->443/tcp

docker-net-2:
0.0.0.0:8380->80/tcp


I then used a reverse proxy on my docker host to provide outside access via port 443 to the different services using name based virtual hosts and making sure everything goes via https.



To prevent direct access to the exposed ports I used the DOCKER-USER chain in iptables.



-A DOCKER-USER -i eth0 -m conntrack --ctstate ESTABLISHED,RELATED -j RETURN
-A DOCKER-USER -i eth0 -j DROP


Now I need to host 2 more applications. They are in separate networks but both expose port 22.



0.0.0.0:9022->22/tcp
0.0.0.0:9122->22/tcp


The tricky part for me now is that I need different firewall rules for those ports.



What I tried so far:




  1. Proxy



    As it is SSH I do not see how it can be easily done




  2. Opening port in DOCKER-USER - 1st attempt



    As per default external access is disabled in my DOCKER-USER I added the follwing:



    -A DOCKER-USER -p tcp -m tcp --dport 9022 -j RETURN
    -A DOCKER-USER -p tcp -m tcp --dport 9122 -j RETURN
    -A DOCKER-USER -i eth0 -m conntrack --ctstate ESTABLISHED,RELATED -j RETURN
    -A DOCKER-USER -i eth0 -j DROP


    Those first 2 rules however never got any hit.




  3. Opening port in DOCKER-USER - 2nd attempt



    When looking at the iptables chains again it became clear that at this point the port is not 9022 but 22.



    -A DOCKER-USER -p tcp -m tcp --dport 22 -j RETURN


    which works as expected.




  4. Opening port in DOCKER-USER - 3rd attempt



    I thought about using the additional network interfaces or ip subnets created by docker to distinguish between the two different applications, but the names of the network interfaces seem like randomly created and the IP addresses are probably also not a good way of solving the problem as those addresses change like the network names when recreated.



What now?



What is the best solution here? Ideally I do not want something that breaks when services are restarted, like manipulating existing DOCKER chains or using IPs that change.










share|improve this question






















  • We have the same problem. Did you found any solution for this?

    – Stepan Kokhanovskiy
    Apr 19 at 9:01











  • Don't expose ports that you don't want accessible outside. That is what exposing is for.

    – Michael Hampton
    Apr 19 at 15:50


















0















I have some difficulties figuring out how to correctly restrict outside access to docker containers.



So far I was using multiple user-defined bridges and exposed HTTP/HTTPS ports.



For example I had:



docker-net-1:
0.0.0.0:9080->80/tcp, 0.0.0.0:9443->443/tcp

docker-net-2:
0.0.0.0:8380->80/tcp


I then used a reverse proxy on my docker host to provide outside access via port 443 to the different services using name based virtual hosts and making sure everything goes via https.



To prevent direct access to the exposed ports I used the DOCKER-USER chain in iptables.



-A DOCKER-USER -i eth0 -m conntrack --ctstate ESTABLISHED,RELATED -j RETURN
-A DOCKER-USER -i eth0 -j DROP


Now I need to host 2 more applications. They are in separate networks but both expose port 22.



0.0.0.0:9022->22/tcp
0.0.0.0:9122->22/tcp


The tricky part for me now is that I need different firewall rules for those ports.



What I tried so far:




  1. Proxy



    As it is SSH I do not see how it can be easily done




  2. Opening port in DOCKER-USER - 1st attempt



    As per default external access is disabled in my DOCKER-USER I added the follwing:



    -A DOCKER-USER -p tcp -m tcp --dport 9022 -j RETURN
    -A DOCKER-USER -p tcp -m tcp --dport 9122 -j RETURN
    -A DOCKER-USER -i eth0 -m conntrack --ctstate ESTABLISHED,RELATED -j RETURN
    -A DOCKER-USER -i eth0 -j DROP


    Those first 2 rules however never got any hit.




  3. Opening port in DOCKER-USER - 2nd attempt



    When looking at the iptables chains again it became clear that at this point the port is not 9022 but 22.



    -A DOCKER-USER -p tcp -m tcp --dport 22 -j RETURN


    which works as expected.




  4. Opening port in DOCKER-USER - 3rd attempt



    I thought about using the additional network interfaces or ip subnets created by docker to distinguish between the two different applications, but the names of the network interfaces seem like randomly created and the IP addresses are probably also not a good way of solving the problem as those addresses change like the network names when recreated.



What now?



What is the best solution here? Ideally I do not want something that breaks when services are restarted, like manipulating existing DOCKER chains or using IPs that change.










share|improve this question






















  • We have the same problem. Did you found any solution for this?

    – Stepan Kokhanovskiy
    Apr 19 at 9:01











  • Don't expose ports that you don't want accessible outside. That is what exposing is for.

    – Michael Hampton
    Apr 19 at 15:50














0












0








0








I have some difficulties figuring out how to correctly restrict outside access to docker containers.



So far I was using multiple user-defined bridges and exposed HTTP/HTTPS ports.



For example I had:



docker-net-1:
0.0.0.0:9080->80/tcp, 0.0.0.0:9443->443/tcp

docker-net-2:
0.0.0.0:8380->80/tcp


I then used a reverse proxy on my docker host to provide outside access via port 443 to the different services using name based virtual hosts and making sure everything goes via https.



To prevent direct access to the exposed ports I used the DOCKER-USER chain in iptables.



-A DOCKER-USER -i eth0 -m conntrack --ctstate ESTABLISHED,RELATED -j RETURN
-A DOCKER-USER -i eth0 -j DROP


Now I need to host 2 more applications. They are in separate networks but both expose port 22.



0.0.0.0:9022->22/tcp
0.0.0.0:9122->22/tcp


The tricky part for me now is that I need different firewall rules for those ports.



What I tried so far:




  1. Proxy



    As it is SSH I do not see how it can be easily done




  2. Opening port in DOCKER-USER - 1st attempt



    As per default external access is disabled in my DOCKER-USER I added the follwing:



    -A DOCKER-USER -p tcp -m tcp --dport 9022 -j RETURN
    -A DOCKER-USER -p tcp -m tcp --dport 9122 -j RETURN
    -A DOCKER-USER -i eth0 -m conntrack --ctstate ESTABLISHED,RELATED -j RETURN
    -A DOCKER-USER -i eth0 -j DROP


    Those first 2 rules however never got any hit.




  3. Opening port in DOCKER-USER - 2nd attempt



    When looking at the iptables chains again it became clear that at this point the port is not 9022 but 22.



    -A DOCKER-USER -p tcp -m tcp --dport 22 -j RETURN


    which works as expected.




  4. Opening port in DOCKER-USER - 3rd attempt



    I thought about using the additional network interfaces or ip subnets created by docker to distinguish between the two different applications, but the names of the network interfaces seem like randomly created and the IP addresses are probably also not a good way of solving the problem as those addresses change like the network names when recreated.



What now?



What is the best solution here? Ideally I do not want something that breaks when services are restarted, like manipulating existing DOCKER chains or using IPs that change.










share|improve this question














I have some difficulties figuring out how to correctly restrict outside access to docker containers.



So far I was using multiple user-defined bridges and exposed HTTP/HTTPS ports.



For example I had:



docker-net-1:
0.0.0.0:9080->80/tcp, 0.0.0.0:9443->443/tcp

docker-net-2:
0.0.0.0:8380->80/tcp


I then used a reverse proxy on my docker host to provide outside access via port 443 to the different services using name based virtual hosts and making sure everything goes via https.



To prevent direct access to the exposed ports I used the DOCKER-USER chain in iptables.



-A DOCKER-USER -i eth0 -m conntrack --ctstate ESTABLISHED,RELATED -j RETURN
-A DOCKER-USER -i eth0 -j DROP


Now I need to host 2 more applications. They are in separate networks but both expose port 22.



0.0.0.0:9022->22/tcp
0.0.0.0:9122->22/tcp


The tricky part for me now is that I need different firewall rules for those ports.



What I tried so far:




  1. Proxy



    As it is SSH I do not see how it can be easily done




  2. Opening port in DOCKER-USER - 1st attempt



    As per default external access is disabled in my DOCKER-USER I added the follwing:



    -A DOCKER-USER -p tcp -m tcp --dport 9022 -j RETURN
    -A DOCKER-USER -p tcp -m tcp --dport 9122 -j RETURN
    -A DOCKER-USER -i eth0 -m conntrack --ctstate ESTABLISHED,RELATED -j RETURN
    -A DOCKER-USER -i eth0 -j DROP


    Those first 2 rules however never got any hit.




  3. Opening port in DOCKER-USER - 2nd attempt



    When looking at the iptables chains again it became clear that at this point the port is not 9022 but 22.



    -A DOCKER-USER -p tcp -m tcp --dport 22 -j RETURN


    which works as expected.




  4. Opening port in DOCKER-USER - 3rd attempt



    I thought about using the additional network interfaces or ip subnets created by docker to distinguish between the two different applications, but the names of the network interfaces seem like randomly created and the IP addresses are probably also not a good way of solving the problem as those addresses change like the network names when recreated.



What now?



What is the best solution here? Ideally I do not want something that breaks when services are restarted, like manipulating existing DOCKER chains or using IPs that change.







iptables docker






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Sep 16 '18 at 11:57









MuhKuhMuhKuh

1163




1163












  • We have the same problem. Did you found any solution for this?

    – Stepan Kokhanovskiy
    Apr 19 at 9:01











  • Don't expose ports that you don't want accessible outside. That is what exposing is for.

    – Michael Hampton
    Apr 19 at 15:50


















  • We have the same problem. Did you found any solution for this?

    – Stepan Kokhanovskiy
    Apr 19 at 9:01











  • Don't expose ports that you don't want accessible outside. That is what exposing is for.

    – Michael Hampton
    Apr 19 at 15:50

















We have the same problem. Did you found any solution for this?

– Stepan Kokhanovskiy
Apr 19 at 9:01





We have the same problem. Did you found any solution for this?

– Stepan Kokhanovskiy
Apr 19 at 9:01













Don't expose ports that you don't want accessible outside. That is what exposing is for.

– Michael Hampton
Apr 19 at 15:50






Don't expose ports that you don't want accessible outside. That is what exposing is for.

– Michael Hampton
Apr 19 at 15:50











1 Answer
1






active

oldest

votes


















0














You should use -m conntrack --ctorigdstport 9022 instead --dport 9022.



More infornation here: https://serverfault.com/a/933803/335954.






share|improve this answer























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "2"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f931139%2frestrict-outside-access-to-docker%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    You should use -m conntrack --ctorigdstport 9022 instead --dport 9022.



    More infornation here: https://serverfault.com/a/933803/335954.






    share|improve this answer



























      0














      You should use -m conntrack --ctorigdstport 9022 instead --dport 9022.



      More infornation here: https://serverfault.com/a/933803/335954.






      share|improve this answer

























        0












        0








        0







        You should use -m conntrack --ctorigdstport 9022 instead --dport 9022.



        More infornation here: https://serverfault.com/a/933803/335954.






        share|improve this answer













        You should use -m conntrack --ctorigdstport 9022 instead --dport 9022.



        More infornation here: https://serverfault.com/a/933803/335954.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Apr 19 at 11:59









        Stepan KokhanovskiyStepan Kokhanovskiy

        1033




        1033



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Server Fault!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f931139%2frestrict-outside-access-to-docker%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How to write a 12-bar blues melodyI-IV-V blues progressionHow to play the bridges in a standard blues progressionHow does Gdim7 fit in C# minor?question on a certain chord progressionMusicology of Melody12 bar blues, spread rhythm: alternative to 6th chord to avoid finger stretchChord progressions/ Root key/ MelodiesHow to put chords (POP-EDM) under a given lead vocal melody (starting from a good knowledge in music theory)Are there “rules” for improvising with the minor pentatonic scale over 12-bar shuffle?Confusion about blues scale and chords

            What if the end-user didn't have the required library?What is setup.py?What is a clean, pythonic way to have multiple constructors in Python?What does Ruby have that Python doesn't, and vice versa?What is the reason for having '//' in Python?How do I create a namespace package in Python?How to package shared objects that python modules depend on?setuptools vs. distutils: why is distutils still a thing?Navigation in Windows 10 vs code not going to virtualenv library when the same library is installed at user levelPython create package for local usePackaging a project that uses multiple python versionsWhy is permission denied on pip install except for when “--user” is included at end of command?

            Esgonzo ibérico Índice Descrición Distribución Hábitat Ameazas Notas Véxase tamén "Acerca dos nomes dos anfibios e réptiles galegos""Chalcides bedriagai"Chalcides bedriagai en Carrascal, L. M. Salvador, A. (Eds). Enciclopedia virtual de los vertebrados españoles. Museo Nacional de Ciencias Naturales, Madrid. España.Fotos