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

keepalived vip (vrrp) requires 224.0.0.18/32 #11327

Merged
merged 1 commit into from
Oct 21, 2016

Conversation

pecameron
Copy link
Contributor

@pecameron pecameron commented Oct 11, 2016

Modified the ipf pod startup to check for iptables rule to allow 224.0.0.18 and if missing add it. By default the rule is added to the head of the INPUT chain. This can be overridden by OPENSHIFT_HA_IPTABLES_CHAIN environment variable in the ipf dc.

Existing deployments do not have OPENSHIFT_HA_IPTABLES_CHAIN and no changes will
be made to the iptables. It is assumed that they are configured
properly. New deployments will have OPENSHIFT_HA_IPTABLES_CHAIN and as long as it
is not empty ("") the rule for 224.0.0.18 will be inserted if not
present.

Added --iptables-chain="" option to oadm ipfailover command to pass
the desired iptables chain. Default is INPUT. When string is ""
no changes are made to iptables.

When keepalived traffic over 224.0.0.18 is blocked multiple nodes
will report as master. This change checks for an iptables rule and
adds it if missing.

Resolves: 1381632
See: openshift/openshift-docs PR 3051

Signed-off-by: Phil Cameron pcameron@redhat.com

@pecameron
Copy link
Contributor Author

@knobunc @rajatchopra @ramr - this change makes the ipf pod create a rule for 224.0.0.18 if none exists.
PTAL

@@ -46,6 +46,14 @@ function setup_failover() {
echo "ERROR: Module ip_vs is NOT available."
fi

echo " - Check for iptables rule for keepalived multicast (224.0.0.18) ..."
iptables -S | grep 224.0.0.18 > /dev/null
if [ $? -eq 1 ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer explicit result check:

if ! iptables -S | grep -q "224.0.0.18"; then

Copy link
Contributor

@ramr ramr Oct 11, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be better to explicitly check if there is an input rule matching that multicast address - iptables has a
check option with -C and change as @stevekuznetsov mentioned. Something like:

if ! iptables -C INPUT -d 224.0.0.18/32 -j ACCEPT > /dev/null ; then  
   ...  
   iptables -I INPUT 1 -d 224.0.0.18/32 -j ACCEPT > /dev/null
fi  

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made Steve's change. Ram, I have found the reference in OS_FIREWALL_ALLOW as well.That is why I just look for the address. Also, an admin can put the rule anywhere it will work.

@pecameron
Copy link
Contributor Author

@stevekuznetsov @ramr @rajatchopra @knobunc I made Steve's change. PTAL

Copy link
Contributor

@knobunc knobunc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also want to see this documented so we don't surprise people.

@@ -46,6 +46,13 @@ function setup_failover() {
echo "ERROR: Module ip_vs is NOT available."
fi

echo " - Check for iptables rule for keepalived multicast (224.0.0.18) ..."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please make this behavior configurable by an ENV? Default it to enabled.

if ! iptables -S | grep 224.0.0.18 > /dev/null ; then
# Add the rule to the beginning of the INPUT chain.
echo " - adding iptables rule to access 224.0.0.18."
iptables -I INPUT 1 -d 224.0.0.18/32 -j ACCEPT > /dev/null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make the chain ENV configurable. Default to INPUT.

@pecameron pecameron force-pushed the bz1381632 branch 2 times, most recently from 773f68a to 3ee8514 Compare October 12, 2016 19:32
@pecameron
Copy link
Contributor Author

@openshift/team-atomicopenshift PTAL

This version makes sure an iptables rule to pass 224.0.0.18 exists. If not a rule is added to the head of chain $OPENSHIFT_HA_CHAIN, if present otherwise chain INPUT.

@pecameron
Copy link
Contributor Author

@stevekuznetsov @knobunc I have made your recommended changes PTAL
How are the change requests resolved?

Copy link
Contributor

@knobunc knobunc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That change looks good. But the other change hasn't been fulfilled... I want a way not to mess with people's chains.

@pecameron
Copy link
Contributor Author

@knobunc I am confused. The new OPENSHIFT_HA_CHAIN variable allows the desired chain to be set in the ipf's dc. What would you like to change?

@pecameron
Copy link
Contributor Author

@knobunc click the "View changes" button at the end of the red x line

@knobunc
Copy link
Contributor

knobunc commented Oct 12, 2016

@pecameron I want a second knob that I can set to tell the ipfailover not to touch iptables at all.

@pecameron
Copy link
Contributor Author

@knobunc I made the change to not alter existing deployments on upgrade. PTAL

@stevekuznetsov
Copy link
Contributor

Looks like this was closed accidentally.

Copy link
Contributor

@knobunc knobunc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. @ramr PTAL

@pecameron
Copy link
Contributor Author

@stevekuznetsov It was closed by accident. You still have a requested change. PTAL

@knobunc there needs to be a doc change for this. I will write it up and get a doc PR going. Do we need a different bug number?

@stevekuznetsov
Copy link
Contributor

I like @ramr idea of a more explicit iptables probe rather than a grep for some address - why do you prefer the grep?

@knobunc
Copy link
Contributor

knobunc commented Oct 13, 2016

@stevekuznetsov I'd argue for the grep because we want to do this by default (for new ipfailover setups), and the user may have already created a rule in iptables to handle it. Since we don't know how the chains are laid out, it could be in a different chain that they jump to (e.g. OS_FIREWALL_ALLOW). However, I see your argument for a more robust check now that we allow specification of a chain, and allow the feature to be disabled. So I could be swayed. Thoughts?

@stevekuznetsov
Copy link
Contributor

I'm always in favor of more restrictive checks, but if we can't control the iptables rules and want to handle the cases where users have custom setups, we can't make the more restrictive check. grep sounds fine to me in that case.

@pecameron
Copy link
Contributor Author

@knobunc @stevekuznetsov @ramr After speaking with Ben we decided to add a new option, --iptables-chain to the oadm ipfailover command. I updated the (origin based) docs and tests as well. PTAL
I am updating the openshift-docs files as well and will add the PR here when it is available.

# (OPENSHIFT_HA_IPTABLES_CHAIN) make sure the rule to pass keepalived
# multicast (224.0.0.18) is in the table.
chain="${OPENSHIFT_HA_IPTABLES_CHAIN:-""}"
if [ ! -z ${chain} ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless this needs POSIX compliance, prefer [[ over [. In ether case, use -n instead of ! -z.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made the changes

@@ -95,6 +95,7 @@ func NewCmdIPFailoverConfig(f *clientcmd.Factory, parentName, name string, out,
cmd.Flags().BoolVar(&options.Create, "create", options.Create, "Create the configuration if it does not exist.")

cmd.Flags().StringVar(&options.VirtualIPs, "virtual-ips", "", "A set of virtual IP ranges and/or addresses that the routers bind and serve on and provide IP failover capability for.")
cmd.Flags().StringVar(&options.IptablesChain, "iptables-chain", "INPUT", "Add a rule to this iptables chain to accept 224.0.0.28 multicast packets if no rule exists. When iptables-chain is empty donot change iptables.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something like:
"If specified and no matching iptables rules exist, adds a rule to this iptables chain that accepts packets sent to an multicast address 224.0.0.28. Defaults to using the iptables INPUT chain.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice wording.

@ramr
Copy link
Contributor

ramr commented Oct 13, 2016

Minor corrections but otherwise looks good to me

@knobunc
Copy link
Contributor

knobunc commented Oct 14, 2016

[test]

@knobunc
Copy link
Contributor

knobunc commented Oct 14, 2016

"FAILURE: Generated docs up to date, but generated man pages out of date. Please run hack/update-generated-docs.sh"

@pecameron
Copy link
Contributor Author

[test]

@marun
Copy link
Contributor

marun commented Oct 14, 2016

flake #11374 re-[test]

@knobunc
Copy link
Contributor

knobunc commented Oct 14, 2016

We need to re-merge this after @marun's fix for #11374 gets in.

@@ -71,6 +71,7 @@ os::cmd::expect_success_and_text 'oadm ipfailover --virtual-ips="1.2.3.4" --dry-
os::cmd::expect_success_and_text 'oadm ipfailover --virtual-ips="1.2.3.4" --dry-run -o yaml' 'name: ipfailover'
os::cmd::expect_success_and_text 'oadm ipfailover --virtual-ips="1.2.3.4" --dry-run -o name' 'deploymentconfig/ipfailover'
os::cmd::expect_success_and_text 'oadm ipfailover --virtual-ips="1.2.3.4" --dry-run -o yaml' '1.2.3.4'
os::cmd::expect_success_and_text 'oadm ipfailover --virtual-ips="1.2.3.4" --iptables-chain="MY_CHAIN"--dry-run -o yaml' 'value: MY_CHAIN'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a space here between MY_CHAIN" and --dry-run ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and if this current syntax doesn't fail this test we need to look into why.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dcbw - Yes it does. Good spot, thanks for looking at this.
I fixed it.

@@ -71,6 +71,7 @@ os::cmd::expect_success_and_text 'oadm ipfailover --virtual-ips="1.2.3.4" --dry-
os::cmd::expect_success_and_text 'oadm ipfailover --virtual-ips="1.2.3.4" --dry-run -o yaml' 'name: ipfailover'
os::cmd::expect_success_and_text 'oadm ipfailover --virtual-ips="1.2.3.4" --dry-run -o name' 'deploymentconfig/ipfailover'
os::cmd::expect_success_and_text 'oadm ipfailover --virtual-ips="1.2.3.4" --dry-run -o yaml' '1.2.3.4'
os::cmd::expect_success_and_text 'oadm ipfailover --virtual-ips="1.2.3.4" --iptables-chain="MY_CHAIN"--dry-run -o yaml' 'value: MY_CHAIN'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, and if this current syntax doesn't fail this test we need to look into why.

@pecameron
Copy link
Contributor Author

[test]

@knobunc
Copy link
Contributor

knobunc commented Oct 18, 2016

@stevekuznetsov PTAL.

@stevekuznetsov
Copy link
Contributor

@knobunc which part should I be looking at?

Copy link
Contributor

@stevekuznetsov stevekuznetsov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bash-isms LGTM, small questions about output suppression.

chain="${OPENSHIFT_HA_IPTABLES_CHAIN:-""}"
if [[ -n ${chain} ]]; then
echo " - check for iptables rule for keepalived multicast (224.0.0.18) ..."
if ! iptables -S | grep 224.0.0.18 > /dev/null ; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If something were to go wrong with this, you'll get stuff from stderr popping out -- maybe this is intended? If not, > /dev/null 2>&1.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can go either way with this. I'll make the change.

if ! iptables -S | grep 224.0.0.18 > /dev/null ; then
# Add the rule to the beginning of the chain.
echo " - adding iptables rule to $chain to access 224.0.0.18."
iptables -I ${chain} 1 -d 224.0.0.18/32 -j ACCEPT > /dev/null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we want to suppress the output of this command?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The echo above notes that we are doing it. I'll display the output (if any)

@knobunc
Copy link
Contributor

knobunc commented Oct 18, 2016

@stevekuznetsov just asking you to re-review and flip your NAK to an ACK if appropriate. Thanks!

Modified the ipf pod startup to check for iptables rule to allow 224.0.0.18
and if missing add it. By default the rule is added to the head of the
INPUT chain. This can be overridden by OPENSHIFT_HA_CHAIN environment
variable in the ipf dc.

Existing deployments do not have OPENSHIFT_HA_CHAIN and no changes will
be made to the iptables. It is assumed that they are configured
properly. New deployments will have OPENSHIFT_HA_CHAIN and as long as it
is not empty ("") the rule for 224.0.0.18 will be inserted if not
present.

Added --iptables-chain="" option to oadm ipfailover command to pass
the desired iptables chain. Default is INPUT. When string is ""
no changes are made to iptables.

When keepalived traffic over 224.0.0.18 is blocked multiple nodes
will report as master. This change checks for an iptables rule and
adds it if missing.

Documentation changes are in openshift-docs (PR ....)

Resolves: 1381632

Signed-off-by: Phil Cameron <pcameron@redhat.com>
@pecameron
Copy link
Contributor Author

@stevekuznetsov I made your suggested changes.

@openshift-bot
Copy link
Contributor

Evaluated for origin test up to b5d81e1

@stevekuznetsov
Copy link
Contributor

LGTM

@knobunc
Copy link
Contributor

knobunc commented Oct 18, 2016

LGTM [merge]

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test FAILURE (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/10206/) (Base Commit: a941850)

@knobunc
Copy link
Contributor

knobunc commented Oct 19, 2016

Flake #11442 [merge]

@pecameron
Copy link
Contributor Author

@knobunc you merged this yesterday and it seems to be stuck.

@stevekuznetsov
Copy link
Contributor

@pecameron as is written in the comment above, you are in the merge queue and will just have to wait your turn

@pecameron
Copy link
Contributor Author

@stevekuznetsov Thanks for the reply. I didn't know how long this should take and after 23 hours I thought it might be hung.

@openshift-bot
Copy link
Contributor

Evaluated for origin merge up to b5d81e1

@openshift-bot
Copy link
Contributor

openshift-bot commented Oct 21, 2016

continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/10373/) (Base Commit: 4a1aec0) (Image: devenv-rhel7_5212)

@openshift-bot openshift-bot merged commit f60c1df into openshift:master Oct 21, 2016
@pecameron pecameron deleted the bz1381632 branch October 21, 2016 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants