Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use same secret key to manage different functions #97

Open
elhe26 opened this issue Dec 3, 2024 · 9 comments
Open

Use same secret key to manage different functions #97

elhe26 opened this issue Dec 3, 2024 · 9 comments

Comments

@elhe26
Copy link

elhe26 commented Dec 3, 2024

Description

As the title implies, please allow using the same key for multiple functions. It's expensive to create the same key over and over again just to be used by 1 function.

Steps to reproduce

NA

Expected Behavior

One secret key for multiple functions.

Actual Behavior

The same key is created and used per function.

Metadata

Typesense Version: 0.27.1

OS: MacOS

@jasonbosco
Copy link
Member

Could you elaborate on this? I'm not sure I understand why you can't use the same API key for multiple instances of the extension?

@elhe26
Copy link
Author

elhe26 commented Dec 5, 2024

Of course @jasonbosco . When using the extension, you create a secret each time you define the function. If you have 5 collections, you need 5 secrets, one per collection, using the same Typesense API key. The configuration must have a way to use the previously created secret from the first function on others.

@jasonbosco
Copy link
Member

Ah I see what you mean now. I wonder if this is a Firebase UI limitation that doesn't let you pick an existing secret? You might want to try using the Firebase CLI to install the extension and then it might allow you to reference an existing secret by its resource ID? (I'm not too familiar with this though - might be a better question for Firebase support).

@elhe26
Copy link
Author

elhe26 commented Dec 5, 2024

Migrating to v2 allows you to use defineSecret by creating a secret key first (ie. "TYPESENSE_API_KEY" on secret manager) and then using that variable with that function (defineSecret). I don't remember being able to do that on v1.

@jasonbosco
Copy link
Member

May I know v2 of what package you're referring to?

@stevebrowndotco
Copy link

stevebrowndotco commented Dec 6, 2024

Im finding this to be a limitation when having multiple extensions for different tyepsense collections when adding the local config and deploying via the CLI. This is the error I get in the cli. Therefore I can confirm a limitation with GCP?

Error: firestore-typesense-search-omitted: Found 'projects/OMITTED/secrets/firestore-typesense-search-TYPESENSE_API_KEY/versions/latest' for secret param TYPESENSE_API_KEY. projects/OMITTED/secrets/firestore-typesense-search-TYPESENSE_API_KEY is managed by a different extension instance (true), so reusing it here can lead to unexpected behavior. Please choose a different name for this secret, and rerun this command.

@elhe26
Copy link
Author

elhe26 commented Dec 6, 2024

May I know v2 of what package you're referring to?

I'm referring to Cloud Functions V2.

Dependencies

...

  "dependencies": {
    ...
    "express": "^4.21.2",
    "firebase": "^11.0.2",
    "firebase-admin": "^13.0.1",
    "firebase-functions": "^6.1.1",
    "typesense": "^1.8.2"
  },
  ...

Firebase Cli

firebase-tools: 13.20.2.

@elhe26
Copy link
Author

elhe26 commented Dec 6, 2024

Interesting @stevebrowndotco . Could you please share the prompt you used to configure the ext? I see that this ext adds the following parameters when creating the secret key: Secret Manager Admin and Secret Manager Secret Accessor. I'm using other keys in different settings without any issues.

@stevebrowndotco
Copy link

@elhe26

  1. I am running firebase ext:install typesense/firestore-typesense-search
  2. It then creates a local .env file with the following entry:
TYPESENSE_API_KEY=projects/omitted/secrets/ext-firestore-typesense-search-TYPESENSE_API_KEY/versions/1
  1. HOWEVER, since I already use the above key , i get the following error:
Error: firestore-typesense-search: Found 'projects/omitted/secrets/ext-firestore-typesense-search-TYPESENSE_API_KEY/versions/1' for secret param TYPESENSE_API_KEY, but this instance was previously using a different secret projects/omitted/secrets/firestore-typesense-search-TYPESENSE_API_KEY.
Changing secrets is not supported. If you want to change the value of this secret, use a new version of projects/omitted/secrets/firestore-typesense-search-TYPESENSE_API_KEY.You can create a new version at https://console.cloud.google.com/security/secret-manager?project=omitted
  1. In my case, make sure the instance name is different to fix the above.

  2. I came to this issue only because I created the extension before google secrets was supported in this library. So for me, the solution was to manually go into the "secrets manager" in GCP, and create an entirely new secret, and modify this line in firestore-typesense-search.env file:

TYPESENSE_API_KEY=projects/omitted/secrets/ext-firestore-typesense-search-TYPESENSE_API_KEY/versions/1

To (for example)

TYPESENSE_API_KEY=projects/omitted/secrets/ext-firestore-typesense-search-ANOTHER-TYPESENSE_API_KEY/versions/1

Also trying multiple versions in the same key will not work either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants