Skip to content

Commit d5726a8

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Remove deprecated [api] use_forwarded_for"
2 parents d28a559 + a5f68d3 commit d5726a8

File tree

9 files changed

+5
-79
lines changed

9 files changed

+5
-79
lines changed

doc/source/admin/metadata-service.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ service-related options:
7676
- :oslo.config:option:`neutron.service_metadata_proxy`
7777
- :oslo.config:option:`neutron.metadata_proxy_shared_secret`
7878
- :oslo.config:option:`api.metadata_cache_expiration`
79-
- :oslo.config:option:`api.use_forwarded_for`
8079
- :oslo.config:option:`api.local_metadata_per_cell`
8180
- :oslo.config:option:`api.dhcp_domain`
8281

@@ -105,7 +104,6 @@ following to a :file:`nova-api.conf` file:
105104
[api]
106105
dhcp_domain =
107106
metadata_cache_expiration = 15
108-
use_forwarded_for = False
109107
local_metadata_per_cell = False
110108
vendordata_providers = StaticJSON
111109
vendordata_jsonfile_path = /etc/nova/vendor_data.json
@@ -124,7 +122,6 @@ The :program:`nova-api-metadata` application accepts almost the same options:
124122
- :oslo.config:option:`neutron.service_metadata_proxy`
125123
- :oslo.config:option:`neutron.metadata_proxy_shared_secret`
126124
- :oslo.config:option:`api.metadata_cache_expiration`
127-
- :oslo.config:option:`api.use_forwarded_for`
128125
- :oslo.config:option:`api.local_metadata_per_cell`
129126
- :oslo.config:option:`api.dhcp_domain`
130127

@@ -151,7 +148,6 @@ file:
151148
[api]
152149
dhcp_domain =
153150
metadata_cache_expiration = 15
154-
use_forwarded_for = False
155151
local_metadata_per_cell = False
156152
157153
.. note::

nova/api/auth.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ def _create_context(env, **kwargs):
9393
def __call__(self, req):
9494
# Build a context, including the auth_token...
9595
remote_address = req.remote_addr
96-
if CONF.api.use_forwarded_for:
97-
remote_address = req.headers.get('X-Forwarded-For', remote_address)
9896

9997
service_catalog = None
10098
if req.headers.get('X_SERVICE_CATALOG') is not None:

nova/api/metadata/handler.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,6 @@ def __call__(self, req):
141141

142142
def _handle_remote_ip_request(self, req):
143143
remote_address = req.remote_addr
144-
if CONF.api.use_forwarded_for:
145-
remote_address = req.headers.get('X-Forwarded-For', remote_address)
146144

147145
try:
148146
meta_data = self.get_metadata_by_remote_address(remote_address)

nova/api/openstack/auth.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ def base_call(self, req, project_id_in_path, always_admin=True):
5151
user_id, _sep, project_id = token.partition(':')
5252
project_id = project_id or user_id
5353
remote_address = getattr(req, 'remote_addr', '127.0.0.1')
54-
if CONF.api.use_forwarded_for:
55-
remote_address = req.headers.get('X-Forwarded-For', remote_address)
5654
is_admin = always_admin or (user_id == 'admin')
5755
ctx = context.RequestContext(
5856
user_id, project_id, is_admin=is_admin,

nova/api/openstack/requestlog.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,6 @@ def _log_req(self, req, res, start):
7171

7272
remote_address = req.environ.get('REMOTE_ADDR', '-')
7373

74-
# If the API is configured to treat the X-Forwarded-For header as the
75-
# canonical remote address, use its value instead.
76-
if CONF.api.use_forwarded_for:
77-
remote_address = req.environ.get(
78-
'HTTP_X_FORWARDED_FOR', remote_address)
79-
8074
data = {
8175
'REMOTE_ADDR': remote_address,
8276
'REQUEST_METHOD': req.environ['REQUEST_METHOD'],

nova/conf/api.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,6 @@
3939
""",
4040
help="""
4141
Determine the strategy to use for authentication.
42-
"""),
43-
cfg.BoolOpt("use_forwarded_for",
44-
default=False,
45-
deprecated_for_removal=True,
46-
deprecated_reason='This feature is duplicate of the HTTPProxyToWSGI '
47-
'middleware in oslo.middleware',
48-
deprecated_group="DEFAULT",
49-
deprecated_since='26.0.0',
50-
help="""
51-
When True, the 'X-Forwarded-For' header is treated as the canonical remote
52-
address. When False (the default), the 'remote_address' header is used.
53-
54-
You should only enable this if you have an HTML sanitizing proxy.
5542
"""),
5643
]
5744

nova/tests/unit/api/openstack/test_requestlog.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_logs_requests(self, emit):
5858
"""
5959

6060
emit.return_value = True
61-
conf = self.useFixture(fixtures.ConfFixture()).conf
61+
self.useFixture(fixtures.ConfFixture())
6262
self.useFixture(fixtures.RPCFixture('nova.test'))
6363
api = self.useFixture(fixtures.OSAPIFixture()).api
6464

@@ -73,25 +73,6 @@ def test_logs_requests(self, emit):
7373
'"GET /" status: 200 len: %s' % content_length)
7474
self.assertIn(log1, self.stdlog.logger.output)
7575

76-
# Verify handling of X-Forwarded-For header, example: load balancer.
77-
# First, try without setting CONF.api.use_forwarded_for, it should not
78-
# use the header value.
79-
headers = {'X-Forwarded-For': '1.2.3.4'}
80-
resp = api.api_request('/', strip_version=True, headers=headers)
81-
content_length = resp.headers['content-length']
82-
log2 = ('INFO [nova.api.openstack.requestlog] 127.0.0.1 '
83-
'"GET /" status: 200 len: %s' % content_length)
84-
self.assertIn(log2, self.stdlog.logger.output)
85-
86-
# Now set CONF.api.use_forwarded_for, it should use the header value.
87-
conf.set_override('use_forwarded_for', True, 'api')
88-
headers = {'X-Forwarded-For': '1.2.3.4'}
89-
resp = api.api_request('/', strip_version=True, headers=headers)
90-
content_length = resp.headers['content-length']
91-
log3 = ('INFO [nova.api.openstack.requestlog] 1.2.3.4 '
92-
'"GET /" status: 200 len: %s' % content_length)
93-
self.assertIn(log3, self.stdlog.logger.output)
94-
9576
@mock.patch('nova.api.openstack.requestlog.RequestLog._should_emit')
9677
def test_logs_mv(self, emit):
9778
"""Ensure logs register microversion if passed.

nova/tests/unit/test_metadata.py

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,36 +1152,6 @@ def test_invalid_path_is_404(self):
11521152
relpath="/2009-04-04/user-data-invalid")
11531153
self.assertEqual(response.status_int, 404)
11541154

1155-
def test_user_data_with_use_forwarded_header(self):
1156-
expected_addr = "192.192.192.2"
1157-
1158-
def fake_get_metadata(self_gm, address):
1159-
if address == expected_addr:
1160-
return self.mdinst
1161-
else:
1162-
raise Exception("Expected addr of %s, got %s" %
1163-
(expected_addr, address))
1164-
1165-
self.flags(use_forwarded_for=True, group='api')
1166-
response = fake_request(self, self.mdinst,
1167-
relpath="/2009-04-04/user-data",
1168-
address="168.168.168.1",
1169-
fake_get_metadata=fake_get_metadata,
1170-
headers={'X-Forwarded-For': expected_addr})
1171-
1172-
self.assertEqual(response.status_int, 200)
1173-
response_ctype = response.headers['Content-Type']
1174-
self.assertTrue(response_ctype.startswith("text/plain"))
1175-
self.assertEqual(response.body,
1176-
base64.decode_as_bytes(self.instance['user_data']))
1177-
1178-
response = fake_request(self, self.mdinst,
1179-
relpath="/2009-04-04/user-data",
1180-
address="168.168.168.1",
1181-
fake_get_metadata=fake_get_metadata,
1182-
headers=None)
1183-
self.assertEqual(response.status_int, 500)
1184-
11851155
@mock.patch('oslo_utils.secretutils.constant_time_compare')
11861156
def test_by_instance_id_uses_constant_time_compare(self, mock_compare):
11871157
mock_compare.side_effect = test.TestingException
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
upgrade:
3+
- |
4+
The deprecated ``[api] use_forwarded_for`` option has been removed.

0 commit comments

Comments
 (0)