Skip to content

Commit d3e2e42

Browse files
committed
feat: testing with IP restrictions
1 parent c42e900 commit d3e2e42

File tree

5 files changed

+38
-0
lines changed

5 files changed

+38
-0
lines changed

Caddyfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
# Step 2: Initialize TX variable
2121
SecAction "id:2,phase:1,pass,nolog,setvar:tx.bucket_ops=0"
2222
23+
# IP allowlist - allow specific IPs
24+
SecRule REMOTE_ADDR "@ipMatch {$ALLOWED_IPS}" "id:999,phase:1,pass,nolog,msg:'Allowed IP access'"
25+
26+
# Block all other IPs (must be after allowlist)
27+
SecRule REMOTE_ADDR "@ipMatch 0.0.0.0/0" "id:1000,phase:1,block,status:403,msg:'IP not in allowlist - access denied'"
28+
2329
# Example rule: Block DELETE on /minio/admin
2430
SecRule REQUEST_URI "@beginsWith /minio/admin" "id:1001,phase:1,deny,status:403,msg:'MinIO Admin API Access Blocked'"
2531
@@ -58,6 +64,12 @@
5864
# Step 2: Initialize TX variable
5965
SecAction "id:11,phase:1,pass,nolog,setvar:tx.bucket_ops=0"
6066
67+
# IP allowlist - allow specific IPs
68+
SecRule REMOTE_ADDR "@ipMatch {$ALLOWED_IPS}" "id:1999,phase:1,pass,nolog,msg:'Allowed IP access'"
69+
70+
# Block all other IPs (must be after allowlist)
71+
SecRule REMOTE_ADDR "@ipMatch 0.0.0.0/0" "id:2000,phase:1,block,status:403,msg:'IP not in allowlist - access denied'"
72+
6173
# Example rule: Log DELETE operations
6274
SecRule REQUEST_METHOD "@streq DELETE" "id:2001,phase:1,log,msg:'DELETE operation logged'"
6375

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ No modules.
190190

191191
| Name | Description | Type | Default | Required |
192192
|------|-------------|------|---------|:--------:|
193+
| <a name="input_allowed_ip_addresses"></a> [allowed\_ip\_addresses](#input\_allowed\_ip\_addresses) | List of IP addresses that will be allowed to access the MinIO service (CIDR format, e.g., ['203.0.113.0/32', '192.168.1.0/24']) | `list(string)` | n/a | yes |
193194
| <a name="input_cert_password"></a> [cert\_password](#input\_cert\_password) | Password for the SSL certificate | `string` | n/a | yes |
194195
| <a name="input_coraza_waf_image"></a> [coraza\_waf\_image](#input\_coraza\_waf\_image) | Coraza WAF container image | `string` | `"ghcr.io/meshcloud/minio_azure_container_app/coraza-caddy:caddy-2.8-coraza-v2.0.0"` | no |
195196
| <a name="input_location"></a> [location](#input\_location) | Azure region for deployment | `string` | `"West Europe"` | no |

main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ resource "azurerm_container_group" "minio_aci_container_group" {
132132
server_name = "${var.public_url_domain_name}.${azurerm_resource_group.minio_aci_rg.location}.azurecontainer.io"
133133
minio_ui_backend = "localhost:8080"
134134
minio_api_backend = "localhost:8081"
135+
allowed_ips = var.allowed_ip_addresses
135136
}))
136137
}
137138
}
@@ -169,6 +170,7 @@ resource "azurerm_container_group" "minio_aci_container_group" {
169170
environment_variables = {
170171
MINIO_UI_BACKEND = "localhost:9001"
171172
MINIO_API_BACKEND = "localhost:9000"
173+
ALLOWED_IPS = join(",", var.allowed_ip_addresses)
172174
}
173175

174176
liveness_probe {

nginx-frontend.conf.tpl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ server {
2525
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384;
2626
ssl_prefer_server_ciphers off;
2727

28+
# IP restrictions - only allow specified IP addresses
29+
%{ for ip in allowed_ips ~}
30+
allow ${ip};
31+
%{ endfor ~}
32+
deny all;
33+
2834
client_max_body_size 1000m;
2935

3036
# MinIO Console (UI) via Coraza WAF
@@ -65,6 +71,12 @@ server {
6571
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384;
6672
ssl_prefer_server_ciphers off;
6773

74+
# IP restrictions - only allow specified IP addresses
75+
%{ for ip in allowed_ips ~}
76+
allow ${ip};
77+
%{ endfor ~}
78+
deny all;
79+
6880
client_max_body_size 1000m;
6981

7082
# MinIO S3 API via Coraza WAF

variables.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,14 @@ variable "coraza_waf_image" {
9898
default = "ghcr.io/meshcloud/minio_azure_container_app/coraza-caddy:caddy-2.8-coraza-v2.0.0"
9999
description = "Coraza WAF container image"
100100
}
101+
102+
variable "allowed_ip_addresses" {
103+
type = list(string)
104+
description = "List of IP addresses that will be allowed to access the MinIO service (CIDR format, e.g., ['203.0.113.0/32', '192.168.1.0/24'])"
105+
validation {
106+
condition = alltrue([
107+
for ip in var.allowed_ip_addresses : can(cidrhost(ip, 0))
108+
])
109+
error_message = "All IP addresses must be in valid CIDR format (e.g., '203.0.113.0/32' for a single IP or '192.168.1.0/24' for a subnet)."
110+
}
111+
}

0 commit comments

Comments
 (0)