From bd021f701b4cecfdeecfdf7fd993c0b282c87d76 Mon Sep 17 00:00:00 2001 From: Redouane Kachach Date: Mon, 23 May 2022 12:14:07 +0200 Subject: [PATCH] mgr/nfs: validate virtual_ip parameter Fixes: https://tracker.ceph.com/issues/54581 Signed-off-by: Redouane Kachach (cherry picked from commit 75aafdaf367cd3624cb33ac5a99a73a27a9e3f52) --- src/pybind/mgr/nfs/cluster.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/pybind/mgr/nfs/cluster.py b/src/pybind/mgr/nfs/cluster.py index 1d8054411324..61bc477727ba 100644 --- a/src/pybind/mgr/nfs/cluster.py +++ b/src/pybind/mgr/nfs/cluster.py @@ -1,3 +1,4 @@ +import ipaddress import logging import json import re @@ -103,7 +104,13 @@ class NFSCluster: ingress: Optional[bool] = None, port: Optional[int] = None, ) -> Tuple[int, str, str]: + try: + if virtual_ip: + # validate virtual_ip value: ip_address throws a ValueError + # exception in case it's not a valid ipv4 or ipv6 address + ip = virtual_ip.split('/')[0] + ipaddress.ip_address(ip) if virtual_ip and not ingress: raise NFSInvalidOperation('virtual_ip can only be provided with ingress enabled') if not virtual_ip and ingress: -- 2.47.3