Skip to content
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

Add support for Redshift IAM authentication #6479

Merged
merged 3 commits into from
Apr 26, 2021
Merged

Add support for Redshift IAM authentication #6479

merged 3 commits into from
Apr 26, 2021

Conversation

r0mant
Copy link
Collaborator

@r0mant r0mant commented Apr 16, 2021

This PR adds support for AWS Redshift IAM authentication to database access.

Redshift supports IAM authentication, but not in the same way as RDS/Aurora. There is a separate API to request Redshift IAM token, GetClusterCredentials. Other than that, Redshift speaks Postgres compatible protocol so psql works as usual, at least in my tests.

Redshift requires one additional parameter in the config, cluster ID, so users would configure it like this (and database agent determines whether this is a Redshift database by the presence of this field):

db_service:
  enabled: "yes"
  databases:
  - name: "redshift"
    protocol: "postgres"
    uri: "redshift-cluster-1.xxx.us-east-1.redshift.amazonaws.com:5439"
    aws:
      region: "us-east-1"
      redshift:
        cluster_id: "redshift-cluster-1"

The actual logic to generate Redshift auth token is actually very small and isolated in the same Auth interface that already generates tokens for RDS and Cloud SQL. But some extra related changes were required:

  • Automatic downloading of Redshift CA, similar to how it was done for RDS so users don't need to download the file themselves.
  • Better management of AWS sessions. Previously, we would just open one AWS session to the "current" region which would cause issues if you had RDS/Aurora/Redshift databases in multiple regions. Now database agent keeps sessions to each needed region depending on what kinds of databases it proxies.
  • I've also refactored database service unit tests quite heavily to be able to test functionality with generating auth tokens and using them for authentication. It turned out pretty cool, I can now configure individual tests with any kinds of databases they need.

Fixes #6029 and needs backport to v6.

@r0mant r0mant added backport-required database-access Database access related issues and PRs labels Apr 16, 2021
@r0mant r0mant added this to the 6.2 "Buffalo" milestone Apr 16, 2021
@r0mant r0mant requested review from awly and fspmarshall April 16, 2021 00:28
@r0mant r0mant self-assigned this Apr 16, 2021
lib/srv/db/access_test.go Outdated Show resolved Hide resolved
lib/srv/db/access_test.go Outdated Show resolved Hide resolved
lib/srv/db/access_test.go Show resolved Hide resolved
lib/srv/db/auth_test.go Outdated Show resolved Hide resolved
lib/srv/db/auth_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@fspmarshall fspmarshall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a couple minor nits. Looks good overall.

lib/srv/db/common/test.go Outdated Show resolved Hide resolved
lib/srv/db/server.go Outdated Show resolved Hide resolved
lib/srv/db/server.go Outdated Show resolved Hide resolved
Copy link
Contributor

@russjones russjones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bot.

@r0mant r0mant enabled auto-merge (squash) April 23, 2021 17:08
@r0mant r0mant merged commit a3d39e3 into master Apr 26, 2021
@r0mant r0mant deleted the roman/redshift branch April 26, 2021 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-required database-access Database access related issues and PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Investigate Redshift support for database access
4 participants