-
Notifications
You must be signed in to change notification settings - Fork 285
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
CP-40754 Update host.https_only field in dbsync based on firewall state #4811
CP-40754 Update host.https_only field in dbsync based on firewall state #4811
Conversation
ocaml/xapi/xapi_host.ml
Outdated
let network_state = | ||
Helpers.call_script !Xapi_globs.firewall_port_config_script [state; "80"] | ||
in | ||
Db.Host.set_https_only ~__context ~self ~value:(bool_of_string network_state) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change should not be done here, but in refresh_localhost_info
in dbsync_slave.ml, which is a function that runs when xapi starts up. At that point we want to query the state of the firewall and sync the DB.
scripts/plugins/firewall-port
Outdated
@@ -52,5 +52,13 @@ case "${OP}" in | |||
exit 1 | |||
;; | |||
esac | |||
|
|||
if [[ -z `iptables -S $CHAIN | grep " $PORT "` ]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This query should go as a new operation in the case statement above, e.g. check
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I put the query under each of the case statements?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, only under one new case. So the script will have three distinct ops: open, close, check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes more sense now, have since adjusted it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above
e341b42
to
54e271b
Compare
scripts/plugins/firewall-port
Outdated
if [[ -z `iptables -S $CHAIN | grep " $PORT "` ]] | ||
then | ||
echo true | ||
else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation needs a fix. Maybe this is part of the design, but I think a more descriptive output would be better unless the output is directly used somewhere else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the stdout feeds into OCaml where it is fed into bool_of_string. This tells Xapi what the state of https_only should be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would still use a more descriptive output and use sscanf
to parse it on the OCaml side. That is safer than using bool_of_string
anyway. Something like: port 80: open
which can be easily parsed.
scripts/plugins/firewall-port
Outdated
else | ||
echo false | ||
fi | ||
;; | ||
*) | ||
echo $"Usage: $0 {open|close} {port} {protocol}" 1>&2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs an update
f5f3602
to
89945a0
Compare
ocaml/xapi/dbsync_slave.ml
Outdated
(Scanf.bscanf | ||
(Scanf.Scanning.from_string network_state) | ||
"Port 80 open: %B" Fun.id | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scanf can fail with an exception. This needs to be caught and raised as internal error. Obviously we expect that the script returns the expected output. You might want to experiment with this in an OCaml shell like utop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ksscanf takes an additional parameter that is a handler in case the string cannot be parsed:
89945a0
to
b4cbdd4
Compare
…and false if it is closed, this is captured in set_https_only to update the DB based on the tate of the network not the requested setting should there be a failure Signed-off-by: jameshensmancitrix <james.hensman@citrix.com>
b4cbdd4
to
2e1385b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice improvements!
This looks good now. But please merge only after testing. |
Am currently testing, I will compare with both network states switched when Xapi is not running |
Testing complete, xapi correctly sets https_only on the host on the basis of the port after systemctl restart xapi |
The firewall-port script returns true if port 80 is blocked … and false if it is closed, this is captured in set_https_only to update the DB based on the state of the network, not the requested setting should there be a failure
Signed-off-by: jameshensmancitrix james.hensman@citrix.com