#community-help

Understanding Alias Usage in API Collections and Environment Security

TLDR gab sought clarity on when collection aliases would be used, if they are public and how they handle different environments. Kishore Nallan explained their purpose and suggested using distinct API keys for each environment for privacy and customization. They also directed gab on how to generate these keys per collection.

Powered by Struct AI
14
28mo
Solved
Join the chat
Jul 30, 2021 (28 months ago)
gab
Photo of md5-8be2a24edf7a95c9c74abce4b1130c3e
gab
12:18 PM
Hello,
In which cases an alias of a collection will be used ? It is something used only when we use search queries or it is also used for any other api?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
12:20 PM
All APIs will respect the alias. If it does not, then that will be a bug.
gab
Photo of md5-8be2a24edf7a95c9c74abce4b1130c3e
gab
12:38 PM
Ok thanks!
12:43
gab
12:43 PM
Is it intended that the aliased collection_name is something public?
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
12:47 PM
The intent behind aliases is so that you can create a new collection behind the scenes and swap over to it without updating your code. For e.g. lets say you want to rebuild your search index daily. Your code can just refer to an alias, say books and then everyday you create a new collection, say books_30_JUL_2021, index it and then just update the books alias to point to this new collection.
12:47
Kishore Nallan
12:47 PM
If something goes wrong, easy to revert also.
gab
Photo of md5-8be2a24edf7a95c9c74abce4b1130c3e
gab
12:56 PM
Yep I see the alias behavior.
But I thought the effective collection name wouldn't have been exposed to the search api.
Let's say I have product alias to product-Whatever . And then I perform a search using only the search token. I wouldn't know about the existence of product-whatever
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
12:59 PM
The collections don't know about aliases. What benefit do you see in keeping the collection name private?
gab
Photo of md5-8be2a24edf7a95c9c74abce4b1130c3e
gab
01:12 PM
In my case I have a single cluster that contains indices for different environnements. My collection name is like so:
`${name}-${environnement}-${date}`

With the alias I can then point wherever I want.

My front application always ask for the alias.
My backend layer create collection & appropriate alias dependending on the environnement.

But the environnement is not something I would like to expose publicly. Nor the date.

For now I can just compose the collection name without "readable information"
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
01:14 PM
You can use different API key for each environment. The API keys allow you to define which collection can be accessed.
gab
Photo of md5-8be2a24edf7a95c9c74abce4b1130c3e
gab
01:24 PM
Yes, completely agree that should be the api key that controls the permission.

I started on typesense cloud with one cluster per environnement. So I had different api keys.
The issue was it cost me Runtime cpu on each cluster even if the environnement was not used at all.
So I have put everything on the same cluster so if at least one env is used, the cluster is not running for nothing.

🙂 would have prefered to completely have separated envorinnements
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
01:36 PM
I don't follow. How would having a single cluster prevent you from generating separate API keys for each collection?
gab
Photo of md5-8be2a24edf7a95c9c74abce4b1130c3e
gab
01:40 PM
ahhh my bad, didn't see there was an ability to give api key per collection. In fact I only had in mind the "generate api keys" from the administration interface. I'm on it reading this documentation section.
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
01:40 PM
👍