Skip to content

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

feat: resolved replication import failure

=6330a27580ab
diff --git a/backend-go/internal/server/api/secretmanager/secret/list_secrets.go b/backend-go/internal/server/api/secretmanager/secret/list_secrets.go
index 2ff6f0e983..eb5d8f8190 100644
--- a/backend-go/internal/server/api/secretmanager/secret/list_secrets.go
+++ b/backend-go/internal/server/api/secretmanager/secret/list_secrets.go
@@ -427,6 +427,8 @@ func (h *Handler) buildImportSecretRaw(ps *secretsvc.ProcessedSecret, projectID
}
// buildImportsResponse builds the imports array for the API response.
+// Only direct imports (depth=0) are returned as entries. Secrets from nested
+// imports (depth>0) are merged into their parent direct import's secrets array.
func (h *Handler) buildImportsResponse(
result *secretsvc.ListSecretsResult,
projectID string,
@@ -438,25 +440,33 @@ func (h *Handler) buildImportsResponse(
secretsByImport[key] = append(secretsByImport[key], *sec)
}
- imports := make([]SecretImport, 0, len(result.Imports))
+ imports := make([]SecretImport, 0)
+ var currentImport *SecretImport
+
for i := range result.Imports {
imp := &result.Imports[i]
envSlug, _ := result.FolderLookup.GetEnvSlug(imp.EnvID)
key := envSlug + ":" + imp.Path
impSecrets := secretsByImport[key]
- importSecrets := make([]ImportSecretRaw, 0, len(impSecrets))
- for j := range impSecrets {
- importSecrets = append(importSecrets, h.buildImportSecretRaw(&impSecrets[j], projectID))
+ if imp.Depth == 0 {
+ // Direct import: create a new entry
+ folderID := imp.FolderID.String()
+ imports = append(imports, SecretImport{
+ SecretPath: imp.Path,
+ Environment: envSlug,
+ FolderID: &folderID,
+ Secrets: make([]ImportSecretRaw, 0, len(impSecrets)),
+ })
+ currentImport = &imports[len(imports)-1]
}
- folderID := imp.FolderID.String()
- imports = append(imports, SecretImport{
- SecretPath: imp.Path,
- Environment: envSlug,
- FolderID: &folderID,
- Secrets: importSecrets,
- })
+ // Add secrets to the current direct import (whether this is depth=0 or nested)
+ if currentImport != nil {
+ for j := range impSecrets {
+ currentImport.Secrets = append(currentImport.Secrets, h.buildImportSecretRaw(&impSecrets[j], projectID))
+ }
+ }
}
return imports
diff --git a/backend-go/internal/services/secretmanager/secretimport/lookup.go b/backend-go/internal/services/secretmanager/secretimport/lookup.go
index fcead540cd..b2c43c9568 100644
--- a/backend-go/internal/services/secretmanager/secretimport/lookup.go
+++ b/backend-go/internal/services/secretmanager/secretimport/lookup.go
@@ -2,11 +2,15 @@ package secretimport
import (
"bytes"
+ "regexp"
"sort"
"github.com/google/uuid"
)
+// reservedReplicationRegex matches /__reserve_replication_<uuid> anywhere in a path.
+var reservedReplicationRegex = regexp.MustCompile(`/__reserve_replication_([a-f0-9-]{36})`)
+
const (
flagReplication = 1 << 0
flagReserved = 1 << 1
@@ -221,6 +225,36 @@ func (l *ImportLookup) ImportersOf(envID uuid.UUID, path string) []int32 {
return l.byTarget[importTarget{envID: envID, path: path}]
}
+// ResolveReserved resolves a reserved replication import to its original source.
+// If the import at index i is reserved (path matches /__reserve_replication_<uuid>),
+// it extracts the UUID, looks up the original import by ID, and returns that import's
+// envID and path. Otherwise returns the import's own envID and path unchanged.
+func (l *ImportLookup) ResolveReserved(i int32) (envID uuid.UUID, path string) {
+ envID = l.TargetEnvID(i)
+ path = l.TargetPath(i)
+
+ if !l.IsReserved(i) {
+ return envID, path
+ }
+
+ match := reservedReplicationRegex.FindStringSubmatch(path)
+ if match == nil {
+ return envID, path
+ }
+
+ originalID, err := uuid.Parse(match[1])
+ if err != nil {
+ return envID, path
+ }
+
+ originalIdx, found := l.IndexByID(originalID)
+ if !found {
+ return envID, path
+ }
+
+ return l.TargetEnvID(originalIdx), l.TargetPath(originalIdx)
+}
+
const maxImportDepth = 10
// ResolvedImport represents a folder in the import chain.
@@ -258,8 +292,10 @@ func (l *ImportLookup) ResolveChain(
continue
}
- envID := l.TargetEnvID(i)
- path := l.TargetPath(i)
+ // For reserved imports, resolve back to the original source's env/path.
+ // This ensures permission checks and API responses use the original
+ // location (e.g. "/") rather than the reserved folder path.
+ envID, path := l.ResolveReserved(i)
key := importTarget{envID: envID, path: path}
if visited[key] {
continue