-
Notifications
You must be signed in to change notification settings - Fork 6
Feature: infisical proxy #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Added `proxy.go` to handle proxy server commands, including starting the server and printing cache debug information. - Introduced a caching mechanism in `cache.go` to store and manage HTTP responses, supporting token-based cache invalidation. - Implemented resync logic to refresh cached entries based on expiration. - Added command-line flags for configuring the proxy server's domain, listen address, resync interval, and cache TTL. - Included a debug endpoint for development mode to retrieve cache information.
- Removed the `startResyncLoop` function from `proxy.go` and moved it to a new `resync.go` file for better organization. - Enhanced the caching system in `cache.go` to include a compound path index for improved cache entry management and eviction after mutation calls. - Introduced a new method to handle resync responses, including rate limit handling and entry eviction based on HTTP status codes. - Updated the proxy server to utilize a streaming client for long-lived connections and improved logging for cache hits and misses. - Added functionality to purge cache entries based on mutation paths across all tokens.
- Updated the `compoundPathIndex` comment in `cache.go` to clarify its purpose for purging after mutation calls. - Changed the locking mechanism in `GetFirstRequestForToken` to use a write lock for thread safety. - Enhanced the `EvictAllEntriesForToken` and `RemoveTokenFromIndex` methods to delete entries from the `compoundPathIndex` when a token is evicted. - Improved response handling in `handleResyncResponse` by ensuring the response body is closed properly in all cases to prevent resource leaks.
Greptile OverviewGreptile SummaryThis PR introduces a new proxy server feature for Infisical CLI that caches secret API responses with intelligent invalidation and background resync capabilities. Key changes:
Critical security issues found:
Missing documentation: No documentation found in Confidence Score: 1/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant Client
participant Proxy as Infisical Proxy
participant Cache
participant API as Infisical API
participant ResyncLoop as Background Resync
Note over Proxy: Server starts with cache-ttl and resync-interval configs
rect rgb(200, 220, 240)
Note over Client,API: GET Request Flow (Cacheable)
Client->>Proxy: GET /api/v3/secrets?projectId=x&environment=prod<br/>(Bearer token in header)
Proxy->>Cache: Check cache with hash(method+path+query+token)
alt Cache Hit
Cache-->>Proxy: Return cached response
Proxy-->>Client: 200 OK (from cache)
else Cache Miss
Proxy->>API: Forward GET request to domain
API-->>Proxy: 200 OK + secrets data
Proxy->>Cache: Store response with IndexEntry<br/>(projectId, environment, secretPath)
Proxy-->>Client: 200 OK + secrets data
end
end
rect rgb(240, 220, 200)
Note over Client,API: PATCH/DELETE Request Flow (Mutation)
Client->>Proxy: PATCH /api/v3/secrets<br/>(body: projectId, environment, secretPath)
Proxy->>API: Forward mutation request
API-->>Proxy: 200 OK
Proxy->>Cache: PurgeByMutation(projectId, environment, secretPath)<br/>across ALL tokens
Note over Cache: Invalidates matching entries<br/>for all users/tokens
Proxy-->>Client: 200 OK
end
rect rgb(220, 240, 220)
Note over ResyncLoop,API: Background Resync Loop (every resync-interval minutes)
loop Every resync-interval
ResyncLoop->>Cache: GetAllTokens()
Cache-->>ResyncLoop: List of tokens
loop For each token
ResyncLoop->>Cache: GetFirstRequestForToken(token)
Cache-->>ResyncLoop: Sample request for token validation
ResyncLoop->>API: Test request with token
alt 401 Unauthorized
API-->>ResyncLoop: 401
ResyncLoop->>Cache: EvictAllEntriesForToken(token)
Note over Cache: All entries for expired token removed
else Valid token
API-->>ResyncLoop: Success
end
end
ResyncLoop->>Cache: GetExpiredRequests(cacheTTL)
Cache-->>ResyncLoop: Entries older than cache-ttl
loop For each expired entry (sorted by age)
ResyncLoop->>API: Refetch with original request params
alt 200 OK
API-->>ResyncLoop: Fresh data
ResyncLoop->>Cache: UpdateResponse(new data, reset timestamp)
else 401/403/404
API-->>ResyncLoop: Auth/Not Found error
ResyncLoop->>Cache: EvictEntry(cacheKey)
else 429 Rate Limited
API-->>ResyncLoop: Rate limit (retry-after: N seconds)
ResyncLoop->>ResyncLoop: Sleep N+2 seconds, then continue
else Other errors
Note over ResyncLoop,Cache: Keep stale entry for availability
end
end
end
end
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3 files reviewed, 6 comments
…y server - Enhanced the `startProxyServer` function in `proxy.go` to log errors when parsing mutation request bodies fails, ensuring better visibility into potential cache issues.
Description 📣
We are introducing the new proxy command to the CLI.
You can use it like this:
infisical proxy start --domain=http://localhost:8080 --resync-interval=2 --cache-ttl=1 --listen-address=localhost:8081Here's a quick demonstration
Screenshare.-.2025-11-14.11_16_51.AM.mp4
And a more in-depth documentation can be found here: https://www.notion.so/infisical/Infisical-Proxy-2a9564692229808db6bdd30b73ed041a
Type ✨
Tests 🛠️
If you're running the CLI locally, you can use the debug command to get a snapshot of your in-memory cache:
go run main.go proxy debug --listen-address=localhost:8081Also, run the proxy start command with the
--log-level=debugflag for better observability in the tests.Tests:
Testing rate-limiting:
Remove this if statement in the
backend/src/server/app.tsfile: