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

feat(userspace/outputs_http): Add option for mTLS #2633

Merged
merged 1 commit into from Aug 29, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions falco.yaml
Expand Up @@ -359,6 +359,12 @@ http_output:
# Path to a folder that will be used as the CA certificate store. CA certificate need to be
# stored as indivitual PEM files in this directory.
ca_path: "/etc/ssl/certs"
# Tell Falco to use mTLS
mtls: false
# Path to the client cert.
client_cert: "/etc/ssl/certs/client.crt"
# Path to the client key.
client_key: "/etc/ssl/certs/client.key"

# [Stable] `program_output`
#
Expand Down
14 changes: 13 additions & 1 deletion userspace/falco/configuration.cpp
Expand Up @@ -194,7 +194,7 @@ void falco_configuration::load_yaml(const std::string& config_name, const yaml_h
bool insecure;
insecure = config.get_scalar<bool>("http_output.insecure", false);
http_output.options["insecure"] = insecure? std::string("true") : std::string("false");

std::string ca_cert;
ca_cert = config.get_scalar<std::string>("http_output.ca_cert", "");
http_output.options["ca_cert"] = ca_cert;
Expand All @@ -207,6 +207,18 @@ void falco_configuration::load_yaml(const std::string& config_name, const yaml_h
ca_path = config.get_scalar<std::string>("http_output.ca_path", "/etc/ssl/certs");
http_output.options["ca_path"] = ca_path;

bool mtls;
mtls = config.get_scalar<bool>("http_output.mtls", false);
http_output.options["mtls"] = mtls? std::string("true") : std::string("false");

std::string client_cert;
client_cert = config.get_scalar<std::string>("http_output.client_cert", "/etc/ssl/certs/client.crt");
http_output.options["client_cert"] = client_cert;

std::string client_key;
client_key = config.get_scalar<std::string>("http_output.client_key", "/etc/ssl/certs/client.key");
http_output.options["client_key"] = client_key;

m_outputs.push_back(http_output);
}

Expand Down
17 changes: 15 additions & 2 deletions userspace/falco/outputs_http.cpp
Expand Up @@ -62,14 +62,14 @@ void falco::outputs::output_http::output(const message *msg)

if(res == CURLE_OK)
{
res = curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, -1L);
res = curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, -1L);
}

if(res == CURLE_OK)
{
if(m_oc.options["insecure"] == std::string("true"))
{
res = curl_easy_setopt(curl,CURLOPT_SSL_VERIFYPEER, 0L);
res = curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);

if(res == CURLE_OK)
{
Expand All @@ -78,6 +78,19 @@ void falco::outputs::output_http::output(const message *msg)
}
}

if(res == CURLE_OK)
{
if(m_oc.options["mtls"] == std::string("true"))
{
res = curl_easy_setopt(curl, CURLOPT_SSLCERT, m_oc.options["client_cert"].c_str());

if(res == CURLE_OK)
{
res = curl_easy_setopt(curl, CURLOPT_SSLKEY, m_oc.options["client_key"].c_str());
}
}
}

if(res == CURLE_OK)
{
if (!m_oc.options["ca_cert"].empty())
Expand Down