auth0-deploy-cli icon indicating copy to clipboard operation
auth0-deploy-cli copied to clipboard

TypeError when using keyword replacement with database enabled clients

Open snorfalorpagus opened this issue 1 year ago • 2 comments

Checklist

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

Description

I’m trying to implement keyword replacement 1 to allow me to manage our development and production tenants. It’s working as expected, but I’m getting an error when I try to use it for the enabled_clients attribute on a username/password database connection. The goal is to enable it for some applications in development, but not in production.

Originally posted in the community forum: https://community.auth0.com/t/typeerror-when-using-keyword-replacement-with-database-enabled-clients/139339/2

Expectation

If I enable debug output when running a0deploy export I see the following:

2024-07-19T16:10:14.369Z - debug: TypeError: (enabledClients || []).map is not a function or its return value is not iterable

Using the same technique for another attribute in the file (e.g. realms) works as expected.

Have I made some mistake in the syntax? Or is this a bug in the CLI?

Reproduction

My config looks like this:

  "AUTH0_KEYWORD_REPLACE_MAPPINGS": {
    "DATABASE_CONNECTIONS_USERNAME_PASSWORD_ENABLED_CLIENTS": [
      "AnApplication",
      "AnotherApplication"
    ],
  }

with a replacement like:

"enabled_clients": "@@DATABASE_CONNECTIONS_USERNAME_PASSWORD_ENABLED_CLIENTS@@"

Deploy CLI version

7.23.1

Node version

18.20.4

snorfalorpagus avatar Jul 22 '24 09:07 snorfalorpagus

I think I've identified the bug. It's specific to using keyword preservation for the enabled_clients attribute. mapClientID2NameSorted is being called with the unsubstituted value (i.e. `"@@...@@") as a string instead of a list of strings. I suppose this isn't a problem for other attributes as they don't have any processing like this.

@willvedd it looks like you added the keyword preservation feature. Do you have any thoughts on what a fix for this would look like? I'm able to help with code but don't have a full model in my head of how everything connects together yet.

snorfalorpagus avatar Aug 05 '24 11:08 snorfalorpagus

@snorfalorpagus Thanks for opening this ticket; especially appreciate your insight on the issue. It seems like keyword preservation running before the database dum operation creates the issue due to client_id and client name mismatch.
Feel free to submit a PR :pray:.

kushalshit27 avatar Sep 16 '24 08:09 kushalshit27

A few things we noticed when switching to version 8.0.0:

  1. On all other options where we are trying to use the placeholders for arrays, we need to enclose the value in double quotes: Eg. Within the brute-force-protection.json we need to use "allowlist": "@@bruteForceProtectionAllowlist@@". If we don’t enclose it in double quotes, then the placeholder is not preserved when exporting again. In the case of the enabled_clients the export will fail with an error if you use the double quotes.
  2. To avoid generating an error for enabled_clients, you need to use the array placeholder without double quotes. However, the placeholder is not preserved on export. NOTE: I’m using the "AUTH0_PRESERVE_KEYWORDS": true config option. Example: I use "enabled_clients": @@databaseEnabledClients@@ where the config file I pass in has an entry in the AUTH0_KEYWORD_REPLACE_MAPPINGS section. On export the placeholder is not preserved and instead the actual tenant value for the enabled_clients replaces the placeholder.

IReid71 avatar Nov 08 '24 13:11 IReid71

Hi all, With this fix you will be able to use: "enabled_clients": "@@DATABASE_CONNECTIONS_USERNAME_PASSWORD_ENABLED_CLIENTS@@"

Make sure to set "AUTH0_PRESERVE_KEYWORDS": true to preserve and add AUTH0_KEYWORD_REPLACE_MAPPINGS with key on config.json

Note: for json, we need to enclose the keyword in double quotes. for more link

kushalshit27 avatar Jun 25 '25 09:06 kushalshit27

We will be releasing this fix in upcoming releases.

kushalshit27 avatar Jun 27 '25 08:06 kushalshit27

The fix for this issue is now available in version 8.10.0. 🚀

Thank you for your patience! This issue has been resolved. Feel free to reopen it if you encounter any further problems.

kushalshit27 avatar Jul 01 '25 11:07 kushalshit27