-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This filter contains the logic to decode the mysql wire protocol and SQL queries (SQL99 only). The code is based on our internal version at VMware. The SQL parser can be found at https://github.com/rshriram/sql-parser. Its a cleaned up version of Hyrise SQL parser. I am keeping the code as a separate library as importing the sources into envoy will cause a lot of changes to the code. Signed-off-by: Giorgio Valentini <[email protected]> Signed-off-by: Deepa Kalani <[email protected]> Signed-off-by: Shriram Rajagopalan <[email protected]> Signed-off-by: Venil Noronha <[email protected]>
- Loading branch information
Showing
41 changed files
with
5,161 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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,8 @@ | ||
load("//bazel:api_build_system.bzl", "api_proto_library_internal") | ||
|
||
licenses(["notice"]) # Apache 2 | ||
|
||
api_proto_library_internal( | ||
name = "mysql_proxy", | ||
srcs = ["mysql_proxy.proto"], | ||
) |
20 changes: 20 additions & 0 deletions
20
api/envoy/config/filter/network/mysql_proxy/v1alpha1/mysql_proxy.proto
This file contains 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,20 @@ | ||
syntax = "proto3"; | ||
|
||
package envoy.config.filter.network.mysql_proxy.v1alpha1; | ||
option java_package = "io.envoyproxy.envoy.config.filter.network.mysql_proxy.v1alpha1"; | ||
option java_multiple_files = true; | ||
option go_package = "v1alpha1"; | ||
|
||
import "validate/validate.proto"; | ||
|
||
// [#protodoc-title: MySQL proxy] | ||
// MySQL Proxy :ref:`configuration overview <config_network_filters_mysql_proxy>`. | ||
message MySQLProxy { | ||
// The human readable prefix to use when emitting :ref:`statistics | ||
// <config_network_filters_mysql_proxy_stats>`. | ||
string stat_prefix = 1 [(validate.rules).string.min_bytes = 1]; | ||
|
||
// [#not-implemented-hide:] The optional path to use for writing MySQL access logs. | ||
// If the access log field is empty, access logs will not be written. | ||
string access_log = 2; | ||
} |
This file contains 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,11 @@ | ||
licenses(["notice"]) # Apache 2 | ||
|
||
cc_library( | ||
name = "sqlparser", | ||
srcs = glob(["src/**/*.cpp"]), | ||
hdrs = glob([ | ||
"include/**/*.h", | ||
"src/**/*.h", | ||
]), | ||
visibility = ["//visibility:public"], | ||
) |
This file contains 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 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
115 changes: 115 additions & 0 deletions
115
docs/root/configuration/network_filters/mysql_proxy_filter.rst
This file contains 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,115 @@ | ||
.. _config_network_filters_mysql_proxy: | ||
|
||
MySQL proxy | ||
=========== | ||
|
||
The MySQL proxy filter decodes the wire protocol between the MySQL client | ||
and server. It decodes the SQL queries in the payload (SQL99 format only). | ||
The decoded info is emitted as dynamic metadata that can be combined with | ||
access log filters to get detailed information on tables accessed as well | ||
as operations performed on each table. | ||
|
||
.. attention:: | ||
|
||
The mysql_proxy filter is experimental and is currently under active | ||
development. Capabilities will be expanded over time and the | ||
configuration structures are likely to change. | ||
|
||
.. _config_network_filters_mysql_proxy_config: | ||
|
||
Configuration | ||
------------- | ||
|
||
The MySQL proxy filter should be chained with the TCP proxy filter as shown | ||
in the configuration snippet below: | ||
|
||
.. code-block:: yaml | ||
filter_chains: | ||
- filters: | ||
- name: envoy.filters.network.mysql_proxy | ||
config: | ||
stat_prefix: mysql | ||
- name: envoy.tcp_proxy | ||
config: | ||
stat_prefix: tcp | ||
cluster: ... | ||
.. _config_network_filters_mysql_proxy_stats: | ||
|
||
Statistics | ||
---------- | ||
|
||
Every configured MySQL proxy filter has statistics rooted at *mysql.<stat_prefix>.* with the | ||
following statistics: | ||
|
||
.. csv-table:: | ||
:header: Name, Type, Description | ||
:widths: 1, 1, 2 | ||
|
||
auth_switch_request, Counter, Number of times the upstream server requested clients to switch to a different authentication method | ||
decoder_errors, Counter, Number of MySQL protocol decoding errors | ||
login_attempts, Counter, Number of login attempts | ||
login_failures, Counter, Number of login failures | ||
protocol_errors, Counter, Number of out of sequence protocol messages encountered in a session | ||
queries_parse_error, Counter, Number of MySQL queries parsed with errors | ||
queries_parsed, Counter, Number of MySQL queries successfully parsed | ||
sessions, Counter, Number of MySQL sessions since start | ||
upgraded_to_ssl, Counter, Number of sessions/connections that were upgraded to SSL | ||
|
||
.. _config_network_filters_mysql_proxy_dynamic_metadata: | ||
|
||
Dynamic Metadata | ||
---------------- | ||
|
||
The MySQL filter emits the following dynamic metadata for each SQL query parsed: | ||
|
||
.. csv-table:: | ||
:header: Name, Type, Description | ||
:widths: 1, 1, 2 | ||
|
||
<table.db>, string, The resource name in *table.db* format. The resource name defaults to the table being accessed if the database cannot be inferred. | ||
[], list, A list of strings representing the operations executed on the resource. Operations can be one of insert/update/select/drop/delete/create/alter/show. | ||
|
||
.. _config_network_filters_mysql_proxy_rbac: | ||
|
||
RBAC Enforcement on Table Accesses | ||
---------------------------------- | ||
|
||
The dynamic metadata emitted by the MySQL filter can be used in conjunction | ||
with the RBAC filter to control accesses to individual tables in a | ||
database. The following configuration snippet shows an example RBAC filter | ||
configuration that denies SQL queries with _update_ statements to the | ||
_catalog_ table in the _productdb_ database. | ||
|
||
.. code-block:: yaml | ||
filter_chains: | ||
- filters: | ||
- name: envoy.filters.network.mysql_proxy | ||
config: | ||
stat_prefix: mysql | ||
- name: envoy.filters.network.rbac | ||
config: | ||
stat_prefix: rbac | ||
rules: | ||
action: DENY | ||
policies: | ||
"product-viewer": | ||
permissions: | ||
- metadata: | ||
filter: envoy.filters.network.mysql_proxy | ||
path: | ||
- key: catalog.productdb | ||
value: | ||
list_match: | ||
one_of: | ||
string_match: | ||
exact: update | ||
principals: | ||
- any: true | ||
- name: envoy.tcp_proxy | ||
config: | ||
stat_prefix: tcp | ||
cluster: mysql |
This file contains 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 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 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 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 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,60 @@ | ||
licenses(["notice"]) # Apache 2 | ||
|
||
# MySQL proxy L7 network filter. | ||
# Public docs: docs/root/configuration/network_filters/mysql_proxy_filter.rst | ||
|
||
load( | ||
"//bazel:envoy_build_system.bzl", | ||
"envoy_cc_library", | ||
"envoy_package", | ||
) | ||
|
||
envoy_package() | ||
|
||
envoy_cc_library( | ||
name = "proxy_lib", | ||
srcs = [ | ||
"mysql_codec_clogin.cc", | ||
"mysql_codec_clogin_resp.cc", | ||
"mysql_codec_command.cc", | ||
"mysql_codec_greeting.cc", | ||
"mysql_codec_switch_resp.cc", | ||
"mysql_decoder.cc", | ||
"mysql_filter.cc", | ||
"mysql_utils.cc", | ||
], | ||
hdrs = [ | ||
"mysql_codec.h", | ||
"mysql_codec_clogin.h", | ||
"mysql_codec_clogin_resp.h", | ||
"mysql_codec_command.h", | ||
"mysql_codec_greeting.h", | ||
"mysql_codec_switch_resp.h", | ||
"mysql_decoder.h", | ||
"mysql_filter.h", | ||
"mysql_session.h", | ||
"mysql_utils.h", | ||
], | ||
external_deps = ["sqlparser"], | ||
deps = [ | ||
"//include/envoy/network:filter_interface", | ||
"//include/envoy/server:filter_config_interface", | ||
"//include/envoy/stats:stats_interface", | ||
"//include/envoy/stats:stats_macros", | ||
"//source/common/config:filter_json_lib", | ||
"//source/common/network:filter_lib", | ||
"//source/extensions/filters/network:well_known_names", | ||
], | ||
) | ||
|
||
envoy_cc_library( | ||
name = "config", | ||
srcs = ["mysql_config.cc"], | ||
hdrs = ["mysql_config.h"], | ||
deps = [ | ||
":proxy_lib", | ||
"//source/extensions/filters/network:well_known_names", | ||
"//source/extensions/filters/network/common:factory_base_lib", | ||
"@envoy_api//envoy/config/filter/network/mysql_proxy/v1alpha1:mysql_proxy_cc", | ||
], | ||
) |
Oops, something went wrong.