Details
-
Type: Bug
-
Status: Resolved
-
Priority: Major
-
Resolution: Fixed
-
Fix Version/s: OpenVZ-legacy
-
Component/s: None
-
Security Level: Public
-
Environment:- Two container hosts
source host : CentOS 6.10-based Virtuozzo 4.7
destination host: virtuozzo7
- ovztransfer.sh
https://src.openvz.org/scm/ovzl/ovztransfer.git.
Description
Katsuhisa Fujinaga (kfujina):
## Description of problem:
The ovztransfer scripts try to add NAME variables to destination container settings if it is not specified.
But this code is not properly quoted, so this code can not add NAME variable to destination container settings.
And, if specified destination cointainer id is used at source container host, the ovztransfer change same id's container setting at source host.
bug code is here:
https://src.openvz.org/projects/OVZL/repos/ovztransfer/browse/ovztransfer.sh#184
This bug is reproduced by following steps.
1. Create container at source hosts (Virtuozzo4.7 or Legacy open-vz)
```
[root@work-vz47-2 ovztransfer.org]# vzlist --all
CTID NPROC STATUS IP_ADDR HOSTNAME
101 - stopped - C4-64
```
2. Check ve.conf at source host.
```
: The NAME variable is not defined in ve.conf
[root@work-vz47-2 ovztransfer.org]# grep -E "^NAME=" /vz/private/101/ve.conf
[root@work-vz47-2 ovztransfer.org]#
```
3. migrate container by using ovztransfer script
```
: Set the same value as source container id to distination container id
[root@work-vz47-2 ovztransfer.org]# ./ovztransfer.sh <destination ip> 101:101
```
4. Check ve.conf at source host.
```
: The NAME variable is defined in ve.conf
[root@work-vz47-2 ovztransfer.org]# grep -E "^NAME=" /vz/private/101/ve.conf
NAME=101-C4-64
[root@work-vz47-2 ovztransfer.org]#
```
5. Check ve.conf at destination host.
```
: The NAME variable is not defined in ve.conf
[root@work-vz7 ~]# grep -E "^NAME=" /vz/private/101/ve.conf
[root@work-vz7 ~]#
```
## How to fix
quote remote codes.
https://src.openvz.org/projects/OVZL/repos/ovztransfer/browse/ovztransfer.sh#184
* before
```
ssh $ssh_opts root@$target echo NAME=$target_veid-$HOSTNAME >> /vz/private/$target_veid/ve.conf
```
* after
```
ssh $ssh_opts root@$target echo NAME=$target_veid-$HOSTNAME >> /vz/private/$target_veid/ve.conf
```
## Pull Request
https://src.openvz.org/projects/OVZL/repos/ovztransfer/pull-requests/3/overview
## Result of fix
0. fix code
```
[root@work-vz47-2 ovztransfer]# diff ../ovztransfer.org/ovztransfer.sh ./ovztransfer.sh
184c184
< ssh $ssh_opts root@$target echo NAME=$target_veid-$HOSTNAME >> /vz/private/$target_veid/ve.conf
---
> ssh $ssh_opts root@$target "echo NAME=$target_veid-$HOSTNAME >> /vz/private/$target_veid/ve.conf"
```
1. Create container at source hosts (Virtuozzo4.7 or Legacy open-vz)
```
[root@work-vz47-2 ovztransfer]# vzlist --all
CTID NPROC STATUS IP_ADDR HOSTNAME
101 - stopped - C4-64
102 14 running - C4-32
```
2. Check ve.conf at source host.
```
: The NAME variable is not defined in ve.conf
[root@work-vz47-2 ovztransfer]# grep -E "^NAME=" /vz/private/102/ve.conf
[root@work-vz47-2 ovztransfer]#
```
3. migrate container by using ovztransfer script
```
: Set the same value as source container id to distination container id
[root@work-vz47-2 ovztransfer]# ./ovztransfer.sh <destination ip> 102:102
```
4. Check ve.conf at source host.
```
: The NAME variable is not defined in ve.conf
[root@work-vz47-2 ovztransfer]# grep -E "^NAME=" /vz/private/102/ve.conf
[root@work-vz47-2 ovztransfer]#
```
5. Check ve.conf at destination host.
```
: The NAME variable is defined in ve.conf
[root@work-vz7 ~]# grep -E "^NAME=" /vz/private/102/ve.conf
NAME="102-C4-32"
[root@work-vz7 ~]#
```
## Description of problem:
The ovztransfer scripts try to add NAME variables to destination container settings if it is not specified.
But this code is not properly quoted, so this code can not add NAME variable to destination container settings.
And, if specified destination cointainer id is used at source container host, the ovztransfer change same id's container setting at source host.
bug code is here:
https://src.openvz.org/projects/OVZL/repos/ovztransfer/browse/ovztransfer.sh#184
This bug is reproduced by following steps.
1. Create container at source hosts (Virtuozzo4.7 or Legacy open-vz)
```
[root@work-vz47-2 ovztransfer.org]# vzlist --all
CTID NPROC STATUS IP_ADDR HOSTNAME
101 - stopped - C4-64
```
2. Check ve.conf at source host.
```
: The NAME variable is not defined in ve.conf
[root@work-vz47-2 ovztransfer.org]# grep -E "^NAME=" /vz/private/101/ve.conf
[root@work-vz47-2 ovztransfer.org]#
```
3. migrate container by using ovztransfer script
```
: Set the same value as source container id to distination container id
[root@work-vz47-2 ovztransfer.org]# ./ovztransfer.sh <destination ip> 101:101
```
4. Check ve.conf at source host.
```
: The NAME variable is defined in ve.conf
[root@work-vz47-2 ovztransfer.org]# grep -E "^NAME=" /vz/private/101/ve.conf
NAME=101-C4-64
[root@work-vz47-2 ovztransfer.org]#
```
5. Check ve.conf at destination host.
```
: The NAME variable is not defined in ve.conf
[root@work-vz7 ~]# grep -E "^NAME=" /vz/private/101/ve.conf
[root@work-vz7 ~]#
```
## How to fix
quote remote codes.
https://src.openvz.org/projects/OVZL/repos/ovztransfer/browse/ovztransfer.sh#184
* before
```
ssh $ssh_opts root@$target echo NAME=$target_veid-$HOSTNAME >> /vz/private/$target_veid/ve.conf
```
* after
```
ssh $ssh_opts root@$target echo NAME=$target_veid-$HOSTNAME >> /vz/private/$target_veid/ve.conf
```
## Pull Request
https://src.openvz.org/projects/OVZL/repos/ovztransfer/pull-requests/3/overview
## Result of fix
0. fix code
```
[root@work-vz47-2 ovztransfer]# diff ../ovztransfer.org/ovztransfer.sh ./ovztransfer.sh
184c184
< ssh $ssh_opts root@$target echo NAME=$target_veid-$HOSTNAME >> /vz/private/$target_veid/ve.conf
---
> ssh $ssh_opts root@$target "echo NAME=$target_veid-$HOSTNAME >> /vz/private/$target_veid/ve.conf"
```
1. Create container at source hosts (Virtuozzo4.7 or Legacy open-vz)
```
[root@work-vz47-2 ovztransfer]# vzlist --all
CTID NPROC STATUS IP_ADDR HOSTNAME
101 - stopped - C4-64
102 14 running - C4-32
```
2. Check ve.conf at source host.
```
: The NAME variable is not defined in ve.conf
[root@work-vz47-2 ovztransfer]# grep -E "^NAME=" /vz/private/102/ve.conf
[root@work-vz47-2 ovztransfer]#
```
3. migrate container by using ovztransfer script
```
: Set the same value as source container id to distination container id
[root@work-vz47-2 ovztransfer]# ./ovztransfer.sh <destination ip> 102:102
```
4. Check ve.conf at source host.
```
: The NAME variable is not defined in ve.conf
[root@work-vz47-2 ovztransfer]# grep -E "^NAME=" /vz/private/102/ve.conf
[root@work-vz47-2 ovztransfer]#
```
5. Check ve.conf at destination host.
```
: The NAME variable is defined in ve.conf
[root@work-vz7 ~]# grep -E "^NAME=" /vz/private/102/ve.conf
NAME="102-C4-32"
[root@work-vz7 ~]#
```