IBM Cloud VPC Security Groups: Reference Another Security Group Instead of Hardcoding IPs
Hardcoding app server IPs in database security group rules breaks when instances are replaced. Reference the remote security group instead—same VPC only—and verify propagation with the CLI.
14 Sept 2026, 08:30 UTC

The problem: static IP allowlists break when instances change
You add a replacement virtual server instance to your application tier, but the database security group still contains the old instance's private IP. New connections fail until someone manually edits the rule. IBM Cloud VPC security groups are stateful firewalls attached to a virtual server instance's network interface. They control traffic by protocol, port, and source or destination, and they automatically allow return traffic for established connections. Relying on a static CIDR or IP list ties the rule to an address rather than to the workload that should be allowed.
Takeaway: reference the application security group by ID in the database security group's inbound rule. Any instance assigned to that group can reach the database, and you avoid editing rules every time an instance is replaced or scaled. Both security groups must exist in the same VPC.
Worked example: application tier to database tier
Suppose you have two security groups in one VPC:
sg-appattached to application virtual server instances.sg-dbattached to database virtual server instances.
Instead of adding an inbound rule for each application instance IP, add one rule to sg-db:
| Direction | Protocol | Port | Remote | Effect |
|---|---|---|---|---|
| Inbound | TCP | 5432 | Security group sg-app | Allow any current app instance to reach the database port. |
| Outbound | All | All | Not required for return traffic | State tracking allows responses back to the app tier automatically. |
Security group rules are evaluated collectively; if any rule permits the traffic, it is allowed. Because the firewall is stateful, the database does not need a separate outbound rule to send responses back to the application instance.
Verify with the IBM Cloud CLI
Run these commands where the IBM Cloud CLI and the VPC infrastructure plug-in are installed, such as your workstation or a CI runner. You need IAM permission to read VPC security groups in the target resource group; creating rules requires editor-level access.
# List rules for a security group. Replace the placeholder with the actual ID.
ibmcloud is security-group-rules
Expected check: the rule list includes an inbound TCP rule for port 5432 whose remote object references . If the rule is missing or still shows a CIDR, the reference was not created.
To confirm which security groups are attached to an instance:
ibmcloud is instance-network-interface
Then test connectivity from a source instance in the application tier. Wait about sixty seconds after creating or changing a rule; security group updates can take up to a minute to propagate to attached network interfaces.
# Run from an instance assigned to sg-app. Replace placeholders.
nc -vz 5432
Expected check: the command reports the port as open or succeeded. A failure immediately after a rule change is likely a propagation delay, not a bad rule. Test again after waiting, rather than assuming the rule is wrong.
Limitations and how to check the result
- Security group references are scoped to a single VPC and region. You cannot reference a security group in a different VPC; use VPC peering or transit gateway designs for cross-VPC traffic instead.
- Deleting a security group that another rule references can break validation or leave dangling references depending on API behavior. Delete dependent rules first, or confirm the referenced group is still present before removing it.
- Security groups do not inspect application-layer payloads. They cannot replace a web application firewall or intrusion prevention system for deep packet inspection.
- Network ACLs are stateless and operate separately at the subnet level. If connectivity still fails after the security group rule is correct, check the subnet's network ACL rules for conflicting denies.
Practical verification: open the VPC infrastructure page in the IBM Cloud console, select the security group, and review its inbound and outbound rules attached to the instance network interface. Combine that with the CLI rule list and a timed nc test before and after changes.
Closing
For your next application and database deployment, create the database security group with an inbound rule that references the application security group ID rather than a static IP list. Audit existing rules for hardcoded addresses that will break when instances are replaced, and verify every change with the CLI list and a connectivity test after the propagation window.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.