diff --git a/content/compatibility.yaml b/content/compatibility.yaml index 713cba2..f43033a 100644 --- a/content/compatibility.yaml +++ b/content/compatibility.yaml @@ -57,7 +57,7 @@ universal: - key: kmsEncryption codes: { ruby: kms_encryption } page: using-plugins/kms-encryption - description: "Transparent column-level encryption using AWS KMS." + description: "Transparent column-level encryption using AWS KMS. Not supported with the `trilogy` driver (it has no prepared statements); use `mysql2` or `pg`." # Reason text for the incompatible cells in the database-type and endpoint # matrices. Cells tag a `reason:` key; the generator emits one footnote per diff --git a/content/dev-guide.yaml b/content/dev-guide.yaml index 45ee451..0496ee1 100644 --- a/content/dev-guide.yaml +++ b/content/dev-guide.yaml @@ -76,7 +76,7 @@ wrappers: # Ruby diagram labels come from the `diagram:` block below. architectureComponents: | - 1. The connection entry points (`WrapperPgConnection`, `WrapperMysql2Client`, and the `aws_postgresql` / `aws_mysql2` ActiveRecord adapters) + 1. The connection entry points (`WrapperPgConnection`, `WrapperMysql2Client`, `WrapperTrilogyClient`, and the `aws_postgresql` / `aws_mysql2` / `aws_trilogy` ActiveRecord adapters) 2. The [plugin manager](./service-container#plugin-manager) (one of the services in the container) 3. The [loadable and extensible plugins](./loadable-plugins) 4. The [service container](./service-container) of discrete services @@ -96,7 +96,7 @@ wrappers: executeKey: "the qualified driver method name (e.g. `connection.query`, `connection.exec`)" notifyConnChangedKey: "notify_connection_changed" - devPrereqs: "Make sure you have Ruby 3.3+ installed, along with your choice of underlying driver gem (`pg` or `mysql2`)." + devPrereqs: "Make sure you have Ruby 3.3+ installed, along with your choice of underlying driver gem (`pg`, `mysql2`, or `trilogy`)." buildTool: "Bundler + RSpec" sampleCode: | A minimal connection example using the wrapper: @@ -166,8 +166,8 @@ wrappers: diagram: entryPoints: - - "WrapperPgConnection / WrapperMysql2Client" - - "aws_postgresql / aws_mysql2 (ActiveRecord)" + - "WrapperPgConnection / WrapperMysql2Client / WrapperTrilogyClient" + - "aws_postgresql / aws_mysql2 / aws_trilogy (ActiveRecord)" wrapperNode: "Wrapper Connection" samplePlugins: - "Plugin A" @@ -353,7 +353,7 @@ wrappers: your plugin. See the dedicated [Plugin Manager](#plugin-manager) section below. perf: - driverNames: "`mysql2`/`pg`" + driverNames: "`mysql2`/`trilogy`/`pg`" # Rough magnitude of the fixed per-call cost, stated in the intro. fixedCostMagnitude: "a microsecond" # The end-to-end real-database benchmark: display name (inline code) and link. diff --git a/content/failover.yaml b/content/failover.yaml index f398db1..ddb9319 100644 --- a/content/failover.yaml +++ b/content/failover.yaml @@ -85,7 +85,7 @@ wrappers: # way because it needs a Rails application around it, so the two paths are # ordered by who the reader is, not by what fits in one file. gettingStarted: - note: "Requires Ruby 3.3 or later. The gem is `aws_advanced_ruby_driver_wrapper` on RubyGems. Tested with Active Record 7.2, 8.0, and 8.1, `pg` 1.6.3 or later, and `mysql2` 0.5.7 or later." + note: "Requires Ruby 3.3 or later. The gem is `aws_advanced_ruby_driver_wrapper` on RubyGems. Tested with Active Record 7.2, 8.0, and 8.1, `pg` 1.6.3 or later, `mysql2` 0.5.7 or later, and `trilogy` 2.13.2 or later." steps: - title: "1. Add the gem" blocks: @@ -93,7 +93,7 @@ wrappers: code: | # Gemfile gem 'aws_advanced_ruby_driver_wrapper' - gem 'pg' # or: gem 'mysql2' + gem 'pg' # or: gem 'mysql2' / gem 'trilogy' for MySQL - lang: bash code: | bundle install @@ -124,15 +124,16 @@ wrappers: - title: "2. Point Active Record at your cluster" blocks: - text: >- - The wrapper registers two adapters, `aws_postgresql` and `aws_mysql2`, - which are drop-in replacements for `postgresql` and `mysql2`. + The wrapper registers three adapters, `aws_postgresql`, `aws_mysql2`, + and `aws_trilogy`, which are drop-in replacements for `postgresql`, + `mysql2`, and `trilogy`. # Without this, Active Record raises AdapterNotFound and names only # its own built-in adapters, which does not hint that a require is # missing. Bundler covers the Rails case; a plain script does not. - text: >- Bundler requires the gem for you. In a plain Ruby script, add `require 'aws_advanced_ruby_driver_wrapper'` first: that single require - is what registers both adapters, and without it Active Record reports + is what registers all three adapters, and without it Active Record reports `aws_postgresql` as a nonexistent adapter. - text: >- If you are starting without a Rails application, add @@ -195,10 +196,11 @@ wrappers: - text: | :::note Mixing wrapped and standard adapters in one application The wrapped adapters register their type information under the underlying - `postgresql` and `mysql2` adapter names. If one application uses both a - standard connection (`postgresql`/`mysql2`) and a wrapped one - (`aws_postgresql`/`aws_mysql2`), a custom type registered for one is shared - with the other, because both resolve under the same underlying adapter key. + `postgresql`, `mysql2`, and `trilogy` adapter names. If one application uses + both a standard connection (`postgresql`/`mysql2`/`trilogy`) and a wrapped one + (`aws_postgresql`/`aws_mysql2`/`aws_trilogy`), a custom type registered for + one is shared with the other, because both resolve under the same underlying + adapter key. ::: - text: | :::note Keeping the password out of your source @@ -215,8 +217,8 @@ wrappers: blocks: - text: >- Without Active Record, the wrapper provides connection classes that - stand in for `PG::Connection` and `Mysql2::Client`. This is a complete - program; save it as `main.rb` and run it: + stand in for `PG::Connection`, `Mysql2::Client`, and `Trilogy`. This is a + complete program; save it as `main.rb` and run it: - lang: ruby code: | # main.rb @@ -246,7 +248,10 @@ wrappers: stands in for `PG::Connection` and takes `dbname:` and `user:`. For MySQL, `require 'aws_advanced_ruby_driver_wrapper/mysql'` and use `AwsAdvancedRubyDriverWrapper::WrapperMysql2Client`, which stands in - for `Mysql2::Client` and takes `database:` and `username:`. Either + for `Mysql2::Client` and takes `database:` and `username:`. To use the + Trilogy driver instead, `require 'aws_advanced_ruby_driver_wrapper/trilogy'` + and use `AwsAdvancedRubyDriverWrapper::WrapperTrilogyClient`, which stands + in for `Trilogy` and takes the same `database:` and `username:`. Either way the calls your code already makes keep working, and the plugins act on each one. - title: "Next" diff --git a/content/plugins.yaml b/content/plugins.yaml index 89447b0..d14d1ab 100644 --- a/content/plugins.yaml +++ b/content/plugins.yaml @@ -226,6 +226,16 @@ plugins: ) ``` + With the Trilogy driver, swap in + `AwsAdvancedRubyDriverWrapper::WrapperTrilogyClient`. IAM authentication works + the same way — keep `enable_cleartext_plugin: true` — but two TLS keys differ + on Trilogy: the CA certificate is `ssl_ca` (Trilogy's name for it) rather than + `sslca`, and on the direct client `ssl_mode` must be an integer constant + (`ssl_mode: Trilogy::SSL_VERIFY_IDENTITY`) — a string or symbol raises + `TypeError`. (The `aws_trilogy` ActiveRecord adapter does accept the string + mode names such as `verify_identity`.) See + [Configuring TLS/SSL](../configuring-tls) for the full per-driver table. + **PostgreSQL (`pg`):** ```ruby @@ -261,6 +271,10 @@ plugins: using the plugin with MySQL. Because the token is sent in cleartext, you must also use a TLS/SSL connection so it is encrypted in transit. This does not apply to PostgreSQL (`pg`). + + This applies to both MySQL drivers (`mysql2` and `trilogy`). On `trilogy`, + omitting `enable_cleartext_plugin: true` makes the driver raise + `Trilogy::AuthPluginError` and the token is never sent. ::: - | ## Token caching @@ -479,6 +493,14 @@ plugins: ) ``` + With the Trilogy driver, use + `AwsAdvancedRubyDriverWrapper::WrapperTrilogyClient`. `enable_cleartext_plugin: + true` is still required — without it Trilogy raises `Trilogy::AuthPluginError` + — but two TLS keys differ: the CA certificate is `ssl_ca` rather than `sslca`, + and on the direct client `ssl_mode` must be an integer constant + (`ssl_mode: Trilogy::SSL_VERIFY_IDENTITY`), not a string. See + [Configuring TLS/SSL](../configuring-tls). + For the full picture, see [Configuring TLS/SSL](../configuring-tls). # ========================================================================= @@ -667,6 +689,14 @@ plugins: ) ``` + With the Trilogy driver, use + `AwsAdvancedRubyDriverWrapper::WrapperTrilogyClient`. `enable_cleartext_plugin: + true` is still required — without it Trilogy raises `Trilogy::AuthPluginError` + — but two TLS keys differ: the CA certificate is `ssl_ca` rather than `sslca`, + and on the direct client `ssl_mode` must be an integer constant + (`ssl_mode: Trilogy::SSL_VERIFY_IDENTITY`), not a string. See + [Configuring TLS/SSL](../configuring-tls). + For the full picture, see [Configuring TLS/SSL](../configuring-tls). # ========================================================================= @@ -842,6 +872,14 @@ plugins: column never holds plaintext. See [Server-side enforcement is required](#server-side-enforcement-is-required) and [Enforce encryption in the database](#enforce-encryption-in-the-database) below. ::: + + :::warning Not supported with the Trilogy driver + The plugin can encrypt a value only when it is sent as a bound parameter, which + requires prepared statements. The Trilogy driver does not support prepared + statements, so the plugin cannot be used with it: both the plugin and + `KeyManagementUtility` refuse a Trilogy connection with an explicit error. Use the + `mysql2` driver (or `pg` on PostgreSQL) for column encryption. + ::: code: ruby: kms_encryption availableSince: @@ -1376,7 +1414,8 @@ plugins: ### Set up an encrypted column `KeyManagementUtility` runs on a plain `pg` or `mysql2` connection that you - open and close yourself. Build its configuration from the same `encryption_*` + open and close yourself. (It does not support `trilogy`, for the same + prepared-statement reason the plugin does not.) Build its configuration from the same `encryption_*` parameters the plugin uses, then create a master key and turn on encryption for an existing binary column: diff --git a/content/scenarios.yaml b/content/scenarios.yaml index aa2579d..1881e09 100644 --- a/content/scenarios.yaml +++ b/content/scenarios.yaml @@ -66,13 +66,13 @@ wrappers: ruby: - engineLabel: { pg: PostgreSQL, mysql: MySQL } - adapter: { pg: aws_postgresql, mysql: aws_mysql2 } - gem: { pg: pg, mysql: mysql2 } - requirePath: { pg: aws_advanced_ruby_driver_wrapper/postgresql, mysql: aws_advanced_ruby_driver_wrapper/mysql } - directClass: { pg: "AwsAdvancedRubyDriverWrapper::WrapperPgConnection", mysql: "AwsAdvancedRubyDriverWrapper::WrapperMysql2Client" } - standsIn: { pg: "PG::Connection", mysql: "Mysql2::Client" } - port: { pg: 5432, mysql: 3306 } + engineLabel: { pg: PostgreSQL, mysql: MySQL, trilogy: MySQL } + adapter: { pg: aws_postgresql, mysql: aws_mysql2, trilogy: aws_trilogy } + gem: { pg: pg, mysql: mysql2, trilogy: trilogy } + requirePath: { pg: aws_advanced_ruby_driver_wrapper/postgresql, mysql: aws_advanced_ruby_driver_wrapper/mysql, trilogy: aws_advanced_ruby_driver_wrapper/trilogy } + directClass: { pg: "AwsAdvancedRubyDriverWrapper::WrapperPgConnection", mysql: "AwsAdvancedRubyDriverWrapper::WrapperMysql2Client", trilogy: "AwsAdvancedRubyDriverWrapper::WrapperTrilogyClient" } + standsIn: { pg: "PG::Connection", mysql: "Mysql2::Client", trilogy: "Trilogy" } + port: { pg: 5432, mysql: 3306, trilogy: 3306 } # ----------------------------------------------------------------------------- # Links. Active Record concepts are linked, not explained. All Rails links point @@ -134,7 +134,8 @@ axes: default: pg options: - { id: pg, label: PostgreSQL } - - { id: mysql, label: MySQL } + - { id: mysql, label: MySQL (mysql2) } + - { id: trilogy, label: MySQL (Trilogy) } - id: arVersion label: Active Record @@ -175,7 +176,7 @@ questions: emit: links: [ar_multiple_databases] - id: direct - label: Through the pg or mysql2 gem directly + label: Through the pg, mysql2, or trilogy gem directly short: the gem directly hint: > The wrapper stands in for the gem's own connection class. There is no @@ -354,25 +355,44 @@ rules: # --- dialect: stating it explicitly removes a class of wrong-guess surprises - when: { deployment: [cluster, cluster_custom, cluster_readonly], engine: [pg] } emit: { params: { wrapper_dialect: aurora-pg } } - - when: { deployment: [cluster, cluster_custom, cluster_readonly], engine: [mysql] } + - when: { deployment: [cluster, cluster_custom, cluster_readonly], engine: [mysql, trilogy] } emit: { params: { wrapper_dialect: aurora-mysql } } - when: { deployment: [global], engine: [pg] } emit: { params: { wrapper_dialect: global-aurora-pg } } - - when: { deployment: [global], engine: [mysql] } + - when: { deployment: [global], engine: [mysql, trilogy] } emit: { params: { wrapper_dialect: global-aurora-mysql } } - when: { deployment: [multi_az_cluster], engine: [pg] } emit: { params: { wrapper_dialect: multi-az-pg-cluster } } - - when: { deployment: [multi_az_cluster], engine: [mysql] } + - when: { deployment: [multi_az_cluster], engine: [mysql, trilogy] } emit: { params: { wrapper_dialect: multi-az-mysql-cluster } } - when: { deployment: [multi_az_instance, instance, proxy], engine: [pg] } emit: { params: { wrapper_dialect: rds-pg } } - - when: { deployment: [multi_az_instance, instance, proxy], engine: [mysql] } + - when: { deployment: [multi_az_instance, instance, proxy], engine: [mysql, trilogy] } emit: { params: { wrapper_dialect: rds-mysql } } - when: { deployment: [community], engine: [pg] } emit: { params: { wrapper_dialect: pg } } - - when: { deployment: [community], engine: [mysql] } + - when: { deployment: [community], engine: [mysql, trilogy] } emit: { params: { wrapper_dialect: mysql } } + # --- IAM authentication: the token travels as the password, so a few more + # settings are needed. On MySQL the token is only sent with the cleartext + # client plugin, so `enable_cleartext_plugin` is required there (not on + # PostgreSQL). TLS is not strictly required but strongly recommended on every + # engine, because the token is sent as the password (in cleartext on MySQL); + # the verification mode and CA-certificate key names differ per driver. + - when: { credentials: [iam], engine: [mysql, trilogy] } + from: "required on MySQL: the IAM token is sent via mysql_clear_password" + emit: { params: { enable_cleartext_plugin: true } } + - when: { credentials: [iam], engine: [pg] } + from: "recommended: encrypts the IAM token (sent as the password) in transit" + emit: { params: { sslmode: verify-full, sslrootcert: "" } } + - when: { credentials: [iam], engine: [mysql] } + from: "recommended: encrypts the IAM token (sent in cleartext) in transit" + emit: { params: { ssl_mode: verify_identity, sslca: "" } } + - when: { credentials: [iam], engine: [trilogy] } + from: "recommended: encrypts the IAM token (sent in cleartext) in transit" + emit: { params: { ssl_mode: verify_identity, ssl_ca: "" } } + # --- resolving the cluster endpoint to a real instance at connect time - when: { continuity: [instance, region], deployment: [cluster, cluster_readonly, global, multi_az_cluster] } emit: @@ -600,6 +620,9 @@ addons: toggle: true label: Encrypt column values with AWS KMS short: column encryption + blockedIf: + - when: { engine: [trilogy] } + reason: kmsUnsupportedTrilogy emit: plugins: [kms_encryption] params: @@ -798,6 +821,7 @@ labels: bgUnsupportedGlobal: "AWS does not support Blue/Green deployments with RDS Proxy on Aurora global databases, and the wrapper's Blue/Green plugin does not support global databases. Use a global switchover or failover instead." bgUnsupportedMultiAzCluster: "AWS Blue/Green deployments are not available for RDS Multi-AZ DB clusters (they are supported for Multi-AZ DB instance deployments)." bgUnsupportedCommunity: "Blue/Green deployments are an Amazon RDS/Aurora feature. A community database you run yourself cannot be set up with one." + kmsUnsupportedTrilogy: "The KMS Encryption Plugin relies on prepared statements, which Trilogy does not support, so it cannot be used with the Trilogy driver. Use the mysql2 driver for column encryption." resultHeading: Your configuration assumesHeading: What this assumes pluginsHeading: Why each plugin is here diff --git a/content/templates/configuring-tls.md.j2 b/content/templates/configuring-tls.md.j2 index c8abdde..377c9f1 100644 --- a/content/templates/configuring-tls.md.j2 +++ b/content/templates/configuring-tls.md.j2 @@ -20,6 +20,9 @@ We strongly recommend a TLS 1.2+ connection **with certificate verification**: |---|---|---| | PostgreSQL (`pg`) | `sslmode: verify-full` | `sslrootcert` | | MySQL (`mysql2`) | `ssl_mode: verify_identity` | `sslca` | +{% if wrapper_id == 'ruby' %} +| MySQL (`trilogy`) | `ssl_mode: verify_identity` | `ssl_ca` | +{% endif %} `verify-full` and `verify_identity` check both the certificate chain **and** that the hostname matches the certificate, which is what protects the connection against a @@ -75,6 +78,12 @@ production: sslca: /path/to/global-bundle.pem ``` +{% if wrapper_id == 'ruby' %} +With the Trilogy driver, use `adapter: aws_trilogy` and name the certificate authority +`ssl_ca` instead of `sslca`; the `ssl_mode` verification names (`verify_identity`, +`verify_ca`, …) are the same. + +{% endif %} Using the driver directly, they are keyword arguments: ```ruby @@ -101,6 +110,13 @@ AwsAdvancedRubyDriverWrapper::WrapperMysql2Client.new( ) ``` +{% if wrapper_id == 'ruby' %} +With Trilogy, use `WrapperTrilogyClient`, name the certificate authority `ssl_ca` +instead of `sslca`, and pass `ssl_mode` as an **integer** constant +(`ssl_mode: Trilogy::SSL_VERIFY_IDENTITY`) — the direct client rejects a string or +symbol with `TypeError`. Without `ssl_mode`, Trilogy makes no TLS connection at all. + +{% endif %} ## Certificate bundle When connecting to an RDS or Aurora endpoint, use the AWS global certificate bundle as the @@ -112,7 +128,7 @@ name — the certificate authority you supply must be the one appropriate for *t endpoint, not for the RDS endpoint behind it. For TLS options beyond those shown here, see the driver documentation: -[`pg`](https://github.com/ged/ruby-pg) and [`mysql2`](https://github.com/brianmario/mysql2). +[`pg`](https://github.com/ged/ruby-pg), [`mysql2`](https://github.com/brianmario/mysql2){% if wrapper_id == 'ruby' %}, and [`trilogy`](https://github.com/trilogy-libraries/trilogy){% endif %}. ## Why this matters for authentication plugins diff --git a/site/docs-ruby/compatibility.md b/site/docs-ruby/compatibility.md index 3211861..418557e 100644 --- a/site/docs-ruby/compatibility.md +++ b/site/docs-ruby/compatibility.md @@ -20,4 +20,4 @@ Legend: ✅ compatible · ❌ not compatible · blank = no constraint recorded. These plugins record no database-type, endpoint, or cross-plugin constraints: -- [`kms_encryption`](./using-plugins/kms-encryption) — Transparent column-level encryption using AWS KMS. \ No newline at end of file +- [`kms_encryption`](./using-plugins/kms-encryption) — Transparent column-level encryption using AWS KMS. Not supported with the `trilogy` driver (it has no prepared statements); use `mysql2` or `pg`. \ No newline at end of file diff --git a/site/docs-ruby/configuring-tls.md b/site/docs-ruby/configuring-tls.md index ad812c2..abd8d98 100644 --- a/site/docs-ruby/configuring-tls.md +++ b/site/docs-ruby/configuring-tls.md @@ -20,6 +20,7 @@ We strongly recommend a TLS 1.2+ connection **with certificate verification**: |---|---|---| | PostgreSQL (`pg`) | `sslmode: verify-full` | `sslrootcert` | | MySQL (`mysql2`) | `ssl_mode: verify_identity` | `sslca` | +| MySQL (`trilogy`) | `ssl_mode: verify_identity` | `ssl_ca` | `verify-full` and `verify_identity` check both the certificate chain **and** that the hostname matches the certificate, which is what protects the connection against a @@ -75,6 +76,10 @@ production: sslca: /path/to/global-bundle.pem ``` +With the Trilogy driver, use `adapter: aws_trilogy` and name the certificate authority +`ssl_ca` instead of `sslca`; the `ssl_mode` verification names (`verify_identity`, +`verify_ca`, …) are the same. + Using the driver directly, they are keyword arguments: ```ruby @@ -101,6 +106,11 @@ AwsAdvancedRubyDriverWrapper::WrapperMysql2Client.new( ) ``` +With Trilogy, use `WrapperTrilogyClient`, name the certificate authority `ssl_ca` +instead of `sslca`, and pass `ssl_mode` as an **integer** constant +(`ssl_mode: Trilogy::SSL_VERIFY_IDENTITY`) — the direct client rejects a string or +symbol with `TypeError`. Without `ssl_mode`, Trilogy makes no TLS connection at all. + ## Certificate bundle When connecting to an RDS or Aurora endpoint, use the AWS global certificate bundle as the @@ -112,7 +122,7 @@ name — the certificate authority you supply must be the one appropriate for *t endpoint, not for the RDS endpoint behind it. For TLS options beyond those shown here, see the driver documentation: -[`pg`](https://github.com/ged/ruby-pg) and [`mysql2`](https://github.com/brianmario/mysql2). +[`pg`](https://github.com/ged/ruby-pg), [`mysql2`](https://github.com/brianmario/mysql2), and [`trilogy`](https://github.com/trilogy-libraries/trilogy). ## Why this matters for authentication plugins diff --git a/site/docs-ruby/development-guide/architecture.md b/site/docs-ruby/development-guide/architecture.md index 9793b95..7a7f4dc 100644 --- a/site/docs-ruby/development-guide/architecture.md +++ b/site/docs-ruby/development-guide/architecture.md @@ -12,8 +12,8 @@ flowchart TB subgraph entry["Entry points"] direction LR - ep1["WrapperPgConnection / WrapperMysql2Client"] - ep2["aws_postgresql / aws_mysql2 (ActiveRecord)"] + ep1["WrapperPgConnection / WrapperMysql2Client / WrapperTrilogyClient"] + ep2["aws_postgresql / aws_mysql2 / aws_trilogy (ActiveRecord)"] end subgraph conn["Wrapper Connection — one per connection"] @@ -59,7 +59,7 @@ flowchart TB The AWS Advanced Ruby Driver Wrapper contains 5 main components: -1. The connection entry points (`WrapperPgConnection`, `WrapperMysql2Client`, and the `aws_postgresql` / `aws_mysql2` ActiveRecord adapters) +1. The connection entry points (`WrapperPgConnection`, `WrapperMysql2Client`, `WrapperTrilogyClient`, and the `aws_postgresql` / `aws_mysql2` / `aws_trilogy` ActiveRecord adapters) 2. The [plugin manager](./service-container#plugin-manager) (one of the services in the container) 3. The [loadable and extensible plugins](./loadable-plugins) 4. The [service container](./service-container) of discrete services diff --git a/site/docs-ruby/development-guide/development-guide.md b/site/docs-ruby/development-guide/development-guide.md index 3446a39..b901d5d 100644 --- a/site/docs-ruby/development-guide/development-guide.md +++ b/site/docs-ruby/development-guide/development-guide.md @@ -8,7 +8,7 @@ This guide is for **open-source contributors to the AWS Advanced Ruby Driver Wra ## Setup -Make sure you have Ruby 3.3+ installed, along with your choice of underlying driver gem (`pg` or `mysql2`). +Make sure you have Ruby 3.3+ installed, along with your choice of underlying driver gem (`pg`, `mysql2`, or `trilogy`). Clone the AWS Advanced Ruby Driver Wrapper repository, then you can make changes in the repository. This project is built using Bundler + RSpec. diff --git a/site/docs-ruby/development-guide/performance.md b/site/docs-ruby/development-guide/performance.md index 0a4c4af..b6ebca2 100644 --- a/site/docs-ruby/development-guide/performance.md +++ b/site/docs-ruby/development-guide/performance.md @@ -5,7 +5,7 @@ title: Performance and Overhead # Performance and Overhead Every database operation goes through the wrapper's plugin pipeline before reaching the underlying -`mysql2`/`pg` driver, which adds some cost. The short version: the wrapper adds a **small, fixed +`mysql2`/`trilogy`/`pg` driver, which adds some cost. The short version: the wrapper adds a **small, fixed amount of work per call** - on the order of a microsecond - and against a real query that cost is too small to measure, dwarfed by the network round trip to the database. diff --git a/site/docs-ruby/overview.md b/site/docs-ruby/overview.md index 54527ef..7ab9583 100644 --- a/site/docs-ruby/overview.md +++ b/site/docs-ruby/overview.md @@ -21,14 +21,14 @@ will follow your choice where an equivalent page exists. ## Getting started -Requires Ruby 3.3 or later. The gem is `aws_advanced_ruby_driver_wrapper` on RubyGems. Tested with Active Record 7.2, 8.0, and 8.1, `pg` 1.6.3 or later, and `mysql2` 0.5.7 or later. +Requires Ruby 3.3 or later. The gem is `aws_advanced_ruby_driver_wrapper` on RubyGems. Tested with Active Record 7.2, 8.0, and 8.1, `pg` 1.6.3 or later, `mysql2` 0.5.7 or later, and `trilogy` 2.13.2 or later. ### 1. Add the gem ```ruby # Gemfile gem 'aws_advanced_ruby_driver_wrapper' -gem 'pg' # or: gem 'mysql2' +gem 'pg' # or: gem 'mysql2' / gem 'trilogy' for MySQL ``` ```bash @@ -55,9 +55,9 @@ required. ### 2. Point Active Record at your cluster -The wrapper registers two adapters, `aws_postgresql` and `aws_mysql2`, which are drop-in replacements for `postgresql` and `mysql2`. +The wrapper registers three adapters, `aws_postgresql`, `aws_mysql2`, and `aws_trilogy`, which are drop-in replacements for `postgresql`, `mysql2`, and `trilogy`. -Bundler requires the gem for you. In a plain Ruby script, add `require 'aws_advanced_ruby_driver_wrapper'` first: that single require is what registers both adapters, and without it Active Record reports `aws_postgresql` as a nonexistent adapter. +Bundler requires the gem for you. In a plain Ruby script, add `require 'aws_advanced_ruby_driver_wrapper'` first: that single require is what registers all three adapters, and without it Active Record reports `aws_postgresql` as a nonexistent adapter. If you are starting without a Rails application, add `gem 'activerecord'` to the Gemfile from step 1 (outside Rails, nothing else installs it), run `bundle install`, and this is a complete program. Save it as `main.rb` and run it: @@ -111,10 +111,11 @@ Active Record keeps its own connection pool and its reading and writing roles; t :::note Mixing wrapped and standard adapters in one application The wrapped adapters register their type information under the underlying -`postgresql` and `mysql2` adapter names. If one application uses both a -standard connection (`postgresql`/`mysql2`) and a wrapped one -(`aws_postgresql`/`aws_mysql2`), a custom type registered for one is shared -with the other, because both resolve under the same underlying adapter key. +`postgresql`, `mysql2`, and `trilogy` adapter names. If one application uses +both a standard connection (`postgresql`/`mysql2`/`trilogy`) and a wrapped one +(`aws_postgresql`/`aws_mysql2`/`aws_trilogy`), a custom type registered for +one is shared with the other, because both resolve under the same underlying +adapter key. ::: @@ -131,7 +132,7 @@ database user with no password at all, consider using `iam` instead; see ### Or connect with the driver directly -Without Active Record, the wrapper provides connection classes that stand in for `PG::Connection` and `Mysql2::Client`. This is a complete program; save it as `main.rb` and run it: +Without Active Record, the wrapper provides connection classes that stand in for `PG::Connection`, `Mysql2::Client`, and `Trilogy`. This is a complete program; save it as `main.rb` and run it: ```ruby # main.rb @@ -158,7 +159,7 @@ end bundle exec ruby main.rb ``` -For PostgreSQL, `require 'aws_advanced_ruby_driver_wrapper/postgresql'` and use `AwsAdvancedRubyDriverWrapper::WrapperPgConnection`, which stands in for `PG::Connection` and takes `dbname:` and `user:`. For MySQL, `require 'aws_advanced_ruby_driver_wrapper/mysql'` and use `AwsAdvancedRubyDriverWrapper::WrapperMysql2Client`, which stands in for `Mysql2::Client` and takes `database:` and `username:`. Either way the calls your code already makes keep working, and the plugins act on each one. +For PostgreSQL, `require 'aws_advanced_ruby_driver_wrapper/postgresql'` and use `AwsAdvancedRubyDriverWrapper::WrapperPgConnection`, which stands in for `PG::Connection` and takes `dbname:` and `user:`. For MySQL, `require 'aws_advanced_ruby_driver_wrapper/mysql'` and use `AwsAdvancedRubyDriverWrapper::WrapperMysql2Client`, which stands in for `Mysql2::Client` and takes `database:` and `username:`. To use the Trilogy driver instead, `require 'aws_advanced_ruby_driver_wrapper/trilogy'` and use `AwsAdvancedRubyDriverWrapper::WrapperTrilogyClient`, which stands in for `Trilogy` and takes the same `database:` and `username:`. Either way the calls your code already makes keep working, and the plugins act on each one. ### Next diff --git a/site/docs-ruby/using-plugins/federated-auth.md b/site/docs-ruby/using-plugins/federated-auth.md index d88d84c..d63dd87 100644 --- a/site/docs-ruby/using-plugins/federated-auth.md +++ b/site/docs-ruby/using-plugins/federated-auth.md @@ -182,5 +182,13 @@ AwsAdvancedRubyDriverWrapper::WrapperMysql2Client.new( ) ``` +With the Trilogy driver, use +`AwsAdvancedRubyDriverWrapper::WrapperTrilogyClient`. `enable_cleartext_plugin: +true` is still required — without it Trilogy raises `Trilogy::AuthPluginError` +— but two TLS keys differ: the CA certificate is `ssl_ca` rather than `sslca`, +and on the direct client `ssl_mode` must be an integer constant +(`ssl_mode: Trilogy::SSL_VERIFY_IDENTITY`), not a string. See +[Configuring TLS/SSL](../configuring-tls). + For the full picture, see [Configuring TLS/SSL](../configuring-tls). diff --git a/site/docs-ruby/using-plugins/iam-authentication.md b/site/docs-ruby/using-plugins/iam-authentication.md index a5f7576..3ee660a 100644 --- a/site/docs-ruby/using-plugins/iam-authentication.md +++ b/site/docs-ruby/using-plugins/iam-authentication.md @@ -66,6 +66,16 @@ AwsAdvancedRubyDriverWrapper::WrapperMysql2Client.new( ) ``` +With the Trilogy driver, swap in +`AwsAdvancedRubyDriverWrapper::WrapperTrilogyClient`. IAM authentication works +the same way — keep `enable_cleartext_plugin: true` — but two TLS keys differ +on Trilogy: the CA certificate is `ssl_ca` (Trilogy's name for it) rather than +`sslca`, and on the direct client `ssl_mode` must be an integer constant +(`ssl_mode: Trilogy::SSL_VERIFY_IDENTITY`) — a string or symbol raises +`TypeError`. (The `aws_trilogy` ActiveRecord adapter does accept the string +mode names such as `verify_identity`.) See +[Configuring TLS/SSL](../configuring-tls) for the full per-driver table. + **PostgreSQL (`pg`):** ```ruby @@ -102,6 +112,10 @@ does **not** set this for you, so pass `enable_cleartext_plugin: true` when using the plugin with MySQL. Because the token is sent in cleartext, you must also use a TLS/SSL connection so it is encrypted in transit. This does not apply to PostgreSQL (`pg`). + +This applies to both MySQL drivers (`mysql2` and `trilogy`). On `trilogy`, +omitting `enable_cleartext_plugin: true` makes the driver raise +`Trilogy::AuthPluginError` and the token is never sent. ::: diff --git a/site/docs-ruby/using-plugins/kms-encryption.md b/site/docs-ruby/using-plugins/kms-encryption.md index 7c0afa6..02acc5d 100644 --- a/site/docs-ruby/using-plugins/kms-encryption.md +++ b/site/docs-ruby/using-plugins/kms-encryption.md @@ -20,6 +20,14 @@ column never holds plaintext. See [Server-side enforcement is required](#server- and [Enforce encryption in the database](#enforce-encryption-in-the-database) below. ::: +:::warning Not supported with the Trilogy driver +The plugin can encrypt a value only when it is sent as a bound parameter, which +requires prepared statements. The Trilogy driver does not support prepared +statements, so the plugin cannot be used with it: both the plugin and +`KeyManagementUtility` refuse a Trilogy connection with an explicit error. Use the +`mysql2` driver (or `pg` on PostgreSQL) for column encryption. +::: + :::info Available since Version 1.0.0 @@ -139,7 +147,8 @@ then use `Plugins::Encryption::KeyManagementUtility` to set up each column. ### Set up an encrypted column `KeyManagementUtility` runs on a plain `pg` or `mysql2` connection that you -open and close yourself. Build its configuration from the same `encryption_*` +open and close yourself. (It does not support `trilogy`, for the same +prepared-statement reason the plugin does not.) Build its configuration from the same `encryption_*` parameters the plugin uses, then create a master key and turn on encryption for an existing binary column: diff --git a/site/docs-ruby/using-plugins/okta-auth.md b/site/docs-ruby/using-plugins/okta-auth.md index 69f1a4f..5829e70 100644 --- a/site/docs-ruby/using-plugins/okta-auth.md +++ b/site/docs-ruby/using-plugins/okta-auth.md @@ -184,5 +184,13 @@ AwsAdvancedRubyDriverWrapper::WrapperMysql2Client.new( ) ``` +With the Trilogy driver, use +`AwsAdvancedRubyDriverWrapper::WrapperTrilogyClient`. `enable_cleartext_plugin: +true` is still required — without it Trilogy raises `Trilogy::AuthPluginError` +— but two TLS keys differ: the CA certificate is `ssl_ca` rather than `sslca`, +and on the direct client `ssl_mode` must be an integer constant +(`ssl_mode: Trilogy::SSL_VERIFY_IDENTITY`), not a string. See +[Configuring TLS/SSL](../configuring-tls). + For the full picture, see [Configuring TLS/SSL](../configuring-tls). diff --git a/site/src/components/ConfigBuilder/emitters.js b/site/src/components/ConfigBuilder/emitters.js index ff666d1..d9aba69 100644 --- a/site/src/components/ConfigBuilder/emitters.js +++ b/site/src/components/ConfigBuilder/emitters.js @@ -242,6 +242,15 @@ function directArgs(config, ctx, { reader }) { lines.push({ text: " failover_mode: 'strict-reader'", why: 'readers only' }); return; } + // The Trilogy driver's direct client takes ssl_mode as an integer constant + // (Trilogy::SSL_VERIFY_IDENTITY), not a string — a string or symbol raises + // TypeError. The aws_trilogy ActiveRecord adapter accepts the string names, + // so this applies only to the direct client. + if (engine === 'trilogy' && key === 'ssl_mode') { + const constant = `Trilogy::SSL_${String(cfg.params[key].value).toUpperCase()}`; + lines.push({ text: ` ${key}: ${constant}`, why: cfg.params[key].from }); + return; + } lines.push({ text: ` ${key}: ${rubyValue(cfg.params[key].value)}`, why: cfg.params[key].from }); }); return lines; diff --git a/site/src/components/ConfigBuilder/model.js b/site/src/components/ConfigBuilder/model.js index d81bda4..23a1eeb 100644 --- a/site/src/components/ConfigBuilder/model.js +++ b/site/src/components/ConfigBuilder/model.js @@ -151,7 +151,24 @@ export function buildConfig(data, state, active) { // The rules key on `deployment`; it comes from the db_type add-on, but only // when that selection is still valid under the current answers. const deployment = effectiveDeployment(data, state, active); - const axisState = { ...state, ...active, deployment }; + // Expose each exclusive add-on's current selection under its add-on id (e.g. + // `credentials: iam`), so a rule can emit configuration that depends on both + // an add-on choice and an axis — for example the cleartext client plugin that + // IAM authentication needs on MySQL but not PostgreSQL. Only a selection that + // actually applies is exposed: if the add-on or its chosen option is blocked + // (e.g. IAM on a community database), it is left out so no rule fires for it. + const baseState = { ...state, ...active, deployment }; + const addonSelections = {}; + for (const addon of data.addons || []) { + if (!addon.exclusive) continue; + const selected = state.addons[addon.id]; + if (!selected) continue; + if (blockReason(addon, baseState, data)) continue; + const option = (addon.options || []).find((o) => o.id === selected); + if (option && blockReason(option, baseState, data)) continue; + addonSelections[addon.id] = selected; + } + const axisState = { ...baseState, ...addonSelections }; for (const question of data.questions) { const chosen = active[question.id]; @@ -161,7 +178,7 @@ export function buildConfig(data, state, active) { } for (const rule of data.rules) { - if (condMet(rule.when, axisState)) applyPatch(config, rule.emit, 'your deployment', data); + if (condMet(rule.when, axisState)) applyPatch(config, rule.emit, rule.from || 'your deployment', data); } for (const addon of data.addons) { diff --git a/site/src/generated/scenarios-ruby.json b/site/src/generated/scenarios-ruby.json index 5b72d1e..da6be9f 100644 --- a/site/src/generated/scenarios-ruby.json +++ b/site/src/generated/scenarios-ruby.json @@ -3,31 +3,38 @@ "meta": { "engineLabel": { "pg": "PostgreSQL", - "mysql": "MySQL" + "mysql": "MySQL", + "trilogy": "MySQL" }, "adapter": { "pg": "aws_postgresql", - "mysql": "aws_mysql2" + "mysql": "aws_mysql2", + "trilogy": "aws_trilogy" }, "gem": { "pg": "pg", - "mysql": "mysql2" + "mysql": "mysql2", + "trilogy": "trilogy" }, "requirePath": { "pg": "aws_advanced_ruby_driver_wrapper/postgresql", - "mysql": "aws_advanced_ruby_driver_wrapper/mysql" + "mysql": "aws_advanced_ruby_driver_wrapper/mysql", + "trilogy": "aws_advanced_ruby_driver_wrapper/trilogy" }, "directClass": { "pg": "AwsAdvancedRubyDriverWrapper::WrapperPgConnection", - "mysql": "AwsAdvancedRubyDriverWrapper::WrapperMysql2Client" + "mysql": "AwsAdvancedRubyDriverWrapper::WrapperMysql2Client", + "trilogy": "AwsAdvancedRubyDriverWrapper::WrapperTrilogyClient" }, "standsIn": { "pg": "PG::Connection", - "mysql": "Mysql2::Client" + "mysql": "Mysql2::Client", + "trilogy": "Trilogy" }, "port": { "pg": 5432, - "mysql": 3306 + "mysql": 3306, + "trilogy": 3306 } }, "links": { @@ -229,6 +236,7 @@ "bgUnsupportedGlobal": "AWS does not support Blue/Green deployments with RDS Proxy on Aurora global databases, and the wrapper's Blue/Green plugin does not support global databases. Use a global switchover or failover instead.", "bgUnsupportedMultiAzCluster": "AWS Blue/Green deployments are not available for RDS Multi-AZ DB clusters (they are supported for Multi-AZ DB instance deployments).", "bgUnsupportedCommunity": "Blue/Green deployments are an Amazon RDS/Aurora feature. A community database you run yourself cannot be set up with one.", + "kmsUnsupportedTrilogy": "The KMS Encryption Plugin relies on prepared statements, which Trilogy does not support, so it cannot be used with the Trilogy driver. Use the mysql2 driver for column encryption.", "resultHeading": "Your configuration", "assumesHeading": "What this assumes", "pluginsHeading": "Why each plugin is here", @@ -280,7 +288,8 @@ "cluster_readonly" ], "engine": [ - "mysql" + "mysql", + "trilogy" ] }, "emit": { @@ -310,7 +319,8 @@ "global" ], "engine": [ - "mysql" + "mysql", + "trilogy" ] }, "emit": { @@ -340,7 +350,8 @@ "multi_az_cluster" ], "engine": [ - "mysql" + "mysql", + "trilogy" ] }, "emit": { @@ -374,7 +385,8 @@ "proxy" ], "engine": [ - "mysql" + "mysql", + "trilogy" ] }, "emit": { @@ -404,7 +416,8 @@ "community" ], "engine": [ - "mysql" + "mysql", + "trilogy" ] }, "emit": { @@ -413,6 +426,74 @@ } } }, + { + "when": { + "credentials": [ + "iam" + ], + "engine": [ + "mysql", + "trilogy" + ] + }, + "from": "required on MySQL: the IAM token is sent via mysql_clear_password", + "emit": { + "params": { + "enable_cleartext_plugin": true + } + } + }, + { + "when": { + "credentials": [ + "iam" + ], + "engine": [ + "pg" + ] + }, + "from": "recommended: encrypts the IAM token (sent as the password) in transit", + "emit": { + "params": { + "sslmode": "verify-full", + "sslrootcert": "" + } + } + }, + { + "when": { + "credentials": [ + "iam" + ], + "engine": [ + "mysql" + ] + }, + "from": "recommended: encrypts the IAM token (sent in cleartext) in transit", + "emit": { + "params": { + "ssl_mode": "verify_identity", + "sslca": "" + } + } + }, + { + "when": { + "credentials": [ + "iam" + ], + "engine": [ + "trilogy" + ] + }, + "from": "recommended: encrypts the IAM token (sent in cleartext) in transit", + "emit": { + "params": { + "ssl_mode": "verify_identity", + "ssl_ca": "" + } + } + }, { "when": { "continuity": [ @@ -599,7 +680,11 @@ }, { "id": "mysql", - "label": "MySQL" + "label": "MySQL (mysql2)" + }, + { + "id": "trilogy", + "label": "MySQL (Trilogy)" } ] }, @@ -644,7 +729,7 @@ }, { "id": "direct", - "label": "Through the pg or mysql2 gem directly", + "label": "Through the pg, mysql2, or trilogy gem directly", "short": "the gem directly", "hint": "The wrapper stands in for the gem's own connection class. There is no pool and no role concept, so both are yours to build.\n", "emit": { @@ -1194,6 +1279,16 @@ "toggle": true, "label": "Encrypt column values with AWS KMS", "short": "column encryption", + "blockedIf": [ + { + "when": { + "engine": [ + "trilogy" + ] + }, + "reason": "kmsUnsupportedTrilogy" + } + ], "emit": { "plugins": [ "kms_encryption"