Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

feat: first sidecar test run completed

=9079dc329ff3
diff --git a/backend-go/CLAUDE.md b/backend-go/CLAUDE.md
index e9f3541759..0bec7d2090 100644
--- a/backend-go/CLAUDE.md
+++ b/backend-go/CLAUDE.md
@@ -25,6 +25,7 @@ Never edit generated code in `gen/` directories — always regenerate.
- **Interfaces for dependencies**: Consumer defines the interface (narrow, only needed methods). Accept interfaces, not concrete types.
- **DAL boundary**: Services must not import `table`, `postgres`, or `qrm`. All queries go through a DAL. Always use type-safe go-jet — no raw SQL (exception: `pg_advisory_xact_lock`).
- **Database error wrapping**: All `err` values returned from DAL/database calls must be wrapped with `errutil.DatabaseErr("<user-facing message>").WithErr(err)` at the service/caller level, NOT inside DAL methods. This logs the real DB error internally but only shows the safe message to clients.
+- **Error cause context**: When returning `errutil` service errors, always attach origin context via `.WithErr()` using `fmt.Errorf` with the function name and relevant args: `errutil.DatabaseErr("Failed to load resource").WithErr(fmt.Errorf("secretfolder.LoadProjectFolders(project=%s): %w", projectID, err))`. Keep client-facing messages generic — the cause is never exposed to clients, it only appears in server logs alongside the Goa service/method from context.
- **Lean code**: Inline helpers with one caller. Only extract when shared. Split DAL files by functionality.
## Architecture
diff --git a/backend-go/internal/libs/errutil/formatter.go b/backend-go/internal/libs/errutil/formatter.go
index 1bd7f21e88..d2cd8d0660 100644
--- a/backend-go/internal/libs/errutil/formatter.go
+++ b/backend-go/internal/libs/errutil/formatter.go
@@ -38,11 +38,15 @@ func (b *ErrorBody) StatusCode() int {
func NewFormatter(logger *slog.Logger) func(ctx context.Context, err error) goahttp.Statuser {
return func(ctx context.Context, err error) goahttp.Statuser {
reqID := requestid.FromContext(ctx)
+ service, _ := ctx.Value(goa.ServiceKey).(string)
+ method, _ := ctx.Value(goa.MethodKey).(string)
var apiErr *Error
if errors.As(err, &apiErr) {
if apiErr.Status >= http.StatusInternalServerError {
logger.ErrorContext(ctx, "server error",
+ slog.String("service", service),
+ slog.String("method", method),
slog.String("name", apiErr.Name),
slog.Int("status", apiErr.Status),
slog.String("message", apiErr.Message),
@@ -58,6 +62,8 @@ func NewFormatter(logger *slog.Logger) func(ctx context.Context, err error) goah
}
logger.WarnContext(ctx, "api error",
+ slog.String("service", service),
+ slog.String("method", method),
slog.String("name", apiErr.Name),
slog.Int("status", apiErr.Status),
slog.String("message", apiErr.Message),
@@ -77,6 +83,8 @@ func NewFormatter(logger *slog.Logger) func(ctx context.Context, err error) goah
if errors.As(err, &goaErr) {
status := mapGoaErrorStatus(goaErr)
logger.WarnContext(ctx, "goa validation error",
+ slog.String("service", service),
+ slog.String("method", method),
slog.String("name", goaErr.Name),
slog.Int("status", status),
slog.String("message", goaErr.Message),
@@ -90,7 +98,11 @@ func NewFormatter(logger *slog.Logger) func(ctx context.Context, err error) goah
}
}
- logger.ErrorContext(ctx, "unhandled server error", slog.Any("error", err))
+ logger.ErrorContext(ctx, "unhandled server error",
+ slog.String("service", service),
+ slog.String("method", method),
+ slog.Any("error", err),
+ )
return &ErrorBody{
Code: http.StatusInternalServerError,
diff --git a/backend-go/internal/services/auth/auth.go b/backend-go/internal/services/auth/auth.go
index 0f6efe0b3e..47a974cca3 100644
--- a/backend-go/internal/services/auth/auth.go
+++ b/backend-go/internal/services/auth/auth.go
@@ -17,6 +17,23 @@ const (
AuthModeServiceToken AuthMode = "service_token"
)
+// AuthTokenType represents the token type claim embedded in JWTs.
+// Values match the Node.js AuthTokenType enum in auth-type.ts.
+type AuthTokenType string
+
+const (
+ AuthTokenTypeAccessToken AuthTokenType = "accessToken"
+ AuthTokenTypeRefreshToken AuthTokenType = "refreshToken"
+ AuthTokenTypeSignupToken AuthTokenType = "signupToken"
+ AuthTokenTypeMfaToken AuthTokenType = "mfaToken"
+ AuthTokenTypeProviderToken AuthTokenType = "providerToken"
+ AuthTokenTypeAPIKey AuthTokenType = "apiKey"
+ AuthTokenTypeServiceAccessToken AuthTokenType = "serviceAccessToken"
+ AuthTokenTypeServiceRefreshToken AuthTokenType = "serviceRefreshToken"
+ AuthTokenTypeIdentityAccessToken AuthTokenType = "identityAccessToken"
+ AuthTokenTypeSCIMToken AuthTokenType = "scimToken"
+)
+
// UserAuthInfo holds the minimal user info stored in request context for audit logging.
// Port of Node.js requestContext.userAuthInfo.
type UserAuthInfo struct {
diff --git a/backend-go/internal/services/auth/claims.go b/backend-go/internal/services/auth/claims.go
index eebd92274a..f286336c5d 100644
--- a/backend-go/internal/services/auth/claims.go
+++ b/backend-go/internal/services/auth/claims.go
@@ -6,7 +6,7 @@ import "github.com/golang-jwt/jwt/v5"
// Exact match of the Node.js AuthModeJwtTokenPayload.
type UserJWTClaims struct {
jwt.RegisteredClaims
- AuthTokenType string `json:"authTokenType"`
+ AuthTokenType AuthTokenType `json:"authTokenType"`
AuthMethod string `json:"authMethod,omitempty"`
UserID string `json:"userId"`
TokenVersionID string `json:"tokenVersionId"`
@@ -20,7 +20,7 @@ type UserJWTClaims struct {
// Exact match of the Node.js TIdentityAccessTokenJwtPayload.
type IdentityJWTClaims struct {
jwt.RegisteredClaims
- AuthTokenType string `json:"authTokenType"`
+ AuthTokenType AuthTokenType `json:"authTokenType"`
IdentityID string `json:"identityId"`
ClientSecretID string `json:"clientSecretId"`
IdentityAccessTokenID string `json:"identityAccessTokenId"`
diff --git a/backend-go/internal/services/auth/classify.go b/backend-go/internal/services/auth/classify.go
index 265421178a..ffd9bf1d23 100644
--- a/backend-go/internal/services/auth/classify.go
+++ b/backend-go/internal/services/auth/classify.go
@@ -9,7 +9,7 @@ import (
// peekClaims is a minimal struct for peeking at the token type
// without performing signature verification.
type peekClaims struct {
- AuthTokenType string `json:"authTokenType"`
+ AuthTokenType AuthTokenType `json:"authTokenType"`
}
// ClassifyToken determines the AuthMode from a raw token string
@@ -21,9 +21,9 @@ func ClassifyToken(token string) AuthMode {
claims := peekJWTClaims(token)
switch claims.AuthTokenType {
- case "AccessToken":
+ case AuthTokenTypeAccessToken:
return AuthModeJWT
- case "IdentityAccessToken":
+ case AuthTokenTypeIdentityAccessToken:
return AuthModeIdentityAccessToken
}
diff --git a/backend-go/internal/services/auth/classify_test.go b/backend-go/internal/services/auth/classify_test.go
index a964689b50..f283507524 100644
--- a/backend-go/internal/services/auth/classify_test.go
+++ b/backend-go/internal/services/auth/classify_test.go
@@ -23,7 +23,7 @@ func TestClassifyToken(t *testing.T) {
})
t.Run("JWT access token", func(t *testing.T) {
- token := makeJWT(map[string]any{"authTokenType": "AccessToken", "userId": "u1"})
+ token := makeJWT(map[string]any{"authTokenType": string(AuthTokenTypeAccessToken), "userId": "u1"})
mode := ClassifyToken(token)
if mode != AuthModeJWT {
t.Errorf("expected %q, got %q", AuthModeJWT, mode)
@@ -31,7 +31,7 @@ func TestClassifyToken(t *testing.T) {
})
t.Run("identity access token", func(t *testing.T) {
- token := makeJWT(map[string]any{"authTokenType": "IdentityAccessToken", "identityId": "id1"})
+ token := makeJWT(map[string]any{"authTokenType": string(AuthTokenTypeIdentityAccessToken), "identityId": "id1"})
mode := ClassifyToken(token)
if mode != AuthModeIdentityAccessToken {
t.Errorf("expected %q, got %q", AuthModeIdentityAccessToken, mode)
diff --git a/backend-go/internal/services/auth/handler.go b/backend-go/internal/services/auth/handler.go
index 4f143feace..d7586dd990 100644
--- a/backend-go/internal/services/auth/handler.go
+++ b/backend-go/internal/services/auth/handler.go
@@ -2,6 +2,8 @@ package auth
import (
"context"
+ "errors"
+ "fmt"
"strings"
"time"
@@ -26,17 +28,28 @@ func NewAuthHandler(dal *DAL, authSecret string) AuthHandler {
return AuthHandler{dal: dal, authSecret: []byte(authSecret)}
}
+// authFailKey is a context key used to propagate the authoritative auth error
+// across Goa's fallback chain. When the token type matches a scheme but validation
+// fails, we stash the real error so subsequent scheme attempts return it instead
+// of a misleading "not supported" message.
+type authFailKey struct{}
+
// JWTAuth implements the Goa security handler. Goa calls this for each scheme in order
// (jwt → identity_access_token → service_token) with the scheme name in sc.Name.
// We classify the token cheaply and only accept when the token type matches the scheme being tried.
func (h AuthHandler) JWTAuth(ctx context.Context, token string, sc *security.JWTScheme) (context.Context, error) {
+ // If a previous scheme already matched the token and failed, return that error.
+ if prevErr, ok := ctx.Value(authFailKey{}).(error); ok {
+ return ctx, prevErr
+ }
+
if token == "" {
return ctx, errutil.Unauthorized("Token missing")
}
tokenMode := ClassifyToken(token)
if tokenMode == "" {
- return ctx, errutil.Unauthorized("You are not allowed to access this resource")
+ return ctx, errutil.Unauthorized("You are not allowed to access this resource").WithErr(errors.New("Token classification failed"))
}
// Map scheme name to expected auth mode.
@@ -49,12 +62,12 @@ func (h AuthHandler) JWTAuth(ctx context.Context, token string, sc *security.JWT
case "service_token":
expectedMode = AuthModeServiceToken
default:
- return ctx, errutil.Unauthorized("You are not allowed to access this resource")
+ return ctx, errutil.Unauthorized("You are not allowed to access this resource").WithErr(errors.New("Invalid token"))
}
// Fast reject: token type doesn't match the scheme being tried.
if tokenMode != expectedMode {
- return ctx, errutil.Unauthorized("You are not allowed to access this resource")
+ return ctx, errutil.Unauthorized("You are not allowed to access this resource").WithErr(fmt.Errorf("Provider token %v not support", tokenMode))
}
var (
@@ -72,7 +85,11 @@ func (h AuthHandler) JWTAuth(ctx context.Context, token string, sc *security.JWT
case AuthModeServiceToken:
identity, err = h.validateServiceToken(ctx, token)
}
+
if err != nil {
+ // Token matched this scheme but validation failed — this is the authoritative error.
+ // Stash it in context so subsequent scheme attempts return it directly.
+ ctx = context.WithValue(ctx, authFailKey{}, err)
return ctx, err
}
@@ -87,12 +104,13 @@ func (h AuthHandler) validateJWT(ctx context.Context, token string) (*Identity,
_, err := jwt.ParseWithClaims(token, claims, func(_ *jwt.Token) (any, error) {
return h.authSecret, nil
})
+
if err != nil {
- return nil, errutil.Unauthorized("Invalid JWT token")
+ return nil, errutil.Unauthorized("Invalid JWT token").WithErr(err)
}
// 2. Validate authTokenType.
- if claims.AuthTokenType != "AccessToken" {
+ if claims.AuthTokenType != AuthTokenTypeAccessToken {
return nil, errutil.Unauthorized("You are not allowed to access this resource")
}
@@ -221,7 +239,7 @@ func (h AuthHandler) validateIdentityAccessToken(ctx context.Context, token, ipA
}
// 2. Validate authTokenType.
- if claims.AuthTokenType != "IdentityAccessToken" {
+ if claims.AuthTokenType != AuthTokenTypeIdentityAccessToken {
return nil, errutil.Unauthorized("You are not allowed to access this resource")
}
diff --git a/backend/src/server/plugins/go-sidecar-forwarding.ts b/backend/src/server/plugins/go-sidecar-forwarding.ts
index ebb508cfe0..f842cd1c9b 100644
--- a/backend/src/server/plugins/go-sidecar-forwarding.ts
+++ b/backend/src/server/plugins/go-sidecar-forwarding.ts
@@ -2,7 +2,7 @@ import replyFrom from "@fastify/reply-from";
import fp from "fastify-plugin";
// Method + URL combinations to forward to the Go sidecar
-const FORWARDED_ROUTES: { method: string; url: string }[] = [];
+const FORWARDED_ROUTES: { method: string; url: string }[] = [{ method: "GET", url: "/api/v4/secrets" }];
export const forwardToGoSidecar = fp(async (server, opt: { sidecarUrl: string }) => {
await server.register(replyFrom, {
@@ -13,7 +13,9 @@ export const forwardToGoSidecar = fp(async (server, opt: { sidecarUrl: string })
server.addHook("onRequest", async (request, reply) => {
const key = `${request.method}:${request.routeOptions.url}`;
+ console.log(">>> KEY", key);
if (routeSet.has(key)) {
+ console.log("hit");
return reply.from(request.url, {
rewriteRequestHeaders: (_req, headers) => ({
...headers,
diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml
index 0c54d6d4cc..ddb85c57d5 100644
--- a/docker-compose.dev.yml
+++ b/docker-compose.dev.yml
@@ -66,7 +66,7 @@ services:
- "8085:8081"
db-test:
- profiles: [ "test" ]
+ profiles: ["test"]
image: postgres:14-alpine
ports:
- "5430:5432"
@@ -112,7 +112,7 @@ services:
- "9090:9090"
command:
- "--config.file=/etc/prometheus/prometheus.yml"
- profiles: [ metrics ]
+ profiles: [metrics]
otel-collector:
image: otel/opentelemetry-collector-contrib
@@ -126,7 +126,7 @@ services:
- 4317:4317 # OTLP gRPC receiver
- 4318:4318 # OTLP http receiver
- 55679:55679 # zpages extension
- profiles: [ metrics-otel ]
+ profiles: [metrics-otel]
grafana:
image: grafana/grafana
@@ -138,7 +138,7 @@ services:
- "3005:3000"
volumes:
- "grafana_storage:/var/lib/grafana"
- profiles: [ metrics ]
+ profiles: [metrics]
frontend:
container_name: infisical-dev-frontend
@@ -170,9 +170,9 @@ services:
environment:
- DB_CONNECTION_URI=postgres://infisical:infisical@db/infisical?sslmode=disable
- REDIS_URL=redis://redis:6379
- - ENCRYPTION_KEY=a984ecdf82ec779e55dbcc21303a900f
- - AUTH_SECRET=test-auth-secret-long-enough-for-jwt
- profiles: [ go ]
+ env_file:
+ - .env
+ profiles: [go]
pgadmin:
image: dpage/pgadmin4
@@ -211,7 +211,7 @@ services:
volumes:
- ldap_data:/var/lib/ldap
- ldap_config:/etc/ldap/slapd.d
- profiles: [ ldap ]
+ profiles: [ldap]
phpldapadmin:
# username: cn=admin,dc=acme,dc=com, pass is admin
@@ -224,7 +224,7 @@ services:
- 6433:80
depends_on:
- openldap
- profiles: [ ldap ]
+ profiles: [ldap]
keycloak:
image: quay.io/keycloak/keycloak:26.1.0
@@ -235,7 +235,7 @@ services:
command: start-dev
ports:
- 8088:8080
- profiles: [ sso ]
+ profiles: [sso]
volumes:
postgres-data: