Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IPv6 on vrrp interface #757

Closed
stfast opened this issue Jan 21, 2018 · 13 comments
Closed

IPv6 on vrrp interface #757

stfast opened this issue Jan 21, 2018 · 13 comments

Comments

@stfast
Copy link

stfast commented Jan 21, 2018

I've noticed that IPv6 is configured on vrrp interface getting split brain on first failover

vrrp.6: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::200:5eff:fe00:106 prefixlen 64 scopeid 0x20
ether 00:00:5e:00:01:06 txqueuelen 1000 (Ethernet)
RX packets 247 bytes 11978 (11.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 12 bytes 952 (952.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

vrrp.7: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::200:5eff:fe00:107 prefixlen 64 scopeid 0x20
ether 00:00:5e:00:01:07 txqueuelen 1000 (Ethernet)
RX packets 247 bytes 11978 (11.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 12 bytes 952 (952.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

If I enable disable_ipv6 for vrrp interfaces everything works normal:

net.ipv4.conf.all.rp_filter = 0
net.ipv4.conf.lo.rp_filter = 0
net.ipv4.conf.default.rp_filter = 0
#net.ipv6.conf.vrrp/6.disable_ipv6 = 1
#net.ipv6.conf.vrrp/7.disable_ipv6 = 1
net.ipv4.ip_nonlocal_bind = 1

Also I noticed that net.ipv4.conf.all.rp_filter is ureadable on keepalived startup:

Jan 21 19:11:44 mx2 Keepalived_vrrp[1582]: vmac: Success creating VMAC interface vrrp.6 for vrrp_instance mx.vlan103
Jan 21 19:11:44 mx2 Keepalived_vrrp[1582]: Unable to read sysctl net.ipv4.conf.all.rp_filter
Jan 21 19:11:44 mx2 Keepalived_vrrp[1582]: vmac: Success creating VMAC interface vrrp.7 for vrrp_instance mx.vlan212
Jan 21 19:11:44 mx2 Keepalived_vrrp[1582]: Unable to read sysctl net.ipv4.conf.all.rp_filter
net.ipv6.conf.vrrp/7.disable_ipv6 = 1

So why vrrp->family for disable_ipv6 is calculated diffrently on other systems with the same OS (FC27) and keepalived (1.3.9) and same (copied) system setup where IPv6 is properly disabled on vrrp interfaces:

vrrp.21: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 00:00:5e:00:01:15 txqueuelen 1000 (Ethernet)
RX packets 1490723 bytes 74286032 (70.8 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

vrrp.22: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 00:00:5e:00:01:16 txqueuelen 1000 (Ethernet)
RX packets 1489359 bytes 74162544 (70.7 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

@pqarmitage
Copy link
Collaborator

Can you please describe the environment that keepalived is being run in, e.g. what kernel version, is keepalived being run in a container or a VM? I take it by FC27 you mean Fedora 27.

Please also provide a copy of your configuration and the output of keepalived -v. Are you using the standard Fedora 27 keepalived rpm?

How are you disabling ipv6 on vrrp.6 and vrrp.7?

If keepalived can't update net.ipv4.conf.all.rp_filter I don't understand why net.ipv4.conf.all.rp_filter = 0 since the default on Fedora, and generally systems that use systemd, is that it is set to 1 (I filed a bug some time ago against systemd saying that this should be 0, and net.ipv4.conf.default.rp_filter should be 1). Have you changed some of the /proc/sys/net settings?

I don't understand what you mean by:

If I enable disable_ipv6 for vrrp interfaces everything works normal:

net.ipv4.conf.all.rp_filter = 0
net.ipv4.conf.lo.rp_filter = 0
net.ipv4.conf.default.rp_filter = 0
#net.ipv6.conf.vrrp/6.disable_ipv6 = 1
#net.ipv6.conf.vrrp/7.disable_ipv6 = 1
net.ipv4.ip_nonlocal_bind = 1

It appears that the disabling of ipv6 is commented out. Or is this some configuration file or is it the output of some command?

I have run keepalived in a Fedora 27 VM and I am not experiencing these problems.

@stfast
Copy link
Author

stfast commented Jan 22, 2018

Yes, It is Fedora 27 with all the latest updates, all standard rpm packages. Keepalived (1.3.9) works on top of OpenvSwitch (2.8.1) interfaces in KVM guest.

This is my custom sysctl configuration :

[root@mx1 ~]# cat /etc/sysctl.conf
...
net.ipv4.conf.all.rp_filter = 0
net.ipv4.conf.lo.rp_filter = 0
net.ipv4.conf.default.rp_filter = 0
net.ipv6.conf.vrrp/6.disable_ipv6 = 1
net.ipv6.conf.vrrp/7.disable_ipv6 = 1

Previously I had no *.disable_ipv6 settings in sysctl.conf. Now keepalived on this system works only when IPv6 is disabled on vrrp intefaces. It is wierd, that I have some systems where IPv6 is properly disabled by keepalived and few systems where IPv6 is still enabled running keepalived.

This is my Keepalived configuration. It differs in state (BACKUP) and priority (51) from backup node.

[root@mx1 ~]# cat /etc/keepalived/keepalived.conf
global_defs {
notification_email {
sysadmin@domain.com
}
enable_script_security
script_user root
notification_email_from mx1@domain.com
smtp_server localhost
smtp_connect_timeout 30
router_id mx1
vrrp_strict
}

vrrp_sync_group mx {
group {
mx.vlan103
mx.vlan212
}
notify_master "/usr/libexec/keepalived/primary-backup.sh primary"
notify_backup "/usr/libexec/keepalived/primary-backup.sh backup"
notify_fault "/usr/libexec/keepalived/primary-backup.sh fault"
}

vrrp_instance mx.vlan103 {
state MASTER
interface vlan99
virtual_router_id 6
priority 151
advert_int 1
garp_master_delay 1
use_vmac
vmac_xmit_base
authentication {
auth_type PASS
auth_pass *******
}
virtual_ipaddress {
172.16.103.225/24 dev vlan103-vip
}
smtp_alert
}

vrrp_instance mx.vlan212 {
state MASTER
interface vlan99
virtual_router_id 7
priority 151
advert_int 1
garp_master_delay 1
use_vmac
vmac_xmit_base
authentication {
auth_type PASS
auth_pass ***********
}
virtual_ipaddress {
8x.2xx.6x.2xx/24 dev vlan212-vip
}
smtp_alert
}

@pqarmitage
Copy link
Collaborator

Looking at the code, it checks whether the read of /proc/sys/net/ipv4/conf/all/rp_filter is successful or not, and we can see that it is failing. Unfortunately the code does not check (at the moment) whether the write to /proc/sys/net/ipv6/conf/vrrp.6/disable_ipv6 etc. is successful or not, and hence no error message is reported.

It appears that the /proc filesystem is not accessible from within the KVM. Can you check whether you are able to modify /proc/sys/net/ipv4/conf/all/rp_filter from within the KVM, since I think that is where your problem lies.

@stfast
Copy link
Author

stfast commented Jan 22, 2018

Thanks for the hint!

It is/was SELinux and this is confirmation:

[root@mx1 ~]# ifconfig vrrp.6
vrrp.6: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::200:5eff:fe00:106 prefixlen 64 scopeid 0x20
ether 00:00:5e:00:01:06 txqueuelen 1000 (Ethernet)
RX packets 89 bytes 4848 (4.7 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 5 bytes 374 (374.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

[root@mx1 ~]# setenforce 0

[root@mx1 ~]# systemctl restart keepalived.service

[root@mx1 ~]# ifconfig vrrp.6
vrrp.6: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 00:00:5e:00:01:06 txqueuelen 1000 (Ethernet)
RX packets 93 bytes 5106 (4.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2 bytes 108 (108.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

[root@mx1 ~]# setenforce 1

[root@mx1 ~]# systemctl restart keepalived.service

[root@mx1 ~]# ifconfig vrrp.6
vrrp.6: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::200:5eff:fe00:106 prefixlen 64 scopeid 0x20
ether 00:00:5e:00:01:06 txqueuelen 1000 (Ethernet)
RX packets 93 bytes 5062 (4.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 5 bytes 374 (374.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

@stfast
Copy link
Author

stfast commented Jan 22, 2018

Since I could not find any good documentation about sysctl settings for keepalived (per linux distribution), can you please enlight us which sysctl setting should be changed in sysctl.conf that keepalived do not set? Is there actually need for custom sysctl changes?

Now I have only net.ipv4.conf.all.rp_filter = 0 set in sysctl.conf:

[root@mx1 ~]# cat /etc/sysctl.conf

#rp_filter settings needed for keepalived VRRP
net.ipv4.conf.all.rp_filter = 0
#net.ipv4.conf.lo.rp_filter = 0
#net.ipv4.conf.default.rp_filter = 0
#net.ipv6.conf.vrrp/6.disable_ipv6 = 1
#net.ipv6.conf.vrrp/7.disable_ipv6 = 1
#allow services to bind to the virtual ip even when this server is the passive machine
net.ipv4.ip_nonlocal_bind = 1

#conntrackd/keepalived
net.netfilter.nf_conntrack_tcp_loose = 0
net.netfilter.nf_conntrack_tcp_be_liberal = 1

@stfast
Copy link
Author

stfast commented Jan 22, 2018

With SELinux enabled I can modify /proc/sys/* settings in terminal. So why keepalived can't, running
under root privileges?

[root@mx1 ~]# sestatus
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: enforcing
Mode from config file: enforcing
Policy MLS status: enabled
Policy deny_unknown status: allowed
Max kernel policy version: 31

[root@mx1 ~]# cat /proc/sys/net/ipv6/conf/vrrp.6/disable_ipv6
0

[root@mx1 ~]# echo 1 > /proc/sys/net/ipv6/conf/vrrp.6/disable_ipv6

[root@mx1 ~]# cat /proc/sys/net/ipv6/conf/vrrp.6/disable_ipv6
1

Maybe this is connected with latest kernel security patches?!

@pqarmitage
Copy link
Collaborator

If I'm readings things properly, mx1 is your Fedora 27 system, and mx2 is the KVM system.

If the above is correct, the problem is with keepalived running in the KVM (mx2), but when you have executed echo 1 > /proc/sys/net/ipv6/conf/vrrp.6/disable_ipv6 from a terminal, you have done that in mx1 rather than mx2.

It seems to me that SELinux in mx1 is preventing the KVM (mx2) from accessing the /proc filesystem in mx1; this though makes mx2 sound more like a container.

@pqarmitage
Copy link
Collaborator

Sorry, I didn't answer your question about which sysctl settings need to be set for keepalived.

The simple answer is none; keepalived sets what it needs to. See keepalived/vrrp/vrrp_if_config.c for the details of what needs to be set and why, and if you follow the code you will see that keepalived is setting them, as you experience when you say It is wierd, that I have some systems where IPv6 is properly disabled by keepalived and few systems where IPv6 is still enabled running keepalived.

As I wrote above, the problem appears to be that mx2 cannot access the /proc filesystem, and that SELinux in the host system mx1 is stopping that access.

@stfast
Copy link
Author

stfast commented Jan 23, 2018

Actually mx1 and mx2, they are both KVM guests.

[root@mx2 ~]# restorecon -r /
[root@mx2 ~]# reboot

With SELinux disabled and restored default SELinux security contexts I still get:

Keepalived_vrrp[1595]: Unable to read sysctl net.ipv4.conf.all.rp_filter.

Jan 21 21:32:44 mx2 Keepalived[1567]: Stopped Keepalived v1.3.9 (10/21,2017)
Jan 21 21:33:36 mx2 Keepalived[1590]: Starting Keepalived v1.3.9 (10/21,2017)
Jan 21 21:33:36 mx2 Keepalived[1590]: Opening file '/etc/keepalived/keepalived.conf'.
Jan 21 21:33:36 mx2 Keepalived[1593]: Starting Healthcheck child process, pid=1594
Jan 21 21:33:36 mx2 Keepalived[1593]: Starting VRRP child process, pid=1595
Jan 21 21:33:36 mx2 Keepalived_healthcheckers[1594]: Opening file '/etc/keepalived/keepalived.conf'.
Jan 21 21:33:36 mx2 Keepalived_vrrp[1595]: Registering Kernel netlink reflector
Jan 21 21:33:36 mx2 Keepalived_vrrp[1595]: Registering Kernel netlink command channel
Jan 21 21:33:36 mx2 Keepalived_vrrp[1595]: Registering gratuitous ARP shared channel
Jan 21 21:33:36 mx2 Keepalived_vrrp[1595]: Opening file '/etc/keepalived/keepalived.conf'.
Jan 21 21:33:36 mx2 Keepalived_vrrp[1595]: vmac: Success creating VMAC interface vrrp.6 for vrrp_instance mx.vlan103
Jan 21 21:33:36 mx2 Keepalived_vrrp[1595]: Unable to read sysctl net.ipv4.conf.all.rp_filter
Jan 21 21:33:36 mx2 Keepalived_vrrp[1595]: vmac: Success creating VMAC interface vrrp.7 for vrrp_instance mx.vlan212
Jan 21 21:33:36 mx2 Keepalived_vrrp[1595]: Unable to read sysctl net.ipv4.conf.all.rp_filter
Jan 21 21:33:36 mx2 Keepalived_vrrp[1595]: Using LinkWatch kernel netlink reflector...
Jan 21 21:33:36 mx2 Keepalived_vrrp[1595]: VRRP_Instance(mx.vlan103) Entering BACKUP STATE
Jan 21 21:33:36 mx2 Keepalived_vrrp[1595]: VRRP_Instance(mx.vlan212) Entering BACKUP STATE
Jan 21 21:33:36 mx2 Keepalived_vrrp[1595]: VRRP sockpool: [ifindex(5), proto(112), unicast(0), fd(10,11)]

[root@mx2 ~]# uname -a
Linux mx2 4.14.13-300.fc27.x86_64 #1 SMP Thu Jan 11 04:00:01 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

[root@mx2 ~]# sestatus
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: permissive
Mode from config file: permissive
Policy MLS status: enabled
Policy deny_unknown status: allowed
Memory protection checking: actual (secure)
Max kernel policy version: 31

[root@mx2 ~]# cat /proc/sys/net/ipv4/conf/all/rp_filter
0
[root@mx2 ~]# echo 1 > /proc/sys/net/ipv4/conf/all/rp_filter

[root@mx2 ~]# cat /proc/sys/net/ipv4/conf/all/rp_filter
1
[root@mx2 ~]# echo 0 > /proc/sys/net/ipv4/conf/all/rp_filter

[root@mx2 ~]# cat /proc/sys/net/ipv4/conf/all/rp_filter
0

@stfast
Copy link
Author

stfast commented Jan 23, 2018

Case solved. I had to re-enabled SELinux to repair security contexts during (re)boot.

Jan 23 13:09:30 mx2 Keepalived[1580]: Starting Keepalived v1.3.9 (10/21,2017)
Jan 23 13:09:30 mx2 Keepalived[1580]: Opening file '/etc/keepalived/keepalived.conf'.
Jan 23 13:09:30 mx2 Keepalived[1585]: Starting Healthcheck child process, pid=1586
Jan 23 13:09:30 mx2 Keepalived[1585]: Starting VRRP child process, pid=1587
Jan 23 13:09:30 mx2 Keepalived_healthcheckers[1586]: Opening file '/etc/keepalived/keepalived.conf'.
Jan 23 13:09:30 mx2 Keepalived_vrrp[1587]: Registering Kernel netlink reflector
Jan 23 13:09:30 mx2 Keepalived_vrrp[1587]: Registering Kernel netlink command channel
Jan 23 13:09:30 mx2 Keepalived_vrrp[1587]: Registering gratuitous ARP shared channel
Jan 23 13:09:30 mx2 Keepalived_vrrp[1587]: Opening file '/etc/keepalived/keepalived.conf'.
Jan 23 13:09:30 mx2 Keepalived_vrrp[1587]: vmac: Success creating VMAC interface vrrp.6 for vrrp_instance mx.vlan103
Jan 23 13:09:30 mx2 Keepalived_vrrp[1587]: NOTICE: setting sysctl net.ipv4.conf.all.rp_filter from 1 to 0
Jan 23 13:09:30 mx2 Keepalived_vrrp[1587]: vmac: Success creating VMAC interface vrrp.7 for vrrp_instance mx.vlan212
Jan 23 13:09:30 mx2 Keepalived_vrrp[1587]: Using LinkWatch kernel netlink reflector...

@stfast
Copy link
Author

stfast commented Jan 23, 2018

Somehow there should be Keepalived SELinux rules to allow reading and writeing /proc/sys/* settings with SELinux enabled.

Jan 23 13:09:30 mx2 Keepalived_vrrp[1587]: Opening file '/etc/keepalived/keepalived.conf'.
Jan 23 13:09:30 mx2 kernel: audit: type=1130 audit(1516709370.190:147): pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='unit=keepalived comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=success'
Jan 23 13:09:30 mx2 audit[1]: SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:init_t:s0 msg='unit=keepalived comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=success'
Jan 23 13:09:30 mx2 kernel: audit: type=1400 audit(1516709370.370:151): avc: denied { read } for pid=1587 comm="keepalived" name="rp_filter" dev="proc" ino=11514 scontext=system_u:system_r:keepalived_t:s0 tcontext=system_u:object_r:sysctl_net_t:s0 tclass=file permissive=1
Jan 23 13:09:30 mx2 kernel: audit: type=1400 audit(1516709370.370:151): avc: denied { open } for pid=1587 comm="keepalived" path="/proc/sys/net/ipv4/conf/all/rp_filter" dev="proc" ino=11514 scontext=system_u:system_r:keepalived_t:s0 tcontext=system_u:object_r:sysctl_net_t:s0 tclass=file permissive=1
Jan 23 13:09:30 mx2 kernel: audit: type=1300 audit(1516709370.370:151): arch=c000003e syscall=257 success=yes exit=10 a0=ffffffffffffff9c a1=55bb78884720 a2=0 a3=0 items=0 ppid=1585 pid=1587 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="keepalived" exe="/usr/sbin/keepalived" subj=system_u:system_r:keepalived_t:s0 key=(null)
Jan 23 13:09:30 mx2 audit[1587]: AVC avc: denied { read } for pid=1587 comm="keepalived" name="rp_filter" dev="proc" ino=11514 scontext=system_u:system_r:keepalived_t:s0 tcontext=system_u:object_r:sysctl_net_t:s0 tclass=file permissive=1
Jan 23 13:09:30 mx2 audit[1587]: AVC avc: denied { open } for pid=1587 comm="keepalived" path="/proc/sys/net/ipv4/conf/all/rp_filter" dev="proc" ino=11514 scontext=system_u:system_r:keepalived_t:s0 tcontext=system_u:object_r:sysctl_net_t:s0 tclass=file permissive=1
Jan 23 13:09:30 mx2 audit[1587]: SYSCALL arch=c000003e syscall=257 success=yes exit=10 a0=ffffffffffffff9c a1=55bb78884720 a2=0 a3=0 items=0 ppid=1585 pid=1587 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="keepalived" exe="/usr/sbin/keepalived" subj=system_u:system_r:keepalived_t:s0 key=(null)
Jan 23 13:09:30 mx2 audit[1587]: AVC avc: denied { write } for pid=1587 comm="keepalived" name="rp_filter" dev="proc" ino=11516 scontext=system_u:system_r:keepalived_t:s0 tcontext=system_u:object_r:sysctl_net_t:s0 tclass=file permissive=1
Jan 23 13:09:30 mx2 audit[1587]: SYSCALL arch=c000003e syscall=257 success=yes exit=10 a0=ffffffffffffff9c a1=55bb78884720 a2=1 a3=0 items=0 ppid=1585 pid=1587 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=4294967295 comm="keepalived" exe="/usr/sbin/keepalived" subj=system_u:system_r:keepalived_t:s0 key=(null)

@pqarmitage
Copy link
Collaborator

OK, that's good from the keepalived perspective, since this is an SELinux issue on mx2.

Am I correct in understanding that you have the problems on both mx1 and mx2, or am I getting muddled (I had previously understood that mx1 was OK but mx2 was not). It appears that some of the testing has been done on mx1 and some on mx2, which is certainly causing me some confusion.

I know that Fedora/RedHat have had to update their SELinux policy to allow keepalived to access various files. What distro's SELinux policy are you using in your VMs?

@pqarmitage
Copy link
Collaborator

Closing due to problem solved and no update for over 3 weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants