launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #09076
[Merge] lp:~allenap/maas/preseed-render-service into lp:maas
Gavin Panella has proposed merging lp:~allenap/maas/preseed-render-service into lp:maas.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~allenap/maas/preseed-render-service/+merge/111492
- Generate and return preseeds anonymously.
- Change the name of the url() for anon node access, and change its
pattern. Normalise other names in the vicinity to closer match the
existing by_mac_patterns.
- Rename ALLOW_ANONYMOUS_METADATA_ACCESS to
ALLOW_UNSAFE_METADATA_ACCESS, because there are some anonymous views
that must be available on a production system.
--
https://code.launchpad.net/~allenap/maas/preseed-render-service/+merge/111492
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~allenap/maas/preseed-render-service into lp:maas.
=== modified file 'src/maas/demo.py'
--- src/maas/demo.py 2012-06-01 06:52:08 +0000
+++ src/maas/demo.py 2012-06-21 21:06:22 +0000
@@ -78,4 +78,4 @@
# For demo purposes, give nodes unauthenticated access to their metadata
# even if we can't pass boot parameters. This is not safe; do not
# enable it on a production MAAS.
-ALLOW_ANONYMOUS_METADATA_ACCESS = True
+ALLOW_UNSAFE_METADATA_ACCESS = True
=== modified file 'src/maas/development.py'
--- src/maas/development.py 2012-06-19 16:01:07 +0000
+++ src/maas/development.py 2012-06-21 21:06:22 +0000
@@ -81,7 +81,7 @@
# Make all nodes' metadata visible. This is not safe; do not enable it
# on a production MAAS.
-ALLOW_ANONYMOUS_METADATA_ACCESS = True
+ALLOW_UNSAFE_METADATA_ACCESS = True
# Use in-branch preseed templates.
PRESEED_TEMPLATE_LOCATIONS = (
=== modified file 'src/maas/settings.py'
--- src/maas/settings.py 2012-06-14 13:57:19 +0000
+++ src/maas/settings.py 2012-06-21 21:06:22 +0000
@@ -288,10 +288,10 @@
COMMISSIONING_TIMEOUT = 60
# Allow anonymous access to the metadata for a node, keyed by its MAC
-# address? This is for development purposes only. DO NOT ENABLE THIS
+# address. This is for development purposes only. DO NOT ENABLE THIS
# IN PRODUCTION or private metadata, including MAAS access credentials
# for all nodes, will be exposed on your network.
-ALLOW_ANONYMOUS_METADATA_ACCESS = False
+ALLOW_UNSAFE_METADATA_ACCESS = False
# Earlier locations in the following list will shadow, or overlay, later
# locations.
=== modified file 'src/maasserver/preseed.py'
--- src/maasserver/preseed.py 2012-06-21 10:27:29 +0000
+++ src/maasserver/preseed.py 2012-06-21 21:06:22 +0000
@@ -217,7 +217,7 @@
# Create the url and the url-data (POST parameters) used to turn off
# PXE booting once the install of the node is finished.
node_disable_pxe_url = absolute_reverse(
- 'metadata-anon-node-edit', args=['latest', node.system_id])
+ 'metadata-node-by-id', args=['latest', node.system_id])
node_disable_pxe_data = urlencode({'op': 'netboot_off'})
node_context = {
'node': node,
=== modified file 'src/metadataserver/api.py'
--- src/metadataserver/api.py 2012-06-20 13:31:10 +0000
+++ src/metadataserver/api.py 2012-06-21 21:06:22 +0000
@@ -42,6 +42,7 @@
Node,
SSHKey,
)
+from maasserver.preseed import get_preseed
from metadataserver.models import (
NodeCommissionResult,
NodeKey,
@@ -78,9 +79,9 @@
"""Identify node being queried based on its MAC address.
This form of access is a security hazard, and thus it is permitted only
- on development systems where ALLOW_ANONYMOUS_METADATA_ACCESS is enabled.
+ on development systems where ALLOW_UNSAFE_METADATA_ACCESS is enabled.
"""
- if not settings.ALLOW_ANONYMOUS_METADATA_ACCESS:
+ if not settings.ALLOW_UNSAFE_METADATA_ACCESS:
raise PermissionDenied(
"Unauthenticated metadata access is not allowed on this MAAS.")
matching_macs = list(MACAddress.objects.filter(mac_address=mac))
@@ -330,6 +331,12 @@
class AnonMetaDataHandler(VersionIndexHandler):
"""Anonymous metadata."""
+ @api_exported('GET')
+ def generate_preseed(self, request, version=None, system_id=None):
+ """Render and return a preseed script for the given node."""
+ node = get_object_or_404(Node, system_id=system_id)
+ return HttpResponse(get_preseed(node), mimetype="text/plain")
+
@api_exported('POST')
def netboot_off(self, request, version=None, system_id=None):
"""Turn off netboot on the node.
=== modified file 'src/metadataserver/tests/test_api.py'
--- src/metadataserver/tests/test_api.py 2012-06-20 14:41:56 +0000
+++ src/metadataserver/tests/test_api.py 2012-06-21 21:06:22 +0000
@@ -30,6 +30,7 @@
from maasserver.testing.factory import factory
from maasserver.testing.oauthclient import OAuthAuthenticatedClient
from maastesting.djangotestcase import DjangoTestCase
+from metadataserver import api
from metadataserver.api import (
check_version,
get_node_for_mac,
@@ -92,7 +93,7 @@
get_node_for_request, self.fake_request())
def test_get_node_for_mac_refuses_if_anonymous_access_disabled(self):
- self.patch(settings, 'ALLOW_ANONYMOUS_METADATA_ACCESS', False)
+ self.patch(settings, 'ALLOW_UNSAFE_METADATA_ACCESS', False)
self.assertRaises(
PermissionDenied, get_node_for_mac, factory.getRandomMACAddress())
@@ -517,7 +518,7 @@
(response.status_code, response.content))
def test_api_normally_disallows_anonymous_node_metadata_access(self):
- self.patch(settings, 'ALLOW_ANONYMOUS_METADATA_ACCESS', False)
+ self.patch(settings, 'ALLOW_UNSAFE_METADATA_ACCESS', False)
mac = factory.make_mac_address()
url = reverse(
'metadata-meta-data-by-mac',
@@ -544,8 +545,7 @@
def test_anonymous_netboot_off(self):
node = factory.make_node(netboot=True)
anon_netboot_off_url = reverse(
- 'metadata-anon-node-edit', args=['latest',
- node.system_id])
+ 'metadata-node-by-id', args=['latest', node.system_id])
response = self.client.post(
anon_netboot_off_url, {'op': 'netboot_off'})
node = reload_object(node)
@@ -553,3 +553,23 @@
(httplib.OK, False),
(response.status_code, node.netboot),
response)
+
+ def test_anonymous_generate_preseed(self):
+ # The preseed for a node can be obtained anonymously.
+ node = factory.make_node()
+ anon_node_url = reverse(
+ 'metadata-node-by-id',
+ args=['latest', node.system_id])
+ # Fake the preseed so we're just exercising the view.
+ fake_preseed = factory.getRandomString()
+ self.patch(api, "get_preseed", lambda node: fake_preseed)
+ response = self.client.get(
+ anon_node_url, {'op': 'generate_preseed'})
+ self.assertEqual(
+ (httplib.OK,
+ "text/plain",
+ fake_preseed),
+ (response.status_code,
+ response["Content-Type"],
+ response.content),
+ response)
=== modified file 'src/metadataserver/urls.py'
--- src/metadataserver/urls.py 2012-06-20 13:38:50 +0000
+++ src/metadataserver/urls.py 2012-06-21 21:06:22 +0000
@@ -35,11 +35,11 @@
index_handler = Resource(IndexHandler, authentication=api_auth)
-# Handlers for anonymous node operations.
-meta_data_node_anon_handler = Resource(AnonMetaDataHandler)
-
-
-# Handlers for anonymous random metadata access.
+# Handlers for anonymous metadata operations.
+meta_data_node_by_id_handler = Resource(AnonMetaDataHandler)
+
+
+# Handlers for UNSAFE anonymous random metadata access.
meta_data_by_mac_handler = Resource(MetaDataHandler)
user_data_by_mac_handler = Resource(UserDataHandler)
version_index_by_mac_handler = Resource(VersionIndexHandler)
@@ -61,22 +61,22 @@
url(r'', index_handler, name='metadata'),
)
-# Anonymous random metadata access. These serve requests from the nodes
-# which happen when the environment is so minimal that proper
+# Anonymous random metadata access, keyed by system ID. These serve requests
+# from the nodes which happen when the environment is so minimal that proper
# authenticated calls are not possible.
-anon_patterns = patterns(
+by_id_patterns = patterns(
'',
# XXX: rvb 2012-06-20 bug=1015559: This method is accessible
# without authentication. This is a security threat.
url(
- r'(?P<version>[^/]+)/(?P<system_id>[\w\-]+)/edit/$',
- meta_data_node_anon_handler,
- name='metadata-anon-node-edit'),
+ r'(?P<version>[^/]+)/by-id/(?P<system_id>[\w\-]+)/$',
+ meta_data_node_by_id_handler,
+ name='metadata-node-by-id'),
)
-# Anonymous random metadata access keyed by MAC address. These won't
-# work unless ALLOW_ANONYMOUS_METADATA_ACCESS is enabled, which you
-# should never do on a production MAAS.
+# UNSAFE anonymous random metadata access, keyed by MAC address. These won't
+# work unless ALLOW_UNSAFE_METADATA_ACCESS is enabled, which you should never
+# do on a production MAAS.
by_mac_patterns = patterns(
'',
url(
@@ -97,4 +97,4 @@
# URL patterns. The anonymous patterns are listed first because they're
# so recognizable: there's no chance of a regular metadata access being
# mistaken for one of these based on URL pattern match.
-urlpatterns = anon_patterns + by_mac_patterns + node_patterns
+urlpatterns = by_id_patterns + by_mac_patterns + node_patterns