Skip to content

Added comprehensive Gerrit HTTP authentication support #366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,7 @@ dist
.sourcebot
/bin
/config.json
.DS_Store
.DS_Store

# Claude Code generated files
CLAUDE.md
123 changes: 107 additions & 16 deletions docs/docs/connections/gerrit.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,74 +6,165 @@ icon: crow

import GerritSchema from '/snippets/schemas/v3/gerrit.schema.mdx'

<Note>Authenticating with Gerrit is currently not supported. If you need this capability, please raise a [feature request](https://github.com/sourcebot-dev/sourcebot/discussions/categories/ideas).</Note>
Sourcebot can sync code from self-hosted Gerrit instances, including both public and authenticated repositories.

Sourcebot can sync code from self-hosted gerrit instances.
## Authentication Support

<Info>
**Authentication Status**: Gerrit authentication is supported through HTTP Basic Auth using username and HTTP password credentials. This guide documents the verified authentication methods and implementation details.
</Info>

### Authentication Methods

Gerrit supports these authentication methods with Sourcebot:

1. **Public Access**: For publicly accessible projects (no authentication required)
2. **HTTP Basic Auth**: Using Gerrit username and HTTP password

If you're not familiar with Sourcebot [connections](/docs/connections/overview), please read that overview first.

## Connecting to a Gerrit instance

To connect to a gerrit instance, provide the `url` property to your config:
### Basic Connection (Public Projects)

For publicly accessible Gerrit projects:

```json
{
"type": "gerrit",
"url": "https://gerrit.example.com",
"projects": ["public-project-name"]
}
```

### Authenticated Connection

For private/authenticated Gerrit projects, you need to provide credentials:

```json
{
"type": "gerrit",
"url": "https://gerrit.example.com"
// .. rest of config ..
"url": "https://gerrit.example.com",
"projects": ["private-project-name"],
"auth": {
"username": "your-gerrit-username",
"password": {
"env": "GERRIT_HTTP_PASSWORD"
}
}
}
```

<Warning>
Use **HTTP Password**, not your Gerrit account password. Generate an HTTP password in Gerrit: **Settings → HTTP Credentials → Generate Password**.
</Warning>

Set your Gerrit HTTP password as an environment variable:

```bash
export GERRIT_HTTP_PASSWORD="your-generated-http-password"
```

When running with Docker:

```bash
docker run -e GERRIT_HTTP_PASSWORD="your-http-password" ...
```

## Authentication Setup

### Generate HTTP Password

1. Log into your Gerrit instance
2. Go to **Settings** → **HTTP Credentials** → **Generate Password**
3. Copy the generated password (this is your HTTP password)

<Note>
**Special Characters**: If your HTTP password contains special characters like `/`, `+`, or `=`, Sourcebot automatically handles URL encoding for git operations.
</Note>

## Examples

<AccordionGroup>
<Accordion title="Public Gerrit instance">
```json
{
"type": "gerrit",
"url": "https://gerrit.googlesource.com",
"projects": ["android/platform/build"]
}
```
</Accordion>

<Accordion title="Private Gerrit with authentication">
```json
{
"type": "gerrit",
"url": "https://gerrit.company.com",
"projects": ["internal-project"],
"auth": {
"username": "john.doe",
"password": {
"env": "GERRIT_HTTP_PASSWORD"
}
}
}
```
</Accordion>

<Accordion title="Sync projects by glob pattern">
```json
{
"type": "gerrit",
"url": "https://gerrit.example.com",
// Sync all repos under project1 and project2/sub-project
"projects": [
"project1/**",
"project2/sub-project/**"
]
],
"auth": {
"username": "your-username",
"password": {
"env": "GERRIT_HTTP_PASSWORD"
}
}
}
```
</Accordion>

<Accordion title="Exclude repos from syncing">
```json
{
"type": "gerrit",
"url": "https://gerrit.example.com",
// Sync all repos under project1 and project2/sub-project...
"projects": [
"project1/**",
"project2/sub-project/**"
],
// ...except:
"exclude": {
// any project that matches these glob patterns
"projects": [
"project1/foo-project",
"project2/sub-project/some-sub-folder/**"
],

// projects that have state READ_ONLY
"readOnly": true,

// projects that have state HIDDEN
"hidden": true
},
"auth": {
"username": "your-username",
"password": {
"env": "GERRIT_HTTP_PASSWORD"
}
}
}
```
</Accordion>
</AccordionGroup>

## Schema reference
## Schema Reference

<Accordion title="Reference">
[schemas/v3/gerrit.json](https://github.com/sourcebot-dev/sourcebot/blob/main/schemas/v3/gerrit.json)

<GerritSchema />

</Accordion>
</Accordion>

2 changes: 2 additions & 0 deletions docs/snippets/schemas/v3/bitbucket.schema.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"properties": {
"secret": {
"type": "string",
"minLength": 1,
"description": "The name of the secret that contains the token."
}
},
Expand All @@ -39,6 +40,7 @@
"properties": {
"env": {
"type": "string",
"minLength": 1,
"description": "The name of the environment variable that contains the token. Only supported in declarative connection configs."
}
},
Expand Down
67 changes: 67 additions & 0 deletions docs/snippets/schemas/v3/connection.schema.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"properties": {
"secret": {
"type": "string",
"minLength": 1,
"description": "The name of the secret that contains the token."
}
},
Expand All @@ -39,6 +40,7 @@
"properties": {
"env": {
"type": "string",
"minLength": 1,
"description": "The name of the environment variable that contains the token. Only supported in declarative connection configs."
}
},
Expand Down Expand Up @@ -239,6 +241,7 @@
"properties": {
"secret": {
"type": "string",
"minLength": 1,
"description": "The name of the secret that contains the token."
}
},
Expand All @@ -252,6 +255,7 @@
"properties": {
"env": {
"type": "string",
"minLength": 1,
"description": "The name of the environment variable that contains the token. Only supported in declarative connection configs."
}
},
Expand Down Expand Up @@ -441,6 +445,7 @@
"properties": {
"secret": {
"type": "string",
"minLength": 1,
"description": "The name of the secret that contains the token."
}
},
Expand All @@ -454,6 +459,7 @@
"properties": {
"env": {
"type": "string",
"minLength": 1,
"description": "The name of the environment variable that contains the token. Only supported in declarative connection configs."
}
},
Expand Down Expand Up @@ -597,6 +603,65 @@
],
"pattern": "^https?:\\/\\/[^\\s/$.?#].[^\\s]*$"
},
"auth": {
"type": "object",
"description": "Authentication configuration for Gerrit",
"properties": {
"username": {
"type": "string",
"description": "Gerrit username for authentication",
"examples": [
"john.doe"
]
},
"password": {
"description": "Gerrit HTTP password (not your account password). Generate this in Gerrit → Settings → HTTP Credentials → Generate Password. Note: HTTP password authentication requires Gerrit's auth.gitBasicAuthPolicy to be set to HTTP or HTTP_LDAP.",
"examples": [
{
"env": "GERRIT_HTTP_PASSWORD"
},
{
"secret": "GERRIT_PASSWORD_SECRET"
}
],
"anyOf": [
{
"type": "object",
"properties": {
"secret": {
"type": "string",
"minLength": 1,
"description": "The name of the secret that contains the token."
}
},
"required": [
"secret"
],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"env": {
"type": "string",
"minLength": 1,
"description": "The name of the environment variable that contains the token. Only supported in declarative connection configs."
}
},
"required": [
"env"
],
"additionalProperties": false
}
]
}
},
"required": [
"username",
"password"
],
"additionalProperties": false
},
"projects": {
"type": "array",
"items": {
Expand Down Expand Up @@ -672,6 +737,7 @@
"properties": {
"secret": {
"type": "string",
"minLength": 1,
"description": "The name of the secret that contains the token."
}
},
Expand All @@ -685,6 +751,7 @@
"properties": {
"env": {
"type": "string",
"minLength": 1,
"description": "The name of the environment variable that contains the token. Only supported in declarative connection configs."
}
},
Expand Down
Loading