getwilds / sixtyfour

🚚 CEO, entrepreneur
https://getwilds.org/sixtyfour/
Other
11 stars 2 forks source link

Secrets manager plus usage in RDS create #32

Closed sckott closed 8 months ago

sckott commented 9 months ago

@seankross Here's the high level changes here:

Add family of functions for AWS secrets manager

fix #29

Integrate secrets into RDS database create

Redshift uses the user's IAM credentials so I think it only makes sense to use secrets manager in RDS.

So aws_db_rds_create now allows the user to not pass in a user or password, and we create them for the user. Likewise, aws_db_rds_con automatically detects secrets in the users aws secrets manager and presents those in a prompt and asks which one they'd like to use, an example:

Make the DB

aws_db_rds_create(
  id = "pineapple", class = "db.t3.micro",
  security_group_ids = list("sg-xxx")
)

#> i `user` is NULL; created user: EvergreenMartyrd
#> i `pwd` is NULL; created password: *******
#> i Uploading user/pwd to secrets manager
#> Instance is up!
#> i See `aws_db_rds_con` for connection info
#> i Instance details:
#> i   host:
#> i   port:
#> i   dbname: dev
#> i   engine: mariadb
#> i   class: db.t3.micro

Get the conn

con_rds <- aws_db_rds_con(id = "pineapple")
#> No credentials were supplied
#> We found 2 in your AWS secrets manager
#> Which set of database credentials do you want to use?
#> 
#> 1: Secret name: bean-a60f072a
#>    Engine: mariadb
#>    Host: bean.xxxx.us-west-2.rds.amazonaws.com
#> 2: Secret name: abear-4027ba84
#>    Engine: mariadb
#>    Host: abear.xxxx.us-west-2.rds.amazonaws.com
#> 
#> Selection:

Secrets management

sckott commented 9 months ago

sean feedback

sckott commented 8 months ago

workflow from sean:

aws_user_create("scott") # exists
aws_db_rds_create("aaa", "mariadb") # exists
add_user_to_rds_db("scott") # DOES NOT EXIST
aws_db_rds_list() # exists
#> # A tibble: 2 × 5
#>   DBInstanceIdentifier DBInstanceClass Engine  DBInstanceStatus DBName
#>   <chr>                <chr>           <chr>   <chr>            <chr>
#> 1 aaa                db.t3.micro      mariadb available         dev
#> 2 bbb                db.t3.micro      mariadb available         dev
con <- aws_db_rds_con("aaa") # exists
# do things with DBI/dplyr/etc

3 steps that need to happen for connecting to a DB instance using IAM authentication::

  1. Enabling and disabling IAM database authentication
    • done with fxn: aws_db_rds_create with arg iam_database_auth=TRUE (possibly on by default?)
  2. Creating and using an IAM policy for IAM database access
    • done with fxns: document_create, aws_policy_create, aws_policy_attach
  3. Creating a database account using IAM authentication
    • done with fxn: not sure yet, a SQL eg for mariadb is CREATE USER jane_doe IDENTIFIED WITH AWSAuthenticationPlugin AS 'RDS';

Probably add_user_to_rds_db("scott") could handle steps 2 and 3

sckott commented 8 months ago

Going to try to split up this PR or possibly close and create two new ones for: