code.gitea.io/gitea@v1.22.3/docs/content/usage/authentication.en-us.md (about) 1 --- 2 date: "2016-12-01T16:00:00+02:00" 3 title: "Authentication" 4 slug: "authentication" 5 sidebar_position: 10 6 toc: false 7 draft: false 8 aliases: 9 - /en-us/authentication 10 menu: 11 sidebar: 12 parent: "usage" 13 name: "Authentication" 14 sidebar_position: 10 15 identifier: "authentication" 16 --- 17 18 # Authentication 19 20 ## LDAP (Lightweight Directory Access Protocol) 21 22 Both the LDAP via BindDN and the simple auth LDAP share the following fields: 23 24 - Authorization Name **(required)** 25 26 - A name to assign to the new method of authorization. 27 28 - Host **(required)** 29 30 - The address where the LDAP server can be reached. 31 - Example: `mydomain.com` 32 33 - Port **(required)** 34 35 - The port to use when connecting to the server. 36 - Example: `389` for LDAP or `636` for LDAP SSL 37 38 - Enable TLS Encryption (optional) 39 40 - Whether to use TLS when connecting to the LDAP server. 41 42 - Admin Filter (optional) 43 44 - An LDAP filter specifying if a user should be given administrator 45 privileges. If a user account passes the filter, the user will be 46 privileged as an administrator. 47 - Example: `(objectClass=adminAccount)` 48 - Example for Microsoft Active Directory (AD): `(memberOf=CN=admin-group,OU=example,DC=example,DC=org)` 49 50 - Username attribute (optional) 51 52 - The attribute of the user's LDAP record containing the user name. Given 53 attribute value will be used for new Gitea account user name after first 54 successful sign-in. Leave empty to use login name given on sign-in form. 55 - This is useful when supplied login name is matched against multiple 56 attributes, but only single specific attribute should be used for Gitea 57 account name, see "User Filter". 58 - Example: `uid` 59 - Example for Microsoft Active Directory (AD): `sAMAccountName` 60 61 - First name attribute (optional) 62 63 - The attribute of the user's LDAP record containing the user's first name. 64 This will be used to populate their account information. 65 - Example: `givenName` 66 67 - Surname attribute (optional) 68 69 - The attribute of the user's LDAP record containing the user's surname. 70 This will be used to populate their account information. 71 - Example: `sn` 72 73 - E-mail attribute **(required)** 74 - The attribute of the user's LDAP record containing the user's email 75 address. This will be used to populate their account information. 76 - Example: `mail` 77 78 ### LDAP via BindDN 79 80 Adds the following fields: 81 82 - Bind DN (optional) 83 84 - The DN to bind to the LDAP server with when searching for the user. This 85 may be left blank to perform an anonymous search. 86 - Example: `cn=Search,dc=mydomain,dc=com` 87 88 - Bind Password (optional) 89 90 - The password for the Bind DN specified above, if any. _Note: The password 91 is stored encrypted with the SECRET_KEY on the server. It is still recommended 92 to ensure that the Bind DN has as few privileges as possible._ 93 94 - User Search Base **(required)** 95 96 - The LDAP base at which user accounts will be searched for. 97 - Example: `ou=Users,dc=mydomain,dc=com` 98 99 - User Filter **(required)** 100 - An LDAP filter declaring how to find the user record that is attempting to 101 authenticate. The `%[1]s` matching parameter will be substituted with login 102 name given on sign-in form. 103 - Example: `(&(objectClass=posixAccount)(|(uid=%[1]s)(mail=%[1]s)))` 104 - Example for Microsoft Active Directory (AD): `(&(objectCategory=Person)(memberOf=CN=user-group,OU=example,DC=example,DC=org)(sAMAccountName=%s)(!(UserAccountControl:1.2.840.113556.1.4.803:=2)))` 105 - To substitute more than once, `%[1]s` should be used instead, e.g. when 106 matching supplied login name against multiple attributes such as user 107 identifier, email or even phone number. 108 - Example: `(&(objectClass=Person)(|(uid=%[1]s)(mail=%[1]s)(mobile=%[1]s)))` 109 - Enable user synchronization 110 - This option enables a periodic task that synchronizes the Gitea users with 111 the LDAP server. The default period is every 24 hours but that can be 112 changed in the app.ini file. See the _cron.sync_external_users_ section in 113 the [sample 114 app.ini](https://github.com/go-gitea/gitea/blob/main/custom/conf/app.example.ini) 115 for detailed comments about that section. The _User Search Base_ and _User 116 Filter_ settings described above will limit which users can use Gitea and 117 which users will be synchronized. When initially run the task will create 118 all LDAP users that match the given settings so take care if working with 119 large Enterprise LDAP directories. 120 121 ### LDAP using simple auth 122 123 Adds the following fields: 124 125 - User DN **(required)** 126 127 - A template to use as the user's DN. The `%s` matching parameter will be 128 substituted with login name given on sign-in form. 129 - Example: `cn=%s,ou=Users,dc=mydomain,dc=com` 130 - Example: `uid=%s,ou=Users,dc=mydomain,dc=com` 131 132 - User Search Base (optional) 133 134 - The LDAP base at which user accounts will be searched for. 135 - Example: `ou=Users,dc=mydomain,dc=com` 136 137 - User Filter **(required)** 138 - An LDAP filter declaring when a user should be allowed to log in. The `%[1]s` 139 matching parameter will be substituted with login name given on sign-in 140 form. 141 - Example: `(&(objectClass=posixAccount)(|(cn=%[1]s)(mail=%[1]s)))` 142 - Example: `(&(objectClass=posixAccount)(|(uid=%[1]s)(mail=%[1]s)))` 143 144 ### Verify group membership in LDAP 145 146 Uses the following fields: 147 148 - Group Search Base DN (optional) 149 150 - The LDAP DN used for groups. 151 - Example: `ou=group,dc=mydomain,dc=com` 152 153 - Group Attribute Containing List Of Users (optional) 154 - The attribute of the group object that lists/contains the group members. 155 - Example: `memberUid` or `member` 156 157 - User Attribute Listed in Group (optional) 158 159 - The user attribute that is used to reference a user in the group object. 160 - Example: `uid` if the group objects contains a `member: bender` and the user object contains a `uid: bender`. 161 - Example: `dn` if the group object contains a `member: uid=bender,ou=users,dc=planetexpress,dc=com`. 162 163 - Verify group membership in LDAP (optional) 164 165 - An LDAP filter declaring how to find valid groups in the above DN. 166 - Example: `(|(cn=gitea_users)(cn=admins))` 167 168 ## PAM (Pluggable Authentication Module) 169 170 This procedure enables PAM authentication. Users may still be added to the 171 system manually using the user administration. PAM provides a mechanism to 172 automatically add users to the current database by testing them against PAM 173 authentication. To work with normal Linux passwords, the user running Gitea 174 must also have read access to `/etc/shadow` in order to check the validity of 175 the account when logging in using a public key. 176 177 **Note**: If a user has added SSH public keys into Gitea, the use of these 178 keys _may_ bypass the login check system. Therefore, if you wish to disable a user who 179 authenticates with PAM, you _should_ also manually disable the account in Gitea using the 180 built-in user manager. 181 182 1. Configure and prepare the installation. 183 - It is recommended that you create an administrative user. 184 - Deselecting automatic sign-up may also be desired. 185 1. Once the database has been initialized, log in as the newly created 186 administrative user. 187 1. Navigate to the user setting (icon in top-right corner), and select 188 `Site Administration` -> `Authentication Sources`, and select 189 `Add Authentication Source`. 190 1. Fill out the field as follows: 191 - `Authentication Type` : `PAM` 192 - `Name` : Any value should be valid here, use "System Authentication" if 193 you'd like. 194 - `PAM Service Name` : Select the appropriate file listed under `/etc/pam.d/` 195 that performs the authentication desired.[^1] 196 - `PAM Email Domain` : The e-mail suffix to append to user authentication. 197 For example, if the login system expects a user called `gituser`, and this 198 field is set to `mail.com`, then Gitea will expect the `user email` field 199 for an authenticated GIT instance to be `gituser@mail.com`.[^2] 200 201 **Note**: PAM support is added via [build-time flags](installation/from-source.md#build), 202 and the official binaries provided do not have this enabled. PAM requires that 203 the necessary libpam dynamic library be available and the necessary PAM 204 development headers be accessible to the compiler. 205 206 [^1]: For example, using standard Linux log-in on Debian "Bullseye" use 207 `common-session-noninteractive` - this value may be valid for other flavors of 208 Debian including Ubuntu and Mint, consult your distribution's documentation. 209 [^2]: **This is a required field for PAM**. Be aware: In the above example, the 210 user will log into the Gitea web interface as `gituser` and not `gituser@mail.com` 211 212 ## SMTP (Simple Mail Transfer Protocol) 213 214 This option allows Gitea to log in to an SMTP host as a Gitea user. To 215 configure this, set the fields below: 216 217 - Authentication Name **(required)** 218 219 - A name to assign to the new method of authorization. 220 221 - SMTP Authentication Type **(required)** 222 223 - Type of authentication to use to connect to SMTP host, PLAIN or LOGIN. 224 225 - Host **(required)** 226 227 - The address where the SMTP host can be reached. 228 - Example: `smtp.mydomain.com` 229 230 - Port **(required)** 231 232 - The port to use when connecting to the server. 233 - Example: `587` 234 235 - Allowed Domains 236 237 - Restrict what domains can log in if using a public SMTP host or SMTP host 238 with multiple domains. 239 - Example: `gitea.com,mydomain.com,mydomain2.com` 240 241 - Force SMTPS 242 243 - SMTPS will be used by default for connections to port 465, if you wish to use SMTPS 244 for other ports. Set this value. 245 - Otherwise if the server provides the `STARTTLS` extension this will be used. 246 247 - Skip TLS Verify 248 249 - Disable TLS verify on authentication. 250 251 - This Authentication Source is Activated 252 - Enable or disable this authentication source. 253 254 ## FreeIPA 255 256 - In order to log in to Gitea using FreeIPA credentials, a bind account needs to 257 be created for Gitea: 258 259 - On the FreeIPA server, create a `gitea.ldif` file, replacing `dc=example,dc=com` 260 with your DN, and provide an appropriately secure password: 261 262 ```sh 263 dn: uid=gitea,cn=sysaccounts,cn=etc,dc=example,dc=com 264 changetype: add 265 objectclass: account 266 objectclass: simplesecurityobject 267 uid: gitea 268 userPassword: secure password 269 passwordExpirationTime: 20380119031407Z 270 nsIdleTimeout: 0 271 ``` 272 273 - Import the LDIF (change localhost to an IPA server if needed). A prompt for 274 Directory Manager password will be presented: 275 276 ```sh 277 ldapmodify -h localhost -p 389 -x -D \ 278 "cn=Directory Manager" -W -f gitea.ldif 279 ``` 280 281 - Add an IPA group for gitea_users : 282 283 ```sh 284 ipa group-add --desc="Gitea Users" gitea_users 285 ``` 286 287 - Note: For errors about IPA credentials, run `kinit admin` and provide the 288 domain admin account password. 289 290 - Log in to Gitea as an Administrator and click on "Authentication" under Admin Panel. 291 Then click `Add New Source` and fill in the details, changing all where appropriate. 292 293 ## SPNEGO with SSPI (Kerberos/NTLM, for Windows only) 294 295 Gitea supports SPNEGO single sign-on authentication (the scheme defined by RFC4559) for the web part of the server via the Security Support Provider Interface (SSPI) built in Windows. SSPI works only in Windows environments - when both the server and the clients are running Windows. 296 297 Before activating SSPI single sign-on authentication (SSO) you have to prepare your environment: 298 299 - Create a separate user account in active directory, under which the `gitea.exe` process will be running (eg. `user` under domain `domain.local`): 300 301 - Create a service principal name for the host where `gitea.exe` is running with class `HTTP`: 302 303 - Start `Command Prompt` or `PowerShell` as a privileged domain user (eg. Domain Administrator) 304 - Run the command below, replacing `host.domain.local` with the fully qualified domain name (FQDN) of the server where the web application will be running, and `domain\user` with the name of the account created in the previous step: 305 306 ```sh 307 setspn -A HTTP/host.domain.local domain\user 308 ``` 309 310 - Sign in (_sign out if you were already signed in_) with the user created 311 312 - Make sure that `ROOT_URL` in the `[server]` section of `custom/conf/app.ini` is the fully qualified domain name of the server where the web application will be running - the same you used when creating the service principal name (eg. `host.domain.local`) 313 314 - Start the web server (`gitea.exe web`) 315 316 - Enable SSPI authentication by adding an `SPNEGO with SSPI` authentication source in `Site Administration -> Authentication Sources` 317 318 - Sign in to a client computer in the same domain with any domain user (client computer, different from the server running `gitea.exe`) 319 320 - If you are using Chrome or Edge, add the URL of the web app to the Local intranet sites (`Internet Options -> Security -> Local intranet -> Sites`) 321 322 - Start Chrome or Edge and navigate to the FQDN URL of Gitea (eg. `http://host.domain.local:3000`) 323 324 - Click the `Sign In` button on the dashboard and choose SSPI to be automatically logged in with the same user that is currently logged on to the computer 325 326 - If it does not work, make sure that: 327 - You are not running the web browser on the same server where Gitea is running. You should be running the web browser on a domain joined computer (client) that is different from the server. If both the client and server are running on the same computer NTLM will be preferred over Kerberos. 328 - There is only one `HTTP/...` SPN for the host 329 - The SPN contains only the hostname, without the port 330 - You have added the URL of the web app to the `Local intranet zone` 331 - The clocks of the server and client should not differ with more than 5 minutes (depends on group policy) 332 - `Integrated Windows Authentication` should be enabled in Internet Explorer (under `Advanced settings`) 333 334 ## Reverse Proxy 335 336 Gitea supports Reverse Proxy Header authentication, it will read headers as a trusted login user name or user email address. This hasn't been enabled by default, you can enable it with 337 338 ```ini 339 [service] 340 ENABLE_REVERSE_PROXY_AUTHENTICATION = true 341 ``` 342 343 The default login user name is in the `X-WEBAUTH-USER` header, you can change it via changing `REVERSE_PROXY_AUTHENTICATION_USER` in app.ini. If the user doesn't exist, you can enable automatic registration with `ENABLE_REVERSE_PROXY_AUTO_REGISTRATION=true`. 344 345 The default login user email is `X-WEBAUTH-EMAIL`, you can change it via changing `REVERSE_PROXY_AUTHENTICATION_EMAIL` in app.ini, this could also be disabled with `ENABLE_REVERSE_PROXY_EMAIL` 346 347 If set `ENABLE_REVERSE_PROXY_FULL_NAME=true`, a user full name expected in `X-WEBAUTH-FULLNAME` will be assigned to the user when auto creating the user. You can also change the header name with `REVERSE_PROXY_AUTHENTICATION_FULL_NAME`. 348 349 You can also limit the reverse proxy's IP address range with `REVERSE_PROXY_TRUSTED_PROXIES` which default value is `127.0.0.0/8,::1/128`. By `REVERSE_PROXY_LIMIT`, you can limit trusted proxies level. 350 351 Notice: Reverse Proxy Auth doesn't support the API. You still need an access token or basic auth to make API requests.