Skip to content
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

Use Mongo auth for Lf Classic connections #817

Merged
merged 1 commit into from
May 27, 2024
Merged
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
8 changes: 8 additions & 0 deletions backend/LfClassicData/DataServiceKernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ public static MongoClientSettings BuildMongoClientSettings(IServiceProvider prov
{
var config = provider.GetRequiredService<IOptions<LfClassicConfig>>();
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<ILoggerFactory>());
mongoSettings.ClusterConfigurator = cb =>
cb.Subscribe(new DiagnosticsActivityEventSubscriber(new() { CaptureCommandText = true }));
Expand Down
5 changes: 5 additions & 0 deletions backend/LfClassicData/LfClassicConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
15 changes: 15 additions & 0 deletions deployment/base/lexbox-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions deployment/base/secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading