The Gatekeeper, or a project gating system
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 KiB

Tenant-scoped admin web API!/story/2001771

The aim of this spec is to extend the existing web API of Zuul to privileged actions, and to scope these actions to tenants, projects and privileged users.

Problem Description

Zuul 3 introduced tenant isolation, and most privileged actions, being scoped to a specific tenant, reflect that change. However the only way to trigger these actions is through the Zuul CLI, which assumes either access to the environment of a Zuul component or to Zuul's configuration itself. This is a problem as being allowed to perform privileged actions on a tenant or for a specific project should not entail full access to Zuul's admin capabilities.

Proposed Change

Zuul will expose privileged actions through its web API. In order to do so, Zuul needs to support user authentication. A JWT (JSON Web Token) will be used to carry user information; from now on it will be called the Authentication Token for the rest of this specification.

Zuul needs also to support authorization and access control. Zuul's configuration will be modified to include access control rules.

A Zuul operator will also be able to generate an Authentication Token manually for a user, and communicate the Authentication Token to said user. This Authentication Token can optionally include authorization claims that override Zuul's authorization configuration, so that an operator can provide privileges temporarily to a user.

By querying Zuul's web API with the Authentication Token set in an "Authorization" header, the user can perform administration tasks.

Zuul will need to provide the following minimal new features:

  • JWT validation
  • Access control configuration
  • administration web API

The manual generation of Authentication Tokens can also be used for testing purposes or non-production environments.

JWT Validation

Expected Format

Note that JWTs can be arbitrarily extended with custom claims, giving flexibility in its contents. It also allows to extend the format as needed for future features.

In its minimal form, the Authentication Token's contents will have the following format:

  • iss is the issuer of the Authorization Token. This can be logged for auditing purposes, and it can be used to filter Identity Providers.
  • aud, as the intended audience, is the client id for the Zuul deployment in the issuer.
  • exp is the Authorization Token's expiry timestamp.
  • iat is the Authorization Token's date of issuance timestamp.
  • sub is the default, unique identifier of the user.

These are standard JWT claims and ensure that Zuul can consume JWTs issued by external authentication systems as Authentication Tokens, assuming the claims are set correctly.

Authentication Tokens lacking any of these claims will be rejected.

Authentication Tokens with an iss claim not matching the white list of accepted issuers in Zuul's configuration will be rejected.

Authentication Tokens addressing a different audience than the expected one for the specific issuer will be rejected.

Unsigned or incorrectly signed Authentication Tokens will be rejected.

Authentication Tokens with an expired timestamp will be rejected.

Extra Authentication Claims

Some JWT Providers can issue extra claims about a user, like preferred_username or email. Zuul will allow an operator to set such an extra claim as the default, unique user identifier in place of sub if it is more convenient.

If the chosen claim is missing from the Authentication Token, it will be rejected.

Authorization Claims

If the Authentication Token is issued manually by a Zuul Operator, it can include extra claims extending Zuul's authorization rules for the Authentication Token's bearer:

  • zuul is a claim reserved for zuul-specific information about the user. It is a dictionary, the only currently supported key is admin.
  • zuul.admin is a list of tenants on which the user is allowed privileged actions.

In the previous example, user alice can perform privileged actions on every project of tenantA and tenantB. This is on top of alice's default authorizations.

These are intended to be whitelists: if a tenant is unlisted the user is assumed not to be allowed to perform a privileged action (unless the authorization rules in effect for this deployment of Zuul allow it.)

Note that iss is set to zuul_operator. This can be used to reject Authentication Tokens with a zuul claim if they come from other issuers.

Access Control Configuration

The Zuul main.yaml configuration file will accept new admin-rule objects describing access rules for privileged actions.

Authorization rules define conditions on the claims in an Authentication Token; if these conditions are met the action is authorized.

In order to allow the parsing of claims with complex structures like dictionaries, an XPath-like format will be supported.

Here is an example of how rules can be defined:

  • name is how the authorization rule will be refered as in Zuul's tenants configuration.
  • conditions is the list of conditions that define a rule. An Authentication Token must match at least one of the conditions for the rule to apply. A condition is a dictionary where keys are claims. All the associated values must match the claims in the user's Authentication Token.

Zuul's authorization engine will adapt matching tests depending on the nature of the claim in the Authentication Token, eg:

  • if the claim is a JSON list, check that the condition value is in the claim
  • if the claim is a string, check that the condition value is equal to the claim's value

The special zuul_uid claim refers to the uid_claim setting in an authenticator's configuration, as will be explained below. By default it refers to the sub claim of an Authentication Token.

This configuration file is completely optional, if the zuul.admin claim is set in the Authentication Token to define tenants on which privileged actions are allowed.

Under the above example, the following Authentication Token would match rules affiliate_or_admin and alice_or_bob:

And this Authentication Token would only match rule affiliate_or_admin:

Privileged actions are tenant-scoped. Therefore the access control will be set in tenants definitions, e.g:

An action on the tenantA tenant will be allowed if an_authz_rule OR another_authz_rule is matched.

An action on the tenantB tenant will be authorized if yet_another_authz_rule is matched.

Administration Web API

Unless specified, all the following endpoints require the presence of the Authorization header in the HTTP query.

Unless specified, all calls to the endpoints return with HTTP status code 201 if successful, 401 if unauthenticated, 403 if the user is not allowed to perform the action, and 400 with a JSON error description otherwise. In case of a 401 code, an additional WWW-Authenticate header is emitted, for example:

WWW-Authenticate: Bearer realm=""
                          error_description="Token expired"

Zuul's web API will be extended to provide the following endpoints:

POST /api/tenant/{tenant}/project/{project}/enqueue

This call allows a user to re-enqueue a buildset, like the enqueue or enqueue-ref subcommands of Zuul's CLI.

To trigger the re-enqueue of a change, the following JSON body must be sent in the query:

To trigger the re-enqueue of a ref, the following JSON body must be sent in the query:

POST /api/tenant/{tenant}/project/{project}/dequeue

This call allows a user to dequeue a buildset, like the dequeue subcommand of Zuul's CLI.

To dequeue a change, the following JSON body must be sent in the query:

To dequeue a ref, the following JSON body must be sent in the query:

POST /api/tenant/{tenant}/project/{project}/autohold

This call allows a user to automatically put a node set on hold in case of a build failure on the chosen job, like the autohold subcommand of Zuul's CLI.

Any of the following JSON bodies must be sent in the query:


GET /api/user/authorizations

This call returns the list of tenant the authenticated user can perform privileged actions on.

This endpoint can be consumed by web clients in order to know which actions to display according to the user's authorizations, either from Zuul's configuration or from the valid Authentication Token's zuul.admin claim if present.

The return value is similar in form to the zuul.admin claim:

The call needs authentication and returns with HTTP code 200, or 401 if no valid Authentication Token is passed in the request's headers. If no rule applies to the user, the return value is


Zuul will log an event when a user presents an Authentication Token with a zuul.admin claim, and if the authorization override is granted or denied:

At DEBUG level the log entry will also contain the zuul.admin claim.

Zuul will log an event when a user presents a valid Authentication Token to perform a privileged action:

At DEBUG level the log entry will also contain the JSON body passed to the query.

The events will be logged at zuul.web's level but a new handler focused on auditing could also be created.

Zuul Client CLI and Admin Web API

The CLI will be modified to call the REST API instead of using a Gearman server if the CLI's configuration file is lacking a [gearman] section but has a [web] section.

In that case the CLI will take the --auth-token argument on the autohold, enqueue, enqueue-ref and dequeue commands. The Authentication Token will be used to query the web API to execute these commands; allowing non-privileged users to use the CLI remotely.

JWT Generation by Zuul

Client CLI

A new command will be added to the Zuul Client CLI to allow an operator to generate an Authorization Token for a third party. It will return the contents of the Authorization header as it should be set when querying the admin web API.

The auth-config argument refers to the authenticator configuration to use (see configuration changes below). The configuration must mention the secret to use to sign the Token.

This way of generating Authorization Tokens is meant for testing purposes only and should not be used in production, where the use of an external Identity Provider is preferred.

Configuration Changes

JWT creation and validation require a secret and an algorithm. While several algorithms are supported by the pyJWT library, using RS256 offers asymmetrical encryption, which allows the public key to be used in untrusted contexts like javascript code living browser side. Therefore this should be the preferred algorithm for issuers. Zuul will also support HS256 as the most widely used algorithm.

Some identity providers use key sets (also known as JWKS), therefore the key to use when verifying the Authentication Token's signatures cannot be known in advance. Zuul must support the RS256 algorithm with JWKS as well.

Here is an example defining the three supported types of authenticators:


# symmetrical encryption
[auth "zuul_operator"]
# symmetrical encryption only needs a shared secret
# accept "zuul.actions" claim in Authentication Token
# what the "aud" claim must be in Authentication Token
# what the "iss" claim must be in Authentication Token
# the claim to use as the unique user identifier, defaults to "sub"
# Auth realm, used in 401 error messages
# (optional) Ensure a Token cannot be valid for longer than this amount of time, in seconds
max_validity_time = 1800000
# (optional) Account for skew between clocks, in seconds
skew = 3

# asymmetrical encryption
[auth "my_oidc_idp"]
# optional, needed only if Authentication Token must be generated manually as well
# if not explicitly set, allow_authz_override defaults to False
# what the "aud" claim must be in Authentication Token
# what the "iss" claim must be in Authentication Token
# Auth realm, used in 401 error messages
# (optional) Ensure a Token cannot be valid for longer than this amount of time, in seconds
max_validity_time = 1800000
# (optional) Account for skew between clocks, in seconds
skew = 3

# asymmetrical encryption using JWKS for validation
# The signing secret being known to the Identity Provider only, this
# authenticator cannot be used to manually issue Tokens with the CLI
[auth google_oauth_playground]
# URL of the JWKS; usually found in the .well-known config of the Identity Provider
# what the "aud" claim must be in Authentication Token
# what the "iss" claim must be in Authentication Token
# Auth realm, used in 401 error messages
# (optional) Account for skew between clocks, in seconds
skew = 3



Primary assignee:


Gerrit Topic

Use Gerrit topic "zuul_admin_web" for all patches related to this spec.

Work Items

Due to its complexity the spec should be implemented in smaller "chunks":


  • The changes in the configuration will need to be documented:
    • configuring authenticators in zuul.conf, supported algorithms and their specific configuration options
    • creating authorization rules
  • The additions to the web API need to be documented.
  • The additions to the Zuul Client CLI need to be documented.
  • The potential impacts of exposing administration tasks in terms of build results or resources management need to be clearly documented for operators (see below).


Anybody with a valid Authentication Token can perform administration tasks exposed through the Web API. Revoking JWT is not trivial, and not in the scope of this spec.

As a mitigation, Authentication Tokens should be generated with a short time to live, like 30 minutes or less. This is especially important if the Authentication Token overrides predefined authorizations with a zuul.admin claim. This could be the default value for generating Tokens with the CLI; this will depend on the configuration of other external issuers otherwise. If using the zuul.admin claims, the Authentication Token should also be generated with as little a scope as possible (one tenant only) to reduce the surface of attack should the Authentication Token be compromised.

Exposing administration tasks can impact build results (dequeue-ing buildsets), and pose potential resources problems with Nodepool if the autohold feature is abused, leading to a significant number of nodes remaining in "hold" state for extended periods of time. Such power should be handed over responsibly.

These security considerations concern operators and the way they handle this feature, and do not impact development. They however need to be clearly documented, as operators need to be aware of the potential side effects of delegating privileges to other users.


  • Unit testing of the new web endpoints will be needed.
  • Validation of the new configuration parameters will be needed.

Follow-up work

The following items fall outside of the scope of this spec but are logical features to implement once the tenant-scoped admin REST API gets finalized:

  • Web UI: log-in, log-out and token refresh support with an external Identity Provider
  • Web UI: dequeue button near a job's status on the status page, if the authenticated user has sufficient authorization
  • autohold button near a job's build result on the builds page, if the authenticated user has sufficient authorization
  • reenqueue button near a buildset on a buildsets page, if the authenticated user has sufficient authorization


  • This implementation will use an existing dependency to pyJWT in Zuul.
  • A new dependency to jsonpath-rw will be added to support XPath-like parsing of complex claims.