-
Notifications
You must be signed in to change notification settings - Fork 5.5k
admin: make admin HTML a compile-time option #21814
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 all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
535e0fc
make admin HTML a compile-time option
jmarantz 5c2907c
header order
jmarantz 88c6073
move AdminHtmlTest to its own file rather than using an ifdef.
jmarantz d0949e9
Remove ifdefs.
jmarantz 5e1b15e
remove -DENVOY_ADMIN_HTML -- was not using it.
jmarantz 1db59a8
backout change which is not needed
jmarantz 481b308
restore the -D because we need it for integration_admin_test.cc.
jmarantz 2aae197
format
jmarantz 7add81f
added release note and doc update for new compile-time option.#
jmarantz 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
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
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
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,122 @@ | ||
| #include "source/common/html/utility.h" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note to reviewers: this code is unchanged; just moved. |
||
| #include "source/server/admin/admin.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Server { | ||
|
|
||
| namespace { | ||
|
|
||
| /** | ||
| * Favicon base64 image was harvested by screen-capturing the favicon from a Chrome tab | ||
| * while visiting https://www.envoyproxy.io/. The resulting PNG was translated to base64 | ||
| * by dropping it into https://www.base64-image.de/ and then pasting the resulting string | ||
| * below. | ||
| * | ||
| * The actual favicon source for that, https://www.envoyproxy.io/img/favicon.ico is nicer | ||
| * because it's transparent, but is also 67646 bytes, which is annoying to inline. We could | ||
| * just reference that rather than inlining it, but then the favicon won't work when visiting | ||
| * the admin page from a network that can't see the internet. | ||
| */ | ||
| const char EnvoyFavicon[] = | ||
| "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1" | ||
| "BAACxjwv8YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAAH9SURBVEhL7ZRdTttAFIUrUFaAX5w9gIhgUfzshFRK+gIbaVbA" | ||
| "zwaqCly1dSpKk5A485/YCdXpHTB4BsdgVe0bD0cZ3Xsm38yZ8byTUuJ/6g3wqqoBrBhPTzmmLfptMbAzttJTpTKAF2MWC" | ||
| "7ADCdNIwXZpvMMwayiIwwS874CcOc9VuQPR1dBBChPMITpFXXU45hukIIH6kHhzVqkEYB8F5HYGvZ5B7EvwmHt9K/59Cr" | ||
| "U3QbY2RNYaQPYmJc+jPIBICNCcg20ZsAsCPfbcrFlRF+cJZpvXSJt9yMTxO/IAzJrCOfhJXiOgFEX/SbZmezTWxyNk4Q9" | ||
| "anHMmjnzAhEyhAW8LCE6wl26J7ZFHH1FMYQxh567weQBOO1AW8D7P/UXAQySq/QvL8Fu9HfCEw4SKALm5BkC3bwjwhSKr" | ||
| "A5hYAMXTJnPNiMyRBVzVjcgCyHiSm+8P+WGlnmwtP2RzbCMiQJ0d2KtmmmPorRHEhfMROVfTG5/fYrF5iWXzE80tfy9WP" | ||
| "sCqx5Buj7FYH0LvDyHiqd+3otpsr4/fa5+xbEVQPfrYnntylQG5VGeMLBhgEfyE7o6e6qYzwHIjwl0QwXSvvTmrVAY4D5" | ||
| "ddvT64wV0jRrr7FekO/XEjwuwwhuw7Ef7NY+dlfXpLb06EtHUJdVbsxvNUqBrwj/QGeEUSfwBAkmWHn5Bb/gAAAABJRU5"; | ||
|
|
||
| const char AdminHtmlStart[] = R"( | ||
| <head> | ||
| <title>Envoy Admin</title> | ||
| <link rel='shortcut icon' type='image/png' href='@FAVICON@'/> | ||
| <style> | ||
| .home-table { | ||
| font-family: sans-serif; | ||
| font-size: medium; | ||
| border-collapse: collapse; | ||
| } | ||
|
|
||
| .home-row:nth-child(even) { | ||
| background-color: #dddddd; | ||
| } | ||
|
|
||
| .home-data { | ||
| border: 1px solid #dddddd; | ||
| text-align: left; | ||
| padding: 8px; | ||
| } | ||
|
|
||
| .home-form { | ||
| margin-bottom: 0; | ||
| } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <table class='home-table'> | ||
| <thead> | ||
| <th class='home-data'>Command</th> | ||
| <th class='home-data'>Description</th> | ||
| </thead> | ||
| <tbody> | ||
| )"; | ||
|
|
||
| const char AdminHtmlEnd[] = R"( | ||
| </tbody> | ||
| </table> | ||
| </body> | ||
| )"; | ||
|
|
||
| } // namespace | ||
|
|
||
| Http::Code AdminImpl::handlerAdminHome(absl::string_view, Http::ResponseHeaderMap& response_headers, | ||
| Buffer::Instance& response, AdminStream&) { | ||
| response_headers.setReferenceContentType(Http::Headers::get().ContentTypeValues.Html); | ||
|
|
||
| response.add(absl::StrReplaceAll(AdminHtmlStart, {{"@FAVICON@", EnvoyFavicon}})); | ||
|
|
||
| // Prefix order is used during searching, but for printing do them in alpha order. | ||
| for (const UrlHandler* handler : sortedHandlers()) { | ||
| absl::string_view path = handler->prefix_; | ||
|
|
||
| if (path == "/") { | ||
| continue; // No need to print self-link to index page. | ||
| } | ||
|
|
||
| // Remove the leading slash from the link, so that the admin page can be | ||
| // rendered as part of another console, on a sub-path. | ||
| // | ||
| // E.g. consider a downstream dashboard that embeds the Envoy admin console. | ||
| // In that case, the "/stats" endpoint would be at | ||
| // https://DASHBOARD/envoy_admin/stats. If the links we present on the home | ||
| // page are absolute (e.g. "/stats") they won't work in the context of the | ||
| // dashboard. Removing the leading slash, they will work properly in both | ||
| // the raw admin console and when embedded in another page and URL | ||
| // hierarchy. | ||
| ASSERT(!path.empty()); | ||
| ASSERT(path[0] == '/'); | ||
| path = path.substr(1); | ||
|
|
||
| // For handlers that mutate state, render the link as a button in a POST form, | ||
| // rather than an anchor tag. This should discourage crawlers that find the / | ||
| // page from accidentally mutating all the server state by GETting all the hrefs. | ||
| const char* link_format = | ||
| handler->mutates_server_state_ | ||
| ? "<form action='{}' method='post' class='home-form'><button>{}</button></form>" | ||
| : "<a href='{}'>{}</a>"; | ||
| const std::string link = fmt::format(link_format, path, path); | ||
|
|
||
| // Handlers are all specified by statically above, and are thus trusted and do | ||
| // not require escaping. | ||
| response.add(fmt::format("<tr class='home-row'><td class='home-data'>{}</td>" | ||
| "<td class='home-data'>{}</td></tr>\n", | ||
| link, Html::Utility::sanitize(handler->help_text_))); | ||
| } | ||
| response.add(AdminHtmlEnd); | ||
| return Http::Code::OK; | ||
| } | ||
|
|
||
| } // namespace Server | ||
| } // namespace Envoy | ||
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,15 @@ | ||
| #include "source/common/html/utility.h" | ||
| #include "source/server/admin/admin.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Server { | ||
|
|
||
| Http::Code AdminImpl::handlerAdminHome(absl::string_view, Http::ResponseHeaderMap& response_headers, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this block here is the only new code in the PR. |
||
| Buffer::Instance& response, AdminStream&) { | ||
| response_headers.setReferenceContentType(Http::Headers::get().ContentTypeValues.Text); | ||
| response.add("HTML output was disabled by building with --define=admin_html=disabled"); | ||
| return Http::Code::OK; | ||
| } | ||
|
|
||
| } // namespace Server | ||
| } // namespace Envoy | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you document this here? https://github.com/envoyproxy/envoy/tree/main/bazel#disabling-optional-features
Probably also worth a release note?