riverrun / comeonin

Password hashing specification for the Elixir programming language

Home Page:https://hex.pm/packages/comeonin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

module Comeonin.Bcrypt is not available

qgadrian opened this issue · comments

Hi!

I'm having problems with this module, using it in a Docker image. When creating the container (I tried several base images, right now using the elixir:1.3.4) I run the commands mix deps.get and mix deps.compile, with succesful output.

The problem is when I'm running the Docker image, the following error is raised:

2017-04-03T18:59:11.085637157Z     ** (UndefinedFunctionError) function Comeonin.Bcrypt.dummy_checkpw/0 is undefined (module Comeonin.Bcrypt is not available)
2017-04-03T18:59:11.085640536Z         (comeonin) Comeonin.Bcrypt.dummy_checkpw()
2017-04-03T18:59:11.085644254Z         (vualala) web/repo/user_repo.ex:8: Vualala.UserRepo.check_login/1
2017-04-03T18:59:11.085648019Z         (vualala) web/controllers/auth_controller.ex:12: Vualala.AuthController.create/2
2017-04-03T18:59:11.085651728Z         (vualala) web/controllers/auth_controller.ex:1: Vualala.AuthController.action/2
2017-04-03T18:59:11.085655100Z         (vualala) web/controllers/auth_controller.ex:1: Vualala.AuthController.phoenix_controller_pipeline/2
2017-04-03T18:59:11.085658416Z         (vualala) lib/vualala/endpoint.ex:1: Vualala.Endpoint.instrument/4
2017-04-03T18:59:11.085661254Z         (vualala) lib/phoenix/router.ex:261: Vualala.Router.dispatch/2
2017-04-03T18:59:11.085686612Z         (vualala) web/router.ex:1: Vualala.Router.do_call/2
2017-04-03T18:59:11.085690145Z         (vualala) lib/vualala/endpoint.ex:1: Vualala.Endpoint.phoenix_pipeline/1
2017-04-03T18:59:11.085692888Z         (vualala) lib/plug/debugger.ex:123: Vualala.Endpoint."call (overridable 3)"/2
2017-04-03T18:59:11.085696032Z         (vualala) lib/vualala/endpoint.ex:1: Vualala.Endpoint.call/2
2017-04-03T18:59:11.085698894Z         (plug) lib/plug/adapters/cowboy/handler.ex:15: Plug.Adapters.Cowboy.Handler.upgrade/4
2017-04-03T18:59:11.085701712Z         (cowboy) /app/deps/cowboy/src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4

The compilation shoulkd be fine, and the application should work properly. Any idea about what is going on?

Thank you!

I'll try to get more info about how other people use Comeonin with Docker.

It looks like the C code is not being built / loaded properly.

Hi riverrun.

I made it work by making the comeonin app inside the docker image. Before doing that I was just doing a deps.compile.

I just added to the Dockerfile the following lines:

RUN cd deps/comeonin && make clean && make

I guess this issue can be closed, but would be great add this information to the README file for avoid this misunderstandings.

Thank you!

Thanks for letting me know. I'll add this info to the wiki and the docs, after which I'll close the issue.

Edited wiki page and added info to README. Thanks for reporting the issue.

Hi @qgadrian
I tried to use the way you suggested, but no luck.
Can you check my makefile: https://github.com/ionull/docker-edib-tool/blob/master/edib/make-app.mk
Thanks

Hi @ionull

Right now I'm just using a Dockerfile:

FROM elixir:1.3.4

// Other suff

RUN cd deps/comeonin && make clean && make

But might be because you are compiling the application after compiling this depdency.

Try to move to execute before the comeoin library this line $(IN_APP_DIR) MIX_ENV=$(MIX_ENV) mix compile.

Hope that will work.

@qgadrian Well, the elixir docker image works fine for me even without make comeonin. But still can't build it with edib (I tried your line switch suggestion as well) :(

@qgadrian Sorry, I forgot to add comeonin in applications (mix.exs). All is ok and easy on edib :) And the image is small, like 20M.

Of note, the command should read RUN cd deps/bcrypt_elixir && make clean && make

Thanks. I'll add that info to the wiki.

Nothing of this really helps.

Here is my Dockerfile, in any case. I can't run the compile instructions in the Dockerfile since the Phoenix app is created manually later inside the container, so deps/whatever doesn't exists on build time. But the files seems to compile anyway after.

I have added comeonin to mix.ex

# Type `mix help deps` for examples and options.
  defp deps do
    [{:phoenix, "~> 1.2.5"},
     {:phoenix_pubsub, "~> 1.0"},
     {:phoenix_ecto, "~> 3.0"},
     {:postgrex, ">= 0.0.0"},
     {:phoenix_html, "~> 2.6"},
     {:phoenix_live_reload, "~> 1.0", only: :dev},
     {:gettext, "~> 0.11"},
     {:cowboy, "~> 1.0"},
     {:bcrypt_elixir, "~> 1.0"},
     {:comeonin, "~> 2.0"}
     ]
  end

After I do docker-compose run web mix deps.get, the module are installed

Dependency resolution completed:
  bcrypt_elixir 1.0.4
  comeonin 2.6.0
 #...

And when I run docker-compose up after getting my deps:

 ==> bcrypt_elixir
web_1  | mkdir -p priv
web_1  | cc -g -O3 -Wall -I/usr/local/lib/erlang/erts-8.3.5.3/include -Ic_src -fPIC -shared  c_src/bcrypt_nif.c c_src/blowfish.c -o priv/bcrypt_nif.so
web_1  | Compiling 3 files (.ex)
web_1  | Generated bcrypt_elixir app

which means it compiles the C dependencies. But when compiling the code where I'm actually using Comeonin:

warning: function Comeonin.BCrypt.hashpwsalt/1 is undefined (module Comeonin.BCrypt is not available)
web_1  |   web/models/user.ex:30

What I am doing wrong?

Could you update to Comeonin version 4 and try again?

Also, Bcrypt seems to be spelled wrong in the error message - it's not BCrypt, it's Bcrypt.

@riverrun, after following your advice, it now seems to work. I think it was due to a typo on my part, but I also updated the module to version 4. To everyone reading this in the future, check the spelling of Bcrypt!

Cool. Glad to hear you got it working.

Hi @riverrun I have a problem with comeonin as well. I currently run RUN cd deps/bcrypt_elixir && make clean && make inside of my dockerfile, but I get this error everytime I call the function Comeonin.Bcrypt.hashpwsalt(MY_PASSWORD). function Bcrypt.Base.gensalt_nif/3 is undefined (module Bcrypt.Base is not available) Any idea why?

@sc4224 do you have bcrypt_elixir in your deps in the mix file? If that's not the problem, please open a new issue, and I'll look into it.