Improved authz


The current (1.9) implementation of authz is lacking in two areas:

  1. Wildcard support and performance
  2. Better access control

Wildcard Support and Performance


A path consists of segments, separated by "/". Whildcards are valid segments and their interpretation depends on the context.

An access control list (ACL) contains a number of access control elements (ACE), each describing which users shall have what access rights. Users might be specified indirectly by using groups.

A path rule specifies what ACL applies to a given path.

Inheritance and Disambiguation

These are the rules as of today, with rule 7 added to support ambiguous path matches caused by pattern matching. Please note the difference between matching (does a path fully match a given pattern?) and applying to (governing the access rights).

  1. An ACL is relevant to a user if the user, one of their aliases or groups that they are a member of is mentioned by at least one ACE in that ACL.
  2. Only path rules with ACLs relevant to the given user may match a path.
  3. If a path rule matches a given repository path, its ACL applies to that path.
  4. If no path rule matches a given repository path, the parent path's ACL applies.
  5. If no ACL is given for the repository root, a default ACL denying everybody access to the root path, applies.
  6. If repository-specific path rules as well as global path rules match a given path, only the repository-specific ones will be considered.
  7. If multiple path rules match a given repository path, only the one specified last in the authz file shall apply.
  8. If multiple ACEs of a given ACL apply to a user, the union of all individually granted access rights is granted.


The idea is to use combine the following approaches:

General Workflow

Putting caching aside, the workflow involved three data models, building on top of each other.

Data models

These are persistent in the sense that we will cache and reuse them. They do not cover transient data models that various algorithms may use e.g. during authz parsing.

Unless indicated otherwise, all collections are ordered.

Only abstract types / the interface view is given here; the actual implementation may be different.

Filtered path rule tree
filtered-tree :=
    root      : filtered-node       // exists due to default path rule

filtered-node :=
    segment   : string              // empty for root
    access    : ref to access-type  // empty if no path ends here
    min-rights: none | r | rw       // user's minimum rights on any path in the sub-tree
    max-rights: none | r | rw       // user's maximum rights on any path in the sub-tree
    repeat    : boolean             // set on nodes for "**" segments

    sub-nodes : { map following segment => filtered-node }[0..*]
                                    // one node per following segment with no wildcards
                                    // empty if no such rules exist

    // the following will be aggregated into a sub-structure to
    // facilitate a quick "has it pattern sub-segments?" check
    any       : filtered-node       // empty if no path rule with "*" in following segment
    any-var   : filtered-node       // empty if no path rule with "**" in following segment
    prefixed  : { list of filtered-node }[0..*]
                                    // empty if no path rule like "bar*" in following segment
    suffixed  : { list of filtered-node }[0..*]
                                    // empty if no path rule like "*bar" in following segment
    complex   : { list of filtered-node }[0..*]
                                    // empty if no path rule with complex wildcard pattern
                                    // like "*for*bar" in following segment

access-type :=
    order-id  : integer             // increases with declaration order in the file
    rights    : none | r | rw
Lookup state
lookup-state :=
    access    : ref to access-type  // user's rights for this path
    min-rights: none | r | rw       // user's minimum rights on any path in the sub-tree
                                    // (aggregated over RIGHTS and all nodes in CURRENT)
    max-rights: none | r | rw       // user's maximum rights on any path in the sub-tree
                                    // (aggregated over RIGHTS and all nodes in CURRENT)
    current   : { ref to filtered-node }[0..*]
                                    // sub nodes of these may match the next segment



Wildcard sequences in paths shall be normalized internally. This is merely done to reduce matching costs later on and some of the matching code may rely on normalized pattern.

    // Variable length wildcards shall be the last in a sequence
    while path contains "/**/*/"
        replace occurrence with "/*/**/"

    // Consecutive variable length wildcards are redundant
    while path contains "/**/**/"
        replace occurrence with "/**/"


Since there is always an implicit path rule at the root for all users, lookup is always necessary.

    init(tree : ref to filtered-tree):
        return new lookup-state
            .rights = tree.root.rule
            .current = { tree.root }, if has_subnodes(tree.root)
                       { }, otherwise

Checking whether we need to continue in our path matching is trivial, just check whether there are any potential matches to sub-paths.

    done(state : ref to lookup-state):
        return is_empty(state.current)

One step in the lookup iteration, i.e. matching the next segment, is relatively simple as well. For simplicity, we ignore the min/max rights optimization here.

    latest(lhs : ref to access-type, rhs : ref to access-type):
        if is_empty(lhs)
            return rhs
        if is_empty(rhs) or lhs.order-id > rhs.order-id
            return lhs
        return rhs

    step(state : ref to lookup-state, segment : string):
        next = { }
        access = empty
        foreach node in state.current:
            if node.repeat:
                next += node
                access = latest(access, node.access)
            foreach sub-node in all-subnodes(node):  // simplified
                if matches(sub-node, segment):           // simplified
                    next += sub-node
                    access = latest(access, sub-node.access)

        if not is_empty(access)
            state.rights = access
        state.current = next

So, the full lookup without caching is as shown below. For efficiency, the implementation will check the accumulated global rights calculated by the parser before performing a tree lookup. There are probably many cases where the result of any lookup can be predicted from those rights, and therefore the lookup itself, and even creation of the filtered tree, could be skipped entirely.

    lookup(tree : ref to filtered-tree, path : string):
        state = init(tree)
        foreach segment in path
            if done(state)
            state = step(state, segment)
        return state.rights

Better Access Control

TODO after 1.10.

Implementation Notes

Changes from Current Behaviour

Rules Defined Only Once

The config-based parser would merge and override access entries in redefined rules. The new parser rejects authz files that define the same rule more than once.

New Rule Syntax for Wildcard Rules

Existing rules come in two flavours; repository-specific and global:


In these rules, /path is always matched literally. The new parser supports two new forms for rules with paths that contain wildcards:


Because a glob rule is not required to actually contain wildcards in the path, two sections with different names may represent the same rule; for example,


the above two rules are identical. The new parser detects (and rejects) such collisions.

Write-only Access is Not Allowed

The config-based authz parser will allow access entries that grant only write access; e.g.,

   * = w

The new parser flags such entries as invalid; our authz implementation does not support write-only access.

Only Group Definitions in the Global Groups File

The new parser allows only group definitions (i.e., only the [groups] section) in the global groups file. The config-based parser would allow other sections there, but they would be ignored.