-
Notifications
You must be signed in to change notification settings - Fork 77
Audit log in successful connection cases #1280
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f55be57
Log in successful connection cases
ryanwixon-emerson 6073f3b
Match source name from installer
ryanwixon-emerson c85a85b
Improve log message formatting and ditch set approach
ryanwixon-emerson e33fe95
Update README to document registry key requirement
ryanwixon-emerson 1d2ce26
Review fixes
ryanwixon-emerson 635f5d7
Fix typo in README
ryanwixon-emerson 422f414
More review fixes (needs test)
ryanwixon-emerson cf4fd28
Documentation update for review
ryanwixon-emerson 09ab168
More review fixes
ryanwixon-emerson 72534c7
Implement cache eviction mechanism
ryanwixon-emerson 1f7b22f
Fix unit test
ryanwixon-emerson fe9aad6
Retrigger CI
ryanwixon-emerson b61831e
Retrigger CI
ryanwixon-emerson 821e32c
Retrigger CI again? Tests fail with a different error every time
ryanwixon-emerson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| #include "client_connection_logger.h" | ||
|
|
||
| #include "logging.h" | ||
|
|
||
| namespace nidevice_grpc { | ||
|
|
||
| namespace { | ||
|
|
||
| bool parse_peer(const std::string& peer, std::string& ip, std::string& port) | ||
|
ryanwixon-emerson marked this conversation as resolved.
|
||
| { | ||
| if (peer.rfind("ipv4:", 0) != 0 && peer.rfind("ipv6:", 0) != 0) | ||
| return false; | ||
|
|
||
| const auto scheme_end = peer.find(':'); | ||
| const auto port_pos = peer.rfind(':'); | ||
|
ryanwixon-emerson marked this conversation as resolved.
Outdated
|
||
| if (port_pos <= scheme_end) | ||
| return false; | ||
|
|
||
| ip = peer.substr(scheme_end + 1, port_pos - scheme_end - 1); | ||
| port = peer.substr(port_pos + 1); | ||
|
|
||
| // Strip ipv6 brackets, e.g. "[::1]" -> "::1". | ||
| if (ip.size() >= 2 && ip.front() == '[' && ip.back() == ']') | ||
| ip = ip.substr(1, ip.size() - 2); | ||
|
|
||
| return !ip.empty() && !port.empty(); | ||
|
ryanwixon-emerson marked this conversation as resolved.
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| void ClientConnectionLogger::PreSynchronousRequest(grpc::ServerContext* context) | ||
|
ryanwixon-emerson marked this conversation as resolved.
ryanwixon-emerson marked this conversation as resolved.
|
||
| { | ||
| const auto peer = context->peer(); | ||
| std::string ip, port; | ||
|
|
||
| // Try to parse the IP + Port out of the peer uri so that the log message can be formatted nicely. If it fails, just log the raw string. | ||
|
ryanwixon-emerson marked this conversation as resolved.
|
||
| if (parse_peer(peer, ip, port)) | ||
| nidevice_grpc::logging::log_to_audit_source(nidevice_grpc::logging::Level_Info, "Remote client successfully connected from %s:%s", ip.c_str(), port.c_str()); | ||
| else | ||
| nidevice_grpc::logging::log_to_audit_source(nidevice_grpc::logging::Level_Info, "Remote client successfully connected from %s", peer.c_str()); | ||
| } | ||
|
|
||
| void ClientConnectionLogger::PostSynchronousRequest(grpc::ServerContext*) | ||
| { | ||
| } | ||
|
|
||
| void register_client_connection_logger() | ||
| { | ||
| // gRPC does not take ownership of the callbacks object, so it will be a static object. | ||
|
ryanwixon-emerson marked this conversation as resolved.
Outdated
|
||
| static ClientConnectionLogger logger; | ||
| grpc::Server::SetGlobalCallbacks(&logger); | ||
| } | ||
|
|
||
| } // namespace nidevice_grpc | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #ifndef NIDEVICE_GRPC_CLIENT_CONNECTION_LOGGER_H | ||
| #define NIDEVICE_GRPC_CLIENT_CONNECTION_LOGGER_H | ||
|
|
||
| #include <grpcpp/grpcpp.h> | ||
|
|
||
| #include <string> | ||
|
|
||
| namespace nidevice_grpc { | ||
|
|
||
| // Implementation of callbacks that the grpc::Server will invoke for individual client RPC calls. | ||
| class ClientConnectionLogger : public grpc::Server::GlobalCallbacks { | ||
| public: | ||
| void PreSynchronousRequest(grpc::ServerContext* context) override; | ||
| void PostSynchronousRequest(grpc::ServerContext* context) override; | ||
| }; | ||
|
|
||
| // Registers a process-wide ClientConnectionLogger with gRPC, must be called before any grpc::Server is built. | ||
| void register_client_connection_logger(); | ||
|
|
||
| } // namespace nidevice_grpc | ||
|
|
||
| #endif // NIDEVICE_GRPC_CLIENT_CONNECTION_LOGGER_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.