Skip to content

Commit 25c75ce

Browse files
committed
MB-49376: Alternative external service address validation
Specifically, if you attempt to set an external alternative address for a service that does not exist on a provisioned node, this is now disallowed. We will continue to allow setting these values on non-provisioned nodes, but after initialization, only the services for which the node actually has are returned (this is how it works now). Change-Id: I6c35c6dff71338fb75226a17eae1d0190f3f214d Reviewed-on: https://review.couchbase.org/c/ns_server/+/165419 Tested-by: Bryan McCoid <[email protected]> Reviewed-by: Steve Watanabe <[email protected]>
1 parent adec9fb commit 25c75ce

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

src/menelaus_web_node.erl

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -957,15 +957,6 @@ validate_settings_paths(Paths) ->
957957

958958
ResPaths.
959959

960-
%% Basic port validation is done.
961-
%% The below port validations are not performed.
962-
%% - Verify if all ports being setup for "external" have their particular
963-
%% service enabled on the node.
964-
%% - Verify if no two hostname:port pair are the same in a cluster.
965-
%% Reasoning behind not performing above validations is that the node can have
966-
%% "external" addresses configured before it has been added to the cluster, or
967-
%% it's services configured. Therefore, we keep port validation simple and trust
968-
%% the admin to setup "external" addresses correctly for the clients.
969960
parse_validate_ports(Params) ->
970961
lists:foldl(
971962
fun ({RestName, Value}, Acc) ->
@@ -1004,18 +995,44 @@ parse_validate_hostname(Hostname) ->
1004995
[?MAX_HOSTNAME_LENGTH]))
1005996
end.
1006997

998+
%% The below port validations are performed:
999+
%% - Provisioned: Verify if all ports being setup for "external" have their
1000+
%% particular service enabled on the node.
1001+
%% - Not Provisioned: If the node is not provisioned we allow modifying the
1002+
%% external ports for any service, because we don't know which ones will
1003+
%% eventually be selected.
10071004
parse_validate_external_params(Params) ->
10081005
Hostname = parse_validate_hostname(proplists:get_value("hostname", Params)),
10091006
Ports = parse_validate_ports(proplists:delete("hostname", Params)),
1010-
[{external, [{hostname, Hostname}, {ports, Ports}]}].
1007+
Config = ns_config:get(),
1008+
ValidResponse = [{external, [{hostname, Hostname}, {ports, Ports}]}],
1009+
case ns_config_auth:is_system_provisioned(Config) of
1010+
true ->
1011+
case lists:all(
1012+
lists:member(
1013+
_, service_ports:services_port_keys(
1014+
ns_cluster_membership:node_active_services(
1015+
Config, node()))), [V || {V, _} <- Ports]) of
1016+
true ->
1017+
ValidResponse;
1018+
false ->
1019+
{error, <<"Cannot set services unavailable on the node">>}
1020+
end;
1021+
false ->
1022+
ValidResponse
1023+
end.
10111024

10121025
%% This replaces any existing alternate_addresses config of this node.
10131026
%% For now this is fine because external is only element in alternate_addresses.
10141027
handle_node_altaddr_external(Req) ->
10151028
Params = mochiweb_request:parse_post(Req),
1016-
External = parse_validate_external_params(Params),
1017-
ns_config:set({node, node(), alternate_addresses}, External),
1018-
menelaus_util:reply(Req, 200).
1029+
case parse_validate_external_params(Params) of
1030+
{error, M} ->
1031+
menelaus_util:reply_text(Req, M, 400);
1032+
External ->
1033+
ns_config:set({node, node(), alternate_addresses}, External),
1034+
menelaus_util:reply(Req, 200)
1035+
end.
10191036

10201037
%% Delete alternate_addresses as external is the only element in
10211038
%% alternate_addresses.

0 commit comments

Comments
 (0)