shahryarjb

shahryarjb

Using micro service isn’t easy for me, unfortunately :frowning_face:. I have a problem to use external api in my services.
Considering I need to connect to the google Recaptcha, but I can’t, because my server is dockeriz.

for example please see these pictures:

and

nginx_master is my container’s name instead of my container’s IP

Although I used a proxy which is my Nginix container but I have an error, how can I fix it ? by the way if I don’t give internet to the elixir html container, it won’t be able to connect to google Recapcha api, but I need to isolate this without internet, because there is a nginx proxy.

and my second problem is how I can use external api in my private microservices behind my api gate way. I don’t want to give an internet to the private container and I need to use a safe proxy.

Thank you

Showing Posts 1 to 10

OvermindDL1

OvermindDL1

Uh, I don’t think nginx can work as a socks proxy, at least I’ve never tried? Why can’t it access straight out or through a tunnel, or reverse proxy recaptcha or so?

EDIT: Apparently there is a socks plugin for nginx, did you compile it in? It looks like it might be a bit out of date too…

shahryarjb

shahryarjb OP

i’m confused, if I don’t give internet to the elixir container, it can’t connect to google api. if I give it to the elixir container, may it have a security problem because it can’t be isolate? what is your suggestion, generally?

I don’t know why it does!!!

OvermindDL1

OvermindDL1

Well if it needs internet access then that needs to be supplied somehow. A single outgoing port and then binding to it for your outgoing connections (or a pool of them) seems perfectly sufficient since no incoming connections would be allowed? Or if you need an incoming connection too then a single port for that or whatever. :slight_smile:

shahryarjb

shahryarjb OP

if I understood what you said, I should create a firewall rule to filter this container internet , shouldn’t I ? if your answer is okay, would you mind telling me how I can do this ? because I tried to create iptables rule to filter and limit to just Google Api, but I couldn’t !!

my docker network was linked by internal domain like: http://elixir_api or http://elixir_html, how can I filter its internet for example http://elixir_html, that it just send and receive from google not another domain

Thanks

OvermindDL1

OvermindDL1

Docker can do it all fine already, just expose the specific port you want to listen in for incoming connections (if any) and just let it communicate ‘out’ via a bridge network to the host. :slight_smile:

Are you actually wanting to restrict it to specific domains only? A reverse proxy would be safer there.

shahryarjb

shahryarjb OP

Thanks, I set rule in iptables, but I couldn’t find anything about you told me, I can expose port from docker but I cant set up in nginx, how can I do? would you mind giving me a reference or tutorial?

OvermindDL1

OvermindDL1

Well what are the very specific requirements you are needing first?

Do you need incoming connections, outgoing connections, both? Do they need to be restricted to very specific sets of IP’s, domains, data, etc…? Etc…

shahryarjb

shahryarjb OP

I do not have much information, but I just need to filter my internet that it is forced to load google not another site or ip . I need incoming connections and outgoing connections, both, but just from google recaptcha api, I want my internet to be filtered to load , Only Google ip or api domain .

can I describe my need well?

OvermindDL1

OvermindDL1

That then begs the question, ‘what’ is making the remote API call, is it your own controlled code or some untrusted user code?

shahryarjb

shahryarjb OP

User send me a Recapcha code that google js file creates and then I send this code to the google api

the code sender:

  def google_post_recap(root_link, params) do
    body = "secret=#{params["secret"]}&response=#{params["response"]}"
    HTTPoison.post(
      "#{root_link}",
       body,
        [
          {"Content-Type", "application/x-www-form-urlencoded"},
          {"Accept", "text/html"}
        ],
       [timeout: 50_000, recv_timeout: 50_000]
    )
  end

and

  # login sender
  def login_register_sender(conn, %{"email" => _email, "password" => _password}  = info_of_login) do

    ip_os = TrangellHtmlSite.ip_os(conn)
    info_map = User.login_mapper(info_of_login)
    with {:ok, %HTTPoison.Response{status_code: 200, body: body_of_token}} <- TrangellHtmlSite.User.google_recap(info_of_login["g-recaptcha-response"]),
    %{"challenge_ts" => _time, "hostname" => _host, "success" => true} <- Jason.decode!(body_of_token),
    {:ok, %HTTPoison.Response{status_code: 200, body: _user_info}} <- User.login_sender(info_map, ip_os.ip, ip_os.os) do

      conn
      |> put_flash(:info, "کد فعال سازی دو مرحله ای برای شما ایمیل گردید لطفا به ایمیل خود مراجعه کرده و در فرم زیر کد مذکور به همراه ایمیل خود وارد کنید")
      |> redirect( to: "/verify-code")
    end
  end

  # google
  def google_recap(response) do
    TrangellHtmlSite.google_post_recap("https://www.google.com/recaptcha/api/siteverify", %{"secret" => "MY secret code", "response" => response}) 
    |> IO.inspect
  end

after those codes google send me a Json that I use like this

{:ok,
 %HTTPoison.Response{
   body: "{\n  \"success\": true,\n  \"challenge_ts\": \"2018-10-31T20:38:43Z\",\n  \"hostname\": \"localhost\"\n}",
   headers: [
     {"Content-Type", "application/json; charset=utf-8"},
     {"Date", "Wed, 31 Oct 2018 20:40:01 GMT"},
     {"Expires", "Wed, 31 Oct 2018 20:40:01 GMT"},
     {"Cache-Control", "private, max-age=0"},
     {"X-Content-Type-Options", "nosniff"},
     {"X-XSS-Protection", "1; mode=block"},
     {"Server", "GSE"},
     {"Alt-Svc", "quic=\":443\"; ma=2592000; v=\"44,43,39,35\""},
     {"Accept-Ranges", "none"},
     {"Vary", "Accept-Encoding"},
     {"Transfer-Encoding", "chunked"}
   ],
   request_url: "https://www.google.com/recaptcha/api/siteverify",
   status_code: 200
 }}

all of my code is that, I think that user sent code can be untrusted but google decides to verify or unverify

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews