Skip to content

Commit 9792954

Browse files
authored
[doc] Changing docs for repository permissions (sourcegraph#48039)
## 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.
1 parent 69c2ef8 commit 9792954

File tree

23 files changed

+758
-700
lines changed

23 files changed

+758
-700
lines changed

doc/admin/auth/index.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
# User authentication (SSO)
1+
# User authentication
22

33
Sourcegraph supports the following ways for users to sign in:
44

5-
- [Guidance](#guidance)
65
- [Builtin password authentication](#builtin-password-authentication)
76
- [GitHub](#github)
87
- [GitLab](#gitlab)
@@ -18,7 +17,7 @@ Sourcegraph supports the following ways for users to sign in:
1817

1918
The authentication provider is configured in the [`auth.providers`](../config/site_config.md#authentication-providers) site configuration option.
2019

21-
## Guidance
20+
## Recommendations
2221

2322
If you are unsure which auth provider is right for you, we recommend applying the following rules in
2423
order:
@@ -331,7 +330,7 @@ Sourcegraph instance:
331330
- Callback URL: `https://sourcegraph.example.com/.auth/bitbucketcloud/callback`
332331
- Permissions:
333332
- `Account`: `Read`
334-
- `Repositories`: `Read` (if [permissions syncing](../repo/permissions.md) is desired)
333+
- `Repositories`: `Read` (more information in [repository permissions section](../permissions/index.md))
335334

336335
After the consumer is created, you will need the `Key` and the `Secret`, which can be found by expanding OAuth consumer in the list.
337336
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
512511
Exceptions to this rule are [HTTP Proxies](#http-authentication-proxies), where there's an option to make the link via username only.
513512
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.
514513

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.
516515
Usernames in Sourcegraph are mutable, so a malicious user could change a username, elevating their privileges.
517516

518517
## Linking accounts from multiple auth providers

doc/admin/config/authorization_and_authentication.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Authentication and authorization in Sourcegraph
1+
# Authentication and authorization
22

33
Sourcegraph has two authentication concepts:
44

@@ -7,7 +7,7 @@ Sourcegraph has two authentication concepts:
77

88
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.
99

10-
## Authentication in Sourcegraph
10+
## Authentication
1111

1212
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))
1313

@@ -68,7 +68,7 @@ In this way, access to Sourcegraph will still be managed by your identity provid
6868

6969
Follow these steps to [configure authentication with GitHub via OAuth](../auth/index.md#github).
7070

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.
7272

7373
### GitLab Enterprise or GitLab Cloud authentication and authorization
7474

@@ -79,13 +79,13 @@ We support both authentication and permissions syncing (through OAuth) for GitLa
7979
1. Use SAML (or another auth mechanism) to log in to GitLab
8080
2. Use GitLab OAuth to log in to Sourcegraph
8181

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).
8383

8484
#### Option 2
8585

8686
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.
8787

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`.
8989

9090
For example, if the GitLab API returns:
9191

@@ -118,15 +118,15 @@ And configure the identity provider to pass the email address as the `nameID`.
118118

119119
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.
120120

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:
122122

123123
1. Create the user accounts in Sourcegraph with matching usernames. (Access using `builtin` auth.)
124124
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.
125125
3. [Configure an HTTP authentication proxy](../auth/index.md#http-authentication-proxies), passing the Bitbucket Server username value as the `usernameHeader`.
126126

127127
### Explicit Permissions API authorization
128128

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.
130130

131131
### OpenID Connect authentication
132132

doc/admin/config/webhooks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Done! Sourcegraph will now receive webhook events from GitHub and use them to sy
7373

7474
Follow the same steps as above, but ensure you include the `push` event under **Let me select individual events**
7575

76-
#### User permissions
76+
#### Repository permissions
7777

7878
Follow the same steps as above, but ensure you include the following events under **Let me select individual events**:
7979
- `Collaborator add, remove, or changed`

doc/admin/deploy/migrate-backup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ This list is not guaranteed to be complete, but rather representative of the typ
3434
|---|---|---|
3535
|Repository metadata (e.g. clone URLs, whether it is a fork or archive, etc.)|Yes||
3636
|User accounts|Yes (if using [SSO authentication](../auth/index.md)), No if using builtin authentication||
37-
|[Repository permissions](../repo/permissions.md)|Yes||
37+
|[Repository permissions](../permissions/index.md)|Yes||
3838
|[Organizations](../organizations.md)|No||
3939
|[User and org settings](../config/settings.md)|No|Global settings can be backed up as described above, but user- and org-level settings cannot.|
4040
|[Saved searches](../../code_search/how-to/saved_searches.md)|No||

doc/admin/external_service/bitbucket_cloud.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,25 @@ If enabled, the default rate is set at 7200 per hour (2 per second), which can b
3838
To configure Bitbucket Cloud as an authentication provider (which will enable sign-in via Bitbucket Cloud), see the
3939
[authentication documentation](../auth/index.md#bitbucket-cloud).
4040

41+
## Repository permissions
42+
43+
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+
4160
## Configuration
4261

4362
Bitbucket Cloud connections support the following configuration options, which are specified in the JSON editor in the site admin "Manage code hosts" area.

doc/admin/external_service/bitbucket_server.md

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,77 @@ Please consult [this page](../config/webhooks.md) in order to configure webhooks
3838

3939
## Repository permissions
4040

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).
56+
57+
<img src="https://imgur.com/Hg4bzOf.png" width="800">
58+
59+
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.
60+
61+
<img src="https://imgur.com/x6vFKIL.png" width="800">
62+
63+
Write `Sourcegraph` as the *Application Name* and select `Generic Application` as the *Application Type*. Leave everything else unset and click **Continue**.
64+
65+
<img src="https://imgur.com/161rbB9.png" width="800">
66+
67+
Now click the edit button in the `Sourcegraph` Application Link that you just created and select the `Incoming Authentication` panel.
68+
69+
<img src="https://imgur.com/sMGmzhH.png" width="800">
70+
71+
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.
72+
73+
<img src="https://imgur.com/1kK2Y5x.png" width="800">
74+
75+
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.
76+
77+
<img src="https://imgur.com/YHm1uSr.png" width="800">
78+
79+
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**.
80+
81+
<img src="https://imgur.com/1qxEAye.png" width="800">
82+
83+
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.
42105

43106
### Fast permission syncing
44107

45108
With the [Sourcegraph Bitbucket Server](../../integration/bitbucket_server.md#sourcegraph-bitbucket-server-plugin) you can enable fast permission syncing:
46109

47110
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.
49112
1. Install the [Sourcegraph Bitbucket Server plugin](../../integration/bitbucket_server.md#sourcegraph-bitbucket-server-plugin) on your Bitbucket Server / Bitbucket Data Center instance.
50113
1. In Sourcegraph, go to **Site admin > Manage code hosts** and edit the Bitbucket Server / Bitbucket Data Center configuration.
51114
1. Add the `"plugin.permissions"` property:

doc/admin/external_service/gerrit.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,22 @@ To connect Gerrit to Sourcegraph:
2525

2626
## Repository permissions
2727

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.
3044
3145
## User authentication
3246

0 commit comments

Comments
 (0)