Portus icon indicating copy to clipboard operation
Portus copied to clipboard

Ldap auth through docker login uses DB stored Password

Open lokarlhorst opened this issue 11 years ago • 7 comments

After some tests we found this issue that login attempts from docker registry are using the database stored password. The ldap server isn't called by login attempts from docker registry.

The documentations points, that the password stored in db will not be used.

#   2. The 'password' is stored in the DB but it's not really used. This is
#      because the DB requires the password to not be blank, but in order to
#      authenticate we always want to check with the LDAP server.

At this point the auth fails and falls back to db auth in lib/portus/ldap.rb :

def load_configuration
      return nil if !::Portus::LDAP.enabled? || params[:user].nil?

Can you implement a solution to use ldap password check when logging in from docker-registry with

docker login -u username your.own.registry

?

lokarlhorst avatar Sep 11 '15 10:09 lokarlhorst

Can confirm. I'll work for a solution as soon as possible. Thanks for reporting :)

mssola avatar Sep 11 '15 12:09 mssola

If we use your solution there is another corresponding error with the crono job. It fails auth with accountname "portus". I think that the user "portus" should be authenticated through db.

We added return nil if !params[:account].nil? && params[:account] == "portus" to def load_configuration to ensure that user "portus" can be used for crono jobs or other auth queries.

return nil if !params[:account].nil? && params[:account] == "portus"

Can you add it to ldap.rb?

lokarlhorst avatar Sep 16 '15 13:09 lokarlhorst

Good catch! I'll leave that to @mssola

flavio avatar Sep 16 '15 13:09 flavio

The way you implemented the solution doesn't make sense if you want to prevent, that user portus can login via web interface. I think you have to make sure, that this will be impossible. In this case we added return nil if !params[:account].nil? to ensure it.

lokarlhorst avatar Sep 17 '15 05:09 lokarlhorst

@sotsy I think I don't follow your logic :) Let's see. The idea is that the Portus user has to authenticate always through the database. Therefore:

return nil if !::Portus::LDAP.enabled? || params[:account] == "portus"

That's enough to make sure that the Portus user won't be authenticated through LDAP. Since it returns nil, this means that the authentication will be done through the DB as usual. So, the way I see it, the !params[:account].nil? check is redundant, since params[:account] == "portus" already makes sure that this does not happen. You can argue that params[:account] won't be nil and not equal to portus if you are using your own RegistryClient instance with a different user. I'd say that's fine to authenticate with LDAP in this case (that would only happen in code inside of Portus, and we only use the portus user anyways).

The only problem here is that logging in through the DB is tied both to the web UI and the registry client class. This means that because we need to authenticate through the DB, as a side effect we can login with the portus user in the web ui. This, in my opinion, is a separate issue, and it should be handled in the code that deals with authentication through the DB, and not in the LDAP code.

@sotsy @flavio do you agree?

mssola avatar Sep 17 '15 08:09 mssola

Yes I agree with @mssola on that.

The fact you can log into the web UI using the "portus" user should be handled with another bug. Personally I don't think this would even be a serious bug because to log into the system you have to know the random password that is used by the "portus" user. If you have access to the file where the password is stored you also have access to other critical credentials (i.e. the database one); hence you can already mess with the system quite a lot...

flavio avatar Sep 17 '15 10:09 flavio

I agree with @mssola and @flavio

lokarlhorst avatar Sep 17 '15 11:09 lokarlhorst