Skip to main content

Featured

Free Text-to-Speech for YouTube Videos: My Kokoro TTS Pipeline

Every tutorial and Short on my YouTube channel Omilabs is narrated by a synthetic voice. I don't record my own voiceover for these videos. The narration comes from a script that turns each line of text into audio, and that script runs on Kokoro, a small open-weight text-to-speech model. In this post I explain how I set it up, the problems I hit, and the checks I now run so the voice sounds clean and stays consistent across more than a hundred videos. Why I Picked an Open TTS Model When you make one video, a paid voice tool is easy. When you make a full series of long episodes plus many Shorts, and you rebuild the audio every time a script line changes, a few things start to matter more: Re-runs cost nothing. I edit scripts often. With a local model I can regenerate a whole episode as many times as I want. It runs anywhere. The model is small enough to run on a normal CPU, including a free GitHub Actions runner, which is where my videos are rendered now. The output is rep...

How I Keep YouTube API Tokens Safe in GitHub Actions

When I moved my YouTube channel Omilabs to a fully automated upload pipeline on GitHub Actions, the hardest part was not the upload code. It was a simpler question: where do the YouTube OAuth credentials live, and how do I make sure they never leak? A YouTube refresh token is effectively a long-lived key to the channel. If it ends up in a log, a commit or a chat message, anyone who sees it can upload, edit or delete videos.

This post explains the setup I use today: how the credentials are stored, how the workflow gets them at run time, what I do when a token has to be re-issued, and the mistakes I made along the way. It is written for anyone automating a YouTube channel (or any OAuth-based API) from CI on a small budget.

What Actually Needs Protecting

A YouTube Data API upload pipeline needs two pieces of sensitive data:

  • The OAuth client file – the client ID and client secret you download from Google Cloud Console. It identifies your app.
  • The user token – the access token and, more importantly, the refresh token issued after you approve the app for your channel. This is the part that grants access to the channel itself.

The access token expires within about an hour, so the refresh token is the real prize. Everything below is designed around one goal: the refresh token should exist in plain text only in memory on a short-lived runner, and in a locked-down file on a machine I control.

Why I Did Not Just Use GitHub Secrets for Everything

The standard advice is to put credentials in GitHub Actions secrets, and for small values that is the right answer. My situation had two complications:

  1. The token file is JSON with several fields. It can be stored as a secret, but the refresh logic rewrites it whenever the access token is renewed, and secrets are write-only from inside a workflow.
  2. Some of my tooling could not manage repository secrets directly. I wanted a setup where updating a token was a normal commit, not a manual trip into the repository settings every time.

So I used a hybrid: one short secret in GitHub, and the larger files encrypted inside the repository.

The Setup: One Key in Secrets, Encrypted Files in the Repo

Step 1: Generate a strong encryption key

I generate a long random key locally (for example with openssl rand -base64 48) and save it in exactly two places: a GitHub Actions secret on the private repository, and a file on my own machine with chmod 600 permissions. It never goes into a commit, a chat or a screenshot.

Step 2: Encrypt the credential files

Both the client file and the token file are encrypted with OpenSSL using AES-256-CBC with PBKDF2 key derivation and a high iteration count. The command looks like this (the key is read from an environment variable so it does not appear in shell history or process lists):

K="$(cat ~/.secrets/key.txt)" openssl enc -aes-256-cbc -pbkdf2 -iter 200000 -salt \
  -in token.json -out yt_token.enc -pass env:K

Only the .enc files are committed. The plain JSON files are listed in .gitignore so they cannot be committed by accident.

Step 3: Decrypt only on the runner

The first step of the upload workflow decrypts the files into the runner's temporary filesystem, using the secret passed in as an environment variable:

- name: Decrypt credentials
  env:
    K: ${{ secrets.YT_KEY }}
  run: |
    openssl enc -d -aes-256-cbc -pbkdf2 -iter 200000 \
      -in yt_token.enc -out "$RUNNER_TEMP/token.json" -pass env:K

GitHub masks secret values in logs, and the runner is destroyed after the job, so the plain token never persists anywhere outside my own machine.

The Rules I Follow in Code

Encryption only protects the files at rest. Most leaks happen through ordinary debugging, so I keep a few strict habits in the upload scripts:

  • Never print credential objects. No print(creds), no dumping the token JSON "just to check". Logs only say things like "token loaded" or "token refreshed".
  • Log API errors by reason, not by full response. For upload failures I log the error reason (for example uploadLimitExceeded) and the video ID, which is enough to debug.
  • No set -x in steps that touch secrets. Shell tracing can echo values that GitHub's masking might not catch if they are transformed.
  • Use the narrowest OAuth scope that works. For uploads I request only the YouTube scope the task needs, not every Google scope available.
  • Check which channel the token belongs to. Because one Google account can own more than one channel, my publisher asks the API which channel it is authenticated as and refuses to upload if it is not the expected one.

Avoiding the 7-Day Token Trap

This one cost me a few days. When a Google Cloud OAuth app is in Testing publishing status, refresh tokens for external users expire after 7 days. Everything works perfectly in the first week, then the scheduled uploads start failing with authorization errors.

The fix was to move the OAuth consent screen to In production status and then issue a fresh token. Tokens issued while the app was still in testing keep their short lifetime, so the re-issue after publishing matters. For a personal app with sensitive scopes, Google may show an "unverified app" warning during consent; since I am the only person approving it, that was acceptable for my use. Check Google's current documentation for your own case, because verification rules can change.

Re-Authorising Without Typing a Password Anywhere

When a token is revoked or expires, I never paste a Google password into a script or a remote session. I use the OAuth device flow instead:

  1. The script requests a device code and prints a short user code.
  2. I open google.com/device on my own phone or laptop, sign in normally and enter the code.
  3. The script receives the new token, which I immediately re-encrypt and commit.
  4. I trigger a test run of the workflow to confirm the new token works end to end.

The password stays between me and Google. The automation only ever sees a token it can lose without exposing my account login.

What I Would Do If the Key Leaked

It is worth writing the incident plan before you need it. Mine is short:

  1. Revoke the token from the Google account's third-party access page. This makes the leaked refresh token useless.
  2. Rotate the client secret in Google Cloud Console if the client file may also have been exposed.
  3. Generate a new encryption key, re-encrypt both files, and replace the GitHub secret.
  4. Review recent channel activity in YouTube Studio for uploads or edits I did not make.

Note that rotating the encryption key alone is not enough: anyone who already decrypted the old files still has a working token until it is revoked at Google's end.

Honest Limits of This Approach

This setup is good enough for a personal channel, but it is not perfect:

  • Anyone with write access to the repository can change the workflow to print decrypted values. Keep the repository private and the collaborator list short.
  • The encryption is only as strong as the key. A short or reused key undermines everything.
  • For teams or business accounts, a proper secrets manager or OIDC-based short-lived credentials is a better long-term choice.

Conclusion

Automating YouTube uploads on GitHub Actions is mostly a credentials problem wearing an automation costume. Keep one strong key in GitHub secrets, commit only encrypted files, decrypt on the runner, never log tokens, publish your OAuth app to production to avoid weekly expiry, and use the device flow for re-authorisation. With that in place, my channel uploads on schedule without my laptop being on, and without a single credential sitting in plain text in the repository.

Written by Omkar Vijay Ghate, Mumbai.

Comments

Adsterra Have a blog? Monetize it with Adsterra (referral link)