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

ext_authz: Check for cluster before sending HTTP request #8144

Merged
merged 5 commits into from
Sep 10, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
17 changes: 14 additions & 3 deletions source/extensions/filters/common/ext_authz/ext_authz_http_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,20 @@ void RawHttpClientImpl::check(RequestCallbacks& callbacks,
std::make_unique<Buffer::OwnedImpl>(request.attributes().request().http().body());
}

request_ = cm_.httpAsyncClientForCluster(config_->cluster())
.send(std::move(message), *this,
Http::AsyncClient::RequestOptions().setTimeout(config_->timeout()));
const std::string& cluster = config_->cluster();

// It's possible that the cluster specified in the filter configuration no longer exists due to a
// CDS removal.
if (!cm_.get(cluster)) {
dio marked this conversation as resolved.
Show resolved Hide resolved
// TODO(dio): Add stats related to this.
ENVOY_LOG(debug, "ext_authz cluster '{}' does not exist", cluster);
dio marked this conversation as resolved.
Show resolved Hide resolved
callbacks_->onComplete(std::make_unique<Response>(errorResponse()));
callbacks_ = nullptr;
} else {
request_ = cm_.httpAsyncClientForCluster(cluster).send(
std::move(message), *this,
Http::AsyncClient::RequestOptions().setTimeout(config_->timeout()));
}
}

void RawHttpClientImpl::onSuccess(Http::MessagePtr&& message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

using testing::_;
using testing::AllOf;
using testing::Eq;
using testing::InSequence;
using testing::Invoke;
using testing::Ref;
using testing::Return;
Expand Down Expand Up @@ -377,6 +379,17 @@ TEST_F(ExtAuthzHttpClientTest, CancelledAuthorizationRequest) {
client_.cancel();
}

TEST_F(ExtAuthzHttpClientTest, NoCluster) {
dio marked this conversation as resolved.
Show resolved Hide resolved
InSequence s;

EXPECT_CALL(cm_, get(Eq("ext_authz"))).WillOnce(Return(nullptr));
EXPECT_CALL(cm_, httpAsyncClientForCluster("ext_authz")).Times(0);
EXPECT_CALL(request_callbacks_,
onComplete_(WhenDynamicCastTo<ResponsePtr&>(AuthzErrorResponse(CheckStatus::Error))));
client_.check(request_callbacks_, envoy::service::auth::v2::CheckRequest{},
Tracing::NullSpan::instance());
}

} // namespace
} // namespace ExtAuthz
} // namespace Common
Expand Down