Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion content/compatibility.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions content/dev-guide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
29 changes: 17 additions & 12 deletions content/failover.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ 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:
- lang: ruby
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand Down
41 changes: 40 additions & 1 deletion content/plugins.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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).

# =========================================================================
Expand Down Expand Up @@ -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).

# =========================================================================
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:

Expand Down
52 changes: 38 additions & 14 deletions content/scenarios.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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: "<path/to/global-bundle.pem>" } }
- when: { credentials: [iam], engine: [mysql] }
from: "recommended: encrypts the IAM token (sent in cleartext) in transit"
emit: { params: { ssl_mode: verify_identity, sslca: "<path/to/global-bundle.pem>" } }
- when: { credentials: [iam], engine: [trilogy] }
from: "recommended: encrypts the IAM token (sent in cleartext) in transit"
emit: { params: { ssl_mode: verify_identity, ssl_ca: "<path/to/global-bundle.pem>" } }

# --- resolving the cluster endpoint to a real instance at connect time
- when: { continuity: [instance, region], deployment: [cluster, cluster_readonly, global, multi_az_cluster] }
emit:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
18 changes: 17 additions & 1 deletion content/templates/configuring-tls.md.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down
Loading
Loading