DACSCHECK(1) | DACS Commands Manual | DACSCHECK(1) |
NAME¶
dacscheck - authorization checkSYNOPSIS¶
dacscheck [-admin]
[-app appname]
[-context file]
[-Dname=value]
[-F field_sep]
[-fd domain]
[-fh hostname]
[-fj jurname]
[-fn fedname]
[-dump] [-groups group_vfs] [-h]
[-i ident]
[-il ident]
[-ilg ident] [-ieuid] [-ieuidg]
[-iuid] [-iuidg] [-lg]
[-ll log_level]
[-name_compare method] [-q]
[-redirect] [-roles roles_vfs]
[-rules rule_vfs] [-v]
[-var name=value]
[-vfs vfs_uri] [--] object
dacscheck --version
DESCRIPTION¶
This program is part of the DACS suite. It is a stand-alone program that neither accepts the usual DACS command line options (dacsoptions) nor accesses any DACS configuration files.dacscheck looks at access control rules to test if a given user is authorized to do something or access something. The command's exit status gives the result of the test, and unless the -q flag is given, a line is printed to stdout that indicates the result. It provides simplified, general-purpose access to DACS's access control rule evaluation engine, even for programs other than web services, and it lends itself to fine-grained access control decisions.
More specifically, dacscheck determines if a request for object should be granted according to specified access control rules and a given evaluation context. To do its job, dacscheck needs to know only a few things:
The command does not perform any authentication. It assumes that the caller (or the execution environment) has already established an identity or the identity is inconsequential. It may be used like any other command: run from the command line or a shell script, executed by a compiled program, or called from a scripting language such as Perl[1], PHP[2]. Python[3], Ruby[4], or Tcl/Tk[5].
Some simple examples will illustrate how dacscheck can be used.
Note
The examples in this document have been simplified for readability; in real use, absolute pathnames should appear, error checking should be performed, and so on. Also, the dacscheck program and the rules that it requires must have file permissions set appropriately.
The first example shows how a shell script might call dacscheck to test whether the user running it is allowed to do so. It obtains the user's identity from the operating system; it assumes that the user has invoked the script from the command line and has therefore already signed in to the system. In the example, dacscheck obtains the identity through a system call, but a script might choose to pass the value of the LOGNAME or USER environment variable.
The shell script simply asks dacscheck if the effective uid (see geteuid(2)[6]) is permitted to access /myapp. The exit status of dacscheck (e.g., $? or $status) gives the result. The pathname /myapp is essentially a label that is used to find the access control rule to apply; in this example it simply represents the name of the program. It could be the program's filename, but it need not be.
#! /bin/sh dacscheck -q -ieuid -rules /usr/local/myapp/rules /myapp st="$?" if test "${st}" != 0 then echo "Access is denied" exit "${st}" fi echo "Access is granted" # Do some stuff exit 0
The directory /usr/local/myapp/rules might include a file named acl-app.0 that grants access only to bob and alice:
<acl_rule status="enabled"> <services> <service url_pattern="/myapp"/> </services> <rule order="allow,deny"> <allow> user(":bob") or user(":alice") </allow> </rule> </acl_rule>
Note
Access control rules are described in dacs.acls(5)[7]. As with dacs_acs(8)[8], these rules must be indexed by dacsacl(1)[9]. For example, in a common use case where a DACS configuration file is not being used, the ruleset consulted by dacscheck might be indexed using a command like:
% dacsacl -un -vfs "[acls]file:///users/bobo/my-rules" -vfs "[dacsacls]file:///dev/null"
If dacsacl is successful in the example above, a file named INDEX will be created or updated in the /users/bobo/my-rules directory, where the files containing the rules are also found. Warning messages can usually be ignored provided INDEX looks correct.
A CGI program can obtain the identity of the user invoking it from the REMOTE_USER environment variable and call dacscheck, as demonstrated in the following shell script, which uses the same rule as above:
#! /bin/sh if test "${REMOTE_USER}x" = "x" then idarg="" else idarg="-i ${REMOTE_USER}" fi echo "Context-Type: text/plain" echo "" # Note: append 2>&1 to the end of the next line to capture error messages dacscheck -q ${idarg} -rules /usr/local/myapp/rules /myapp st="$?" if test "${st}" = 0 then echo "Access is granted" else echo "Access is denied" fi exit 0
This example can easily be translated into any scripting language that allows an external program to be called and its exit status examined. Here is a similar example in PHP:
$user = $_SERVER["REMOTE_USER"]; putenv("REMOTE_USER=$user"); system("/usr/local/dacs/bin/dacscheck -q -fn DEMO -icgi -rules /usr/local/myapp/rules /myapp", $st); if ($st != 0) { // Access is denied, bail out exit($st); } // Access is granted, proceed
Note
Some may question the point of having a program call dacscheck to test if the user invoking it is allowed to merely run the program. At first glance it might appear that one could achieve the same result by simply setting file permissions such that only bob and alice can run the program. If that could be done, the coarse-grained testing done by dacscheck in the examples would be unnecessary. It turns out that there is more to it than that.
Setting file permissions to achieve this on a traditional Unix-type system requires creating a new group in /etc/group, something that generally can only be done by a system administrator. Ordinary users must therefore either bother the system administrator each time such a group must be created or modified, or find some other way to achieve the same result (e.g., by encryption, using a special setuid or setgid command that provides password-protected access, or some other clumsy and possibly insecure solution).
To address this limitation and others, many Unix-type operating systems now include file systems that extend the traditional Unix file permissions with an ACL-based mechanism (e.g., providing the getfacl(1)[10] and setfacl(1)[11] commands, and the acl(3)[12] ACL security API).
dacscheck provides similar functionality but for arbitrary names, not only for objects in the file system, and with respect to arbitrary identities, not only for those known to the operating system. For example, a CGI script can call dacscheck to test access on behalf of a user known to the web server (e.g., via an account created using htpasswd(1)[13]) but not having an account on the underlying system. Therefore, besides being portable across platforms and available on systems without ACL-type file permissions, dacscheck is a much more general solution than what most operating systems provide. In contrast to a system-provided ACL-based mechanism, however, dacscheck is not invoked transparently (i.e., it is not called automatically by the operating system when a resource such as a file is accessed). Also, with respect to testing whether a user is allowed to run a program, that program will typically perform the test itself and must therefore begin execution.
For additional information:
Because the authorization checking performed by dacscheck is completely separate from that performed by the operating system for system calls, a Unix identity such as root has no special rights or capabilities as far as dacscheck is concerned unless rules have been written to grant them. The same applies to the application of Unix groups.
The next example demonstrates how some typical Perl code can be improved by dacscheck. The code fragment:
if ($logged_in_as_root || $logged_in_as_current_admin) { # Do something privileged... }
which depends on the two variables being properly initialized depending on the value of $username, can be replaced by this:
# Determine if $username has admin privileges $output = `dacscheck -q -i $username -app myapp /myapp/admin`; $is_admin = ($? >> 8) == 0; if ($is_admin) { # Do something privileged... } # Later... if ($is_admin) { # Do something else privileged... }
The new authorization test depends on the identity that is running the program ($username) and the separate ruleset that determines whether that identity should be granted access to /myapp/admin, which is simply a label for a rule that might look like this:
<acl_rule status="enabled"> <services> <service url_pattern="/myapp/admin"/> </services> <rule order="allow,deny"> <allow> user("%:admin") </allow> </rule> </acl_rule>
This rule grants access if and only if $username is a member of the DACS group named admin or is associated with that DACS role. Membership in that group can be changed dynamically, and can even be reduced to zero.
The important observation is that the conditions that determine whether the user running this Perl code has administrative privileges are defined outside of the program and can be changed without modifying the code and often without even modifying access control rules.
A few concepts that are used in this document are described elsewhere. Variables, variable namespaces, and expressions that are used in access control rules are discussed in dacs.exprs(5)[22]. Naming in DACS is discussed in dacs(1)[23], and DACS groups and roles are covered in dacs.groups(5)[24].
Security
Clearly dacscheck, its caller, and the resources in question must be "isolated" from the user on whose behalf dacscheck is being run, otherwise the user could access the resources directly or subvert access control tests. Therefore, dacscheck and its caller must either be more privileged than the user on whose behalf it is being run or both programs must run in a secure context. This generally means that both dacscheck and its caller should be run in isolation from users (as on a remote server) or as an effective user ID different from the user's.
Advantages¶
Programs that perform authorization tests typically contain code like:Complicated applications can be littered with these kinds of tests, making them prone to bugs and security problems. Changes to security policies may involve modifications throughout an application or suite of applications. Also, password handling is often incorporated into such programs; because password management can require a significant implementation effort and is difficult to do securely, it seems wise to try to leverage existing implementations.
Compared to custom-coded solutions, dacscheck has many advantages:
Data-driven policies
Programming Efficiency
Portability
Increased Sharing
Flexibility
Increased Security
While the performance of dacscheck ought not to be a factor for many applications, the C/C++ API can be used where it is an issue. This API can be used to incorporate dacscheck functionality into compiled programs and extensible languages, such as Perl, Python, Tcl/Tk, and PHP.
Identities¶
The identity for which access is to be tested is given to the program or obtained by the program from its execution environment. This identity is converted into DACS's internal representation.More than one identity can be specified; the check is made on behalf of the union of all the identities. If the identities bob and alice are specified, for instance, a rule that is satisfied by either identity may grant access.
If no identity is given, the check is made on behalf of an unauthenticated user.
An identity can be:
Notes
Regardless of how it is specified, each identity must satisfy the syntactic requirements of a DACS user identity after this conversion and expansion (see dacs(1)[26]). If a login name is specified as an identity, for example, it must be valid as a component of a DACS user identity; therefore, it cannot contain any invalid characters.
Here are some examples of identities that may follow the -i flag:
bob :bob DSS:bob {u = bob} {u="bob"} {u="alice",g="admin"} {u="DSS:bob",g="guest"} {u="bob",a="a", g="guest"}
Note
This string may need to be quoted appropriately on the command line because the brace characters are significant to some shells; e.g.,
-i '{u="bob"}'
Apache and other web servers set the environment variable REMOTE_USER to the authenticated identity that invoked a web service. Provided its syntax is suitable, this identity can be passed to dacscheck. For DACS-wrapped web services, DACS identities are available in this variable.
By default, the federation, jurisdiction, and hostnames associated with the rules are derived from the system's hostname as returned by gethostname(3)[28]. If that name is unsuitable because it is not a FQDN (i.e., it is not a fully-qualified domain name because it does not contain a period), each of the alias names is examined (using gethostbyname(3)[29]) until a FQDN is found. The jurisdiction name comes from the left-most component of the selected FQDN and the federation domain and name come from the remaining components. If no FQDN is found, the system's hostname will be selected as the jurisdiction name and defaults will be used as the federation domain and name (EXAMPLE.COM and EXAMPLE-COM, respectively).
If the system's hostname is found to be (or explicitly given as) demo.example.com, for instance, the following variables will be set as indicated during rule evaluation:
Often, rules and identities can be expressed such that the names chosen for the federation and jurisdiction are unimportant. When this is not the case, however, and the defaults chosen by dacscheck are incorrect, they can be set on the command line. In some circumstances it might be appropriate for the jurisdiction name to be the name of the application, for example.
Regardless of their origins, federation and jurisdiction names must always be syntactically valid (see dacs(1)[26]).
Objects¶
While an object will often be an actual thing, such as a file, menu, or variable, it can also be an abstraction, such as an operation. dacscheck works with names - in the form of URIs - rather than objects per se. It does not associate any particular meaning with names, it merely uses them to locate an applicable access control rule. Therefore, provided the rule writer and applications that consult the rules agree on the naming scheme, the names that are chosen are largely irrelevant.An application assigns names to every object or class of objects that need to be referenced by access control rules. At its simplest, only one name is required (the name of the application, for example). In more complex situations, a wide variety of objects need to be named. The choice of names and the details of the naming hierarchy are up to the particular application, much like the organization of a software package's run-time file and directory organization depends on the particular package.
The object argument is the name that is matched against the services specified in access control rules. It can be either a URI or an absolute pathname (one that begins with a slash character), and either can have an optional query string component attached. An absolute pathname path is mapped internally to a URI as file://path; e.g., /myapp is interpreted as file:///myapp (see RFC 1738[30]).
The various components of the URI that names the object are available as DACS variables and environment variables (see below). If a query string is given, it is parsed and the individual arguments are made available to rules through the Args namespace, just as for DACS-wrapped web services.
Note
Only the path component of the URI is considered when DACS matches an object's name against the url_pattern of an access control rule. At present, the object name is not automatically canonicalized or resolved (see RFC 3986[31]), as is usually done by a web server, so relative path components such as "." and ".." should be avoided.
Rule Evaluation Context¶
Rules are evaluated within an execution context that may affect expression evaluation implicitly or may be examined explicitly through variables.Since dacscheck does not consult the DACS configuration files, the Conf namespace is instantiated with few variables. At present, only the VFS directives are available in it.
The Args namespace is instantiated if an object argument has a query string component.
The DACS namespace is instantiated with a few standard variables (such as ${DACS::JURISDICTION}) but can also be instantiated in various ways from the command line and from files.
The Env namespace is instantiated from the environment. Syntactically invalid variable names are silently ignored.
Many variables normally set by a web server are instantiated by dacscheck based on the object name. These variables are available in the Env and DACS namespaces. For example, if the object name is https://example.com:8443/myapp/edit-menu?entry=item1, the following variables will be set as indicated:
${Env::HTTPS}=on ${Env::SERVER_NAME}=example.com ${Env::SERVER_ADDR}=142.179.101.118 ${Env::HTTP_HOST}=example.com:8443 ${Env::SERVER_PORT}=8443 ${Env::REQUEST_URI}=/myapp/edit-menu ${Env::DOCUMENT_ROOT}=/ ${Env::REQUEST_METHOD}=GET ${Env::SERVER_SOFTWARE}=dacscheck-1.4.8b ${Env::QUERY_STRING}=entry=item1 ${Env::ARG_COUNT}=1 ${Env::CURRENT_URI}=/myapp/edit-menu?entry=item1 ${Env::CURRENT_URI_NO_QUERY}=/myapp/edit-menu
Variables of the same name will also be set in the DACS namespace and exported as environment variables. The value of ${Args::entry} will be item1. The request method defaults to GET. The variable ${Env::REMOTE_USER} (and therefore ${DACS::REMOTE_USER} and the environment variable REMOTE_USER) will be set based on the first identity specified on the command line; if no identity has been specified, this variable will be undefined.
An Example Application¶
To illustrate how the pieces fit together, let's consider a hypothetical (yet realistic) calendar application named cal that is written in Perl and invoked as a CGI program. We'll allow a user that has been authenticated by the web server to read, create, or update only her own calendars, unless the owner of a calendar gives her permission to perform a read or update operation on the calendar. Each owner can specify which users have access to her own calendar and the type(s) of access allowed.This authorization policy can be specified fairly easily. One approach is to use:
The program's administrator might collect all of the run-time files for the application in the directory /usr/local/cal and its subdirectories, and organize it as follows:
/usr/local/cal/rules/{acl-rule.0,acl-rule.1,...}
/usr/local/cal/users/username
/usr/local/cal/users/username/cal-1/data/*
/usr/local/cal/users/username/rules/{acl-cal1.0,acl-cal2.0,...}
/usr/local/cal/users/username/groups/*
Given these naming conventions:
Users' access control rules could themselves be under access control. A command line, GUI, or web interface would give the administrator and users the ability to manage rules.
See the EXAMPLES[32] section for example rules.
This is by no means the only way to organize the calendars, and a delegation-based approach isn't required. The administrator might instead put all of the rules under a common directory, like /usr/local/cal/rules/acl-username.0/{acl-cal1.0,acl-cal2.0,...}, or put them closer to the calendar they are controlling, like /usr/local/cal/users/username/cal-1/acl-cal1.0.
Instead of testing whether an operation is permitted, rules can be written to return a constraint string that tells the caller what kind (or kinds) of access are permitted. The program's output line will include the constraint string within quotes.
Comparing dacscheck with dacs_acs¶
dacs_acs(8)[8] is the DACS component that is called by Apache (by the DACS mod_auth_dacs[25] module, actually) to perform access control processing on web service requests. Its operation is normally invisible to web services; dacs_acs does all of its work before a web service is even executed or a web page is returned.dacscheck performs a function similar to the -check_only mode of operation of dacs_acs in that it simply returns an access control decision. There are important differences between the two programs, however.
dacscheck:
While dacscheck uses ordinary DACS access control rules (dacs.acls(5)[7]), unlike most DACS commands it does not consult any DACS configuration files. The evaluation environment for access control rules is similar to that of web service testing, but it is not identical since there need not be a web server in the picture. Other than the attributes related to constraints, attributes such as pass_credentials have no meaning to dacscheck.
Use and configuration of DACS by dacscheck is greatly simplified because no real federation or jurisdictions are defined; a completely self-contained environment is created so that a single program or set of related programs can perform both course-grained and fine-grained access control tests. No federation or jurisdiction cryptographic keys are used, and no real DACS credentials are created. Federation and jurisdiction names are instantiated, but those who write rules will often not need to be aware of them.
OPTIONS¶
The arguments are processed as they are examined (left-to-right) and their ordering can be significant; for example, values established by the -fh flag may affect options that follow it, such as those that use string interpolation. Exactly one object argument is required.-admin
-app appname
-context file
FOO=one BAZ=two
then within access control rules ${DACS::FOO} will have the value "one" and ${DACS::BAZ} will have the value "two". This flag may be repeated, although the standard input can be read only once.
-Dname=value
-dump
-F field_sep
Note
Note that only the first occurrence of the character (from left to right) is treated as the separator character.
-fd domain
-fh hostname
-fj jurname
-fn fedname
-groups group_vfs
-groups "[groups]dacs-fs:/local/groups" -groups /home/bob/mygroups
By default, a reference to the group %FOO:people will be mapped to a file named people.grp within the directory FOO relative to the DACS group directory.
-h
-i ident
-icgi
-icgig
-il ident
-ilg ident
-ieuid
-ieuidg
-iuid
-iuidg
-lg
-ll log_level
-name_compare method
-q
-redirect
-roles roles_vfs
bobo:users auggie:admin,users harley:guest
then the command line:
% dacscheck -roles /usr/local/myapp/roles -i auggie /myapp/admin
will test access for the identity {u="auggie",g="admin,users"}.
-rules rule_vfs
-rules "[acls1]dacs-fs:/local/acls" -rules /usr/local/myrules
This flag may be repeated; rulesets will examined in the order in which they are specified on the command line.
-v
-var name=value
--version
-vfs vfs_uri
--
EXAMPLES¶
To illustrate how dacscheck might be used with real applications, here are some examples. The first few continue with the hypothetical calendar application described earlier.<acl_rule status="enabled"> <services> <delegate url_pattern="/users/alice/*" rule_uri="/usr/local/cal/users/alice/rules/> <delegate url_pattern="/users/bob/*" rule_uri="/usr/local/cal/users/bob/rules/> <service url_pattern="/usr/local/cal/bin/*"/> </services> <rule order="allow,deny"> <allow> user("auth") </allow> </rule> </acl_rule>
This rule redirects requests for a particular user's calendar to that user's access control rules. It also says that access to the application's binaries is restricted to authenticated users. The application might issue a command such as:
% dacscheck -i $REMOTE_USER -rules /usr/local/cal/rules object
which will return an exit status of 0 if REMOTE_USER is granted access to object; otherwise an exit status of 1 will be returned. A better choice is to use the command:
% dacscheck -icgi -rules /usr/local/cal/rules object
which will leave the user unauthenticated if REMOTE_USER is unset or invalid.
<acl_rule status="enabled"> <services> <service url_pattern="/users/alice/cal-1/*"/> </services> <rule order="allow,deny"> <precondition> <predicate> user(":alice") </predicate> </precondition> <allow> return(1) </allow> </rule> <rule order="allow,deny"> <precondition> <predicate> ${Args::OP} eq "read" </predicate> </precondition> <allow> user(":bob") </allow> </rule> </acl_rule>
This rule says that alice is allowed full access to the calendar (there is no restriction on the operation), but bob only has read access. dacscheck would be called with /users/alice/cal-1?OP=create, /users/alice/cal-1?OP=update, or /users/alice/cal-1?OP=read to test for authorization to perform a create, update, or read operation on the calendar, respectively.
<rule order="allow,deny"> <precondition> <predicate> ${Args::OP} eq "read" or ${Args::OP} eq "update"</predicate> </precondition> <allow> user("%:alice-family") </allow> </rule>
This rule says that any member of the group alice-family is allowed read and update access to this calendar. The command:
% dacscheck -i julia /users/alice/cal-1?OP=update
would report that access is granted.
<acl_rule status="enabled"> <services> <service url_pattern="/users/alice/groups/*"/> </services> <rule order="allow,deny"> <precondition> <predicate> user(":alice") </predicate> </precondition> <allow> return(1) </allow> </rule> </acl_rule>
This rule allows only alice to manage the membership of this group, but she is free modify the rule to allow others to manage her groups.
<acl_rule status="enabled"> <services> <service url_pattern="/users/alice/groups/*"/> </services> <rule order="allow,deny"> <precondition> <predicate> user(":alice") </predicate> </precondition> <allow> return(1) </allow> </rule> </acl_rule>
This rule allows only alice to manage the membership of this group, but she is free modify the rule to allow others to manage her groups.
my $exit_value = 0; system "/usr/local/dacs/bin/dacscheck", "-q", "-icgi", "-rules", "/usr/local/webstats/acls", "/webstats"; $exit_value = $? >> 8; # print "dacscheck returned $exit_value for user \"$remote_user\"\n"; if ($exit_value != 0) { # dacscheck denies access; print message and exit exit 1; } # dacscheck grants access, so continue
Tip
The DACS distribution includes a Perl module (/usr/local/dacs/lib/perl/DACScheck.pm) to make dacscheck a little easier to use. The example above would be written as:
use DACScheck.pm; dacscheck_rules("/usr/local/webstats/acls"); my $result = dacscheck_cgi("/webstats"); if ($result != 1) { # dacscheck denies access; print message and exit exit 1; } # dacscheck grants access, so continue
DIAGNOSTICS¶
The program exits 0 if access is granted and 1 if access is denied. Any other exit status indicates an error occurred.BUGS¶
A light-weight method of defining DACS groups is needed. Once the internal are stable, this program's functionality will be made available through a C/C++ API, which will permit direct, efficient use by other applications and extensible languages (through perlxs(1), for example).The DACS_ACS argument[38] is not recognized by dacscheck.
Identities are not considered when roles are looked up; only the username is matched.
Unlike dacs_acs(8)[8], there is no support for automatically setting variables by parsing a message body (a MIME document).
It might be possible to create a layer between an application and the underlying system so that dacscheck can be called transparently, or nearly so.
SEE ALSO¶
See dacs(1)[23], dacsacl(1)[9], dacs.acls(5)[7], dacs.conf(5)[33], dacs.exprs(5)[22], dacs.groups(5)[24], dacs.java(7)[39].Rule-based access control[40]
DACScheck.pm
AUTHOR¶
Distributed Systems Software (www.dss.ca[41])COPYING¶
Copyright © 2003-2018 Distributed Systems Software. See the LICENSE[42] file that accompanies the distribution for licensing information.NOTES¶
- 1.
- Perl
- 2.
- PHP
- 3.
- Python
- 4.
- Ruby
- 5.
- Tcl/Tk
- 6.
- geteuid(2)
- 7.
- dacs.acls(5)
- 8.
- dacs_acs(8)
- 9.
- dacsacl(1)
- 10.
- getfacl(1)
- 11.
- setfacl(1)
- 12.
- acl(3)
- 13.
- htpasswd(1)
- 14.
- Using FreeBSD's ACLs
- 15.
- ONLamp.com
- 16.
- POSIX ACLs in Linux
- 17.
- linux.com
- 18.
- Solaris acl(2) and facl(2)
- 19.
- Sun Microsystems
- 20.
- Using Solaris ACLs
- 21.
- Dept. of Computer Science, Duke University
- 22.
- dacs.exprs(5)
- 23.
- dacs(1)
- 24.
- dacs.groups(5)
- 25.
- mod_auth_dacs
- 26.
- dacs(1)
- 27.
- concise syntax
- 28.
- gethostname(3)
- 29.
- gethostbyname(3)
- 30.
- RFC 1738
- 31.
- RFC 3986
- 32.
- EXAMPLES
- 33.
- dacs.conf(5)
- 34.
- dacs.conf(5)
- 35.
- dacs.conf(5)
- 36.
- NAME_COMPARE
- 37.
- redirect()
- 38.
- DACS_ACS argument
- 39.
- dacs.java(7)
- 40.
- Rule-based access control
- 41.
- www.dss.ca
- 42.
- LICENSE
02/19/2019 | DACS 1.4.40 |