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

Cannot trust or retire a retired node #797

Merged
merged 2 commits into from
Feb 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/node/rpc/memberfrontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,14 @@ namespace ccf
auto nodes = tx.get_view(this->network.nodes);
auto info = nodes->get(id);
if (!info)
{
throw std::logic_error(fmt::format("Node {} does not exist", id));
}
if (info->status == NodeStatus::RETIRED)
{
throw std::logic_error(
fmt::format("Node {} is already retired", id));
}
info->status = NodeStatus::TRUSTED;
nodes->put(id, *info);
LOG_INFO_FMT("Node {} is now {}", id, info->status);
Expand All @@ -154,9 +161,17 @@ namespace ccf
auto nodes = tx.get_view(this->network.nodes);
auto info = nodes->get(id);
if (!info)
{
throw std::logic_error(fmt::format("Node {} does not exist", id));
}
if (info->status == NodeStatus::RETIRED)
{
throw std::logic_error(
fmt::format("Node {} is already retired", id));
}
info->status = NodeStatus::RETIRED;
nodes->put(id, *info);
LOG_INFO_FMT("Node {} is now {}", id, info->status);
return true;
}},
// accept new code
Expand Down
64 changes: 64 additions & 0 deletions src/node/rpc/test/membervoting_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,70 @@ TEST_CASE("Accept node")
frontend_process(frontend, read_values_j, member_0_cert);
CHECK(r.result.status == NodeStatus::TRUSTED);
}

// m0 proposes retire node
{
Script proposal(R"xxx(
local tables, node_id = ...
return Calls:call("retire_node", node_id)
)xxx");
json proposej = create_json_req(Propose::In{proposal, node_id}, "propose");
Response<Propose::Out> r =
frontend_process(frontend, proposej, member_0_cert);

CHECK(!r.result.completed);
CHECK(r.result.id == 1);
}

// m1 votes for retiring node
{
const Script vote_ballot("return true");
json votej = create_json_req_signed(Vote{1, vote_ballot}, "vote", kp);
check_success(frontend_process(frontend, votej, member_1_cert));
}

// check that node exists with status retired
{
auto read_values_j =
create_json_req(read_params<int>(node_id, Tables::NODES), "read");
Response<NodeInfo> r =
frontend_process(frontend, read_values_j, member_0_cert);
CHECK(r.result.status == NodeStatus::RETIRED);
}

// check that retired node cannot be trusted
{
Script proposal(R"xxx(
local tables, node_id = ...
return Calls:call("trust_node", node_id)
)xxx");
json proposej = create_json_req(Propose::In{proposal, node_id}, "propose");
Response<Propose::Out> r =
frontend_process(frontend, proposej, member_0_cert);

const Script vote_ballot("return true");
json votej = create_json_req_signed(Vote{2, vote_ballot}, "vote", kp);
check_error(
frontend_process(frontend, votej, member_1_cert),
StandardErrorCodes::INTERNAL_ERROR);
}

// check that retired node cannot be retired again
{
Script proposal(R"xxx(
local tables, node_id = ...
return Calls:call("retire_node", node_id)
)xxx");
json proposej = create_json_req(Propose::In{proposal, node_id}, "propose");
Response<Propose::Out> r =
frontend_process(frontend, proposej, member_0_cert);

const Script vote_ballot("return true");
json votej = create_json_req_signed(Vote{3, vote_ballot}, "vote", kp);
check_error(
frontend_process(frontend, votej, member_1_cert),
StandardErrorCodes::INTERNAL_ERROR);
}
}

bool test_raw_writes(
Expand Down
1 change: 0 additions & 1 deletion src/runtime_config/default_whitelists.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ namespace ccf
Tables::MEMBER_CERTS,
Copy link
Member

Choose a reason for hiding this comment

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

Members should have access to the nodes table via lua, same as they do to the members table, etc. If they want to change the way that the nodes are handled they should be able to propose and vote for that.

Copy link
Member

Choose a reason for hiding this comment

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

The join protocol is implemented in C++ though, and we do want to enforce a particular set of conditions and transitions for nodes to preserve security guarantees. What's the use case for opening this up completely?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Raised #806

Tables::USERS,
Tables::USER_CERTS,
Tables::NODES,
Tables::VALUES,
Tables::WHITELISTS,
Tables::GOV_SCRIPTS,
Expand Down