Skip to content

Commit 37b7ebf

Browse files
authored
Merge pull request #7 from lroolle/fix/env-vars-and-auth-improvements
Environment variables, authentication improvements, and critical security fix
2 parents 98328d9 + 8dada53 commit 37b7ebf

5 files changed

Lines changed: 446 additions & 162 deletions

File tree

DEV-LOGS.md

Lines changed: 144 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,144 @@
11
# Development Logs
2+
- Prepend new entries with `## Issue Analysis: YYYY-MM-DD`.
3+
- We write or explain to the damn point. Be clear, be super concise - no fluff, no hand-holding, no repeating.
4+
- Minimal markdown markers, no unnecessary formatting, minimal unicode emojis.
5+
6+
## Issue Analysis: 2025-06-22
7+
8+
### [problem-discovered] GitHub CLI auth fails in containers
9+
10+
**Problem**: Mounting `~/.config/gh/` doesn't work for GitHub CLI authentication in containers.
11+
12+
**Root Cause**: Modern `gh` uses secure keyring storage instead of plain text files:
13+
- **Host**: Tokens stored in macOS Keychain/Linux Secret Service/Windows Credential Manager
14+
- **Container**: No keyring access, auth fails even with mounted config directory
15+
- **Split State**: Config files present but tokens inaccessible
16+
17+
**Technical Details**:
18+
```bash
19+
# Host auth state:
20+
~/.config/gh/config.yml # Configuration
21+
~/.config/gh/hosts.yml # May contain tokens OR keyring references
22+
System Keyring # Actual tokens (secure storage)
23+
24+
# Container reality:
25+
/root/.config/gh/config.yml # ✅ Mounted successfully
26+
/root/.config/gh/hosts.yml # ✅ Mounted but may reference unavailable keyring
27+
No System Keyring # ❌ DBus/keyring services not available
28+
```
29+
30+
**Why This Matters**: Current codebase has complete auth system for Claude/AWS/GCloud but GitHub CLI missing.
31+
32+
**Immediate Impact**: Cannot create PRs or manage GitHub repos from within containers.
33+
34+
**Solutions Research**:
35+
1. **Environment Variable**: `GH_TOKEN="ghp_xxx"` - simple, headless-friendly
36+
2. **Insecure Storage**: `gh auth login --insecure-storage` on host, then mount works
37+
3. **Token Injection**: `echo $TOKEN | gh auth login --with-token` in container
38+
4. **Mount Strategy**: Add explicit GitHub CLI auth mounting to claude.sh
39+
40+
**Status**: Research complete, need implementation decision.
41+
42+
---
43+
44+
## Issue Analysis: 2025-06-22
45+
46+
### [enhancement] Controlled auth directory mounting
47+
48+
**Problem**: Symlinking all /root/* was too broad and risky.
49+
50+
**Better approach**: Explicit, controlled mounts with proper permissions:
51+
```bash
52+
# claude.sh mounts:
53+
~/.claude → /root/.claude # read-write (auth tokens)
54+
~/.config → /root/.config:ro # read-only (XDG tools)
55+
~/.aws → /root/.aws:ro # read-only
56+
~/.ssh → /root/.ssh:ro # read-only
57+
~/.gitconfig → /root/.gitconfig:ro # read-only
58+
59+
# docker-entrypoint.sh:
60+
- Symlinks specific directories to /home/claude
61+
- Sets XDG_CONFIG_HOME=/root/.config
62+
- Maintains controlled access list
63+
```
64+
65+
**Benefits**:
66+
- ✅ Security: Read-only where appropriate
67+
- ✅ XDG compliance: Entire .config dir for gh/gcloud/etc
68+
- ✅ Explicit: Clear what's accessible
69+
- ✅ Safe: No unexpected file exposure
70+
71+
**Status**: -> **IMPLEMENTED**
72+
73+
### [enhancement-implemented] Consolidate auth options to --auth-with pattern
74+
75+
**Problem**: Auth flags conflict with common conventions (-v for volumes vs Vertex).
76+
77+
**Current mess**:
78+
- `-c/--claude` → Claude app (OAuth)
79+
- `-a/--api-key` → Anthropic API
80+
- `-b/--bedrock` → AWS Bedrock
81+
- `-v/--vertex` → Google Vertex AI (blocks -v for volumes!)
82+
83+
**Solution**: Single `--auth-with` parameter:
84+
```bash
85+
claude.sh --auth-with vertex . # Explicit auth method
86+
claude.sh -v ~/.ssh:/root/.ssh . # -v now free for volumes
87+
```
88+
89+
**Implementation**:
90+
1. ✅ Added `--auth-with METHOD` parsing in claude.sh
91+
2. ✅ Kept old flags for backward compatibility (with deprecation warnings)
92+
3. ✅ Freed up `-v` for volume mounting (Docker convention)
93+
4. ✅ Updated claude-yolo to use `-v` instead of `--mount`
94+
95+
**Benefits**:
96+
- ✅ Follows Docker convention (-v for volumes)
97+
- ✅ Cleaner, extensible auth interface
98+
- ✅ No more flag conflicts
99+
- ✅ Better CLI UX
100+
101+
**Status**: ✅ **IMPLEMENTED**
102+
103+
### [enhancement-implemented] Generalized config mounting
104+
105+
**Problem**: Hardcoding each tool's config mount doesn't scale.
106+
107+
**Root cause**: Mount to /root, run as claude user -> symlink hell.
108+
109+
**Initial Proposal**: Mount entire ~/.config, use XDG standards.
110+
111+
**Implemented Solution**: Added flexible volume mounting via `-v` argument in claude-yolo.
112+
113+
```bash
114+
# New usage - users can mount any config they need:
115+
claude-yolo -v ~/.gitconfig:/root/.gitconfig .
116+
claude-yolo -v ~/.ssh:/root/.ssh:ro .
117+
claude-yolo -v ~/tools:/tools -v ~/data:/data .
118+
119+
# Implementation in claude-yolo:
120+
- Parse -v/--mount arguments, collect in array
121+
- Pass to claude.sh via CLAUDE_EXTRA_VOLUMES env var
122+
- claude.sh adds these volumes to Docker run command
123+
```
124+
125+
**Benefits**:
126+
-**Flexible**: Mount any config/directory as needed
127+
-**Familiar**: Uses Docker's -v syntax
128+
-**Secure**: Users control what to expose
129+
-**Extensible**: No hardcoded tool list to maintain
130+
131+
**Result**: Zero maintenance. New tools work via explicit mounting.
132+
133+
**Status**: ✅ **IMPLEMENTED** - Added -v/--mount support to claude-yolo
2134

3135
## Issue Analysis: 2025-06-22
4136

5137
### [bug-fixed] --trace flag doesn't pass --dangerously-skip-permissions in YOLO mode
6138

7139
**Problem**: `claude-yolo --trace .` fails to add `--dangerously-skip-permissions` to the claude command.
8140

9-
**Root Cause Found**:
141+
**Root Cause Found**:
10142
- In `claude.sh:562`, when `--trace` is used, the command was incorrectly constructed as:
11143
```bash
12144
claude-trace --include-all-requests --run-with .
@@ -17,11 +149,7 @@
17149

18150
1. **Fixed command construction** in `claude.sh:562`:
19151
```bash
20-
# Before (broken):
21-
DOCKER_ARGS+=("claude-trace" "--include-all-requests" "--run-with" "${CLAUDE_ARGS[@]}")
22-
23-
# After (fixed):
24-
DOCKER_ARGS+=("claude-trace" "--include-all-requests" "--run-with" "claude" "${CLAUDE_ARGS[@]}")
152+
claude-trace --include-all-requests --run-with claude .
25153
```
26154

27155
2. **Enhanced argument injection** in `docker-entrypoint.sh`:
@@ -36,7 +164,7 @@
36164
done
37165
```
38166

39-
**Result**:
167+
**Result**:
40168
- Input: `claude-yolo --trace .`
41169
- Command: `claude-trace --include-all-requests --run-with claude .`
42170
- Executed: `claude-trace --include-all-requests --run-with claude --dangerously-skip-permissions .`
@@ -49,7 +177,7 @@
49177

50178
**Problem**: All dev tools are baked into Dockerfile, requiring full image rebuild for new tools.
51179

52-
**Current State**:
180+
**Current State**:
53181
- Tools installed in Dockerfile:92-117 (gh, delta, claude, claude-trace)
54182
- Static installation makes customization inflexible
55183
- Image size grows with every tool added
@@ -103,7 +231,7 @@ Cons: Multiple package manager complexity
103231

104232
**Current Auth State**:
105233
-**Claude**: Auto-mounted via `~/.claude``/root/.claude``/home/claude/.claude` (symlink)
106-
-**AWS**: Auto-mounted via `~/.aws``/root/.aws``/home/claude/.aws` (symlink)
234+
-**AWS**: Auto-mounted via `~/.aws``/root/.aws``/home/claude/.aws` (symlink)
107235
-**Google Cloud**: Auto-mounted via `~/.config/gcloud``/root/.config/gcloud``/home/claude/.config/gcloud` (symlink)
108236
-**GitHub CLI**: Requires manual `gh auth login` or token pasting into `/home/claude/.config/gh/`
109237
-**Docker Hub**: No auth mounting for `docker login`
@@ -118,7 +246,7 @@ Cons: Multiple package manager complexity
118246
```bash
119247
# In claude.sh, add more auth directories
120248
[ -d "$HOME/.config/gh" ] && DOCKER_ARGS+=("-v" "$HOME/.config/gh:/root/.config/gh")
121-
[ -f "$HOME/.npmrc" ] && DOCKER_ARGS+=("-v" "$HOME/.npmrc:/root/.npmrc")
249+
[ -f "$HOME/.npmrc" ] && DOCKER_ARGS+=("-v" "$HOME/.npmrc:/root/.npmrc")
122250
[ -d "$HOME/.docker" ] && DOCKER_ARGS+=("-v" "$HOME/.docker:/root/.docker")
123251
[ -d "$HOME/.terraform.d" ] && DOCKER_ARGS+=("-v" "$HOME/.terraform.d:/root/.terraform.d")
124252
```
@@ -167,13 +295,13 @@ AUTH_PATHS=(
167295

168296
---
169297

170-
### [enhancement-resolved] Multiple Claude instances workflow
298+
### [enhancement-resolved] Multiple Claude instances workflow
171299

172300
**Original Problem**: Users wanted multiple Claude instances in same project without container name conflicts.
173301

174302
**Original Goal Misunderstanding**: We thought users wanted shared containers, but they actually just wanted **multiple simultaneous instances**.
175303

176-
**Simple Solution Implemented**:
304+
**Simple Solution Implemented**:
177305
- **Reverted to process-based naming**: `claude-code-yolo-${CURRENT_DIR_BASENAME}-$$`
178306
- **Keep `--rm` for auto-cleanup**: Each instance gets its own container
179307
- **No complexity needed**: Each process gets unique container name via `$$`
@@ -183,7 +311,7 @@ AUTH_PATHS=(
183311
# Terminal 1:
184312
claude-yolo . # → claude-code-yolo-myproject-12345
185313

186-
# Terminal 2:
314+
# Terminal 2:
187315
claude-yolo . # → claude-code-yolo-myproject-67890
188316

189317
# Both run simultaneously, both auto-cleanup
@@ -213,7 +341,7 @@ claude-yolo . # → claude-code-yolo-myproject-67890
213341

214342
**Features Added**:
215343
- `claude-yolo --inspect`: Auto-find and enter container as claude user
216-
- `claude-yolo --ps`: List all containers for current project
344+
- `claude-yolo --ps`: List all containers for current project
217345
- **Smart selection**: Auto-select single container, prompt for multiple
218346
- **Project-aware**: Only shows containers matching current directory pattern
219347

@@ -241,7 +369,7 @@ fi
241369
**Before** (painful):
242370
```bash
243371
docker ps # Find container
244-
docker exec -it claude-code-yolo-proj-12345 /bin/zsh # Enter container
372+
docker exec -it claude-code-yolo-proj-12345 /bin/zsh # Enter container
245373
su - claude # Switch to proper user
246374
```
247375

@@ -256,7 +384,7 @@ claude-yolo --inspect
256384

257385
Multiple containers found for this project:
258386
1) claude-code-yolo-myproject-12345 (Up 5 minutes)
259-
2) claude-code-yolo-myproject-67890 (Up 2 minutes)
387+
2) claude-code-yolo-myproject-67890 (Up 2 minutes)
260388

261389
Select container to inspect (1-2): 1
262390
Entering container claude-code-yolo-myproject-12345 as claude user...
@@ -269,68 +397,3 @@ Entering container claude-code-yolo-myproject-12345 as claude user...
269397
**Status**: ✅ **COMPLETED** - Issue #4 resolved
270398

271399
---
272-
273-
## Current Implementation Summary
274-
275-
### What We've Built
276-
277-
**Issue #1**: ✅ Fixed `--trace` flag not passing `--dangerously-skip-permissions`
278-
- **Solution**: Added explicit `claude-trace` detection in `docker-entrypoint.sh:167,182`
279-
- **Result**: `claude-yolo --trace .` now works correctly in YOLO mode
280-
281-
**Issue #4**: ✅ Added container inspection shortcuts
282-
- **Solution**: Enhanced `claude-yolo` with `--inspect` and `--ps` commands
283-
- **Result**: One-command container access with smart multi-container selection
284-
285-
**Multiple Instances**: ✅ Simplified approach for concurrent Claude instances
286-
- **Solution**: Reverted to process-based naming `$$` for unique containers
287-
- **Result**: Multiple `claude-yolo .` commands work simultaneously, auto-cleanup
288-
289-
### Current Architecture
290-
291-
**claude.sh** (578 lines):
292-
- Main Docker wrapper with authentication, environment setup, and container creation
293-
- Process-based container naming: `claude-code-yolo-${CURRENT_DIR_BASENAME}-$$`
294-
- Always uses `--rm` for auto-cleanup
295-
- Supports 4 auth modes: Claude app, API key, AWS Bedrock, Google Vertex AI
296-
297-
**docker-entrypoint.sh** (194 lines):
298-
- Container initialization with environment reporting
299-
- Non-root user setup with proper UID/GID alignment
300-
- Authentication symlink creation (`/root/.claude``/home/claude/.claude`)
301-
- Fixed pattern matching for Claude commands (including `claude-trace`)
302-
303-
**claude-yolo** (75 lines):
304-
- Enhanced wrapper with container inspection shortcuts
305-
- Smart container discovery and selection
306-
- Simple fallback to `claude.sh --yolo` for normal operations
307-
308-
### Key Design Principles Applied
309-
310-
1. **Simplicity over complexity**: Chose unique container names over shared containers
311-
2. **User experience focus**: One-command access for common operations
312-
3. **Pattern matching**: Project-aware container management
313-
4. **Auto-cleanup**: Containers remove themselves when done
314-
5. **Smart defaults**: Auto-select single containers, prompt for multiple
315-
316-
---
317-
318-
## Technical Details
319-
320-
### File Locations
321-
- Main wrapper: `claude.sh:559` (YOLO trace command)
322-
- Entrypoint logic: `docker-entrypoint.sh:167-169, 181-183` (dangerous permissions logic)
323-
- Tool installation: `Dockerfile:92-117` (static tool setup)
324-
325-
### Key Functions
326-
- `claude.sh` line 557-562: Trace command construction
327-
- `docker-entrypoint.sh` line 156-189: Command execution with permission handling
328-
- `docker-entrypoint.sh` line 11-64: Environment reporting
329-
330-
---
331-
332-
## Next Steps
333-
1. Create GitHub issues for both problems
334-
2. Implement trace flag fix (simple pattern matching)
335-
3. Design runtime tool installation system
336-
4. Consider adding `.claude-tools` config support

README.md

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,56 @@ claude-yolo . # Run in current directory
4747
# Using claude.sh for more control
4848
claude.sh --yolo . # YOLO mode
4949
claude.sh . # Local mode (no Docker)
50-
claude.sh -a . # Use API key
51-
claude.sh -b . # Use AWS Bedrock
50+
claude.sh --auth-with api-key . # Use API key
51+
claude.sh --auth-with bedrock . # Use AWS Bedrock
52+
claude.sh --auth-with vertex . # Use Google Vertex AI
5253
claude.sh --shell # Open shell in container
5354
claude.sh --help # Show all options
5455
```
5556

5657
## Authentication Methods
5758

58-
- **Claude App** (default): Uses `~/.claude` OAuth
59-
- **API Key** (`-a`): Set `ANTHROPIC_API_KEY` environment variable
60-
- **AWS Bedrock** (`-b`): Uses `~/.aws` credentials
61-
- **Google Vertex** (`-v`): Uses `~/.config/gcloud` credentials
59+
- **Claude App** (default): Uses `~/.claude` OAuth - `--auth-with claude`
60+
- **API Key**: Set `ANTHROPIC_API_KEY` environment variable - `--auth-with api-key`
61+
- If OAuth exists, use `/login` in Claude to switch to API key auth
62+
- **AWS Bedrock**: Uses `~/.aws` credentials - `--auth-with bedrock`
63+
- **Google Vertex**: Uses `~/.config/gcloud` credentials - `--auth-with vertex`
64+
65+
## GitHub CLI Authentication
66+
67+
For GitHub operations (creating PRs, managing repos), set the `GH_TOKEN` environment variable:
68+
69+
```bash
70+
# Set your GitHub token
71+
export GH_TOKEN="ghp_xxxxxxxxxxxx"
72+
73+
# Now gh commands work in containers
74+
claude-yolo .
75+
# Inside container: gh pr create, gh issue list, etc.
76+
```
77+
78+
**Note**: This avoids mounting `~/.config/gh/` which fails due to secure keyring storage in modern GitHub CLI versions.
79+
80+
## Custom Volume Mounting
81+
82+
You can mount additional configuration files or directories using the `-v` flag:
83+
84+
```bash
85+
# Mount Git configuration
86+
claude-yolo -v ~/.gitconfig:/root/.gitconfig .
87+
88+
# Mount SSH keys (read-only)
89+
claude-yolo -v ~/.ssh:/root/.ssh:ro .
90+
91+
# Multiple mounts
92+
claude-yolo -v ~/tools:/tools -v ~/data:/data .
93+
94+
# Mount custom tool configs
95+
claude-yolo -v ~/.config/gh:/root/.config/gh .
96+
claude-yolo -v ~/.terraform.d:/root/.terraform.d .
97+
```
98+
99+
**Note**: Volumes mounted to `/root/*` are automatically symlinked to `/home/claude/*` for non-root user access.
62100

63101
## Key Features
64102

@@ -88,3 +126,4 @@ make build
88126
- **[meal/claude-code-cli](https://github.com/meal/claude-code-cli)** - Containerized Claude Code with ready-to-use Docker setup
89127
- **[gagarinyury/claude-code-root-runner](https://github.com/gagarinyury/claude-code-root-runner)** - Root privilege bypass for Claude Code using temporary users
90128
- **[textcortex/claude-code-sandbox](https://github.com/textcortex/claude-code-sandbox)** - Full sandbox environment with web UI and autonomous workflows
129+

0 commit comments

Comments
 (0)