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.

Warning

The mysql_proxy filter was tested with MySQL v5.5. The filter may not work with other versions of MySQL due to differences in the protocol implementation.

Configuration

The MySQL proxy filter should be chained with the TCP proxy filter as shown in the configuration snippet below:

  1. filter_chains:
  2. - filters:
  3. - name: envoy.filters.network.mysql_proxy
  4. typed_config:
  5. "@type": type.googleapis.com/envoy.config.filter.network.mysql_proxy.v1alpha1.MySQLProxy
  6. stat_prefix: mysql
  7. - name: envoy.tcp_proxy
  8. typed_config:
  9. "@type": type.googleapis.com/envoy.config.filter.network.tcp_proxy.v2.TcpProxy
  10. stat_prefix: tcp
  11. cluster: ...

Statistics

Every configured MySQL proxy filter has statistics rooted at mysql.. with the following statistics:

NameTypeDescription
auth_switch_requestCounterNumber of times the upstream server requested clients to switch to a different authentication method
decoder_errorsCounterNumber of MySQL protocol decoding errors
login_attemptsCounterNumber of login attempts
login_failuresCounterNumber of login failures
protocol_errorsCounterNumber of out of sequence protocol messages encountered in a session
queries_parse_errorCounterNumber of MySQL queries parsed with errors
queries_parsedCounterNumber of MySQL queries successfully parsed
sessionsCounterNumber of MySQL sessions since start
upgraded_to_sslCounterNumber of sessions/connections that were upgraded to SSL

Dynamic Metadata

The MySQL filter emits the following dynamic metadata for each SQL query parsed:

NameTypeDescription
<table.db>stringThe resource name in table.db format. The resource name defaults to the table being accessed if the database cannot be inferred.
[]listA list of strings representing the operations executed on the resource. Operations can be one of insert/update/select/drop/delete/create/alter/show.

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.

  1. filter_chains:
  2. - filters:
  3. - name: envoy.filters.network.mysql_proxy
  4. typed_config:
  5. "@type": type.googleapis.com/envoy.config.filter.network.mysql_proxy.v1alpha1.MySQLProxy
  6. stat_prefix: mysql
  7. - name: envoy.filters.network.rbac
  8. typed_config:
  9. "@type": type.googleapis.com/envoy.config.filter.network.rbac.v2.RBAC
  10. stat_prefix: rbac
  11. rules:
  12. action: DENY
  13. policies:
  14. "product-viewer":
  15. permissions:
  16. - metadata:
  17. filter: envoy.filters.network.mysql_proxy
  18. path:
  19. - key: catalog.productdb
  20. value:
  21. list_match:
  22. one_of:
  23. string_match:
  24. exact: update
  25. principals:
  26. - any: true
  27. - name: envoy.tcp_proxy
  28. typed_config:
  29. "@type": type.googleapis.com/envoy.config.filter.network.tcp_proxy.v2.TcpProxy
  30. stat_prefix: tcp
  31. cluster: mysql