|
| 1 | +--- |
| 2 | +title: AWS RDS Enrollment Wizard |
| 3 | +description: Enroll AWS RDS databases with your Teleport cluster using an enrollment wizard. |
| 4 | +tocDepth: 3 |
| 5 | +--- |
| 6 | + |
| 7 | +The AWS RDS enrollment wizard is available in your Teleport cluster Web UI as |
| 8 | +part of the [AWS OIDC integration](./awsoidc-integration.mdx). |
| 9 | + |
| 10 | +The enrollment wizard configures AWS IAM resources and deploys a Teleport |
| 11 | +Database Service instance on ECS Fargate to proxy connections to Amazon RDS |
| 12 | +databases. |
| 13 | + |
| 14 | +The enrollment wizard can be used to enroll RDS databases in a Teleport cluster. |
| 15 | +It's also useful as an example of a serverless Teleport Database Service |
| 16 | +deployment on ECS. |
| 17 | + |
| 18 | +## How it works |
| 19 | + |
| 20 | +### AWS OIDC Integration |
| 21 | + |
| 22 | +The RDS enrollment wizard depends on the |
| 23 | +[AWS OIDC integration](./awsoidc-integration.mdx). |
| 24 | +The AWS OIDC integration creates and configures an AWS IAM OpenID Connect |
| 25 | +Identity Provider (OIDC IdP) and an AWS IAM role that your Teleport cluster can |
| 26 | +assume. |
| 27 | + |
| 28 | +The RDS enrollment wizard adds permissions to the AWS OIDC integration IAM role |
| 29 | +to list RDS databases and VPC resources like subnets and security groups and |
| 30 | +to deploy an Amazon ECS service. |
| 31 | + |
| 32 | +Once the integration role permissions are configured, the wizard walks you |
| 33 | +through enrolling database(s) and deploying the Teleport Database Service in a |
| 34 | +high availability (HA) setup on AWS Fargate for Amazon ECS. |
| 35 | + |
| 36 | +### Dynamic Database Enrollment |
| 37 | + |
| 38 | +Whether you choose to enroll a single database or enroll all databases using |
| 39 | +auto-discovery, the wizard enrolls database(s) by creating `db` objects in your |
| 40 | +Teleport cluster. |
| 41 | +You can view detailed information about them with `tctl`: |
| 42 | + |
| 43 | +```code |
| 44 | +$ tctl get db/<database name> |
| 45 | +``` |
| 46 | + |
| 47 | +### Teleport Database Service Deployment |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | +In the "Deploy Database Service" step, the wizard guides you through creating |
| 52 | +and configuring the ECS Fargate deployment. |
| 53 | + |
| 54 | +The wizard generates a script for you to run, which will create an IAM role for |
| 55 | +Teleport Database Service instances to use. |
| 56 | +The IAM role has permissions to output logs in ECS, describe RDS databases, and |
| 57 | +connect to RDS databases. |
| 58 | + |
| 59 | +You then choose subnets and security groups for the deployment on ECS Fargate. |
| 60 | + |
| 61 | +When you click "Deploy Teleport Service" the wizard creates an ECS task |
| 62 | +definition that includes various settings for configuring and starting a |
| 63 | +Teleport Database Service instance. |
| 64 | +The task definition uses the IAM role created in the first step as both the |
| 65 | +[ECS task execution role](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_execution_IAM_role.html). |
| 66 | +and the |
| 67 | +[ECS task role](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-iam-roles.html) |
| 68 | + |
| 69 | +The wizard then creates an ECS deployment in the same AWS VPC as your RDS |
| 70 | +databases, configured to use the subnets and security groups you chose. |
| 71 | +The ECS deployment is configured to run two replicas of the Teleport Database |
| 72 | +Service task definition for an HA setup. |
| 73 | +By deploying the Teleport Database Service instances in the same VPC as the RDS |
| 74 | +databases, the instances can connect to databases in private subnets. |
| 75 | +Note that the database security group rules must allow inbound traffic from the |
| 76 | +ECS tasks as well. |
| 77 | + |
| 78 | +Once an ECS task starts, it pulls the Teleport image and starts `teleport`. |
| 79 | +The Teleport Database Service instance then establishes a tunnel connection to |
| 80 | +your Teleport cluster and starts accepting connections from authorized |
| 81 | +Teleport users to connect to the database(s) it proxies. |
| 82 | + |
| 83 | +This is a serverless HA approach to deploying the Teleport Database Service. |
| 84 | +It does not require any allowed inbound traffic from the internet and supports |
| 85 | +[automatic agent upgrades](../../../upgrading/automatic-agent-updates.mdx). |
| 86 | + |
| 87 | +The Teleport Database Service instances are configured to use |
| 88 | +[dynamic database registration](../../../enroll-resources/database-access/guides/dynamic-registration.mdx) |
| 89 | +so that you can enroll or disenroll databases without restarting or modifying |
| 90 | +the deployment. |
| 91 | +The instances will match and proxy connections for all dynamic `db` resources in |
| 92 | +Teleport that have the following labels: |
| 93 | + |
| 94 | +```yaml |
| 95 | +account-id: "<AWS account ID>" |
| 96 | +region: "<AWS region>" |
| 97 | +vpc-id: "<AWS VPC ID>" |
| 98 | +``` |
| 99 | +
|
| 100 | +The `db` object(s) created by the wizard will have these labels, so the Teleport |
| 101 | +Database Service instances will match them and proxy connections to them. |
| 102 | + |
| 103 | +### AWS Resource Tags |
| 104 | + |
| 105 | +AWS resources created by the RDS enrollment wizard are tagged in AWS so that you |
| 106 | +can search and export them using the |
| 107 | +[AWS Resource Groups / Tag Editor](https://console.aws.amazon.com/resource-groups/tag-editor/find-resources). |
| 108 | +The following tags are applied: |
| 109 | + |
| 110 | +```yaml |
| 111 | +teleport.dev/cluster: <Var name="cluster-name"/> |
| 112 | +teleport.dev/origin: integration_awsoidc |
| 113 | +teleport.dev/integration: <Var name="my-integration"/> |
| 114 | +``` |
| 115 | + |
| 116 | +You can also search for AWS resources created by the wizard using the `aws` cli: |
| 117 | + |
| 118 | +```code |
| 119 | +$ aws resourcegroupstaggingapi get-resources \ |
| 120 | +--region <Var name="us-west-1"/> \ |
| 121 | +--tag-filters \ |
| 122 | +Key=teleport.dev/cluster,Values=<Var name="cluster-name"/> \ |
| 123 | +Key=teleport.dev/integration,Values=<Var name="my-integration"/> \ |
| 124 | +Key=teleport.dev/origin,Values=integration_awsoidc |
| 125 | +``` |
| 126 | + |
| 127 | +## Prerequisites |
| 128 | + |
| 129 | +- A running Teleport cluster |
| 130 | +- An AWS account and permissions to create IAM Identity Providers and roles |
| 131 | + |
| 132 | +## Step 1/2. Configure RBAC |
| 133 | + |
| 134 | +The RDS enrollment wizard is a part of the AWS OIDC integration. |
| 135 | +You will need the following allow rules in one of your Teleport roles. |
| 136 | +These are available by default in the preset `editor` role: |
| 137 | + |
| 138 | +```yaml |
| 139 | +kind: role |
| 140 | +version: v7 |
| 141 | +metadata: |
| 142 | + name: example |
| 143 | +spec: |
| 144 | + allow: |
| 145 | + rules: |
| 146 | + - resources: |
| 147 | + - integration |
| 148 | + verbs: |
| 149 | + - create |
| 150 | + - update |
| 151 | + - list |
| 152 | + - read |
| 153 | +``` |
| 154 | + |
| 155 | +## Step 2/2. Visit the Web UI |
| 156 | + |
| 157 | +The RDS enrollment wizard is available in the "Add new resource" panel of the |
| 158 | +Teleport Web UI: |
| 159 | + |
| 160 | + |
| 161 | + |
| 162 | +The Teleport Web UI walks you through the steps to set up an AWS OIDC |
| 163 | +integration (if you don't have one already), configure IAM permissions, create |
| 164 | +an ECS deployment in your AWS account, and run a database connection test. |
| 165 | + |
| 166 | +## Troubleshooting |
| 167 | + |
| 168 | +The enrollment wizard waits for the ECS deployment tasks to start and connect to |
| 169 | +your Teleport cluster. |
| 170 | +If that does not happen, then either the ECS tasks have failed to start or they |
| 171 | +do not have network connectivity to your Teleport cluster. |
| 172 | +You should inspect the ECS deployment to troubleshoot the issue further. |
| 173 | + |
| 174 | +Most of the troubleshooting steps below assume you already know how to find |
| 175 | +the ECS deployment and get more information about what is happening in ECS. |
| 176 | +If you do not know how to find the ECS deployment, then first read about |
| 177 | +[how to find the ECS deployment](#how-to-find-the-ecs-deployment). |
| 178 | + |
| 179 | +### How to find the ECS deployment |
| 180 | + |
| 181 | +Navigate to the ECS service in AWS: https://console.aws.amazon.com/ecs/v2/clusters. |
| 182 | +Make sure you select the same AWS region that you selected at the start of the |
| 183 | +RDS enrollment wizard. |
| 184 | + |
| 185 | +The ECS cluster that the wizard created will be named after your Teleport |
| 186 | +cluster except with dots `.` replaced with underscores `_` and the additional |
| 187 | +suffix `-teleport`. |
| 188 | +For example if your Teleport cluster is named |
| 189 | +`example.teleport.sh`, then the corresponding ECS cluster will be named |
| 190 | +`example_teleport_sh-teleport`. |
| 191 | + |
| 192 | +Click on your ECS cluster: |
| 193 | + |
| 194 | + |
| 195 | + |
| 196 | +An ECS cluster is composed of one or more ECS services. |
| 197 | +Click on the service named after the VPC you chose in the enrollment wizard - |
| 198 | +the VPC ID is used as the suffix of the corresponding ECS service name, e.g |
| 199 | +`database-service-vpc-123456789abcdefgh`: |
| 200 | + |
| 201 | + |
| 202 | + |
| 203 | +In the ECS service overview page you should click on the "Tasks" panel to see |
| 204 | +the deployment tasks. |
| 205 | +There should be two tasks either running or pending: |
| 206 | + |
| 207 | + |
| 208 | + |
| 209 | +If you don't see any tasks, then proceed to |
| 210 | +[ECS tasks not running](#ecs-tasks-not-running). |
| 211 | + |
| 212 | +### How to find Teleport Database Service logs |
| 213 | + |
| 214 | +Each ECS task is a replica of the Teleport Database Service task definition. |
| 215 | +[Navigate to the ECS service tasks page](#how-to-find-the-ecs-deployment) |
| 216 | +and click on one of the running tasks. |
| 217 | +On the task overview page, click the "Logs" panel to see logs being emitted |
| 218 | +to Amazon CloudWatch: |
| 219 | + |
| 220 | + |
| 221 | + |
| 222 | +On this page you have to refresh the logs to see new output. |
| 223 | +You can click "View in CloudWatch" and then start tailing the logs on that page |
| 224 | +to watch for new log output automatically. |
| 225 | + |
| 226 | +### ECS tasks not running |
| 227 | + |
| 228 | +If you see that the tasks in your deployment remain in a "pending" state or have |
| 229 | +stopped, then you should check individual tasks to see what is blocking them |
| 230 | +from starting. |
| 231 | + |
| 232 | +Navigate to the ECS deployment tasks panel, select the "Filter desired status" |
| 233 | +dropdown, and choose "Any desired status". |
| 234 | +You should see all tasks now, including tasks that are not running: |
| 235 | + |
| 236 | + |
| 237 | + |
| 238 | +Click on a task that is stopped to see why it stopped. AWS will display an error |
| 239 | +message explaining what went wrong. |
| 240 | + |
| 241 | +Typically an error message only appears after the task has been stopped by ECS, |
| 242 | +which may take a few minutes after it enters the "Pending" state. |
| 243 | + |
| 244 | +The most common failure is that a task cannot pull the Teleport image: |
| 245 | + |
| 246 | +```code |
| 247 | +CannotPullContainerError: pull image manifest has been retried 5 time(s): failed to resolve ref public.ecr.aws/gravitational/teleport-ent-distroless:16.4.3: failed to do request: Head "https://public.ecr.aws/v2/gravitational/teleport-ent-distroless/manifests/16.4.3": dial tcp 99.83.145.10:443: i/o timeout |
| 248 | +``` |
| 249 | + |
| 250 | +This is caused by a network connectivity issue that prevents the ECS task from |
| 251 | +reaching the public Teleport image repository. |
| 252 | + |
| 253 | +You may need to use different security groups or subnets for the deployment, but |
| 254 | +you cannot update the ECS service networking configuration in the AWS console. |
| 255 | +Fortunately, you can redeploy the ECS service from the RDS enrollment wizard in |
| 256 | +Teleport and it will recreate the ECS service for you with updated network |
| 257 | +settings. |
| 258 | +Doing so will trigger a new ECS deployment rollout, which will only tear down |
| 259 | +running tasks from a prior deployment after new tasks have started. |
| 260 | + |
| 261 | +Navigate to the ECS service network setting located under "Configuration and networking": |
| 262 | + |
| 263 | + |
| 264 | + |
| 265 | +Check that the ECS service's security groups allow outbound internet access. |
| 266 | +Remember that AWS security group rules are additive, meaning that if you selected |
| 267 | +multiple security groups then only one of them needs to have an outbound rule |
| 268 | +like the following in order to establish an outbound connection to the Teleport |
| 269 | +image repository: |
| 270 | + |
| 271 | + |
| 272 | + |
| 273 | +Next, check that the ECS task subnets have access to the internet. |
| 274 | +There must be a network route to either an internet gateway or a NAT gateway. |
| 275 | +Make a note of the list of subnets and navigate to the VPC overview page to |
| 276 | +check each of them: |
| 277 | + |
| 278 | + |
| 279 | + |
| 280 | +You may need to create a NAT gateway or internet gateway, update your routing |
| 281 | +table(s), or use different subnets for the ECS service. |
| 282 | + |
| 283 | +Finally, check that the network Access Control Lists (ACLs) associated with the |
| 284 | +ECS service's subnets allow outbound traffic to the internet as well. |
| 285 | +Network ACLs allow all inbound and outbound traffic by default, so this should |
| 286 | +only be a potential cause of network problems if you have customized your |
| 287 | +network ACLs. |
| 288 | + |
| 289 | +Once network connectivity from the ECS service to the Teleport image repository |
| 290 | +is established, ECS tasks should successfully start on their own after some |
| 291 | +time. |
| 292 | + |
| 293 | +### Database connection test timeout |
| 294 | + |
| 295 | +If you test the connection to a database and the connection times out, then |
| 296 | +you need to fix network connectivity to the database from the ECS deployment. |
| 297 | + |
| 298 | +For example, this is what it looks like when an ECS deployment task cannot reach |
| 299 | +an RDS postgres database because an AWS security group is blocking the |
| 300 | +connection: |
| 301 | + |
| 302 | + |
| 303 | + |
| 304 | +The most common cause of this error is that the security group rules attached to |
| 305 | +the RDS database do not allow inbound traffic from the ECS task. |
| 306 | + |
| 307 | +The easiest way to fix that problem is to add an inbound rule to one of the RDS |
| 308 | +database's security groups that allows traffic from one of the security groups |
| 309 | +associated with your ECS service. |
| 310 | +Here's what that might look like in AWS: |
| 311 | + |
| 312 | + |
| 313 | + |
| 314 | +You can also run the AWS reachability analyzer to diagnose network problems. |
| 315 | +Navigate to your ECS service and click on one of the tasks, then choose the |
| 316 | +"Networking" tab and click "Run Reachability Analyzer": |
| 317 | + |
| 318 | + |
| 319 | + |
| 320 | +On the analyzer path creation page, the "Path Source" should be automatically |
| 321 | +populated with the AWS Elastic Network Interface (ENI) of the ECS task. |
| 322 | + |
| 323 | +Set the "Path destination" to the ENI associated with your database. |
| 324 | +To find the database ENI, navigate to the |
| 325 | +[ENI overview](https://console.aws.amazon.com/ec2/home#NIC) |
| 326 | +(make sure you have the right AWS region selected) and search for "RDS". |
| 327 | + |
| 328 | +Create the network analyzer path and run it. |
| 329 | +After a short delay, the analysis results will be available, but you may need to |
| 330 | +click the refresh icon a few times. |
| 331 | + |
| 332 | +For example, this is what it looks like when the database security groups |
| 333 | +don't allow inbound traffic from the ECS service task: |
| 334 | + |
| 335 | + |
| 336 | + |
| 337 | +## Next steps |
| 338 | + |
| 339 | +(!docs/pages/includes/database-access/guides-next-steps.mdx!) |
| 340 | +- Set up [automatic database user provisioning](../../../enroll-resources/database-access/auto-user-provisioning/auto-user-provisioning.mdx). |
0 commit comments