Skip to content

9.12.0

Choose a tag to compare

@github-actions github-actions released this 18 Oct 14:36
· 452 commits to master since this release
337eadc

RESTHeart 9.12.0

This release changes how RESTHeart picks the ACL permission that applies to a request, and how restheart-accounts stores teams and puts them in tokens. Several changes alter existing behaviour. Read "Before you upgrade" first.

Before you upgrade

Check these points. Each one has a section below with the details.

  1. You use fileAclAuthorizer with more than one permission per role. The highest priority number now wins. Check which permission you want to apply and give it the higher number.
  2. Your users have more than one role. The matching permission with the highest priority now applies, whatever the order of the roles.
  3. Two of your permissions can match the same request with the same priority. Give them different priorities.
  4. You use restheart-accounts. Tokens no longer carry the team claim. In your ACL rules, replace @user.team._id with @team._id and @user.team.role with @team.role.
  5. You use restheart-accounts with its default membership provider. Run the one-off data migration once.

ACL permissions: which one applies

When a request matches more than one permission, RESTHeart applies one of them, together with its mongo options: filters, write modes, projections. Three changes make that choice follow the documented rule.

fileAclAuthorizer evaluates the highest priority first (#764)

The documentation says that higher priority numbers are evaluated first, and mongoAclAuthorizer works that way. fileAclAuthorizer evaluated the lowest number first. Both authorizers now follow the documentation.

A permission without priority is now evaluated last, in both authorizers. Before, it received the largest possible priority, so mongoAclAuthorizer evaluated it first.

If your acl.yml has more than one permission for the same role that can match the same request, the one that applies may change. Check those permissions and give the higher number to the one that must win.

Users with more than one role (#760)

Before, the role listed first on the account decided which permission applied. RESTHeart now compares the matching permissions of all the user's roles and applies the one with the highest priority.

For example, with these two permissions:

{ "_id": "editorsWriteAll", "roles": ["editor"], "predicate": "path-prefix('/articles') and method(PATCH)", "priority": 200, "mongo": { "allowWriteMode": true } }
{ "_id": "authorsWriteOwn", "roles": ["author"], "predicate": "path-prefix('/articles') and method(PATCH)", "priority": 100, "mongo": { "writeFilter": { "author": "@user._id" } } }

a user with both roles now always gets editorsWriteAll and can edit any article. Before, a user whose roles were listed as [author, editor] got authorsWriteOwn and could edit only their own articles.

Contributed by @axmc1 in #760.

Permissions with the same priority (#767)

When two matching permissions have the same priority, a fixed rule now decides:

  • fileAclAuthorizer applies the one that comes first in the configuration. Before, it applied the last one.
  • mongoAclAuthorizer applies the one with the greatest _id. Its query already did this within a role; it now does it across roles too.

The order of the user's roles no longer plays a part. Still, the best practice is to give different priorities to permissions that can match the same request.

restheart-accounts: the active team

The @team variable (#765)

restheart-accounts registers a new ACL variable, @team, named after accountsConfig.team-claim-name. It holds the caller's active team as { _id, role }, read from the membership provider at every request. Use @team._id and @team.role in predicates, readFilter and mergeRequest:

- roles: [user]
  predicate: path-prefix('/orders') and equals(@team.role, "owner")
  mongo:
    readFilter: {"team": "@team._id"}
    mergeRequest: {"team": "@team._id"}

The value comes from the membership provider, never from the token. A token issued before a switch of team reads as the new team, and a custom membership provider gives the same result on every login path.

Tokens no longer carry the team claim (#765, breaking)

The tokens that restheart-accounts issues no longer contain the team claim: activation, email verification, password reset, POST /auth/switch-team, POST /auth/teams and the OAuth callback. The POST /auth/switch-team response body still returns the team.

What to do:

  • In ACL rules, replace @user.team._id with @team._id and @user.team.role with @team.role. @user.team resolves to nothing once tokens carry no claim.
  • Clients that read the team from the JWT can read it from GET /auth/teams or from the POST /auth/switch-team response.
  • To keep the team in the token, add "@team" to jwtConfigProvider.account-properties-claims (next section). The claim then appears in every token, POST /token included.

ACL variables in account-properties-claims (#765)

An entry of jwtConfigProvider.account-properties-claims that starts with @ is an ACL variable. RESTHeart resolves it with the request that issues the token and puts the value in the token under the variable's name. Quote it, since @ is reserved in YAML:

jwtConfigProvider:
  account-properties-claims:
    - email
    - "@team"

A variable that resolves to nothing adds no claim. An entry that names no registered variable is reported in the startup log.

Memberships live on the team (#766, breaking)

The default membership provider now keeps who belongs to a team, and with which role, in one place: the team's members. The user document keeps only the active team, as team: { _id }. The teams array and team.role on the user document are no longer read or written.

Before, the same membership was written in three places with separate updates, and a failure in between left them in disagreement. Now adding a member, removing one or changing a role is a single update of the team document.

To migrate existing data:

  1. Set accountsConfig.migrate-memberships: true and restart once.
  2. Read the log. Every membership listed in a user's teams that the team itself does not confirm is reported as a warning. It is never added to the team.
  3. Set the option back to false.

The migration also removes teams and team.role from the user documents. Running it again finds nothing to do.

Custom membership providers are not affected.

Deleting a user document does not remove the user from the teams that list it. Remove the member first, with DELETE /auth/remove-member.

Other fixes in restheart-accounts (#765)

  • The accounts endpoints now use jwtConfigProvider.account-properties-claims when the deprecated accountsConfig.account-properties-claims is not set. Before, they added no configured claim at all.
  • POST /auth/switch-team, POST /auth/teams and the OAuth callback now select the configured claims from the user document. Before, a claim such as profile was missing from the tokens they issued.

restheart-stripe

The subscription owner and the payer of an order are now resolved through @team, so they keep working with tokens that carry no team claim (#766).

Bug fixes

  • ACL predicates with quoted BSON values (#761). Since 9.0.0, predicates such as bson-request-array-is-subset(key=roles, values={'"user"','"admin"'}) and bson-request-prop-equals(key=status, value='"draft"') did not work: the permission was discarded at startup, or never matched. They work again.

Thanks

Thanks to @axmc1 for #760. The pull request found that a user with more than one role could get a different permission depending on the order of the roles, and fixed it in both ACL authorizers. Its tests also showed that fileAclAuthorizer evaluated priorities in the opposite order, which led to #764.