mirror of
https://github.com/SynologyOpenSource/synology-csi.git
synced 2026-08-19 11:36:33 +00:00
The DSM WebAPI client disabled TLS certificate verification for all
HTTPS connections (InsecureSkipVerify: true), then sent the configured
DSM account and password to the endpoint. An attacker able to intercept,
redirect, or impersonate the DSM HTTPS endpoint could therefore obtain
the DSM credentials stored in the CSI client config / Kubernetes secret
(CWE-295 Improper Certificate Validation, OWASP A3:2017 Sensitive Data Exposure)
TLS certificate verification is now enabled by default. The client trusts
the system CA pool, so certificates signed by a public CA work without
extra configuration. Three optional client-info fields are added:
- tlsCACert: PEM CA cert to trust (for DSM self-signed certs);
merged with the system CA pool.
- tlsServerName: override the name checked during verification,
e.g. when connecting by IP.
- insecureSkipVerify: explicit opt-out that restores the old behavior;
logs a warning on every connection.
The new fields are propagated through all DSM construction sites
(service, synocli, and the HA GetAnotherController path).
BREAKING CHANGE: deployments using `https: true` against a DSM with a
self-signed certificate (the DSM default) will fail to connect after
upgrade until they set `tlsCACert`, `tlsServerName`, or (discouraged)
`insecureSkipVerify: true`.
Adds TLS tests covering default-reject, valid-CA accept, wrong-CA reject,
insecureSkipVerify opt-in, and the tlsServerName DNS-SAN scenarios.
93 lines
1.9 KiB
Go
93 lines
1.9 KiB
Go
// Copyright 2022 Synology Inc.
|
|
|
|
package webapi
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/SynologyOpenSource/synology-csi/pkg/utils"
|
|
)
|
|
|
|
func (dsm *DSM) IsUC() bool {
|
|
return strings.Contains(dsm.FirmwareVer, "DSM UC")
|
|
}
|
|
|
|
func (dsm *DSM) GetAnotherController() (*DSM, error) {
|
|
anotherDsm := &DSM{
|
|
Port: dsm.Port,
|
|
Username: dsm.Username,
|
|
Password: dsm.Password,
|
|
Https: dsm.Https,
|
|
TLSCACert: dsm.TLSCACert,
|
|
TLSServerName: dsm.TLSServerName,
|
|
InsecureSkipVerify: dsm.InsecureSkipVerify,
|
|
}
|
|
|
|
netListA, err := dsm.NetworkInterfaceList("node0")
|
|
if err != nil {
|
|
return nil, fmt.Errorf("Failed to get DSM network list of controller A. %v", err)
|
|
}
|
|
|
|
netListB, err := dsm.NetworkInterfaceList("node1")
|
|
if err != nil {
|
|
return nil, fmt.Errorf("Failed to get DSM network list of controller B. %v", err)
|
|
}
|
|
|
|
ips, err := utils.LookupIPv4(dsm.Ip) // because dsm.Ip may be a domain
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
dsm.Controller = "A"
|
|
anotherDsm.Controller = "B"
|
|
anotherList := netListB
|
|
for _, netIf := range netListB {
|
|
if netIf.Ip == ips[0] {
|
|
dsm.Controller = "B"
|
|
anotherDsm.Controller = "A"
|
|
anotherList = netListA
|
|
break
|
|
}
|
|
}
|
|
|
|
ipPrefix := ips[0]
|
|
for i := 0; i < 4; i++ {
|
|
dotPos := strings.LastIndex(ipPrefix, ".")
|
|
|
|
if dotPos == -1 {
|
|
ipPrefix = ""
|
|
} else {
|
|
ipPrefix = ipPrefix[:dotPos]
|
|
}
|
|
|
|
for _, netIf := range anotherList {
|
|
if ipPrefix != "" && !strings.HasPrefix(netIf.Ip, ipPrefix) {
|
|
continue
|
|
}
|
|
|
|
if netIf.Status == "connected" && CheckIpReachable(netIf.Ip, anotherDsm.Port){
|
|
anotherDsm.Ip = netIf.Ip
|
|
return anotherDsm, nil
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil, fmt.Errorf("Failed to get reachable network of another controller.")
|
|
}
|
|
|
|
func CheckIpReachable(ip string, port int) bool {
|
|
seconds := 5
|
|
timeOut := time.Duration(seconds) * time.Second
|
|
|
|
_, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%d", ip, port), timeOut)
|
|
|
|
if err != nil {
|
|
return false
|
|
}
|
|
|
|
return true
|
|
}
|