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

Issue #844 Add host information to log messages #45

Closed
wants to merge 13 commits into from

Conversation

jmjatlanta
Copy link

@jmjatlanta jmjatlanta commented May 11, 2018

Issue bitshares/bitshares-core#844. Adding host information to the rpc log.
Related: bitshares/bitshares-core#802

This adds the host to the log message. I don't particularly care for the output style, but I didn't want to declare a variable just for a log message. Perhaps I should use a lower level function than wdump(). What do you think?

Copy link
Member

@abitmore abitmore left a comment

Choose a reason for hiding this comment

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

Good. I'd suggest that output host info first, then payload (swap the positions).

@abitmore
Copy link
Member

By the way, I guess the real host info won't be available when the API node is running behind a reverse proxy. Unfortunately most of API nodes in production are running this way.

@pmconrad
Copy link

Hm, could use the x-forwarded-for header in this case. But need a flag if that header should be trusted.

@jmjatlanta
Copy link
Author

jmjatlanta commented May 21, 2018

But need a flag if that header should be trusted.

  1. So, use x-forwarded-for if it exists, if not, use the host?
    a. Or a command line or logging switch that tells us which to use?
  2. What should we do if it is not "trusted"?
  3. How do we know if it should be trusted?
    a. The user tells us "Don't trust x-forwarded-for"?
    b. Something else in the header indicates it shouldn't be trusted?

@abitmore
Copy link
Member

About trust: basically, if you're running nodes behind reverse proxies, the proxies are trustworthy for the nodes. So the proxy should add "x-forwarded-for" header according whatever standard and the nodes extract real addresses of clients. But there would be multiple or nested/chained "x-forwarded-for" header if the original request has that header already, in this case the node need to know which one is added by the reverse proxy, and likely don't want to trust the address in the original header. From this post, it's good practice to use a self-defined header, so I think

  • we need a configurable HTTP header name (but not a hard-coded x-Forwarded-For or whatever else) for both nodes and reverse proxies,
    • the reverse proxies will add clients' real addresses with this header,
    • the nodes will extract the address when this header presents, use the host address when the header doesn't present.

@abitmore
Copy link
Member

Need to take care of the new logging added by #62.

@pmconrad
Copy link

@jmjatlanta please address the remaining comments so we can merge

@@ -173,6 +154,14 @@ namespace fc { namespace http {
return _ws_connection->get_request_header(key);
}

virtual std::string get_host()override
Copy link
Author

Choose a reason for hiding this comment

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

Please take a look at what I am doing here. I am attempting to get a "custom" header to help with the log message. This is untested code, but I would like some input to (in)validate my approach.

@jmjatlanta
Copy link
Author

@abitmore please see https://github.com/bitshares/bitshares-fc/pull/45/files#r244624285 and let me know what you think. Thanks.

@jmjatlanta jmjatlanta force-pushed the jmj_issue_844 branch 2 times, most recently from 74e9f6a to c3941d8 Compare January 15, 2019 17:07
@abitmore
Copy link
Member

abitmore commented Feb 4, 2019

@jmjatlanta sorry I don't have enough time to review this. Wish others could help.

virtual std::string get_host()override
{
auto header = get_request_header("BS-Forwarded");
if (header.length() > 2)

Choose a reason for hiding this comment

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

why 2?

Copy link
Author

Choose a reason for hiding this comment

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

Because I love magic numbers. Perhaps you don't like 2, so I replaced it with 3. (actually replaced with !string::empty() )

auto header = get_request_header("BS-Forwarded");
if (header.length() > 2)
return header;
return _ws_connection->get_host();

Choose a reason for hiding this comment

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

I think get_host is wrong, according to the docs it returns the host component of the requested URI, not the remote host.

Copy link
Author

@jmjatlanta jmjatlanta Apr 24, 2019

Choose a reason for hiding this comment

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

I will investigate. Please do not bother reviewing until I edit this comment.

@@ -173,6 +154,14 @@ namespace fc { namespace http {
return _ws_connection->get_request_header(key);
}

virtual std::string get_host()override
{
auto header = get_request_header("BS-Forwarded");

Choose a reason for hiding this comment

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

Header name should be configurable like @abitmore said, and absence of configured value means ignore all headers and use remote host of connection.

Copy link
Author

Choose a reason for hiding this comment

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

Implemented a configurable header. Will need to adjust in bitshares-core to make use of it.

@pmconrad
Copy link

Replaced by #134

@pmconrad pmconrad closed this May 28, 2019
@abitmore abitmore deleted the jmj_issue_844 branch May 28, 2019 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants