[[ux_authz]]
Configuring attribute sources
-----------------------------

The authorization process in UNICORE/X requires that each Grid user 
(identified by an X.509 certificate or just the DN) is assigned 
some _attributes_ such as her _role_.   

So the single most important item for security configuration is
selecting and maintaining a so called _attribute source_, which is
used by UNICORE/X to assign attributes to Grid users.

Several attribute sources are available, that can even be combined 
for maximum flexibility and administrative control.

To configure the attribute sources, the +uas.security.attributes.order+ 
property in the 'uas.config' file is used. This is a space-separated 
list with attribute sources names, where the named attribute sources will 
be queried one after the other, allowing you to query multiple 
attribute sources, override values etc. 

A second property, +uas.security.attributes.combiningPolicy+, allows you 
to control how attributes from different sources are combined.

For example, the following configuration snippet

------
#
# Authorisation attribute source configuration
# 
uas.security.attributes.order=XUUDB FILE

#
# Combining policy
#
# MERGE_LAST_OVERRIDES (default), FIRST_APPLICABLE, FIRST_ACCESSIBLE or  MERGE
uas.security.attributes.combiningPolicy=MERGE_LAST_OVERRIDES
------  

will declare two attribute sources, "XUUDB" and "FILE", which should
be both queried and combined using the MERGE_LAST_OVERRIDES policy.

Since all attribute sources will be queried, it has to be defined how 
attributes will be combined. For example, assume you have both XUUDB and FILE,
and both return a xlogin attribute for a certain user, say "xlogin_1" and "xlogin_2".

The different combining policies are
  
  - MERGE_LAST_OVERRIDES : new attributes override those from previous sources. 
In our example, the result would be "xlogin_2". 
  
  - FIRST_APPLICABLE : the attributes from the first source that returned a non 
empty list of attributes  are used. In our case this would be "xlogin_1". If there 
were no xlogin attribute for the user in XUUDB then "xlogin_2" would be returned.
  
  - FIRST_ACCESSIBLE : the attributes from the first source that is accessible are used. 
In our case this would be "xlogin_1". This policy is useful for redundant attribute sources. 
E.g. you can configure two instances of XUUDB with the same users data; the 2nd one will 
be tried only if the first one is down.  
  
  - MERGE : attributes are merged. In our example, the result would be "xlogin_1, xlogin_2",
and the user would be able to choose between them.


Each of the sources needs a mandatory configuration option defining
the Java class, and several optional properties that configure the
attribute source. In our example, one would need to configure both
the "XUUDB" and the "FILE" source:

------  
uas.security.attributes.XUUDB.class=...
uas.security.attributes.XUUDB.xuudbHost=...
...

uas.security.attributes.FILE.class=...
uas.security.attributes.FILE.file=...
...

------ 
 
Additionally you can mix several combining policies together, see "Chained attribute source" 
below for details.


UNICORE incarnation attributes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Precisely speaking UNICORE uses user's attributes for two purposes:
 
 - to perform 'user incarnation', i.e. map the grid user to the local system,
 - to authorize the user.
 
Note that actual names of the 
attributes presented here are not very important. Real attribute
names are defined by attribute source (advanced attribute sources, like UVOS/SAML attribute
source, even provide a possibility to choose what attributes are mapped to internal UNICORE 
attributes. Therefore it is only important to know the concepts represented by the below internal attributes.
On the other hand values which are defined below are important.   

The attributes in UNICORE are multi-valued.

There are several special attributes used for incarnation:

   - 'Xlogin' - specify what local user id (in UNIX so called 'uid') 
   should be assigned for the grid user.
   - 'Group' - specify the primary group (primary gid) that the grid user should get. 
   - 'Supplementary groups' - specify all supplementary groups the grid user should get.
   - 'Add operating system groups' - boolean attribute saying whether groups assigned to the 
   Xlogin (i.e. the local uid of the grid user) in the operating system should be additionally
   added for the grid user.
   - 'Queue' - override IDB queues setting for the particular user, 
   defining available BSS queues. 

There is one special authorization attribute:

   - 'role' - represents abstract users role. The role is used in a default (and rarely changed)
   UNICORE authorization policy and in authorization process in general. There are several 
   possible values that make sense: 
     - +user+ - value specifies that the subject is allowed to use the site as a normal user
     (submit jobs, get results, ...)
     - +admin+ - value specifies that the subject is an admin and may do everything. 
     For example may submit jobs, get results of jobs of other users and even delete them.
     - +trustedAgent+ - this value is used to express that the subject may act as any user
     the subject wants. E.g. if John has this role then can get Marry's job results and also
     submit job as Frank. It is highly suggested not to use this role, its support is minimal
     mostly for backwards compatibility.
     - anything else - means that user is not allowed to do anything serious. Some very basic,
     read-only operations are allowed, but this is technical detail. It is a good practice to
     use value +banned+ in such case. 

Finally UNICORE can consume other attributes. All other attributes are used only for authorization.
Currently all such additional attributes which are received from attribute source are treated
as XACML attributes and are put into XACML evaluation context. This feature is rather
rarely used, but it allows to create a very fine grained authorization policies, using
custom attributes. 

Particular attribute sources define how to assign these attribute to users. Not always 
all are supported, e.g. XUUDB can not define per-user queues and offers only 
'Group' attribute for controlling users' groups. 

After presenting all special UNICORE attributes it must be noted that those attributes are
used in two ways. Their primary role is to strictly define what is allowed for the
user. For instance the 'Xlogin' values specify the valid Xlogins from which the user may
choose one. One exception here is 'Add operating system groups' - user is always able to 
set this according to his/her preference.

The second way of using those attributes is to specify the default behavior, when the user 
is not expressing a preference. E.g. a default 'Group' (which must be single valued) 
specify which group should be used if the user didn't provide any.

Attribute sources define the permitted values and default values for the attributes in 
various ways. Some use conventions (e.g. that first permitted value is a default one), some
use pair of real attributes to define each of UNICORE attributes.     



XUUDB
~~~~~

The XUUDB is the standard option in UNICORE. It has the following features
  
   - Web service interface for querying and administration. It is suitable for serving data for multiple 
   clients. Usually it is deployed to handle attributes for a whole grid site.
   
   - Access protected by client-authenticated SSL
   
   - Supports the +xlogin+, +role+ and +project+ attributes (where +project+ maps to Unix groups)

   - Multiple xlogins per certificate or DN, where the user can select one
   
   - Entries are grouped using the so-called 'Grid component ID' (GCID). This makes it easy to
assign users different attributes when accessing different UNICORE/X servers.
    
   
To enable and configure the XUUDB, set the following properties in 'uas.config'.

----------
uas.security.attributes.order=... XUUDB ...
uas.security.attributes.XUUDB.class=eu.unicore.uas.security.XUUDBAuthoriser
uas.security.attributes.XUUDB.xuudbHost=https://<xuudbhost>
uas.security.attributes.XUUDB.xuudbPort=<xuudbport>
uas.security.attributes.XUUDB.xuudbGCID=<your_gcid>
----------

Full XUUDB documentation is available from http.://www.unicore.eu/documentation/manuals/xuudb


UVOS
~~~~

The UNICORE Virtual Organisation Service (UVOS) is a powerful tool for managing access 
based on the concept of virtual organisations. A detailed description and configuration 
guidance can be obtained from
http://unicore-dev.zam.kfa-juelich.de/documentation/xfire-voutils-1.4.0/manual.html[http://unicore-dev.zam.kfa-juelich.de/documentation/xfire-voutils-1.4.0/manual.html]


File attribute source
~~~~~~~~~~~~~~~~~~~~~

In simple circumstances, or as an addition to a XUUDB or UVOS, the file attribute source 
can be used. As the name implies a simple map file is used to map DNs to xlogin, role 
and other attributes. It is useful when you don't want to setup an additional service 
(XUUDB or UVOS) and also when you want to locally override attributes for selected users
(e.g. to ban somebody).
  
To use, set
  
----------
uas.security.attributes.order=... FILE ...
uas.security.attributes.FILE.class=eu.unicore.uas.security.file.FileAttributeSource
uas.security.attributes.FILE.file=<your map file>
uas.security.attributes.FILE.matching=<strict|regexp>
----------

The map file itself has the following format: 
  
------------
<?xml version="1.0" encoding="UTF-8"?>
<fileAttributeSource>
   <entry key="USER DN">
      <attribute name="role">
         <value>user</value>
      </attribute>
      <attribute name="xlogin">
         <value>unixuser</value>
         <value>nobody</value>
         ...
      </attribute>
      ...
   </entry>
   ...
</fileAttributeSource>
------------


You can add an arbitrary number of attributes and attribute values.

The 'matching' option controls how a client's DN is mapped to a file entry.
In 'strict' mode, the canonical representation of the key is compared with the 
canonical representation of the argument. In 'regexp' mode the key is considered 
a Java regular expression and the argument is matched with it.  When constructing 
regular expressions a special care must be taken to construct the regular expression 
from the canonical representation of the DN. The canonical representation is defined 
http://download.oracle.com/javase/6/docs/api/javax/security/auth/x500/X500Principal.html#getName(java.lang.String)[here].
(but you don't have to perform the two last upper/lower case operations).
In 90% of all cases (no multiple attributes in one RDN, no special characters, no 
uncommon attributes) it just means that you should remove extra spaces between RDNs.  

The evaluation is simplistic: the first entry matching the client is used (which is 
important when you use regular expressions). 

The attributes file is automatically refreshed after any change, before a subsequent read. 
If the syntax is wrong then an error message is logged and the old version is used.

Recognized attribute names are: 

   - +xlogin+
   - +role+
   - +group+
   - +supplementaryGroups+
   - +addOsGroups+ (with values +true+ or +false+)
   - +queue+
    
Attributes with those names (case insensitive) are handled as special UNICORE incarnation
attributes. The correspondence should be straightforward, e.g. the +xlogin+ is 
used to provide available local OS user names for the client. 

For all attributes except of the +supplementaryGroups+ the default value is the first one
provided. For +supplementaryGroups+ the default value contains all defined values. 

You can also define other attributes - those will be used as XACML authorization 
attributes, with XACML string type.  


Chained attribute source
~~~~~~~~~~~~~~~~~~~~~~~~

Chained attribute source is a meta source which allows you to mix different combining 
policies together. It is configured as other attribute sources with two parameters 
(except of its class): order and combiningPolicy. The result of the chain attribute 
source is the set of attributes returned by the configured chain. 

Let's consider the following example situation where we want to configure two 
redundant UVOS servers (both serving the same data) to achieve high availability. 
Additionally we want to override settings for some
users using a local file attribute source (e.g. to ban selected users).

----------
# The main chain configuration:
uas.security.attributes.order=UVOS_CLUSTER FILE
uas.security.attributes.combiningPolicy=MERGE_LAST_OVERRIDES

# The FILE source cfg:
uas.security.attributes.FILE.class=eu.unicore.uas.security.file.FileBasedAuthoriser
uas.security.attributes.FILE.file=<your map file>

# The UVOS_CLUSTER is a sub chain:
uas.security.attributes.UVOS_CLUSTER.class=de.fzj.unicore.uas.security.util.AttributeSourcesChain
uas.security.attributes.UVOS_CLUSTER.order=UVOS1 UVOS2
uas.security.attributes.UVOS_CLUSTER.combiningPolicy=FIRST_ACCESSIBLE

# And configuration of the two real sources used in the sub chain:
uas.security.attributes.UVOS1.class=...
...
uas.security.attributes.UVOS2.class=...
...
----------  
