Skip to main content
Gogs supports authentication through various external sources. Currently supported backends are LDAP, SMTP, PAM, and HTTP header. Authentication sources can be configured in two ways:
  • Admin Panel: Navigate to Admin Panel > Authentication Sources
  • Configuration files: Place .conf files in the custom/conf/auth.d/ directory. Each file describes one source using INI format. Files are loaded once at startup and keyed by id. See the “Configuration file” subsection under each backend below for examples.

LDAP

Gogs supports two variants of LDAP authentication: Simple Auth and Bind DN. In both cases, authentication is performed by attempting to bind to the LDAP server with the User DN and password. The difference is that with Bind DN, a preliminary query is performed (using the Bind DN credentials) to find the User DN first.
The Bind DN mechanism has these advantages:
  • It may be more secure than blindly attempting to bind with a possibly non-existent User DN.
  • It supports login with attributes such as email address or phone number. The preliminary search can look up the User DN using mail or mobile attributes.
  • It is required when the LDAP does not allow the User DN to query its own attributes or group memberships.
The downside is that, unless the LDAP allows anonymous queries, it requires a bind DN to be defined and Gogs needs to store its credentials. Gogs currently does not encrypt these credentials.

Shared fields

The following fields are shared between both Bind DN and Simple Auth configurations:
The User Filter field can be used to filter on group membership if the User DN object has memberOf attributes. For example:
In the Bind DN authenticator, the User Filter can also match against multiple user attributes:

Simple Auth fields

LDAP via Simple Auth adds the following field:

Bind DN fields

LDAP via Bind DN adds the following fields:
The Bind Password is stored in plaintext on the server. Ensure that your Bind DN has the minimum privileges necessary.

Group membership verification

You can optionally verify LDAP group membership using the following fields:

Configuration files

LDAP sources can also be defined as .conf files in custom/conf/auth.d/ instead of through the admin panel. Files are loaded at startup and keyed by id.

FreeIPA examples

It is possible to use either Bind DN or Simple Auth with FreeIPA. The examples below assume your domain is domain.com and that users must be a member of the gogs_users group to get access.
Setting up access using Simple Auth is straightforward:
If you want to allow login by email address, note that FreeIPA by default does not grant anonymous search access to the mail attribute. This can be changed in IPA:
Alternatively, you can ask your LDAP administrators for a dedicated bind user account.
Allowing email-based login via Bind DN may no longer be necessary. Gogs translates email logins to the corresponding user ID before making the authentication call to the backend LDAP. The only requirement is that the user’s first login is with their user ID. After that, they can use either user ID or email address.
More precisely, Gogs maps the login name onto the user’s “Authentication Login Name”, which administrators can edit on the user’s Edit Account page.

PAM

To configure PAM authentication, set the PAM Service Name to a filename in /etc/pam.d/.
If you want PAM authentication to work with normal Linux passwords, the user running Gogs must have read access to /etc/shadow.

Configuration file

SMTP

SMTP authentication allows Gogs to log in to your SMTP host to verify user credentials. Configure the following fields:

Configuration file

HTTP header

If your reverse proxy already handles user authentication (e.g. via SSO, OAuth, or client certificates), Gogs can trust the authenticated username from an HTTP header. This is configured in custom/conf/app.ini under [auth]:
When auto-registration is enabled, Gogs creates new accounts with an activated status and a placeholder email address. The user can update their email after first login.
Only enable this feature if Gogs is exclusively accessed through a trusted reverse proxy that sets the header. Exposing Gogs directly to the internet with this enabled would allow anyone to impersonate any user by setting the header themselves.