Skip to content
This repository has been archived by the owner on Feb 5, 2020. It is now read-only.

Commit

Permalink
modules/aws: tighten security groups (#264)
Browse files Browse the repository at this point in the history
* modules/aws: tighten security groups

Currently masters and workers share a pretty open security group.
Furthermore workers expose ingress traffic at critical k8s ports like
10250 and 10255.

This fixes it by removing the common cluster default security group and
specifying separate ingress/egress rules reflecting settings from the
current tectonic installer.

It also assigns only one security group for masters and workers.

Fixes #248, #243, #227

* Documentation/generic-platform: change flannel port to 4789

... because that one is configured and recommended since it is the IANA
based one. Tools like tcpdump then decode vxlan packets natively.

The old port (8472) is retained as the default port in the kernel for
backwards compatibility purposes only, see [1].

Other projects also switched to the new IANA assigned port.

[1] http://lxr.free-electrons.com/source/drivers/net/vxlan.c#L43
  • Loading branch information
Sergiusz Urbaniak authored and alexsomesan committed Apr 19, 2017
1 parent 9a72640 commit b620c16
Show file tree
Hide file tree
Showing 18 changed files with 528 additions and 208 deletions.
4 changes: 2 additions & 2 deletions Documentation/generic-platform.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Master nodes run most, if not all, control plane components including the API se
- **Network:**
- Ingress
- MUST allow tcp port 22 [ssh] from user network
- MUST allow port 8472 (UDP) from masters & workers for flannel
- MUST allow port 4789 (UDP) from masters & workers for flannel
- MUST allow 32000-32002 from all for: Tectonic ingress (if using node ports for ingress like on AWS, otherwise use host ports on workers)
- SHOULD allow port 9100 from masters & workers for: Prometheus Node Exporter metrics
- MAY have tcp/udp port 30000-32767 [node port range open]
Expand Down Expand Up @@ -60,7 +60,7 @@ Worked nodes run all of the user applications. The only component they must run
- **Ingress**
- MUST allow all ports open to master nodes (TODO: be more specific)
- MUST have 30000 to 32767 host port range access open
- MUST allow port 8472 (UDP) from masters & workers for: VXLAN (flannel)
- MUST allow port 4789 (UDP) from masters & workers for: VXLAN (flannel)
- SHOULD allow port 10250 from masters for k8s features: port-forward, exec, proxy
- SHOULD allow port 9100 from masters & workers for: Prometheus Node Exporter metrics
- SHOULD allow port 4194 from masters for: Heapster connections to CAdvisor
Expand Down
38 changes: 0 additions & 38 deletions modules/aws/etcd/network.tf

This file was deleted.

2 changes: 1 addition & 1 deletion modules/aws/etcd/nodes.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ resource "aws_instance" "etcd_node" {
subnet_id = "${var.subnets[count.index % var.az_count]}"
key_name = "${var.ssh_key}"
user_data = "${ignition_config.etcd.*.rendered[count.index]}"
vpc_security_group_ids = ["${aws_security_group.etcd_sec_group.id}"]
vpc_security_group_ids = ["${var.sg_ids}"]

tags = "${merge(map(
"Name", "${var.cluster_name}-etcd-${count.index}",
Expand Down
9 changes: 5 additions & 4 deletions modules/aws/etcd/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ variable "instance_count" {
default = "3"
}

variable "vpc_id" {
type = "string"
}

variable "ssh_key" {
type = "string"
}
Expand Down Expand Up @@ -66,3 +62,8 @@ variable "root_volume_iops" {
type = "string"
description = "The amount of provisioned IOPS for the root block device."
}

variable "sg_ids" {
type = "list"
description = "The security group IDs to be applied."
}
13 changes: 3 additions & 10 deletions modules/aws/master-asg/elb.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ resource "aws_elb" "api-internal" {
name = "${var.cluster_name}-api-internal"
subnets = ["${var.subnet_ids}"]
internal = true
security_groups = ["${aws_security_group.master_sec_group.id}"]
security_groups = ["${var.api_sg_ids}"]

listener {
instance_port = 443
Expand All @@ -11,13 +11,6 @@ resource "aws_elb" "api-internal" {
lb_protocol = "tcp"
}

listener {
instance_port = 10255
instance_protocol = "tcp"
lb_port = 10255
lb_protocol = "tcp"
}

health_check {
healthy_threshold = 2
unhealthy_threshold = 2
Expand Down Expand Up @@ -49,7 +42,7 @@ resource "aws_elb" "api-external" {
name = "${var.custom_dns_name == "" ? var.cluster_name : var.custom_dns_name}-api-external"
subnets = ["${var.subnet_ids}"]
internal = false
security_groups = ["${aws_security_group.master_sec_group.id}"]
security_groups = ["${var.api_sg_ids}"]

listener {
instance_port = 22
Expand Down Expand Up @@ -96,7 +89,7 @@ resource "aws_elb" "console" {
name = "${var.custom_dns_name == "" ? var.cluster_name : var.custom_dns_name}-console"
subnets = ["${var.subnet_ids}"]
internal = "${var.public_vpc ? false : true}"
security_groups = ["${aws_security_group.master_sec_group.id}"]
security_groups = ["${var.console_sg_ids}"]

listener {
instance_port = 32001
Expand Down
51 changes: 1 addition & 50 deletions modules/aws/master-asg/master.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ data "aws_ami" "coreos_ami" {
}
}

data "aws_vpc" "cluster_vpc" {
id = "${var.vpc_id}"
}

resource "aws_autoscaling_group" "masters" {
name = "${var.cluster_name}-masters"
desired_capacity = "${var.instance_count}"
Expand Down Expand Up @@ -60,7 +56,7 @@ resource "aws_launch_configuration" "master_conf" {
image_id = "${data.aws_ami.coreos_ami.image_id}"
name_prefix = "${var.cluster_name}-master-"
key_name = "${var.ssh_key}"
security_groups = ["${concat(list(aws_security_group.master_sec_group.id), var.extra_sg_ids)}"]
security_groups = ["${var.master_sg_ids}"]
iam_instance_profile = "${aws_iam_instance_profile.master_profile.arn}"
associate_public_ip_address = "${var.public_vpc}"
user_data = "${var.user_data}"
Expand All @@ -76,51 +72,6 @@ resource "aws_launch_configuration" "master_conf" {
}
}

resource "aws_security_group" "master_sec_group" {
vpc_id = "${data.aws_vpc.cluster_vpc.id}"

tags = "${merge(map(
"Name", "${var.cluster_name}_master_sg",
"KubernetesCluster", "${var.cluster_name}"
), var.extra_tags)}"

ingress {
protocol = -1
self = true
from_port = 0
to_port = 0
}

ingress {
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
from_port = 22
to_port = 22
}

ingress {
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
from_port = 443
to_port = 443
}

ingress {
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
from_port = 10255
to_port = 10255
}

egress {
from_port = 0
to_port = 0
protocol = "-1"
self = true
cidr_blocks = ["0.0.0.0/0"]
}
}

resource "aws_iam_instance_profile" "master_profile" {
name = "${var.cluster_name}-master-profile"
roles = ["${aws_iam_role.master_role.name}"]
Expand Down
21 changes: 14 additions & 7 deletions modules/aws/master-asg/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ variable "ssh_key" {
type = "string"
}

variable "vpc_id" {
type = "string"
}

variable "cl_channel" {
type = "string"
}
Expand All @@ -26,8 +22,19 @@ variable "subnet_ids" {
type = "list"
}

variable "extra_sg_ids" {
type = "list"
variable "master_sg_ids" {
type = "list"
description = "The security group IDs to be applied to the master nodes."
}

variable "api_sg_ids" {
type = "list"
description = "The security group IDs to be applied to the public facing ELB."
}

variable "console_sg_ids" {
type = "list"
description = "The security group IDs to be applied to the console ELB."
}

variable "base_domain" {
Expand All @@ -51,7 +58,7 @@ variable "user_data" {
}

variable "public_vpc" {
description = "If set to true, public facing ingress resource are created."
description = "If set to true, public facing ingress resources are created."
default = true
}

Expand Down
26 changes: 21 additions & 5 deletions modules/aws/vpc/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
output "vpc_id" {
value = "${length(var.external_vpc_id) > 0 ? var.external_vpc_id : join(" ", aws_vpc.new_vpc.*.id)}"
}

output "cluster_default_sg" {
value = "${aws_security_group.cluster_default.id}"
value = "${data.aws_vpc.cluster_vpc.id}"
}

# We have to do this join() & split() 'trick' because null_data_source and
Expand All @@ -15,3 +11,23 @@ output "master_subnet_ids" {
output "worker_subnet_ids" {
value = ["${split(",", var.external_vpc_id == "" ? join(",", aws_subnet.worker_subnet.*.id) : join(",", data.aws_subnet.external_worker.*.id))}"]
}

output "etcd_sg_id" {
value = "${aws_security_group.etcd.id}"
}

output "master_sg_id" {
value = "${aws_security_group.master.id}"
}

output "worker_sg_id" {
value = "${aws_security_group.worker.id}"
}

output "api_sg_id" {
value = "${aws_security_group.api.id}"
}

output "console_sg_id" {
value = "${aws_security_group.console.id}"
}
23 changes: 0 additions & 23 deletions modules/aws/vpc/security-groups.tf

This file was deleted.

54 changes: 54 additions & 0 deletions modules/aws/vpc/sg-elb.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
resource "aws_security_group" "api" {
vpc_id = "${data.aws_vpc.cluster_vpc.id}"

tags = "${merge(map(
"Name", "${var.cluster_name}_api_sg",
"KubernetesCluster", "${var.cluster_name}"
), var.extra_tags)}"

egress {
from_port = 0
to_port = 0
protocol = "-1"
self = true
cidr_blocks = ["0.0.0.0/0"]
}

ingress {
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
from_port = 443
to_port = 443
}
}

resource "aws_security_group" "console" {
vpc_id = "${data.aws_vpc.cluster_vpc.id}"

tags = "${merge(map(
"Name", "${var.cluster_name}_console_sg",
"KubernetesCluster", "${var.cluster_name}"
), var.extra_tags)}"

egress {
from_port = 0
to_port = 0
protocol = "-1"
self = true
cidr_blocks = ["0.0.0.0/0"]
}

ingress {
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
from_port = 80
to_port = 80
}

ingress {
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
from_port = 443
to_port = 443
}
}
Loading

0 comments on commit b620c16

Please sign in to comment.