diff --git a/backend/LfClassicData/DataServiceKernel.cs b/backend/LfClassicData/DataServiceKernel.cs index bf5cc351a..d026e4931 100644 --- a/backend/LfClassicData/DataServiceKernel.cs +++ b/backend/LfClassicData/DataServiceKernel.cs @@ -35,6 +35,14 @@ public static MongoClientSettings BuildMongoClientSettings(IServiceProvider prov { var config = provider.GetRequiredService>(); var mongoSettings = MongoClientSettings.FromConnectionString(config.Value.ConnectionString); + if (config.Value.HasCredentials) + { + mongoSettings.Credential = MongoCredential.CreateCredential( + databaseName: config.Value.AuthSource, + username: config.Value.Username, + password: config.Value.Password + ); + } mongoSettings.LoggingSettings = new LoggingSettings(provider.GetRequiredService()); mongoSettings.ClusterConfigurator = cb => cb.Subscribe(new DiagnosticsActivityEventSubscriber(new() { CaptureCommandText = true })); diff --git a/backend/LfClassicData/LfClassicConfig.cs b/backend/LfClassicData/LfClassicConfig.cs index f55a0b4ae..2634f60db 100644 --- a/backend/LfClassicData/LfClassicConfig.cs +++ b/backend/LfClassicData/LfClassicConfig.cs @@ -6,4 +6,9 @@ public class LfClassicConfig { [Required] public required string ConnectionString { get; set; } + + public string? AuthSource { get; set; } + public string? Username { get; set; } + public string? Password { get; set; } + public bool HasCredentials => AuthSource is not null && Username is not null && Password is not null; } diff --git a/deployment/base/lexbox-deployment.yaml b/deployment/base/lexbox-deployment.yaml index 8d141d288..96e6debd1 100644 --- a/deployment/base/lexbox-deployment.yaml +++ b/deployment/base/lexbox-deployment.yaml @@ -120,6 +120,21 @@ spec: value: Host=db;Port=5432;Username=postgres;Password=$(POSTGRES_PASSWORD);Database=$(POSTGRES_DB) - name: LfClassicConfig__ConnectionString value: mongodb://db.languageforge:27017 + - name: LfClassicConfig__AuthSource + valueFrom: + secretKeyRef: + key: MONGODB_AUTHSOURCE + name: lf-mongo-auth + - name: LfClassicConfig__Username + valueFrom: + secretKeyRef: + key: MONGODB_USER + name: lf-mongo-auth + - name: LfClassicConfig__Password + valueFrom: + secretKeyRef: + key: MONGODB_PASS + name: lf-mongo-auth - name: Authentication__Jwt__Secret valueFrom: secretKeyRef: diff --git a/deployment/base/secrets.yaml b/deployment/base/secrets.yaml index ca823a19a..94236d32a 100644 --- a/deployment/base/secrets.yaml +++ b/deployment/base/secrets.yaml @@ -13,6 +13,18 @@ stringData: --- +apiVersion: v1 +kind: Secret +metadata: + name: lf-mongo-auth + namespace: languagedepot +stringData: + MONGODB_AUTHSOURCE: '' + MONGODB_USER: '' + MONGODB_PASS: '' + +--- + apiVersion: v1 kind: Secret metadata: