Merge pull request #46877 from robmry/early_error_for_cifs_url_with_port
Don't allow port in CIFS URL
This commit is contained in:
commit
df59a357ec
2 changed files with 38 additions and 7 deletions
|
@ -199,6 +199,32 @@ func TestVolCreateValidation(t *testing.T) {
|
||||||
"o": "foo",
|
"o": "foo",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
doc: "cifs",
|
||||||
|
opts: map[string]string{
|
||||||
|
"type": "cifs",
|
||||||
|
"device": "//some.example.com/thepath",
|
||||||
|
"o": "foo",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
doc: "cifs with port in url",
|
||||||
|
opts: map[string]string{
|
||||||
|
"type": "cifs",
|
||||||
|
"device": "//some.example.com:2345/thepath",
|
||||||
|
"o": "foo",
|
||||||
|
},
|
||||||
|
expectedErr: "port not allowed in CIFS device URL, include 'port' in 'o='",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
doc: "cifs with bad url",
|
||||||
|
opts: map[string]string{
|
||||||
|
"type": "cifs",
|
||||||
|
"device": ":::",
|
||||||
|
"o": "foo",
|
||||||
|
},
|
||||||
|
expectedErr: `error parsing mount device url: parse ":::": missing protocol scheme`,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, tc := range tests {
|
for i, tc := range tests {
|
||||||
|
|
|
@ -56,6 +56,15 @@ func (r *Root) validateOpts(opts map[string]string) error {
|
||||||
return errdefs.InvalidParameter(errors.Errorf("invalid option: %q", opt))
|
return errdefs.InvalidParameter(errors.Errorf("invalid option: %q", opt))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if typeOpt, deviceOpt := opts["type"], opts["device"]; typeOpt == "cifs" && deviceOpt != "" {
|
||||||
|
deviceURL, err := url.Parse(deviceOpt)
|
||||||
|
if err != nil {
|
||||||
|
return errdefs.InvalidParameter(errors.Wrapf(err, "error parsing mount device url"))
|
||||||
|
}
|
||||||
|
if deviceURL.Port() != "" {
|
||||||
|
return errdefs.InvalidParameter(errors.New("port not allowed in CIFS device URL, include 'port' in 'o='"))
|
||||||
|
}
|
||||||
|
}
|
||||||
if val, ok := opts["size"]; ok {
|
if val, ok := opts["size"]; ok {
|
||||||
size, err := units.RAMInBytes(val)
|
size, err := units.RAMInBytes(val)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -131,16 +140,12 @@ func (v *localVolume) mount() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "error parsing mount device url")
|
return errors.Wrapf(err, "error parsing mount device url")
|
||||||
}
|
}
|
||||||
if deviceURL.Host != "" && net.ParseIP(deviceURL.Hostname()) == nil {
|
if deviceURL.Host != "" && net.ParseIP(deviceURL.Host) == nil {
|
||||||
ipAddr, err := net.ResolveIPAddr("ip", deviceURL.Hostname())
|
ipAddr, err := net.ResolveIPAddr("ip", deviceURL.Host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "error resolving passed in network volume address")
|
return errors.Wrapf(err, "error resolving passed in network volume address")
|
||||||
}
|
}
|
||||||
if deviceURL.Port() != "" {
|
deviceURL.Host = ipAddr.String()
|
||||||
deviceURL.Host = net.JoinHostPort(ipAddr.String(), deviceURL.Port())
|
|
||||||
} else {
|
|
||||||
deviceURL.Host = ipAddr.String()
|
|
||||||
}
|
|
||||||
mountDevice = deviceURL.String()
|
mountDevice = deviceURL.String()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue