Ce contenu n'est pas disponible dans la langue sélectionnée.
Chapter 7. Configuring security groups
Security groups are sets of IP filter rules that control network and protocol access to and from instances, such as ICMP to allow you to ping an instance, and SSH to allow you to connect to an instance. Security groups and their rules apply to the ports which they are associated with.
In a Red Hat OpenStack Services on OpenShift (RHOSO) environment, all projects have a default security group called default, which is used when you do not specify a security group for your instances. By default, the default security group allows all outgoing traffic and denies all incoming traffic from any source other than instances in the same security group. You can either add rules to the default security group or create a new security group for your project. You can apply one or more security groups to an instance during instance creation. To apply a security group to a running instance, apply the security group to a port attached to the instance.
When you create a security group, you can choose stateful or stateless.
Security groups are stateful by default and in most cases stateful security groups provide better control with less administrative overhead.
A stateless security group can provide significant performance benefits, because it bypasses connection tracking in the underlying firewall. But stateless security groups require more security group rules than stateful security groups. Stateless security groups also offer less granularity in some cases.
- Stateless security group advantages
- Stateless security groups can be faster than stateful security groups
- Stateless security groups are the only viable security group option in applications that offload OpenFlow actions to hardware.
- Stateless security group disadvantages
- Stateless security group rules do not automatically allow returning traffic. For example, if you create a rule to allow outgoing TCP traffic from a port that is in a stateless security group, you must also create a rule that allows incoming replies. Stateful security groups automatically allow the incoming replies.
- Control over those incoming replies may not be as granular as the control provided by stateful security groups.
In general, use the default stateful security group type unless your application is highly sensitive to performance or uses hardware offloading of OpenFlow actions.
This section contains the following topics:
You cannot apply a role-based access control (RBAC)-shared security group directly to an instance during instance creation. To apply an RBAC-shared security group to an instance you must first create the port, apply the shared security group to that port, and then assign that port to the instance. See Adding a security group to a port in Creating and managing instances.
7.1. Creating a security group Copier lienLien copié sur presse-papiers!
You can create a new security group to apply to instances and ports within a project in a Red Hat OpenStack Services on OpenShift (RHOSO) environment.
Prerequisites
-
The administrator has created a project for you and has provided you with a
clouds.yamlfile for you to access the cloud. -
You have installed the
python-openstackclientpackage.
Procedure
Confirm that the system
OS_CLOUDvariable is set for your cloud:echo $OS_CLOUD
$ echo $OS_CLOUD my_cloudCopy to Clipboard Copied! Toggle word wrap Toggle overflow Reset the variable if necessary:
export OS_CLOUD=my_other_cloud
$ export OS_CLOUD=my_other_cloudCopy to Clipboard Copied! Toggle word wrap Toggle overflow As an alternative, you can specify the cloud name by adding the
--os-cloud <cloud_name>option each time you run anopenstackcommand.Optional: To ensure the security group you need does not already exist, review the available security groups and their rules:
openstack security group list openstack security group rule list <sec_group>
$ openstack security group list $ openstack security group rule list <sec_group>Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Replace
<sec_group>with the name or ID of the security group that you retrieved from the list of available security groups.
-
Replace
Create your security group:
openstack security group create [--stateless] mySecGroup
$ openstack security group create [--stateless] mySecGroupCopy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: Include the
--statelessoption to create a stateless security group.Security groups are stateful by default.
Add rules to your security group:
openstack security group rule create --protocol <protocol> \ [--dst-port <port-range>] \ [--remote-ip <ip-address> | --remote-group <group>] \ [--ingress | --egress] mySecGroup
$ openstack security group rule create --protocol <protocol> \ [--dst-port <port-range>] \ [--remote-ip <ip-address> | --remote-group <group>] \ [--ingress | --egress] mySecGroupCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
Replace
<protocol>with the name of the protocol you want to allow to communicate with your instances. -
Optional: Replace
<port-range>with the destination port or port range to open for the protocol. Required for IP protocols TCP, UDP, and SCTP. Set to-1to allow all ports for the specified protocol. Separate port range values with a colon. -
Optional: You can allow access only from specified IP addresses by using
--remote-ipto specify the remote IP address block, or--remote-groupto specify that the rule only applies to packets from interfaces that are a member of the remote group. If using--remote-ip, replace<ip-address>with the remote IP address block. You can use CIDR notation. If using--remote-group, replace<group>with the name or ID of the existing security group. If neither option is specified, then access is allowed to all addresses, as the remote IP access range defaults (IPv4 default:0.0.0.0/0; IPv6 default:::/0). Specify the direction of network traffic the protocol rule applies to, either incoming (
ingress) or outgoing (egress). If not specified, defaults toingress.NoteIf you created a stateless security group, and you created a rule to allow outgoing TCP traffic from a port that is in the stateless security group, you must also create a rule that allows incoming replies.
-
Replace
Repeat the previous step until you have created rules for all the protocols that you want to allow to access your instances.
The following example creates a rule to allow SSH connections to instances in the security group
mySecGroup:openstack security group rule create --protocol tcp \ --dst-port 22 mySecGroup
$ openstack security group rule create --protocol tcp \ --dst-port 22 mySecGroupCopy to Clipboard Copied! Toggle word wrap Toggle overflow
7.2. Updating security group rules Copier lienLien copié sur presse-papiers!
You can update the rules of any security group that you have access to in a Red Hat OpenStack Services on OpenShift (RHOSO) environment.
Prerequisites
-
The administrator has created a project for you and has provided you with a
clouds.yamlfile for you to access the cloud. The
python-openstackclientpackage resides on your workstation.dnf list installed python-openstackclient
$ dnf list installed python-openstackclientCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Procedure
Confirm that the system
OS_CLOUDvariable is set for your cloud:echo $OS_CLOUD
$ echo $OS_CLOUD my_cloudCopy to Clipboard Copied! Toggle word wrap Toggle overflow Reset the variable if necessary:
export OS_CLOUD=my_other_cloud
$ export OS_CLOUD=my_other_cloudCopy to Clipboard Copied! Toggle word wrap Toggle overflow As an alternative, you can specify the cloud name by adding the
--os-cloud <cloud_name>option each time you run anopenstackcommand.Retrieve the name or ID of the security group that you want to update the rules for:
openstack security group list
$ openstack security group listCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Determine the rules that you need to apply to the security group.
Add rules to your security group:
openstack security group rule create --protocol <protocol> \ [--dst-port <port-range>] \ [--remote-ip <ip-address> | --remote-group <group>] \ [--ingress | --egress] <group_name>
$ openstack security group rule create --protocol <protocol> \ [--dst-port <port-range>] \ [--remote-ip <ip-address> | --remote-group <group>] \ [--ingress | --egress] <group_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
Replace
<protocol>with the name of the protocol you want to allow to communicate with your instances. -
Optional: Replace
<port-range>with the destination port or port range to open for the protocol. Required for IP protocols TCP, UDP, and SCTP. Set to-1to allow all ports for the specified protocol.Separate port range values with a colon. -
Optional: You can allow access only from specified IP addresses by using
--remote-ipto specify the remote IP address block, or--remote-groupto specify that the rule only applies to packets from interfaces that are a member of the remote group. If using--remote-ip, replace<ip-address>with the remote IP address block. You can use CIDR notation. If using--remote-group, replace<group>with the name or ID of the existing security group. If neither option is specified, then access is allowed to all addresses, as the remote IP access range defaults (IPv4 default:0.0.0.0/0; IPv6 default:::/0). -
Specify the direction of network traffic the protocol rule applies to, either incoming (
ingress) or outgoing (egress). If not specified, defaults toingress. -
Replace
<group_name>with the name or ID of the security group that you want to apply the rule to.
-
Replace
Repeat the previous step until you have created rules for all the protocols that you want to allow to access your instances.
The following example creates a rule to allow SSH connections to instances in the security group
mySecGroup:openstack security group rule create --protocol tcp \ --dst-port 22 mySecGroup
$ openstack security group rule create --protocol tcp \ --dst-port 22 mySecGroupCopy to Clipboard Copied! Toggle word wrap Toggle overflow
7.3. Deleting security group rules Copier lienLien copié sur presse-papiers!
You can delete rules from a security group in a Red Hat OpenStack Services on OpenShift (RHOSO) environment.
Prerequisites
-
The administrator has created a project for you and has provided you with a
clouds.yamlfile for you to access the cloud. The
python-openstackclientpackage resides on your workstation.dnf list installed python-openstackclient
$ dnf list installed python-openstackclientCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Procedure
Confirm that the system
OS_CLOUDvariable is set for your cloud:echo $OS_CLOUD
$ echo $OS_CLOUD my_cloudCopy to Clipboard Copied! Toggle word wrap Toggle overflow Reset the variable if necessary:
export OS_CLOUD=my_other_cloud
$ export OS_CLOUD=my_other_cloudCopy to Clipboard Copied! Toggle word wrap Toggle overflow As an alternative, you can specify the cloud name by adding the
--os-cloud <cloud_name>option each time you run anopenstackcommand.Identify the security group that the rules are applied to:
openstack security group list
$ openstack security group listCopy to Clipboard Copied! Toggle word wrap Toggle overflow Retrieve IDs of the rules associated with the security group:
openstack security group show <sec-group>
$ openstack security group show <sec-group>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Delete the rule or rules:
openstack security group rule delete <rule> [<rule> ...]
$ openstack security group rule delete <rule> [<rule> ...]Copy to Clipboard Copied! Toggle word wrap Toggle overflow Replace
<rule>with the ID of the rule to delete. You can delete more than one rule at a time by specifying a space-delimited list of the IDs of the rules to delete.
7.4. Deleting a security group Copier lienLien copié sur presse-papiers!
You can delete security groups that are not associated with any ports in a Red Hat OpenStack Services on OpenShift (RHOSO) environment.
Prerequisites
-
The administrator has created a project for you and has provided you with a
clouds.yamlfile for you to access the cloud. -
You have installed the
python-openstackclientpackage.
Procedure
Confirm that the system
OS_CLOUDvariable is set for your cloud:echo $OS_CLOUD
$ echo $OS_CLOUD my_cloudCopy to Clipboard Copied! Toggle word wrap Toggle overflow Reset the variable if necessary:
export OS_CLOUD=my_other_cloud
$ export OS_CLOUD=my_other_cloudCopy to Clipboard Copied! Toggle word wrap Toggle overflow As an alternative, you can specify the cloud name by adding the
--os-cloud <cloud_name>option each time you run anopenstackcommand.Retrieve the name or ID of the security group that you want to delete:
openstack security group list
$ openstack security group listCopy to Clipboard Copied! Toggle word wrap Toggle overflow Retrieve a list of the available ports:
openstack port list
$ openstack port listCopy to Clipboard Copied! Toggle word wrap Toggle overflow Check each port for an associated security group:
openstack port show <port-uuid> -c security_group_ids
$ openstack port show <port-uuid> -c security_group_idsCopy to Clipboard Copied! Toggle word wrap Toggle overflow If the security group you want to delete is associated with any of the ports, then you must first remove the security group from the port. For more information, see Removing a security group from a port in Creating and managing instances.
Delete the security group:
openstack security group delete <group> [<group> ...]
$ openstack security group delete <group> [<group> ...]Copy to Clipboard Copied! Toggle word wrap Toggle overflow Replace
<group>with the ID of the group that you want to delete. You can delete more than one group at a time by specifying a space-delimited list of the IDs of the groups to delete.