File: security-groups.rst

package info (click to toggle)
nova 2%3A18.1.0-6
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 49,532 kB
  • sloc: python: 383,759; pascal: 1,610; xml: 1,184; sh: 917; makefile: 140; sql: 43
file content (251 lines) | stat: -rw-r--r-- 13,000 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
=======================
Manage project security
=======================

Security groups are sets of IP filter rules that are applied to all project
instances, which define networking access to the instance. Group rules are
project specific; project members can edit the default rules for their group
and add new rule sets.

All projects have a ``default`` security group which is applied to any instance
that has no other defined security group. Unless you change the default, this
security group denies all incoming traffic and allows only outgoing traffic to
your instance.

You can use the ``allow_same_net_traffic`` option in the
``/etc/nova/nova.conf`` file to globally control whether the rules apply to
hosts which share a network. There are two possible values:

``True`` (default)
  Hosts on the same subnet are not filtered and are allowed to pass all types
  of traffic between them. On a flat network, this allows all instances from
  all projects unfiltered communication.  With VLAN networking, this allows
  access between instances within the same project. You can also simulate this
  setting by configuring the default security group to allow all traffic from
  the subnet.

``False``
  Security groups are enforced for all connections.

Additionally, the number of maximum rules per security group is controlled by
the ``security_group_rules`` and the number of allowed security groups per
project is controlled by the ``security_groups`` quota (see
:ref:`manage-quotas`).

List and view current security groups
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

From the command-line you can get a list of security groups for the project,
using the :command:`openstack` and :command:`nova` commands:

#. Ensure your system variables are set for the user and project for which you
   are checking security group rules. For example:

   .. code-block:: console

      export OS_USERNAME=demo00
      export OS_TENANT_NAME=tenant01

#. Output security groups, as follows:

   .. code-block:: console

      $ openstack security group list
      +--------------------------------------+---------+-------------+
      | Id                                   | Name    | Description |
      +--------------------------------------+---------+-------------+
      | 73580272-d8fa-4927-bd55-c85e43bc4877 | default | default     |
      | 6777138a-deb7-4f10-8236-6400e7aff5b0 | open    | all ports   |
      +--------------------------------------+---------+-------------+

#. View the details of a group, as follows:

   .. code-block:: console

      $ openstack security group rule list GROUPNAME

   For example:

   .. code-block:: console

      $ openstack security group rule list open
      +--------------------------------------+-------------+-----------+-----------------+-----------------------+
      | ID                                   | IP Protocol | IP Range  | Port Range      | Remote Security Group |
      +--------------------------------------+-------------+-----------+-----------------+-----------------------+
      | 353d0611-3f67-4848-8222-a92adbdb5d3a | udp         | 0.0.0.0/0 | 1:65535         | None                  |
      | 63536865-e5b6-4df1-bac5-ca6d97d8f54d | tcp         | 0.0.0.0/0 | 1:65535         | None                  |
      +--------------------------------------+-------------+-----------+-----------------+-----------------------+

   These rules are allow type rules as the default is deny. The first column is
   the IP protocol (one of ICMP, TCP, or UDP). The second and third columns
   specify the affected port range. The third column specifies the IP range in
   CIDR format. This example shows the full port range for all protocols
   allowed from all IPs.

Create a security group
~~~~~~~~~~~~~~~~~~~~~~~

When adding a new security group, you should pick a descriptive but brief name.
This name shows up in brief descriptions of the instances that use it where the
longer description field often does not. For example, seeing that an instance
is using security group "http" is much easier to understand than "bobs\_group"
or "secgrp1".

#. Ensure your system variables are set for the user and project for which you
   are creating security group rules.

#. Add the new security group, as follows:

   .. code-block:: console

      $ openstack security group create GroupName --description Description

   For example:

   .. code-block:: console

      $ openstack security group create global_http --description "Allows Web traffic anywhere on the Internet."
      +-----------------+--------------------------------------------------------------------------------------------------------------------------+
      | Field           | Value                                                                                                                    |
      +-----------------+--------------------------------------------------------------------------------------------------------------------------+
      | created_at      | 2016-11-03T13:50:53Z                                                                                                     |
      | description     | Allows Web traffic anywhere on the Internet.                                                                             |
      | headers         |                                                                                                                          |
      | id              | c0b92b20-4575-432a-b4a9-eaf2ad53f696                                                                                     |
      | name            | global_http                                                                                                              |
      | project_id      | 5669caad86a04256994cdf755df4d3c1                                                                                         |
      | project_id      | 5669caad86a04256994cdf755df4d3c1                                                                                         |
      | revision_number | 1                                                                                                                        |
      | rules           | created_at='2016-11-03T13:50:53Z', direction='egress', ethertype='IPv4', id='4d8cec94-e0ee-4c20-9f56-8fb67c21e4df',      |
      |                 | project_id='5669caad86a04256994cdf755df4d3c1', revision_number='1', updated_at='2016-11-03T13:50:53Z'                    |
      |                 | created_at='2016-11-03T13:50:53Z', direction='egress', ethertype='IPv6', id='31be2ad1-be14-4aef-9492-ecebede2cf12',      |
      |                 | project_id='5669caad86a04256994cdf755df4d3c1', revision_number='1', updated_at='2016-11-03T13:50:53Z'                    |
      | updated_at      | 2016-11-03T13:50:53Z                                                                                                     |
      +-----------------+--------------------------------------------------------------------------------------------------------------------------+

#. Add a new group rule, as follows:

   .. code-block:: console

      $ openstack security group rule create SEC_GROUP_NAME \
          --protocol PROTOCOL --dst-port FROM_PORT:TO_PORT --remote-ip CIDR

   The arguments are positional, and the ``from-port`` and ``to-port``
   arguments specify the local port range connections are allowed to access,
   not the source and destination ports of the connection. For example:

   .. code-block:: console

      $ openstack security group rule create global_http \
          --protocol tcp --dst-port 80:80 --remote-ip 0.0.0.0/0
      +-------------------+--------------------------------------+
      | Field             | Value                                |
      +-------------------+--------------------------------------+
      | created_at        | 2016-11-06T14:02:00Z                 |
      | description       |                                      |
      | direction         | ingress                              |
      | ethertype         | IPv4                                 |
      | headers           |                                      |
      | id                | 2ba06233-d5c8-43eb-93a9-8eaa94bc9eb5 |
      | port_range_max    | 80                                   |
      | port_range_min    | 80                                   |
      | project_id        | 5669caad86a04256994cdf755df4d3c1     |
      | project_id        | 5669caad86a04256994cdf755df4d3c1     |
      | protocol          | tcp                                  |
      | remote_group_id   | None                                 |
      | remote_ip_prefix  | 0.0.0.0/0                            |
      | revision_number   | 1                                    |
      | security_group_id | c0b92b20-4575-432a-b4a9-eaf2ad53f696 |
      | updated_at        | 2016-11-06T14:02:00Z                 |
      +-------------------+--------------------------------------+

   You can create complex rule sets by creating additional rules. For example,
   if you want to pass both HTTP and HTTPS traffic, run:

   .. code-block:: console

      $ openstack security group rule create global_http \
          --protocol tcp --dst-port 443:443 --remote-ip 0.0.0.0/0
      +-------------------+--------------------------------------+
      | Field             | Value                                |
      +-------------------+--------------------------------------+
      | created_at        | 2016-11-06T14:09:20Z                 |
      | description       |                                      |
      | direction         | ingress                              |
      | ethertype         | IPv4                                 |
      | headers           |                                      |
      | id                | 821c3ef6-9b21-426b-be5b-c8a94c2a839c |
      | port_range_max    | 443                                  |
      | port_range_min    | 443                                  |
      | project_id        | 5669caad86a04256994cdf755df4d3c1     |
      | project_id        | 5669caad86a04256994cdf755df4d3c1     |
      | protocol          | tcp                                  |
      | remote_group_id   | None                                 |
      | remote_ip_prefix  | 0.0.0.0/0                            |
      | revision_number   | 1                                    |
      | security_group_id | c0b92b20-4575-432a-b4a9-eaf2ad53f696 |
      | updated_at        | 2016-11-06T14:09:20Z                 |
      +-------------------+--------------------------------------+

   Despite only outputting the newly added rule, this operation is additive
   (both rules are created and enforced).

#. View all rules for the new security group, as follows:

   .. code-block:: console

      $ openstack security group rule list global_http
      +--------------------------------------+-------------+-----------+-----------------+-----------------------+
      | ID                                   | IP Protocol | IP Range  | Port Range      | Remote Security Group |
      +--------------------------------------+-------------+-----------+-----------------+-----------------------+
      | 353d0611-3f67-4848-8222-a92adbdb5d3a | tcp         | 0.0.0.0/0 | 80:80           | None                  |
      | 63536865-e5b6-4df1-bac5-ca6d97d8f54d | tcp         | 0.0.0.0/0 | 443:443         | None                  |
      +--------------------------------------+-------------+-----------+-----------------+-----------------------+

Delete a security group
~~~~~~~~~~~~~~~~~~~~~~~

#. Ensure your system variables are set for the user and project for which you
   are deleting a security group.

#. Delete the new security group, as follows:

   .. code-block:: console

      $ openstack security group delete GROUPNAME

   For example:

   .. code-block:: console

      $ openstack security group delete global_http

Create security group rules for a cluster of instances
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Source Groups are a special, dynamic way of defining the CIDR of allowed
sources. The user specifies a Source Group (Security Group name), and all the
user's other Instances using the specified Source Group are selected
dynamically. This alleviates the need for individual rules to allow each new
member of the cluster.

#. Make sure to set the system variables for the user and project for which you
   are creating a security group rule.

#. Add a source group, as follows:

   .. code-block:: console

      $ openstack security group rule create secGroupName \
          --remote-group source-group --protocol ip-protocol \
          --dst-port from-port:to-port

   For example:

   .. code-block:: console

      $ openstack security group rule create cluster \
          --remote-group global_http --protocol tcp --dst-port 22:22

   The ``cluster`` rule allows SSH access from any other instance that uses the
   ``global_http`` group.