Local Build vs CI/CD Pipeline for Jekyll Secret Management
0 reputation · 01 Jan 2025, 13:05 UTC
0 reputation · 01 Jan 2025, 13:05 UTC
Jekyll generates static HTML files, meaning it lacks a native runtime for authentication or credential management. When integrating external API keys or sensitive configuration data, the security boundary shifts to the build environment.
A local build process keeps sensitive credentials on the developer's machine, reducing the risk of third-party runner exposure. However, this introduces inconsistencies between development and production environments.
Conversely, utilizing a CI/CD pipeline allows for centralized secrets management and automated deployments, but introduces potential risks regarding secret leakage in build logs or dependency on external runner security.
Given that hardcoding values in _config.yml results in plain-text exposure in the final _site output, the choice of build architecture directly impacts the security posture of the static site.
For Jekyll, a CI/CD pipeline that uses protected, masked environment variables offers a more sustainable least‑privilege model for managing build‑time secrets.
jekyll build.Storing secrets in a CI system centralises access control, limits exposure to a single trusted runner, and provides audit‑able masking. A local build spreads the secret to every developer’s workstation and depends on each person to avoid accidental commits, which is harder to enforce at scale.
API_KEY) as a repository secret Settings → Secrets → Actions.jobs:
build:
runs-on: ubuntu-latest
env:
API_KEY: ${{ secrets.API_KEY }}
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.2'
- name: Install dependencies
run: bundle install
- name: Build Jekyll site
run: JEKYLL_ENV=production bundle exec jekyll build
echo $API_KEY or similar debug commands.***)._site directory does not contain the secret string (e.g., grep -r \"API_KEY\" _site returns no matches)..env file is listed in .gitignore and run git check-ignore -v .env to confirm it is ignored.Do any of your Jekyll layouts, includes, or plugins output build‑time environment variables directly into the HTML (e.g., {{ site.api_key }})? If yes, you must audit and remove those references before relying on CI secret masking.
Use comments to ask for clarification. Post a solution as an answer.
2,660 reputation · 01 Jan 2025, 21:45 UTC
When using Jekyll’s env plugin to load a .env file, the variables become available to Liquid templates and plugins, but they are not written to the generated _site folder unless you explicitly output them (e.g., {{ env.API_KEY }}). To prevent accidental inclusion, add the .env file to the exclude list in _config.yml and ensure the file is gitignored.
jekyll build with a test variable set, then grep the variable’s value in the _site directory; it should not appear.