You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+78
Original file line number
Diff line number
Diff line change
@@ -67,6 +67,84 @@ To address this, our user data script configures both a maximum journal size and
67
67
68
68
👀 To view these metrics, navigate in the AWS Console to “CWAgent” → “AutoScalingGroupName, ImageId, InstanceId, InstanceType, device, fstype, path” → “disk_used_percent” for the root path “/”.
69
69
70
+
## Direct and Relayed Connections
71
+
72
+
Tailscale supports two primary types of [connection types](https://tailscale.com/kb/1257/connection-types) for subnet routers:
73
+
74
+
-**Direct (peer-to-peer)**: Nodes communicate directly with each other when possible, offering better performance and reliability.
75
+
-**Relayed**: Traffic is routed through Tailscale's DERP (Designated Encrypted Relay for Packets) servers when direct connectivity isn't possible (e.g. when the subnet router is in a private VPC subnet).
76
+
77
+
### Addressing Connection Stability Issues
78
+
79
+
We've been using relayed connections for our subnet routers, but we've observed that relayed connections can sometimes cause intermittent connectivity issues, particularly when working with database connections through the Tailscale proxy (see [this issue](https://github.com/cyrilgdn/terraform-provider-postgresql/issues/495) for an example).
80
+
81
+
These issues appear as connection timeouts or SOCKS server errors:
82
+
83
+
```sh
84
+
│ Error: Error connecting to PostgreSQL server dev.example.com (scheme: postgres): socks connect tcp localhost:1055->dev.example.com:5432: unknown error general SOCKS server failure
85
+
│
86
+
│ with data.postgresql_schemas.schemas["example"],
87
+
│ on main.tf line 65, in data "postgresql_schemas""schemas":
88
+
│ 65: data "postgresql_schemas""schemas" {
89
+
│
90
+
╵
91
+
netstack: decrementing connsInFlightByClient[100.0.108.92] because the packet was not handled; new value is 0
92
+
[RATELIMIT] format("netstack: decrementing connsInFlightByClient[%v] because the packet was not handled; new value is %d")
93
+
```
94
+
95
+
### Configuring Direct Connections
96
+
97
+
To optimize fordirect connectionsin your Tailscale subnet router, follow this example:
subnet_ids = local.public_subnets # Ensure subnet router is in a public subnet
112
+
113
+
additional_security_group_ids = [module.direct_sg.id] # Attach the security group to the subnet router
114
+
tailscaled_extra_flags = ["--port=${local.direct_port}"] # Ensure `tailscaled` listens on the same port as the security group is configured
115
+
116
+
context = module.this.context
117
+
}
118
+
119
+
module "direct_sg" {
120
+
source = "cloudposse/security-group/aws"
121
+
version = "2.2.0"
122
+
enabled = true
123
+
124
+
vpc_id = local.vpc_id
125
+
attributes = ["tailscale", "direct"]
126
+
127
+
rules = [{
128
+
key ="direct_ingress"
129
+
type="ingress"
130
+
from_port = local.direct_port
131
+
to_port = local.direct_port
132
+
protocol ="udp"
133
+
cidr_blocks = ["0.0.0.0/0"]
134
+
description ="Allow a direct Tailscale connection from any peer."
135
+
}]
136
+
137
+
context = module.this.context
138
+
}
139
+
```
140
+
141
+
The above configuration ensures that the subnet router can establish direct connections with other Tailscale nodes:
142
+
143
+
1. It is in a public subnet and gets a public IP address.
144
+
2. The security group is attached and configured to listen on a fixed port.
145
+
3. The `tailscaled` daemon is configured to listen on the same port as the security group is configured to listen on.
146
+
4. The outgoing UDP and TCP packets on port `443` are permitted. In our example, [`cloudposse/security-group/aws`](https://github.com/cloudposse/terraform-aws-security-group) module allows all egress.
147
+
70
148
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
0 commit comments