Stop devstack from exploding in paste config changes

Change-Id: I842691479c7c1b46bab627a1f436d9cef3f5148d
diff --git a/stack.sh b/stack.sh
index a79f794..c0763d4 100755
--- a/stack.sh
+++ b/stack.sh
@@ -777,14 +777,26 @@
 
 # Nova
 # ----
-
 if [[ "$ENABLED_SERVICES" =~ "n-api" ]]; then
     # We are going to use a sample http middleware configuration based on the
     # one from the keystone project to launch nova.  This paste config adds
-    # the configuration required for nova to validate keystone tokens. We add
-    # our own service token to the configuration.
-    cp $FILES/nova-api-paste.ini $NOVA_DIR/bin
+    # the configuration required for nova to validate keystone tokens.
+
+    # First we add a some extra data to the default paste config from nova
+    cat $NOVA_DIR/etc/nova/api-paste.ini $FILES/nova-api-paste.ini > $NOVA_DIR/bin/nova-api-paste.ini
+
+    # Then we add our own service token to the configuration
     sed -e "s,%SERVICE_TOKEN%,$SERVICE_TOKEN,g" -i $NOVA_DIR/bin/nova-api-paste.ini
+
+    # Finally, we change the pipelines in nova to use keystone
+    function replace_pipeline() {
+        sed "/\[pipeline:$1\]/,/\[/s/^pipeline = .*/pipeline = $2/" -i $NOVA_DIR/bin/nova-api-paste.ini
+    }
+    replace_pipeline "ec2cloud" "ec2faultwrap logrequest totoken authtoken keystonecontext cloudrequest authorizer ec2executor"
+    replace_pipeline "ec2admin" "ec2faultwrap logrequest totoken authtoken keystonecontext adminrequest authorizer ec2executor"
+    replace_pipeline "openstack_api_v2" "faultwrap authtoken keystonecontext ratelimit serialize extensions osapi_app_v2"
+    replace_pipeline "openstack_compute_api_v2" "faultwrap authtoken keystonecontext ratelimit serialize compute_extensions osapi_compute_app_v2"
+    replace_pipeline "openstack_volume_api_v1" "faultwrap authtoken keystonecontext ratelimit serialize volume_extensions osapi_volume_app_v1"
 fi
 
 # Helper to clean iptables rules
@@ -998,7 +1010,7 @@
    sed "s,%SWIFT_LOGDIR%,${swift_log_dir}," $FILES/swift/rsyslog.conf | sudo \
        tee /etc/rsyslog.d/10-swift.conf
    sudo restart rsyslog
-   
+
    # We create two helper scripts :
    #
    # - swift-remakerings