JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.
If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.
If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.
| CodeSonar® 9.2p0 | CONFIDENTIAL | CodeSecure Inc |
Adding a new CodeSonar hub authentication mechanism involves four steps:
This tutorial illustrates these steps with a simple example authentication plug-in, and provides a more complex example for users that are interested.
Note that third party authentication service accounts and hub user accounts remain separate entities with separate sets of credentials. Changing hub user account credentials (for example, by changing your password in the Settings: Account tab) has no effect on authentication service account information, and changing authentication service account credentials has no effect on hub user account information.
In this section (and throughout this manual), $CSONAR indicates the CodeSonar installation directory.
The requirements for adding a custom hub authentication plug-in are described in Custom Hub-Authentication Plug-ins
Adding A Simple Authenticator walks through the steps for a trivial authenticator.
A More Complex Authenticator provides a more "realistic" example that you can use as a basis for creating your own authentication plug-ins.
In this example you will add a simple example authenticator that
checks user credentials against a hardcoded username/password
table.
The following instructions are based on a hub listening at
interface:port with hub directory at hubDir.
The CodeSonar command lines and GUI interactions described in these steps require the following permissions.
It is sufficient to authenticate as a user with the special Administrator role, which immutably has all the necessary permissions. In particular, it is always sufficient to authenticate as special user Administrator.
The hardcoded table used by the simple example authenticator includes a user called 'Administrator'. This might cause a security problem in some cases:
We therefore provide a configuration setting to optionally disable authentication for this user. Note that this setting only applies to authentication with the simple example authenticator: Administrator will still be able to sign in using hub credentials and through any other configured authentication service that permits it.
We need one piece of service-specific configuration information, so our HTML fragment must include an input field to collect it.
We will use the following fragment: you will see in the next step that we have implemented function get_conf_html() to return this text.
<style>
#tutorial_auth_table{ width: 800px; }
#tutorial_auth_table td{vertical-align: top;text-align: left;}
</style>
<table id="tutorial_auth_table" cellpadding="10">
<tr>
<td><b>Include Administrator?</b>:</td>
<td><input type="checkbox" name="include_admin"><br>
The user database for this authentication scheme includes a user<br>
called 'Administrator'. If this is not the same person as the hub<br>
Administrator, it is a good idea to exclude them from authentication.</td>
</tr>
</table>
The Python wrapper for the authenticator is shown below.
# Nontrivial authenticators should raise an AuthException if something # unexpected happens. This authenticator does not actually raise any # exceptions, but the import statement is included as a reminder in # case you decide to use this file as a basis for implementing a # 'real' authenticator. from auth import AuthException class TutorialAuthExample(object): """A very simple example of writing an authorization mechanism""" name = "TutorialAuthExample" # Required name data member. # set of permitted username/password pairs user_db = [('Alex','1234'), ('Administrator','5678')] def get_user(self,username, password, conf_data): # Required get_user() method. # Never authenticate 'Administrator' if plug-in was configured # to exclude this user. if username=='Administrator' and not conf_data['Authenticate Administrator?']: return None # Trivial authentication: check list membership. if (username,password) in self.user_db: # On success, return a dict with keys 'user' and 'email'. # 'user' must map to a nonempty string. 'email' can be a string # or None. return { 'user': username, 'email': None } else: # On failure, return None return None def validate(self, conf_data): # Optional validate() method. # transform checkbox data into a binary attribute new_conf_data = { 'Authenticate Administrator?': 'include_admin' in conf_data} return new_conf_data def get_conf_html(self, conf_data=None): # Optional get_conf_html() method. # Returns the HTML fragment from step 2. return """ <style> #tutorial_auth_table{ width: 800px; } #tutorial_auth_table td{vertical-align: top;text-align: left;} </style> <table id='tutorial_auth_table' cellpadding="10"> <tr> <td><b>Include Administrator?</b>:</td> <td><input type="checkbox" name="include_admin"><br> The user database for this authentication scheme includes a user<br> called 'Administrator'. If this is not the same person as the hub<br> Administrator, it is a good idea to exclude them from authentication.</td> </tr> </table>""" # Required assignment to AUTH_PLUGINS AUTH_PLUGINS = (TutorialAuthExample(),)
In the previous step, you placed the Python wrapper file in the $CSONAR/codesonar/py/hub/auth/ directory. This means that it will be available for configuration on your hub (and any other hubs running from the same CodeSonar installation).
We have provided the following source files for a more complex example authenticator: one based on SSH login authentication.
| auth_ssh_nix.html | A separate HTML file containing the fragment created for Step 2. |
| gtauth_ssh.cpp | A C++ source file implementing the underlying authentication. |
| ssh_nix_authplugin.py | The Python file created for Step 3: a wrapper for the authentication functionality in the binary compiled from gtauth_ssh.cpp. |
This example is provided for illustration only: we do not provide build instructions for the C++ component, although you can certainly try it for yourself if you wish. The following steps represent a guided inspection of the plug-in files.
To report problems with this documentation, please visit https://support.codesecure.com/.