Skip to content

feat(cliproxyapi): enable api-keys authentication on Linux only - #461

Merged
shunkakinoki merged 3 commits into
mainfrom
feat/cliproxyapi-linux-api-keys
Dec 28, 2025
Merged

feat(cliproxyapi): enable api-keys authentication on Linux only#461
shunkakinoki merged 3 commits into
mainfrom
feat/cliproxyapi-linux-api-keys

Conversation

@shunkakinoki

@shunkakinoki shunkakinoki commented Dec 28, 2025

Copy link
Copy Markdown
Owner

Changes

  • Add platform-specific api-keys configuration in cliproxyapi start.sh
  • Linux: Uncomment and enable api-keys section with CLIPROXY_API_KEY substitution
  • macOS: Keep api-keys commented for open access
  • Update config.yaml template to use __CLIPROXY_API_KEY__ placeholder

Technical Details

  • Added conditional sed processing in start.sh that runs only on Linux (uname = Linux)
  • The sed command uncomments the # api-keys: and # - "__CLIPROXY_API_KEY__" lines
  • Substitutes the placeholder with the CLIPROXY_API_KEY environment variable

Testing

  • Linux: api-keys section will be active in generated config.yaml
  • macOS: api-keys section remains commented (open access)

🤖 Generated with Claude Code by claude-opus-4-5-20250101


Note

Introduces platform-specific client authentication for CLIProxyAPI.

  • Adds Linux-only sed step in start.sh to uncomment api-keys and substitute CLIPROXY_API_KEY into the generated config.yaml
  • Updates config/cliproxyapi/config.yaml template to include "__CLIPROXY_API_KEY__" placeholder under commented api-keys

Written by Cursor Bugbot for commit c0b61b8. Configure here.


Summary by cubic

Enable API key authentication on Linux by uncommenting the api-keys section and substituting CLIPROXY_API_KEY in the generated config.yaml. On macOS, api-keys remain commented for open access.

  • Migration
    • On Linux, set CLIPROXY_API_KEY before starting cliproxyapi.

Written for commit fceb681. Summary will update automatically on new commits.

On Linux, uncomment and enable the api-keys section with CLIPROXY_API_KEY
environment variable substitution. On macOS, keep api-keys commented for
open access.

🤖 Generated with Claude Code by claude-opus-4-5-20250101
@mesa-dot-dev

mesa-dot-dev Bot commented Dec 28, 2025

Copy link
Copy Markdown

You do not have enough credits to review this pull request. Please purchase more credits to continue.

@shunkakinoki
shunkakinoki enabled auto-merge (squash) December 28, 2025 04:12
@coderabbitai

coderabbitai Bot commented Dec 28, 2025

Copy link
Copy Markdown

Warning

Rate limit exceeded

@shunkakinoki has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 10 minutes and 41 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between c0b61b8 and fceb681.

📒 Files selected for processing (2)
  • .github/workflows/shell.yml
  • spec/cliproxyapi_spec.sh

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

📝 Walkthrough

Walkthrough

Updates the CLIPROXY API key placeholder in the configuration file and adds a Linux-specific post-template step to the startup script that uncomments and injects the CLIPROXY_API_KEY into the generated config.yaml file during initialization.

Changes

Cohort / File(s) Summary
CLIPROXY API Key Configuration
config/cliproxyapi/config.yaml
Updated API key placeholder from "your-api-key" to "CLIPROXY_API_KEY" in the authentication keys section.
Startup Script Authentication Injection
home-manager/services/cliproxyapi/scripts/start.sh
Added Linux-specific post-template step to uncomment and inject CLIPROXY_API_KEY environment variable into config.yaml. Gated by platform check; macOS workflow remains unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 A placeholder blooms with CLIPROXY_API_KEY grace,
Linux awakens, secrets find their place,
Post-template magic uncomments the way,
Authentication flows on startup's day! 🔐

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main change: enabling API-keys authentication on Linux only, which aligns with both file changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The pull request description clearly outlines the changes: adding platform-specific API key configuration for cliproxyapi, with Linux enabling api-keys authentication and macOS keeping it commented, along with config.yaml template updates.

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 and usage tips.

@shunkakinoki shunkakinoki added the enhancement Indicates new feature requests. label Dec 28, 2025
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @shunkakinoki, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a feature to enable API key authentication for the cliproxyapi service specifically on Linux environments. The change ensures that config.yaml is dynamically configured to enforce API keys when deployed on Linux, enhancing security, while maintaining an open access configuration for macOS users to avoid breaking existing workflows. This allows for more granular control over access based on the operating system.

Highlights

  • Platform-Specific API Key Authentication: API key authentication is now conditionally enabled for Linux systems, while macOS installations will continue to have open access without API key enforcement.
  • Configuration Script Update: The start.sh script has been modified to include platform-specific logic, using sed to uncomment and populate the API key section in the generated config.yaml only when running on Linux.
  • Config Template Placeholder: The config.yaml template now uses a __CLIPROXY_API_KEY__ placeholder, which is dynamically replaced with the CLIPROXY_API_KEY environment variable on Linux.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@mesa-dot-dev

mesa-dot-dev Bot commented Dec 28, 2025

Copy link
Copy Markdown

Mesa Description

TL;DR

Enables API key authentication for the cliproxyapi service on Linux only, maintaining open access on macOS.

What changed?

  • config/cliproxyapi/config.yaml: Updated the API key placeholder to __CLIPROXY_API_KEY__ within the commented api-keys section.
  • home-manager/services/cliproxyapi/scripts/start.sh: Added conditional sed processing to uncomment the api-keys section and substitute CLIPROXY_API_KEY on Linux, while keeping it commented on macOS.
  • spec/cliproxyapi_spec.sh: Added new shell spec tests to verify platform-specific API key configuration for cliproxyapi.

Description generated by Mesa. Update settings

@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 adds platform-specific logic to enable API key authentication for cliproxyapi on Linux, while leaving it open on macOS. The changes involve updating the YAML config template with a placeholder and adding a sed command to the start.sh script to activate the configuration on Linux. My review identifies a critical vulnerability in the new shell script logic. The sed command is susceptible to injection if the API key contains special characters, which could break the service startup. Additionally, the script enables authentication even with an empty API key, which is a potential security risk or misconfiguration. I have provided a detailed comment with a suggested code change to address these issues by adding a check for a non-empty key and properly escaping the key value before substitution.

Comment on lines +72 to +79
# Linux: uncomment and enable api-keys for client authentication
# macOS: leave api-keys commented for open access
if [ "$(uname)" = "Linux" ]; then
@sed@ -i \
-e "s|^# api-keys:|api-keys:|" \
-e "s|^# - \"__CLIPROXY_API_KEY__\"| - \"${CLIPROXY_API_KEY:-}\"|" \
"$CONFIG"
fi

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.

critical

This block has two significant issues:

  1. Empty API Key: It enables API key authentication even if CLIPROXY_API_KEY is empty. This will result in api-keys: [ "" ] in the configuration, which could be a security risk (allowing access with an empty key) or cause the service to fail if an empty key is invalid. Authentication should only be enabled when a valid key is present.

  2. sed Injection Vulnerability: The sed command is vulnerable to script injection. If CLIPROXY_API_KEY contains characters that are special to sed's replacement string (e.g., the delimiter |, &, or \), the shell expansion will break the sed command or corrupt the key in the config file. This can prevent the service from starting.

Here is a more robust implementation that addresses both points by first checking for a non-empty key and then safely escaping it before substitution.

Suggested change
# Linux: uncomment and enable api-keys for client authentication
# macOS: leave api-keys commented for open access
if [ "$(uname)" = "Linux" ]; then
@sed@ -i \
-e "s|^# api-keys:|api-keys:|" \
-e "s|^# - \"__CLIPROXY_API_KEY__\"| - \"${CLIPROXY_API_KEY:-}\"|" \
"$CONFIG"
fi
# Linux: uncomment and enable api-keys for client authentication
# macOS: leave api-keys commented for open access
if [ "$(uname)" = "Linux" ] && [ -n "${CLIPROXY_API_KEY:-}" ]; then
# Escape characters that are special to sed's replacement string: &, \, and the delimiter |
safe_api_key=$(printf '%s' "$CLIPROXY_API_KEY" | @sed@ -e 's/[&|\\]/\\&/g')
@sed@ -i \
-e "s|^# api-keys:|api-keys:|" \
-e "s|^# - \"__CLIPROXY_API_KEY__\"| - \"$safe_api_key\"|" \
"$CONFIG"
fi

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +74 to +78
if [ "$(uname)" = "Linux" ]; then
@sed@ -i \
-e "s|^# api-keys:|api-keys:|" \
-e "s|^# - \"__CLIPROXY_API_KEY__\"| - \"${CLIPROXY_API_KEY:-}\"|" \
"$CONFIG"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Guard against empty CLIPROXY_API_KEY on Linux

On Linux this block always uncomments api-keys and substitutes ${CLIPROXY_API_KEY:-}; when the env var is unset (e.g., missing .env in a systemd context), the config becomes api-keys: [""]. Depending on CLIProxyAPI’s auth logic, that either locks out all clients (no one has an empty key) or unintentionally allows empty-key access if a missing header is treated as "". To avoid surprising outages or false security, only enable the section when the key is non-empty or fail fast if it’s required.

Useful? React with 👍 / 👎.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is the final PR Bugbot will review for you during this billing cycle

Your free Bugbot reviews will reset on January 27

Details

You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

if [ "$(uname)" = "Linux" ]; then
@sed@ -i \
-e "s|^# api-keys:|api-keys:|" \
-e "s|^# - \"__CLIPROXY_API_KEY__\"| - \"${CLIPROXY_API_KEY:-}\"|" \

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Empty API key enabled when environment variable unset

When CLIPROXY_API_KEY is not set or empty, the substitution ${CLIPROXY_API_KEY:-} results in an empty string being configured as a valid API key. On Linux, this produces a config with api-keys: [""], meaning the authentication system is enabled but with an empty string as the only valid key. Depending on how cliproxyapi validates API keys, this could either allow authentication with an empty API key header (security bypass) or block all legitimate requests (service outage). The script unconditionally uncomments the api-keys section without verifying the environment variable is set and non-empty.

Fix in Cursor Fix in Web

@cubic-dev-ai cubic-dev-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.

1 issue found across 2 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="home-manager/services/cliproxyapi/scripts/start.sh">

<violation number="1" location="home-manager/services/cliproxyapi/scripts/start.sh:74">
P1: The API key authentication is enabled unconditionally on Linux without checking if `CLIPROXY_API_KEY` is actually set. When the environment variable is empty or unset, the config will contain `api-keys: [&quot;&quot;]`, which could either lock out all clients (if empty keys are rejected) or create a security vulnerability (if empty keys are accepted). Add a check for a non-empty key value before enabling authentication.</violation>
</file>

Reply to cubic to teach it or ask questions. Tag @cubic-dev-ai to re-run a review.


# Linux: uncomment and enable api-keys for client authentication
# macOS: leave api-keys commented for open access
if [ "$(uname)" = "Linux" ]; then

@cubic-dev-ai cubic-dev-ai Bot Dec 28, 2025

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.

P1: The API key authentication is enabled unconditionally on Linux without checking if CLIPROXY_API_KEY is actually set. When the environment variable is empty or unset, the config will contain api-keys: [""], which could either lock out all clients (if empty keys are rejected) or create a security vulnerability (if empty keys are accepted). Add a check for a non-empty key value before enabling authentication.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At home-manager/services/cliproxyapi/scripts/start.sh, line 74:

<comment>The API key authentication is enabled unconditionally on Linux without checking if `CLIPROXY_API_KEY` is actually set. When the environment variable is empty or unset, the config will contain `api-keys: [&quot;&quot;]`, which could either lock out all clients (if empty keys are rejected) or create a security vulnerability (if empty keys are accepted). Add a check for a non-empty key value before enabling authentication.</comment>

<file context>
@@ -68,6 +68,15 @@ if [ -f &quot;$TEMPLATE&quot; ]; then
+
+  # Linux: uncomment and enable api-keys for client authentication
+  # macOS: leave api-keys commented for open access
+  if [ &quot;$(uname)&quot; = &quot;Linux&quot; ]; then
+    @sed@ -i \
+      -e &quot;s|^# api-keys:|api-keys:|&quot; \
</file context>
Suggested change
if [ "$(uname)" = "Linux" ]; then
if [ "$(uname)" = "Linux" ] && [ -n "${CLIPROXY_API_KEY:-}" ]; then
Fix with Cubic

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
home-manager/services/cliproxyapi/scripts/start.sh (1)

72-79: Consider validating that CLIPROXY_API_KEY is set on Linux.

The current implementation uses ${CLIPROXY_API_KEY:-}, which defaults to an empty string if the variable is unset. On Linux, this would generate api-keys: with an empty list item - "", which may not provide the intended authentication behavior.

🔎 Proposed validation to fail fast if the key is missing on Linux
   # Linux: uncomment and enable api-keys for client authentication
   # macOS: leave api-keys commented for open access
   if [ "$(uname)" = "Linux" ]; then
+    if [ -z "${CLIPROXY_API_KEY:-}" ]; then
+      echo "ERROR: CLIPROXY_API_KEY must be set on Linux for client authentication" >&2
+      exit 1
+    fi
     @sed@ -i \
       -e "s|^# api-keys:|api-keys:|" \
-      -e "s|^#   - \"__CLIPROXY_API_KEY__\"|  - \"${CLIPROXY_API_KEY:-}\"|" \
+      -e "s|^#   - \"__CLIPROXY_API_KEY__\"|  - \"${CLIPROXY_API_KEY}\"|" \
       "$CONFIG"
   fi
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between e7ee75b and c0b61b8.

📒 Files selected for processing (2)
  • config/cliproxyapi/config.yaml
  • home-manager/services/cliproxyapi/scripts/start.sh
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{json,yaml,yml,toml}

📄 CodeRabbit inference engine (.cursor/rules/formatting.mdc)

**/*.{json,yaml,yml,toml}: Use consistent indentation (2 spaces) in configuration files
Sort keys alphabetically when possible in configuration files
Use clear, descriptive names in configuration files

Files:

  • config/cliproxyapi/config.yaml
**/*.{yaml,yml,toml}

📄 CodeRabbit inference engine (.cursor/rules/formatting.mdc)

Add comments for complex configurations

Files:

  • config/cliproxyapi/config.yaml
**/*.{sh,bash}

📄 CodeRabbit inference engine (CLAUDE.md)

Use shfmt with 2-space indentation for shell scripts

**/*.{sh,bash}: Use 2 spaces for indentation in shell scripts
Add proper shebang lines to shell scripts
Follow shellcheck recommendations in shell scripts
Document complex commands in shell scripts
Use consistent variable naming in shell scripts

Files:

  • home-manager/services/cliproxyapi/scripts/start.sh
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (15)
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: Cursor Bugbot
  • GitHub Check: nix-nixos
  • GitHub Check: nix-darwin
  • GitHub Check: nix-linux
  • GitHub Check: e2e-run (MacOS, macos-latest)
  • GitHub Check: e2e-run (NixOS, ubuntu-latest)
  • GitHub Check: e2e-run (Ubuntu, ubuntu-latest)
  • GitHub Check: shellcheck
  • GitHub Check: shellspec
  • GitHub Check: docker-build-push (linux/arm64, arm64, ubuntu-24.04-arm)
  • GitHub Check: docker-build-push (linux/amd64, amd64, ubuntu-latest)
  • GitHub Check: lua-neovim
  • GitHub Check: lua-neovim-test
  • GitHub Check: lua-hammerspoon
🔇 Additional comments (2)
config/cliproxyapi/config.yaml (1)

18-18: LGTM! Placeholder aligns with the injection mechanism.

The placeholder format is consistent with other configuration placeholders in the file (__CLIPROXY_MANAGEMENT_PASSWORD__) and correctly matches the sed pattern in start.sh (line 77) that will uncomment and substitute this value on Linux.

home-manager/services/cliproxyapi/scripts/start.sh (1)

74-79: Sed patterns work correctly and produce valid YAML; platform-specific behavior is properly implemented.

The transformation successfully uncomments the api-keys section and replaces the placeholder on Linux. The generated config is valid YAML. The conditional at line 74 correctly limits the transformation to Linux only, leaving the api-keys commented on macOS for open access as intended.

Note: While the sed patterns currently match the template structure exactly, these patterns are inherently fragile. Consider documenting the expected template format or adding a validation step if the config template structure changes frequently.

Add ShellSpec tests to verify:
- Linux: api-keys section is uncommented and CLIPROXY_API_KEY substituted
- macOS: api-keys section remains commented for open access
- Script contains the Linux-specific uncommenting logic

🤖 Generated with Claude Code by claude-opus-4-5-20250101
@shunkakinoki
shunkakinoki force-pushed the feat/cliproxyapi-linux-api-keys branch from 01210c1 to 46dae4e Compare December 28, 2025 04:26
@shunkakinoki
shunkakinoki merged commit fb15ff7 into main Dec 28, 2025
7 checks passed
@shunkakinoki
shunkakinoki deleted the feat/cliproxyapi-linux-api-keys branch December 28, 2025 04:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Indicates new feature requests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant