Skip to content

Commit ec0075a

Browse files
author
sivakami
committed
Rename subnets. Changed NSG rules to prevent network connectivity between vnet 1 subnet 1 and vnet 1 subnet2.
1 parent 3a78c19 commit ec0075a

File tree

6 files changed

+31
-44
lines changed

6 files changed

+31
-44
lines changed

.pipelines/swiftv2-long-running/scripts/create_aks.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env bash
22
set -e
3+
trap 'echo "[ERROR] Failed during Resource group or AKS cluster creation." >&2' ERR
34

45
SUBSCRIPTION_ID=$1
56
LOCATION=$2
Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,48 @@
11
#!/usr/bin/env bash
22
set -e
3-
trap 'echo "[ERROR] Failed during NSG creation." >&2' ERR
3+
trap 'echo "[ERROR] Failed during NSG creation or rule setup." >&2' ERR
44

55
SUBSCRIPTION_ID=$1
66
RG=$2
7-
LOCATION=${3:-centraluseuap}
7+
LOCATION=$3
88

99
VNET_A1="cx_vnet_a1"
10+
SUBNET1_PREFIX="10.10.1.0/24"
11+
SUBNET2_PREFIX="10.10.2.0/24"
1012
NSG_NAME="${VNET_A1}-nsg"
1113

1214
echo "==> Creating Network Security Group: $NSG_NAME"
1315
az network nsg create -g "$RG" -n "$NSG_NAME" -l "$LOCATION" --output none \
14-
&& echo "NSG $NSG_NAME created."
16+
&& echo "[OK] NSG '$NSG_NAME' created."
1517

16-
echo "==> Adding NSG rules"
17-
18-
# Allow SSH from any
18+
echo "==> Creating NSG rule to DENY traffic from Subnet1 ($SUBNET1_PREFIX) to Subnet2 ($SUBNET2_PREFIX)"
1919
az network nsg rule create \
2020
-g "$RG" \
2121
--nsg-name "$NSG_NAME" \
22-
-n allow-ssh \
22+
-n deny-subnet1-to-subnet2 \
2323
--priority 100 \
24-
--source-address-prefixes "*" \
25-
--destination-port-ranges 22 \
24+
--source-address-prefixes "$SUBNET1_PREFIX" \
25+
--destination-address-prefixes "$SUBNET2_PREFIX" \
2626
--direction Inbound \
27-
--access Allow \
28-
--protocol Tcp \
29-
--description "Allow SSH access" \
27+
--access Deny \
28+
--protocol "*" \
29+
--description "Deny all traffic from Subnet1 to Subnet2" \
3030
--output none \
31-
&& echo "Rule allow-ssh created."
31+
&& echo "[OK] Deny rule from Subnet1 → Subnet2 created."
3232

33-
# Allow internal VNet traffic
33+
echo "==> Creating NSG rule to DENY traffic from Subnet2 ($SUBNET2_PREFIX) to Subnet1 ($SUBNET1_PREFIX)"
3434
az network nsg rule create \
3535
-g "$RG" \
3636
--nsg-name "$NSG_NAME" \
37-
-n allow-vnet \
37+
-n deny-subnet2-to-subnet1 \
3838
--priority 200 \
39-
--source-address-prefixes VirtualNetwork \
40-
--destination-address-prefixes VirtualNetwork \
39+
--source-address-prefixes "$SUBNET2_PREFIX" \
40+
--destination-address-prefixes "$SUBNET1_PREFIX" \
4141
--direction Inbound \
42-
--access Allow \
42+
--access Deny \
4343
--protocol "*" \
44-
--description "Allow VNet internal traffic" \
45-
--output none \
46-
&& echo "Rule allow-vnet created."
47-
48-
# Allow AKS API traffic
49-
az network nsg rule create \
50-
-g "$RG" \
51-
--nsg-name "$NSG_NAME" \
52-
-n allow-aks-controlplane \
53-
--priority 300 \
54-
--source-address-prefixes AzureCloud \
55-
--destination-port-ranges 443 \
56-
--direction Inbound \
57-
--access Allow \
58-
--protocol Tcp \
59-
--description "Allow AKS control plane traffic" \
44+
--description "Deny all traffic from Subnet2 to Subnet1" \
6045
--output none \
61-
&& echo "Rule allow-aks-controlplane created."
46+
&& echo "[OK] Deny rule from Subnet2 → Subnet1 created."
6247

63-
echo "NSG '$NSG_NAME' created successfully with rules."
48+
echo "NSG '$NSG_NAME' created successfully with bidirectional isolation between Subnet1 and Subnet2."

.pipelines/swiftv2-long-running/scripts/create_peerings.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ peer_two_vnets() {
2020
peer_two_vnets "$RG" "$VNET_A1" "$VNET_A2" "A1-to-A2" "A2-to-A1"
2121
peer_two_vnets "$RG" "$VNET_A2" "$VNET_A3" "A2-to-A3" "A3-to-A2"
2222
peer_two_vnets "$RG" "$VNET_A1" "$VNET_A3" "A1-to-A3" "A3-to-A1"
23-
echo "VNet peerings created successfully."
23+
echo "VNet peerings created successfully."

.pipelines/swiftv2-long-running/scripts/create_storage.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ for SA in "$SA1" "$SA2"; do
2929
&& echo "Storage account $SA created successfully."
3030
done
3131

32-
echo "All storage accounts created successfully."
32+
echo "All storage accounts created successfully."

.pipelines/swiftv2-long-running/scripts/create_vnets.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,19 @@ az network vnet subnet create -g "$RG" --vnet-name "$VNET_A1" -n pe --address-pr
3535
&& echo "Created $VNET_A1 with subnet pe"
3636

3737
# A2
38-
az network vnet create -g "$RG" -n "$VNET_A2" --address-prefix 10.11.0.0/16 --subnet-name s-A2 --subnet-prefix "$A2_MAIN" -l "$LOCATION" --output none \
39-
&& echo "Created $VNET_A2 with subnet s-A2"
38+
az network vnet create -g "$RG" -n "$VNET_A2" --address-prefix 10.11.0.0/16 --subnet-name s1 --subnet-prefix "$A2_MAIN" -l "$LOCATION" --output none \
39+
&& echo "Created $VNET_A2 with subnet s1"
4040
az network vnet subnet create -g "$RG" --vnet-name "$VNET_A2" -n pe --address-prefix "$A2_PE" --output none \
4141
&& echo "Created $VNET_A2 with subnet pe"
4242

4343
# A3
44-
az network vnet create -g "$RG" -n "$VNET_A3" --address-prefix 10.12.0.0/16 --subnet-name s-A3 --subnet-prefix "$A3_MAIN" -l "$LOCATION" --output none \
45-
&& echo "Created $VNET_A3 with subnet s-A3"
44+
az network vnet create -g "$RG" -n "$VNET_A3" --address-prefix 10.12.0.0/16 --subnet-name s1 --subnet-prefix "$A3_MAIN" -l "$LOCATION" --output none \
45+
&& echo "Created $VNET_A3 with subnet s1"
4646
az network vnet subnet create -g "$RG" --vnet-name "$VNET_A3" -n pe --address-prefix "$A3_PE" --output none \
4747
&& echo "Created $VNET_A3 with subnet pe"
4848

4949
# B1
50-
az network vnet create -g "$RG" -n "$VNET_B1" --address-prefix 10.20.0.0/16 --subnet-name s-B1 --subnet-prefix "$B1_MAIN" -l "$LOCATION" --output none \
51-
&& echo "Created $VNET_B1 with subnet s-B1"
50+
az network vnet create -g "$RG" -n "$VNET_B1" --address-prefix 10.20.0.0/16 --subnet-name s1 --subnet-prefix "$B1_MAIN" -l "$LOCATION" --output none \
51+
&& echo "Created $VNET_B1 with subnet s1"
5252

5353
echo "All VNets and subnets created successfully."

.pipelines/swiftv2-long-running/template/long-running-pipeline-template.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,4 @@ stages:
123123
arguments: >
124124
${{ parameters.subscriptionId }}
125125
${{ parameters.resourceGroupName }}
126+
${{ parameters.location }}

0 commit comments

Comments
 (0)