Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/automl/bff/internal/api/s3_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,17 @@ func (app *App) resolveS3Client(w http.ResponseWriter, r *http.Request, secretNa
}
}

// Dev-only: rewrite S3 endpoint to localhost via dynamic port-forward.
// portForwardManager is nil in production (requires DevMode=true).
if app.portForwardManager != nil && creds.EndpointURL != "" {
if rewritten, pfErr := app.portForwardManager.ForwardURL(ctx, creds.EndpointURL); pfErr != nil {
app.logger.Warn("dynamic port-forward failed for S3 endpoint, using original URL",
"error", pfErr, "url", creds.EndpointURL)
} else {
creds.EndpointURL = rewritten
}
}

s3Client, err := app.s3ClientFactory.CreateClient(creds)
if err != nil {
if errors.Is(err, s3int.ErrEndpointValidation) {
Expand Down
11 changes: 11 additions & 0 deletions packages/autorag/bff/internal/api/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,17 @@ func (app *App) AttachLlamaStackClientFromSecret(next func(http.ResponseWriter,
return
}

// Dev-only: rewrite LlamaStack URL to localhost via dynamic port-forward.
// portForwardManager is nil in production (requires DevMode=true).
if app.portForwardManager != nil {
if rewritten, pfErr := app.portForwardManager.ForwardURL(ctx, baseURL); pfErr != nil {
logger.Warn("dynamic port-forward failed for LlamaStack endpoint, using original URL",
"error", pfErr, "url", baseURL)
} else {
baseURL = rewritten
}
}

logger.Debug("Creating LlamaStack client from secret",
"namespace", namespace,
"secretName", secretName,
Expand Down
11 changes: 11 additions & 0 deletions packages/autorag/bff/internal/api/s3_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,17 @@ func (app *App) resolveS3Client(w http.ResponseWriter, r *http.Request, secretNa
// A new AWS S3 client is created on every request. The AWS SDK client
// is designed for reuse (connection pooling, TLS session caching). Consider caching
// clients by credential identity (e.g. namespace/secretName) with a sync.Map or TTL cache.
// Dev-only: rewrite S3 endpoint to localhost via dynamic port-forward.
// portForwardManager is nil in production (requires DevMode=true).
if app.portForwardManager != nil && creds.EndpointURL != "" {
if rewritten, pfErr := app.portForwardManager.ForwardURL(ctx, creds.EndpointURL); pfErr != nil {
app.logger.Warn("dynamic port-forward failed for S3 endpoint, using original URL",
"error", pfErr, "url", creds.EndpointURL)
} else {
creds.EndpointURL = rewritten
}
}

s3Client, err := app.s3ClientFactory.CreateClient(creds)
if err != nil {
if errors.Is(err, s3int.ErrEndpointValidation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ func (c *LlamaStackClient) ListProviders(ctx context.Context) ([]models.LlamaSta
return nil, NewConnectionError(fmt.Sprintf("failed to create request for LlamaStack providers: %s", err.Error()))
}

// Set headers — omit Authorization over plain HTTP to avoid leaking tokens
// Set headers — omit Authorization over plain HTTP to avoid leaking tokens,
// except for localhost (dev-mode port-forwarding tunnels in-cluster traffic locally).
req.Header.Set("Accept", "application/json")
if c.authToken != "" && req.URL.Scheme == "https" {
isLocalhost := req.URL.Hostname() == "localhost" || req.URL.Hostname() == "127.0.0.1"
if c.authToken != "" && (req.URL.Scheme == "https" || isLocalhost) {
req.Header.Set("Authorization", "Bearer "+c.authToken)
}

Expand Down
Loading