Developer’s Authorization

Auth Server

class swift.auth.server.AuthController(conf, ring=None)

Bases: object

Sample implementation of an authorization server for development work. This server only implements the basic functionality and isn’t written for high availability or to scale to thousands (or even hundreds) of requests per second. It is mainly for use by developers working on the rest of the system.

The design of the auth system was restricted by a couple of existing systems.

This implementation stores an account name, user name, and password (in plain text!) as well as a corresponding Swift cluster url and account hash. One existing auth system used account, user, and password whereas another used just account and an “API key”. Here, we support both systems with their various, sometimes colliding headers.

The most common use case is by the end user:

  • The user makes a ReST call to the auth server requesting a token and url to use to access the Swift cluster.
  • The auth system validates the user info and returns a token and url for the user to use with the Swift cluster.
  • The user makes a ReST call to the Swift cluster using the url given with the token as the X-Auth-Token header.
  • The Swift cluster makes an ReST call to the auth server to validate the token for the given account hash, caching the result for future requests up to the expiration the auth server returns.
  • The auth server validates the token / account hash given and returns the expiration for the token.
  • The Swift cluster completes the user’s request.

Another use case is creating a new account:

  • The developer makes a ReST call to create a new account.
  • The auth server makes ReST calls to the Swift cluster’s account servers to create a new account on its end.
  • The auth server records the information in its database.

A last use case is recreating existing accounts; this is really only useful on a development system when the drives are reformatted quite often but the auth server’s database is retained:

  • A developer makes an ReST call to have the existing accounts recreated.
  • For each account in its database, the auth server makes ReST calls to the Swift cluster’s account servers to create a specific account on its end.
Parameters:
  • conf – The [auth-server] dictionary of the auth server configuration file
  • ring – Overrides loading the account ring from a file; useful for testing.

See the etc/auth-server.conf-sample for information on the possible configuration parameters.

add_storage_account(account_name='')

Creates an account within the Swift cluster by making a ReST call to each of the responsible account servers.

Parameter:account_name – The desired name for the account; if omitted a UUID4 will be used.
Returns:False upon failure, otherwise the name of the account within the Swift cluster.
create_account(new_account, new_user, new_password)

Handles the create_account call for developers, used to request an account be created both on a Swift cluster and in the auth server database.

This will make ReST requests to the Swift cluster’s account servers to have an account created on its side. The resulting account hash along with the URL to use to access the account, the account name, the user name, and the password is recorded in the auth server’s database. The url is constructed now and stored separately to support changing the configuration file’s default_cluster_url for directing new accounts to a different Swift cluster while still supporting old accounts going to the Swift clusters they were created on.

Parameters:
  • new_account – The name for the new account
  • new_user – The name for the new user
  • new_password – The password for the new account
Returns:

False if the create fails, storage url if successful

get_conn(*args, **kwds)
Returns a DB API connection instance to the auth server’s SQLite database. This is a contextmanager call to be use with the ‘with’ statement. It takes no parameters.
handleREST(env, start_response)

Handles routing of ReST requests. This handler also logs all requests.

Parameters:
  • env – WSGI environment
  • start_response – WSGI start_response function
handle_account_create(request)

Handles Rest requests from developers to have an account created.

Valid URL paths:
  • PUT /account/<account-name>/<user-name> - create the account
Valid headers:
  • X-Auth-Key: <password> (Only required when creating an account)

If the HTTP request returns with a 204, then the account was created, and the storage url will be available in the X-Storage-Url header.

Parameter:request – webob.Request object
handle_account_recreate(request)

Handles ReST requests from developers to have accounts in the Auth system recreated in Swift. I know this is bad ReST style, but this isn’t production right? :)

Valid URL paths:
  • POST /recreate_accounts
Parameter:request – webob.Request object
handle_auth(request)

Handles ReST requests from end users for a Swift cluster url and auth token. This can handle all the various headers and formats that existing auth systems used, so it’s a bit of a chameleon.

Valid URL paths:
  • GET /v1/<account-name>/auth
  • GET /auth
  • GET /v1.0
Valid headers:
  • X-Auth-User: <account-name>:<user-name>

  • X-Auth-Key: <password>

  • X-Storage-User: [<account-name>:]<user-name>

    The [<account-name>:] is only optional here if the /v1/<account-name>/auth path is used.

  • X-Storage-Pass: <password>

The (currently) preferred method is to use /v1.0 path and the X-Auth-User and X-Auth-Key headers.

Parameter:request – A webob.Request instance.
handle_token(request)

Hanles ReST request from Swift to validate tokens

Valid URL paths:
  • GET /token/<account-hash>/<token>

If the HTTP equest returns with a 204, then the token is valid, and the TTL of the token will be available in the X-Auth-Ttl header.

Parameter:request – webob.Request object
purge_old_tokens()
Removes tokens that have expired from the auth server’s database. This is called by validate_token() and GET() to help keep the database clean.
recreate_accounts()

Recreates the accounts from the existing auth database in the Swift cluster. This is useful on a development system when the drives are reformatted quite often but the auth server’s database is retained.

Returns:A string indicating accounts and failures
validate_token(token, account_hash)

Tests if the given token is a valid token

Parameters:
  • token – The token to validate
  • account_hash – The account hash the token is being used with
Returns:

TTL if valid, False otherwise

Table Of Contents

Previous topic

Object

Next topic

Misc

This Page