Skip to content

Commit ebe0842

Browse files
authored
Merge branch 'main' into bump-to-rc.4
2 parents 8c94491 + e767463 commit ebe0842

File tree

7 files changed

+298
-51
lines changed

7 files changed

+298
-51
lines changed

config.schema.json

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
},
3333
"gitleaks": {
3434
"type": "object",
35-
"description": "Configuration for the gitleaks (https://github.com/gitleaks/gitleaks) plugin",
35+
"description": "Configuration for the gitleaks [https://github.com/gitleaks/gitleaks](https://github.com/gitleaks/gitleaks) plugin",
3636
"properties": {
3737
"enabled": { "type": "boolean" },
3838
"ignoreGitleaksAllow": { "type": "boolean" },
@@ -192,17 +192,20 @@
192192
"additionalProperties": false,
193193
"properties": {
194194
"text": {
195-
"type": "string"
195+
"type": "string",
196+
"description": "Tooltip text"
196197
},
197198
"links": {
198199
"type": "array",
200+
"description": "An array of links to display under the tooltip text, providing additional context about the question",
199201
"items": {
200202
"type": "object",
201203
"additionalProperties": false,
202204
"properties": {
203-
"text": { "type": "string" },
204-
"url": { "type": "string", "format": "url" }
205-
}
205+
"text": { "type": "string", "description": "Link text" },
206+
"url": { "type": "string", "format": "url", "description": "Link URL" }
207+
},
208+
"required": ["text", "url"]
206209
}
207210
}
208211
},
@@ -377,15 +380,56 @@
377380
"required": ["project", "name", "url"]
378381
},
379382
"database": {
380-
"type": "object",
381-
"properties": {
382-
"type": { "type": "string" },
383-
"enabled": { "type": "boolean" },
384-
"connectionString": { "type": "string" },
385-
"options": { "type": "object" },
386-
"params": { "type": "object" }
387-
},
388-
"required": ["type", "enabled"]
383+
"description": "Configuration entry for a database",
384+
"oneOf": [
385+
{
386+
"type": "object",
387+
"name": "MongoDB Config",
388+
"description": "Connection properties for mongoDB. Options may be passed in either the connection string or broken out in the options object",
389+
"properties": {
390+
"type": { "type": "string", "const": "mongo" },
391+
"enabled": { "type": "boolean" },
392+
"connectionString": {
393+
"type": "string",
394+
"description": "mongoDB Client connection string, see [https://www.mongodb.com/docs/manual/reference/connection-string/](https://www.mongodb.com/docs/manual/reference/connection-string/)"
395+
},
396+
"options": {
397+
"type": "object",
398+
"description": "mongoDB Client connection options. Please note that only custom options are described here, see [https://www.mongodb.com/docs/drivers/node/current/connect/connection-options/](https://www.mongodb.com/docs/drivers/node/current/connect/connection-options/) for all config options.",
399+
"properties": {
400+
"authMechanismProperties": {
401+
"type": "object",
402+
"properties": {
403+
"AWS_CREDENTIAL_PROVIDER": {
404+
"type": "boolean",
405+
"description": "If set to true, the `fromNodeProviderChain()` function from @aws-sdk/credential-providers is passed as the `AWS_CREDENTIAL_PROVIDER`"
406+
}
407+
},
408+
"additionalProperties": true
409+
}
410+
},
411+
"required": [],
412+
"additionalProperties": true
413+
}
414+
},
415+
"required": ["type", "enabled", "connectionString"]
416+
},
417+
{
418+
"type": "object",
419+
"name": "File-based DB Config",
420+
"description": "Connection properties for an neDB file-based database",
421+
"properties": {
422+
"type": { "type": "string", "const": "fs" },
423+
"enabled": { "type": "boolean" },
424+
"params": {
425+
"type": "object",
426+
"description": "Legacy config property not currently used",
427+
"deprecated": true
428+
}
429+
},
430+
"required": ["type", "enabled"]
431+
}
432+
]
389433
},
390434
"authenticationElement": {
391435
"type": "object",

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
"url": "https://github.com/finos/git-proxy"
8282
},
8383
"dependencies": {
84+
"@aws-sdk/credential-providers": "^3.940.0",
8485
"@material-ui/core": "^4.12.4",
8586
"@material-ui/icons": "4.11.3",
8687
"@primer/octicons-react": "^19.21.0",

src/config/generated/config.ts

Lines changed: 90 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ export interface GitProxyConfig {
112112
*/
113113
export interface API {
114114
/**
115-
* Configuration for the gitleaks (https://github.com/gitleaks/gitleaks) plugin
115+
* Configuration for the gitleaks
116+
* [https://github.com/gitleaks/gitleaks](https://github.com/gitleaks/gitleaks) plugin
116117
*/
117118
gitleaks?: Gitleaks;
118119
/**
@@ -124,7 +125,8 @@ export interface API {
124125
}
125126

126127
/**
127-
* Configuration for the gitleaks (https://github.com/gitleaks/gitleaks) plugin
128+
* Configuration for the gitleaks
129+
* [https://github.com/gitleaks/gitleaks](https://github.com/gitleaks/gitleaks) plugin
128130
*/
129131
export interface Gitleaks {
130132
configPath?: string;
@@ -157,7 +159,7 @@ export interface Ls {
157159
*/
158160
export interface AuthenticationElement {
159161
enabled: boolean;
160-
type: Type;
162+
type: AuthenticationElementType;
161163
/**
162164
* Additional Active Directory configuration supporting LDAP connection which can be used to
163165
* confirm group membership. For the full set of available options see the activedirectory 2
@@ -251,7 +253,7 @@ export interface OidcConfig {
251253
[property: string]: any;
252254
}
253255

254-
export enum Type {
256+
export enum AuthenticationElementType {
255257
ActiveDirectory = 'ActiveDirectory',
256258
Jwt = 'jwt',
257259
Local = 'local',
@@ -286,13 +288,26 @@ export interface Question {
286288
* and used to provide additional guidance to the reviewer.
287289
*/
288290
export interface QuestionTooltip {
291+
/**
292+
* An array of links to display under the tooltip text, providing additional context about
293+
* the question
294+
*/
289295
links?: Link[];
296+
/**
297+
* Tooltip text
298+
*/
290299
text: string;
291300
}
292301

293302
export interface Link {
294-
text?: string;
295-
url?: string;
303+
/**
304+
* Link text
305+
*/
306+
text: string;
307+
/**
308+
* Link URL
309+
*/
310+
url: string;
296311
}
297312

298313
export interface AuthorisedRepo {
@@ -458,15 +473,61 @@ export interface RateLimit {
458473
windowMs: number;
459474
}
460475

476+
/**
477+
* Configuration entry for a database
478+
*
479+
* Connection properties for mongoDB. Options may be passed in either the connection string
480+
* or broken out in the options object
481+
*
482+
* Connection properties for an neDB file-based database
483+
*/
461484
export interface Database {
485+
/**
486+
* mongoDB Client connection string, see
487+
* [https://www.mongodb.com/docs/manual/reference/connection-string/](https://www.mongodb.com/docs/manual/reference/connection-string/)
488+
*/
462489
connectionString?: string;
463490
enabled: boolean;
464-
options?: { [key: string]: any };
491+
/**
492+
* mongoDB Client connection options. Please note that only custom options are described
493+
* here, see
494+
* [https://www.mongodb.com/docs/drivers/node/current/connect/connection-options/](https://www.mongodb.com/docs/drivers/node/current/connect/connection-options/)
495+
* for all config options.
496+
*/
497+
options?: Options;
498+
type: DatabaseType;
499+
/**
500+
* Legacy config property not currently used
501+
*/
465502
params?: { [key: string]: any };
466-
type: string;
467503
[property: string]: any;
468504
}
469505

506+
/**
507+
* mongoDB Client connection options. Please note that only custom options are described
508+
* here, see
509+
* [https://www.mongodb.com/docs/drivers/node/current/connect/connection-options/](https://www.mongodb.com/docs/drivers/node/current/connect/connection-options/)
510+
* for all config options.
511+
*/
512+
export interface Options {
513+
authMechanismProperties?: AuthMechanismProperties;
514+
[property: string]: any;
515+
}
516+
517+
export interface AuthMechanismProperties {
518+
/**
519+
* If set to true, the `fromNodeProviderChain()` function from @aws-sdk/credential-providers
520+
* is passed as the `AWS_CREDENTIAL_PROVIDER`
521+
*/
522+
AWS_CREDENTIAL_PROVIDER?: boolean;
523+
[property: string]: any;
524+
}
525+
526+
export enum DatabaseType {
527+
FS = 'fs',
528+
Mongo = 'mongo',
529+
}
530+
470531
/**
471532
* Toggle the generation of temporary password for git-proxy admin user
472533
*/
@@ -747,7 +808,7 @@ const typeMap: any = {
747808
AuthenticationElement: o(
748809
[
749810
{ json: 'enabled', js: 'enabled', typ: true },
750-
{ json: 'type', js: 'type', typ: r('Type') },
811+
{ json: 'type', js: 'type', typ: r('AuthenticationElementType') },
751812
{ json: 'adConfig', js: 'adConfig', typ: u(undefined, r('AdConfig')) },
752813
{ json: 'adminGroup', js: 'adminGroup', typ: u(undefined, '') },
753814
{ json: 'domain', js: 'domain', typ: u(undefined, '') },
@@ -807,8 +868,8 @@ const typeMap: any = {
807868
),
808869
Link: o(
809870
[
810-
{ json: 'text', js: 'text', typ: u(undefined, '') },
811-
{ json: 'url', js: 'url', typ: u(undefined, '') },
871+
{ json: 'text', js: 'text', typ: '' },
872+
{ json: 'url', js: 'url', typ: '' },
812873
],
813874
false,
814875
),
@@ -875,12 +936,26 @@ const typeMap: any = {
875936
[
876937
{ json: 'connectionString', js: 'connectionString', typ: u(undefined, '') },
877938
{ json: 'enabled', js: 'enabled', typ: true },
878-
{ json: 'options', js: 'options', typ: u(undefined, m('any')) },
939+
{ json: 'options', js: 'options', typ: u(undefined, r('Options')) },
940+
{ json: 'type', js: 'type', typ: r('DatabaseType') },
879941
{ json: 'params', js: 'params', typ: u(undefined, m('any')) },
880-
{ json: 'type', js: 'type', typ: '' },
881942
],
882943
'any',
883944
),
945+
Options: o(
946+
[
947+
{
948+
json: 'authMechanismProperties',
949+
js: 'authMechanismProperties',
950+
typ: u(undefined, r('AuthMechanismProperties')),
951+
},
952+
],
953+
'any',
954+
),
955+
AuthMechanismProperties: o(
956+
[{ json: 'AWS_CREDENTIAL_PROVIDER', js: 'AWS_CREDENTIAL_PROVIDER', typ: u(undefined, true) }],
957+
'any',
958+
),
884959
TempPassword: o(
885960
[
886961
{ json: 'emailConfig', js: 'emailConfig', typ: u(undefined, m('any')) },
@@ -911,5 +986,6 @@ const typeMap: any = {
911986
],
912987
'any',
913988
),
914-
Type: ['ActiveDirectory', 'jwt', 'local', 'openidconnect'],
989+
AuthenticationElementType: ['ActiveDirectory', 'jwt', 'local', 'openidconnect'],
990+
DatabaseType: ['fs', 'mongo'],
915991
};

src/db/mongo/helper.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { MongoClient, Db, Collection, Filter, Document, FindOptions } from 'mongodb';
22
import { getDatabase } from '../../config';
33
import MongoDBStore from 'connect-mongo';
4+
import { fromNodeProviderChain } from '@aws-sdk/credential-providers';
45

56
let _db: Db | null = null;
67

@@ -15,6 +16,11 @@ export const connect = async (collectionName: string): Promise<Collection> => {
1516
throw new Error('MongoDB connection string is not provided');
1617
}
1718

19+
if (options?.authMechanismProperties?.AWS_CREDENTIAL_PROVIDER) {
20+
// we break from the config types here as we're providing a function to the mongoDB client
21+
(options.authMechanismProperties.AWS_CREDENTIAL_PROVIDER as any) = fromNodeProviderChain();
22+
}
23+
1824
const client = new MongoClient(connectionString, options);
1925
await client.connect();
2026
_db = client.db();

src/service/passport/jwtAuthHandler.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
import { assignRoles, validateJwt } from './jwtUtils';
22
import type { Request, Response, NextFunction } from 'express';
33
import { getAPIAuthMethods } from '../../config';
4-
import { AuthenticationElement, JwtConfig, RoleMapping, Type } from '../../config/generated/config';
4+
import {
5+
AuthenticationElement,
6+
JwtConfig,
7+
RoleMapping,
8+
AuthenticationElementType,
9+
} from '../../config/generated/config';
510

611
export const type = 'jwt';
712

813
export const jwtAuthHandler = (overrideConfig: JwtConfig | null = null) => {
914
return async (req: Request, res: Response, next: NextFunction): Promise<void> => {
1015
const apiAuthMethods: AuthenticationElement[] = overrideConfig
11-
? [{ type: 'jwt' as Type, enabled: true, jwtConfig: overrideConfig }]
16+
? [{ type: 'jwt' as AuthenticationElementType, enabled: true, jwtConfig: overrideConfig }]
1217
: getAPIAuthMethods();
1318

1419
const jwtAuthMethod = apiAuthMethods.find((method) => method.type.toLowerCase() === type);

test/generated-config.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('Generated Config (QuickType)', () => {
2323
],
2424
sink: [
2525
{
26-
type: 'memory',
26+
type: 'fs',
2727
enabled: true,
2828
},
2929
],

0 commit comments

Comments
 (0)