Skip to content

Client grants differing only by subject_type overwrite each other in directory-format exports #1472

Description

@TheInfinity007

Checklist

  • I have looked into the README and have not found a suitable solution or answer.
  • I have looked into the documentation and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have upgraded to the latest version of this tool and the issue still persists.
  • I have searched the Auth0 Community forums and have not found a suitable solution or answer.
  • I agree to the terms within the Auth0 Code of Conduct.

Description

In --format=directory, client grant filenames are built from client name + API name only
(src/context/directory/handlers/clientGrants.ts). subject_type is not included.

A client holding both a client and a user grant on the same audience therefore maps both
grants to one file — the second write silently overwrites the first. No error or warning is
emitted; the dump only validates that the generated name is non-empty.

This contradicts the import side, where a grant's identity is (client_id, audience,
subject_type) per the identifiers list in src/tools/auth0/handlers/clientGrants.ts, which
also has dedicated DELETE + CREATE handling because subject_type is immutable.

Consequence: the lost grant is absent from the export and becomes a deletion candidate on the
next import (removed outright when AUTH0_ALLOW_DELETE is enabled).

Separately, the clientGrants handler never prunes stale files, unlike connections. A grant
deleted from the tenant keeps its file and is recreated on the next import.

Expectation

Every client grant on the tenant should produce its own file, and a round-trip
(export → import) should be lossless. Files for grants no longer on the tenant should not
persist and be re-imported.

Reproduction

  1. On a tenant, give one client two grants on the same audience — one with
    subject_type "client", one with subject_type "user".
  2. a0deploy export -c config.json -f directory -o ./out
  3. Inspect ./out/grants/ — only one file exists for that client/audience pair, containing
    whichever grant was written last. Total file count is one fewer than the number of
    grants on the tenant.

Deploy CLI version

8.43.0

Node version

24.18.0

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions