Mirrowel commited on
Commit
0fd5b85
Β·
1 Parent(s): a42743f

feat(ui): display proxy API key and improve onboarding/security warnings

Browse files

Improve startup and launcher TUI onboarding and security messaging:

- Refine initial-setup wording to clarify .env and provider credential responsibilities.
- Add an explicit security warning when a .env exists but PROXY_API_KEY is not set.
- Surface the actual PROXY_API_KEY value in the launcher and startup logs (or show "Not Set (INSECURE!)" when missing).
- Simplify onboarding detection to only trigger on a missing .env file (PROXY_API_KEY no longer forces onboarding).

Files changed (2) hide show
  1. src/proxy_app/launcher_tui.py +34 -13
  2. src/proxy_app/main.py +32 -18
src/proxy_app/launcher_tui.py CHANGED
@@ -239,30 +239,45 @@ class LauncherTUI:
239
  ))
240
  self.console.print("[dim]GitHub: [blue underline]https://github.com/Mirrowel/LLM-API-Key-Proxy[/blue underline][/dim]")
241
 
242
- # Show warning if needed
243
  if show_warning:
244
  self.console.print()
245
  self.console.print(Panel(
246
  Text.from_markup(
247
- "⚠️ [bold yellow]CONFIGURATION REQUIRED[/bold yellow]\n\n"
248
- "The proxy cannot start because:\n"
249
- " ❌ No .env file found (or)\n"
250
- " ❌ PROXY_API_KEY is not set in .env\n\n"
251
  "Why this matters:\n"
252
- " β€’ The .env file stores your proxy's authentication key\n"
253
- " β€’ The PROXY_API_KEY protects your proxy from unauthorized access\n"
254
- " β€’ Without it, the proxy cannot securely start\n\n"
255
  "What to do:\n"
256
  " 1. Select option \"3. Manage Credentials\" to launch the credential tool\n"
257
  " 2. The tool will create .env and set up PROXY_API_KEY automatically\n"
258
- " 3. You can also add LLM provider credentials while you're there\n\n"
259
- "⚠️ Important: While provider credentials are optional for startup,\n"
260
- " the proxy won't do anything useful without them. See README.md\n"
261
- " for supported providers and setup instructions."
262
  ),
263
  border_style="yellow",
264
  expand=False
265
  ))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
266
 
267
  # Show config
268
  self.console.print()
@@ -271,7 +286,13 @@ class LauncherTUI:
271
  self.console.print(f" Host: {self.config.config['host']}")
272
  self.console.print(f" Port: {self.config.config['port']}")
273
  self.console.print(f" Request Logging: {'βœ… Enabled' if self.config.config['enable_request_logging'] else '❌ Disabled'}")
274
- self.console.print(f" Proxy API Key: {'βœ… Set' if os.getenv('PROXY_API_KEY') else '❌ Not Set'}")
 
 
 
 
 
 
275
 
276
  # Show status summary
277
  self.console.print()
 
239
  ))
240
  self.console.print("[dim]GitHub: [blue underline]https://github.com/Mirrowel/LLM-API-Key-Proxy[/blue underline][/dim]")
241
 
242
+ # Show warning if .env file doesn't exist
243
  if show_warning:
244
  self.console.print()
245
  self.console.print(Panel(
246
  Text.from_markup(
247
+ "⚠️ [bold yellow]INITIAL SETUP REQUIRED[/bold yellow]\n\n"
248
+ "The proxy needs initial configuration:\n"
249
+ " ❌ No .env file found\n\n"
 
250
  "Why this matters:\n"
251
+ " β€’ The .env file stores your credentials and settings\n"
252
+ " β€’ PROXY_API_KEY protects your proxy from unauthorized access\n"
253
+ " β€’ Provider API keys enable LLM access\n\n"
254
  "What to do:\n"
255
  " 1. Select option \"3. Manage Credentials\" to launch the credential tool\n"
256
  " 2. The tool will create .env and set up PROXY_API_KEY automatically\n"
257
+ " 3. You can add provider credentials (API keys or OAuth)\n\n"
258
+ "⚠️ Note: The credential tool adds PROXY_API_KEY by default.\n"
259
+ " You can remove it later if you want an unsecured proxy."
 
260
  ),
261
  border_style="yellow",
262
  expand=False
263
  ))
264
+ # Show security warning if PROXY_API_KEY is missing (but .env exists)
265
+ elif not os.getenv("PROXY_API_KEY"):
266
+ self.console.print()
267
+ self.console.print(Panel(
268
+ Text.from_markup(
269
+ "⚠️ [bold red]SECURITY WARNING: PROXY_API_KEY Not Set[/bold red]\n\n"
270
+ "Your proxy is currently UNSECURED!\n"
271
+ "Anyone can access it without authentication.\n\n"
272
+ "This is a serious security risk if your proxy is accessible\n"
273
+ "from the internet or untrusted networks.\n\n"
274
+ "πŸ‘‰ [bold]Recommended:[/bold] Set PROXY_API_KEY in .env file\n"
275
+ " Use option \"2. Configure Proxy Settings\" β†’ \"3. Set Proxy API Key\"\n"
276
+ " or option \"3. Manage Credentials\""
277
+ ),
278
+ border_style="red",
279
+ expand=False
280
+ ))
281
 
282
  # Show config
283
  self.console.print()
 
286
  self.console.print(f" Host: {self.config.config['host']}")
287
  self.console.print(f" Port: {self.config.config['port']}")
288
  self.console.print(f" Request Logging: {'βœ… Enabled' if self.config.config['enable_request_logging'] else '❌ Disabled'}")
289
+
290
+ # Show actual API key value
291
+ proxy_key = os.getenv('PROXY_API_KEY')
292
+ if proxy_key:
293
+ self.console.print(f" Proxy API Key: {proxy_key}")
294
+ else:
295
+ self.console.print(" Proxy API Key: [red]Not Set (INSECURE!)[/red]")
296
 
297
  # Show status summary
298
  self.console.print()
src/proxy_app/main.py CHANGED
@@ -37,9 +37,17 @@ if args.add_credential:
37
 
38
  # If we get here, we're ACTUALLY running the proxy - NOW show startup messages and start timer
39
  _start_time = time.time()
 
 
 
 
 
 
 
 
40
  print("━" * 70)
41
  print(f"Starting proxy on {args.host}:{args.port}")
42
- print(f"Proxy API Key: {'βœ“ Set' if os.getenv('PROXY_API_KEY') else 'βœ— Not Set'}")
43
  print(f"GitHub: https://github.com/Mirrowel/LLM-API-Key-Proxy")
44
  print("━" * 70)
45
  print("Loading server components...")
@@ -115,6 +123,19 @@ class ModelList(BaseModel):
115
  _elapsed = time.time() - _start_time
116
  print(f"βœ“ Server ready in {_elapsed:.2f}s ({_plugin_count} providers discovered in {_provider_time:.2f}s)")
117
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
 
119
  # Note: Debug logging will be added after logging configuration below
120
 
@@ -848,14 +869,11 @@ if __name__ == "__main__":
848
  Check if the proxy needs onboarding (first-time setup).
849
  Returns True if onboarding is needed, False otherwise.
850
  """
851
- # Check 1: Does .env file exist?
 
852
  if not ENV_FILE.is_file():
853
  return True
854
 
855
- # Check 2: Is PROXY_API_KEY set in environment?
856
- if not PROXY_API_KEY:
857
- return True
858
-
859
  return False
860
 
861
  def show_onboarding_message():
@@ -867,25 +885,21 @@ if __name__ == "__main__":
867
  ))
868
  console.print("[bold yellow]⚠️ Configuration Required[/bold yellow]\n")
869
 
870
- console.print("The proxy cannot start because:")
871
- if not ENV_FILE.is_file():
872
- console.print(" [red]❌ No .env file found[/red]")
873
- else:
874
- console.print(" [red]❌ PROXY_API_KEY is not set in .env[/red]")
875
 
876
  console.print("\n[bold]Why this matters:[/bold]")
877
- console.print(" β€’ The .env file stores your proxy's authentication key")
878
- console.print(" β€’ The PROXY_API_KEY protects your proxy from unauthorized access")
879
- console.print(" β€’ Without it, the proxy cannot securely start")
880
 
881
  console.print("\n[bold]What happens next:[/bold]")
882
- console.print(" 1. We'll create a .env file with a default PROXY_API_KEY")
883
  console.print(" 2. You can add LLM provider credentials (API keys or OAuth)")
884
  console.print(" 3. The proxy will then start normally")
885
 
886
- console.print("\n[bold yellow]⚠️ Important:[/bold yellow] While provider credentials are optional for startup,")
887
- console.print(" the proxy won't do anything useful without them. See [bold cyan]README.md[/bold cyan]")
888
- console.print(" for supported providers and setup instructions.\n")
889
 
890
  console.input("[bold green]Press Enter to launch the credential setup tool...[/bold green]")
891
 
 
37
 
38
  # If we get here, we're ACTUALLY running the proxy - NOW show startup messages and start timer
39
  _start_time = time.time()
40
+
41
+ # Get proxy API key for display
42
+ proxy_api_key = os.getenv("PROXY_API_KEY")
43
+ if proxy_api_key:
44
+ key_display = f"βœ“ {proxy_api_key}"
45
+ else:
46
+ key_display = "βœ— Not Set (INSECURE - anyone can access!)"
47
+
48
  print("━" * 70)
49
  print(f"Starting proxy on {args.host}:{args.port}")
50
+ print(f"Proxy API Key: {key_display}")
51
  print(f"GitHub: https://github.com/Mirrowel/LLM-API-Key-Proxy")
52
  print("━" * 70)
53
  print("Loading server components...")
 
123
  _elapsed = time.time() - _start_time
124
  print(f"βœ“ Server ready in {_elapsed:.2f}s ({_plugin_count} providers discovered in {_provider_time:.2f}s)")
125
 
126
+ # Clear screen and reprint header for clean startup view
127
+ # This pushes loading messages up (still in scroll history) but shows a clean final screen
128
+ import os as _os_module
129
+ _os_module.system('cls' if _os_module.name == 'nt' else 'clear')
130
+
131
+ # Reprint header
132
+ print("━" * 70)
133
+ print(f"Starting proxy on {args.host}:{args.port}")
134
+ print(f"Proxy API Key: {key_display}")
135
+ print(f"GitHub: https://github.com/Mirrowel/LLM-API-Key-Proxy")
136
+ print("━" * 70)
137
+ print(f"βœ“ Server ready in {_elapsed:.2f}s ({_plugin_count} providers discovered in {_provider_time:.2f}s)")
138
+
139
 
140
  # Note: Debug logging will be added after logging configuration below
141
 
 
869
  Check if the proxy needs onboarding (first-time setup).
870
  Returns True if onboarding is needed, False otherwise.
871
  """
872
+ # Only check if .env file exists
873
+ # PROXY_API_KEY is optional (will show warning if not set)
874
  if not ENV_FILE.is_file():
875
  return True
876
 
 
 
 
 
877
  return False
878
 
879
  def show_onboarding_message():
 
885
  ))
886
  console.print("[bold yellow]⚠️ Configuration Required[/bold yellow]\n")
887
 
888
+ console.print("The proxy needs initial configuration:")
889
+ console.print(" [red]❌ No .env file found[/red]")
 
 
 
890
 
891
  console.print("\n[bold]Why this matters:[/bold]")
892
+ console.print(" β€’ The .env file stores your credentials and settings")
893
+ console.print(" β€’ PROXY_API_KEY protects your proxy from unauthorized access")
894
+ console.print(" β€’ Provider API keys enable LLM access")
895
 
896
  console.print("\n[bold]What happens next:[/bold]")
897
+ console.print(" 1. We'll create a .env file with PROXY_API_KEY")
898
  console.print(" 2. You can add LLM provider credentials (API keys or OAuth)")
899
  console.print(" 3. The proxy will then start normally")
900
 
901
+ console.print("\n[bold yellow]⚠️ Note:[/bold yellow] The credential tool adds PROXY_API_KEY by default.")
902
+ console.print(" You can remove it later if you want an unsecured proxy.\n")
 
903
 
904
  console.input("[bold green]Press Enter to launch the credential setup tool...[/bold green]")
905