Skip to content

Commit a023838

Browse files
authored
Merge pull request #168 from dolthub/taylor/user-header
Pass through user headers from reverse proxy for commit author
2 parents 87a3ce4 + a340fdb commit a023838

File tree

42 files changed

+345
-117
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+345
-117
lines changed

docker/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,46 @@ Or you can run a Dolt SQL server for an existing database on your local machine:
190190

191191
When you enter your database configuration from the UI, you can use `my-doltdb` as the host name to connect to the database running in that container.
192192

193+
## Using a reverse proxy
194+
195+
In some circumstances you may want to add a reverse proxy in front of the Dolt Workbench
196+
for authentication or other purposes. If you'd like to use the authenticated user from the
197+
proxy as the author for commits or tags, you can pass through the user headers.
198+
199+
For example, given this [NGINX](https://www.nginx.com/) configuration that implements basic authentication:
200+
201+
```conf
202+
events {}
203+
204+
http {
205+
server {
206+
listen 80;
207+
server_name localhost;
208+
209+
location / {
210+
auth_basic "Restricted Access";
211+
auth_basic_user_file /etc/nginx/.htpasswd;
212+
213+
proxy_pass http://workbench:3000;
214+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
215+
proxy_set_header Host $host;
216+
proxy_set_header X-Forwarded-Proto $scheme;
217+
proxy_set_header X-Forwarded-User $remote_user;
218+
proxy_set_header X-Forwarded-Email [email protected];
219+
}
220+
}
221+
}
222+
```
223+
224+
The `X-Forwarded-User` and `X-Forwarded-Email` headers are passed through to the workbench
225+
and can used as the
226+
[author](https://docs.dolthub.com/sql-reference/version-control/dolt-sql-procedures#options-6)
227+
when creating a commit. Simply check the "Use name and email from headers as commit
228+
author" checkbox. The commit will be created with the user and email.
229+
230+
You can also utilize this checkbox when creating releases and merging pull requests. If
231+
the headers are not properly configured the checkbox will be disabled.
232+
193233
## Contact
194234

195235
You can reach us on [Discord](https://discord.com/invite/RFwfYpu) or [file a GitHub issue](https://github.com/dolthub/dolt-workbench/issues).
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
taylor:$apr1$0jAEdtKz$bijebRrD5MD9MR0buo6eH1
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# nginx-reverse-proxy
2+
3+
Adds a reverse proxy in front of the Dolt Workbench that implements basic authentication.
4+
It passes through user headers that can be used by the workbench as the author of commits
5+
and tags.
6+
7+
## Getting started
8+
9+
```
10+
% docker compose build
11+
% docker compose up
12+
```
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
services:
2+
combined:
3+
build:
4+
context: ../../../
5+
dockerfile: docker/Dockerfile
6+
ports:
7+
- 3000:3000
8+
- 9002:9002
9+
image: docker.io/dolthub/dolt-workbench:latest
10+
11+
proxy:
12+
image: nginx:latest
13+
ports:
14+
- "80:80"
15+
volumes:
16+
- ./nginx.conf:/etc/nginx/nginx.conf:ro
17+
- ./.htpasswd:/etc/nginx/.htpasswd:ro
18+
depends_on:
19+
- combined
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
events {}
2+
3+
http {
4+
server {
5+
listen 80;
6+
server_name localhost;
7+
8+
location / {
9+
auth_basic "Restricted Access";
10+
auth_basic_user_file /etc/nginx/.htpasswd;
11+
12+
proxy_pass http://combined:3000;
13+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
14+
proxy_set_header Host $host;
15+
proxy_set_header X-Forwarded-Proto $scheme;
16+
proxy_set_header X-Forwarded-User $remote_user;
17+
proxy_set_header X-Forwarded-Email $remote_user@dolthub.com;
18+
}
19+
}
20+
}

graphql-server/schema.gql

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,8 @@ type Mutation {
346346
createSchema(schemaName: String!): Boolean!
347347
resetDatabase: Boolean!
348348
loadDataFile(tableName: String!, refName: String!, databaseName: String!, importOp: ImportOperation!, fileType: FileType!, file: Upload!, modifier: LoadDataModifier): Boolean!
349-
mergePull(databaseName: String!, fromBranchName: String!, toBranchName: String!): Boolean!
350-
createTag(tagName: String!, databaseName: String!, message: String, fromRefName: String!): String!
349+
mergePull(fromBranchName: String!, toBranchName: String!, databaseName: String!, author: AuthorInfo): Boolean!
350+
createTag(tagName: String!, databaseName: String!, message: String, fromRefName: String!, author: AuthorInfo): String!
351351
deleteTag(databaseName: String!, tagName: String!): Boolean!
352352
}
353353

@@ -366,4 +366,9 @@ scalar Upload
366366
enum LoadDataModifier {
367367
Ignore
368368
Replace
369+
}
370+
371+
input AuthorInfo {
372+
name: String!
373+
email: String!
369374
}

graphql-server/src/app.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Module } from "@nestjs/common";
33
import { ConfigModule } from "@nestjs/config";
44
import { GraphQLModule } from "@nestjs/graphql";
55
import { TerminusModule } from "@nestjs/terminus";
6+
import { ConnectionProvider } from "./connections/connection.provider";
67
import { DataStoreModule } from "./dataStore/dataStore.module";
78
import { FileStoreModule } from "./fileStore/fileStore.module";
89
import resolvers from "./resolvers";
@@ -19,6 +20,6 @@ import resolvers from "./resolvers";
1920
ConfigModule.forRoot({ isGlobal: true }),
2021
DataStoreModule,
2122
],
22-
providers: resolvers,
23+
providers: [ConnectionProvider, ...resolvers],
2324
})
2425
export class AppModule {}

graphql-server/src/branches/branch.resolver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
ResolveField,
99
Resolver,
1010
} from "@nestjs/graphql";
11-
import { ConnectionResolver } from "../connections/connection.resolver";
11+
import { ConnectionProvider } from "../connections/connection.provider";
1212
import { RawRow } from "../queryFactory/types";
1313
import { Table } from "../tables/table.model";
1414
import { TableResolver } from "../tables/table.resolver";
@@ -53,7 +53,7 @@ class ListBranchesArgs extends DBArgsWithOffset {
5353
@Resolver(_of => Branch)
5454
export class BranchResolver {
5555
constructor(
56-
private readonly conn: ConnectionResolver,
56+
private readonly conn: ConnectionProvider,
5757
private readonly tableResolver: TableResolver,
5858
) {}
5959

graphql-server/src/commits/commit.resolver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Args, ArgsType, Field, Query, Resolver } from "@nestjs/graphql";
2-
import { ConnectionResolver } from "../connections/connection.resolver";
2+
import { ConnectionProvider } from "../connections/connection.provider";
33
import { RawRow } from "../queryFactory/types";
44
import { ROW_LIMIT, getNextOffset } from "../utils";
55
import { DBArgsWithOffset } from "../utils/commonTypes";
@@ -23,7 +23,7 @@ export class ListCommitsArgs extends DBArgsWithOffset {
2323

2424
@Resolver(_of => Commit)
2525
export class CommitResolver {
26-
constructor(private readonly conn: ConnectionResolver) {}
26+
constructor(private readonly conn: ConnectionProvider) {}
2727

2828
@Query(_returns => CommitList)
2929
async commits(

graphql-server/src/connections/connection.resolver.ts renamed to graphql-server/src/connections/connection.provider.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Resolver } from "@nestjs/graphql";
1+
import { Injectable } from "@nestjs/common";
22
import * as mysql from "mysql2/promise";
33
import { DataSource } from "typeorm";
44
import { DatabaseType } from "../databases/database.enum";
@@ -19,8 +19,8 @@ export class WorkbenchConfig {
1919
schema?: string; // Postgres only
2020
}
2121

22-
@Resolver()
23-
export class ConnectionResolver {
22+
@Injectable()
23+
export class ConnectionProvider {
2424
private ds: DataSource | undefined;
2525

2626
private qf: QueryFactory | undefined;

0 commit comments

Comments
 (0)