Active Directory not working #4074

Closed
opened 2025-11-02 05:36:42 -06:00 by GiteaMirror · 17 comments
Owner

Originally created by @Mr-Reca on GitHub (Oct 7, 2019).

  • Gitea version (or commit ref): gitea:latest from Docker
  • Git version: gitea:latest from Docker
  • Operating system:
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant
  • Log gist:

Description

I'm trying to configure AD Authentication. I followed all guides on Internet, but the output is the same:

2019/10/07 15:26:12 ...dels/login_source.go:717:UserSignIn() [W] Failed to login '<username>' via 'AD': user does not exist [uid: 0, name: <username>, keyid: 0]
2019/10/07 15:26:12 routers/user/auth.go:167:SignInPost() [I] Failed authentication attempt for <username> from <source_ip>

I'm using now the config above in Authentication Source (sorry it's in Spanish):

Is it possible to "automate" this process when using Docker? In case the pod is restarted or I update the info. Or is this info stored in the MySQL, so I will need some script to deploy it from scratch?
...

Screenshots

imagen

Originally created by @Mr-Reca on GitHub (Oct 7, 2019). <!-- NOTE: If your issue is a security concern, please send an email to security@gitea.io instead of opening a public issue --> <!-- 1. Please speak English, this is the language all maintainers can speak and write. 2. Please ask questions or configuration/deploy problems on our Discord server (https://discord.gg/gitea) or forum (https://discourse.gitea.io). 3. Please take a moment to check that your issue doesn't already exist. 4. Please give all relevant information below for bug reports, because incomplete details will be handled as an invalid report. --> - Gitea version (or commit ref): gitea:latest from Docker - Git version: gitea:latest from Docker - Operating system: - Database (use `[x]`): - [ ] PostgreSQL - [X] MySQL - [ ] MSSQL - [ ] SQLite - Can you reproduce the bug at https://try.gitea.io: - [ ] Yes (provide example URL) - [ ] No - [X] Not relevant - Log gist: ## Description I'm trying to configure AD Authentication. I followed all guides on Internet, but the output is the same: ``` 2019/10/07 15:26:12 ...dels/login_source.go:717:UserSignIn() [W] Failed to login '<username>' via 'AD': user does not exist [uid: 0, name: <username>, keyid: 0] 2019/10/07 15:26:12 routers/user/auth.go:167:SignInPost() [I] Failed authentication attempt for <username> from <source_ip> ``` I'm using now the config above in Authentication Source (sorry it's in Spanish): Is it possible to "automate" this process when using Docker? In case the pod is restarted or I update the info. Or is this info stored in the MySQL, so I will need some script to deploy it from scratch? ... ## Screenshots ![imagen](https://user-images.githubusercontent.com/17903554/66325919-5d03bb00-e928-11e9-9bed-3bee1260abed.png) <!-- **If this issue involves the Web Interface, please include a screenshot** -->
GiteaMirror added the type/questionissue/stale labels 2025-11-02 05:36:42 -06:00
Author
Owner

@guillep2k commented on GitHub (Oct 7, 2019):

I guess <username> is something you replaced, not something that actually shows up in your log, isn't it?

@guillep2k commented on GitHub (Oct 7, 2019): I guess `<username>` is something you replaced, not something that actually shows up in your log, isn't it?
Author
Owner

@Mr-Reca commented on GitHub (Oct 7, 2019):

Yes. I put a “placeholder” because of internal policies.

@Mr-Reca commented on GitHub (Oct 7, 2019): Yes. I put a “placeholder” because of internal policies.
Author
Owner

@guillep2k commented on GitHub (Oct 7, 2019):

Anyway, you need to replace some of the values depending on your configuration. For example, for my own system ("miempresa.es"), it should be something like this:

  • Báse de búsqueda de usuarios: CN=Users,dc=miempresa,dc=es. Notice that it's CN= and not OU=; also in my case it's Users and not Usuarios (my server was installed in English, but I believe that this doesn't change with the server language).

  • DN de Usuario: same considerations.

There are other kinds of queries that can be used, including using the OU= parameter, but they must exist in your AD configuration in order to work.

You could check some tool like this (I don't know it, it just popped up on a search) to test your search parameters.

Please notice that this is not a support forum. If you're still having problems, please ask in the #Configuration channel of our Discord server, or in our forum.

@guillep2k commented on GitHub (Oct 7, 2019): Anyway, you need to replace some of the values depending on your configuration. For example, for my own system ("miempresa.es"), it should be something like this: - ***Báse de búsqueda de usuarios***: `CN=Users,dc=miempresa,dc=es`. Notice that it's `CN=` and not `OU=`; also in my case it's `Users` and not `Usuarios` (my server was installed in English, but I believe that this doesn't change with the server language). - ***DN de Usuario***: same considerations. There are other kinds of queries that can be used, including using the `OU=` parameter, but they must exist in your AD configuration in order to work. You could check some tool like [this](http://www.joeware.net/freetools/tools/adfind/index.htm) (I don't know it, it just popped up on a search) to test your search parameters. Please notice that this is not a support forum. If you're still having problems, please ask in the `#Configuration` channel of our [Discord server](https://discord.gg/NsatcWJ), or in our [forum](https://discourse.gitea.io/).
Author
Owner

@Mr-Reca commented on GitHub (Oct 8, 2019):

I also tried that configuration.

I opened the issue because there are lots of links with configurations and none of them works. I think that maybe something is missing (in documentation or implementation of LDAP)

@Mr-Reca commented on GitHub (Oct 8, 2019): I also tried that configuration. I opened the issue because there are lots of links with configurations and none of them works. I think that maybe something is missing (in documentation or implementation of LDAP)
Author
Owner

@Mr-Reca commented on GitHub (Oct 8, 2019):

Hi @guillep2k ,

I tried AdFind and the same query does not work in Gitea. Is it better to close this issue and talk through the forum, or do you think it can be something? Is it possible to test this feature with another AD?

Thank you so much for your time,

@Mr-Reca commented on GitHub (Oct 8, 2019): Hi @guillep2k , I tried AdFind and the same query does not work in Gitea. Is it better to close this issue and talk through the forum, or do you think it can be something? Is it possible to test this feature with another AD? Thank you so much for your time,
Author
Owner

@guillep2k commented on GitHub (Oct 8, 2019):

@Mr-Reca The AD feature is not only used in many installations (it's a popular way of using Gitea) but it's also tested every time a single line of code is added to Gitea in our continuos integration tests. Everything is susceptible of having bugs and we're far from 100% test coverage, so bugs can still slip in.

Anyway, check this link and search around the forum; you might find the solution there.

Feel free to leave this issue open if you feel that it's a bug in Gitea.

@guillep2k commented on GitHub (Oct 8, 2019): @Mr-Reca The AD feature is not only used in many installations (it's a popular way of using Gitea) but it's also tested every time a single line of code is added to Gitea in our [continuos integration tests](https://drone.gitea.io/go-gitea/gitea/13546). Everything is susceptible of having bugs and we're far from 100% test coverage, so bugs *can still slip in*. Anyway, [check this link](https://discourse.gitea.io/t/using-samaccountname-for-ldap-login/860/7) and search around the forum; you might find the solution there. Feel free to leave this issue open if you feel that it's a bug in Gitea.
Author
Owner

@markkrj commented on GitHub (Oct 8, 2019):

Considering Active Directory, your User DN is wrong. It must be CN=username,OU=your,OU=user,OU=organization,OU=unity,DC=your,DC=domain. But you really must consider using LDAPS and bind DN for security.

@markkrj commented on GitHub (Oct 8, 2019): Considering Active Directory, your User DN is wrong. It must be CN=username,OU=your,OU=user,OU=organization,OU=unity,DC=your,DC=domain. But you really must consider using LDAPS and bind DN for security.
Author
Owner

@Mr-Reca commented on GitHub (Oct 9, 2019):

Hi @markkrj

I'm trying now without LDAPS for testing, I'll set it up later. Is it safer to user BindDN? When I check this option, Gitea says that this value will be stored in raw.

I'll try to change my user DN. @guillep2k I also realized that my DN has the following format:

CN=<my_display_fullname>,OU=Usuarios,OU=<department>,OU=<office>,DC=<domain>,DC=<local>

In my case, the users will have the same department. But the office is different (Barcelona, Madrid, London...).

The group has the same format, but department and office is always the same for everyone.

Maybe our AD is misconfigured? Or will it be a problem to use LDAP with different OU?

Thank you so much for your time,

@Mr-Reca commented on GitHub (Oct 9, 2019): Hi @markkrj I'm trying now without LDAPS for testing, I'll set it up later. Is it safer to user BindDN? When I check this option, Gitea says that this value will be stored in raw. I'll try to change my user DN. @guillep2k I also realized that my DN has the following format: `CN=<my_display_fullname>,OU=Usuarios,OU=<department>,OU=<office>,DC=<domain>,DC=<local>` In my case, the users will have the same `department`. But the `office` is different (Barcelona, Madrid, London...). The group has the same format, but `department` and `office` is always the same for everyone. Maybe our AD is misconfigured? Or will it be a problem to use LDAP with different OU? Thank you so much for your time,
Author
Owner

@lafriks commented on GitHub (Oct 9, 2019):

User DN should probably be:

CN=%s,OU=Usuarios,OU=<department>,OU=<office>,DC=<domain>,DC=<local>

Does sAMAccountName is the same as CN= for users?

If it is not that it will not work and you should use something like this for user filter:

(&(objectCategory=Person)(!(UserAccountControl:1.2.840.113556.1.4.803:=2)))
@lafriks commented on GitHub (Oct 9, 2019): User DN should probably be: ``` CN=%s,OU=Usuarios,OU=<department>,OU=<office>,DC=<domain>,DC=<local> ``` Does `sAMAccountName` is the same as `CN=` for users? If it is not that it will not work and you should use something like this for user filter: ``` (&(objectCategory=Person)(!(UserAccountControl:1.2.840.113556.1.4.803:=2))) ```
Author
Owner

@lafriks commented on GitHub (Oct 9, 2019):

Also for AD I would probably recommend using LDAP (via BindDN)

Of course you need to create service user in AD for this

@lafriks commented on GitHub (Oct 9, 2019): Also for AD I would probably recommend using `LDAP (via BindDN)` Of course you need to create service user in AD for this
Author
Owner

@Mr-Reca commented on GitHub (Oct 9, 2019):

User DN should probably be:

CN=%s,OU=Usuarios,OU=<department>,OU=<office>,DC=<domain>,DC=<local>

Does sAMAccountName is the same as CN= for users?

If it is not that it will not work and you should use something like this for user filter:

(&(objectCategory=Person)(!(UserAccountControl:1.2.840.113556.1.4.803:=2)))

No, it's not the same. the CN in User DN is the display name. sAMAccountName is the username

Example:

CN=Lore Ipsum,OU=Usuarios,OU=<department>,OU=<office>,DC=<domain>,DC=<local>
sAMAccountName=lore.ipsum
@Mr-Reca commented on GitHub (Oct 9, 2019): > > > User DN should probably be: > > ``` > CN=%s,OU=Usuarios,OU=<department>,OU=<office>,DC=<domain>,DC=<local> > ``` > > Does `sAMAccountName` is the same as `CN=` for users? > > If it is not that it will not work and you should use something like this for user filter: > > ``` > (&(objectCategory=Person)(!(UserAccountControl:1.2.840.113556.1.4.803:=2))) > ``` No, it's not the same. the CN in User DN is the display name. sAMAccountName is the username Example: ``` CN=Lore Ipsum,OU=Usuarios,OU=<department>,OU=<office>,DC=<domain>,DC=<local> sAMAccountName=lore.ipsum ```
Author
Owner

@lafriks commented on GitHub (Oct 9, 2019):

That is why it does not work as you enter user CN but user filter filters it out as it does not match

@lafriks commented on GitHub (Oct 9, 2019): That is why it does not work as you enter user CN but user filter filters it out as it does not match
Author
Owner

@Mr-Reca commented on GitHub (Oct 9, 2019):

So I could configure to use displayName which matchs with DN, but I am not able to use sAMAccountName ?

@Mr-Reca commented on GitHub (Oct 9, 2019): So I could configure to use `displayName` which matchs with DN, but I am not able to use `sAMAccountName` ?
Author
Owner

@stale[bot] commented on GitHub (Dec 8, 2019):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions.

@stale[bot] commented on GitHub (Dec 8, 2019): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 weeks. Thank you for your contributions.
Author
Owner

@finkr commented on GitHub (Dec 20, 2019):

set "LEVEL=debug" in the file app.ini to see error messages (restart required)

@finkr commented on GitHub (Dec 20, 2019): set "LEVEL=debug" in the file `app.ini` to see error messages (restart required)
Author
Owner

@stale[bot] commented on GitHub (Feb 19, 2020):

This issue has been automatically marked as stale because it has not had recent activity. I am here to help clear issues left open even if solved or waiting for more insight. This issue will be closed if no further activity occurs during the next 2 weeks. If the issue is still valid just add a comment to keep it alive. Thank you for your contributions.

@stale[bot] commented on GitHub (Feb 19, 2020): This issue has been automatically marked as stale because it has not had recent activity. I am here to help clear issues left open even if solved or waiting for more insight. This issue will be closed if no further activity occurs during the next 2 weeks. If the issue is still valid just add a comment to keep it alive. Thank you for your contributions.
Author
Owner

@stale[bot] commented on GitHub (Mar 4, 2020):

This issue has been automatically closed because of inactivity. You can re-open it if needed.

@stale[bot] commented on GitHub (Mar 4, 2020): This issue has been automatically closed because of inactivity. You can re-open it if needed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#4074