Validate returns errors errors if invalid config is present
(ctx context.Context, isEnterpriseEdition bool)
| 1495 | |
| 1496 | // Validate returns errors errors if invalid config is present |
| 1497 | func (sc *StartupConfig) Validate(ctx context.Context, isEnterpriseEdition bool) (errorMessages error) { |
| 1498 | var multiError *base.MultiError |
| 1499 | if sc.Bootstrap.Server == "" { |
| 1500 | multiError = multiError.Append(fmt.Errorf("a server must be provided in the Bootstrap configuration")) |
| 1501 | } |
| 1502 | |
| 1503 | secureServer := base.ServerIsTLS(sc.Bootstrap.Server) |
| 1504 | if base.ValDefault(sc.Bootstrap.UseTLSServer, DefaultUseTLSServer) { |
| 1505 | if !secureServer && !base.ServerIsWalrus(sc.Bootstrap.Server) { |
| 1506 | multiError = multiError.Append(fmt.Errorf("Must use secure scheme in Couchbase Server URL, or opt out by setting bootstrap.use_tls_server to false. Current URL: %s", base.SD(sc.Bootstrap.Server))) |
| 1507 | } |
| 1508 | } else { |
| 1509 | if secureServer { |
| 1510 | multiError = multiError.Append(fmt.Errorf("Couchbase server URL cannot use secure protocol when bootstrap.use_tls_server is false. Current URL: %s", base.SD(sc.Bootstrap.Server))) |
| 1511 | } |
| 1512 | } |
| 1513 | |
| 1514 | if sc.Bootstrap.ServerTLSSkipVerify != nil && *sc.Bootstrap.ServerTLSSkipVerify && sc.Bootstrap.CACertPath != "" { |
| 1515 | multiError = multiError.Append(fmt.Errorf("cannot skip server TLS validation and use CA Cert")) |
| 1516 | } |
| 1517 | |
| 1518 | // Make sure if a SSL key or cert is provided, they are both provided |
| 1519 | if (sc.API.HTTPS.TLSKeyPath != "" || sc.API.HTTPS.TLSCertPath != "") && (sc.API.HTTPS.TLSKeyPath == "" || sc.API.HTTPS.TLSCertPath == "") { |
| 1520 | multiError = multiError.Append(fmt.Errorf("both TLS Key Path and TLS Cert Path must be provided when using client TLS. Disable client TLS by not providing either of these options")) |
| 1521 | } |
| 1522 | |
| 1523 | if sc.Auth.BcryptCost > 0 && (sc.Auth.BcryptCost < auth.DefaultBcryptCost || sc.Auth.BcryptCost > bcrypt.MaxCost) { |
| 1524 | multiError = multiError.Append(fmt.Errorf("%v: %d outside allowed range: %d-%d", auth.ErrInvalidBcryptCost, sc.Auth.BcryptCost, auth.DefaultBcryptCost, bcrypt.MaxCost)) |
| 1525 | } |
| 1526 | |
| 1527 | if len(sc.Bootstrap.ConfigGroupID) > persistentConfigGroupIDMaxLength { |
| 1528 | multiError = multiError.Append(fmt.Errorf("group_id must be at most %d characters in length", persistentConfigGroupIDMaxLength)) |
| 1529 | } |
| 1530 | |
| 1531 | if sc.DatabaseCredentials != nil { |
| 1532 | for dbName, creds := range sc.DatabaseCredentials { |
| 1533 | if (creds.X509CertPath != "" || creds.X509KeyPath != "") && (creds.Username != "" || creds.Password != "") { |
| 1534 | base.WarnfCtx(ctx, "database %q in database_credentials cannot use both x509 and basic auth. Will use x509 only.", base.MD(dbName)) |
| 1535 | } |
| 1536 | } |
| 1537 | } |
| 1538 | |
| 1539 | if sc.IsServerless() && len(sc.BucketCredentials) == 0 { |
| 1540 | multiError = multiError.Append(fmt.Errorf("at least 1 bucket must be defined in bucket_credentials when running in serverless mode")) |
| 1541 | } |
| 1542 | |
| 1543 | if sc.BucketCredentials != nil { |
| 1544 | for bucketName, creds := range sc.BucketCredentials { |
| 1545 | if (creds.X509CertPath != "" || creds.X509KeyPath != "") && (creds.Username != "" || creds.Password != "") { |
| 1546 | multiError = multiError.Append(fmt.Errorf("bucket %q in bucket_credentials cannot use both x509 and basic auth", base.MD(bucketName))) |
| 1547 | } |
| 1548 | } |
| 1549 | } |
| 1550 | |
| 1551 | // EE only features |
| 1552 | if !isEnterpriseEdition { |
| 1553 | if sc.API.EnableAdminAuthenticationPermissionsCheck != nil && *sc.API.EnableAdminAuthenticationPermissionsCheck { |
| 1554 | multiError = multiError.Append(fmt.Errorf("enable_advanced_auth_dp is only supported in enterprise edition")) |