Simple Webserver with Openstack Swift

2 minute read


Openstack

Swift Based Webserver

How can I use Swift as a simple websever?

I received this question a few times recently. Below is a quick how to using Bluemix object storage.

Steps

  1. Create a swift instance
  2. Put content into swift
  3. Permit unauthenticated read access to the container


Create a swift container

Login into your BlueMix account here. After you login, select catalog from the top navigation. On the left navigation bar select the checkbox next to Storage to limit the display to IBM Cloud storage services only. Your screen should look like this:

Storage services on Bluemix
List of storage services on Bluemix
  • Select Object Storage
  • Select whichever plan is necessary for your scaling goals
  • Leave the other defaults values
  • Click create.

After a few moments, the IBM Cloud Object Storage service should be created and added to your Bluemix space.

Click on service credentials on the left navigation bar to find your API key.

Note this API key, you will need it to access your object storage instance.

Storage credentials on Bluemix
Storage credentials

Your Bluemix space now has object storage enabled

Insert content into swift

Create a container

Click on “Manage” on the left navigation bar. Then click “Add a container”

Add a container
Add storage container to Bluemix

Name the container

After clicking “Add a container” you will be prompted to give the container a name. Choose whatever name you want.

Name the container
Name your new storage container in Bluemix

Add a file

Click on “Add files” to upload new files to your container. This will open a file selector window. I uploaded the Openstack image you see above.

Add files to a container
Add a file to your storage container in Bluemix

Once you select your file, your container information in Bluemix should update with storage space consumed and details on the uploaded file.

Files added to container
Files added to to your storage container in Bluemix

Permit unauthenticated read access to the container

Setup swift command line tool

Follow the steps in the Bluemix Docs to setup and install the swift CLI.

Export service credentials

Once the CLI is installed the first step will be to take the service credentials you noted earlier and export them into the appropriate environment variables for the swift tool. Below is an example.

export OS_USER_ID=24a20b8e4e724f5fa9e7bfdc79ca7e85
export OS_PASSWORD=aaa55AAAaaaaa]?,
export OS_PROJECT_ID=383ec90b22ff4ba4a78636f4e989d5b1
export OS_AUTH_URL=https://identity.open.softlayer.com/v3
export OS_REGION_NAME=dallas
export OS_IDENTITY_API_VERSION=3
export OS_AUTH_VERSION=3

Authenticate

Next execute the “swift auth” command. This will authenticate the swift session and output the storage path to the files that were added.

swift auth
export OS_STORAGE_URL=https://dal.objectstorage.open.softlayer.com/v1/AUTH_2f1d538663bf4333b8bb498369241ce5
export OS_AUTH_TOKEN=fooooooovlYmo5-UdEdYg_uRh0JWniXxKr_zuO0FC__ebrXqrhOPwVZRwa-EBPTbrTd1fwQ7-Dhyqs7ZZsc2uEtrmvwD6g5Wi3Vg__tnl1LkfClsY6rR_iZgYFcDPwYdsLbpCSo0eoU7FNsZHTCJyXJefZXhzm2aWZC0XPMeaDoFv0uik

Note the OS_STORAGE_URL, this is the base URL for all unauthentacted public requests to object storage.

Modify container permissions

Use the swift command to enable unauthenticated read access to the container.

swift post foo --read-acl ".r:*,.rlistings"
swift post -m 'web-listings: true' foo

Test access

Noting the OS_STORAGE_URL above, the fully constructed URL for my object is:

https://dal.objectstorage.open.softlayer.com/v1/AUTH_2f1d538663bf4333b8bb498369241ce5/foo/openstack.jpg

Test accessing this with wget:

wget -O/dev/null -q https://dal.objectstorage.open.softlayer.com/v1/AUTH_2f1d538663bf4333b8bb498369241ce5/foo/openstack.jpg && echo exists || echo not exist
exists

If the above command outputs exists, the file is now readable by all. Any additional files you add to the container will now also be readable from the web.

Limitations

You can use use Bluemix object storage as a quick and dirty webserver. However, object storage does not give you the full control and customizations usually needed for a production web server. For simple things this is an easy way to get objects onto the web. In fact, I am serving the openstack logo at the top of this page out of Bluemix object storage.

Resources

Should you run into any issues consult the BlueMix Documentation or reach out to me on twitter