Bläddra i källkod

Initial Phantom Module

* Creates instance now called 'phantom-server'
* Creates ALB for phantom.pvt.xdr{test}.accenturefederalcyber.com
* Creates DNS entries for above

Will eventually be tagged v1.22.0, but not yet.
Fred Damstra 4 år sedan
förälder
incheckning
d74efebb1b

+ 141 - 0
base/phantom/alb.tf

@@ -0,0 +1,141 @@
+#----------------------------------------------------------------------------
+# INTERNAL LB
+#----------------------------------------------------------------------------
+resource "aws_alb" "phantom_internal" {
+  name               = "phantom-alb-internal-${var.environment}"
+  security_groups    = [ aws_security_group.phantom_alb_internal.id ]
+  internal           = true 
+  subnets            = var.public_subnets
+  load_balancer_type = "application"
+
+  access_logs {
+    bucket  = "xdr-elb-${ var.environment }"
+    enabled = true
+  }
+
+  idle_timeout = 1200
+
+  tags = merge(var.standard_tags, var.tags, { Name = "phantom-alb-internal-${var.environment}" })
+}
+
+# Create a new target group
+resource "aws_alb_target_group" "phantom_internal" {
+  name                 = "phantom-alb-targets"
+  port                 = 443
+  protocol             = "HTTPS"
+  vpc_id               = var.vpc_id
+
+  health_check {
+    protocol = "HTTPS"
+    port     = "443"
+    path     = "/"
+    matcher  = "200,302"
+    timeout  = "4"
+    interval = "5"
+    unhealthy_threshold = 2
+    healthy_threshold   = 2
+  }
+
+  #stickiness {
+  #  type    = "lb_cookie"
+  #  enabled = false 
+  #}
+
+  tags = merge(var.standard_tags, var.tags)
+}
+
+resource "aws_lb_target_group_attachment" "phantom_internal" {
+  target_group_arn = aws_alb_target_group.phantom_internal.arn
+  target_id        = aws_instance.phantom-server-instance.id
+  port             = 443
+}
+
+# Create a new alb listener
+resource "aws_alb_listener" "phantom_https_internal" {
+  load_balancer_arn = aws_alb.phantom_internal.arn
+  port              = "443"
+  protocol          = "HTTPS"
+  ssl_policy        = "ELBSecurityPolicy-FS-1-2-Res-2019-08" # PFS, TLS1.2, most "restrictive" policy (took awhile to find that)
+  certificate_arn   = aws_acm_certificate.cert_private.arn
+
+  default_action {
+    target_group_arn = aws_alb_target_group.phantom_internal.arn
+    type             = "forward"
+  }
+}
+
+resource "aws_lb_listener" "phantom_listener_http" {
+  load_balancer_arn = aws_alb.phantom_internal.arn
+  port              = "80"
+  protocol          = "HTTP"
+
+  default_action {
+    type             = "redirect"
+
+    redirect {
+      port        = "443"
+      protocol    = "HTTPS"
+      status_code = "HTTP_301"
+    }
+  }
+}
+
+# #########################
+# # DNS Entry
+module "private_dns_record" {
+  source = "../../submodules/dns/private_CNAME_record"
+
+  name = "phantom"
+  target_dns_names = [ aws_alb.phantom_internal.dns_name ]
+  dns_info = var.dns_info
+
+  providers = {
+    aws.c2 = aws.c2
+  }
+}
+
+#----------------------------------------------------------------------------
+# ALB Security Group
+#----------------------------------------------------------------------------
+resource "aws_security_group" "phantom_alb_internal" {
+  vpc_id      = var.vpc_id
+  name        = "phantom-alb-sg-internal"
+  description = "ALB for Phantom"
+  tags = merge(var.standard_tags, var.tags)
+}
+
+#----------------------------------------------------------------------------
+# INGRESS
+#----------------------------------------------------------------------------
+resource "aws_security_group_rule" "http_from_local" {
+  description = "HTTP inbound from Internet"
+  type = "ingress"
+  from_port = "80"
+  to_port = "80"
+  protocol = "tcp"
+  cidr_blocks = [ "10.0.0.0/8" ]
+  security_group_id = aws_security_group.phantom_alb_internal.id
+}
+
+resource "aws_security_group_rule" "https_from_local" {
+  description = "HTTPS inbound from Internet"
+  type = "ingress"
+  from_port = "443"
+  to_port = "443"
+  protocol = "tcp"
+  cidr_blocks = [ "10.0.0.0/8" ]
+  security_group_id = aws_security_group.phantom_alb_internal.id
+}
+
+#----------------------------------------------------------------------------
+# EGRESS
+#----------------------------------------------------------------------------
+resource "aws_security_group_rule" "phantom_alb_to_server" {
+  description = "Jira to the Server"
+  type = "egress"
+  from_port = "8080"
+  to_port = "8080"
+  protocol = "tcp"
+  source_security_group_id = aws_security_group.phantom_server.id
+  security_group_id = aws_security_group.phantom_alb_internal.id
+}

+ 1 - 0
base/phantom/amis.tf

@@ -0,0 +1 @@
+../amis.tf

+ 33 - 0
base/phantom/certificate.tf

@@ -0,0 +1,33 @@
+#----------------------------------------------------------------------------
+# Public DNS Certificate
+#----------------------------------------------------------------------------
+resource "aws_acm_certificate" "cert_private" {
+  domain_name       = "phantom.${var.dns_info["private"]["zone"]}"
+  validation_method = "DNS"
+
+  tags = merge(var.standard_tags, var.tags)
+}
+
+resource "aws_acm_certificate_validation" "cert_private" {
+  certificate_arn         = aws_acm_certificate.cert_private.arn
+  validation_record_fqdns = [for record in aws_route53_record.cert_validation_private: record.fqdn]
+}
+
+resource "aws_route53_record" "cert_validation_private" {
+  provider = aws.mdr-common-services-commercial
+
+  for_each = {
+    for dvo in aws_acm_certificate.cert_private.domain_validation_options : dvo.domain_name => {
+      name   = dvo.resource_record_name
+      record = dvo.resource_record_value
+      type   = dvo.resource_record_type
+    }
+  }
+
+  allow_overwrite = true
+  name            = each.value.name
+  records         = [each.value.record]
+  ttl             = 60
+  type            = each.value.type
+  zone_id         = var.dns_info["public"]["zone_id"] # private zones sitll use public dns for validation
+}

+ 73 - 0
base/phantom/cloud-init/cloud-init.tpl

@@ -0,0 +1,73 @@
+#cloud-config
+preserve_hostname: false
+hostname: ${hostname}
+salt-master: ${salt_master}
+fqdn: ${fqdn}
+
+# Write files happens early
+write_files:
+- content: |
+    proxy=http://${proxy}:80
+  path: /etc/yum.conf
+  append: true
+- content: |
+    [global]
+    proxy=${proxy}
+  path: /etc/pip.conf
+- content: |
+    export HTTPS_PROXY=http://${proxy}:80
+    export HTTP_PROXY=http://${proxy}:80
+    export NO_PROXY=localhost,127.0.0.1,169.254.169.254,pvt.xdrtest.accenturefederalcyber.com,pvt.xdr.accenturefederalcyber.com,reposerver.msoc.defpoint.local,jenkins.msoc.defpoint.local,pod1search-splunk-sh.msoc.defpoint.local,s3.amazonaws.com,ssm.${ aws_region }.amazonaws.com,ec2messages.${ aws_region }.amazonaws.com,ec2.${ aws_region }.amazonaws.com,ssmmessages.${ aws_region }.amazonaws.com,iratemoses.mdr.defpoint.com,jira.mdr.defpoint.com,reposerver.pvt.xdr.accenturefederalcyber.com,jenkins.pvt.xdr.accenturefederalcyber.com,pod1search-splunk-sh.pvt.xdr.accenturefederalcyber.com,reposerver.pvt.xdrtest.accenturefederalcyber.com,jenkins.pvt.xdrtest.accenturefederalcyber.com,pod1search-splunk-sh.pvt.xdrtest.accenturefederalcyber.com,iratemoses.xdr.accenturefederalcyber.com,jira.xdr.accenturefederalcyber.com,iratemoses.xdrtest.accenturefederalcyber.com,jira.xdrtest.accenturefederalcyber.com
+    export https_proxy=$HTTPS_PROXY
+    export http_proxy=$HTTP_PROXY
+    export no_proxy=$NO_PROXY
+  path: /etc/profile.d/proxy.sh
+- content: |
+    ${fqdn}
+  path: /etc/salt/minion_id
+- content: |
+    master: ${salt_master}
+  path: /etc/salt/minion
+- content: |
+    grains:
+      environment: ${ environment }
+      aws_partition: ${ aws_partition }
+      aws_partition_alias: ${ aws_partition_alias }
+      aws_region: ${ aws_region }
+  path: /etc/salt/minion.d/cloud_init_grains.conf
+
+#yum_repos:
+#  epel-release:
+#    baseurl: http://download.fedoraproject.org/pub/epel/7/$basearch
+#    enabled: false
+#    failovermethod: priority
+#    gpgcheck: true
+#    gpgkey: http://download.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7
+#    name: Extra Packages for Enterprise Linux 7 - Release
+
+packages:
+ - vim
+
+package_update: true # Always patch
+
+growpart:
+  mode: auto
+  devices: [ '/', '/var', '/var/log', '/var/log/audit', '/var/tmp', '/tmp', '/home' ]
+  ignore_growroot_disabled: false
+
+runcmd:
+ - /bin/systemctl restart salt-minion
+ - /bin/systemctl enable salt-minion
+ - /bin/systemctl start amazon-ssm-agent
+ - /bin/systemctl enable amazon-ssm-agent
+ - /usr/sbin/aide --update --verbose=0
+ - /bin/cp /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz
+
+# Either final message or power state, but probably not both
+final_message: "The system is up after $UPTIME seconds"
+#power_state:
+#  delay: "+30"
+#  mode: reboot
+#  message: "System configured after $UPTIME seconds"
+#  timeout: 300
+#  condition: true

+ 80 - 0
base/phantom/cloud-init/opt.boothook

@@ -0,0 +1,80 @@
+#!/bin/bash
+#
+#
+exec > /dev/console
+exec 2>&1
+
+declare -A EBSMAP
+
+# Build a map of EBS NVMe disks from their AWS-API-name to their NVMe name
+# this makes an associative array (like a python hash) of the
+# sdX/xvdX name you'd set in AWS API to the corresponding nvmeX name
+# Thanks Fred for the awesome id-ctrl stuff I'd never seen before
+#
+# One interesting side effect observed:  the id-ctrl output is different when
+# volumes are attached at boot time (no /dev/) versus attached after the OS
+# is started (includes /dev/)
+function make_nve_ebs_map {
+        for DEVICE in $( lsblk -d -o NAME,MODEL -n | egrep "Elastic Block Store" | awk '{ print $1 }' ); do
+                UNDERLYING=$( nvme id-ctrl --raw-binary /dev/${DEVICE} 2>/dev/null | cut -c 3073-3104 | tr -d ' ' | sed "s#/dev/##" )
+
+                EBSMAP[$UNDERLYING]=$DEVICE
+                UNDERLYING2=$( echo $UNDERLYING | sed "s/sd/xvd/" )
+                EBSMAP[$UNDERLYING2]=$DEVICE
+        done
+}
+
+function do_the_mount
+{
+	VOL_LABEL=$1
+	VOLUME=$2
+	MOUNTPOINT=$3
+
+
+	DONE=0
+	TRIES=0
+	while [[ $DONE -ne 1 ]] && [[ $TRIES -lt 20 ]]; do
+		echo "Looking for $VOLUME to come attached"
+		make_nve_ebs_map
+
+		#echo "------- current nvme/ebs map -------"
+		#for K in "${!EBSMAP[@]}"; do echo $K  = ${EBSMAP[$K]} ; done
+		#echo "------- end current nvme/ebs map -------"
+
+		if [[ -b /dev/$VOLUME ]]; then
+			DEV="/dev/$VOLUME"
+			DONE=1
+		elif [[ -b /dev/${EBSMAP[$VOLUME]} ]]; then
+			DEV="/dev/${EBSMAP[$VOLUME]}"
+			DONE=1
+		else
+			sleep 10
+			TRIES=$(( $TRIES + 1 ))
+		fi
+
+		echo "Volume $VOLUME available at $DEV"
+	done
+
+	if ! [[ -d ${MOUNTPOINT} ]]; then
+		echo "Creating mount directory ${MOUNTPOINT}"
+		mkdir -p ${MOUNTPOINT}
+	fi
+
+	if ! blkid -l -t LABEL=${VOL_LABEL}; then
+		echo "Making filesystem for LABEL=${VOL_LABEL} on ${DEV}"
+		mkfs.xfs -L ${VOL_LABEL} ${DEV}
+	fi
+
+	if ! egrep -q "LABEL=${VOL_LABEL}" /etc/fstab; then
+		echo "Adding LABEL=${VOL_LABEL} to /etc/fstab"
+		echo "LABEL=${VOL_LABEL}       ${MOUNTPOINT}    xfs    noatime,nofail  0 2" >> /etc/fstab
+	fi
+
+	if ! mountpoint ${MOUNTPOINT} >/dev/null 2>&1; then
+		echo "Mounting ${MOUNTPOINT}"
+		mount ${MOUNTPOINT}
+	fi
+
+}
+
+do_the_mount opt_splunk xvdf /opt

+ 85 - 0
base/phantom/instance-profile.tf.skipped

@@ -0,0 +1,85 @@
+resource "aws_iam_instance_profile" "jira_server_instance_profile" {
+  name     = "jira-server-instance-profile"
+  role     = aws_iam_role.jira_server.name
+}
+
+resource "aws_iam_role" "jira_server" {
+  name     = "jira-server-instance-role"
+  path     = "/instance/"
+
+  assume_role_policy = <<EOF
+{
+    "Version": "2012-10-17",
+    "Statement": [
+      {
+        "Sid": "",
+        "Effect": "Allow",
+        "Principal": {
+          "Service": [
+            "ec2.amazonaws.com",
+            "ssm.amazonaws.com"
+            ]
+        },
+        "Action": "sts:AssumeRole"
+      }
+    ]
+  }
+EOF
+}
+
+data "aws_iam_policy_document" "jira_server_ecr_policy" {
+  statement {
+    actions = [
+      "ecr:GetAuthorizationToken",
+    ]
+
+    resources = ["*"]
+  }
+
+  statement {
+    sid    = "AllowCluCommunicationECR"
+    effect = "Allow"
+
+    actions = [
+			"ecr:BatchCheckLayerAvailability",
+			"ecr:GetDownloadUrlForLayer",
+			"ecr:GetRepositoryPolicy",
+			"ecr:DescribeRepositories",
+			"ecr:ListImages",
+			"ecr:DescribeImages",
+			"ecr:BatchGetImage",
+			"ecr:InitiateLayerUpload",
+			"ecr:UploadLayerPart",
+			"ecr:CompleteLayerUpload",
+			"ecr:PutImage"
+    ]
+
+    resources = [
+      "arn:${var.aws_partition}:ecr:us-east-1:${var.aws_account_id}:repository/*"
+    ]
+  }
+
+  statement {
+    sid    = "Tags"
+    effect = "Allow"
+
+    actions = [
+      "ec2:DescribeTags",
+      "ec2:DescribeInstances"
+    ]
+    resources = [
+      "*"
+    ]
+  }
+}
+
+resource "aws_iam_policy" "jira_server_ecr_policy" {
+  name     = "jira-server"
+  path     = "/instance/"
+  policy   = data.aws_iam_policy_document.jira_server_ecr_policy.json
+}
+
+resource "aws_iam_role_policy_attachment" "jira_server_ecr" {
+  role       = aws_iam_role.jira_server.name
+  policy_arn = aws_iam_policy.jira_server_ecr_policy.arn
+}

+ 202 - 0
base/phantom/main.tf

@@ -0,0 +1,202 @@
+# Some instance variables
+locals {
+  ami_selection       = "minion" # master, minion, ...
+}
+
+data "aws_security_group" "typical-host" {
+  name   = "typical-host"
+  vpc_id = var.vpc_id
+}
+
+# Use the default EBS key
+data "aws_kms_key" "ebs-key" {
+  key_id = "alias/ebs_root_encrypt_decrypt"
+}
+
+resource "aws_network_interface" "phantom-server-interface" {
+  subnet_id = var.public_subnets[0] # Phantom is on a public subnet for direct comms
+  security_groups = [ data.aws_security_group.typical-host.id, aws_security_group.phantom_server.id ]
+  description = "phantom-server"
+  tags = merge(var.standard_tags, var.tags, { Name = "phantom-server" })
+}
+
+resource "aws_eip" "instance" {
+  vpc = true
+  tags = merge(var.standard_tags, var.tags, { Name = "phantom-server" })
+}
+
+resource "aws_eip_association" "instance" {
+  network_interface_id = aws_network_interface.phantom-server-interface.id
+  allocation_id = aws_eip.instance.id
+}
+
+resource "aws_instance" "phantom-server-instance" {
+  tenancy = "default"
+  ebs_optimized = true
+  disable_api_termination = var.instance_termination_protection
+  instance_initiated_shutdown_behavior = "stop"
+  instance_type = var.instance_type
+  key_name = "msoc-build"
+  monitoring = false
+  iam_instance_profile = "msoc-default-instance-profile"
+
+  ami = local.ami_map[local.ami_selection]
+  # We need to ignore ebs_block_device changes, because if the AMI changes, so does the snapshot_id.
+  # If they add a feature to block more specific changes (eg `ebs_block_devices[*].snapshot_id`), then
+  # that could be removed.
+  #lifecycle { ignore_changes = [ ami, key_name, user_data, ebs_block_device ] }
+  lifecycle { ignore_changes = [ ami, key_name, user_data ] }
+
+  # These device definitions are optional, but added for clarity.
+  root_block_device {
+      volume_type = "gp3"
+      # volume_size = "100"
+      delete_on_termination = true
+      encrypted = true
+      kms_key_id = data.aws_kms_key.ebs-key.arn
+  }
+
+  ebs_block_device {
+    # /opt - NOTE: Not in ami
+    device_name = "/dev/xvdf"
+    volume_type = "gp3"
+    volume_size = 30 # legacy was 58, but only 7.2G used
+    delete_on_termination = true
+    encrypted = true
+    kms_key_id = data.aws_kms_key.ebs-key.arn
+  }
+  ebs_block_device {
+    # swap
+    device_name = "/dev/xvdm"
+    volume_type = "gp3"
+    volume_size = 8
+    delete_on_termination = true
+    encrypted = true
+    kms_key_id = data.aws_kms_key.ebs-key.arn
+    # Snapshot IDs need to be grabbed from the ami, or it will replace every time. It's ugly.
+    # This may prompt replacement when the AMI is updated.
+    # See:
+    #   https://github.com/hashicorp/terraform/issues/19958
+    #   https://github.com/terraform-providers/terraform-provider-aws/issues/13118
+    snapshot_id = local.block_device_mappings[local.ami_selection]["/dev/xvdm"].ebs.snapshot_id
+  }
+  ebs_block_device {
+    # /home
+    device_name = "/dev/xvdn"
+    volume_type = "gp3"
+    # volume_size = xx
+    delete_on_termination = true
+    encrypted = true
+    kms_key_id = data.aws_kms_key.ebs-key.arn
+    snapshot_id = local.block_device_mappings[local.ami_selection]["/dev/xvdn"].ebs.snapshot_id
+
+  }
+  ebs_block_device {
+    # /var
+    device_name = "/dev/xvdo"
+    volume_type = "gp3"
+    # volume_size = xx
+    delete_on_termination = true
+    encrypted = true
+    kms_key_id = data.aws_kms_key.ebs-key.arn
+    snapshot_id = local.block_device_mappings[local.ami_selection]["/dev/xvdo"].ebs.snapshot_id
+  }
+  ebs_block_device {
+    # /var/tmp
+    device_name = "/dev/xvdp"
+    volume_type = "gp3"
+    # volume_size = xx
+    delete_on_termination = true
+    encrypted = true
+    kms_key_id = data.aws_kms_key.ebs-key.arn
+    snapshot_id = local.block_device_mappings[local.ami_selection]["/dev/xvdp"].ebs.snapshot_id
+  }
+  ebs_block_device {
+    # /var/log
+    device_name = "/dev/xvdq"
+    volume_type = "gp3"
+    # volume_size = xx
+    delete_on_termination = true
+    encrypted = true
+    kms_key_id = data.aws_kms_key.ebs-key.arn
+    snapshot_id = local.block_device_mappings[local.ami_selection]["/dev/xvdq"].ebs.snapshot_id
+  }
+  ebs_block_device {
+    # /var/log/audit
+    device_name = "/dev/xvdr"
+    volume_type = "gp3"
+    # volume_size = xx
+    delete_on_termination = true
+    encrypted = true
+    kms_key_id = data.aws_kms_key.ebs-key.arn
+    snapshot_id = local.block_device_mappings[local.ami_selection]["/dev/xvdr"].ebs.snapshot_id
+  }
+  ebs_block_device {
+    # /tmp
+    device_name = "/dev/xvds"
+    volume_type = "gp3"
+    # volume_size = xx
+    delete_on_termination = true
+    encrypted = true
+    kms_key_id = data.aws_kms_key.ebs-key.arn
+    snapshot_id = local.block_device_mappings[local.ami_selection]["/dev/xvds"].ebs.snapshot_id
+  }
+
+  network_interface {
+    device_index = 0
+    network_interface_id = aws_network_interface.phantom-server-interface.id
+  }
+
+  user_data = data.template_cloudinit_config.cloud-init.rendered
+  tags = merge( var.standard_tags, var.tags, { Name = "phantom-server" })
+  volume_tags = merge( var.standard_tags, var.tags, { Name = "phantom-server" })
+}
+
+data "template_file" "cloud-init" {
+  # Should these be in a common directory? I suspect they'd be reusable
+  template = file("${path.module}/cloud-init/cloud-init.tpl")
+
+  vars = {
+    hostname = "phantom-server"
+    fqdn = "phantom-server.${var.dns_info["private"]["zone"]}"
+    environment = var.environment
+    salt_master  = var.salt_master
+    proxy = var.proxy
+    aws_partition = var.aws_partition
+    aws_partition_alias = var.aws_partition_alias
+    aws_region = var.aws_region
+  }
+}
+
+# Render a multi-part cloud-init config making use of the part
+# above, and other source files
+data "template_cloudinit_config" "cloud-init" {
+  gzip          = true
+  base64_encode = true
+
+  # Main cloud-config configuration file.
+  part {
+    filename     = "init.cfg"
+    content_type = "text/cloud-config"
+    content      = data.template_file.cloud-init.rendered
+  }
+
+  # mount /dev/xvdf at /opt/
+  part {
+    content_type = "text/cloud-boothook"
+    content      = file("${path.module}/cloud-init/opt.boothook")
+  }
+}
+
+module "private_dns_record_phantom-server" {
+  source = "../../submodules/dns/private_A_record"
+
+  name = "phantom-server"
+  ip_addresses = [ aws_instance.phantom-server-instance.private_ip ]
+  dns_info = var.dns_info
+  reverse_enabled = var.reverse_enabled
+
+  providers = {
+    aws.c2 = aws.c2
+  }
+}

+ 15 - 0
base/phantom/outputs.tf

@@ -0,0 +1,15 @@
+output phantom_instance_arn {
+  value = aws_instance.phantom-server-instance.arn
+}
+
+output phantom_instance_private_ip {
+  value = aws_instance.phantom-server-instance.private_ip
+}
+
+output private_fqdn {
+  value = module.private_dns_record_phantom-server.forward
+}
+
+output alb_fqdn {
+  value = module.private_dns_record.forward
+}

+ 86 - 0
base/phantom/securitygroup-server.tf

@@ -0,0 +1,86 @@
+# SG Summary - Server
+#   Inbound::
+#     tcp/8888 - from 10.0.0.0/8
+#     tcp/443  - from load balancers, vpc-access (legacy was from 10.0.0.0/8)
+#
+#   Outbound:
+#     tcp/8089 - 10.0.0.0/8 (splunk)
+#     udp/53 - 0.0.0.0/0 (dns for oscontext)
+#     DISABLED tcp/464 - 10.80.0.0/16 (legacy vpc)
+#     DISABLED tcp/636 - 0.0.0.0/0 (LDAPS outbound)
+#     DISABLED tcp/389 - 10.80.0.0/16 (legacy vpc)
+#     DISABLED tcp+udp/88 - 10.80.0.0/16 (idm)
+#
+#   New:
+resource "aws_security_group" "phantom_server" {
+  name_prefix = "phantom_server"
+  tags = merge( var.standard_tags, var.tags, { Name = "phantom_server" } )
+  vpc_id      = var.vpc_id
+  description = "Phantom Server"
+}
+
+#-----------------------------------------------------------------
+# Inbound access
+#-----------------------------------------------------------------
+resource "aws_security_group_rule" "phantom_server_inbound_8888" {
+  security_group_id        = aws_security_group.phantom_server.id
+  type                     = "ingress"
+  cidr_blocks              = [ "10.0.0.0/8" ]
+  from_port                = 8888
+  to_port                  = 8888
+  protocol                 = "tcp"
+  description              = "Inbound 8888 - Phantom Websocket"
+}
+
+resource "aws_security_group_rule" "phantom_server_inbound_alb_443" {
+  security_group_id        = aws_security_group.phantom_server.id
+  type                     = "ingress"
+  source_security_group_id = aws_security_group.phantom_alb_internal.id
+  from_port                = 443
+  to_port                  = 443
+  protocol                 = "tcp"
+  description              = "Inbound 443 (from load balancers)"
+}
+
+resource "aws_security_group_rule" "phantom_server_inbound_alb_443_from_vpn" {
+  security_group_id        = aws_security_group.phantom_server.id
+  type                     = "ingress"
+  cidr_blocks              = var.cidr_map["vpc-access"]
+  from_port                = 443
+  to_port                  = 443
+  protocol                 = "tcp"
+  description              = "Inbound 443 (from load access, for troubleshooting)"
+}
+
+#-----------------------------------------------------------------
+# Outbound access
+#-----------------------------------------------------------------
+resource "aws_security_group_rule" "phantom_server_outbound_postgres" {
+  security_group_id        = aws_security_group.phantom_server.id
+  type                     = "egress"
+  cidr_blocks               = [ "10.0.0.0/8" ]
+  from_port                = 8089
+  to_port                  = 8089
+  protocol                 = "tcp"
+  description              = "Outbound to splunk everywhere"
+}
+
+resource "aws_security_group_rule" "phantom_server_outbound_udp_dns" {
+  security_group_id        = aws_security_group.phantom_server.id
+  type                     = "egress"
+  cidr_blocks               = [ "0.0.0.0/0" ]
+  from_port                = 53
+  to_port                  = 53
+  protocol                 = "tcp"
+  description              = "Outbound tcp dns anywhere"
+}
+
+resource "aws_security_group_rule" "phantom_server_outbound_tcp_dns" {
+  security_group_id        = aws_security_group.phantom_server.id
+  type                     = "egress"
+  cidr_blocks               = [ "0.0.0.0/0" ]
+  from_port                = 53
+  to_port                  = 53
+  protocol                 = "udp"
+  description              = "Outbound udp dns anywhere"
+}

+ 44 - 0
base/phantom/vars.tf

@@ -0,0 +1,44 @@
+variable "public_subnets" {
+  type = list(string)
+}
+
+variable "azs" {
+  type = list(string)
+}
+
+variable "vpc_id" {
+  type = string
+}
+
+variable "tags" {
+  description = "Tags to add to the resource (in addition to global standard tags)"
+  type        = map
+  default     = { }
+}
+
+variable "instance_type" { 
+  type = string
+  default = "t3a.micro"
+}
+
+variable "reverse_enabled" { 
+  description = "Whether to create the reverse DNS entry."
+  type = bool
+  default = true
+}
+
+variable "trusted_ips" { type = list(string) }
+variable "proxy" { type = string }
+variable "salt_master" { type = string }
+
+variable "cidr_map" { type = map }
+variable "dns_info" { type = map }
+variable "standard_tags" { type = map }
+variable "environment" { type = string }
+variable "aws_region" { type = string }
+variable "ses_region" { type = string }
+variable "aws_partition" { type = string }
+variable "aws_partition_alias" { type = string }
+variable "aws_account_id" { type = string }
+variable "common_services_account" { type = string }
+variable "instance_termination_protection" { type = bool }

+ 3 - 0
base/phantom/version.tf

@@ -0,0 +1,3 @@
+terraform {
+  required_version = "~> 0.13"
+}