Skip to content

Ldap authentication#369

Open
jdoucerain wants to merge 28 commits into
jpillora:masterfrom
jdoucerain:LDAP-authentication
Open

Ldap authentication#369
jdoucerain wants to merge 28 commits into
jpillora:masterfrom
jdoucerain:LDAP-authentication

Conversation

@jdoucerain

Copy link
Copy Markdown

This PR is to allow LDAP authentication of chisel client.
The chisel server ldap configuration is maintained in a file pointed by the --ldap-config option
The ldap-config file structure is as follow:
BindDN for non anonymous search
BindPassword for non anonymous search
Url ldap server url
BaseDN for search
Filter ldap objects filter
IDMapTo ldap attribute used as id
CA file containing the PEM formatted certificates to trust when connecting to ldap server
Insecure true if we skip the certificates validation

The users are authentication against the ldap server.
The authorization pattern is unchanged (in authfile)
In the auth file we maintain the userid and the remotes. The password is left to an empty string

@kblanckaert

Copy link
Copy Markdown

Hi,

Interesting feature!
Would really like to see this added as well, but I wouldn't completely disable the password authentication functionality once LDAP configuration is in place.

The documentation about how to use this could also be made more clear:

  • An example of the ldap.json configuration file
  • The fact that the LDAP users have to be added to the users.json file
  • The fact that LDAP over port 389 doesn't seem to work (TLS issues when trying)

I've added some comments about the above mentioned improvements in your code.

Comment thread README.md
Comment thread server/server.go Outdated
@kblanckaert

Copy link
Copy Markdown

@jpillora Can you merge this please? Thanks!

@jpillora jpillora left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable from a quick glance

Would be great if we could flatten the 5 deep if-else blocks

Also what’s the binary size difference after importing ldap v3?

@kblanckaert

Copy link
Copy Markdown

binary size difference: 12214.113 KB (master) -> 12397.106 KB (ldap-authentication)

Comment thread server/server.go
… to both rely on local or LDAP authentication
@jdoucerain

Copy link
Copy Markdown
Author

@jpillora could you please have a look at the bit improved version of the password validation ?
Thanks

Comment thread README.md Outdated
Comment thread README.md Outdated

<!--tmpl,code=plain:echo "$ chisel client --help" && go run main.go client --help | sed 's#0.0.0-src (go1\..*)#X.Y.Z#' -->
``` plain
``` plain

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these spacing edits come from your IDE i think,
can we revert them to reduce the size of the change set

easiest way is to execute the markdown template https://github.com/jpillora/md-tmpl

Comment thread share/settings/ldap.go
Comment thread share/settings/ldap.go Outdated
Comment thread server/server.go Outdated
Comment thread share/settings/ldap.go Outdated
}

// Ldap Connection with TLS
func ConnectTLS(ldapconfig LdapConfig) (*ldap.Conn, error) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we unexport ConnectTLS and any other functions that arent used

Comment thread main.go Outdated
Comment thread server/server.go Outdated
if !found || user.Pass != string(password) {
s.Debugf("Login failed for user: %s", n)
return nil, errors.New("Invalid authentication for username: %s")
if (found && string(password) != "") {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

although the users config file acts as a nice whitelist and access control, its not technically required - ldap can tell us both, if a user exists, and if the password is correct. should it work no users defined?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My opinion on this is the following:
if we want to use LDAP to only authenticate and forget about authorization, I think it should be explicitly mentioned with an additional flag to avoid confusion.
Now from the enterprise perspective (which was coming with the LDAP authentication) I am not seeing the only authentication and no authorization as a use-case and if I may I would deal with this as a separate change.

@jdoucerain

Copy link
Copy Markdown
Author

@jpillora thanks for the review you did and I tried to follow what you said.
Could you please review this change again ?
Thanks again

@jpillora

Copy link
Copy Markdown
Owner

Sorry @jdoucerain I was going to merge a bunch of PRs and release though tests are broken for latest versions of Go and I haven't had time to fix them #390

@jdoucerain

Copy link
Copy Markdown
Author

Hi @jpillora would you have some time to check if you could merge this branch ?

@jdoucerain

Copy link
Copy Markdown
Author

Hi @jpillora could you please check if you could merge this branch ? Thanks

Signed-off-by: Jerome Doucerain <jerome.doucerain@bell.ca>
@jpillora

jpillora commented Jul 8, 2023

Copy link
Copy Markdown
Owner

Looks pretty good, will try take a look toknight

I think the server config should only have the ldap config, the path string should be in main (cli code) - settings can export a LoadLDAP(path) LDAPConfig which is used my main, and by server package consumers

I’m happy to do this change if you’d like

@jdoucerain

Copy link
Copy Markdown
Author

@jpillora please go ahead if you have some bandwidth. Thanks

@jpillora

jpillora commented Jul 9, 2023

Copy link
Copy Markdown
Owner

looking at the is PR now. it appears you still have to define users in the --auth or --authfile, and the "local" password still works. ldap just adds an additional password that will now work. can you confirm this is correct and intended?

@jpillora

jpillora commented Jul 9, 2023

Copy link
Copy Markdown
Owner

IMO, i think ldap should work in either one of two ways:

  1. using ldap should be used if the local user is not found. so by default all user attempts use ldap. config.AllowedUsers []string could be added to whitelist users. maybe you could place remote configuration as a user attribute? otherwise all remotes are allowed
  2. using ldap should force all "local" passwords to be blank. must be --auth foo if --auth foo:bar then fails to start. similarly with --authfile

jpillora added a commit that referenced this pull request Jul 9, 2023
commit 8786463
Author: Jerome Doucerain <jerome.doucerain@bell.ca>
Date:   Fri Jul 7 19:16:27 2023 -0400

    fix unreachable code

    Signed-off-by: Jerome Doucerain <jerome.doucerain@bell.ca>

commit 3a6f13c
Author: Jerome Doucerain <jerome.doucerain@bell.ca>
Date:   Fri Jul 7 17:22:12 2023 -0400

    update README.md with features from master upstream branch

    Signed-off-by: Jerome Doucerain <jerome.doucerain@bell.ca>

commit 3f92a77
Merge: 6b87e3f ce307e5
Author: Jerome Doucerain <jerome.doucerain@bell.ca>
Date:   Fri Jul 7 16:45:51 2023 -0400

    Merge branch 'master' of https://github.com/jpillora/chisel into LDAP-authentication

commit 6b87e3f
Author: Jerome Doucerain <jerome.doucerain@bell.ca>
Date:   Fri Nov 25 16:52:56 2022 -0500

    MD again

commit b66e317
Author: Jerome Doucerain <jerome.doucerain@bell.ca>
Date:   Fri Nov 25 16:50:20 2022 -0500

    markdown adjustments

commit 62920af
Merge: 3e05ec5 8f96052
Author: Jerome Doucerain <jerome.doucerain@bell.ca>
Date:   Fri Nov 25 16:34:44 2022 -0500

    Merge branch 'LDAP-authentication' of https://github.com/jdoucerain/chisel into LDAP-authentication

commit 3e05ec5
Author: Jerome Doucerain <jerome.doucerain@bell.ca>
Date:   Fri Nov 25 16:14:53 2022 -0500

    markdown adjustments

commit 659c06d
Author: Jerome Doucerain <jerome.doucerain@bell.ca>
Date:   Fri Nov 25 16:10:52 2022 -0500

    markdown adjustments

commit cfb1d00
Author: Jerome Doucerain <jerome.doucerain@bell.ca>
Date:   Fri Nov 25 15:58:32 2022 -0500

    Changes as recommended by J.Pillora

commit 69a8ce0
Author: Jerome Doucerain <jerome.doucerain@bell.ca>
Date:   Wed Oct 19 12:04:33 2022 -0400

    a bit improved version of the password validation keeping the ability to both rely on local or LDAP authentication

commit 40da157
Author: Jerome Doucerain <jerome.doucerain@bell.ca>
Date:   Tue Oct 18 10:59:02 2022 -0400

    allow combination of both LDAP and local authentication and give ldap-config example

commit 4708fe1
Author: Jerome Doucerain <jerome.doucerain@bell.ca>
Date:   Wed Jun 29 19:33:27 2022 -0400

    ca file debug

commit 92b20ba
Author: Jerome Doucerain <jerome.doucerain@bell.ca>
Date:   Wed Jun 29 18:51:14 2022 -0400

    add user in debugging log when too many entries

commit ba54e8d
Author: Jerome Doucerain <jerome.doucerain@bell.ca>
Date:   Wed Jun 29 18:43:24 2022 -0400

    remove comments in ldap.go

commit 505ba02
Author: Jerome Doucerain <jerome.doucerain@bell.ca>
Date:   Wed Jun 29 18:39:23 2022 -0400

    new --ldap-config in README.md

commit 111b545
Author: Jerome Doucerain <jerome.doucerain@bell.ca>
Date:   Wed Jun 29 18:33:57 2022 -0400

    ldap authentication

    Signed-off-by: Jerome Doucerain <jerome.doucerain@bell.ca>

commit 8f96052
Author: Jerome Doucerain <jerome.doucerain@bell.ca>
Date:   Fri Nov 25 16:14:53 2022 -0500

    markdown adjustments

commit 2d7c977
Author: Jerome Doucerain <jerome.doucerain@bell.ca>
Date:   Fri Nov 25 16:10:52 2022 -0500

    markdown adjustments

commit 7c0e741
Author: Jerome Doucerain <jerome.doucerain@bell.ca>
Date:   Fri Nov 25 15:58:32 2022 -0500

    Changes as recommended by J.Pillora

commit f7cdb96
Author: Jerome Doucerain <jerome.doucerain@bell.ca>
Date:   Wed Oct 19 12:04:33 2022 -0400

    a bit improved version of the password validation keeping the ability to both rely on local or LDAP authentication

commit 00836b1
Author: Jerome Doucerain <jerome.doucerain@bell.ca>
Date:   Tue Oct 18 10:59:02 2022 -0400

    allow combination of both LDAP and local authentication and give ldap-config example

commit 6f7bc5d
Merge: 79c0a67 bea4540
Author: jdoucerain <jerome.doucerain@bell.ca>
Date:   Tue Oct 18 09:53:06 2022 -0400

    Merge branch 'jpillora:master' into LDAP-authentication

commit 79c0a67
Author: Jerome Doucerain <jerome.doucerain@bell.ca>
Date:   Wed Jun 29 19:33:27 2022 -0400

    ca file debug

commit 5b77520
Author: Jerome Doucerain <jerome.doucerain@bell.ca>
Date:   Wed Jun 29 18:51:14 2022 -0400

    add user in debugging log when too many entries

commit 6c50813
Author: Jerome Doucerain <jerome.doucerain@bell.ca>
Date:   Wed Jun 29 18:43:24 2022 -0400

    remove comments in ldap.go

commit 4bc9fc4
Author: Jerome Doucerain <jerome.doucerain@bell.ca>
Date:   Wed Jun 29 18:39:23 2022 -0400

    new --ldap-config in README.md

commit 6c1f269
Author: Jerome Doucerain <jerome.doucerain@bell.ca>
Date:   Wed Jun 29 18:33:57 2022 -0400

    ldap authentication

    Signed-off-by: Jerome Doucerain <jerome.doucerain@bell.ca>
@jdoucerain

Copy link
Copy Markdown
Author

looking at the is PR now. it appears you still have to define users in the --auth or --authfile, and the "local" password still works. ldap just adds an additional password that will now work. can you confirm this is correct and intended?

@jdoucerain

Copy link
Copy Markdown
Author

Yes this is intentional. We have to cover case where the users could or could not be in the enterprise directory.

@jdoucerain

Copy link
Copy Markdown
Author

And the presence in the directory is not enough for us to allow anyone to use chisel. This is why we are maintaining the authfile for each individual. This is our use case.

@jdoucerain

jdoucerain commented Jul 9, 2023

Copy link
Copy Markdown
Author

I think using ldap as authentication only and applying a default parameterized remote is another use case to be developed.
And limiting the authentication to ldap only and blocking the ability to authenticate with local password when ldap is active is also another use case.

@jpillora

jpillora commented Jul 9, 2023

Copy link
Copy Markdown
Owner

gotcha, would you prefer option 2?

I’m finding it hard to see a good use case for two passwords

@jdoucerain

jdoucerain commented Jul 9, 2023

Copy link
Copy Markdown
Author

Yes I agree with option 2
I will update the PR consequently

@jdoucerain

Copy link
Copy Markdown
Author

@jpillora option 2 (using ldap should force all "local" passwords to be blank. must be --auth foo if --auth foo:bar then fails to start. similarly with --authfile) is implemented.

@jpillora

jpillora commented Jul 11, 2023 via email

Copy link
Copy Markdown
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants