I think your best bet is to have a config partial which contains all the sensitive data, and you have git ignore that file. If you’re trying to use github actions, you can add a build step which creates the config file programmatically
Wait, so I would put this in a partial and then include it either on default.hbs or the specific page I would need it? And then .gitignore on the partial?
Yep, exactly! It’s very similar to how dotenv works, but since Ghost doesn’t support executing arbitrary code, you put that data in a config partial instead
On the same page you can see two search bars (one for the whole website, one just to search through the books. Each of these uses a different SearchInGhost API key.
I use GitHub to work on my theme, to let me revert back to any point and to collaborate with others and I don’t want the confidential API keys to be exposed there.
Before uploading my theme to github, I used to go in and manually delete the API keys from the Javascript files and then add them back in (because I’d need them for testing and for production).
By putting them in a partial file and adding that file to the .gitignore, I’ve neatly solved this problem!
Oh! I see now (just viewed the source of my website)
Yeah, you’re right they are already exposed on the site.
There might be little benefit to what I’ve done indeed
To be honest I don’t feel like I know what I’m doing and I’m just making it up as I go. When exposing a key in the past, I get emails from various services yelling at me, so I assumed it was serious.
Generally speaking, there are two types of API keys:
First off, you have your traditional secret API keys that have write access to your account or to the API resources, so it can be used to do damage (e.g. change data, delete stuff, or worse). This is the default for most APIs. Never ever use these in client-side code. That’s probably why those emails were yelling at you.
An example of a secret API is the Ghost Admin API. you can use it to edit content, delete posts, and basically destroy the entire site. So don’t publish your Admin API key anywhere, ever.
Then there are read-only API keys that are meant to be used in client-side code. They can only read data from the API, not write to it or change anything. For example the Ghost Content API. These are fine to use in client-side Javascript since people can’t abuse them. Often it is noted explicitly in the documentation if you can use a key in your client-side code.
I haven’t used the Google Books API, but I’ve worked with other Google APIs and most of them are very dynamic and configurable. So if you have set up a read-only API key, it should be fine to just leave that key in your repository if you don’t want to bother with it too much.
I believe that it’s a read-only as I only use it for reading and edit the book list manually on Google Books. Same with the SearchInGhost Ghost Content API keys, it just looks at content to use for searching.
I would suggest migrate your repository to Gitlab rather than Github. Why? Because Gitlab offer you free PRIVATE repositories (in github you must pay for private repos), thus you can versionate whatever you want without this issue of privacy.