Skip to content

Commit 2ae11c1

Browse files
author
Sean Sundberg
committed
Restricts the rules for the default network acl
Signed-off-by: Sean Sundberg <[email protected]>
1 parent 239abe1 commit 2ae11c1

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

main.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ resource null_resource post_vpc_address_pfx_default {
6161
}
6262
}
6363

64+
resource null_resource setup_default_acl {
65+
depends_on = [null_resource.post_vpc_address_pfx_default]
66+
count = var.provision ? 1 : 0
67+
68+
provisioner "local-exec" {
69+
command = "${path.module}/scripts/setup-default-acl.sh ${data.ibm_is_vpc.vpc.default_network_acl}"
70+
}
71+
}
72+
6473
resource ibm_is_security_group base {
6574
count = var.provision ? 1 : 0
6675

scripts/setup-default-acl.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
3+
## Currently the IBM terraform provider does not have a resource to add or remove rules from an ACL.
4+
## This script uses the IBM Cloud cli to remove the existing rules from the existing ACL and adds a locked down
5+
## set of rules
6+
7+
ACL_ID="$1"
8+
9+
# Assume that we are already logged in
10+
11+
# Install jq if not available
12+
13+
echo "Deleting existing rules"
14+
ibmcloud is network-acl "${ACL_ID}" --output JSON | \
15+
jq -c '.rules[]'
16+
17+
ibmcloud is network-acl "${ACL_ID}" --output JSON | \
18+
jq -r '.rules[].id' | \
19+
while read rule_id;
20+
do
21+
ibmcloud network-acl-rule-delete "${ACL_ID}" "${rule_id}"
22+
done
23+
24+
ibmcloud is network-acl-rule-add "${ACL_ID}" allow inbound all 10.0.0.0/8 10.0.0.0/8 --name allow-internal-ingress
25+
ibmcloud is network-acl-rule-add "${ACL_ID}" allow outbound all 10.0.0.0/8 10.0.0.0/8 --name allow-internal-egress
26+
27+
ibmcloud is network-acl-rule-add "${ACL_ID}" deny inbound tcp 0.0.0.0/0 0.0.0.0/0 --name deny-external-ssh --source-port-min 22 --source-port-max 22 --destination-port-min 22 --destination-port-max 22
28+
ibmcloud is network-acl-rule-add "${ACL_ID}" deny inbound tcp 0.0.0.0/0 0.0.0.0/0 --name deny-external-rdp --source-port-min 3389 --source-port-max 3389 --destination-port-min 3389 --destination-port-max 3389
29+
ibmcloud is network-acl-rule-add "${ACL_ID}" deny inbound all 0.0.0.0/0 0.0.0.0/0 --name deny-external-ingress

0 commit comments

Comments
 (0)