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

infra-config: Add more DB config settings #1694

Merged
merged 2 commits into from
Jan 10, 2025
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
688 changes: 351 additions & 337 deletions proto/encore/runtime/v1/infra.pb.go

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions proto/encore/runtime/v1/infra.proto
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ message TLSConfig {
// If invalid hostnames are trusted, *any* valid certificate for *any* site will be trusted for use.
// This introduces significant vulnerabilities, and should only be used as a last resort.
bool disable_tls_hostname_verification = 2;

// If true, skips CA cert validation when connecting.
// This introduces significant vulnerabilities, and should only be used as a last resort.
bool disable_ca_validation = 3;
}

message SQLServer {
Expand Down
7 changes: 6 additions & 1 deletion runtimes/core/src/infracfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,13 @@ pub struct TLSConfig {
pub client_cert: Option<ClientCert>,
#[serde(default)]
pub disable_tls_hostname_verification: bool,
#[serde(default)]
pub disable_ca_validation: bool,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct SQLDatabase {
pub name: Option<String>,
pub max_connections: Option<i32>,
pub min_connections: Option<i32>,
pub username: String,
Expand Down Expand Up @@ -651,7 +654,7 @@ pub fn map_infra_to_runtime(infra: InfraConfig) -> RuntimeConfig {
SqlDatabase {
rid: get_next_rid(),
encore_name: name.clone(),
cloud_name: name,
cloud_name: db.name.unwrap_or(name),
conn_pools: vec![SqlConnectionPool {
is_readonly: false,
role_rid,
Expand All @@ -676,6 +679,7 @@ pub fn map_infra_to_runtime(infra: InfraConfig) -> RuntimeConfig {
server_ca_cert: tls.ca,
disable_tls_hostname_verification: tls
.disable_tls_hostname_verification,
disable_ca_validation: tls.disable_ca_validation,
}),
},
),
Expand Down Expand Up @@ -754,6 +758,7 @@ pub fn map_infra_to_runtime(infra: InfraConfig) -> RuntimeConfig {
server_ca_cert: tls.ca,
disable_tls_hostname_verification: tls
.disable_tls_hostname_verification,
disable_ca_validation: tls.disable_ca_validation,
}),
},
),
Expand Down
3 changes: 3 additions & 0 deletions runtimes/core/src/sqldb/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ fn databases_from_cfg(
if tls_config.disable_tls_hostname_verification {
tls_builder.danger_accept_invalid_hostnames(true);
}
if tls_config.disable_ca_validation {
tls_builder.danger_accept_invalid_certs(true);
}
} else {
config.ssl_mode(tokio_postgres::config::SslMode::Disable);
}
Expand Down
2 changes: 2 additions & 0 deletions runtimes/go/appruntime/exported/config/infra/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,13 +472,15 @@ type TLSConfig struct {
CA string `json:"ca,omitempty"`
ClientCert *ClientCert `json:"client_cert,omitempty"`
DisableTLSHostnameVerification bool `json:"disable_tls_hostname_verification,omitempty"`
DisableCAValidation bool `json:"disable_ca_validation,omitempty"`
}

func (t *TLSConfig) Validate(v *validator) {
v.ValidateChild("client_cert", t.ClientCert)
}

type SQLDatabase struct {
Name string `json:"name,omitempty"`
MaxConnections int `json:"max_connections,omitempty"`
MinConnections int `json:"min_connections,omitempty"`
Username EnvString `json:"username,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion runtimes/go/appruntime/exported/config/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func parseInfraConfigEnv(infraCfgPath string) *Runtime {
for dbName, db := range sqlServer.Databases {
cfg.SQLDatabases = append(cfg.SQLDatabases, &SQLDatabase{
ServerID: i,
EncoreName: dbName,
EncoreName: orDefault(db.Name, dbName),
DatabaseName: dbName,
User: db.Username.Value(),
Password: db.Password.Value(),
Expand Down
2 changes: 1 addition & 1 deletion tsparser/litparser-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ fn is_optional(ty: &syn::Type) -> bool {
path: syn::Path { segments, .. },
}) => {
// Return true if the last path segment is "Option".
segments.last().map_or(false, |seg| seg.ident == "Option")
segments.last().is_some_and(|seg| seg.ident == "Option")
}
_ => false,
}
Expand Down
Loading