Skip to content

Commit

Permalink
Use Mongo auth for Lf Classic connections (#817)
Browse files Browse the repository at this point in the history
The username and password supplied in the k8s secrets are for an account
with read-only access to any non-system database.
  • Loading branch information
rmunn authored May 27, 2024
1 parent 774f253 commit b83c78b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
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

0 comments on commit b83c78b

Please sign in to comment.