feat(cassandra): add TLS store support
This commit is contained in:
26 files changed
+1203
-36
No files matched your search
@@ -13,7 +13,8 @@ multi-session JSON-RPC protocol without a JVM.
|
|||||||
- Astra validation: secure-connect bundle parsing and transport configuration;
|
- Astra validation: secure-connect bundle parsing and transport configuration;
|
||||||
live Astra credentials were not available
|
live Astra credentials were not available
|
||||||
- Authentication: username/password and Kerberos/GSSAPI
|
- Authentication: username/password and Kerberos/GSSAPI
|
||||||
- TLS: CA verification, optional client certificate/key, hostname verification
|
- TLS: CA verification, optional client certificate/key, JKS/PKCS#12 stores,
|
||||||
|
hostname verification
|
||||||
- Cloud: DataStax Astra secure connect bundles
|
- Cloud: DataStax Astra secure connect bundles
|
||||||
- Configuration: Java Driver 4 HOCON `configfile` mapping plus native extensions
|
- Configuration: Java Driver 4 HOCON `configfile` mapping plus native extensions
|
||||||
- Metadata: keyspaces, tables, columns, indexes, CQL table DDL, completion search
|
- Metadata: keyspaces, tables, columns, indexes, CQL table DDL, completion search
|
||||||
@@ -38,6 +39,8 @@ syntax.
|
|||||||
| `enablessl` | TLS enablement |
|
| `enablessl` | TLS enablement |
|
||||||
| `sslenginefactory` | the standard `DefaultSslEngineFactory` maps to native TLS |
|
| `sslenginefactory` | the standard `DefaultSslEngineFactory` maps to native TLS |
|
||||||
| `hostnameverification` | TLS hostname verification; enabled by default |
|
| `hostnameverification` | TLS hostname verification; enabled by default |
|
||||||
|
| `truststorepath`, `truststorepassword` | JKS/PKCS#12 server trust configuration |
|
||||||
|
| `keystorepath`, `keystorepassword` | JKS/PKCS#12 client certificate configuration |
|
||||||
| `user`, `password` | password authentication |
|
| `user`, `password` | password authentication |
|
||||||
| `configfile` | Java Driver 4 HOCON configuration; overrides URL options except contact points and keyspace |
|
| `configfile` | Java Driver 4 HOCON configuration; overrides URL options except contact points and keyspace |
|
||||||
| `usekrb5` | Kerberos/GSSAPI authentication using password, keytab, or FILE credential cache |
|
| `usekrb5` | Kerberos/GSSAPI authentication using password, keytab, or FILE credential cache |
|
||||||
@@ -48,8 +51,8 @@ syntax.
|
|||||||
|
|
||||||
The Agent rejects custom Java implementation classes because they cannot be
|
The Agent rejects custom Java implementation classes because they cannot be
|
||||||
loaded by a native binary. This includes custom authentication, SSL, retry,
|
loaded by a native binary. This includes custom authentication, SSL, retry,
|
||||||
reconnection, and load-balancing classes. Java JKS/PKCS12 truststores and
|
reconnection, and load-balancing classes. The default SSL engine's JKS and
|
||||||
keystores are not read directly; use the native PEM paths described below.
|
PKCS#12 truststores and keystores are supported directly.
|
||||||
|
|
||||||
## Java Driver HOCON configuration
|
## Java Driver HOCON configuration
|
||||||
|
|
||||||
@@ -66,7 +69,8 @@ Mapped Java Driver paths include:
|
|||||||
- `advanced.socket.tcp-no-delay` and `keep-alive`
|
- `advanced.socket.tcp-no-delay` and `keep-alive`
|
||||||
- `advanced.protocol.version`, retry policy, and reconnection policy
|
- `advanced.protocol.version`, retry policy, and reconnection policy
|
||||||
- `advanced.auth-provider` plaintext and Instaclustr Kerberos options
|
- `advanced.auth-provider` plaintext and Instaclustr Kerberos options
|
||||||
- `advanced.ssl-engine-factory` default TLS and hostname validation
|
- `advanced.ssl-engine-factory` default TLS, hostname validation, truststore,
|
||||||
|
and keystore settings
|
||||||
|
|
||||||
Native-only settings can be placed under `dbx.cassandra`:
|
Native-only settings can be placed under `dbx.cassandra`:
|
||||||
|
|
||||||
@@ -133,7 +137,8 @@ go test -run TestCassandraIntegration -v
|
|||||||
|
|
||||||
Optional variables include `CASSANDRA_TEST_URL_PARAMS`, `CASSANDRA_TEST_SSL`,
|
Optional variables include `CASSANDRA_TEST_URL_PARAMS`, `CASSANDRA_TEST_SSL`,
|
||||||
`CASSANDRA_TEST_CA_CERT_PATH`, `CASSANDRA_TEST_CLIENT_CERT_PATH`, and
|
`CASSANDRA_TEST_CA_CERT_PATH`, `CASSANDRA_TEST_CLIENT_CERT_PATH`, and
|
||||||
`CASSANDRA_TEST_CLIENT_KEY_PATH`.
|
`CASSANDRA_TEST_CLIENT_KEY_PATH`. Truststore and keystore settings can also be
|
||||||
|
provided through `CASSANDRA_TEST_URL_PARAMS`.
|
||||||
|
|
||||||
See `bench/README.md` for the archived JDBC comparison workflow and measured
|
See `bench/README.md` for the archived JDBC comparison workflow and measured
|
||||||
Cassandra 4.1.10 results.
|
Cassandra 4.1.10 results.
|
||||||
@@ -31,6 +31,10 @@ type cassandraConfig struct {
|
|||||||
caCertPath string
|
caCertPath string
|
||||||
clientCertPath string
|
clientCertPath string
|
||||||
clientKeyPath string
|
clientKeyPath string
|
||||||
|
truststorePath string
|
||||||
|
truststorePassword string
|
||||||
|
keystorePath string
|
||||||
|
keystorePassword string
|
||||||
hostVerification bool
|
hostVerification bool
|
||||||
tcpNoDelay bool
|
tcpNoDelay bool
|
||||||
keepAlive bool
|
keepAlive bool
|
||||||
@@ -61,6 +65,10 @@ func parseCassandraConfig(cp connectParams) (cassandraConfig, error) {
|
|||||||
caCertPath: cp.CACertPath,
|
caCertPath: cp.CACertPath,
|
||||||
clientCertPath: cp.ClientCertPath,
|
clientCertPath: cp.ClientCertPath,
|
||||||
clientKeyPath: cp.ClientKeyPath,
|
clientKeyPath: cp.ClientKeyPath,
|
||||||
|
truststorePath: cp.TruststorePath,
|
||||||
|
truststorePassword: cp.TruststorePassword,
|
||||||
|
keystorePath: cp.KeystorePath,
|
||||||
|
keystorePassword: cp.KeystorePassword,
|
||||||
hostVerification: true,
|
hostVerification: true,
|
||||||
tcpNoDelay: true,
|
tcpNoDelay: true,
|
||||||
retryCount: 3,
|
retryCount: 3,
|
||||||
@@ -224,6 +232,14 @@ func applyCassandraURLParams(config *cassandraConfig, params url.Values) error {
|
|||||||
return fmt.Errorf("invalid host verification option: %w", err)
|
return fmt.Errorf("invalid host verification option: %w", err)
|
||||||
}
|
}
|
||||||
config.hostVerification = enabled
|
config.hostVerification = enabled
|
||||||
|
case "truststorepath":
|
||||||
|
config.truststorePath = value
|
||||||
|
case "truststorepassword":
|
||||||
|
config.truststorePassword = value
|
||||||
|
case "keystorepath":
|
||||||
|
config.keystorePath = value
|
||||||
|
case "keystorepassword":
|
||||||
|
config.keystorePassword = value
|
||||||
case "tcpnodelay":
|
case "tcpnodelay":
|
||||||
enabled, err := strconv.ParseBool(value)
|
enabled, err := strconv.ParseBool(value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -406,12 +422,20 @@ func (config cassandraConfig) clusterConfig(keyspace string) (*gocql.ClusterConf
|
|||||||
cluster.Authenticator = gocql.PasswordAuthenticator{Username: config.username, Password: config.password}
|
cluster.Authenticator = gocql.PasswordAuthenticator{Username: config.username, Password: config.password}
|
||||||
}
|
}
|
||||||
if config.secureConnectBundle == "" && config.ssl {
|
if config.secureConnectBundle == "" && config.ssl {
|
||||||
cluster.SslOpts = &gocql.SslOptions{
|
sslOptions := &gocql.SslOptions{
|
||||||
CaPath: config.caCertPath,
|
CaPath: config.caCertPath,
|
||||||
CertPath: config.clientCertPath,
|
CertPath: config.clientCertPath,
|
||||||
KeyPath: config.clientKeyPath,
|
KeyPath: config.clientKeyPath,
|
||||||
EnableHostVerification: config.hostVerification,
|
EnableHostVerification: config.hostVerification,
|
||||||
}
|
}
|
||||||
|
if config.truststorePath != "" || config.keystorePath != "" {
|
||||||
|
tlsConfig, err := buildCassandraTLSConfig(config)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
sslOptions.Config = tlsConfig
|
||||||
|
}
|
||||||
|
cluster.SslOpts = sslOptions
|
||||||
}
|
}
|
||||||
if config.debug {
|
if config.debug {
|
||||||
cluster.Logger = gocql.NewLogger(gocql.LogLevelDebug)
|
cluster.Logger = gocql.NewLogger(gocql.LogLevelDebug)
|
||||||
@@ -435,6 +459,31 @@ func (config *cassandraConfig) finalize() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("invalid Cassandra secureconnectbundle: %w", err)
|
return fmt.Errorf("invalid Cassandra secureconnectbundle: %w", err)
|
||||||
}
|
}
|
||||||
|
if config.secureConnectBundle == "" {
|
||||||
|
config.truststorePath, err = normalizeLocalFilePath(config.truststorePath)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("invalid Cassandra truststore path: %w", err)
|
||||||
|
}
|
||||||
|
config.keystorePath, err = normalizeLocalFilePath(config.keystorePath)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("invalid Cassandra keystore path: %w", err)
|
||||||
|
}
|
||||||
|
if config.truststorePassword != "" && config.truststorePath == "" {
|
||||||
|
return fmt.Errorf("Cassandra truststore password requires a truststore path")
|
||||||
|
}
|
||||||
|
if config.keystorePassword != "" && config.keystorePath == "" {
|
||||||
|
return fmt.Errorf("Cassandra keystore password requires a keystore path")
|
||||||
|
}
|
||||||
|
if config.truststorePath != "" && strings.TrimSpace(config.caCertPath) != "" {
|
||||||
|
return fmt.Errorf("Cassandra truststore cannot be combined with a PEM CA certificate")
|
||||||
|
}
|
||||||
|
if config.keystorePath != "" && (strings.TrimSpace(config.clientCertPath) != "" || strings.TrimSpace(config.clientKeyPath) != "") {
|
||||||
|
return fmt.Errorf("Cassandra keystore cannot be combined with PEM client certificate settings")
|
||||||
|
}
|
||||||
|
if config.truststorePath != "" || config.keystorePath != "" {
|
||||||
|
config.ssl = true
|
||||||
|
}
|
||||||
|
}
|
||||||
if config.secureConnectBundle != "" && config.kerberos.enabled {
|
if config.secureConnectBundle != "" && config.kerberos.enabled {
|
||||||
return fmt.Errorf("Cassandra secure connect bundles cannot be combined with Kerberos authentication")
|
return fmt.Errorf("Cassandra secure connect bundles cannot be combined with Kerberos authentication")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -263,13 +263,25 @@ func applyHOCONSSL(config *cassandraConfig, parsed *hocon.Config) error {
|
|||||||
config.hostVerification = value
|
config.hostVerification = value
|
||||||
config.ssl = true
|
config.ssl = true
|
||||||
}
|
}
|
||||||
for _, path := range []string{prefix + "truststore-path", prefix + "keystore-path"} {
|
stringMappings := []struct {
|
||||||
if value, ok, err := hoconString(parsed, path); err != nil {
|
path string
|
||||||
|
target *string
|
||||||
|
}{
|
||||||
|
{prefix + "truststore-path", &config.truststorePath},
|
||||||
|
{prefix + "truststore-password", &config.truststorePassword},
|
||||||
|
{prefix + "keystore-path", &config.keystorePath},
|
||||||
|
{prefix + "keystore-password", &config.keystorePassword},
|
||||||
|
}
|
||||||
|
for _, mapping := range stringMappings {
|
||||||
|
if value, ok, err := hoconString(parsed, mapping.path); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if ok && value != "" {
|
} else if ok {
|
||||||
return fmt.Errorf("Java truststore and keystore files are not supported; use dbx.cassandra.tls PEM paths")
|
*mapping.target = value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if config.truststorePath != "" || config.keystorePath != "" {
|
||||||
|
config.ssl = true
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,6 +52,10 @@ datastax-java-driver {
|
|||||||
ssl-engine-factory {
|
ssl-engine-factory {
|
||||||
class = DefaultSslEngineFactory
|
class = DefaultSslEngineFactory
|
||||||
hostname-validation = false
|
hostname-validation = false
|
||||||
|
truststore-path = /certs/client.truststore
|
||||||
|
truststore-password = trust-secret
|
||||||
|
keystore-path = /certs/client.keystore
|
||||||
|
keystore-password = key-secret
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -110,6 +114,12 @@ datastax-java-driver {
|
|||||||
if !config.ssl || config.hostVerification {
|
if !config.ssl || config.hostVerification {
|
||||||
t.Fatalf("unexpected TLS config: %#v", config)
|
t.Fatalf("unexpected TLS config: %#v", config)
|
||||||
}
|
}
|
||||||
|
if config.truststorePath != filepath.Clean("/certs/client.truststore") || config.truststorePassword != "trust-secret" {
|
||||||
|
t.Fatalf("unexpected truststore config: %#v", config)
|
||||||
|
}
|
||||||
|
if config.keystorePath != filepath.Clean("/certs/client.keystore") || config.keystorePassword != "key-secret" {
|
||||||
|
t.Fatalf("unexpected keystore config: %#v", config)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCassandraConfigFileSupportsKerberosLoginOptionCasing(t *testing.T) {
|
func TestCassandraConfigFileSupportsKerberosLoginOptionCasing(t *testing.T) {
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ require (
|
|||||||
github.com/gurkankaymak/hocon v1.3.0
|
github.com/gurkankaymak/hocon v1.3.0
|
||||||
github.com/jcmturner/gofork v1.7.6
|
github.com/jcmturner/gofork v1.7.6
|
||||||
github.com/jcmturner/gokrb5/v8 v8.4.4
|
github.com/jcmturner/gokrb5/v8 v8.4.4
|
||||||
|
github.com/pavlo-v-chernykh/keystore-go/v4 v4.5.0
|
||||||
|
software.sslmate.com/src/go-pkcs12 v0.7.3
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
@@ -23,7 +25,7 @@ require (
|
|||||||
github.com/jcmturner/rpc/v2 v2.0.3 // indirect
|
github.com/jcmturner/rpc/v2 v2.0.3 // indirect
|
||||||
go.uber.org/multierr v1.10.0 // indirect
|
go.uber.org/multierr v1.10.0 // indirect
|
||||||
go.uber.org/zap v1.27.0 // indirect
|
go.uber.org/zap v1.27.0 // indirect
|
||||||
golang.org/x/crypto v0.6.0 // indirect
|
golang.org/x/crypto v0.11.0 // indirect
|
||||||
golang.org/x/net v0.7.0 // indirect
|
golang.org/x/net v0.10.0 // indirect
|
||||||
gopkg.in/inf.v0 v0.9.1 // indirect
|
gopkg.in/inf.v0 v0.9.1 // indirect
|
||||||
)
|
)
|
||||||
@@ -45,6 +45,8 @@ github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxec
|
|||||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||||
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
|
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
|
||||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||||
|
github.com/pavlo-v-chernykh/keystore-go/v4 v4.5.0 h1:2nosf3P75OZv2/ZO/9Px5ZgZ5gbKrzA3joN1QMfOGMQ=
|
||||||
|
github.com/pavlo-v-chernykh/keystore-go/v4 v4.5.0/go.mod h1:lAVhWwbNaveeJmxrxuSTxMgKpF6DjnuVpn6T8WiBwYQ=
|
||||||
github.com/pierrec/lz4/v4 v4.1.8 h1:ieHkV+i2BRzngO4Wd/3HGowuZStgq6QkPsD1eolNAO4=
|
github.com/pierrec/lz4/v4 v4.1.8 h1:ieHkV+i2BRzngO4Wd/3HGowuZStgq6QkPsD1eolNAO4=
|
||||||
github.com/pierrec/lz4/v4 v4.1.8/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
|
github.com/pierrec/lz4/v4 v4.1.8/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
@@ -74,16 +76,18 @@ go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
|
|||||||
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
|
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||||
golang.org/x/crypto v0.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc=
|
|
||||||
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
|
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
|
||||||
|
golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA=
|
||||||
|
golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio=
|
||||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||||
golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g=
|
|
||||||
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||||
|
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
|
||||||
|
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
@@ -112,3 +116,5 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
software.sslmate.com/src/go-pkcs12 v0.7.3 h1:JBQD3FDqYjTeyDAeZQklj2ar88ykBLtALloPJHyAauU=
|
||||||
|
software.sslmate.com/src/go-pkcs12 v0.7.3/go.mod h1:Qiz0EyvDRJjjxGyUQa2cCNZn/wMyzrRJ/qcDXOQazLI=
|
||||||
@@ -35,18 +35,22 @@ type response struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type connectParams struct {
|
type connectParams struct {
|
||||||
Host string `json:"host"`
|
Host string `json:"host"`
|
||||||
Port int `json:"port"`
|
Port int `json:"port"`
|
||||||
Database string `json:"database"`
|
Database string `json:"database"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
URLParams string `json:"url_params"`
|
URLParams string `json:"url_params"`
|
||||||
ConnectionString string `json:"connection_string"`
|
ConnectionString string `json:"connection_string"`
|
||||||
SSL bool `json:"ssl"`
|
SSL bool `json:"ssl"`
|
||||||
CACertPath string `json:"ca_cert_path"`
|
CACertPath string `json:"ca_cert_path"`
|
||||||
ClientCertPath string `json:"client_cert_path"`
|
ClientCertPath string `json:"client_cert_path"`
|
||||||
ClientKeyPath string `json:"client_key_path"`
|
ClientKeyPath string `json:"client_key_path"`
|
||||||
SessionRole string `json:"sessionRole"`
|
TruststorePath string `json:"truststore_path"`
|
||||||
|
TruststorePassword string `json:"truststore_password"`
|
||||||
|
KeystorePath string `json:"keystore_path"`
|
||||||
|
KeystorePassword string `json:"keystore_password"`
|
||||||
|
SessionRole string `json:"sessionRole"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type queryOptions struct {
|
type queryOptions struct {
|
||||||
|
|||||||
@@ -0,0 +1,181 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"crypto/tls"
|
||||||
|
"crypto/x509"
|
||||||
|
"encoding/binary"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
keystore "github.com/pavlo-v-chernykh/keystore-go/v4"
|
||||||
|
pkcs12 "software.sslmate.com/src/go-pkcs12"
|
||||||
|
)
|
||||||
|
|
||||||
|
const jksMagic = 0xfeedfeed
|
||||||
|
|
||||||
|
func buildCassandraTLSConfig(config cassandraConfig) (*tls.Config, error) {
|
||||||
|
tlsConfig := &tls.Config{InsecureSkipVerify: !config.hostVerification}
|
||||||
|
if config.truststorePath != "" {
|
||||||
|
certificates, err := loadTruststore(config.truststorePath, config.truststorePassword)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("load Cassandra truststore %q: %w", config.truststorePath, err)
|
||||||
|
}
|
||||||
|
roots := x509.NewCertPool()
|
||||||
|
for _, certificate := range certificates {
|
||||||
|
roots.AddCert(certificate)
|
||||||
|
}
|
||||||
|
tlsConfig.RootCAs = roots
|
||||||
|
}
|
||||||
|
if config.keystorePath != "" {
|
||||||
|
certificate, err := loadKeystore(config.keystorePath, config.keystorePassword)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("load Cassandra keystore %q: %w", config.keystorePath, err)
|
||||||
|
}
|
||||||
|
tlsConfig.Certificates = []tls.Certificate{certificate}
|
||||||
|
}
|
||||||
|
return tlsConfig, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadTruststore(path string, password string) ([]*x509.Certificate, error) {
|
||||||
|
data, err := os.ReadFile(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if isJKS(data) {
|
||||||
|
return loadJKSTruststore(data, password)
|
||||||
|
}
|
||||||
|
certificates, err := pkcs12.DecodeTrustStore(data, password)
|
||||||
|
if err == nil && len(certificates) > 0 {
|
||||||
|
return certificates, nil
|
||||||
|
}
|
||||||
|
_, certificate, chain, chainErr := pkcs12.DecodeChain(data, password)
|
||||||
|
if chainErr != nil {
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("decode PKCS#12 truststore: %w", err)
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("PKCS#12 truststore contains no trusted certificates")
|
||||||
|
}
|
||||||
|
return append([]*x509.Certificate{certificate}, chain...), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadKeystore(path string, password string) (tls.Certificate, error) {
|
||||||
|
data, err := os.ReadFile(path)
|
||||||
|
if err != nil {
|
||||||
|
return tls.Certificate{}, err
|
||||||
|
}
|
||||||
|
if isJKS(data) {
|
||||||
|
return loadJKSKeystore(data, password)
|
||||||
|
}
|
||||||
|
privateKey, certificate, caCertificates, err := pkcs12.DecodeChain(data, password)
|
||||||
|
if err != nil {
|
||||||
|
return tls.Certificate{}, fmt.Errorf("decode PKCS#12 keystore: %w", err)
|
||||||
|
}
|
||||||
|
chain := make([][]byte, 0, 1+len(caCertificates))
|
||||||
|
chain = append(chain, certificate.Raw)
|
||||||
|
for _, caCertificate := range caCertificates {
|
||||||
|
chain = append(chain, caCertificate.Raw)
|
||||||
|
}
|
||||||
|
return tls.Certificate{Certificate: chain, PrivateKey: privateKey, Leaf: certificate}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func isJKS(data []byte) bool {
|
||||||
|
return len(data) >= 4 && binary.BigEndian.Uint32(data[:4]) == jksMagic
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadJKS(data []byte, password string) (keystore.KeyStore, error) {
|
||||||
|
store := keystore.New()
|
||||||
|
passwordBytes := []byte(password)
|
||||||
|
defer clear(passwordBytes)
|
||||||
|
if err := store.Load(bytes.NewReader(data), passwordBytes); err != nil {
|
||||||
|
return keystore.KeyStore{}, fmt.Errorf("decode JKS: %w", err)
|
||||||
|
}
|
||||||
|
return store, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadJKSTruststore(data []byte, password string) ([]*x509.Certificate, error) {
|
||||||
|
store, err := loadJKS(data, password)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
certificates := make([]*x509.Certificate, 0)
|
||||||
|
for _, alias := range store.Aliases() {
|
||||||
|
switch {
|
||||||
|
case store.IsTrustedCertificateEntry(alias):
|
||||||
|
entry, err := store.GetTrustedCertificateEntry(alias)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("read trusted certificate %q: %w", alias, err)
|
||||||
|
}
|
||||||
|
certificate, err := x509.ParseCertificate(entry.Certificate.Content)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("parse trusted certificate %q: %w", alias, err)
|
||||||
|
}
|
||||||
|
certificates = append(certificates, certificate)
|
||||||
|
case store.IsPrivateKeyEntry(alias):
|
||||||
|
chain, err := store.GetPrivateKeyEntryCertificateChain(alias)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("read certificate chain %q: %w", alias, err)
|
||||||
|
}
|
||||||
|
for _, entry := range chain {
|
||||||
|
certificate, err := x509.ParseCertificate(entry.Content)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("parse certificate chain %q: %w", alias, err)
|
||||||
|
}
|
||||||
|
certificates = append(certificates, certificate)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(certificates) == 0 {
|
||||||
|
return nil, fmt.Errorf("JKS truststore contains no trusted certificates")
|
||||||
|
}
|
||||||
|
return certificates, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadJKSKeystore(data []byte, password string) (tls.Certificate, error) {
|
||||||
|
store, err := loadJKS(data, password)
|
||||||
|
if err != nil {
|
||||||
|
return tls.Certificate{}, err
|
||||||
|
}
|
||||||
|
passwordBytes := []byte(password)
|
||||||
|
defer clear(passwordBytes)
|
||||||
|
for _, alias := range store.Aliases() {
|
||||||
|
if !store.IsPrivateKeyEntry(alias) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
entry, err := store.GetPrivateKeyEntry(alias, passwordBytes)
|
||||||
|
if err != nil {
|
||||||
|
return tls.Certificate{}, fmt.Errorf("read private key %q: %w", alias, err)
|
||||||
|
}
|
||||||
|
privateKey, err := parsePrivateKey(entry.PrivateKey)
|
||||||
|
if err != nil {
|
||||||
|
return tls.Certificate{}, fmt.Errorf("parse private key %q: %w", alias, err)
|
||||||
|
}
|
||||||
|
chain := make([][]byte, 0, len(entry.CertificateChain))
|
||||||
|
for _, certificate := range entry.CertificateChain {
|
||||||
|
chain = append(chain, certificate.Content)
|
||||||
|
}
|
||||||
|
if len(chain) == 0 {
|
||||||
|
return tls.Certificate{}, fmt.Errorf("private key %q has no certificate chain", alias)
|
||||||
|
}
|
||||||
|
leaf, err := x509.ParseCertificate(chain[0])
|
||||||
|
if err != nil {
|
||||||
|
return tls.Certificate{}, fmt.Errorf("parse client certificate %q: %w", alias, err)
|
||||||
|
}
|
||||||
|
return tls.Certificate{Certificate: chain, PrivateKey: privateKey, Leaf: leaf}, nil
|
||||||
|
}
|
||||||
|
return tls.Certificate{}, fmt.Errorf("JKS keystore contains no private key entries")
|
||||||
|
}
|
||||||
|
|
||||||
|
func parsePrivateKey(data []byte) (any, error) {
|
||||||
|
if value, err := x509.ParsePKCS8PrivateKey(data); err == nil {
|
||||||
|
return value, nil
|
||||||
|
}
|
||||||
|
if value, err := x509.ParsePKCS1PrivateKey(data); err == nil {
|
||||||
|
return value, nil
|
||||||
|
}
|
||||||
|
if value, err := x509.ParseECPrivateKey(data); err == nil {
|
||||||
|
return value, nil
|
||||||
|
}
|
||||||
|
return nil, errors.New("unsupported private key encoding")
|
||||||
|
}
|
||||||
@@ -0,0 +1,152 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"crypto/ecdsa"
|
||||||
|
"crypto/elliptic"
|
||||||
|
"crypto/rand"
|
||||||
|
"crypto/x509"
|
||||||
|
"crypto/x509/pkix"
|
||||||
|
"math/big"
|
||||||
|
"net/url"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
keystore "github.com/pavlo-v-chernykh/keystore-go/v4"
|
||||||
|
pkcs12 "software.sslmate.com/src/go-pkcs12"
|
||||||
|
)
|
||||||
|
|
||||||
|
const tlsStoreTestPassword = "changeit"
|
||||||
|
|
||||||
|
func TestLoadJKSStores(t *testing.T) {
|
||||||
|
_, certificate, privateKeyDER := testTLSIdentity(t)
|
||||||
|
store := keystore.New()
|
||||||
|
if err := store.SetTrustedCertificateEntry("ca", keystore.TrustedCertificateEntry{
|
||||||
|
CreationTime: time.Now(),
|
||||||
|
Certificate: keystore.Certificate{Type: "X509", Content: certificate.Raw},
|
||||||
|
}); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := store.SetPrivateKeyEntry("client", keystore.PrivateKeyEntry{
|
||||||
|
CreationTime: time.Now(),
|
||||||
|
PrivateKey: privateKeyDER,
|
||||||
|
CertificateChain: []keystore.Certificate{
|
||||||
|
{Type: "X509", Content: certificate.Raw},
|
||||||
|
},
|
||||||
|
}, []byte(tlsStoreTestPassword)); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
var encoded bytes.Buffer
|
||||||
|
if err := store.Store(&encoded, []byte(tlsStoreTestPassword)); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
path := filepath.Join(t.TempDir(), "client.jks")
|
||||||
|
if err := os.WriteFile(path, encoded.Bytes(), 0o600); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
trusted, err := loadTruststore(path, tlsStoreTestPassword)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
identity, err := loadKeystore(path, tlsStoreTestPassword)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if len(trusted) != 2 || identity.Leaf == nil {
|
||||||
|
t.Fatalf("unexpected JKS contents: trusted=%d identity=%#v", len(trusted), identity)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLoadPKCS12Stores(t *testing.T) {
|
||||||
|
privateKey, certificate, _ := testTLSIdentity(t)
|
||||||
|
truststore, err := pkcs12.Modern.EncodeTrustStore([]*x509.Certificate{certificate}, tlsStoreTestPassword)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
keystoreData, err := pkcs12.Modern.Encode(privateKey, certificate, nil, tlsStoreTestPassword)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
directory := t.TempDir()
|
||||||
|
truststorePath := filepath.Join(directory, "client-trust.p12")
|
||||||
|
keystorePath := filepath.Join(directory, "client-key.p12")
|
||||||
|
if err := os.WriteFile(truststorePath, truststore, 0o600); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := os.WriteFile(keystorePath, keystoreData, 0o600); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
tlsConfig, err := buildCassandraTLSConfig(cassandraConfig{
|
||||||
|
truststorePath: truststorePath,
|
||||||
|
truststorePassword: tlsStoreTestPassword,
|
||||||
|
keystorePath: keystorePath,
|
||||||
|
keystorePassword: tlsStoreTestPassword,
|
||||||
|
hostVerification: true,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if tlsConfig.RootCAs == nil || len(tlsConfig.Certificates) != 1 || tlsConfig.InsecureSkipVerify {
|
||||||
|
t.Fatalf("unexpected PKCS#12 TLS config: %#v", tlsConfig)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParseCassandraConfigRejectsStorePasswordWithoutPath(t *testing.T) {
|
||||||
|
_, err := parseCassandraConfig(connectParams{Host: "localhost", TruststorePassword: "secret"})
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("expected truststore path validation error")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSecureConnectBundleIgnoresManualTLSStoreSettings(t *testing.T) {
|
||||||
|
config, err := parseCassandraConfig(connectParams{
|
||||||
|
Username: "token",
|
||||||
|
Password: "secret",
|
||||||
|
CACertPath: "ca.pem",
|
||||||
|
URLParams: url.Values{
|
||||||
|
"secureconnectbundle": []string{"bundle.zip"},
|
||||||
|
"truststorepath": []string{"https://ignored.example/truststore"},
|
||||||
|
"truststorepassword": []string{"ignored"},
|
||||||
|
}.Encode(),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if config.secureConnectBundle != "bundle.zip" {
|
||||||
|
t.Fatalf("unexpected secure connect bundle: %q", config.secureConnectBundle)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func testTLSIdentity(t *testing.T) (*ecdsa.PrivateKey, *x509.Certificate, []byte) {
|
||||||
|
t.Helper()
|
||||||
|
privateKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
template := &x509.Certificate{
|
||||||
|
SerialNumber: big.NewInt(1),
|
||||||
|
Subject: pkix.Name{CommonName: "cassandra-client"},
|
||||||
|
NotBefore: time.Now().Add(-time.Hour),
|
||||||
|
NotAfter: time.Now().Add(time.Hour),
|
||||||
|
KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageCertSign,
|
||||||
|
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth, x509.ExtKeyUsageServerAuth},
|
||||||
|
IsCA: true,
|
||||||
|
}
|
||||||
|
certificateDER, err := x509.CreateCertificate(rand.Reader, template, template, &privateKey.PublicKey, privateKey)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
certificate, err := x509.ParseCertificate(certificateDER)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
privateKeyDER, err := x509.MarshalPKCS8PrivateKey(privateKey)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
return privateKey, certificate, privateKeyDER
|
||||||
|
}
|
||||||
@@ -62,6 +62,7 @@ import { SQLITE_DATABASE_FILE_EXTENSIONS } from "@/lib/database/databaseFileDete
|
|||||||
import { connectionAttemptOriginalErrorMessage, connectionAttemptTimeoutMessage, connectionAttemptTimeoutMs } from "@/lib/connection/connectionAttemptTimeout";
|
import { connectionAttemptOriginalErrorMessage, connectionAttemptTimeoutMessage, connectionAttemptTimeoutMs } from "@/lib/connection/connectionAttemptTimeout";
|
||||||
import { consulAgentAddressesMatch } from "@/lib/consul/agentTarget";
|
import { consulAgentAddressesMatch } from "@/lib/consul/agentTarget";
|
||||||
import { appendConnectionErrorHints, isJdbcMissingRuntimeDependencyError } from "@/lib/connection/connectionErrorHints";
|
import { appendConnectionErrorHints, isJdbcMissingRuntimeDependencyError } from "@/lib/connection/connectionErrorHints";
|
||||||
|
import { buildCassandraExternalConfig, cassandraTlsConfigFromExternalConfig, type CassandraTlsConfig } from "@/lib/connection/cassandraTlsOptions";
|
||||||
import { preventDialogDocumentSelectAll } from "@/lib/connection/dialogTextSelection";
|
import { preventDialogDocumentSelectAll } from "@/lib/connection/dialogTextSelection";
|
||||||
import { postgresLegacyTlsEnabled, postgresTlsModeForForm, setPostgresLegacyTlsEnabled } from "@/lib/connection/postgresTlsMode";
|
import { postgresLegacyTlsEnabled, postgresTlsModeForForm, setPostgresLegacyTlsEnabled } from "@/lib/connection/postgresTlsMode";
|
||||||
import { buildMqKafkaConnectionExtra, mqKafkaConnectionTarget, resolveMqKafkaConnectionSource, type MqKafkaConnectionSource } from "@/lib/connection/mqKafkaConnection";
|
import { buildMqKafkaConnectionExtra, mqKafkaConnectionTarget, resolveMqKafkaConnectionSource, type MqKafkaConnectionSource } from "@/lib/connection/mqKafkaConnection";
|
||||||
@@ -396,6 +397,12 @@ const defaultForm = (): ConnectionForm => ({
|
|||||||
save_password: true,
|
save_password: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const cassandraTls = reactive<CassandraTlsConfig>(cassandraTlsConfigFromExternalConfig(undefined));
|
||||||
|
|
||||||
|
function resetCassandraTlsFields(externalConfig: unknown) {
|
||||||
|
Object.assign(cassandraTls, cassandraTlsConfigFromExternalConfig(externalConfig));
|
||||||
|
}
|
||||||
|
|
||||||
const elasticsearchConnectionMode = ref<ElasticsearchConnectionMode>("direct");
|
const elasticsearchConnectionMode = ref<ElasticsearchConnectionMode>("direct");
|
||||||
const elasticsearchKibanaBasePath = ref("");
|
const elasticsearchKibanaBasePath = ref("");
|
||||||
const elasticsearchConnectivityCheckPath = ref("");
|
const elasticsearchConnectivityCheckPath = ref("");
|
||||||
@@ -2333,6 +2340,9 @@ function applyProfile(val: string, preserveConnectionFields = false) {
|
|||||||
if (profile.type !== "elasticsearch" || previousDatabaseType !== "elasticsearch") {
|
if (profile.type !== "elasticsearch" || previousDatabaseType !== "elasticsearch") {
|
||||||
resetElasticsearchProxyFields();
|
resetElasticsearchProxyFields();
|
||||||
}
|
}
|
||||||
|
if (profile.type !== "cassandra" || previousDatabaseType !== "cassandra") {
|
||||||
|
resetCassandraTlsFields(undefined);
|
||||||
|
}
|
||||||
if (!preserveConnectionFields) {
|
if (!preserveConnectionFields) {
|
||||||
oracleTnsAdminPath.value = "";
|
oracleTnsAdminPath.value = "";
|
||||||
form.value.port = profile.port;
|
form.value.port = profile.port;
|
||||||
@@ -2572,6 +2582,7 @@ watch(
|
|||||||
} else {
|
} else {
|
||||||
resetMqFields();
|
resetMqFields();
|
||||||
}
|
}
|
||||||
|
resetCassandraTlsFields(config.db_type === "cassandra" ? config.external_config : undefined);
|
||||||
if (config.db_type === "nacos") {
|
if (config.db_type === "nacos") {
|
||||||
hydrateNacosFields(config.external_config);
|
hydrateNacosFields(config.external_config);
|
||||||
} else {
|
} else {
|
||||||
@@ -2643,6 +2654,7 @@ watch(
|
|||||||
selectedType.value = "mysql";
|
selectedType.value = "mysql";
|
||||||
customDriverName.value = "";
|
customDriverName.value = "";
|
||||||
resetMqFields();
|
resetMqFields();
|
||||||
|
resetCassandraTlsFields(undefined);
|
||||||
resetNacosFields();
|
resetNacosFields();
|
||||||
resetInfluxDbFields();
|
resetInfluxDbFields();
|
||||||
resetElasticsearchProxyFields();
|
resetElasticsearchProxyFields();
|
||||||
@@ -3012,6 +3024,7 @@ const tlsCapableDatabaseTypes = new Set<DatabaseType>([
|
|||||||
"chromadb",
|
"chromadb",
|
||||||
"influxdb",
|
"influxdb",
|
||||||
"victoriametrics",
|
"victoriametrics",
|
||||||
|
"cassandra",
|
||||||
]);
|
]);
|
||||||
const supportsTlsToggle = computed(() => tlsCapableDatabaseTypes.has(form.value.db_type));
|
const supportsTlsToggle = computed(() => tlsCapableDatabaseTypes.has(form.value.db_type));
|
||||||
const supportsCaCertificatePath = computed(() => form.value.db_type === "clickhouse" || form.value.db_type === "victoriametrics");
|
const supportsCaCertificatePath = computed(() => form.value.db_type === "clickhouse" || form.value.db_type === "victoriametrics");
|
||||||
@@ -3922,6 +3935,20 @@ function connectionConfigForSubmit(id: string, generatedName = ""): ConnectionCo
|
|||||||
config.database = undefined;
|
config.database = undefined;
|
||||||
config.connection_string = undefined;
|
config.connection_string = undefined;
|
||||||
config.url_params = "";
|
config.url_params = "";
|
||||||
|
} else if (config.db_type === "cassandra") {
|
||||||
|
// Go 侧在配置了 truststore/keystore 时会自动启用 TLS,前端保持一致:有 store 配置就不丢弃 external_config。
|
||||||
|
const cassandraHasTlsStore = Boolean(cassandraTls.truststore_path.trim() || cassandraTls.truststore_password) || Boolean(cassandraTls.keystore_path.trim() || cassandraTls.keystore_password);
|
||||||
|
if (!config.ssl && !cassandraHasTlsStore) {
|
||||||
|
config.external_config = undefined;
|
||||||
|
} else {
|
||||||
|
if (cassandraTls.truststore_password && !cassandraTls.truststore_path.trim()) {
|
||||||
|
throw new Error(t("connection.cassandraTruststorePasswordRequiresPath"));
|
||||||
|
}
|
||||||
|
if (cassandraTls.keystore_password && !cassandraTls.keystore_path.trim()) {
|
||||||
|
throw new Error(t("connection.cassandraKeystorePasswordRequiresPath"));
|
||||||
|
}
|
||||||
|
config.external_config = buildCassandraExternalConfig(cassandraTls);
|
||||||
|
}
|
||||||
} else if (config.db_type === "nacos") {
|
} else if (config.db_type === "nacos") {
|
||||||
const nacosConfig = buildNacosAdminConfig();
|
const nacosConfig = buildNacosAdminConfig();
|
||||||
config.external_config = nacosConfig;
|
config.external_config = nacosConfig;
|
||||||
@@ -5476,6 +5503,23 @@ async function browseCaCertPath() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function browseCassandraStore(target: "truststore" | "keystore") {
|
||||||
|
if (!isTauriRuntime()) return;
|
||||||
|
const { open } = await import("@tauri-apps/plugin-dialog");
|
||||||
|
const selected = await open({
|
||||||
|
title: target === "truststore" ? t("connection.cassandraTruststoreBrowse") : t("connection.cassandraKeystoreBrowse"),
|
||||||
|
multiple: false,
|
||||||
|
filters: [
|
||||||
|
{ name: "Java KeyStore / PKCS#12", extensions: ["jks", "p12", "pfx", "truststore", "keystore"] },
|
||||||
|
{ name: "All Files", extensions: ["*"] },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
if (typeof selected === "string") {
|
||||||
|
if (target === "truststore") cassandraTls.truststore_path = selected;
|
||||||
|
else cassandraTls.keystore_path = selected;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function browseDamengSslFilesPath() {
|
async function browseDamengSslFilesPath() {
|
||||||
if (isTauriRuntime()) {
|
if (isTauriRuntime()) {
|
||||||
const { open } = await import("@tauri-apps/plugin-dialog");
|
const { open } = await import("@tauri-apps/plugin-dialog");
|
||||||
@@ -7913,6 +7957,56 @@ function openExternalUrl(url: string) {
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<template v-if="form.db_type === 'cassandra'">
|
||||||
|
<div class="grid grid-cols-4 items-start gap-4">
|
||||||
|
<Label :class="connectionLabelSmallPaddedClass">
|
||||||
|
<span class="inline-flex items-center justify-end gap-1">
|
||||||
|
<ShieldCheck class="h-3.5 w-3.5" />
|
||||||
|
{{ t("connection.cassandraTruststore") }}
|
||||||
|
</span>
|
||||||
|
</Label>
|
||||||
|
<div class="col-span-3 grid gap-2">
|
||||||
|
<div class="flex items-center gap-1">
|
||||||
|
<Input v-model="cassandraTls.truststore_path" class="flex-1" :placeholder="t('connection.cassandraTruststorePlaceholder')" :disabled="!tlsEnabled" />
|
||||||
|
<Tooltip v-if="isDesktop">
|
||||||
|
<TooltipTrigger as-child>
|
||||||
|
<Button variant="outline" size="icon" class="h-9 w-9 shrink-0" :disabled="!tlsEnabled" @click="browseCassandraStore('truststore')">
|
||||||
|
<FolderOpen class="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent>{{ t("connection.cassandraTruststoreBrowse") }}</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
</div>
|
||||||
|
<PasswordInput v-model="cassandraTls.truststore_password" :placeholder="t('connection.cassandraTruststorePassword')" :disabled="!tlsEnabled" />
|
||||||
|
<p class="text-[11px] leading-4 text-muted-foreground">{{ t("connection.cassandraTruststoreHint") }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="grid grid-cols-4 items-start gap-4">
|
||||||
|
<Label :class="connectionLabelSmallPaddedClass">
|
||||||
|
<span class="inline-flex items-center justify-end gap-1">
|
||||||
|
<KeyRound class="h-3.5 w-3.5" />
|
||||||
|
{{ t("connection.cassandraKeystore") }}
|
||||||
|
</span>
|
||||||
|
</Label>
|
||||||
|
<div class="col-span-3 grid gap-2">
|
||||||
|
<div class="flex items-center gap-1">
|
||||||
|
<Input v-model="cassandraTls.keystore_path" class="flex-1" :placeholder="t('connection.cassandraKeystorePlaceholder')" :disabled="!tlsEnabled" />
|
||||||
|
<Tooltip v-if="isDesktop">
|
||||||
|
<TooltipTrigger as-child>
|
||||||
|
<Button variant="outline" size="icon" class="h-9 w-9 shrink-0" :disabled="!tlsEnabled" @click="browseCassandraStore('keystore')">
|
||||||
|
<FolderOpen class="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent>{{ t("connection.cassandraKeystoreBrowse") }}</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
</div>
|
||||||
|
<PasswordInput v-model="cassandraTls.keystore_password" :placeholder="t('connection.cassandraKeystorePassword')" :disabled="!tlsEnabled" />
|
||||||
|
<p class="text-[11px] leading-4 text-muted-foreground">{{ t("connection.cassandraKeystoreHint") }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
<div v-if="form.db_type === 'redis'" class="grid grid-cols-4 items-start gap-4">
|
<div v-if="form.db_type === 'redis'" class="grid grid-cols-4 items-start gap-4">
|
||||||
<Label :class="connectionLabelSmallClass">{{ t("connection.redisTlsInsecure") }}</Label>
|
<Label :class="connectionLabelSmallClass">{{ t("connection.redisTlsInsecure") }}</Label>
|
||||||
<label class="col-span-3 flex items-start gap-2 cursor-pointer">
|
<label class="col-span-3 flex items-start gap-2 cursor-pointer">
|
||||||
|
|||||||
@@ -566,6 +566,18 @@ export default withEnglishFallback({
|
|||||||
caCertPath: "CA sertifikatı",
|
caCertPath: "CA sertifikatı",
|
||||||
caCertPathPlaceholder: "İstəyə bağlı, məsələn, ~/.yandex/RootCA.crt",
|
caCertPathPlaceholder: "İstəyə bağlı, məsələn, ~/.yandex/RootCA.crt",
|
||||||
caCertPathBrowse: "Sertifikat seç",
|
caCertPathBrowse: "Sertifikat seç",
|
||||||
|
cassandraTruststore: "Etibar anbarı",
|
||||||
|
cassandraTruststorePlaceholder: "/path/to/client.truststore",
|
||||||
|
cassandraTruststorePassword: "Etibar anbarı parolu",
|
||||||
|
cassandraTruststoreBrowse: "Cassandra etibar anbarını seçin",
|
||||||
|
cassandraTruststoreHint: "Cassandra server sertifikatlarını yoxlamaq üçün JKS və ya PKCS#12 etibar anbarı.",
|
||||||
|
cassandraTruststorePasswordRequiresPath: "Parolu daxil etməzdən əvvəl Cassandra etibar anbarını seçin.",
|
||||||
|
cassandraKeystore: "Müştəri açarlar anbarı",
|
||||||
|
cassandraKeystorePlaceholder: "/path/to/client.keystore",
|
||||||
|
cassandraKeystorePassword: "Açarlar anbarı parolu",
|
||||||
|
cassandraKeystoreBrowse: "Cassandra müştəri açarlar anbarını seçin",
|
||||||
|
cassandraKeystoreHint: "Müştəri sertifikatı ilə identifikasiya üçün istəyə bağlı JKS və ya PKCS#12 açarlar anbarı.",
|
||||||
|
cassandraKeystorePasswordRequiresPath: "Parolu daxil etməzdən əvvəl Cassandra müştəri açarlar anbarını seçin.",
|
||||||
damengSslFilesPath: "Sertifikat qovluğu",
|
damengSslFilesPath: "Sertifikat qovluğu",
|
||||||
damengSslFilesPathPlaceholder: "/path/to/dmcert",
|
damengSslFilesPathPlaceholder: "/path/to/dmcert",
|
||||||
damengSslFilesPathBrowse: "Sertifikat qovluğunu seçin",
|
damengSslFilesPathBrowse: "Sertifikat qovluğunu seçin",
|
||||||
|
|||||||
@@ -567,6 +567,18 @@ export default {
|
|||||||
caCertPath: "CA Certificate",
|
caCertPath: "CA Certificate",
|
||||||
caCertPathPlaceholder: "Optional, e.g. ~/.yandex/RootCA.crt",
|
caCertPathPlaceholder: "Optional, e.g. ~/.yandex/RootCA.crt",
|
||||||
caCertPathBrowse: "Browse certificate",
|
caCertPathBrowse: "Browse certificate",
|
||||||
|
cassandraTruststore: "Truststore",
|
||||||
|
cassandraTruststorePlaceholder: "/path/to/client.truststore",
|
||||||
|
cassandraTruststorePassword: "Truststore password",
|
||||||
|
cassandraTruststoreBrowse: "Choose Cassandra truststore",
|
||||||
|
cassandraTruststoreHint: "JKS or PKCS#12 truststore used to verify Cassandra server certificates.",
|
||||||
|
cassandraTruststorePasswordRequiresPath: "Select a Cassandra truststore before entering its password.",
|
||||||
|
cassandraKeystore: "Client Keystore",
|
||||||
|
cassandraKeystorePlaceholder: "/path/to/client.keystore",
|
||||||
|
cassandraKeystorePassword: "Keystore password",
|
||||||
|
cassandraKeystoreBrowse: "Choose Cassandra client keystore",
|
||||||
|
cassandraKeystoreHint: "Optional JKS or PKCS#12 keystore for client certificate authentication.",
|
||||||
|
cassandraKeystorePasswordRequiresPath: "Select a Cassandra client keystore before entering its password.",
|
||||||
damengSslFilesPath: "Certificate directory",
|
damengSslFilesPath: "Certificate directory",
|
||||||
damengSslFilesPathPlaceholder: "/path/to/dmcert",
|
damengSslFilesPathPlaceholder: "/path/to/dmcert",
|
||||||
damengSslFilesPathBrowse: "Select certificate directory",
|
damengSslFilesPathBrowse: "Select certificate directory",
|
||||||
|
|||||||
@@ -546,6 +546,18 @@ export default withEnglishFallback({
|
|||||||
caCertPath: "Certificado CA",
|
caCertPath: "Certificado CA",
|
||||||
caCertPathPlaceholder: "Opcional, p. ej. ~/.yandex/RootCA.crt",
|
caCertPathPlaceholder: "Opcional, p. ej. ~/.yandex/RootCA.crt",
|
||||||
caCertPathBrowse: "Buscar certificado",
|
caCertPathBrowse: "Buscar certificado",
|
||||||
|
cassandraTruststore: "Almacén de confianza",
|
||||||
|
cassandraTruststorePlaceholder: "/ruta/al/client.truststore",
|
||||||
|
cassandraTruststorePassword: "Contraseña del almacén de confianza",
|
||||||
|
cassandraTruststoreBrowse: "Elegir almacén de confianza de Cassandra",
|
||||||
|
cassandraTruststoreHint: "Almacén de confianza JKS o PKCS#12 usado para verificar los certificados del servidor Cassandra.",
|
||||||
|
cassandraTruststorePasswordRequiresPath: "Selecciona un almacén de confianza de Cassandra antes de introducir su contraseña.",
|
||||||
|
cassandraKeystore: "Almacén de claves del cliente",
|
||||||
|
cassandraKeystorePlaceholder: "/ruta/al/client.keystore",
|
||||||
|
cassandraKeystorePassword: "Contraseña del almacén de claves",
|
||||||
|
cassandraKeystoreBrowse: "Elegir almacén de claves de cliente de Cassandra",
|
||||||
|
cassandraKeystoreHint: "Almacén de claves JKS o PKCS#12 opcional para la autenticación con certificado de cliente.",
|
||||||
|
cassandraKeystorePasswordRequiresPath: "Selecciona un almacén de claves de cliente de Cassandra antes de introducir su contraseña.",
|
||||||
damengSslFilesPath: "Directorio de certificados",
|
damengSslFilesPath: "Directorio de certificados",
|
||||||
damengSslFilesPathPlaceholder: "/path/to/dmcert",
|
damengSslFilesPathPlaceholder: "/path/to/dmcert",
|
||||||
damengSslFilesPathBrowse: "Seleccionar directorio de certificados",
|
damengSslFilesPathBrowse: "Seleccionar directorio de certificados",
|
||||||
|
|||||||
@@ -545,6 +545,18 @@ export default withEnglishFallback({
|
|||||||
caCertPath: "Certificato CA",
|
caCertPath: "Certificato CA",
|
||||||
caCertPathPlaceholder: "Opzionale, es. ~/.yandex/RootCA.crt",
|
caCertPathPlaceholder: "Opzionale, es. ~/.yandex/RootCA.crt",
|
||||||
caCertPathBrowse: "Sfoglia certificato",
|
caCertPathBrowse: "Sfoglia certificato",
|
||||||
|
cassandraTruststore: "Truststore",
|
||||||
|
cassandraTruststorePlaceholder: "/percorso/di/client.truststore",
|
||||||
|
cassandraTruststorePassword: "Password del truststore",
|
||||||
|
cassandraTruststoreBrowse: "Scegli truststore Cassandra",
|
||||||
|
cassandraTruststoreHint: "Truststore JKS o PKCS#12 usato per verificare i certificati del server Cassandra.",
|
||||||
|
cassandraTruststorePasswordRequiresPath: "Seleziona un truststore Cassandra prima di inserirne la password.",
|
||||||
|
cassandraKeystore: "Keystore client",
|
||||||
|
cassandraKeystorePlaceholder: "/percorso/di/client.keystore",
|
||||||
|
cassandraKeystorePassword: "Password del keystore",
|
||||||
|
cassandraKeystoreBrowse: "Scegli keystore client Cassandra",
|
||||||
|
cassandraKeystoreHint: "Keystore JKS o PKCS#12 facoltativo per l'autenticazione con certificato client.",
|
||||||
|
cassandraKeystorePasswordRequiresPath: "Seleziona un keystore client Cassandra prima di inserirne la password.",
|
||||||
damengSslFilesPath: "Directory certificati",
|
damengSslFilesPath: "Directory certificati",
|
||||||
damengSslFilesPathPlaceholder: "/path/to/dmcert",
|
damengSslFilesPathPlaceholder: "/path/to/dmcert",
|
||||||
damengSslFilesPathBrowse: "Seleziona directory certificati",
|
damengSslFilesPathBrowse: "Seleziona directory certificati",
|
||||||
|
|||||||
@@ -545,6 +545,18 @@ export default withEnglishFallback({
|
|||||||
caCertPath: "CA証明書",
|
caCertPath: "CA証明書",
|
||||||
caCertPathPlaceholder: "任意、例: ~/.yandex/RootCA.crt",
|
caCertPathPlaceholder: "任意、例: ~/.yandex/RootCA.crt",
|
||||||
caCertPathBrowse: "証明書を参照",
|
caCertPathBrowse: "証明書を参照",
|
||||||
|
cassandraTruststore: "トラストストア",
|
||||||
|
cassandraTruststorePlaceholder: "/path/to/client.truststore",
|
||||||
|
cassandraTruststorePassword: "トラストストアのパスワード",
|
||||||
|
cassandraTruststoreBrowse: "Cassandra トラストストアを選択",
|
||||||
|
cassandraTruststoreHint: "Cassandra サーバー証明書の検証に使用する JKS または PKCS#12 トラストストア。",
|
||||||
|
cassandraTruststorePasswordRequiresPath: "パスワードを入力する前に Cassandra トラストストアを選択してください。",
|
||||||
|
cassandraKeystore: "クライアントキーストア",
|
||||||
|
cassandraKeystorePlaceholder: "/path/to/client.keystore",
|
||||||
|
cassandraKeystorePassword: "キーストアのパスワード",
|
||||||
|
cassandraKeystoreBrowse: "Cassandra クライアントキーストアを選択",
|
||||||
|
cassandraKeystoreHint: "クライアント証明書認証用のオプションの JKS / PKCS#12 キーストア。",
|
||||||
|
cassandraKeystorePasswordRequiresPath: "パスワードを入力する前に Cassandra クライアントキーストアを選択してください。",
|
||||||
damengSslFilesPath: "証明書ディレクトリ",
|
damengSslFilesPath: "証明書ディレクトリ",
|
||||||
damengSslFilesPathPlaceholder: "/path/to/dmcert",
|
damengSslFilesPathPlaceholder: "/path/to/dmcert",
|
||||||
damengSslFilesPathBrowse: "証明書ディレクトリを選択",
|
damengSslFilesPathBrowse: "証明書ディレクトリを選択",
|
||||||
|
|||||||
@@ -561,6 +561,18 @@ export default withEnglishFallback({
|
|||||||
caCertPath: "CA 인증서",
|
caCertPath: "CA 인증서",
|
||||||
caCertPathPlaceholder: "선택, 예: ~/.yandex/RootCA.crt",
|
caCertPathPlaceholder: "선택, 예: ~/.yandex/RootCA.crt",
|
||||||
caCertPathBrowse: "인증서 찾아보기",
|
caCertPathBrowse: "인증서 찾아보기",
|
||||||
|
cassandraTruststore: "트러스트스토어",
|
||||||
|
cassandraTruststorePlaceholder: "/path/to/client.truststore",
|
||||||
|
cassandraTruststorePassword: "트러스트스토어 비밀번호",
|
||||||
|
cassandraTruststoreBrowse: "Cassandra 트러스트스토어 선택",
|
||||||
|
cassandraTruststoreHint: "Cassandra 서버 인증서를 검증하는 JKS 또는 PKCS#12 트러스트스토어.",
|
||||||
|
cassandraTruststorePasswordRequiresPath: "비밀번호를 입력하기 전에 Cassandra 트러스트스토어를 먼저 선택하세요.",
|
||||||
|
cassandraKeystore: "클라이언트 키스토어",
|
||||||
|
cassandraKeystorePlaceholder: "/path/to/client.keystore",
|
||||||
|
cassandraKeystorePassword: "키스토어 비밀번호",
|
||||||
|
cassandraKeystoreBrowse: "Cassandra 클라이언트 키스토어 선택",
|
||||||
|
cassandraKeystoreHint: "클라이언트 인증서 인증용 선택적 JKS / PKCS#12 키스토어.",
|
||||||
|
cassandraKeystorePasswordRequiresPath: "비밀번호를 입력하기 전에 Cassandra 클라이언트 키스토어를 먼저 선택하세요.",
|
||||||
damengSslFilesPath: "인증서 디렉터리",
|
damengSslFilesPath: "인증서 디렉터리",
|
||||||
damengSslFilesPathPlaceholder: "/path/to/dmcert",
|
damengSslFilesPathPlaceholder: "/path/to/dmcert",
|
||||||
damengSslFilesPathBrowse: "인증서 디렉터리 선택",
|
damengSslFilesPathBrowse: "인증서 디렉터리 선택",
|
||||||
|
|||||||
@@ -546,6 +546,18 @@ export default withEnglishFallback({
|
|||||||
caCertPath: "Certificado CA",
|
caCertPath: "Certificado CA",
|
||||||
caCertPathPlaceholder: "Opcional, ex.: ~/.yandex/RootCA.crt",
|
caCertPathPlaceholder: "Opcional, ex.: ~/.yandex/RootCA.crt",
|
||||||
caCertPathBrowse: "Procurar certificado",
|
caCertPathBrowse: "Procurar certificado",
|
||||||
|
cassandraTruststore: "Truststore",
|
||||||
|
cassandraTruststorePlaceholder: "/caminho/do/client.truststore",
|
||||||
|
cassandraTruststorePassword: "Senha do truststore",
|
||||||
|
cassandraTruststoreBrowse: "Escolher truststore do Cassandra",
|
||||||
|
cassandraTruststoreHint: "Truststore JKS ou PKCS#12 usado para verificar os certificados do servidor Cassandra.",
|
||||||
|
cassandraTruststorePasswordRequiresPath: "Selecione um truststore do Cassandra antes de informar a senha.",
|
||||||
|
cassandraKeystore: "Keystore do cliente",
|
||||||
|
cassandraKeystorePlaceholder: "/caminho/do/client.keystore",
|
||||||
|
cassandraKeystorePassword: "Senha do keystore",
|
||||||
|
cassandraKeystoreBrowse: "Escolher keystore de cliente do Cassandra",
|
||||||
|
cassandraKeystoreHint: "Keystore JKS ou PKCS#12 opcional para autenticação por certificado de cliente.",
|
||||||
|
cassandraKeystorePasswordRequiresPath: "Selecione um keystore de cliente do Cassandra antes de informar a senha.",
|
||||||
damengSslFilesPath: "Diretório de certificados",
|
damengSslFilesPath: "Diretório de certificados",
|
||||||
damengSslFilesPathPlaceholder: "/path/to/dmcert",
|
damengSslFilesPathPlaceholder: "/path/to/dmcert",
|
||||||
damengSslFilesPathBrowse: "Selecionar diretório de certificados",
|
damengSslFilesPathBrowse: "Selecionar diretório de certificados",
|
||||||
|
|||||||
@@ -568,6 +568,18 @@ export default withEnglishFallback({
|
|||||||
caCertPath: "CA Sertifikası",
|
caCertPath: "CA Sertifikası",
|
||||||
caCertPathPlaceholder: "İsteğe bağlı, örn. ~/.yandex/RootCA.crt",
|
caCertPathPlaceholder: "İsteğe bağlı, örn. ~/.yandex/RootCA.crt",
|
||||||
caCertPathBrowse: "Sertifikaya gözat",
|
caCertPathBrowse: "Sertifikaya gözat",
|
||||||
|
cassandraTruststore: "Güven deposu",
|
||||||
|
cassandraTruststorePlaceholder: "/yol/client.truststore",
|
||||||
|
cassandraTruststorePassword: "Güven deposu parolası",
|
||||||
|
cassandraTruststoreBrowse: "Cassandra güven deposunu seç",
|
||||||
|
cassandraTruststoreHint: "Cassandra sunucu sertifikalarını doğrulamak için kullanılan JKS veya PKCS#12 güven deposu.",
|
||||||
|
cassandraTruststorePasswordRequiresPath: "Parolayı girmeden önce bir Cassandra güven deposu seçin.",
|
||||||
|
cassandraKeystore: "İstemci anahtar deposu",
|
||||||
|
cassandraKeystorePlaceholder: "/yol/client.keystore",
|
||||||
|
cassandraKeystorePassword: "Anahtar deposu parolası",
|
||||||
|
cassandraKeystoreBrowse: "Cassandra istemci anahtar deposunu seç",
|
||||||
|
cassandraKeystoreHint: "İstemci sertifikası kimlik doğrulaması için isteğe bağlı JKS veya PKCS#12 anahtar deposu.",
|
||||||
|
cassandraKeystorePasswordRequiresPath: "Parolayı girmeden önce bir Cassandra istemci anahtar deposu seçin.",
|
||||||
damengSslFilesPath: "Sertifika dizini",
|
damengSslFilesPath: "Sertifika dizini",
|
||||||
damengSslFilesPathPlaceholder: "/path/to/dmcert",
|
damengSslFilesPathPlaceholder: "/path/to/dmcert",
|
||||||
damengSslFilesPathBrowse: "Sertifika dizinini seçin",
|
damengSslFilesPathBrowse: "Sertifika dizinini seçin",
|
||||||
|
|||||||
@@ -492,6 +492,18 @@ export default withEnglishFallback({
|
|||||||
caCertPath: "CA 证书",
|
caCertPath: "CA 证书",
|
||||||
caCertPathPlaceholder: "可选,例如 ~/.yandex/RootCA.crt",
|
caCertPathPlaceholder: "可选,例如 ~/.yandex/RootCA.crt",
|
||||||
caCertPathBrowse: "选择证书",
|
caCertPathBrowse: "选择证书",
|
||||||
|
cassandraTruststore: "信任库",
|
||||||
|
cassandraTruststorePlaceholder: "/path/to/client.truststore",
|
||||||
|
cassandraTruststorePassword: "信任库密码",
|
||||||
|
cassandraTruststoreBrowse: "选择 Cassandra 信任库",
|
||||||
|
cassandraTruststoreHint: "用于验证 Cassandra 服务端证书的 JKS 或 PKCS#12 信任库。",
|
||||||
|
cassandraTruststorePasswordRequiresPath: "输入密码前请先选择 Cassandra 信任库。",
|
||||||
|
cassandraKeystore: "客户端密钥库",
|
||||||
|
cassandraKeystorePlaceholder: "/path/to/client.keystore",
|
||||||
|
cassandraKeystorePassword: "密钥库密码",
|
||||||
|
cassandraKeystoreBrowse: "选择 Cassandra 客户端密钥库",
|
||||||
|
cassandraKeystoreHint: "可选,用于客户端证书认证的 JKS 或 PKCS#12 密钥库。",
|
||||||
|
cassandraKeystorePasswordRequiresPath: "输入密码前请先选择 Cassandra 客户端密钥库。",
|
||||||
damengSslFilesPath: "证书目录",
|
damengSslFilesPath: "证书目录",
|
||||||
damengSslFilesPathPlaceholder: "/path/to/dmcert",
|
damengSslFilesPathPlaceholder: "/path/to/dmcert",
|
||||||
damengSslFilesPathBrowse: "选择证书目录",
|
damengSslFilesPathBrowse: "选择证书目录",
|
||||||
|
|||||||
@@ -546,6 +546,18 @@ export default withEnglishFallback({
|
|||||||
caCertPath: "CA 憑證",
|
caCertPath: "CA 憑證",
|
||||||
caCertPathPlaceholder: "可選,例如 ~/.yandex/RootCA.crt",
|
caCertPathPlaceholder: "可選,例如 ~/.yandex/RootCA.crt",
|
||||||
caCertPathBrowse: "瀏覽憑證",
|
caCertPathBrowse: "瀏覽憑證",
|
||||||
|
cassandraTruststore: "信任庫",
|
||||||
|
cassandraTruststorePlaceholder: "/path/to/client.truststore",
|
||||||
|
cassandraTruststorePassword: "信任庫密碼",
|
||||||
|
cassandraTruststoreBrowse: "選擇 Cassandra 信任庫",
|
||||||
|
cassandraTruststoreHint: "用於驗證 Cassandra 伺服器憑證的 JKS 或 PKCS#12 信任庫。",
|
||||||
|
cassandraTruststorePasswordRequiresPath: "輸入密碼前請先選擇 Cassandra 信任庫。",
|
||||||
|
cassandraKeystore: "用戶端金鑰庫",
|
||||||
|
cassandraKeystorePlaceholder: "/path/to/client.keystore",
|
||||||
|
cassandraKeystorePassword: "金鑰庫密碼",
|
||||||
|
cassandraKeystoreBrowse: "選擇 Cassandra 用戶端金鑰庫",
|
||||||
|
cassandraKeystoreHint: "可選,用於用戶端憑證驗證的 JKS 或 PKCS#12 金鑰庫。",
|
||||||
|
cassandraKeystorePasswordRequiresPath: "輸入密碼前請先選擇 Cassandra 用戶端金鑰庫。",
|
||||||
damengSslFilesPath: "憑證目錄",
|
damengSslFilesPath: "憑證目錄",
|
||||||
damengSslFilesPathPlaceholder: "/path/to/dmcert",
|
damengSslFilesPathPlaceholder: "/path/to/dmcert",
|
||||||
damengSslFilesPathBrowse: "選擇憑證目錄",
|
damengSslFilesPathBrowse: "選擇憑證目錄",
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { buildCassandraExternalConfig, cassandraTlsConfigFromExternalConfig } from "../cassandraTlsOptions";
|
||||||
|
|
||||||
|
describe("Cassandra TLS options", () => {
|
||||||
|
it("reads validated truststore and keystore fields", () => {
|
||||||
|
expect(
|
||||||
|
cassandraTlsConfigFromExternalConfig({
|
||||||
|
tls: {
|
||||||
|
truststore_path: "/certs/client.truststore",
|
||||||
|
truststore_password: "trust-secret",
|
||||||
|
keystore_path: "/certs/client.keystore",
|
||||||
|
keystore_password: "key-secret",
|
||||||
|
ignored: true,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
).toEqual({
|
||||||
|
truststore_path: "/certs/client.truststore",
|
||||||
|
truststore_password: "trust-secret",
|
||||||
|
keystore_path: "/certs/client.keystore",
|
||||||
|
keystore_password: "key-secret",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("ignores malformed external values", () => {
|
||||||
|
expect(cassandraTlsConfigFromExternalConfig({ tls: { truststore_path: 42 } })).toEqual({
|
||||||
|
truststore_path: "",
|
||||||
|
truststore_password: "",
|
||||||
|
keystore_path: "",
|
||||||
|
keystore_password: "",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("trims paths without changing passwords", () => {
|
||||||
|
expect(
|
||||||
|
buildCassandraExternalConfig({
|
||||||
|
truststore_path: " /certs/client.p12 ",
|
||||||
|
truststore_password: " trust-secret ",
|
||||||
|
keystore_path: " /certs/client.jks ",
|
||||||
|
keystore_password: " key-secret ",
|
||||||
|
}),
|
||||||
|
).toEqual({
|
||||||
|
tls: {
|
||||||
|
truststore_path: "/certs/client.p12",
|
||||||
|
truststore_password: " trust-secret ",
|
||||||
|
keystore_path: "/certs/client.jks",
|
||||||
|
keystore_password: " key-secret ",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("omits empty TLS store configuration", () => {
|
||||||
|
expect(
|
||||||
|
buildCassandraExternalConfig({
|
||||||
|
truststore_path: "",
|
||||||
|
truststore_password: "",
|
||||||
|
keystore_path: "",
|
||||||
|
keystore_password: "",
|
||||||
|
}),
|
||||||
|
).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
export interface CassandraTlsConfig {
|
||||||
|
truststore_path: string;
|
||||||
|
truststore_password: string;
|
||||||
|
keystore_path: string;
|
||||||
|
keystore_password: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CassandraExternalConfig {
|
||||||
|
tls: CassandraTlsConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
function stringField(value: unknown, key: keyof CassandraTlsConfig): string {
|
||||||
|
if (!value || typeof value !== "object") return "";
|
||||||
|
const field = (value as Record<string, unknown>)[key];
|
||||||
|
return typeof field === "string" ? field : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
export function cassandraTlsConfigFromExternalConfig(value: unknown): CassandraTlsConfig {
|
||||||
|
const tls = value && typeof value === "object" ? (value as Record<string, unknown>).tls : undefined;
|
||||||
|
return {
|
||||||
|
truststore_path: stringField(tls, "truststore_path"),
|
||||||
|
truststore_password: stringField(tls, "truststore_password"),
|
||||||
|
keystore_path: stringField(tls, "keystore_path"),
|
||||||
|
keystore_password: stringField(tls, "keystore_password"),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function buildCassandraExternalConfig(tls: CassandraTlsConfig): CassandraExternalConfig | undefined {
|
||||||
|
const truststorePath = tls.truststore_path.trim();
|
||||||
|
const keystorePath = tls.keystore_path.trim();
|
||||||
|
if (!truststorePath && !tls.truststore_password && !keystorePath && !tls.keystore_password) return undefined;
|
||||||
|
return {
|
||||||
|
tls: {
|
||||||
|
truststore_path: truststorePath,
|
||||||
|
truststore_password: tls.truststore_password,
|
||||||
|
keystore_path: keystorePath,
|
||||||
|
keystore_password: tls.keystore_password,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -47,6 +47,19 @@ fn h2_uses_custom_driver(config: &ConnectionConfig) -> bool {
|
|||||||
&& config.driver_profile.as_deref().is_some_and(|profile| profile.eq_ignore_ascii_case("h2-custom"))
|
&& config.driver_profile.as_deref().is_some_and(|profile| profile.eq_ignore_ascii_case("h2-custom"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn cassandra_tls_field<'a>(config: &'a ConnectionConfig, field: &str) -> &'a str {
|
||||||
|
if config.db_type != DatabaseType::Cassandra {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
config
|
||||||
|
.external_config
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|value| value.get("tls"))
|
||||||
|
.and_then(|value| value.get(field))
|
||||||
|
.and_then(serde_json::Value::as_str)
|
||||||
|
.unwrap_or("")
|
||||||
|
}
|
||||||
|
|
||||||
pub fn agent_connect_params(
|
pub fn agent_connect_params(
|
||||||
config: &ConnectionConfig,
|
config: &ConnectionConfig,
|
||||||
host: &str,
|
host: &str,
|
||||||
@@ -120,6 +133,10 @@ pub fn agent_connect_params_with_role(
|
|||||||
"ca_cert_path": config.ca_cert_path,
|
"ca_cert_path": config.ca_cert_path,
|
||||||
"client_cert_path": config.client_cert_path,
|
"client_cert_path": config.client_cert_path,
|
||||||
"client_key_path": config.client_key_path,
|
"client_key_path": config.client_key_path,
|
||||||
|
"truststore_path": cassandra_tls_field(config, "truststore_path"),
|
||||||
|
"truststore_password": cassandra_tls_field(config, "truststore_password"),
|
||||||
|
"keystore_path": cassandra_tls_field(config, "keystore_path"),
|
||||||
|
"keystore_password": cassandra_tls_field(config, "keystore_password"),
|
||||||
"connect_timeout_secs": config.effective_connect_timeout_secs(),
|
"connect_timeout_secs": config.effective_connect_timeout_secs(),
|
||||||
"etcd_endpoints": etcd_endpoints,
|
"etcd_endpoints": etcd_endpoints,
|
||||||
"zookeeper_connect_string": zookeeper_connect_string,
|
"zookeeper_connect_string": zookeeper_connect_string,
|
||||||
@@ -777,6 +794,27 @@ mod tests {
|
|||||||
assert_eq!(params["sessionRole"], "metadata");
|
assert_eq!(params["sessionRole"], "metadata");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn cassandra_agent_connect_params_include_tls_stores() {
|
||||||
|
let mut cfg = config(DatabaseType::Cassandra, Some("app"));
|
||||||
|
cfg.ssl = true;
|
||||||
|
cfg.external_config = Some(serde_json::json!({
|
||||||
|
"tls": {
|
||||||
|
"truststore_path": "/certs/client.truststore",
|
||||||
|
"truststore_password": "trust-secret",
|
||||||
|
"keystore_path": "/certs/client.keystore",
|
||||||
|
"keystore_password": "key-secret"
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
let params = agent_connect_params(&cfg, "cassandra.example.com", 9042, "app").unwrap();
|
||||||
|
|
||||||
|
assert_eq!(params["truststore_path"], "/certs/client.truststore");
|
||||||
|
assert_eq!(params["truststore_password"], "trust-secret");
|
||||||
|
assert_eq!(params["keystore_path"], "/certs/client.keystore");
|
||||||
|
assert_eq!(params["keystore_password"], "key-secret");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn oracle_form_connections_use_orcl_when_database_is_omitted() {
|
fn oracle_form_connections_use_orcl_when_database_is_omitted() {
|
||||||
for (mode, expected_url) in [
|
for (mode, expected_url) in [
|
||||||
|
|||||||
@@ -13,8 +13,9 @@ use std::net::{IpAddr, Ipv4Addr};
|
|||||||
|
|
||||||
use crate::ai::AiConfigItem;
|
use crate::ai::AiConfigItem;
|
||||||
use crate::connection_secrets::{
|
use crate::connection_secrets::{
|
||||||
MQ_AUTH_API_KEY_VALUE_KEY, MQ_AUTH_CLIENT_SECRET_KEY, MQ_AUTH_PASSWORD_KEY, MQ_AUTH_TOKEN_KEY,
|
CASSANDRA_KEYSTORE_PASSWORD_KEY, CASSANDRA_TRUSTSTORE_PASSWORD_KEY, MQ_AUTH_API_KEY_VALUE_KEY,
|
||||||
MQ_TOKEN_SIGNING_KEY, NACOS_AUTH_PASSWORD_KEY, NACOS_RNACOS_CONSOLE_PASSWORD_KEY,
|
MQ_AUTH_CLIENT_SECRET_KEY, MQ_AUTH_PASSWORD_KEY, MQ_AUTH_TOKEN_KEY, MQ_TOKEN_SIGNING_KEY,
|
||||||
|
NACOS_AUTH_PASSWORD_KEY, NACOS_RNACOS_CONSOLE_PASSWORD_KEY,
|
||||||
};
|
};
|
||||||
use crate::models::connection::{ConnectionConfig, DatabaseType, TransportLayerConfig};
|
use crate::models::connection::{ConnectionConfig, DatabaseType, TransportLayerConfig};
|
||||||
use crate::saved_sql::SavedSqlLibrary;
|
use crate::saved_sql::SavedSqlLibrary;
|
||||||
@@ -42,6 +43,8 @@ const SECRET_KEYS: &[&str] = &[
|
|||||||
MQ_TOKEN_SIGNING_KEY,
|
MQ_TOKEN_SIGNING_KEY,
|
||||||
NACOS_AUTH_PASSWORD_KEY,
|
NACOS_AUTH_PASSWORD_KEY,
|
||||||
NACOS_RNACOS_CONSOLE_PASSWORD_KEY,
|
NACOS_RNACOS_CONSOLE_PASSWORD_KEY,
|
||||||
|
CASSANDRA_TRUSTSTORE_PASSWORD_KEY,
|
||||||
|
CASSANDRA_KEYSTORE_PASSWORD_KEY,
|
||||||
];
|
];
|
||||||
const SSH_TUNNEL_SECRET_PREFIX: &str = "ssh_tunnels.";
|
const SSH_TUNNEL_SECRET_PREFIX: &str = "ssh_tunnels.";
|
||||||
const TRANSPORT_LAYER_SECRET_PREFIX: &str = "transport_layers.";
|
const TRANSPORT_LAYER_SECRET_PREFIX: &str = "transport_layers.";
|
||||||
@@ -969,6 +972,7 @@ fn scrub_connection_secrets(config: &mut ConnectionConfig) {
|
|||||||
scrub_mqtt_auth_secrets(config);
|
scrub_mqtt_auth_secrets(config);
|
||||||
scrub_mq_external_config_secrets(config);
|
scrub_mq_external_config_secrets(config);
|
||||||
scrub_nacos_auth_secrets(config);
|
scrub_nacos_auth_secrets(config);
|
||||||
|
scrub_cassandra_tls_secrets(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn scrub_mqtt_auth_secrets(config: &mut ConnectionConfig) {
|
fn scrub_mqtt_auth_secrets(config: &mut ConnectionConfig) {
|
||||||
@@ -1044,6 +1048,7 @@ async fn build_sensitive_payload(
|
|||||||
push_secret(&mut connection_secrets, &config.id, "connection_string", connection_string);
|
push_secret(&mut connection_secrets, &config.id, "connection_string", connection_string);
|
||||||
}
|
}
|
||||||
push_mq_external_config_secrets(&mut connection_secrets, config);
|
push_mq_external_config_secrets(&mut connection_secrets, config);
|
||||||
|
push_cassandra_tls_secrets(&mut connection_secrets, config);
|
||||||
if config.save_password {
|
if config.save_password {
|
||||||
push_nacos_external_config_secrets(&mut connection_secrets, config);
|
push_nacos_external_config_secrets(&mut connection_secrets, config);
|
||||||
}
|
}
|
||||||
@@ -1098,6 +1103,50 @@ fn scrub_mq_external_config_secrets(config: &mut ConnectionConfig) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn push_cassandra_tls_secrets(secrets: &mut Vec<ConnectionSecretSnapshot>, config: &ConnectionConfig) {
|
||||||
|
if config.db_type != DatabaseType::Cassandra {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let Some(tls) = config
|
||||||
|
.external_config
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|external_config| external_config.get("tls"))
|
||||||
|
.and_then(serde_json::Value::as_object)
|
||||||
|
else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
push_json_secret(
|
||||||
|
secrets,
|
||||||
|
&config.id,
|
||||||
|
CASSANDRA_TRUSTSTORE_PASSWORD_KEY,
|
||||||
|
tls,
|
||||||
|
"truststore_password",
|
||||||
|
);
|
||||||
|
push_json_secret(
|
||||||
|
secrets,
|
||||||
|
&config.id,
|
||||||
|
CASSANDRA_KEYSTORE_PASSWORD_KEY,
|
||||||
|
tls,
|
||||||
|
"keystore_password",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn scrub_cassandra_tls_secrets(config: &mut ConnectionConfig) {
|
||||||
|
if config.db_type != DatabaseType::Cassandra {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let Some(tls) = config
|
||||||
|
.external_config
|
||||||
|
.as_mut()
|
||||||
|
.and_then(|external_config| external_config.get_mut("tls"))
|
||||||
|
.and_then(serde_json::Value::as_object_mut)
|
||||||
|
else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
scrub_json_secret(tls, "truststore_password");
|
||||||
|
scrub_json_secret(tls, "keystore_password");
|
||||||
|
}
|
||||||
|
|
||||||
fn push_nacos_external_config_secrets(secrets: &mut Vec<ConnectionSecretSnapshot>, config: &ConnectionConfig) {
|
fn push_nacos_external_config_secrets(secrets: &mut Vec<ConnectionSecretSnapshot>, config: &ConnectionConfig) {
|
||||||
if config.db_type != DatabaseType::Nacos {
|
if config.db_type != DatabaseType::Nacos {
|
||||||
return;
|
return;
|
||||||
@@ -1615,7 +1664,10 @@ mod tests {
|
|||||||
SnippetProvider, SnippetSyncClient, SnippetSyncConfig, WebDavClient, WebDavConfig, DEFAULT_SNIPPET_FILE_NAME,
|
SnippetProvider, SnippetSyncClient, SnippetSyncConfig, WebDavClient, WebDavConfig, DEFAULT_SNIPPET_FILE_NAME,
|
||||||
};
|
};
|
||||||
use crate::ai::{AiApiStyle, AiAuthMethod, AiConfig, AiConfigItem};
|
use crate::ai::{AiApiStyle, AiAuthMethod, AiConfig, AiConfigItem};
|
||||||
use crate::connection_secrets::{NACOS_AUTH_PASSWORD_KEY, NACOS_RNACOS_CONSOLE_PASSWORD_KEY};
|
use crate::connection_secrets::{
|
||||||
|
CASSANDRA_KEYSTORE_PASSWORD_KEY, CASSANDRA_TRUSTSTORE_PASSWORD_KEY, NACOS_AUTH_PASSWORD_KEY,
|
||||||
|
NACOS_RNACOS_CONSOLE_PASSWORD_KEY,
|
||||||
|
};
|
||||||
use crate::models::connection::{
|
use crate::models::connection::{
|
||||||
default_redis_key_separator, ConnectionConfig, DatabaseType, SshTunnelConfig, TransportLayerConfig,
|
default_redis_key_separator, ConnectionConfig, DatabaseType, SshTunnelConfig, TransportLayerConfig,
|
||||||
};
|
};
|
||||||
@@ -1818,6 +1870,22 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn cassandra_connection(id: &str) -> ConnectionConfig {
|
||||||
|
let mut config = postgres_connection(id, "");
|
||||||
|
config.name = "Cassandra".to_string();
|
||||||
|
config.db_type = DatabaseType::Cassandra;
|
||||||
|
config.port = 9042;
|
||||||
|
config.external_config = Some(serde_json::json!({
|
||||||
|
"tls": {
|
||||||
|
"truststore_path": "/certs/client.truststore",
|
||||||
|
"truststore_password": "trust-secret",
|
||||||
|
"keystore_path": "/certs/client.keystore",
|
||||||
|
"keystore_password": "key-secret"
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
config
|
||||||
|
}
|
||||||
|
|
||||||
fn nacos_connection(id: &str, password: &str) -> ConnectionConfig {
|
fn nacos_connection(id: &str, password: &str) -> ConnectionConfig {
|
||||||
ConnectionConfig {
|
ConnectionConfig {
|
||||||
docs_notes_path: None,
|
docs_notes_path: None,
|
||||||
@@ -2161,6 +2229,33 @@ mod tests {
|
|||||||
assert!(super::SECRET_KEYS.contains(&"init_script"));
|
assert!(super::SECRET_KEYS.contains(&"init_script"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn cassandra_tls_store_passwords_move_to_sensitive_sync_payload() {
|
||||||
|
let config = cassandra_connection("cassandra");
|
||||||
|
let mut public_config = config.clone();
|
||||||
|
scrub_connection_secrets(&mut public_config);
|
||||||
|
let tls = public_config
|
||||||
|
.external_config
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|external_config| external_config.get("tls"))
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(tls["truststore_password"], "");
|
||||||
|
assert_eq!(tls["keystore_password"], "");
|
||||||
|
|
||||||
|
let storage = Storage::open(&temp_db_path("cassandra-sensitive-payload")).await.unwrap();
|
||||||
|
let payload = build_sensitive_payload(&storage, &[config], &[]).await.unwrap();
|
||||||
|
assert!(payload.connection_secrets.iter().any(|secret| {
|
||||||
|
secret.connection_id == "cassandra"
|
||||||
|
&& secret.key == CASSANDRA_TRUSTSTORE_PASSWORD_KEY
|
||||||
|
&& secret.secret == "trust-secret"
|
||||||
|
}));
|
||||||
|
assert!(payload.connection_secrets.iter().any(|secret| {
|
||||||
|
secret.connection_id == "cassandra"
|
||||||
|
&& secret.key == CASSANDRA_KEYSTORE_PASSWORD_KEY
|
||||||
|
&& secret.secret == "key-secret"
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn encrypted_sensitive_payload_round_trips() {
|
fn encrypted_sensitive_payload_round_trips() {
|
||||||
let payload = SensitiveSyncPayload {
|
let payload = SensitiveSyncPayload {
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ pub const NACOS_AUTH_PASSWORD_KEY: &str = "nacos.auth.password";
|
|||||||
pub const NACOS_RNACOS_CONSOLE_PASSWORD_KEY: &str = "nacos.auth.rnacos_console_password";
|
pub const NACOS_RNACOS_CONSOLE_PASSWORD_KEY: &str = "nacos.auth.rnacos_console_password";
|
||||||
pub const MQTT_AUTH_SECRET_PREFIX: &str = "mqtt.auth.";
|
pub const MQTT_AUTH_SECRET_PREFIX: &str = "mqtt.auth.";
|
||||||
pub const MQTT_AUTH_PASSWORD_KEY: &str = "mqtt.auth.password";
|
pub const MQTT_AUTH_PASSWORD_KEY: &str = "mqtt.auth.password";
|
||||||
|
pub const CASSANDRA_TLS_SECRET_PREFIX: &str = "cassandra.tls.";
|
||||||
|
pub const CASSANDRA_TRUSTSTORE_PASSWORD_KEY: &str = "cassandra.tls.truststore_password";
|
||||||
|
pub const CASSANDRA_KEYSTORE_PASSWORD_KEY: &str = "cassandra.tls.keystore_password";
|
||||||
|
|
||||||
pub trait ConnectionSecretStore {
|
pub trait ConnectionSecretStore {
|
||||||
fn set_secret(&self, connection_id: &str, key: &str, secret: &str) -> Result<(), String>;
|
fn set_secret(&self, connection_id: &str, key: &str, secret: &str) -> Result<(), String>;
|
||||||
@@ -112,6 +115,7 @@ pub fn save_connections_to_file(
|
|||||||
persist_mq_auth_secrets(store, config)?;
|
persist_mq_auth_secrets(store, config)?;
|
||||||
persist_mq_token_signing_secret(store, config)?;
|
persist_mq_token_signing_secret(store, config)?;
|
||||||
persist_mqtt_auth_secrets(store, config)?;
|
persist_mqtt_auth_secrets(store, config)?;
|
||||||
|
persist_cassandra_tls_secrets(store, config)?;
|
||||||
|
|
||||||
// New configs persist transport-layer secrets only. Remove legacy transport secret slots after the
|
// New configs persist transport-layer secrets only. Remove legacy transport secret slots after the
|
||||||
// migrated layer values have been written so old configs do not keep two sources of truth.
|
// migrated layer values have been written so old configs do not keep two sources of truth.
|
||||||
@@ -181,6 +185,7 @@ pub fn load_connections_from_file(
|
|||||||
hydrate_mq_auth_secrets(store, config, &mut needs_rewrite)?;
|
hydrate_mq_auth_secrets(store, config, &mut needs_rewrite)?;
|
||||||
hydrate_mq_token_signing_secret(store, config, &mut needs_rewrite)?;
|
hydrate_mq_token_signing_secret(store, config, &mut needs_rewrite)?;
|
||||||
hydrate_mqtt_auth_secrets(store, config, &mut needs_rewrite)?;
|
hydrate_mqtt_auth_secrets(store, config, &mut needs_rewrite)?;
|
||||||
|
hydrate_cassandra_tls_secrets(store, config, &mut needs_rewrite)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if needs_rewrite {
|
if needs_rewrite {
|
||||||
@@ -360,6 +365,7 @@ fn delete_removed_connection_secrets(
|
|||||||
delete_secret_prefix(store, &config.id, MQ_AUTH_SECRET_PREFIX)?;
|
delete_secret_prefix(store, &config.id, MQ_AUTH_SECRET_PREFIX)?;
|
||||||
delete_secret_prefix(store, &config.id, MQ_TOKEN_SIGNING_SECRET_PREFIX)?;
|
delete_secret_prefix(store, &config.id, MQ_TOKEN_SIGNING_SECRET_PREFIX)?;
|
||||||
delete_secret_prefix(store, &config.id, MQTT_AUTH_SECRET_PREFIX)?;
|
delete_secret_prefix(store, &config.id, MQTT_AUTH_SECRET_PREFIX)?;
|
||||||
|
delete_secret_prefix(store, &config.id, CASSANDRA_TLS_SECRET_PREFIX)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -554,6 +560,87 @@ fn scrub_mq_token_signing_secret(config: &mut ConnectionConfig) {
|
|||||||
scrub_json_secret(signing, "key");
|
scrub_json_secret(signing, "key");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn persist_cassandra_tls_secrets(
|
||||||
|
store: &dyn ConnectionSecretStore,
|
||||||
|
config: &ConnectionConfig,
|
||||||
|
) -> Result<(), String> {
|
||||||
|
if config.db_type != DatabaseType::Cassandra {
|
||||||
|
return delete_secret_prefix(store, &config.id, CASSANDRA_TLS_SECRET_PREFIX);
|
||||||
|
}
|
||||||
|
let Some(tls) = cassandra_tls_object(config.external_config.as_ref()) else {
|
||||||
|
return delete_secret_prefix(store, &config.id, CASSANDRA_TLS_SECRET_PREFIX);
|
||||||
|
};
|
||||||
|
persist_secret(
|
||||||
|
store,
|
||||||
|
&config.id,
|
||||||
|
CASSANDRA_TRUSTSTORE_PASSWORD_KEY,
|
||||||
|
tls.get("truststore_password")
|
||||||
|
.and_then(serde_json::Value::as_str)
|
||||||
|
.unwrap_or(""),
|
||||||
|
)?;
|
||||||
|
persist_secret(
|
||||||
|
store,
|
||||||
|
&config.id,
|
||||||
|
CASSANDRA_KEYSTORE_PASSWORD_KEY,
|
||||||
|
tls.get("keystore_password")
|
||||||
|
.and_then(serde_json::Value::as_str)
|
||||||
|
.unwrap_or(""),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn hydrate_cassandra_tls_secrets(
|
||||||
|
store: &dyn ConnectionSecretStore,
|
||||||
|
config: &mut ConnectionConfig,
|
||||||
|
needs_rewrite: &mut bool,
|
||||||
|
) -> Result<(), String> {
|
||||||
|
if config.db_type != DatabaseType::Cassandra {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
let connection_id = config.id.clone();
|
||||||
|
let Some(tls) = cassandra_tls_object_mut(config.external_config.as_mut()) else {
|
||||||
|
return Ok(());
|
||||||
|
};
|
||||||
|
hydrate_json_secret(
|
||||||
|
store,
|
||||||
|
&connection_id,
|
||||||
|
CASSANDRA_TRUSTSTORE_PASSWORD_KEY,
|
||||||
|
tls,
|
||||||
|
"truststore_password",
|
||||||
|
needs_rewrite,
|
||||||
|
)?;
|
||||||
|
hydrate_json_secret(
|
||||||
|
store,
|
||||||
|
&connection_id,
|
||||||
|
CASSANDRA_KEYSTORE_PASSWORD_KEY,
|
||||||
|
tls,
|
||||||
|
"keystore_password",
|
||||||
|
needs_rewrite,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn scrub_cassandra_tls_secrets(config: &mut ConnectionConfig) {
|
||||||
|
if config.db_type != DatabaseType::Cassandra {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let Some(tls) = cassandra_tls_object_mut(config.external_config.as_mut()) else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
scrub_json_secret(tls, "truststore_password");
|
||||||
|
scrub_json_secret(tls, "keystore_password");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn cassandra_tls_object(
|
||||||
|
value: Option<&serde_json::Value>,
|
||||||
|
) -> Option<&serde_json::Map<String, serde_json::Value>> {
|
||||||
|
value?.get("tls")?.as_object()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn cassandra_tls_object_mut(
|
||||||
|
value: Option<&mut serde_json::Value>,
|
||||||
|
) -> Option<&mut serde_json::Map<String, serde_json::Value>> {
|
||||||
|
value?.get_mut("tls")?.as_object_mut()
|
||||||
|
}
|
||||||
|
|
||||||
// ── MQTT 密钥持久化 ──────────────────────────────────────────────
|
// ── MQTT 密钥持久化 ──────────────────────────────────────────────
|
||||||
|
|
||||||
fn persist_mqtt_auth_secrets(store: &dyn ConnectionSecretStore, config: &ConnectionConfig) -> Result<(), String> {
|
fn persist_mqtt_auth_secrets(store: &dyn ConnectionSecretStore, config: &ConnectionConfig) -> Result<(), String> {
|
||||||
@@ -745,6 +832,7 @@ fn sanitize_connections(configs: &[ConnectionConfig]) -> Vec<ConnectionConfig> {
|
|||||||
scrub_mq_auth_secrets(&mut config);
|
scrub_mq_auth_secrets(&mut config);
|
||||||
scrub_mq_token_signing_secret(&mut config);
|
scrub_mq_token_signing_secret(&mut config);
|
||||||
scrub_mqtt_auth_secrets(&mut config);
|
scrub_mqtt_auth_secrets(&mut config);
|
||||||
|
scrub_cassandra_tls_secrets(&mut config);
|
||||||
config
|
config
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
@@ -757,9 +845,11 @@ pub fn secret_account(connection_id: &str, key: &str) -> String {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::{
|
use super::{
|
||||||
load_connections_from_file, save_connections_to_file, ConnectionSecretStore, CONNECTION_STRING_KEY,
|
load_connections_from_file, save_connections_to_file, ConnectionSecretStore,
|
||||||
INIT_SCRIPT_KEY, MAIN_PASSWORD_KEY, MQTT_AUTH_PASSWORD_KEY, MQ_AUTH_PASSWORD_KEY, MQ_AUTH_TOKEN_KEY,
|
CASSANDRA_KEYSTORE_PASSWORD_KEY, CASSANDRA_TRUSTSTORE_PASSWORD_KEY,
|
||||||
MQ_TOKEN_SIGNING_KEY, REDIS_SENTINEL_PASSWORD_KEY, SSH_PASSWORD_KEY,
|
CONNECTION_STRING_KEY, INIT_SCRIPT_KEY, MAIN_PASSWORD_KEY, MQTT_AUTH_PASSWORD_KEY,
|
||||||
|
MQ_AUTH_PASSWORD_KEY, MQ_AUTH_TOKEN_KEY, MQ_TOKEN_SIGNING_KEY, REDIS_SENTINEL_PASSWORD_KEY,
|
||||||
|
SSH_PASSWORD_KEY,
|
||||||
};
|
};
|
||||||
use crate::models::connection::{
|
use crate::models::connection::{
|
||||||
ConnectionConfig, DatabaseType, HttpTunnelConfig, SshTunnelConfig, TransportLayerConfig,
|
ConnectionConfig, DatabaseType, HttpTunnelConfig, SshTunnelConfig, TransportLayerConfig,
|
||||||
@@ -1127,6 +1217,57 @@ mod tests {
|
|||||||
assert_eq!(auth.get("token").and_then(serde_json::Value::as_str), Some("mq-token-secret"));
|
assert_eq!(auth.get("token").and_then(serde_json::Value::as_str), Some("mq-token-secret"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn save_connections_moves_cassandra_store_passwords_to_secret_store_and_restores_them() {
|
||||||
|
let path = temp_connections_file("cassandra-tls");
|
||||||
|
let store = MemorySecretStore::default();
|
||||||
|
let mut config = connection("cassandra", "", "");
|
||||||
|
config.db_type = DatabaseType::Cassandra;
|
||||||
|
config.external_config = Some(serde_json::json!({
|
||||||
|
"tls": {
|
||||||
|
"truststore_path": "/certs/client.truststore",
|
||||||
|
"truststore_password": "trust-secret",
|
||||||
|
"keystore_path": "/certs/client.keystore",
|
||||||
|
"keystore_password": "key-secret"
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
save_connections_to_file(&path, &[config], &store).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
store
|
||||||
|
.get_existing("cassandra", CASSANDRA_TRUSTSTORE_PASSWORD_KEY)
|
||||||
|
.as_deref(),
|
||||||
|
Some("trust-secret")
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
store
|
||||||
|
.get_existing("cassandra", CASSANDRA_KEYSTORE_PASSWORD_KEY)
|
||||||
|
.as_deref(),
|
||||||
|
Some("key-secret")
|
||||||
|
);
|
||||||
|
let persisted_json = std::fs::read_to_string(&path).unwrap();
|
||||||
|
assert!(!persisted_json.contains("trust-secret"));
|
||||||
|
assert!(!persisted_json.contains("key-secret"));
|
||||||
|
|
||||||
|
let loaded = load_connections_from_file(&path, &store).unwrap();
|
||||||
|
let tls = loaded[0]
|
||||||
|
.external_config
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|value| value.get("tls"))
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
tls.get("truststore_password")
|
||||||
|
.and_then(serde_json::Value::as_str),
|
||||||
|
Some("trust-secret")
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
tls.get("keystore_password")
|
||||||
|
.and_then(serde_json::Value::as_str),
|
||||||
|
Some("key-secret")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn save_connections_moves_mq_basic_and_oauth_secrets_to_secret_store_and_restores_them() {
|
fn save_connections_moves_mq_basic_and_oauth_secrets_to_secret_store_and_restores_them() {
|
||||||
let path = temp_connections_file("mq-auth-multiple");
|
let path = temp_connections_file("mq-auth-multiple");
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ use crate::ai::{
|
|||||||
AiRunStatus,
|
AiRunStatus,
|
||||||
};
|
};
|
||||||
use crate::connection_secrets::{
|
use crate::connection_secrets::{
|
||||||
|
CASSANDRA_KEYSTORE_PASSWORD_KEY, CASSANDRA_TLS_SECRET_PREFIX, CASSANDRA_TRUSTSTORE_PASSWORD_KEY,
|
||||||
MQ_AUTH_API_KEY_VALUE_KEY, MQ_AUTH_CLIENT_SECRET_KEY, MQ_AUTH_PASSWORD_KEY, MQ_AUTH_SECRET_PREFIX,
|
MQ_AUTH_API_KEY_VALUE_KEY, MQ_AUTH_CLIENT_SECRET_KEY, MQ_AUTH_PASSWORD_KEY, MQ_AUTH_SECRET_PREFIX,
|
||||||
MQ_AUTH_TOKEN_KEY, MQ_TOKEN_SIGNING_KEY, MQ_TOKEN_SIGNING_SECRET_PREFIX, NACOS_AUTH_PASSWORD_KEY,
|
MQ_AUTH_TOKEN_KEY, MQ_TOKEN_SIGNING_KEY, MQ_TOKEN_SIGNING_SECRET_PREFIX, NACOS_AUTH_PASSWORD_KEY,
|
||||||
NACOS_AUTH_SECRET_PREFIX, NACOS_RNACOS_CONSOLE_PASSWORD_KEY,
|
NACOS_AUTH_SECRET_PREFIX, NACOS_RNACOS_CONSOLE_PASSWORD_KEY,
|
||||||
@@ -1362,6 +1363,17 @@ fn scrub_nacos_auth_secrets(config: &mut ConnectionConfig) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn scrub_cassandra_tls_secrets(config: &mut ConnectionConfig) {
|
||||||
|
if config.db_type != DatabaseType::Cassandra {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let Some(tls) = cassandra_tls_object_mut(config.external_config.as_mut()) else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
scrub_json_secret(tls, "truststore_password");
|
||||||
|
scrub_json_secret(tls, "keystore_password");
|
||||||
|
}
|
||||||
|
|
||||||
fn delete_secret_prefix_in_tx(
|
fn delete_secret_prefix_in_tx(
|
||||||
tx: &rusqlite::Transaction<'_>,
|
tx: &rusqlite::Transaction<'_>,
|
||||||
connection_id: &str,
|
connection_id: &str,
|
||||||
@@ -3190,6 +3202,7 @@ fn sanitized_connection_config(config: &ConnectionConfig) -> ConnectionConfig {
|
|||||||
scrub_mq_auth_secrets(&mut sanitized);
|
scrub_mq_auth_secrets(&mut sanitized);
|
||||||
scrub_mq_token_signing_secret(&mut sanitized);
|
scrub_mq_token_signing_secret(&mut sanitized);
|
||||||
scrub_nacos_auth_secrets(&mut sanitized);
|
scrub_nacos_auth_secrets(&mut sanitized);
|
||||||
|
scrub_cassandra_tls_secrets(&mut sanitized);
|
||||||
sanitized
|
sanitized
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3265,7 +3278,8 @@ fn persist_connection_in_tx(tx: &rusqlite::Transaction<'_>, config: &ConnectionC
|
|||||||
}
|
}
|
||||||
persist_mq_auth_secrets_in_tx(tx, &config)?;
|
persist_mq_auth_secrets_in_tx(tx, &config)?;
|
||||||
persist_mq_token_signing_secret_in_tx(tx, &config)?;
|
persist_mq_token_signing_secret_in_tx(tx, &config)?;
|
||||||
persist_nacos_auth_secrets_in_tx(tx, &config)
|
persist_nacos_auth_secrets_in_tx(tx, &config)?;
|
||||||
|
persist_cassandra_tls_secrets_in_tx(tx, &config)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn insert_connection_copy_next_to_source(entries: &mut Vec<serde_json::Value>, source_id: &str, copy_id: &str) -> bool {
|
fn insert_connection_copy_next_to_source(entries: &mut Vec<serde_json::Value>, source_id: &str, copy_id: &str) -> bool {
|
||||||
@@ -3400,6 +3414,7 @@ impl Storage {
|
|||||||
scrub_mq_auth_secrets(&mut sanitized);
|
scrub_mq_auth_secrets(&mut sanitized);
|
||||||
scrub_mq_token_signing_secret(&mut sanitized);
|
scrub_mq_token_signing_secret(&mut sanitized);
|
||||||
scrub_nacos_auth_secrets(&mut sanitized);
|
scrub_nacos_auth_secrets(&mut sanitized);
|
||||||
|
scrub_cassandra_tls_secrets(&mut sanitized);
|
||||||
let json = serde_json::to_string(&sanitized).map_err(|e| e.to_string())?;
|
let json = serde_json::to_string(&sanitized).map_err(|e| e.to_string())?;
|
||||||
|
|
||||||
tx.execute("INSERT INTO connections (id, config_json) VALUES (?1, ?2)", params![config_id, json])
|
tx.execute("INSERT INTO connections (id, config_json) VALUES (?1, ?2)", params![config_id, json])
|
||||||
@@ -3721,13 +3736,17 @@ impl Storage {
|
|||||||
let needs_mq_auth_rewrite = self.hydrate_mq_auth_secrets(&id, &mut config).await?;
|
let needs_mq_auth_rewrite = self.hydrate_mq_auth_secrets(&id, &mut config).await?;
|
||||||
let needs_mq_token_signing_rewrite = self.hydrate_mq_token_signing_secret(&id, &mut config).await?;
|
let needs_mq_token_signing_rewrite = self.hydrate_mq_token_signing_secret(&id, &mut config).await?;
|
||||||
let needs_nacos_auth_rewrite = self.hydrate_nacos_auth_secret(&id, &mut config).await?;
|
let needs_nacos_auth_rewrite = self.hydrate_nacos_auth_secret(&id, &mut config).await?;
|
||||||
let needs_external_secret_rewrite =
|
let needs_cassandra_tls_rewrite = self.hydrate_cassandra_tls_secrets(&id, &mut config).await?;
|
||||||
needs_mq_auth_rewrite || needs_mq_token_signing_rewrite || needs_nacos_auth_rewrite;
|
let needs_external_secret_rewrite = needs_mq_auth_rewrite
|
||||||
|
|| needs_mq_token_signing_rewrite
|
||||||
|
|| needs_nacos_auth_rewrite
|
||||||
|
|| needs_cassandra_tls_rewrite;
|
||||||
if needs_external_secret_rewrite {
|
if needs_external_secret_rewrite {
|
||||||
let mut sanitized = config.clone().canonicalized();
|
let mut sanitized = config.clone().canonicalized();
|
||||||
scrub_mq_auth_secrets(&mut sanitized);
|
scrub_mq_auth_secrets(&mut sanitized);
|
||||||
scrub_mq_token_signing_secret(&mut sanitized);
|
scrub_mq_token_signing_secret(&mut sanitized);
|
||||||
scrub_nacos_auth_secrets(&mut sanitized);
|
scrub_nacos_auth_secrets(&mut sanitized);
|
||||||
|
scrub_cassandra_tls_secrets(&mut sanitized);
|
||||||
let sanitized_json = serde_json::to_string(&sanitized).map_err(|e| e.to_string())?;
|
let sanitized_json = serde_json::to_string(&sanitized).map_err(|e| e.to_string())?;
|
||||||
let update_id = id.clone();
|
let update_id = id.clone();
|
||||||
self.with_conn(move |conn| {
|
self.with_conn(move |conn| {
|
||||||
@@ -3838,6 +3857,36 @@ impl Storage {
|
|||||||
}
|
}
|
||||||
Ok(rewritten)
|
Ok(rewritten)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn hydrate_cassandra_tls_secrets(
|
||||||
|
&self,
|
||||||
|
connection_id: &str,
|
||||||
|
config: &mut ConnectionConfig,
|
||||||
|
) -> Result<bool, String> {
|
||||||
|
if config.db_type != DatabaseType::Cassandra {
|
||||||
|
return Ok(false);
|
||||||
|
}
|
||||||
|
let Some(tls) = cassandra_tls_object_mut(config.external_config.as_mut()) else {
|
||||||
|
return Ok(false);
|
||||||
|
};
|
||||||
|
let truststore_rewrite = hydrate_mq_json_secret(
|
||||||
|
self,
|
||||||
|
connection_id,
|
||||||
|
CASSANDRA_TRUSTSTORE_PASSWORD_KEY,
|
||||||
|
tls,
|
||||||
|
"truststore_password",
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
let keystore_rewrite = hydrate_mq_json_secret(
|
||||||
|
self,
|
||||||
|
connection_id,
|
||||||
|
CASSANDRA_KEYSTORE_PASSWORD_KEY,
|
||||||
|
tls,
|
||||||
|
"keystore_password",
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
Ok(truststore_rewrite || keystore_rewrite)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Saved SQL
|
// Saved SQL
|
||||||
@@ -5104,6 +5153,36 @@ fn persist_nacos_auth_secrets_in_tx(tx: &rusqlite::Transaction<'_>, config: &Con
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn persist_cassandra_tls_secrets_in_tx(
|
||||||
|
tx: &rusqlite::Transaction<'_>,
|
||||||
|
config: &ConnectionConfig,
|
||||||
|
) -> Result<(), String> {
|
||||||
|
if config.db_type != DatabaseType::Cassandra {
|
||||||
|
delete_secret_prefix_in_tx(tx, &config.id, CASSANDRA_TLS_SECRET_PREFIX)?;
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
let Some(tls) = cassandra_tls_object(config.external_config.as_ref()) else {
|
||||||
|
delete_secret_prefix_in_tx(tx, &config.id, CASSANDRA_TLS_SECRET_PREFIX)?;
|
||||||
|
return Ok(());
|
||||||
|
};
|
||||||
|
persist_secret_in_tx(
|
||||||
|
tx,
|
||||||
|
&config.id,
|
||||||
|
CASSANDRA_TRUSTSTORE_PASSWORD_KEY,
|
||||||
|
tls.get("truststore_password")
|
||||||
|
.and_then(serde_json::Value::as_str)
|
||||||
|
.unwrap_or(""),
|
||||||
|
)?;
|
||||||
|
persist_secret_in_tx(
|
||||||
|
tx,
|
||||||
|
&config.id,
|
||||||
|
CASSANDRA_KEYSTORE_PASSWORD_KEY,
|
||||||
|
tls.get("keystore_password")
|
||||||
|
.and_then(serde_json::Value::as_str)
|
||||||
|
.unwrap_or(""),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
fn persist_json_secret_if_present_in_tx(
|
fn persist_json_secret_if_present_in_tx(
|
||||||
tx: &rusqlite::Transaction<'_>,
|
tx: &rusqlite::Transaction<'_>,
|
||||||
connection_id: &str,
|
connection_id: &str,
|
||||||
@@ -5165,6 +5244,18 @@ fn mq_token_signing_object_mut(
|
|||||||
value?.get_mut("tokenSigning")?.as_object_mut()
|
value?.get_mut("tokenSigning")?.as_object_mut()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn cassandra_tls_object(
|
||||||
|
value: Option<&serde_json::Value>,
|
||||||
|
) -> Option<&serde_json::Map<String, serde_json::Value>> {
|
||||||
|
value?.get("tls")?.as_object()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn cassandra_tls_object_mut(
|
||||||
|
value: Option<&mut serde_json::Value>,
|
||||||
|
) -> Option<&mut serde_json::Map<String, serde_json::Value>> {
|
||||||
|
value?.get_mut("tls")?.as_object_mut()
|
||||||
|
}
|
||||||
|
|
||||||
fn nacos_auth_object(value: Option<&serde_json::Value>) -> Option<&serde_json::Map<String, serde_json::Value>> {
|
fn nacos_auth_object(value: Option<&serde_json::Value>) -> Option<&serde_json::Map<String, serde_json::Value>> {
|
||||||
value?.get("auth")?.as_object()
|
value?.get("auth")?.as_object()
|
||||||
}
|
}
|
||||||
@@ -5224,7 +5315,8 @@ mod tests {
|
|||||||
};
|
};
|
||||||
use crate::connection_secrets::NACOS_RNACOS_CONSOLE_PASSWORD_KEY;
|
use crate::connection_secrets::NACOS_RNACOS_CONSOLE_PASSWORD_KEY;
|
||||||
use crate::connection_secrets::{
|
use crate::connection_secrets::{
|
||||||
MQ_AUTH_PASSWORD_KEY, MQ_AUTH_TOKEN_KEY, MQ_TOKEN_SIGNING_KEY, NACOS_AUTH_PASSWORD_KEY,
|
CASSANDRA_KEYSTORE_PASSWORD_KEY, CASSANDRA_TRUSTSTORE_PASSWORD_KEY, MQ_AUTH_PASSWORD_KEY,
|
||||||
|
MQ_AUTH_TOKEN_KEY, MQ_TOKEN_SIGNING_KEY, NACOS_AUTH_PASSWORD_KEY,
|
||||||
};
|
};
|
||||||
use crate::history::{HistoryConnectionFilter, HistoryDatabaseFilter, HistoryEntry, HistorySearchRequest};
|
use crate::history::{HistoryConnectionFilter, HistoryDatabaseFilter, HistoryEntry, HistorySearchRequest};
|
||||||
use crate::models::connection::{
|
use crate::models::connection::{
|
||||||
@@ -5842,6 +5934,71 @@ mod tests {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn cassandra_connection(id: &str) -> ConnectionConfig {
|
||||||
|
let mut config = plain_connection(id, "");
|
||||||
|
config.name = "Cassandra".to_string();
|
||||||
|
config.db_type = DatabaseType::Cassandra;
|
||||||
|
config.port = 9042;
|
||||||
|
config.ssl = true;
|
||||||
|
config.external_config = Some(serde_json::json!({
|
||||||
|
"tls": {
|
||||||
|
"truststore_path": "/certs/client.truststore",
|
||||||
|
"truststore_password": "trust-secret",
|
||||||
|
"keystore_path": "/certs/client.keystore",
|
||||||
|
"keystore_password": "key-secret"
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
config
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn save_connections_moves_cassandra_tls_passwords_to_secret_table_and_restores_them() {
|
||||||
|
let path = temp_db_path("cassandra-tls-secrets");
|
||||||
|
let storage = Storage::open(&path).await.unwrap();
|
||||||
|
|
||||||
|
storage.save_connections(&[cassandra_connection("cassandra")]).await.unwrap();
|
||||||
|
|
||||||
|
let raw_json = raw_connection_json(&storage, "cassandra").await;
|
||||||
|
assert!(!raw_json.contains("trust-secret"));
|
||||||
|
assert!(!raw_json.contains("key-secret"));
|
||||||
|
assert_eq!(
|
||||||
|
storage
|
||||||
|
.get_secret("cassandra", CASSANDRA_TRUSTSTORE_PASSWORD_KEY)
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.as_deref(),
|
||||||
|
Some("trust-secret")
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
storage
|
||||||
|
.get_secret("cassandra", CASSANDRA_KEYSTORE_PASSWORD_KEY)
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.as_deref(),
|
||||||
|
Some("key-secret")
|
||||||
|
);
|
||||||
|
|
||||||
|
let loaded = storage.load_connections().await.unwrap();
|
||||||
|
let tls = loaded[0].external_config.as_ref().unwrap().get("tls").unwrap();
|
||||||
|
assert_eq!(tls["truststore_password"], "trust-secret");
|
||||||
|
assert_eq!(tls["keystore_password"], "key-secret");
|
||||||
|
|
||||||
|
let mut disabled = cassandra_connection("cassandra");
|
||||||
|
disabled.ssl = false;
|
||||||
|
disabled.external_config = None;
|
||||||
|
storage.save_connections(&[disabled]).await.unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
storage.get_secret("cassandra", CASSANDRA_TRUSTSTORE_PASSWORD_KEY).await.unwrap(),
|
||||||
|
None
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
storage.get_secret("cassandra", CASSANDRA_KEYSTORE_PASSWORD_KEY).await.unwrap(),
|
||||||
|
None
|
||||||
|
);
|
||||||
|
|
||||||
|
let _ = std::fs::remove_file(path);
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn save_connections_does_not_persist_password_when_save_password_false() {
|
async fn save_connections_does_not_persist_password_when_save_password_false() {
|
||||||
let path = temp_db_path("save-password-false");
|
let path = temp_db_path("save-password-false");
|
||||||
|
|||||||
Reference in new issue
Block a user