Skip to content

chore: relocate secrets from pod.yaml to .env and automate key initialization#184

Merged
sheepdestroyer merged 7 commits into
masterfrom
fix/secrets-relocation
Jul 1, 2026
Merged

chore: relocate secrets from pod.yaml to .env and automate key initialization#184
sheepdestroyer merged 7 commits into
masterfrom
fix/secrets-relocation

Conversation

@sheepdestroyer

@sheepdestroyer sheepdestroyer commented Jun 30, 2026

Copy link
Copy Markdown
Owner

This PR relocates all hardcoded/truncated secrets out of pod.yaml and places them in .env.

Additional improvements:

  1. Replaces secrets in pod.yaml with UPPERCASE placeholder tokens.
  2. Fully qualifies docker.io image names in pod.yaml to avoid short-name resolution failures in non-TTY environments.
  3. Automatically prompts or generates missing secrets on startup in start-stack.sh using openssl to format UUID-like keys.

Summary by Sourcery

Relocate hardcoded secrets from pod.yaml into environment variables and automate their initialization in the startup script.

New Features:

  • Automatically generate Langfuse public/secret keys and persist them to .env when missing.
  • Interactively prompt for or initialize a default Ollama API key and store it in .env when not set.

Enhancements:

  • Extend startup secret checks to cover Langfuse and Ollama keys so all required credentials are validated on stack launch.
  • Refine pod.yaml to use explicit placeholder tokens for all secrets and resolve them from environment at render time.
  • Fully qualify container image references in pod.yaml with docker.io to improve reliability across environments.

Summary by CodeRabbit

  • Bug Fixes

    • Improved datetime handling so database records can be serialized more reliably across different runtime sources.
  • New Features

    • Enhanced stack startup to generate and manage additional required secrets automatically.
    • Expanded setup prompts and defaults for missing API keys and credentials.
  • Chores

    • Updated bundled container image references to newer, fully qualified versions.
    • Replaced embedded sensitive values with placeholder-based configuration for safer deployment setup.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@sourcery-ai

sourcery-ai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Secrets are moved out of pod.yaml into environment-driven placeholders, with start-stack.sh now responsible for generating or prompting for missing keys (including Langfuse and Ollama) and render_pod_yaml updated to substitute these placeholders, while Docker images are fully qualified with docker.io prefixes.

Sequence diagram for secret initialization and pod.yaml rendering

sequenceDiagram
    actor Operator
    participant start_stack_sh
    participant openssl
    participant env_file as .env
    participant render_pod_yaml

    Operator->>start_stack_sh: run start-stack.sh
    start_stack_sh->>start_stack_sh: check POSTGRES_PASSWORD, NEXTAUTH_SECRET, SALT, ENCRYPTION_KEY, LITELLM_MASTER_KEY, LANGFUSE_PUBLIC_KEY, LANGFUSE_SECRET_KEY, OLLAMA_API_KEY
    alt any_secret_missing
        start_stack_sh->>openssl: command -v openssl
        alt secret_is_generated
            start_stack_sh->>openssl: openssl rand -base64 32
            start_stack_sh->>openssl: openssl rand -hex 16 (generate_uuid)
            openssl-->>start_stack_sh: generated key material
            start_stack_sh->>env_file: append generated secrets
        else OLLAMA_API_KEY_missing_and_TTY
            start_stack_sh->>Operator: prompt for OLLAMA_API_KEY
            Operator-->>start_stack_sh: enter OLLAMA_API_KEY
            start_stack_sh->>env_file: append OLLAMA_API_KEY
        else OLLAMA_API_KEY_missing_and_non_TTY
            start_stack_sh->>env_file: write default OLLAMA_API_KEY
        end
    end

    start_stack_sh->>render_pod_yaml: call render_pod_yaml
    render_pod_yaml->>render_pod_yaml: load pod.yaml
    render_pod_yaml->>render_pod_yaml: replace *_PLACEHOLDER with env vars
    render_pod_yaml-->>Operator: rendered pod.yaml ready for pod startup
Loading

File-Level Changes

Change Details Files
Extend start-stack.sh to manage new secrets and add a reusable UUID-style key generator.
  • Include LANGFUSE_PUBLIC_KEY and LANGFUSE_SECRET_KEY in the openssl-required checks for missing secrets.
  • Add generate_uuid() helper that formats openssl random data into UUID-like strings.
  • Automatically generate LANGFUSE_PUBLIC_KEY and LANGFUSE_SECRET_KEY when absent, with pk-lf-/sk-lf- prefixes.
  • Add interactive/non-interactive initialization flow for OLLAMA_API_KEY, prompting in TTY or using a default value otherwise.
  • Ensure new secrets are persisted to .env with restrictive permissions.
start-stack.sh
Refactor pod.yaml to use environment placeholders instead of hardcoded secrets and ensure images are fully qualified.
  • Replace literal secrets (Postgres passwords, Litellm master key, Langfuse keys, Ollama API key) with UPPERCASE placeholder tokens.
  • Introduce distinct placeholders for raw and URL-encoded Postgres passwords in DATABASE_URL settings.
  • Update all Docker image references to include docker.io/ registry prefix.
  • Align Langfuse-related env vars (web and worker) to use placeholders for secrets and DB URLs.
  • Ensure all services consistently reference the new placeholders for secrets and connection strings.
pod.yaml
Update render_pod_yaml in start-stack.sh to export additional env variables and map new placeholders to runtime values.
  • Export OLLAMA_API_KEY, LANGFUSE_PUBLIC_KEY, and LANGFUSE_SECRET_KEY so they are available to the Python renderer.
  • Replace old inline secret strings in pod.yaml with new placeholder names in the Python placeholders list.
  • Add substitution logic for raw and URL-encoded Postgres password placeholders using urllib.parse.quote_plus.
  • Wire up substitutions for the new Langfuse and Ollama API key placeholders from the environment.
  • Keep existing NEXTAUTH_SECRET, SALT, ENCRYPTION_KEY, and LITELLM_MASTER_KEY substitution behavior while removing hardcoded sample values.
start-stack.sh

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@sheepdestroyer, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 27 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 45f60a57-4b8f-4589-ac94-8369d447c13e

📥 Commits

Reviewing files that changed from the base of the PR and between 7c4270d and 889faff.

📒 Files selected for processing (2)
  • litellm/entrypoint.py
  • start-stack.sh
📝 Walkthrough

Walkthrough

This PR updates start-stack.sh to generate additional secrets (Langfuse keys, Ollama key with interactive prompt fallback) and expands render_pod_yaml() placeholder substitution logic; pod.yaml is updated with matching placeholder values and fully qualified docker.io image references; litellm/entrypoint.py registers a Prisma datetime serializer for both original and patched datetime classes.

Changes

Secret Generation and Pod Templating

Layer / File(s) Summary
OpenSSL guards and UUID helper
start-stack.sh
Expands OpenSSL availability checks to cover new secrets and adds a generate_uuid() helper using openssl rand.
Secret generation for Langfuse and Ollama
start-stack.sh
Conditionally generates LANGFUSE_PUBLIC_KEY/LANGFUSE_SECRET_KEY and initializes OLLAMA_API_KEY interactively or with a default, persisting to .env.
render_pod_yaml() placeholder substitution
start-stack.sh
Extends exported env vars, placeholder validation list, and substitution logic, including splitting Postgres password into raw and URL-encoded forms.
pod.yaml placeholder values and image updates
pod.yaml
Updates container env vars to placeholder strings and changes several container images to fully qualified docker.io references.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Prisma Datetime Serialization

Layer / File(s) Summary
Prisma serializer registration
litellm/entrypoint.py
Registers a shared UTC-aware ISO8601 datetime serializer for both original_datetime and RobustDatetime, guarded by try/except ImportError.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • sheepdestroyer/LLM-Routing#101: Similar templated env-injection approach for NEXTAUTH_SECRET, SALT, ENCRYPTION_KEY placeholders in start-stack.sh/pod.yaml.
  • sheepdestroyer/LLM-Routing#102: Also modifies start-stack.sh pod YAML rendering to replace hardcoded Langfuse cryptographic values with dynamically generated placeholders.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: moving secrets into .env and automating missing key initialization.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/secrets-relocation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 security issue, and 1 other issue

Security issues:

  • Detected an Ollama API Key, which may expose local and hosted AI model serving to unauthorized access. (link)
Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="start-stack.sh" line_range="182" />
<code_context>
+        echo "✓ Ollama API key saved securely to $ENV_FILE"
+    else
+        echo "⚠️ OLLAMA_API_KEY not set in .env. Initializing with the default key."
+        OLLAMA_API_KEY="3cd542f8fca14fd08bedfd4f2ab36f9f.6G7Iukbvu1Keyi9x8eKckNEO"
+        echo "OLLAMA_API_KEY=\"$OLLAMA_API_KEY\"" >> "$ENV_FILE"
+        chmod 600 "$ENV_FILE"
</code_context>
<issue_to_address>
**🚨 issue (security):** Avoid shipping a real-looking default OLLAMA_API_KEY in the script, especially for non-interactive runs.

Using a realistic-looking default key in non-interactive mode is risky: it could be mistakenly used in real environments, and if it ever corresponds to a real key, it leaks credentials. Instead, either fail when `OLLAMA_API_KEY` is missing in non-interactive runs, or write a clearly invalid placeholder (e.g. `OLLAMA_API_KEY="CHANGE_ME"`) so misconfiguration is obvious. If you need a random value, reuse the existing `openssl`-based key generation rather than hardcoding a static string.
</issue_to_address>

### Comment 2
<location path="start-stack.sh" line_range="182" />
<code_context>
3cd542f8fca14fd08bedfd4f2ab36f9f.6G7Iukbvu1Keyi9x8eKckNEO
</code_context>
<issue_to_address>
**security (ollama-api-key):** Detected an Ollama API Key, which may expose local and hosted AI model serving to unauthorized access.

*Source: betterleaks*
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread start-stack.sh Outdated
Comment thread start-stack.sh Outdated
…ma serializer to fix spend logs serialization issue

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@start-stack.sh`:
- Around line 159-169: The Langfuse secret write path in start-stack.sh appends
keys to ENV_FILE without reapplying restrictive permissions. After the
LANGFUSE_PUBLIC_KEY and LANGFUSE_SECRET_KEY blocks, add the same chmod 600
"$ENV_FILE" hardening used elsewhere (for example in the Ollama branch) so the
.env file stays owner-readable only after secrets are written.
- Around line 171-185: The OLLAMA_API_KEY fallback in start-stack.sh
reintroduces a hardcoded secret and should be removed. Update the startup logic
in the OLLAMA_API_KEY handling block so that interactive runs prompt the user
and save only the entered value, while non-interactive runs fail fast with a
clear message instead of assigning a committed default. Keep the fix localized
to the OLLAMA_API_KEY branch and preserve the existing ENV_FILE write behavior
for user-supplied keys.
- Around line 424-428: The Postgres password encoding in the DATABASE_URL
assembly is using the wrong encoder, so replace the `urllib.parse.quote_plus`
call in `start-stack.sh` with percent-encoding that preserves spaces correctly
in URI userinfo. Update the password handling around the `encoded_password`
assignment and the `POSTGRES_PASSWORD_ENCODED_PLACEHOLDER` replacement to use
the proper encoder for DSN insertion, keeping the rest of the
`text.replace(...)` flow unchanged.
- Around line 119-122: The generate_uuid function is masking failures from
openssl rand because the command substitution is assigned directly to local val,
so the function can still succeed with an empty or partial value. Update
generate_uuid to explicitly capture and check the openssl rand exit status
before echoing the formatted UUID, and make sure callers that write
pk-lf-/sk-lf- values only proceed when a valid 32-hex-character value was
generated.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8946d55b-0919-4601-be92-8b55c3b2bda8

📥 Commits

Reviewing files that changed from the base of the PR and between c1dc3fd and 7c4270d.

📒 Files selected for processing (3)
  • litellm/entrypoint.py
  • pod.yaml
  • start-stack.sh

Comment thread start-stack.sh
Comment thread start-stack.sh
Comment thread start-stack.sh
Comment thread start-stack.sh
@sheepdestroyer

Copy link
Copy Markdown
Owner Author

@gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request replaces hardcoded credentials and keys in pod.yaml with placeholders, updates start-stack.sh to dynamically generate or prompt for these keys (including Langfuse and Ollama keys), and registers both RobustDatetime and original_datetime with the Prisma serializer in litellm/entrypoint.py. The review feedback suggests: 1) using safe='' with urllib.parse.quote to ensure slash characters in PostgreSQL passwords are correctly encoded; 2) catching a broader Exception instead of just ImportError when registering Prisma serializers to prevent startup failures; and 3) consolidating the redundant openssl availability checks in start-stack.sh by adding ROUTER_API_KEY to the initial check.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread start-stack.sh Outdated
Comment thread litellm/entrypoint.py Outdated
Comment thread start-stack.sh Outdated
Comment thread start-stack.sh
sheepdestroyer and others added 3 commits July 1, 2026 09:53
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@sheepdestroyer
sheepdestroyer merged commit 2179aee into master Jul 1, 2026
5 of 6 checks passed
@sheepdestroyer
sheepdestroyer deleted the fix/secrets-relocation branch July 1, 2026 07:55
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

Successfully merging this pull request may close these issues.

1 participant