You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## TODO
- ❌ ~~Add an FAQ~~ I think we can add FAQ as a followup improvement
- [x] Add an example to how long it takes for permissions to take effect
(what I call lag-time in the docs).
- [x] Render math formulas nicely
## Old docs
[Link to the current docs
page](https://docs.sourcegraph.com/admin/repo/permissions)
## New docs
[Link to the docs page with code from this
branch](https://docs.sourcegraph.com/@milan_docs_permissions/admin/permissions)
## Test plan
Docs changes only, so eyeballing is the only method I did 🤷
## Disclaimer
I need to move on to other tasks. So if you find big issues or room for
improvement that cannot be fixed in ~20 minutes, we can create followup
PRs later, if there's time before the code freeze.
- `Repositories`: `Read` (if [permissions syncing](../repo/permissions.md) is desired)
333
+
- `Repositories`: `Read` (more information in [repository permissions section](../permissions/index.md))
335
334
336
335
After the consumer is created, you will need the `Key` and the `Secret`, which can be found by expanding OAuth consumer in the list.
337
336
Then add the following lines to your [site configuration](config/site_config.md):
@@ -512,7 +511,7 @@ Let's say the email field in your Sourcegraph account was kept blank when a site
512
511
Exceptions to this rule are [HTTP Proxies](#http-authentication-proxies), where there's an option to make the link via username only.
513
512
For [Bitbucket](../config/authorization_and_authentication.md#bitbucket-server-bitbucket-data-center-authorization), we don't support OAuth. Still, the match between the chosen auth provider used with Bitbucket and a user's Bitbucket account happens via username.
514
513
515
-
Using only a username to match a Sourcegraph account to an auth provider account is not recommended, as you can see [here](../repo/permissions.md#username), for example.
514
+
Using only a username to match a Sourcegraph account to an auth provider account is not recommended, as you can see [here](../external_service/gitlab.md#username), for example.
516
515
Usernames in Sourcegraph are mutable, so a malicious user could change a username, elevating their privileges.
Copy file name to clipboardExpand all lines: doc/admin/config/authorization_and_authentication.md
+7-7Lines changed: 7 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
# Authentication and authorization in Sourcegraph
1
+
# Authentication and authorization
2
2
3
3
Sourcegraph has two authentication concepts:
4
4
@@ -7,7 +7,7 @@ Sourcegraph has two authentication concepts:
7
7
8
8
We suggest configuring both when using Sourcegraph Enterprise. If you do not configure permissions, all users will be able to see all of the code in the instance.
9
9
10
-
## Authentication in Sourcegraph
10
+
## Authentication
11
11
12
12
Sourcegraph supports username/password auth by default and SAML, OAuth, HTTP Proxy auth, and OpenID Connect if configured. Changing a username in Sourcegraph will allow the user to escalate permissions, so if you are syncing permissions, you will need to add the following to your site config at `https://sourcegraph.yourdomain.com/siteadmin/configuration` ([Learn more about viewing and editing your site configuration.](./site_config.md#view-and-edit-site-configuration))
13
13
@@ -68,7 +68,7 @@ In this way, access to Sourcegraph will still be managed by your identity provid
68
68
69
69
Follow these steps to [configure authentication with GitHub via OAuth](../auth/index.md#github).
70
70
71
-
Once authentication with GitHub via OAuth is configured, follow [these steps to configure access permissions](../repo/permissions.md#github). Users will log into Sourcegraph using Github OAuth, and permissions will be synced in the background.
71
+
Once authentication with GitHub via OAuth is configured, follow [these steps to configure access permissions](../external_service/github.md#repository-permissions). Users will log into Sourcegraph using Github OAuth, and permissions will be synced in the background.
72
72
73
73
### GitLab Enterprise or GitLab Cloud authentication and authorization
74
74
@@ -79,13 +79,13 @@ We support both authentication and permissions syncing (through OAuth) for GitLa
79
79
1. Use SAML (or another auth mechanism) to log in to GitLab
80
80
2. Use GitLab OAuth to log in to Sourcegraph
81
81
82
-
In this way, access to Sourcegraph will still be managed by your identity provider, using the code host as a middle step. This option is the simplest to configure. To do so, [set up GitLab as an authentication option](../auth/index.md#gitlab), and then [enable permissions syncing](../repo/permissions.md#oauth-application).
82
+
In this way, access to Sourcegraph will still be managed by your identity provider, using the code host as a middle step. This option is the simplest to configure. To do so, [set up GitLab as an authentication option](../auth/index.md#gitlab), and then [enable permissions syncing](../external_service/gitlab.md#oauth-application).
83
83
84
84
#### Option 2
85
85
86
86
Alternatively, you can configure SAML authentication in Sourcegraph, and use GitLab permissions syncing in the background to control access permissions. To implement this method, you will need to make sure that GitLab is able to return a value in `identities.provider` for the `GET /users` endpoint ([GitLab documentation](https://docs.gitlab.com/ee/api/users.html#for-admins)) that your identity provider is able to pass as the `nameID` in the SAML response. If that isn’t possible, you will need to use the first option.
87
87
88
-
To configure SAML auth with GitLab permissions, you will need to first [configure permissions from GitLab](../repo/permissions.md#administrator-sudo-level-access-token). Then, [configure SAML authentication](../auth/saml/index.md). The `nameID` passed by the identity provider will need to match the value of `identities.provider`.
88
+
To configure SAML auth with GitLab permissions, you will need to first [configure permissions from GitLab](../external_service/gitlab.md#administrator-sudo-level-access-token). Then, [configure SAML authentication](../auth/saml/index.md). The `nameID` passed by the identity provider will need to match the value of `identities.provider`.
89
89
90
90
For example, if the GitLab API returns:
91
91
@@ -118,15 +118,15 @@ And configure the identity provider to pass the email address as the `nameID`.
118
118
119
119
We do not currently support OAuth for Bitbucket Server or Bitbucket Data Center. You will need to combine permissions syncing from Bitbucket Server / Bitbucket Data Center with another authentication mechanism (SAML, built-in auth, HTTP authentication proxies). Bitbucket Server and Bitbucket Data Center only pass usernames to Sourcegraph, so you’ll need to make sure that those usernames are matched by whatever mechanism you choose to use for access.
120
120
121
-
Follow the steps to [sync Bitbucket Server / Bitbucket Data Center permissions](../repo/permissions.md#bitbucket-server). Then, do one of the following:
121
+
Follow the steps to [sync Bitbucket Server / Bitbucket Data Center permissions](../external_service/bitbucket_server.md#repository-permissions). Then, do one of the following:
122
122
123
123
1. Create the user accounts in Sourcegraph with matching usernames. (Access using `builtin` auth.)
124
124
2.[Configure SAML authentication](../auth/saml/index.md). If you are using Bitbucket Server / Bitbucket Data Center, the `login` attribute is *not* optional. You need to pass the Bitbucket Server username as the `login` attribute.
125
125
3.[Configure an HTTP authentication proxy](../auth/index.md#http-authentication-proxies), passing the Bitbucket Server username value as the `usernameHeader`.
126
126
127
127
### Explicit Permissions API authorization
128
128
129
-
With any authentication mechanism, you can use our GraphQL API to set permissions for all repositories. If you choose to do this, this is the *only* mechanism that can be used for permissions—all others will be ignored. Follow the instructions for the [mutations needed within the GraphQL API](../repo/permissions.md#explicit-permissions-api) to configure access.
129
+
With any authentication mechanism, you can use our GraphQL API to set permissions for all repositories. If you choose to do this, this is the *only* mechanism that can be used for permissions—all others will be ignored. Follow the instructions for the [mutations needed within the GraphQL API](../permissions/api.md) to configure access.
Prerequisite: [Add Bitbucket Cloud as an authentication provider](#user-authentication).
44
+
45
+
Then, add or edit a Bitbucket Cloud connection as described above and include the `authorization` field:
46
+
47
+
```json
48
+
{
49
+
// The URL used to set up the Bitbucket Cloud authentication provider must match this URL.
50
+
"url": "https://bitbucket.com",
51
+
"username": "horsten",
52
+
"appPassword": "$APP_PASSWORD",
53
+
// ...
54
+
"authorization": {}
55
+
}
56
+
```
57
+
58
+
> NOTE: It can take some time to complete full cycle of repository permissions sync if you have a large number of users or repositories. [See sync duration time](../permissions/syncing.md#sync-duration) for more information.
59
+
41
60
## Configuration
42
61
43
62
Bitbucket Cloud connections support the following configuration options, which are specified in the JSON editor in the site admin "Manage code hosts" area.
Copy file name to clipboardExpand all lines: doc/admin/external_service/bitbucket_server.md
+65-2Lines changed: 65 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -38,14 +38,77 @@ Please consult [this page](../config/webhooks.md) in order to configure webhooks
38
38
39
39
## Repository permissions
40
40
41
-
By default, all Sourcegraph users can view all repositories. To configure Sourcegraph to use Bitbucket Server / Bitbucket Data Center's repository permissions, see [Repository permissions](../repo/permissions.md#bitbucket_server).
41
+
Enforcing Bitbucket Server / Bitbucket Data Center permissions can be configured via the `authorization` setting in its configuration.
42
+
43
+
> NOTE: It can take some time to complete full cycle of repository permissions sync if you have a large number of users or repositories. [See sync duration time](../permissions/syncing.md#sync-duration) for more information.
44
+
45
+
### Prerequisites
46
+
47
+
1. You have the exact same user accounts, **with matching usernames**, in Sourcegraph and Bitbucket Server / Bitbucket Data Center. This can be accomplished by configuring an [external authentication provider](../auth/index.md) that mirrors user accounts from a central directory like LDAP or Active Directory. The same should be done on Bitbucket Server / Bitbucket Data Center with [external user directories](https://confluence.atlassian.com/bitbucketserver/external-user-directories-776640394.html).
48
+
1. Ensure you have set `auth.enableUsernameChanges` to **`false`** in the [site config](../config/site_config.md) to prevent users from changing their usernames and **escalating their privileges**.
49
+
50
+
51
+
### Setup
52
+
53
+
This section walks you through the process of setting up an *Application Link between Sourcegraph and Bitbucket Server / Bitbucket Data Center* and configuring the Sourcegraph Bitbucket Server / Bitbucket Data Center configuration with `authorization` settings. It assumes the above prerequisites are met.
54
+
55
+
As an admin user, go to the "Application Links" page. You can use the sidebar navigation in the admin dashboard, or go directly to [https://bitbucketserver.example.com/plugins/servlet/applinks/listApplicationLinks](https://bitbucketserver.example.com/plugins/servlet/applinks/listApplicationLinks).
Write Sourcegraph's external URL in the text area (e.g. `https://sourcegraph.example.com`) and click **Create new link**. Click **Continue** even if Bitbucket Server / Bitbucket Data Center warns you about the given URL not responding.
Write `Sourcegraph` as the *Application Name* and select `Generic Application` as the *Application Type*. Leave everything else unset and click **Continue**.
Generate a *Consumer Key* in your terminal with `echo sourcegraph$(openssl rand -hex 16)`. Copy this command's output and paste it in the *Consumer Key* field. Write `Sourcegraph` in the *Consumer Name* field.
Generate an RSA key pair in your terminal with `openssl genrsa -out sourcegraph.pem 4096 && openssl rsa -in sourcegraph.pem -pubout > sourcegraph.pub`. Copy the contents of `sourcegraph.pub` and paste them in the *Public Key* field.
Scroll to the bottom and check the *Allow 2-Legged OAuth* checkbox, then write your admin account's username in the *Execute as* field and, lastly, check the *Allow user impersonation through 2-Legged OAuth* checkbox. Press **Save**.
Go to your Sourcegraph's *Manage code hosts* page (i.e. `https://sourcegraph.example.com/site-admin/external-services`) and either edit or create a new *Bitbucket Server / Bitbucket Data Center* connection. Add the following settings:
84
+
85
+
```json
86
+
{
87
+
// Other config goes here
88
+
"authorization": {
89
+
"identityProvider": {
90
+
"type": "username"
91
+
},
92
+
"oauth": {
93
+
"consumerKey": "<KEY GOES HERE>",
94
+
"signingKey": "<KEY GOES HERE>"
95
+
}
96
+
}
97
+
}
98
+
```
99
+
100
+
Copy the *Consumer Key* you generated before to the `oauth.consumerKey` field and the output of the command `base64 sourcegraph.pem | tr -d '\n'` to the `oauth.signingKey` field. Finally, **save the configuration**. You're done!
101
+
102
+
### Fast permission sync with Bitbucket Server plugin
103
+
104
+
By installing the [Bitbucket Server plugin](../../../integration/bitbucket_server.md), you can make use of the fast permission sync feature that allows using Bitbucket Server / Bitbucket Data Center permissions on larger instances.
42
105
43
106
### Fast permission syncing
44
107
45
108
With the [Sourcegraph Bitbucket Server](../../integration/bitbucket_server.md#sourcegraph-bitbucket-server-plugin) you can enable fast permission syncing:
46
109
47
110
1. Connect Bitbucket Server / Bitbucket Data Center to Sourcegraph (_see instructions above_).
48
-
1. Follow the [instructions to set up repository permissions](../repo/permissions.md#bitbucket_server) with Bitbucket Server / Bitbucket Data Center.
111
+
1. Follow the [instructions to set up repository permissions](#repository-permissions) with Bitbucket Server / Bitbucket Data Center.
49
112
1. Install the [Sourcegraph Bitbucket Server plugin](../../integration/bitbucket_server.md#sourcegraph-bitbucket-server-plugin) on your Bitbucket Server / Bitbucket Data Center instance.
50
113
1. In Sourcegraph, go to **Site admin > Manage code hosts** and edit the Bitbucket Server / Bitbucket Data Center configuration.
Copy file name to clipboardExpand all lines: doc/admin/external_service/gerrit.md
+16-2Lines changed: 16 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -25,8 +25,22 @@ To connect Gerrit to Sourcegraph:
25
25
26
26
## Repository permissions
27
27
28
-
By default, all Sourcegraph users can view all repositories. To configure
29
-
Sourcegraph to use Gerrit's access management, see "[Repository permissions](../repo/permissions.md#gerrit)".
28
+
Prerequisite: [Add Gerrit as an authentication provider](../auth/index.md#gerrit).
29
+
30
+
Then, add or edit a Gerrit connection as described above and include the `authorization` field:
31
+
32
+
```json
33
+
{
34
+
// The Gerrit URL used to set up the Gerrit authentication provider must match this URL.
35
+
"url": "https://gerrit.example.com",
36
+
"username": "<admin username>",
37
+
"password": "<admin password>",
38
+
// ...
39
+
"authorization": {}
40
+
}
41
+
```
42
+
43
+
> NOTE: It can take some time to complete full cycle of repository permissions sync if you have a large number of users or repositories. [See sync duration time](../permissions/syncing.md#sync-duration) for more information.
0 commit comments