OpenDaylight comes with a set of REST interfaces. For instance, in one of my previous posts, I have introduced OpenDaylight’s REST interface for programming flows. With these interfaces, you can easily outsource your control logic to a remote server other than the server on which the OpenDaylight controller is running. Basically, the controller offers a web service, and the control application invokes this service sending REST requests via HTTP.
Although the concept to offer network services as web services is very nice and lowers the barriers to “program” the network significantly, it also brings up security problems well known from web services. If you do not authenticate clients, any client that can send HTTP requests to your controller can control your network — certainly something you want to avoid!
Therefore, in this post, I will show how to secure OpenDaylight’s REST interfaces.
Authentication in OpenDaylight
The REST interfaces are so-called northbound interfaces between controller and control application. So you can think of the controller as the service and the control application as the client as shown in the figure below.
In order to ensure that the controller only accepts requests from authorized clients, clients have to authenticate themselves. OpenDaylight uses HTTP Basic authentication, which is based on user names and passwords (default: admin, admin). Sounds good: So only a client with the valid password can invoke the service … or is there a problem? In order to see the security threats, we have to take a closer look at the HTTP Basic authentication mechanism.
The follwing command invokes the Flow Programmer service of OpenDaylight via cURL and prints the HTTP header information of the request:
user@host:$ curl -u admin:admin -H 'Accept: application/xml' -v 'http://localhost:8080/controller/nb/v2/flowprogrammer/default/' * About to connect() to localhost port 8080 (#0) * Trying 127.0.0.1... connected * Server auth using Basic with user 'admin' > GET /controller/nb/v2/flowprogrammer/default/ HTTP/1.1 > Authorization: Basic YWRtaW46YWRtaW4= > User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/18.104.22.168 libidn/1.23 librtmp/2.3 > Host: localhost:8080 > Accept: application/xml > < HTTP/1.1 200 OK < Server: Apache-Coyote/1.1 < Cache-Control: private < Expires: Thu, 01 Jan 1970 01:00:00 CET < Set-Cookie: JSESSIONIDSSO=9426E0F12A0A0C80BE549451707EF339; Path=/ < Set-Cookie: JSESSIONID=DB23D1EE61348E101E6CE8117A04B8D8; Path=/ < Content-Type: application/xml < Content-Length: 62 < Date: Sun, 12 Jan 2014 16:50:38 GMT < * Connection #0 to host localhost left intact * Closing connection #0 <?xml version="1.0" encoding="UTF-8" standalone="yes"?><list/>
The interesting header field is “Authorization” with its value “Basic YWRtaW46YWRtaW4=”. Here, “YWRtaW46YWRtaW4=” is the user name and password sent from the client to the controller. Although this value looks quite cryptic, it is actually plain text. This value is simply the Base64 encoding of the user name and password string “admin:admin”. Base64 is a simple translation of 8 bit characters to 6 bit characters involving no encryption or hashing at all! Basically, it comes from the time when SMTP was restricted to sending 7 bit ASCII characters. Everything else like binary (8 bit) content had to be translated to 7 bit characters first, and exactly that’s the job of Base64 encoding. You can use a paper and pencil to decode it. Just interpret the bit pattern of three 8 bit characters as four 6 bit characters and look-up the values of the 6 bit characters in the Base64 table. Or if you are lazy, just use one of the many Base64 decoders in the WWW.
Now the problem should become obvious. If your network between client and controller is non-trusted and an attacker can eavesdrop on the communication channel, he can read your user name and password.
Securing the REST Interface
Now that we see the problem, also the solution should become obvious. We need a secure channel between client and controller, so an attacker cannot read the header fields of the HTTP request. The HTTPS standard provides exactly that. Moreover, the client can make sure that it really connects to the right controller, and not the controller of an attacker who just wants to intercept our password. So we use HTTPS to encrypt the channel between client and controller and to authenticate the controller, and HTTP Basic authentication to authenticate the client.
So the trick is, enabling HTTPS in OpenDaylight, which is turned off by default. Note that above we used the insecure HTTP protocol on port 8080. Now we want to use HTTPS on port 8443 (or 443 if you want to use the official HTTPS port instead of the alternative port).
OpenDaylight uses the Tomcat servlet container to provide its web services. Therefore, the steps to enable HTTPS are very similar to configuring Tomcat.
First, we need a server certificate that the client can use to authenticate the server. Of course, a certificate signed by a trusted certification authority would be best. However, here I will show how to create your own self-signed certificate using the Java keytool:
user@host:$ keytool -genkeypair -v -alias tomcat -storepass changeit -validity 1825 -keysize 1024 -keyalg DSA What is your first and last name? [Unknown]: duerr-mininet.informatik.uni-stuttgart.de What is the name of your organizational unit? [Unknown]: Institute of Parallel and Distributed Systems What is the name of your organization? [Unknown]: University of Stuttgart What is the name of your City or Locality? [Unknown]: Stuttgart What is the name of your State or Province? [Unknown]: Baden-Wuerttemberg What is the two-letter country code for this unit? [Unknown]: de Is CN=duerr-mininet.informatik.uni-stuttgart.de, OU=Institute of Parallel and Distributed Systems, O=University of Stuttgart, L=Stuttgart, ST=Baden-Wuerttemberg, C=de correct? [no]: yes Generating 1,024 bit DSA key pair and self-signed certificate (SHA1withDSA) with a validity of 1,825 days for: CN=duerr-mininet.informatik.uni-stuttgart.de, OU=Institute of Parallel and Distributed Systems, O=University of Stuttgart, L=Stuttgart, ST=Baden-Wuerttemberg, C=de Enter key password for <tomcat> (RETURN if same as keystore password): Re-enter new password: [Storing /home/duerrfk/.keystore]
This creates a certificate valid for five years (1825 days) and stores it in the keystore .keystore in my home directory /home/duerrfk. As first and last name, we use the DNS name of the machine, the controller is running on. The rest should be pretty obvious.
With this information, we can now configure the OpenDaylight controller. First, check out and compile OpenDaylight, if you haven’t done so already:
user@host:$ git clone https://git.opendaylight.org/gerrit/p/controller.git user@host:$ cd controller/opendaylight/distribution/opendaylight/ user@host:$ mvn clean install
Now edit the following file, where “controller” is the root directory of the controller you checked out:
user@host:$ emacs controller/opendaylight/distribution/opendaylight/target/distribution.opendaylight-osgipackage/opendaylight/configuration/tomcat-server.xml
Comment in the following XML element:
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" maxThreads="150" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" keystoreFile="/home/duerrfk/.keystore" keystorePass="changeit"/>
Use the keystore location and password that you used before with the keytool command.
Now you can start OpenDaylight and connect via HTTPS to the controller on port 8443. Use your web browser to try it.
Making Secure Calls
One last step needs to be done before we can call the controller securely by a client. If you did not use a certificate signed by a well-known certification authority — like we did above with our self-signed certficate –, you need to present the client with the server certificate it should use for authenticating the controller. If you are using cURL, the required option is “–cacert”:
user@host:$ curl -u admin:admin --cacert ~/cert-duerr-mininet.pem -v -H 'Accept: application/xml' 'https://duerr-mininet.informatik.uni-stuttgart.de:8443/controller/nb/v2/flowprogrammer/default/'
So the last question is, how do we get the server certificate in PEM format? To this end, we can use openssl to call our server and store the returned certificate:
user@host:$ openssl s_client -connect duerr-mininet.informatik.uni-stuttgart.de:8443
The PEM certificate is everything between “—–BEGIN CERTIFICATE—–” and “—–END CERTIFICATE—–” (including these two lines), so we can just copy this to a file. Note that you have to make sure that the call is actually going to the right server (not the server of an attacker). So better call it from the machine where your controller is running to avoid a “chicken and egg” problem.
Now we can securely outsource our control application to a remote host, for instance, a host in our campus network or a cloud server running in a remote data center.
- The tutorial is licensed under the Attribution-ShareAlike 4.0 International License (CC BY-SA 4.0).