Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
feat: refactored authenticator to seperate module
=ee1427094731
diff --git a/backend-go/internal/server/api/platform/projects/projects.go b/backend-go/internal/server/api/platform/projects/projects.goindex 9dd9d6121c..0370c19443 100644--- a/backend-go/internal/server/api/platform/projects/projects.go+++ b/backend-go/internal/server/api/platform/projects/projects.go@@ -4,9 +4,8 @@ import ("context""log/slog"- "github.com/infisical/api/internal/services/auth"-genprojects "github.com/infisical/api/internal/server/gen/projects"+ "github.com/infisical/api/internal/services/auth/apiauth""github.com/infisical/api/internal/services/permission")@@ -15,14 +14,14 @@ type permissionGetter interface {}type service struct {- auth.Authenticator+ apiauth.Authenticatorlogger *slog.Loggerpermission permissionGetter}// Deps holds the dependencies for the projects service.type Deps struct {- Authenticator auth.Authenticator+ Authenticator apiauth.AuthenticatorPermission permissionGetter}diff --git a/backend-go/internal/server/api/platform/projects/projects_integration_test.go b/backend-go/internal/server/api/platform/projects/projects_integration_test.goindex d1853707a9..ab2fdeab5f 100644--- a/backend-go/internal/server/api/platform/projects/projects_integration_test.go+++ b/backend-go/internal/server/api/platform/projects/projects_integration_test.go@@ -13,7 +13,7 @@ import ("github.com/infisical/api/internal/server/api/platform/projects"projectssvr "github.com/infisical/api/internal/server/gen/http/projects/server"genprojects "github.com/infisical/api/internal/server/gen/projects"- "github.com/infisical/api/internal/services/auth"+ "github.com/infisical/api/internal/services/auth/apiauth""github.com/infisical/api/internal/services/permission""github.com/infisical/api/internal/testutil""github.com/infisical/api/internal/testutil/infra"@@ -39,7 +39,7 @@ func setupMux(t *testing.T) *testutil.TestMux {permLib := permission.NewService(testutil.NopLogger(), &permission.Deps{DB: stack.DB()})- authenticator := auth.NewAuthenticator(stack.DB(), infra.AuthSecret, keystore.NewMemoryKeyStore())+ authenticator := apiauth.NewAuthenticator(stack.DB(), infra.AuthSecret, keystore.NewMemoryKeyStore())svc := projects.NewService(testutil.NopLogger(), projects.Deps{Authenticator: authenticator,diff --git a/backend-go/internal/server/api/platform_services.go b/backend-go/internal/server/api/platform_services.goindex addda14897..aaf4b1b63c 100644--- a/backend-go/internal/server/api/platform_services.go+++ b/backend-go/internal/server/api/platform_services.go@@ -5,7 +5,7 @@ import ("fmt""github.com/infisical/api/internal/services/auditlog"- "github.com/infisical/api/internal/services/auth"+ "github.com/infisical/api/internal/services/auth/apiauth""github.com/infisical/api/internal/services/kms""github.com/infisical/api/internal/services/license""github.com/infisical/api/internal/services/permission"@@ -13,7 +13,7 @@ import ()type platformServices struct {- authenticator auth.Authenticator+ authenticator apiauth.Authenticatorpermission *permission.Servicekms *kms.Servicelicense *license.Service@@ -42,7 +42,7 @@ func newPlatformServices(ctx context.Context, infra *Infra) (*platformServices,KeyStore: infra.KeyStore,})- authenticator := auth.NewAuthenticator(infra.DB, infra.Config.AuthSecret, infra.KeyStore)+ authenticator := apiauth.NewAuthenticator(infra.DB, infra.Config.AuthSecret, infra.KeyStore)permissionSvc := permission.NewService(infra.Logger, &permission.Deps{DB: infra.DB})diff --git a/backend-go/internal/server/api/secretmanager/secret/secret.go b/backend-go/internal/server/api/secretmanager/secret/secret.goindex 229452a6e2..ea22cde0e6 100644--- a/backend-go/internal/server/api/secretmanager/secret/secret.go+++ b/backend-go/internal/server/api/secretmanager/secret/secret.go@@ -10,6 +10,7 @@ import (gensecrets "github.com/infisical/api/internal/server/gen/secrets""github.com/infisical/api/internal/services/auditlog""github.com/infisical/api/internal/services/auth"+ "github.com/infisical/api/internal/services/auth/apiauth""github.com/infisical/api/internal/services/permission"secretsvc "github.com/infisical/api/internal/services/secretmanager/secret")@@ -41,7 +42,7 @@ type SecretsService interface {// Handler implements the Goa secrets service interface.type Handler struct {- auth.Authenticator+ apiauth.Authenticatorlogger *slog.Loggerpermission PermissionServiceproject ProjectService@@ -52,7 +53,7 @@ type Handler struct {// Deps holds the dependencies for the secrets handler.type Deps struct {Logger *slog.Logger- Authenticator auth.Authenticator+ Authenticator apiauth.AuthenticatorPermission PermissionServiceProject ProjectServiceAuditLog AuditLogService@@ -267,7 +268,7 @@ func (h *Handler) buildImportsResponse(// getUserID extracts user ID from identity if actor is a user.func getUserID(identity *auth.Identity) *uuid.UUID {- if identity.Actor == permission.ActorTypeUser {+ if identity.Actor == auth.ActorTypeUser {return &identity.ActorID}return nil@@ -279,7 +280,7 @@ func getSecretType(identity *auth.Identity, requestedType string) string {return "shared"}switch identity.Actor {- case permission.ActorTypeIdentity, permission.ActorTypeService:+ case auth.ActorTypeIdentity, auth.ActorTypeService:return "shared"default:return requestedTypediff --git a/backend-go/internal/server/api/secretmanager/secret/secrets_integration_test.go b/backend-go/internal/server/api/secretmanager/secret/secrets_integration_test.goindex d38e55dbad..d46513bc46 100644--- a/backend-go/internal/server/api/secretmanager/secret/secrets_integration_test.go+++ b/backend-go/internal/server/api/secretmanager/secret/secrets_integration_test.go@@ -17,6 +17,7 @@ import (gensecrets "github.com/infisical/api/internal/server/gen/secrets""github.com/infisical/api/internal/services/auditlog""github.com/infisical/api/internal/services/auth"+ "github.com/infisical/api/internal/services/auth/apiauth""github.com/infisical/api/internal/services/kms""github.com/infisical/api/internal/services/permission""github.com/infisical/api/internal/services/project"@@ -52,7 +53,7 @@ func newSecretsHandler(t *testing.T) gensecrets.Service {permSvc := permission.NewService(testutil.NopLogger(), &permission.Deps{DB: stack.DB()})- authenticator := auth.NewAuthenticator(stack.DB(), infra.AuthSecret, keystore.NewMemoryKeyStore())+ authenticator := apiauth.NewAuthenticator(stack.DB(), infra.AuthSecret, keystore.NewMemoryKeyStore())redisClient := stack.Redis().Client()t.Cleanup(func() { redisClient.Close() })@@ -99,7 +100,7 @@ func listSecretsAsAdmin(t *testing.T, identityID, orgID string, payload *gensecrctx := auth.WithIdentity(context.Background(), &auth.Identity{AuthMode: auth.AuthModeIdentityAccessToken,- Actor: permission.ActorTypeIdentity,+ Actor: auth.ActorTypeIdentity,ActorID: uuid.MustParse(identityID),OrgID: uuid.MustParse(orgID),AuthMethod: "",@@ -803,7 +804,7 @@ func TestListSecretsV4_PersonalOverrides_NeverInclude(t *testing.T) {svc := newSecretsHandler(t)ctx := auth.WithIdentity(context.Background(), &auth.Identity{AuthMode: auth.AuthModeJWT,- Actor: permission.ActorTypeUser,+ Actor: auth.ActorTypeUser,ActorID: uuid.MustParse(nodejs.UserID()),OrgID: uuid.MustParse(nodejs.OrgID()),AuthMethod: "",@@ -841,7 +842,7 @@ func TestListSecretsV4_PersonalOverrides_Priority(t *testing.T) {svc := newSecretsHandler(t)ctx := auth.WithIdentity(context.Background(), &auth.Identity{AuthMode: auth.AuthModeJWT,- Actor: permission.ActorTypeUser,+ Actor: auth.ActorTypeUser,ActorID: uuid.MustParse(nodejs.UserID()),OrgID: uuid.MustParse(nodejs.OrgID()),AuthMethod: "",@@ -1509,7 +1510,7 @@ func TestListSecrets_Comprehensive(t *testing.T) {svc := newSecretsHandler(t)ctx := auth.WithIdentity(context.Background(), &auth.Identity{AuthMode: auth.AuthModeJWT,- Actor: permission.ActorTypeUser,+ Actor: auth.ActorTypeUser,ActorID: uuid.MustParse(nodejs.UserID()),OrgID: uuid.MustParse(nodejs.OrgID()),AuthMethod: "",@@ -1537,7 +1538,7 @@ func TestListSecrets_Comprehensive(t *testing.T) {svc := newSecretsHandler(t)ctx := auth.WithIdentity(context.Background(), &auth.Identity{AuthMode: auth.AuthModeJWT,- Actor: permission.ActorTypeUser,+ Actor: auth.ActorTypeUser,ActorID: uuid.MustParse(nodejs.UserID()),OrgID: uuid.MustParse(nodejs.OrgID()),AuthMethod: "",@@ -1563,7 +1564,7 @@ func TestListSecrets_Comprehensive(t *testing.T) {svc := newSecretsHandler(t)ctx := auth.WithIdentity(context.Background(), &auth.Identity{AuthMode: auth.AuthModeJWT,- Actor: permission.ActorTypeUser,+ Actor: auth.ActorTypeUser,ActorID: uuid.MustParse(nodejs.UserID()),OrgID: uuid.MustParse(nodejs.OrgID()),AuthMethod: "",@@ -1589,7 +1590,7 @@ func TestListSecrets_Comprehensive(t *testing.T) {svc := newSecretsHandler(t)ctx := auth.WithIdentity(context.Background(), &auth.Identity{AuthMode: auth.AuthModeJWT,- Actor: permission.ActorTypeUser,+ Actor: auth.ActorTypeUser,ActorID: uuid.MustParse(nodejs.UserID()),OrgID: uuid.MustParse(nodejs.OrgID()),AuthMethod: "",@@ -1613,7 +1614,7 @@ func TestListSecrets_Comprehensive(t *testing.T) {svc := newSecretsHandler(t)ctx := auth.WithIdentity(context.Background(), &auth.Identity{AuthMode: auth.AuthModeIdentityAccessToken,- Actor: permission.ActorTypeIdentity,+ Actor: auth.ActorTypeIdentity,ActorID: uuid.MustParse(identity.ID),OrgID: uuid.MustParse(nodejs.OrgID()),AuthMethod: "",@@ -1635,7 +1636,7 @@ func TestListSecrets_Comprehensive(t *testing.T) {svc := newSecretsHandler(t)ctx := auth.WithIdentity(context.Background(), &auth.Identity{AuthMode: auth.AuthModeIdentityAccessToken,- Actor: permission.ActorTypeIdentity,+ Actor: auth.ActorTypeIdentity,ActorID: uuid.MustParse(identity.ID),OrgID: uuid.MustParse(nodejs.OrgID()),AuthMethod: "",@@ -1658,7 +1659,7 @@ func TestListSecrets_Comprehensive(t *testing.T) {svc := newSecretsHandler(t)ctx := auth.WithIdentity(context.Background(), &auth.Identity{AuthMode: auth.AuthModeIdentityAccessToken,- Actor: permission.ActorTypeIdentity,+ Actor: auth.ActorTypeIdentity,ActorID: uuid.MustParse(identity.ID),OrgID: uuid.MustParse(nodejs.OrgID()),AuthMethod: "",@@ -1681,7 +1682,7 @@ func TestListSecrets_Comprehensive(t *testing.T) {svc := newSecretsHandler(t)ctx := auth.WithIdentity(context.Background(), &auth.Identity{AuthMode: auth.AuthModeIdentityAccessToken,- Actor: permission.ActorTypeIdentity,+ Actor: auth.ActorTypeIdentity,ActorID: uuid.MustParse(identity.ID),OrgID: uuid.MustParse(nodejs.OrgID()),AuthMethod: "",@@ -1702,7 +1703,7 @@ func TestListSecrets_Comprehensive(t *testing.T) {svc := newSecretsHandler(t)ctx := auth.WithIdentity(context.Background(), &auth.Identity{AuthMode: auth.AuthModeIdentityAccessToken,- Actor: permission.ActorTypeIdentity,+ Actor: auth.ActorTypeIdentity,ActorID: uuid.MustParse(identity.ID),OrgID: uuid.MustParse(nodejs.OrgID()),AuthMethod: "",@@ -1737,7 +1738,7 @@ func TestListSecrets_Comprehensive(t *testing.T) {svc := newSecretsHandler(t)ctx := auth.WithIdentity(context.Background(), &auth.Identity{AuthMode: auth.AuthModeJWT,- Actor: permission.ActorTypeUser,+ Actor: auth.ActorTypeUser,ActorID: uuid.MustParse(nodejs.UserID()),OrgID: uuid.MustParse(nodejs.OrgID()),AuthMethod: "",@@ -1777,7 +1778,7 @@ func TestGetSecretByName_ExpandsSameFolderRefsWithoutImports(t *testing.T) {svc := newSecretsHandler(t)ctx := auth.WithIdentity(context.Background(), &auth.Identity{AuthMode: auth.AuthModeIdentityAccessToken,- Actor: permission.ActorTypeIdentity,+ Actor: auth.ActorTypeIdentity,ActorID: uuid.MustParse(identity.ID),OrgID: uuid.MustParse(nodejs.OrgID()),AuthMethod: "",@@ -1817,7 +1818,7 @@ func TestGetSecretByName_ExpandsNestedRefsWithoutImports(t *testing.T) {svc := newSecretsHandler(t)ctx := auth.WithIdentity(context.Background(), &auth.Identity{AuthMode: auth.AuthModeIdentityAccessToken,- Actor: permission.ActorTypeIdentity,+ Actor: auth.ActorTypeIdentity,ActorID: uuid.MustParse(identity.ID),OrgID: uuid.MustParse(nodejs.OrgID()),AuthMethod: "",diff --git a/backend-go/internal/server/api/secretmanager/secret/secrets_permission_integration_test.go b/backend-go/internal/server/api/secretmanager/secret/secrets_permission_integration_test.goindex eba18f4502..76298ecf3c 100644--- a/backend-go/internal/server/api/secretmanager/secret/secrets_permission_integration_test.go+++ b/backend-go/internal/server/api/secretmanager/secret/secrets_permission_integration_test.go@@ -13,12 +13,11 @@ import (gensecrets "github.com/infisical/api/internal/server/gen/secrets""github.com/infisical/api/internal/services/auth"- "github.com/infisical/api/internal/services/permission""github.com/infisical/api/internal/testutil/infra")// listSecrets is a helper that calls ListSecretsV4 with the given identity context.-func listSecrets(t *testing.T, actorType permission.ActorType, actorID, orgID string, payload *gensecrets.ListSecretsV4Payload) (*gensecrets.ListSecretsResult, error) {+func listSecrets(t *testing.T, actorType auth.ActorType, actorID, orgID string, payload *gensecrets.ListSecretsV4Payload) (*gensecrets.ListSecretsResult, error) {t.Helper()ctx := auth.WithIdentity(context.Background(), &auth.Identity{@@ -34,7 +33,7 @@ func listSecrets(t *testing.T, actorType permission.ActorType, actorID, orgID st}// getSecretByName is a helper that calls GetSecretByNameV4 with the given identity context.-func getSecretByName(t *testing.T, actorType permission.ActorType, actorID, orgID string, payload *gensecrets.GetSecretByNameV4Payload) (*gensecrets.GetSecretResult, error) {+func getSecretByName(t *testing.T, actorType auth.ActorType, actorID, orgID string, payload *gensecrets.GetSecretByNameV4Payload) (*gensecrets.GetSecretResult, error) {t.Helper()ctx := auth.WithIdentity(context.Background(), &auth.Identity{@@ -63,7 +62,7 @@ func TestIdentityAdmin_CanReadAllSecrets(t *testing.T) {identity := nodejs.CreateIdentity(t, "admin-secrets-identity")nodejs.AddIdentityToProject(t, proj.ID, identity.ID, infra.Role("admin"))- result, err := listSecrets(t, permission.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{+ result, err := listSecrets(t, auth.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{ProjectID: proj.ID,Environment: proj.EnvSlug,SecretPath: "/",@@ -88,7 +87,7 @@ func TestIdentityMember_CanReadAllSecrets(t *testing.T) {identity := nodejs.CreateIdentity(t, "member-secrets-identity")nodejs.AddIdentityToProject(t, proj.ID, identity.ID, infra.Role("member"))- result, err := listSecrets(t, permission.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{+ result, err := listSecrets(t, auth.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{ProjectID: proj.ID,Environment: proj.EnvSlug,SecretPath: "/",@@ -111,7 +110,7 @@ func TestIdentityViewer_CanReadSecrets(t *testing.T) {identity := nodejs.CreateIdentity(t, "viewer-secrets-identity")nodejs.AddIdentityToProject(t, proj.ID, identity.ID, infra.Role("viewer"))- result, err := listSecrets(t, permission.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{+ result, err := listSecrets(t, auth.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{ProjectID: proj.ID,Environment: proj.EnvSlug,SecretPath: "/",@@ -135,7 +134,7 @@ func TestIdentityNoAccess_EmptyResult(t *testing.T) {identity := nodejs.CreateIdentity(t, "noaccess-secrets-identity")nodejs.AddIdentityToProject(t, proj.ID, identity.ID, infra.Role("no-access"))- result, err := listSecrets(t, permission.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{+ result, err := listSecrets(t, auth.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{ProjectID: proj.ID,Environment: proj.EnvSlug,SecretPath: "/",@@ -155,7 +154,7 @@ func TestIdentityNotMember_Forbidden(t *testing.T) {// Create identity but do NOT add to projectidentity := nodejs.CreateIdentity(t, "outsider-secrets-identity")- _, err := listSecrets(t, permission.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{+ _, err := listSecrets(t, auth.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{ProjectID: proj.ID,Environment: proj.EnvSlug,SecretPath: "/",@@ -179,7 +178,7 @@ func TestUserAdmin_CanReadSecrets(t *testing.T) {user := nodejs.InviteAndCreateUser(t, "[email protected]")nodejs.AddUserToProject(t, proj.ID, user.Email, []string{"admin"})- result, err := listSecrets(t, permission.ActorTypeUser, user.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{+ result, err := listSecrets(t, auth.ActorTypeUser, user.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{ProjectID: proj.ID,Environment: proj.EnvSlug,SecretPath: "/",@@ -200,7 +199,7 @@ func TestUserViewer_CanReadSecrets(t *testing.T) {user := nodejs.InviteAndCreateUser(t, "[email protected]")nodejs.AddUserToProject(t, proj.ID, user.Email, []string{"viewer"})- result, err := listSecrets(t, permission.ActorTypeUser, user.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{+ result, err := listSecrets(t, auth.ActorTypeUser, user.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{ProjectID: proj.ID,Environment: proj.EnvSlug,SecretPath: "/",@@ -241,7 +240,7 @@ func TestIdentityCustomRole_EnvironmentScoped(t *testing.T) {nodejs.AddIdentityToProject(t, proj.ID, identity.ID, infra.Role(customRole.Slug))// Should see dev secrets- devResult, err := listSecrets(t, permission.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{+ devResult, err := listSecrets(t, auth.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{ProjectID: proj.ID,Environment: "dev",SecretPath: "/",@@ -252,7 +251,7 @@ func TestIdentityCustomRole_EnvironmentScoped(t *testing.T) {assert.Equal(t, "DEV_SECRET", devResult.Secrets[0].SecretKey)// Should NOT see staging secrets- stagingResult, err := listSecrets(t, permission.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{+ stagingResult, err := listSecrets(t, auth.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{ProjectID: proj.ID,Environment: "staging",SecretPath: "/",@@ -291,7 +290,7 @@ func TestIdentityCustomRole_PathScoped(t *testing.T) {nodejs.AddIdentityToProject(t, proj.ID, identity.ID, infra.Role(customRole.Slug))// Should see secrets under /app- appResult, err := listSecrets(t, permission.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{+ appResult, err := listSecrets(t, auth.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{ProjectID: proj.ID,Environment: proj.EnvSlug,SecretPath: "/app",@@ -302,7 +301,7 @@ func TestIdentityCustomRole_PathScoped(t *testing.T) {assert.Equal(t, "APP_SECRET", appResult.Secrets[0].SecretKey)// Should see secrets under /app/config- configResult, err := listSecrets(t, permission.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{+ configResult, err := listSecrets(t, auth.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{ProjectID: proj.ID,Environment: proj.EnvSlug,SecretPath: "/app/config",@@ -313,7 +312,7 @@ func TestIdentityCustomRole_PathScoped(t *testing.T) {assert.Equal(t, "CONFIG_SECRET", configResult.Secrets[0].SecretKey)// Should NOT see secrets under /other- otherResult, err := listSecrets(t, permission.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{+ otherResult, err := listSecrets(t, auth.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{ProjectID: proj.ID,Environment: proj.EnvSlug,SecretPath: "/other",@@ -338,7 +337,7 @@ func TestGroupAdmin_UserInheritsAccess(t *testing.T) {nodejs.AddUserToGroup(t, group.ID, user.Email)nodejs.AddGroupToProject(t, proj.ID, group.ID, "admin")- result, err := listSecrets(t, permission.ActorTypeUser, user.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{+ result, err := listSecrets(t, auth.ActorTypeUser, user.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{ProjectID: proj.ID,Environment: proj.EnvSlug,SecretPath: "/",@@ -362,7 +361,7 @@ func TestGroupViewer_UserInheritsReadAccess(t *testing.T) {nodejs.AddUserToGroup(t, group.ID, user.Email)nodejs.AddGroupToProject(t, proj.ID, group.ID, "viewer")- result, err := listSecrets(t, permission.ActorTypeUser, user.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{+ result, err := listSecrets(t, auth.ActorTypeUser, user.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{ProjectID: proj.ID,Environment: proj.EnvSlug,SecretPath: "/",@@ -401,7 +400,7 @@ func TestGroupCustomRole_UserInheritsCustomPermissions(t *testing.T) {nodejs.AddGroupToProject(t, proj.ID, group.ID, customRole.Slug)// Should see dev secrets via group's custom role- devResult, err := listSecrets(t, permission.ActorTypeUser, user.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{+ devResult, err := listSecrets(t, auth.ActorTypeUser, user.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{ProjectID: proj.ID,Environment: "dev",SecretPath: "/",@@ -412,7 +411,7 @@ func TestGroupCustomRole_UserInheritsCustomPermissions(t *testing.T) {assert.Equal(t, "DEV_SECRET", devResult.Secrets[0].SecretKey)// Should NOT see staging secrets- stagingResult, err := listSecrets(t, permission.ActorTypeUser, user.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{+ stagingResult, err := listSecrets(t, auth.ActorTypeUser, user.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{ProjectID: proj.ID,Environment: "staging",SecretPath: "/",@@ -448,7 +447,7 @@ func TestIdentityAdditionalPrivilege_ExtendsRole(t *testing.T) {}, nil)// Should see dev secrets via additional privilege- devResult, err := listSecrets(t, permission.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{+ devResult, err := listSecrets(t, auth.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{ProjectID: proj.ID,Environment: "dev",SecretPath: "/",@@ -459,7 +458,7 @@ func TestIdentityAdditionalPrivilege_ExtendsRole(t *testing.T) {assert.Equal(t, "DEV_SECRET", devResult.Secrets[0].SecretKey)// Should NOT see staging secrets- stagingResult, err := listSecrets(t, permission.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{+ stagingResult, err := listSecrets(t, auth.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{ProjectID: proj.ID,Environment: "staging",SecretPath: "/",@@ -502,7 +501,7 @@ func TestIdentityMultipleAdditionalPrivileges_Merge(t *testing.T) {}, nil)// Should see dev secrets- devResult, err := listSecrets(t, permission.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{+ devResult, err := listSecrets(t, auth.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{ProjectID: proj.ID,Environment: "dev",SecretPath: "/",@@ -512,7 +511,7 @@ func TestIdentityMultipleAdditionalPrivileges_Merge(t *testing.T) {require.Len(t, devResult.Secrets, 1)// Should also see staging secrets (merged privileges)- stagingResult, err := listSecrets(t, permission.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{+ stagingResult, err := listSecrets(t, auth.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{ProjectID: proj.ID,Environment: "staging",SecretPath: "/",@@ -547,7 +546,7 @@ func TestIdentityTemporaryRole_ActiveGrantsAccess(t *testing.T) {},})- result, err := listSecrets(t, permission.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{+ result, err := listSecrets(t, auth.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{ProjectID: proj.ID,Environment: proj.EnvSlug,SecretPath: "/",@@ -580,7 +579,7 @@ func TestIdentityTemporaryRole_ExpiredDeniesAccess(t *testing.T) {},})- result, err := listSecrets(t, permission.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{+ result, err := listSecrets(t, auth.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{ProjectID: proj.ID,Environment: proj.EnvSlug,SecretPath: "/",@@ -613,7 +612,7 @@ func TestIdentityTemporaryRole_MixedWithPermanent(t *testing.T) {},})- result, err := listSecrets(t, permission.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{+ result, err := listSecrets(t, auth.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{ProjectID: proj.ID,Environment: proj.EnvSlug,SecretPath: "/",@@ -642,7 +641,7 @@ func TestIdentityTemporaryAdditionalPrivilege_Active(t *testing.T) {},}, &infra.IdentityPrivilegeOpts{TemporaryRange: "1h", TemporaryAccessStartTime: time.Now().UTC().Format(time.RFC3339)})- result, err := listSecrets(t, permission.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{+ result, err := listSecrets(t, auth.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{ProjectID: proj.ID,Environment: proj.EnvSlug,SecretPath: "/",@@ -669,7 +668,7 @@ func TestIdentityTemporaryAdditionalPrivilege_Expired(t *testing.T) {},}, &infra.IdentityPrivilegeOpts{TemporaryRange: "1h", TemporaryAccessStartTime: time.Now().Add(-2 * time.Hour).UTC().Format(time.RFC3339)})- result, err := listSecrets(t, permission.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{+ result, err := listSecrets(t, auth.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{ProjectID: proj.ID,Environment: proj.EnvSlug,SecretPath: "/",@@ -693,7 +692,7 @@ func TestViewSecretValue_False_HidesValues(t *testing.T) {identity := nodejs.CreateIdentity(t, "view-value-identity")nodejs.AddIdentityToProject(t, proj.ID, identity.ID, infra.Role("admin"))- result, err := listSecrets(t, permission.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{+ result, err := listSecrets(t, auth.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{ProjectID: proj.ID,Environment: proj.EnvSlug,SecretPath: "/",@@ -715,7 +714,7 @@ func TestViewSecretValue_True_ShowsValues(t *testing.T) {identity := nodejs.CreateIdentity(t, "view-value-true-identity")nodejs.AddIdentityToProject(t, proj.ID, identity.ID, infra.Role("admin"))- result, err := listSecrets(t, permission.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{+ result, err := listSecrets(t, auth.ActorTypeIdentity, identity.ID, nodejs.OrgID(), &gensecrets.ListSecretsV4Payload{ProjectID: proj.ID,Environment: proj.EnvSlug,SecretPath: "/",@@ -766,7 +765,7 @@ func TestGetSecretByName_ImportPermissions(t *testing.T) {nodejs.AddIdentityToProject(t, proj.ID, adminIdentity.ID, infra.Role("admin"))t.Run("direct secret allowed with env-scoped permission", func(t *testing.T) {- result, err := getSecretByName(t, permission.ActorTypeIdentity, devOnlyIdentity.ID, nodejs.OrgID(), &gensecrets.GetSecretByNameV4Payload{+ result, err := getSecretByName(t, auth.ActorTypeIdentity, devOnlyIdentity.ID, nodejs.OrgID(), &gensecrets.GetSecretByNameV4Payload{SecretName: "DEV_DIRECT",ProjectID: proj.ID,Environment: "dev",@@ -783,7 +782,7 @@ func TestGetSecretByName_ImportPermissions(t *testing.T) {t.Run("imported secret denied without source env permission", func(t *testing.T) {// Request secret via dev, but it's actually in staging// dev-only identity should NOT be able to read it- _, err := getSecretByName(t, permission.ActorTypeIdentity, devOnlyIdentity.ID, nodejs.OrgID(), &gensecrets.GetSecretByNameV4Payload{+ _, err := getSecretByName(t, auth.ActorTypeIdentity, devOnlyIdentity.ID, nodejs.OrgID(), &gensecrets.GetSecretByNameV4Payload{SecretName: "STAGING_SECRET",ProjectID: proj.ID,Environment: "dev",@@ -797,7 +796,7 @@ func TestGetSecretByName_ImportPermissions(t *testing.T) {})t.Run("imported secret allowed with admin permission", func(t *testing.T) {- result, err := getSecretByName(t, permission.ActorTypeIdentity, adminIdentity.ID, nodejs.OrgID(), &gensecrets.GetSecretByNameV4Payload{+ result, err := getSecretByName(t, auth.ActorTypeIdentity, adminIdentity.ID, nodejs.OrgID(), &gensecrets.GetSecretByNameV4Payload{SecretName: "STAGING_SECRET",ProjectID: proj.ID,Environment: "dev",@@ -813,7 +812,7 @@ func TestGetSecretByName_ImportPermissions(t *testing.T) {})t.Run("imported secret not found when includeImports is false", func(t *testing.T) {- _, err := getSecretByName(t, permission.ActorTypeIdentity, adminIdentity.ID, nodejs.OrgID(), &gensecrets.GetSecretByNameV4Payload{+ _, err := getSecretByName(t, auth.ActorTypeIdentity, adminIdentity.ID, nodejs.OrgID(), &gensecrets.GetSecretByNameV4Payload{SecretName: "STAGING_SECRET",ProjectID: proj.ID,Environment: "dev",diff --git a/backend-go/internal/services/actor/actor.go b/backend-go/internal/services/actor/actor.godeleted file mode 100644index f19c308667..0000000000--- a/backend-go/internal/services/actor/actor.go+++ /dev/null@@ -1,88 +0,0 @@-package actor--import (- "context"-- "github.com/google/uuid"-)--// Type identifies the kind of entity performing an action.-type Type string--const (- TypeUser Type = "user"- TypeIdentity Type = "identity"- TypeService Type = "service"-)--// AuthMethod represents the authentication method used by the actor (e.g. "jwt", "api-key").-// An empty string means no specific method (e.g. platform-level actions).-type AuthMethod string--// IdentityAuthMethod represents the authentication method used by machine identities.-type IdentityAuthMethod string--const (- IdentityAuthMethodUniversal IdentityAuthMethod = "universal_auth"- IdentityAuthMethodKubernetes IdentityAuthMethod = "kubernetes_auth"- IdentityAuthMethodGCP IdentityAuthMethod = "gcp_auth"- IdentityAuthMethodAliCloud IdentityAuthMethod = "alicloud_auth"- IdentityAuthMethodAWS IdentityAuthMethod = "aws_auth"- IdentityAuthMethodAzure IdentityAuthMethod = "azure_auth"- IdentityAuthMethodToken IdentityAuthMethod = "token_auth"- IdentityAuthMethodTLSCert IdentityAuthMethod = "tls_cert_auth"- IdentityAuthMethodOCI IdentityAuthMethod = "oci_auth"- IdentityAuthMethodOIDC IdentityAuthMethod = "oidc_auth"- IdentityAuthMethodJWT IdentityAuthMethod = "jwt_auth"- IdentityAuthMethodLDAP IdentityAuthMethod = "ldap_auth"- IdentityAuthMethodSPIFFE IdentityAuthMethod = "spiffe_auth"-)--// AuthOIDC holds OIDC-specific claims from the identity JWT payload.-// Used for permission template interpolation (e.g., {{identity.auth.oidc.sub}}).-type AuthOIDC struct {- Claims map[string]string-}--// AuthKubernetes holds Kubernetes-specific metadata from the identity JWT payload.-// Used for permission template interpolation (e.g., {{identity.auth.kubernetes.namespace}}).-type AuthKubernetes struct {- Namespace string- Name string-}--// AuthAWS holds AWS-specific principal details from the identity JWT payload.-// Used for permission template interpolation (e.g., {{identity.auth.aws.accountId}}).-type AuthAWS struct {- AccountID string- ARN string- UserID string- Partition string- Service string- ResourceType string- ResourceName string-}--// AuthInfo holds auth-method-specific claims for permission template interpolation.-// Set by the auth layer, read by the permission service.-type AuthInfo struct {- IdentityID uuid.UUID- IdentityName string- AuthMethod IdentityAuthMethod- OIDC *AuthOIDC- Kubernetes *AuthKubernetes- AWS *AuthAWS-}--type authInfoKey struct{}--// WithAuthInfo stores the actor auth info in the context.-func WithAuthInfo(ctx context.Context, info *AuthInfo) context.Context {- return context.WithValue(ctx, authInfoKey{}, info)-}--// AuthInfoFromContext returns the actor auth info stored in ctx, or nil if absent.-func AuthInfoFromContext(ctx context.Context) *AuthInfo {- info, _ := ctx.Value(authInfoKey{}).(*AuthInfo)- return info-}diff --git a/backend-go/internal/services/auditlog/info.go b/backend-go/internal/services/auditlog/info.goindex 07e4c9fc99..93f79cda72 100644--- a/backend-go/internal/services/auditlog/info.go+++ b/backend-go/internal/services/auditlog/info.go@@ -2,7 +2,6 @@ package auditlogimport ("github.com/infisical/api/internal/services/auth"- "github.com/infisical/api/internal/services/permission")// AuditLogInfo holds the pre-built audit log context from an identity.@@ -31,7 +30,7 @@ func BuildAuditLogInfo(identity *auth.Identity) *AuditLogInfo {func buildActor(identity *auth.Identity) Actor {switch identity.Actor {- case permission.ActorTypeUser:+ case auth.ActorTypeUser:return Actor{Type: ActorTypeUser,Metadata: UserActorMetadata{@@ -41,7 +40,7 @@ func buildActor(identity *auth.Identity) Actor {AuthMethod: string(identity.AuthMethod),},}- case permission.ActorTypeIdentity:+ case auth.ActorTypeIdentity:return Actor{Type: ActorTypeIdentity,Metadata: IdentityActorMetadata{@@ -50,7 +49,7 @@ func buildActor(identity *auth.Identity) Actor {AuthMethod: string(identity.AuthMethod),},}- case permission.ActorTypeService:+ case auth.ActorTypeService:return Actor{Type: ActorTypeService,Metadata: ServiceActorMetadata{diff --git a/backend-go/internal/services/auth/handler.go b/backend-go/internal/services/auth/apiauth/authenticator.gosimilarity index 89%rename from backend-go/internal/services/auth/handler.gorename to backend-go/internal/services/auth/apiauth/authenticator.goindex 0ce036005c..54e4ed7024 100644--- a/backend-go/internal/services/auth/handler.go+++ b/backend-go/internal/services/auth/apiauth/authenticator.go@@ -1,4 +1,4 @@-package auth+package apiauthimport ("context"@@ -18,7 +18,7 @@ import ("github.com/infisical/api/internal/database/pg""github.com/infisical/api/internal/keystore""github.com/infisical/api/internal/libs/errutil"- "github.com/infisical/api/internal/services/actor"+ "github.com/infisical/api/internal/services/auth")// maxMachineIdentityTokenAge is the maximum TTL in seconds for identity access tokens.@@ -64,14 +64,14 @@ func (a Authenticator) JWTAuth(ctx context.Context, token string, sc *security.J}// Map scheme name to expected auth mode.- var expectedMode AuthMode+ var expectedMode auth.AuthModeswitch sc.Name {case "jwt":- expectedMode = AuthModeJWT+ expectedMode = auth.AuthModeJWTcase "identity_access_token":- expectedMode = AuthModeIdentityAccessToken+ expectedMode = auth.AuthModeIdentityAccessTokencase "service_token":- expectedMode = AuthModeServiceToken+ expectedMode = auth.AuthModeServiceTokendefault:return ctx, errutil.Unauthorized("You are not allowed to access this resource").WithErr(errors.New("invalid token"))}@@ -82,19 +82,19 @@ func (a Authenticator) JWTAuth(ctx context.Context, token string, sc *security.J}var (- identity *Identity+ identity *auth.Identityerr error)switch expectedMode {- case AuthModeJWT:+ case auth.AuthModeJWT:identity, err = a.validateJWT(ctx, token)- case AuthModeIdentityAccessToken:+ case auth.AuthModeIdentityAccessToken:ipAddress := ""- if httpInfo := HTTPInfoFromContext(ctx); httpInfo != nil {+ if httpInfo := auth.HTTPInfoFromContext(ctx); httpInfo != nil {ipAddress = httpInfo.IPAddress}identity, err = a.validateIdentityAccessToken(ctx, token, ipAddress)- case AuthModeServiceToken:+ case auth.AuthModeServiceToken:identity, err = a.validateServiceToken(ctx, token)}@@ -106,19 +106,19 @@ func (a Authenticator) JWTAuth(ctx context.Context, token string, sc *security.J}// Populate HTTP layer fields from context (set by HTTPInfoMiddleware).- if httpInfo := HTTPInfoFromContext(ctx); httpInfo != nil {+ if httpInfo := auth.HTTPInfoFromContext(ctx); httpInfo != nil {identity.IPAddress = httpInfo.IPAddressidentity.UserAgent = httpInfo.UserAgentidentity.UserAgentType = httpInfo.UserAgentType}- return WithIdentity(ctx, identity), nil+ return auth.WithIdentity(ctx, identity), nil}// TODO(gov0): Missing test// validateJWT performs real JWT validation.// Exact port of fnValidateJwtIdentity in auth-token-service.ts:212-285.-func (a Authenticator) validateJWT(ctx context.Context, token string) (*Identity, error) {+func (a Authenticator) validateJWT(ctx context.Context, token string) (*auth.Identity, error) {// 1. Parse and verify JWT signature (HS256 only).claims := &UserJWTClaims{}_, err := jwt.ParseWithClaims(token, claims, func(t *jwt.Token) (any, error) {@@ -133,7 +133,7 @@ func (a Authenticator) validateJWT(ctx context.Context, token string) (*Identity}// 2. Validate authTokenType.- if claims.AuthTokenType != AuthTokenTypeAccessToken {+ if claims.AuthTokenType != auth.AuthTokenTypeAccessToken {return nil, errutil.Unauthorized("You are not allowed to access this resource").WithErrf("validateJWT: invalid authTokenType %s", claims.AuthTokenType)}@@ -191,7 +191,7 @@ func (a Authenticator) validateJWT(ctx context.Context, token string) (*Identityreturn nil, errutil.Forbidden("Sub-organization does not belong to the token's organization").WithErrf("validateJWT(subOrgId=%s, claimOrgId=%s): org mismatch", subOrg.ID, claims.OrganizationID)}- orgMembership, err := a.findEffectiveOrgMembership(ctx, actor.TypeUser, user.ID, subOrg.ID, "accepted")+ orgMembership, err := a.findEffectiveOrgMembership(ctx, auth.ActorTypeUser, user.ID, subOrg.ID, "accepted")if err != nil {return nil, errutil.DatabaseErr("Failed to check org membership").WithErrf("validateJWT(userId=%s, orgId=%s): %w", user.ID, subOrg.ID, err)}@@ -215,7 +215,7 @@ func (a Authenticator) validateJWT(ctx context.Context, token string) (*Identityreturn nil, errutil.DatabaseErr("Failed to find organization").WithErrf("validateJWT(orgId=%s): %w", claims.OrganizationID, err)}- orgMembership, err := a.findEffectiveOrgMembership(ctx, actor.TypeUser, user.ID, claims.OrganizationID, "accepted")+ orgMembership, err := a.findEffectiveOrgMembership(ctx, auth.ActorTypeUser, user.ID, claims.OrganizationID, "accepted")if err != nil {return nil, errutil.DatabaseErr("Failed to check org membership").WithErrf("validateJWT(userId=%s, orgId=%s): %w", user.ID, claims.OrganizationID, err)}@@ -245,19 +245,19 @@ func (a Authenticator) validateJWT(ctx context.Context, token string) (*Identityusername = user.Username.V}- return &Identity{- AuthMode: AuthModeJWT,- Actor: actor.TypeUser,+ return &auth.Identity{+ AuthMode: auth.AuthModeJWT,+ Actor: auth.ActorTypeUser,ActorID: user.ID,OrgID: orgID,RootOrgID: rootOrgID,ParentOrgID: parentOrgID,OrgName: orgName,- AuthMethod: actor.AuthMethod(claims.AuthMethod),+ AuthMethod: auth.ActorAuthMethod(claims.AuthMethod),IsSuperAdmin: isSuperAdmin,IsMfaVerified: claims.IsMfaVerified,MfaMethod: claims.MfaMethod,- UserAuthInfo: &UserAuthInfo{+ UserAuthInfo: &auth.UserAuthInfo{UserID: user.ID,Email: email,},@@ -270,7 +270,7 @@ func (a Authenticator) validateJWT(ctx context.Context, token string) (*Identity// Port of fnValidateIdentityAccessTokenFast in identity-access-token-service.ts.// New-format tokens carry all claims in the JWT for stateless validation; legacy tokens// fall back to DB lookup.-func (a Authenticator) validateIdentityAccessToken(ctx context.Context, token, ipAddress string) (*Identity, error) {+func (a Authenticator) validateIdentityAccessToken(ctx context.Context, token, ipAddress string) (*auth.Identity, error) {// 1. Parse and verify JWT signature (HS256 only).claims := &IdentityJWTClaims{}_, err := jwt.ParseWithClaims(token, claims, func(t *jwt.Token) (any, error) {@@ -284,7 +284,7 @@ func (a Authenticator) validateIdentityAccessToken(ctx context.Context, token, i}// 2. Validate authTokenType.- if claims.AuthTokenType != AuthTokenTypeIdentityAccessToken {+ if claims.AuthTokenType != auth.AuthTokenTypeIdentityAccessToken {return nil, errutil.Unauthorized("You are not allowed to access this resource").WithErrf("validateIdentityAccessToken: invalid authTokenType %s", claims.AuthTokenType)}@@ -292,7 +292,7 @@ func (a Authenticator) validateIdentityAccessToken(ctx context.Context, token, ivar (identityID = claims.IdentityIDidentityName string- authMethod actor.IdentityAuthMethod+ authMethod auth.IdentityAuthMethodorgID uuid.UUIDrootOrgID uuid.UUIDparentOrgID uuid.UUID@@ -301,7 +301,7 @@ func (a Authenticator) validateIdentityAccessToken(ctx context.Context, token, iif claims.HasFullRenewClaims() {// New-format token: use claims directly (stateless validation)identityName = claims.IdentityName- authMethod = actor.IdentityAuthMethod(claims.AuthMethod)+ authMethod = auth.IdentityAuthMethod(claims.AuthMethod)orgID = claims.OrgIDrootOrgID = claims.RootOrgIDparentOrgID = claims.ParentOrgID@@ -311,11 +311,8 @@ func (a Authenticator) validateIdentityAccessToken(ctx context.Context, token, iif err != nil {return nil, errutil.DatabaseErr("Failed to find identity access token").WithErrf("validateIdentityAccessToken(tokenId=%s): %w", claims.IdentityAccessTokenID, err)}- if accessToken == nil {- return nil, errutil.Unauthorized("No identity access token found").WithErrf("validateIdentityAccessToken(tokenId=%s): token not found in DB", claims.IdentityAccessTokenID)- }- if accessToken.IsAccessTokenRevoked {- return nil, errutil.Unauthorized("Failed to authorize revoked access token, access token is revoked").WithErrf("validateIdentityAccessToken(tokenId=%s): token is revoked", accessToken.ID)+ if accessToken == nil || accessToken.IsAccessTokenRevoked {+ return nil, errutil.Unauthorized("Cannot renew revoked or unknown access token").WithErrf("validateIdentityAccessToken(tokenId=%s): token not found or revoked", claims.IdentityAccessTokenID)}identityName = accessToken.IdentityName@@ -354,7 +351,7 @@ func (a Authenticator) validateIdentityAccessToken(ctx context.Context, token, i}// 5. Check org membership.- membership, err := a.findEffectiveOrgMembership(ctx, actor.TypeIdentity, identityID, orgID, "")+ membership, err := a.findEffectiveOrgMembership(ctx, auth.ActorTypeIdentity, identityID, orgID, "")if err != nil {return nil, errutil.DatabaseErr("Failed to check org membership").WithErrf("validateIdentityAccessToken(identityId=%s, orgId=%s): %w", identityID, orgID, err)}@@ -387,7 +384,7 @@ func (a Authenticator) validateIdentityAccessToken(ctx context.Context, token, i}// 6. Build identity auth info (for audit logging).- identityAuthInfo := &IdentityAuthInfo{+ identityAuthInfo := &auth.AuthInfo{IdentityID: identityID,IdentityName: identityName,AuthMethod: authMethod,@@ -405,14 +402,14 @@ func (a Authenticator) validateIdentityAccessToken(ctx context.Context, token, i}// 7. Build identity.- return &Identity{- AuthMode: AuthModeIdentityAccessToken,- Actor: actor.TypeIdentity,+ return &auth.Identity{+ AuthMode: auth.AuthModeIdentityAccessToken,+ Actor: auth.ActorTypeIdentity,ActorID: identityID,OrgID: orgID,RootOrgID: rootOrgID,ParentOrgID: parentOrgID,- AuthMethod: actor.AuthMethod(authMethod),+ AuthMethod: auth.ActorAuthMethod(authMethod),IdentityAuthInfo: identityAuthInfo,Name: identityName,}, nil@@ -420,7 +417,7 @@ func (a Authenticator) validateIdentityAccessToken(ctx context.Context, token, i// validateServiceToken performs real service token validation.// Exact port of fnValidateServiceToken in service-token-service.ts:172-199.-func (a Authenticator) validateServiceToken(ctx context.Context, token string) (*Identity, error) {+func (a Authenticator) validateServiceToken(ctx context.Context, token string) (*auth.Identity, error) {// 1. Split token: "st.<tokenID>.<tokenSecret>"parts := strings.SplitN(token, ".", 3)if len(parts) != 3 || parts[0] != "st" {@@ -471,9 +468,9 @@ func (a Authenticator) validateServiceToken(ctx context.Context, token string) (// 7. Build identity.orgID, rootOrgID, parentOrgID, orgName := resolveOrgHierarchy(org)- return &Identity{- AuthMode: AuthModeServiceToken,- Actor: actor.TypeService,+ return &auth.Identity{+ AuthMode: auth.AuthModeServiceToken,+ Actor: auth.ActorTypeService,ActorID: serviceToken.ID,OrgID: orgID,RootOrgID: rootOrgID,@@ -532,20 +529,20 @@ type projectRow struct {// identityAccessTokenRow holds the identity_access_tokens columns + joined identity fields.type identityAccessTokenRow struct {- ID uuid.UUID `db:"id"`- AccessTokenTTL int64 `db:"access_token_ttl"`- AccessTokenMaxTTL int64 `db:"access_token_max_ttl"`- AccessTokenNumUses int64 `db:"access_token_num_uses"`- AccessTokenNumUsesLimit int64 `db:"access_token_num_uses_limit"`- AccessTokenLastRenewedAt sql.Null[time.Time] `db:"access_token_last_renewed_at"`- IsAccessTokenRevoked bool `db:"is_access_token_revoked"`- IdentityID uuid.UUID `db:"identity_id"`- CreatedAt sql.Null[time.Time] `db:"created_at"`- AuthMethod actor.IdentityAuthMethod `db:"auth_method"`- AccessTokenPeriod int64 `db:"access_token_period"`- SubOrganizationID sql.Null[uuid.UUID] `db:"sub_organization_id"`- IdentityOrgID uuid.UUID `db:"identity_org_id"`- IdentityName string `db:"identity_name"`+ ID uuid.UUID `db:"id"`+ AccessTokenTTL int64 `db:"access_token_ttl"`+ AccessTokenMaxTTL int64 `db:"access_token_max_ttl"`+ AccessTokenNumUses int64 `db:"access_token_num_uses"`+ AccessTokenNumUsesLimit int64 `db:"access_token_num_uses_limit"`+ AccessTokenLastRenewedAt sql.Null[time.Time] `db:"access_token_last_renewed_at"`+ IsAccessTokenRevoked bool `db:"is_access_token_revoked"`+ IdentityID uuid.UUID `db:"identity_id"`+ CreatedAt sql.Null[time.Time] `db:"created_at"`+ AuthMethod auth.IdentityAuthMethod `db:"auth_method"`+ AccessTokenPeriod int64 `db:"access_token_period"`+ SubOrganizationID sql.Null[uuid.UUID] `db:"sub_organization_id"`+ IdentityOrgID uuid.UUID `db:"identity_org_id"`+ IdentityName string `db:"identity_name"`}// serviceTokenRow holds the subset of service_tokens used by the authenticator.@@ -648,7 +645,7 @@ func (a Authenticator) findProjectByID(ctx context.Context, id string) (*projectreturn &project, nil}-// findIdentityAccessTokenByID returns the token (joined with identity) if not revoked, or nil.+// findIdentityAccessTokenByID returns the token (joined with identity), or nil if not found.func (a Authenticator) findIdentityAccessTokenByID(ctx context.Context, id string) (*identityAccessTokenRow, error) {query := `SELECT@@ -668,7 +665,7 @@ func (a Authenticator) findIdentityAccessTokenByID(ctx context.Context, id strinidentity.name AS identity_nameFROM identity_access_tokens tokenINNER JOIN identities identity ON token."identityId" = identity.id- WHERE token.id = @id AND token."isAccessTokenRevoked" = false+ WHERE token.id = @id`args := pgx.NamedArgs{"id": id}@@ -731,9 +728,9 @@ func (a Authenticator) deleteServiceTokenByID(ctx context.Context, id uuid.UUID)// findEffectiveOrgMembership returns the first effective org membership for an actor (user or identity),// including direct membership and membership via groups.// Exact port of Node.js orgDAL.findEffectiveOrgMembership.-func (a Authenticator) findEffectiveOrgMembership(ctx context.Context, actorType actor.Type, actorID, orgID uuid.UUID, filterStatus string) (*membershipRow, error) {+func (a Authenticator) findEffectiveOrgMembership(ctx context.Context, actorType auth.ActorType, actorID, orgID uuid.UUID, filterStatus string) (*membershipRow, error) {var actorCondition string- if actorType == actor.TypeUser {+ if actorType == auth.ActorTypeUser {actorCondition = `(membership."actorUserId" = @actorIDOR membership."actorGroupId" IN (@@ -788,34 +785,34 @@ func (a Authenticator) findEffectiveOrgMembership(ctx context.Context, actorType// findTrustedIPsByAuthMethod returns the parsed trusted IPs for an identity's auth method.// Exact port of Node.js identityDAL.getTrustedIpsByAuthMethod.-func (a Authenticator) findTrustedIPsByAuthMethod(ctx context.Context, identityID uuid.UUID, authMethod actor.IdentityAuthMethod) ([]TrustedIP, error) {+func (a Authenticator) findTrustedIPsByAuthMethod(ctx context.Context, identityID uuid.UUID, authMethod auth.IdentityAuthMethod) ([]TrustedIP, error) {var tableName stringswitch authMethod {- case actor.IdentityAuthMethodUniversal:+ case auth.IdentityAuthMethodUniversal:tableName = "identity_universal_auths"- case actor.IdentityAuthMethodKubernetes:+ case auth.IdentityAuthMethodKubernetes:tableName = "identity_kubernetes_auths"- case actor.IdentityAuthMethodGCP:+ case auth.IdentityAuthMethodGCP:tableName = "identity_gcp_auths"- case actor.IdentityAuthMethodAliCloud:+ case auth.IdentityAuthMethodAliCloud:tableName = "identity_alicloud_auths"- case actor.IdentityAuthMethodAWS:+ case auth.IdentityAuthMethodAWS:tableName = "identity_aws_auths"- case actor.IdentityAuthMethodAzure:+ case auth.IdentityAuthMethodAzure:tableName = "identity_azure_auths"- case actor.IdentityAuthMethodToken:+ case auth.IdentityAuthMethodToken:tableName = "identity_token_auths"- case actor.IdentityAuthMethodTLSCert:+ case auth.IdentityAuthMethodTLSCert:tableName = "identity_tls_cert_auths"- case actor.IdentityAuthMethodOCI:+ case auth.IdentityAuthMethodOCI:tableName = "identity_oci_auths"- case actor.IdentityAuthMethodOIDC:+ case auth.IdentityAuthMethodOIDC:tableName = "identity_oidc_auths"- case actor.IdentityAuthMethodJWT:+ case auth.IdentityAuthMethodJWT:tableName = "identity_jwt_auths"- case actor.IdentityAuthMethodLDAP:+ case auth.IdentityAuthMethodLDAP:tableName = "identity_ldap_auths"- case actor.IdentityAuthMethodSPIFFE:+ case auth.IdentityAuthMethodSPIFFE:tableName = "identity_spiffe_auths"default:return nil, nildiff --git a/backend-go/internal/services/auth/handler_test.go b/backend-go/internal/services/auth/apiauth/authenticator_test.gosimilarity index 96%rename from backend-go/internal/services/auth/handler_test.gorename to backend-go/internal/services/auth/apiauth/authenticator_test.goindex 38af61ffcc..9229c50a98 100644--- a/backend-go/internal/services/auth/handler_test.go+++ b/backend-go/internal/services/auth/apiauth/authenticator_test.go@@ -1,4 +1,4 @@-package auth+package apiauthimport ("testing"@@ -6,6 +6,8 @@ import ("github.com/golang-jwt/jwt/v5""github.com/google/uuid""github.com/stretchr/testify/assert"++ "github.com/infisical/api/internal/services/auth")// =============================================================================@@ -18,22 +20,22 @@ func TestClassifyToken_ServiceToken(t *testing.T) {tests := []struct {name stringtoken string- expected AuthMode+ expected auth.AuthMode}{{name: "valid service token format",token: "st." + uuid.New().String() + ".secret123",- expected: AuthModeServiceToken,+ expected: auth.AuthModeServiceToken,},{name: "service token with only prefix and id",token: "st." + uuid.New().String(),- expected: AuthModeServiceToken,+ expected: auth.AuthModeServiceToken,},{name: "service token with empty parts after prefix",token: "st..",- expected: AuthModeServiceToken,+ expected: auth.AuthModeServiceToken,},{name: "wrong prefix sv",@@ -66,19 +68,19 @@ func TestClassifyToken_JWT(t *testing.T) {tests := []struct {name stringtoken string- expected AuthMode+ expected auth.AuthMode}{{name: "JWT with accessToken type",// payload: {"authTokenType":"accessToken"}token: "eyJhbGciOiJIUzI1NiJ9.eyJhdXRoVG9rZW5UeXBlIjoiYWNjZXNzVG9rZW4ifQ.sig",- expected: AuthModeJWT,+ expected: auth.AuthModeJWT,},{name: "JWT with identityAccessToken type",// payload: {"authTokenType":"identityAccessToken"}token: "eyJhbGciOiJIUzI1NiJ9.eyJhdXRoVG9rZW5UeXBlIjoiaWRlbnRpdHlBY2Nlc3NUb2tlbiJ9.sig",- expected: AuthModeIdentityAccessToken,+ expected: auth.AuthModeIdentityAccessToken,},{name: "JWT with refreshToken type returns empty",@@ -138,7 +140,7 @@ func TestClassifyToken_Malformed(t *testing.T) {t.Run(tt.name, func(t *testing.T) {t.Parallel()result := ClassifyToken(tt.token)- assert.Equal(t, AuthMode(""), result, "malformed token should return empty AuthMode")+ assert.Equal(t, auth.AuthMode(""), result, "malformed token should return empty AuthMode")})}}@@ -462,6 +464,10 @@ func RegisteredClaimsWithJTI(jti string) jwt.RegisteredClaims {func TestParseUsesRemaining(t *testing.T) {t.Parallel()+ ten := int64(10)+ zero := int64(0)+ negFive := int64(-5)+tests := []struct {name stringinput string@@ -475,17 +481,17 @@ func TestParseUsesRemaining(t *testing.T) {{name: "valid positive number",input: "10",- expected: new(int64(10)),+ expected: &ten,},{name: "zero",input: "0",- expected: new(int64(0)),+ expected: &zero,},{name: "negative number",input: "-5",- expected: new(int64(-5)),+ expected: &negFive,},{name: "non-numeric returns nil",diff --git a/backend-go/internal/services/auth/claims.go b/backend-go/internal/services/auth/apiauth/claims.gosimilarity index 58%rename from backend-go/internal/services/auth/claims.gorename to backend-go/internal/services/auth/apiauth/claims.goindex 800b20b93e..bca1065527 100644--- a/backend-go/internal/services/auth/claims.go+++ b/backend-go/internal/services/auth/apiauth/claims.go@@ -1,24 +1,26 @@-package auth+package apiauthimport ("github.com/golang-jwt/jwt/v5""github.com/google/uuid"++ "github.com/infisical/api/internal/services/auth")// UserJWTClaims represents the JWT payload for user browser sessions.// Exact match of the Node.js AuthModeJwtTokenPayload.type UserJWTClaims struct {jwt.RegisteredClaims- AuthTokenType AuthTokenType `json:"authTokenType"`- AuthMethod string `json:"authMethod,omitempty"`- UserID uuid.UUID `json:"userId"`- TokenVersionID uuid.UUID `json:"tokenVersionId"`- AccessVersion int `json:"accessVersion"`- OrganizationID uuid.UUID `json:"organizationId,omitempty"`- SubOrganizationID uuid.UUID `json:"subOrganizationId,omitempty"`- IsMfaVerified bool `json:"isMfaVerified,omitempty"`- MfaMethod string `json:"mfaMethod,omitempty"`- MCP bool `json:"mcp,omitempty"`+ AuthTokenType auth.AuthTokenType `json:"authTokenType"`+ AuthMethod string `json:"authMethod,omitempty"`+ UserID uuid.UUID `json:"userId"`+ TokenVersionID uuid.UUID `json:"tokenVersionId"`+ AccessVersion int `json:"accessVersion"`+ OrganizationID uuid.UUID `json:"organizationId,omitempty"`+ SubOrganizationID uuid.UUID `json:"subOrganizationId,omitempty"`+ IsMfaVerified bool `json:"isMfaVerified,omitempty"`+ MfaMethod string `json:"mfaMethod,omitempty"`+ MCP bool `json:"mcp,omitempty"`}// IdentityJWTClaims represents the JWT payload for machine identity access tokens.@@ -27,11 +29,11 @@ type UserJWTClaims struct {// only have minimal claims and require DB lookup.type IdentityJWTClaims struct {jwt.RegisteredClaims- AuthTokenType AuthTokenType `json:"authTokenType"`- IdentityID uuid.UUID `json:"identityId"`- ClientSecretID string `json:"clientSecretId"`- IdentityAccessTokenID string `json:"identityAccessTokenId"`- IdentityAuth *IdentityAuth `json:"identityAuth,omitempty"`+ AuthTokenType auth.AuthTokenType `json:"authTokenType"`+ IdentityID uuid.UUID `json:"identityId"`+ ClientSecretID string `json:"clientSecretId"`+ IdentityAccessTokenID string `json:"identityAccessTokenId"`+ IdentityAuth *IdentityAuth `json:"identityAuth,omitempty"`// New-format claims for stateless validation (optional for legacy tokens)IdentityName string `json:"identityName,omitempty"`@@ -58,9 +60,9 @@ func (c *IdentityJWTClaims) HasFullRenewClaims() bool {}// IdentityAuth holds auth-method-specific metadata from the identity JWT payload.-// Used to populate IdentityAuthInfo for audit logging.+// Used to populate AuthInfo for audit logging.type IdentityAuth struct {- OIDC *IdentityAuthOIDC `json:"oidc,omitempty"`- Kubernetes *IdentityAuthKubernetes `json:"kubernetes,omitempty"`- AWS *IdentityAuthAWS `json:"aws,omitempty"`+ OIDC *auth.AuthOIDC `json:"oidc,omitempty"`+ Kubernetes *auth.AuthKubernetes `json:"kubernetes,omitempty"`+ AWS *auth.AuthAWS `json:"aws,omitempty"`}diff --git a/backend-go/internal/services/auth/classify.go b/backend-go/internal/services/auth/apiauth/classify.gosimilarity index 58%rename from backend-go/internal/services/auth/classify.gorename to backend-go/internal/services/auth/apiauth/classify.goindex 11298b478a..4bc0fc4bf1 100644--- a/backend-go/internal/services/auth/classify.go+++ b/backend-go/internal/services/auth/apiauth/classify.go@@ -1,38 +1,40 @@-package auth+package apiauthimport ("encoding/base64""encoding/json""strings"++ "github.com/infisical/api/internal/services/auth")// peekClaims is a minimal struct for peeking at the token type// without performing signature verification.type peekClaims struct {- AuthTokenType AuthTokenType `json:"authTokenType"`+ AuthTokenType auth.AuthTokenType `json:"authTokenType"`}// ClassifyToken determines the AuthMode from a raw token string// using cheap checks only (string prefix, base64 decode) — no crypto.-func ClassifyToken(token string) AuthMode {+func ClassifyToken(token string) auth.AuthMode {if strings.HasPrefix(token, "st.") {- return AuthModeServiceToken+ return auth.AuthModeServiceToken}claims := peekJWTClaims(token)switch claims.AuthTokenType {- case AuthTokenTypeAccessToken:- return AuthModeJWT- case AuthTokenTypeIdentityAccessToken:- return AuthModeIdentityAccessToken- case AuthTokenTypeRefreshToken,- AuthTokenTypeSignupToken,- AuthTokenTypeMfaToken,- AuthTokenTypeProviderToken,- AuthTokenTypeAPIKey,- AuthTokenTypeServiceAccessToken,- AuthTokenTypeServiceRefreshToken,- AuthTokenTypeSCIMToken:+ case auth.AuthTokenTypeAccessToken:+ return auth.AuthModeJWT+ case auth.AuthTokenTypeIdentityAccessToken:+ return auth.AuthModeIdentityAccessToken+ case auth.AuthTokenTypeRefreshToken,+ auth.AuthTokenTypeSignupToken,+ auth.AuthTokenTypeMfaToken,+ auth.AuthTokenTypeProviderToken,+ auth.AuthTokenTypeAPIKey,+ auth.AuthTokenTypeServiceAccessToken,+ auth.AuthTokenTypeServiceRefreshToken,+ auth.AuthTokenTypeSCIMToken:return ""}diff --git a/backend-go/internal/services/auth/classify_test.go b/backend-go/internal/services/auth/apiauth/classify_test.gosimilarity index 73%rename from backend-go/internal/services/auth/classify_test.gorename to backend-go/internal/services/auth/apiauth/classify_test.goindex 488ff27754..5304c8d395 100644--- a/backend-go/internal/services/auth/classify_test.go+++ b/backend-go/internal/services/auth/apiauth/classify_test.go@@ -1,9 +1,11 @@-package auth+package apiauthimport ("encoding/base64""encoding/json""testing"++ "github.com/infisical/api/internal/services/auth")// makeJWT builds a minimal unsigned JWT with the given payload claims for testing.@@ -17,24 +19,24 @@ func makeJWT(claims map[string]any) string {func TestClassifyToken_VariousInputTypes(t *testing.T) {t.Run("service token", func(t *testing.T) {mode := ClassifyToken("st.abc123.secretpart")- if mode != AuthModeServiceToken {- t.Errorf("expected %q, got %q", AuthModeServiceToken, mode)+ if mode != auth.AuthModeServiceToken {+ t.Errorf("expected %q, got %q", auth.AuthModeServiceToken, mode)}})t.Run("JWT access token", func(t *testing.T) {- token := makeJWT(map[string]any{"authTokenType": string(AuthTokenTypeAccessToken), "userId": "u1"})+ token := makeJWT(map[string]any{"authTokenType": string(auth.AuthTokenTypeAccessToken), "userId": "u1"})mode := ClassifyToken(token)- if mode != AuthModeJWT {- t.Errorf("expected %q, got %q", AuthModeJWT, mode)+ if mode != auth.AuthModeJWT {+ t.Errorf("expected %q, got %q", auth.AuthModeJWT, mode)}})t.Run("identity access token", func(t *testing.T) {- token := makeJWT(map[string]any{"authTokenType": string(AuthTokenTypeIdentityAccessToken), "identityId": "id1"})+ token := makeJWT(map[string]any{"authTokenType": string(auth.AuthTokenTypeIdentityAccessToken), "identityId": "id1"})mode := ClassifyToken(token)- if mode != AuthModeIdentityAccessToken {- t.Errorf("expected %q, got %q", AuthModeIdentityAccessToken, mode)+ if mode != auth.AuthModeIdentityAccessToken {+ t.Errorf("expected %q, got %q", auth.AuthModeIdentityAccessToken, mode)}})diff --git a/backend-go/internal/services/auth/ip.go b/backend-go/internal/services/auth/apiauth/ip.gosimilarity index 78%rename from backend-go/internal/services/auth/ip.gorename to backend-go/internal/services/auth/apiauth/ip.goindex e14140087d..babefc575e 100644--- a/backend-go/internal/services/auth/ip.go+++ b/backend-go/internal/services/auth/apiauth/ip.go@@ -1,8 +1,9 @@-package auth+package apiauthimport ("encoding/json""net"+ "strconv""github.com/infisical/api/internal/libs/errutil")@@ -46,7 +47,7 @@ func checkIPAgainstBlocklist(ipAddress string, trustedIPs []TrustedIP) error {}if tip.Prefix > 0 {- _, cidr, err := net.ParseCIDR(tip.IPAddress + "/" + itoa(tip.Prefix))+ _, cidr, err := net.ParseCIDR(tip.IPAddress + "/" + strconv.Itoa(tip.Prefix))if err != nil {continue}@@ -60,20 +61,3 @@ func checkIPAgainstBlocklist(ipAddress string, trustedIPs []TrustedIP) error {return errutil.Forbidden("You are not allowed to access this resource from the current IP address").WithErrf("checkIPAgainstBlocklist: IP %s not in allowlist", ipAddress)}--// itoa converts an int to its decimal string representation without importing strconv.-func itoa(n int) string {- if n == 0 {- return "0"- }- buf := make([]byte, 0, 4)- for n > 0 {- buf = append(buf, byte('0'+n%10))- n /= 10- }- // reverse- for i, j := 0, len(buf)-1; i < j; i, j = i+1, j-1 {- buf[i], buf[j] = buf[j], buf[i]- }- return string(buf)-}diff --git a/backend-go/internal/services/auth/ip_test.go b/backend-go/internal/services/auth/apiauth/ip_test.gosimilarity index 92%rename from backend-go/internal/services/auth/ip_test.gorename to backend-go/internal/services/auth/apiauth/ip_test.goindex 3d4de83194..03acd18375 100644--- a/backend-go/internal/services/auth/ip_test.go+++ b/backend-go/internal/services/auth/apiauth/ip_test.go@@ -1,4 +1,4 @@-package auth+package apiauthimport ("testing"@@ -139,24 +139,3 @@ func TestCheckIPAgainstBlocklist_VariousScenarios(t *testing.T) {}})}--func TestItoa_ConvertsIntToString(t *testing.T) {- tests := []struct {- input int- expected string- }{- {0, "0"},- {1, "1"},- {8, "8"},- {24, "24"},- {128, "128"},- {255, "255"},- }-- for _, tc := range tests {- got := itoa(tc.input)- if got != tc.expected {- t.Errorf("itoa(%d) = %q, want %q", tc.input, got, tc.expected)- }- }-}diff --git a/backend-go/internal/services/auth/auth.go b/backend-go/internal/services/auth/auth.goindex 446f00c30f..6e8190c7a3 100644--- a/backend-go/internal/services/auth/auth.go+++ b/backend-go/internal/services/auth/auth.go@@ -6,10 +6,76 @@ import ("context""github.com/google/uuid"+)++// ActorType identifies the kind of entity performing an action.+type ActorType string- "github.com/infisical/api/internal/services/actor"+const (+ ActorTypeUser ActorType = "user"+ ActorTypeIdentity ActorType = "identity"+ ActorTypeService ActorType = "service")+// ActorAuthMethod represents the authentication method used by the actor (e.g. "jwt", "api-key").+// An empty string means no specific method (e.g. platform-level actions).+type ActorAuthMethod string++// IdentityAuthMethod represents the authentication method used by machine identities.+type IdentityAuthMethod string++const (+ IdentityAuthMethodUniversal IdentityAuthMethod = "universal_auth"+ IdentityAuthMethodKubernetes IdentityAuthMethod = "kubernetes_auth"+ IdentityAuthMethodGCP IdentityAuthMethod = "gcp_auth"+ IdentityAuthMethodAliCloud IdentityAuthMethod = "alicloud_auth"+ IdentityAuthMethodAWS IdentityAuthMethod = "aws_auth"+ IdentityAuthMethodAzure IdentityAuthMethod = "azure_auth"+ IdentityAuthMethodToken IdentityAuthMethod = "token_auth"+ IdentityAuthMethodTLSCert IdentityAuthMethod = "tls_cert_auth"+ IdentityAuthMethodOCI IdentityAuthMethod = "oci_auth"+ IdentityAuthMethodOIDC IdentityAuthMethod = "oidc_auth"+ IdentityAuthMethodJWT IdentityAuthMethod = "jwt_auth"+ IdentityAuthMethodLDAP IdentityAuthMethod = "ldap_auth"+ IdentityAuthMethodSPIFFE IdentityAuthMethod = "spiffe_auth"+)++// AuthOIDC holds OIDC-specific claims from the identity JWT payload.+// Used for permission template interpolation (e.g., {{identity.auth.oidc.sub}}).+type AuthOIDC struct {+ Claims map[string]string+}++// AuthKubernetes holds Kubernetes-specific metadata from the identity JWT payload.+// Used for permission template interpolation (e.g., {{identity.auth.kubernetes.namespace}}).+type AuthKubernetes struct {+ Namespace string+ Name string+}++// AuthAWS holds AWS-specific principal details from the identity JWT payload.+// Used for permission template interpolation (e.g., {{identity.auth.aws.accountId}}).+type AuthAWS struct {+ AccountID string+ ARN string+ UserID string+ Partition string+ Service string+ ResourceType string+ ResourceName string+}++// AuthInfo holds auth-method-specific claims for permission template interpolation.+// Set by the auth layer, read by the permission service.+type AuthInfo struct {+ IdentityID uuid.UUID+ IdentityName string+ AuthMethod IdentityAuthMethod+ OIDC *AuthOIDC+ Kubernetes *AuthKubernetes+ AWS *AuthAWS+}+// AuthMode identifies the authentication mechanism used by the caller.type AuthMode string@@ -43,30 +109,17 @@ type UserAuthInfo struct {Email string}-// IdentityAuthInfo is an alias for actor.AuthInfo for backward compatibility.-// Port of Node.js requestContext.identityAuthInfo.-type IdentityAuthInfo = actor.AuthInfo--// IdentityAuthOIDC is an alias for actor.AuthOIDC for backward compatibility.-type IdentityAuthOIDC = actor.AuthOIDC--// IdentityAuthKubernetes is an alias for actor.AuthKubernetes for backward compatibility.-type IdentityAuthKubernetes = actor.AuthKubernetes--// IdentityAuthAWS is an alias for actor.AuthAWS for backward compatibility.-type IdentityAuthAWS = actor.AuthAWS-// Identity holds the resolved actor information extracted from a request token.// It is the Go equivalent of the Node.js backend's req.auth / req.permission object.type Identity struct {AuthMode AuthMode- Actor actor.Type+ Actor ActorTypeActorID uuid.UUIDOrgID uuid.UUIDRootOrgID uuid.UUIDParentOrgID uuid.UUIDOrgName string- AuthMethod actor.AuthMethod+ AuthMethod ActorAuthMethodIsSuperAdmin bool// MFA fields (for JWT user auth).@@ -76,7 +129,7 @@ type Identity struct {// UserAuthInfo is set for JWT (user) auth. Used for audit logging.UserAuthInfo *UserAuthInfo// IdentityAuthInfo is set for identity access token auth. Used for audit logging.- IdentityAuthInfo *IdentityAuthInfo+ IdentityAuthInfo *AuthInfo// HTTP layer fields (populated by middleware, used for audit logging).IPAddress string@@ -90,6 +143,7 @@ type Identity struct {type ctxKey struct{}type httpInfoKey struct{}+type authInfoKey struct{}// HTTPInfo holds HTTP request information for audit logging.type HTTPInfo struct {@@ -119,3 +173,14 @@ func IdentityFromContext(ctx context.Context) *Identity {id, _ := ctx.Value(ctxKey{}).(*Identity)return id}++// WithAuthInfo stores the actor auth info in the context.+func WithAuthInfo(ctx context.Context, info *AuthInfo) context.Context {+ return context.WithValue(ctx, authInfoKey{}, info)+}++// AuthInfoFromContext returns the actor auth info stored in ctx, or nil if absent.+func AuthInfoFromContext(ctx context.Context) *AuthInfo {+ info, _ := ctx.Value(authInfoKey{}).(*AuthInfo)+ return info+}diff --git a/backend-go/internal/services/auth/handler_integration_test.go b/backend-go/internal/services/auth/handler_integration_test.goindex 0630566437..635f35bd96 100644--- a/backend-go/internal/services/auth/handler_integration_test.go+++ b/backend-go/internal/services/auth/handler_integration_test.go@@ -20,14 +20,14 @@ import ("github.com/infisical/api/internal/keystore""github.com/infisical/api/internal/libs/errutil"- "github.com/infisical/api/internal/services/actor""github.com/infisical/api/internal/services/auth"+ "github.com/infisical/api/internal/services/auth/apiauth""github.com/infisical/api/internal/testutil/infra")var (stack *infra.Stack- authenticator auth.Authenticator+ authenticator apiauth.AuthenticatormemKeyStore *keystore.MemoryKeyStore)@@ -39,7 +39,7 @@ func TestMain(m *testing.M) {MustStart()memKeyStore = keystore.NewMemoryKeyStore()- authenticator = auth.NewAuthenticator(stack.DB(), infra.AuthSecret, memKeyStore)+ authenticator = apiauth.NewAuthenticator(stack.DB(), infra.AuthSecret, memKeyStore)code := m.Run()stack.Stop()@@ -50,9 +50,9 @@ func TestMain(m *testing.M) {// JWT Signing Helpers// =============================================================================-func signUserJWT(t *testing.T, secret string, mut func(*auth.UserJWTClaims)) string {+func signUserJWT(t *testing.T, secret string, mut func(*apiauth.UserJWTClaims)) string {t.Helper()- claims := &auth.UserJWTClaims{+ claims := &apiauth.UserJWTClaims{AuthTokenType: auth.AuthTokenTypeAccessToken,UserID: uuid.MustParse(stack.NodeJS().UserID()),TokenVersionID: uuid.New(),@@ -72,9 +72,9 @@ func signUserJWT(t *testing.T, secret string, mut func(*auth.UserJWTClaims)) strreturn tokenString}-func signIdentityJWT(t *testing.T, secret string, mut func(*auth.IdentityJWTClaims)) string {+func signIdentityJWT(t *testing.T, secret string, mut func(*apiauth.IdentityJWTClaims)) string {t.Helper()- claims := &auth.IdentityJWTClaims{+ claims := &apiauth.IdentityJWTClaims{AuthTokenType: auth.AuthTokenTypeIdentityAccessToken,IdentityID: uuid.New(),IdentityAccessTokenID: uuid.New().String(),@@ -136,7 +136,7 @@ func TestJWTAuth_UserToken_Valid(t *testing.T) {identity := auth.IdentityFromContext(ctx)require.NotNil(t, identity)assert.Equal(t, auth.AuthModeJWT, identity.AuthMode)- assert.Equal(t, actor.TypeUser, identity.Actor)+ assert.Equal(t, auth.ActorTypeUser, identity.Actor)assert.Equal(t, uuid.MustParse(stack.NodeJS().UserID()), identity.ActorID)assert.Equal(t, uuid.MustParse(stack.NodeJS().OrgID()), identity.OrgID)// Verify user-specific fields are populated@@ -173,7 +173,7 @@ func TestJWTAuth_UserToken_Errors(t *testing.T) {{name: "expired token",token: func(t *testing.T) string {- return signUserJWT(t, infra.AuthSecret, func(c *auth.UserJWTClaims) {+ return signUserJWT(t, infra.AuthSecret, func(c *apiauth.UserJWTClaims) {c.ExpiresAt = jwt.NewNumericDate(time.Now().Add(-time.Hour))})},@@ -185,7 +185,7 @@ func TestJWTAuth_UserToken_Errors(t *testing.T) {{name: "wrong auth token type",token: func(t *testing.T) string {- return signUserJWT(t, infra.AuthSecret, func(c *auth.UserJWTClaims) {+ return signUserJWT(t, infra.AuthSecret, func(c *apiauth.UserJWTClaims) {c.AuthTokenType = "wrong-type"})},@@ -196,7 +196,7 @@ func TestJWTAuth_UserToken_Errors(t *testing.T) {{name: "session not found",token: func(t *testing.T) string {- return signUserJWT(t, infra.AuthSecret, func(c *auth.UserJWTClaims) {+ return signUserJWT(t, infra.AuthSecret, func(c *apiauth.UserJWTClaims) {c.TokenVersionID = uuid.New() // non-existent session})},@@ -208,7 +208,7 @@ func TestJWTAuth_UserToken_Errors(t *testing.T) {{name: "user not found",token: func(t *testing.T) string {- return signUserJWT(t, infra.AuthSecret, func(c *auth.UserJWTClaims) {+ return signUserJWT(t, infra.AuthSecret, func(c *apiauth.UserJWTClaims) {c.UserID = uuid.New() // non-existent user})},@@ -247,7 +247,7 @@ func TestJWTAuth_UserToken_StaleAccessVersion(t *testing.T) {})// Create token with access_version = 1 (stale)- token := signUserJWT(t, infra.AuthSecret, func(c *auth.UserJWTClaims) {+ token := signUserJWT(t, infra.AuthSecret, func(c *apiauth.UserJWTClaims) {c.TokenVersionID = sessionIDc.AccessVersion = 1 // Different from DB's 5})@@ -262,10 +262,11 @@ func TestJWTAuth_UserToken_StaleAccessVersion(t *testing.T) {func TestJWTAuth_UserToken_UserLocked(t *testing.T) {// Create a user that is permanently lockedlockedUserID := uuid.New()+ testEmail := "locked-" + uuid.New().String() + "@test.com"_, err := stack.DB().Primary().Exec(context.Background(), `- INSERT INTO users (id, email, "isAccepted", "isLocked", "createdAt", "updatedAt")- VALUES (@userID, @email, true, true, NOW(), NOW())- `, pgx.NamedArgs{"userID": lockedUserID, "email": "locked-" + uuid.New().String() + "@test.com"})+ INSERT INTO users (id, email, username, "isAccepted", "isLocked", "createdAt", "updatedAt")+ VALUES (@userID, @email, @username, true, true, NOW(), NOW())+ `, pgx.NamedArgs{"userID": lockedUserID, "email": testEmail, "username": testEmail})require.NoError(t, err)t.Cleanup(func() {_, _ = stack.DB().Primary().Exec(context.Background(),@@ -286,7 +287,7 @@ func TestJWTAuth_UserToken_UserLocked(t *testing.T) {pgx.NamedArgs{"sessionID": sessionID})})- token := signUserJWT(t, infra.AuthSecret, func(c *auth.UserJWTClaims) {+ token := signUserJWT(t, infra.AuthSecret, func(c *apiauth.UserJWTClaims) {c.UserID = lockedUserIDc.TokenVersionID = sessionIDc.AccessVersion = 1@@ -301,11 +302,12 @@ func TestJWTAuth_UserToken_UserLocked(t *testing.T) {func TestJWTAuth_UserToken_UserTemporarilyLocked(t *testing.T) {// Create a user that is temporarily locked (lock expires in the future)tempLockedUserID := uuid.New()+ testEmail := "templocked-" + uuid.New().String() + "@test.com"lockEnd := time.Now().Add(time.Hour) // Locked for another hour_, err := stack.DB().Primary().Exec(context.Background(), `- INSERT INTO users (id, email, "isAccepted", "temporaryLockDateEnd", "createdAt", "updatedAt")- VALUES (@userID, @email, true, @lockEnd, NOW(), NOW())- `, pgx.NamedArgs{"userID": tempLockedUserID, "email": "templocked-" + uuid.New().String() + "@test.com", "lockEnd": lockEnd})+ INSERT INTO users (id, email, username, "isAccepted", "temporaryLockDateEnd", "createdAt", "updatedAt")+ VALUES (@userID, @email, @username, true, @lockEnd, NOW(), NOW())+ `, pgx.NamedArgs{"userID": tempLockedUserID, "email": testEmail, "username": testEmail, "lockEnd": lockEnd})require.NoError(t, err)t.Cleanup(func() {_, _ = stack.DB().Primary().Exec(context.Background(),@@ -326,7 +328,7 @@ func TestJWTAuth_UserToken_UserTemporarilyLocked(t *testing.T) {pgx.NamedArgs{"sessionID": sessionID})})- token := signUserJWT(t, infra.AuthSecret, func(c *auth.UserJWTClaims) {+ token := signUserJWT(t, infra.AuthSecret, func(c *apiauth.UserJWTClaims) {c.UserID = tempLockedUserIDc.TokenVersionID = sessionIDc.AccessVersion = 1@@ -341,10 +343,11 @@ func TestJWTAuth_UserToken_UserTemporarilyLocked(t *testing.T) {func TestJWTAuth_UserToken_UserNotAccepted(t *testing.T) {// Create a user that has not acceptednotAcceptedUserID := uuid.New()+ testEmail := "notaccepted-" + uuid.New().String() + "@test.com"_, err := stack.DB().Primary().Exec(context.Background(), `- INSERT INTO users (id, email, "isAccepted", "createdAt", "updatedAt")- VALUES (@userID, @email, false, NOW(), NOW())- `, pgx.NamedArgs{"userID": notAcceptedUserID, "email": "notaccepted-" + uuid.New().String() + "@test.com"})+ INSERT INTO users (id, email, username, "isAccepted", "createdAt", "updatedAt")+ VALUES (@userID, @email, @username, false, NOW(), NOW())+ `, pgx.NamedArgs{"userID": notAcceptedUserID, "email": testEmail, "username": testEmail})require.NoError(t, err)t.Cleanup(func() {_, _ = stack.DB().Primary().Exec(context.Background(),@@ -365,7 +368,7 @@ func TestJWTAuth_UserToken_UserNotAccepted(t *testing.T) {pgx.NamedArgs{"sessionID": sessionID})})- token := signUserJWT(t, infra.AuthSecret, func(c *auth.UserJWTClaims) {+ token := signUserJWT(t, infra.AuthSecret, func(c *apiauth.UserJWTClaims) {c.UserID = notAcceptedUserIDc.TokenVersionID = sessionIDc.AccessVersion = 1@@ -389,7 +392,7 @@ func TestJWTAuth_IdentityToken_Valid(t *testing.T) {identity := auth.IdentityFromContext(ctx)require.NotNil(t, identity)assert.Equal(t, auth.AuthModeIdentityAccessToken, identity.AuthMode)- assert.Equal(t, actor.TypeIdentity, identity.Actor)+ assert.Equal(t, auth.ActorTypeIdentity, identity.Actor)assert.NotEqual(t, uuid.Nil, identity.ActorID)assert.Equal(t, uuid.MustParse(stack.NodeJS().OrgID()), identity.OrgID)// Verify identity-specific fields@@ -415,7 +418,7 @@ func TestJWTAuth_IdentityToken_Errors(t *testing.T) {{name: "expired token",token: func(t *testing.T) string {- return signIdentityJWT(t, infra.AuthSecret, func(c *auth.IdentityJWTClaims) {+ return signIdentityJWT(t, infra.AuthSecret, func(c *apiauth.IdentityJWTClaims) {c.ExpiresAt = jwt.NewNumericDate(time.Now().Add(-time.Hour))})},@@ -426,7 +429,7 @@ func TestJWTAuth_IdentityToken_Errors(t *testing.T) {{name: "wrong auth token type",token: func(t *testing.T) string {- return signIdentityJWT(t, infra.AuthSecret, func(c *auth.IdentityJWTClaims) {+ return signIdentityJWT(t, infra.AuthSecret, func(c *apiauth.IdentityJWTClaims) {c.AuthTokenType = "wrong-type"})},@@ -437,13 +440,13 @@ func TestJWTAuth_IdentityToken_Errors(t *testing.T) {{name: "token not found in DB (legacy path)",token: func(t *testing.T) string {- return signIdentityJWT(t, infra.AuthSecret, func(c *auth.IdentityJWTClaims) {+ return signIdentityJWT(t, infra.AuthSecret, func(c *apiauth.IdentityJWTClaims) {c.IdentityAccessTokenID = uuid.New().String()})},assertError: func(t *testing.T, err error) {assertUnauthorized(t, err)- assert.Contains(t, err.Error(), "No identity access token found")+ assert.Contains(t, err.Error(), "Cannot renew revoked or unknown access token")},},}@@ -478,7 +481,7 @@ func TestJWTAuth_IdentityToken_CustomIdentity(t *testing.T) {authIdentity := auth.IdentityFromContext(ctx)require.NotNil(t, authIdentity)assert.Equal(t, auth.AuthModeIdentityAccessToken, authIdentity.AuthMode)- assert.Equal(t, actor.TypeIdentity, authIdentity.Actor)+ assert.Equal(t, auth.ActorTypeIdentity, authIdentity.Actor)assert.Equal(t, uuid.MustParse(identity.ID), authIdentity.ActorID)}@@ -593,7 +596,7 @@ func TestJWTAuth_ServiceToken_Valid(t *testing.T) {identity := auth.IdentityFromContext(ctx)require.NotNil(t, identity)assert.Equal(t, auth.AuthModeServiceToken, identity.AuthMode)- assert.Equal(t, actor.TypeService, identity.Actor)+ assert.Equal(t, auth.ActorTypeService, identity.Actor)assert.Equal(t, st.ID, identity.ActorID.String())}@@ -637,10 +640,7 @@ func TestJWTAuth_ServiceToken_Expired(t *testing.T) {// Create a service token that expires in 1 secondexpiresIn := 1st := nodejs.CreateServiceToken(t, proj.ID, "dev", &expiresIn)- t.Cleanup(func() {- // Token may be auto-deleted when expired, ignore errors- nodejs.DeleteServiceToken(t, st.ID)- })+ // No cleanup needed - token is auto-deleted when expired// Wait for expirationtime.Sleep(2 * time.Second)@@ -673,7 +673,7 @@ func TestJWTAuth_IdentityToken_NumUsesLimitExhausted(t *testing.T) {token := nodejs.GetIdentityAccessToken(t, identity.ID)// Parse to get token ID- claims := &auth.IdentityJWTClaims{}+ claims := &apiauth.IdentityJWTClaims{}_, _ = jwt.ParseWithClaims(token, claims, func(_ *jwt.Token) (any, error) {return []byte(infra.AuthSecret), nil})@@ -690,7 +690,7 @@ func TestJWTAuth_IdentityToken_NumUsesLimitExhausted(t *testing.T) {// Create a new authenticator that checks numUsesLimit// We need to sign a token WITH numUsesLimit claim- tokenWithLimit := signIdentityJWT(t, infra.AuthSecret, func(c *auth.IdentityJWTClaims) {+ tokenWithLimit := signIdentityJWT(t, infra.AuthSecret, func(c *apiauth.IdentityJWTClaims) {c.IdentityID = uuid.MustParse(identity.ID)c.OrgID = uuid.MustParse(stack.NodeJS().OrgID())c.RootOrgID = uuid.MustParse(stack.NodeJS().OrgID())@@ -704,7 +704,7 @@ func TestJWTAuth_IdentityToken_NumUsesLimitExhausted(t *testing.T) {_, err = authenticator.JWTAuth(context.Background(), tokenWithLimit, &security.JWTScheme{Name: "identity_access_token"})assertUnauthorized(t, err)- assert.Contains(t, err.Error(), "exceeded")+ assert.Contains(t, err.Error(), "usage limit")}// =============================================================================@@ -726,7 +726,7 @@ func TestJWTAuth_UserToken_AlgNoneAttack(t *testing.T) {func TestJWTAuth_UserToken_WrongAlgorithm(t *testing.T) {// Try to use RS256 when the server expects HS256// This tests that the server properly validates the algorithm- token := jwt.NewWithClaims(jwt.SigningMethodHS384, &auth.UserJWTClaims{+ token := jwt.NewWithClaims(jwt.SigningMethodHS384, &apiauth.UserJWTClaims{AuthTokenType: auth.AuthTokenTypeAccessToken,UserID: uuid.MustParse(stack.NodeJS().UserID()),TokenVersionID: uuid.New(),@@ -785,7 +785,7 @@ func TestJWTAuth_IdentityToken_LegacyRevoked(t *testing.T) {})// Create a legacy token (no full renew claims) pointing to this DB row- legacyToken := signIdentityJWT(t, infra.AuthSecret, func(c *auth.IdentityJWTClaims) {+ legacyToken := signIdentityJWT(t, infra.AuthSecret, func(c *apiauth.IdentityJWTClaims) {c.IdentityID = identityIDc.IdentityAccessTokenID = tokenID.String()// Don't set OrgID, RootOrgID, ParentOrgID, AuthMethod, AccessTokenTTLdiff --git a/backend-go/internal/services/permission/permission.go b/backend-go/internal/services/permission/permission.goindex 79fa64e0cf..45a9299dfd 100644--- a/backend-go/internal/services/permission/permission.go+++ b/backend-go/internal/services/permission/permission.go@@ -17,25 +17,10 @@ import ("github.com/infisical/api/internal/database/pg/sqln""github.com/infisical/api/internal/libs/errutil""github.com/infisical/api/internal/libs/fn"- "github.com/infisical/api/internal/services/actor"+ "github.com/infisical/api/internal/services/auth""github.com/infisical/api/internal/services/permission/project")-// ActorType identifies the kind of entity performing an action.-// Type alias for actor.Type for backward compatibility.-type ActorType = actor.Type--const (- ActorTypeUser ActorType = actor.TypeUser- ActorTypeIdentity ActorType = actor.TypeIdentity- ActorTypeService ActorType = actor.TypeService-)--// ActorAuthMethod represents the authentication method used by the actor (e.g. "jwt", "api-key").-// An empty string means no specific method (e.g. platform-level actions).-// Type alias for actor.AuthMethod for backward compatibility.-type ActorAuthMethod = actor.AuthMethod-// ActionProjectType scopes the permission check to a specific project type.type ActionProjectType string@@ -50,10 +35,10 @@ const (// GetProjectPermissionArgs holds the input for a project-level permission check.type GetProjectPermissionArgs struct {- Actor ActorType+ Actor auth.ActorTypeActorID uuid.UUIDProjectID string // text in DB- ActorAuthMethod ActorAuthMethod+ ActorAuthMethod auth.ActorAuthMethodActorOrgID uuid.UUIDActionProjectType ActionProjectType}@@ -117,7 +102,7 @@ func NewService(logger *slog.Logger, deps *Deps) *Service {// Exact port of permission-service.ts:403-573.func (p *Service) GetProjectPermission(ctx context.Context, args *GetProjectPermissionArgs) (*GetProjectPermissionResult, error) {// 1. SERVICE actor → delegate to service token path- if args.Actor == ActorTypeService {+ if args.Actor == auth.ActorTypeService {return p.getServiceTokenProjectPermission(ctx, args.ActorID.String(), args.ProjectID, args.ActorOrgID, args.ActionProjectType)}@@ -129,7 +114,7 @@ func (p *Service) GetProjectPermission(ctx context.Context, args *GetProjectPerm// - Swap actor/actorId if assumption is valid// 3. Validate actor type- if args.Actor != ActorTypeUser && args.Actor != ActorTypeIdentity {+ if args.Actor != auth.ActorTypeUser && args.Actor != auth.ActorTypeIdentity {return nil, errutil.BadRequest("Invalid actor provided").WithErrf("GetProjectPermission: unsupported actor type %s", args.Actor)}@@ -196,7 +181,7 @@ func (p *Service) GetProjectPermission(ctx context.Context, args *GetProjectPerm// Implementation requires:// - validateOrgSSO function checking orgAuthEnforced, googleSsoAuthEnforced, bypassOrgAuthEnabled// - Org-level permission check for SSO bypass capability- // - Only applies to ActorTypeUser+ // - Only applies to auth.ActorTypeUser// 11. Build rulesrules, parseErrors := buildProjectPermissionRules(permissionFromRoles)@@ -214,7 +199,7 @@ func (p *Service) GetProjectPermission(ctx context.Context, args *GetProjectPerm// 13. Fetch usernamevar username string- if args.Actor == ActorTypeUser {+ if args.Actor == auth.ActorTypeUser {username, err = p.findUserUsername(ctx, args.ActorID)if err != nil {return nil, errutil.DatabaseErr("finding user username").WithErrf("GetProjectPermission(userId=%s): %w", args.ActorID, err)@@ -419,7 +404,7 @@ func checkProjectEnforcement(projectDetails *projectDetail) func(string) bool {// for use in permission template variable interpolation.// Port of permission-service.ts:528-532.func buildIdentityAuthMap(ctx context.Context, actorID uuid.UUID) map[string]any {- authInfo := actor.AuthInfoFromContext(ctx)+ authInfo := auth.AuthInfoFromContext(ctx)if authInfo == nil {return map[string]any{}}@@ -472,7 +457,7 @@ type getPermissionParams struct {OrgID uuid.UUIDProjectID stringActorID uuid.UUID- ActorType ActorType+ ActorType auth.ActorType}// RoleInfo represents a single role assignment from the permission query.@@ -555,7 +540,7 @@ var permissionGrouper = sqln.Grouper[permissionData, uuid.UUID]{func (s *Service) getPermission(ctx context.Context, params *getPermissionParams) ([]permissionData, error) {// Build actor subquery for group membershipvar groupSubquery string- if params.ActorType == ActorTypeUser {+ if params.ActorType == auth.ActorTypeUser {groupSubquery = `SELECT grp.id FROM groups grpINNER JOIN user_group_membership ugm ON ugm."groupId" = grp.id@@ -573,7 +558,7 @@ func (s *Service) getPermission(ctx context.Context, params *getPermissionParamswhere := qb.NewWhere().Add(`membership."scopeOrgId" = @orgID`)// Actor condition- if params.ActorType == ActorTypeUser {+ if params.ActorType == auth.ActorTypeUser {where.Add(`(membership."actorUserId" = @actorID OR membership."actorGroupId" IN (` + groupSubquery + `))`)} else {where.Add(`(membership."actorIdentityId" = @actorID OR membership."actorGroupId" IN (` + groupSubquery + `))`)@@ -588,7 +573,7 @@ func (s *Service) getPermission(ctx context.Context, params *getPermissionParams// Build additional privilege join conditionapJoinCond := qb.NewWhere()- if params.ActorType == ActorTypeIdentity {+ if params.ActorType == auth.ActorTypeIdentity {apJoinCond.Add(`membership."actorIdentityId" = addlPriv."actorIdentityId"`)} else {apJoinCond.Add(`membership."actorUserId" = addlPriv."actorUserId"`)@@ -601,7 +586,7 @@ func (s *Service) getPermission(ctx context.Context, params *getPermissionParams// Build metadata join conditionmetaJoinCond := qb.NewWhere()- if params.ActorType == ActorTypeUser {+ if params.ActorType == auth.ActorTypeUser {metaJoinCond.Add(`identityMeta."userId" = @actorID`).Add(`membership."scopeOrgId" = identityMeta."orgId"`)} else {metaJoinCond.Add(`identityMeta."identityId" = @actorID`)diff --git a/backend-go/internal/services/permission/permission_integration_test.go b/backend-go/internal/services/permission/permission_integration_test.goindex ceb66b3be3..ea4049c2c0 100644--- a/backend-go/internal/services/permission/permission_integration_test.go+++ b/backend-go/internal/services/permission/permission_integration_test.go@@ -13,6 +13,7 @@ import ("github.com/stretchr/testify/assert""github.com/stretchr/testify/require"+ "github.com/infisical/api/internal/services/auth""github.com/infisical/api/internal/services/permission""github.com/infisical/api/internal/services/permission/project""github.com/infisical/api/internal/testutil"@@ -42,7 +43,7 @@ func newPermissionService() *permission.Service {return permission.NewService(testutil.NopLogger(), &permission.Deps{DB: stack.DB()})}-func getProjectPermission(t *testing.T, actorType permission.ActorType, actorID string) *permission.GetProjectPermissionResult {+func getProjectPermission(t *testing.T, actorType auth.ActorType, actorID string) *permission.GetProjectPermissionResult {t.Helper()ctx := context.Background()svc := newPermissionService()@@ -69,7 +70,7 @@ func TestIdentityAdmin_CanDoEverything(t *testing.T) {identity := nodejs.CreateIdentity(t, "admin-identity")nodejs.AddIdentityToProject(t, proj.ID, identity.ID, infra.Role("admin"))- result := getProjectPermission(t, permission.ActorTypeIdentity, identity.ID)+ result := getProjectPermission(t, auth.ActorTypeIdentity, identity.ID)ability := result.Permission.Ability// Secrets CRUD@@ -117,7 +118,7 @@ func TestIdentityMember_LimitedAccess(t *testing.T) {identity := nodejs.CreateIdentity(t, "member-identity")nodejs.AddIdentityToProject(t, proj.ID, identity.ID, infra.Role("member"))- result := getProjectPermission(t, permission.ActorTypeIdentity, identity.ID)+ result := getProjectPermission(t, auth.ActorTypeIdentity, identity.ID)ability := result.Permission.Ability// Members CAN read/create/edit/delete secrets@@ -147,7 +148,7 @@ func TestIdentityViewer_ReadOnly(t *testing.T) {identity := nodejs.CreateIdentity(t, "viewer-identity")nodejs.AddIdentityToProject(t, proj.ID, identity.ID, infra.Role("viewer"))- result := getProjectPermission(t, permission.ActorTypeIdentity, identity.ID)+ result := getProjectPermission(t, auth.ActorTypeIdentity, identity.ID)ability := result.Permission.Ability// Viewers CAN read (viewer has describeSecret + readValue, not the combined "read" action)@@ -193,7 +194,7 @@ func TestIdentityNoAccess_DeniedEverything(t *testing.T) {identity := nodejs.CreateIdentity(t, "no-access-identity")nodejs.AddIdentityToProject(t, proj.ID, identity.ID, infra.Role("no-access"))- result := getProjectPermission(t, permission.ActorTypeIdentity, identity.ID)+ result := getProjectPermission(t, auth.ActorTypeIdentity, identity.ID)ability := result.Permission.Ability// No-access CANNOT do anything@@ -217,7 +218,7 @@ func TestIdentityNotMember_Forbidden(t *testing.T) {svc := newPermissionService()_, err := svc.GetProjectPermission(ctx, &permission.GetProjectPermissionArgs{- Actor: permission.ActorTypeIdentity,+ Actor: auth.ActorTypeIdentity,ActorID: uuid.MustParse(identity.ID),ProjectID: proj.ID,ActorAuthMethod: "",@@ -237,7 +238,7 @@ func TestUserAdmin_CanDoEverything(t *testing.T) {user := nodejs.InviteAndCreateUser(t, "[email protected]")nodejs.AddUserToProject(t, proj.ID, user.Email, []string{"admin"})- result := getProjectPermission(t, permission.ActorTypeUser, user.ID)+ result := getProjectPermission(t, auth.ActorTypeUser, user.ID)ability := result.Permission.Ability// Admin can do everything@@ -259,7 +260,7 @@ func TestUserViewer_ReadOnly(t *testing.T) {user := nodejs.InviteAndCreateUser(t, "[email protected]")nodejs.AddUserToProject(t, proj.ID, user.Email, []string{"viewer"})- result := getProjectPermission(t, permission.ActorTypeUser, user.ID)+ result := getProjectPermission(t, auth.ActorTypeUser, user.ID)ability := result.Permission.Ability// Can read (viewer has describeSecret + readValue, not combined "read")@@ -291,7 +292,7 @@ func TestWrongOrgID_Forbidden(t *testing.T) {fakeOrgID := uuid.New()_, err := svc.GetProjectPermission(ctx, &permission.GetProjectPermissionArgs{- Actor: permission.ActorTypeIdentity,+ Actor: auth.ActorTypeIdentity,ActorID: uuid.MustParse(identity.ID),ProjectID: proj.ID,ActorAuthMethod: "",@@ -312,7 +313,7 @@ func TestWrongProjectType_BadRequest(t *testing.T) {// Project is secret-manager, but we request certificate-manager_, err := svc.GetProjectPermission(ctx, &permission.GetProjectPermissionArgs{- Actor: permission.ActorTypeIdentity,+ Actor: auth.ActorTypeIdentity,ActorID: uuid.MustParse(identity.ID),ProjectID: proj.ID,ActorAuthMethod: "",@@ -328,13 +329,13 @@ func TestProjectTypeAny_Allowed(t *testing.T) {identity := nodejs.CreateIdentity(t, "any-type-identity")nodejs.AddIdentityToProject(t, proj.ID, identity.ID, infra.Role("viewer"))- result := getProjectPermission(t, permission.ActorTypeIdentity, identity.ID)+ result := getProjectPermission(t, auth.ActorTypeIdentity, identity.ID)// ActionProjectTypeAny is used by getProjectPermission helper via ActionProjectTypeSecretManager,// but let's test Any explicitlyctx := context.Background()svc := newPermissionService()resultAny, err := svc.GetProjectPermission(ctx, &permission.GetProjectPermissionArgs{- Actor: permission.ActorTypeIdentity,+ Actor: auth.ActorTypeIdentity,ActorID: uuid.MustParse(identity.ID),ProjectID: proj.ID,ActorAuthMethod: "",@@ -361,7 +362,7 @@ func TestNonExistentProject_NotFound(t *testing.T) {svc := newPermissionService()_, err := svc.GetProjectPermission(ctx, &permission.GetProjectPermissionArgs{- Actor: permission.ActorTypeIdentity,+ Actor: auth.ActorTypeIdentity,ActorID: uuid.MustParse(identity.ID),ProjectID: "non-existent-project-id",ActorAuthMethod: "",@@ -381,7 +382,7 @@ func TestMemberships_ReturnedCorrectly(t *testing.T) {identity := nodejs.CreateIdentity(t, "membership-check-identity")nodejs.AddIdentityToProject(t, proj.ID, identity.ID, infra.Role("member"))- result := getProjectPermission(t, permission.ActorTypeIdentity, identity.ID)+ result := getProjectPermission(t, auth.ActorTypeIdentity, identity.ID)require.NotEmpty(t, result.Memberships, "memberships should not be empty")assert.True(t, result.HasRole("member"))@@ -398,7 +399,7 @@ func TestHasProjectEnforcement_ReturnsFunction(t *testing.T) {identity := nodejs.CreateIdentity(t, "enforcement-identity")nodejs.AddIdentityToProject(t, proj.ID, identity.ID, infra.Role("viewer"))- result := getProjectPermission(t, permission.ActorTypeIdentity, identity.ID)+ result := getProjectPermission(t, auth.ActorTypeIdentity, identity.ID)require.NotNil(t, result.HasProjectEnforcement)// Default project should not have encrypted metadata enforcement@@ -425,7 +426,7 @@ func TestIdentityCustomRole_SecretsReadCreateOnly(t *testing.T) {identity := nodejs.CreateIdentity(t, "custom-role-identity")nodejs.AddIdentityToProject(t, proj.ID, identity.ID, infra.Role(customRole.Slug))- result := getProjectPermission(t, permission.ActorTypeIdentity, identity.ID)+ result := getProjectPermission(t, auth.ActorTypeIdentity, identity.ID)ability := result.Permission.Ability// CAN read and create secrets@@ -461,7 +462,7 @@ func TestUserCustomRole_SecretsReadCreateOnly(t *testing.T) {user := nodejs.InviteAndCreateUser(t, "[email protected]")nodejs.AddUserToProject(t, proj.ID, user.Email, []string{customRole.Slug})- result := getProjectPermission(t, permission.ActorTypeUser, user.ID)+ result := getProjectPermission(t, auth.ActorTypeUser, user.ID)ability := result.Permission.Ability// CAN read and create secrets@@ -497,7 +498,7 @@ func TestIdentityCustomRole_EnvironmentScoped(t *testing.T) {identity := nodejs.CreateIdentity(t, "env-scoped-identity")nodejs.AddIdentityToProject(t, proj.ID, identity.ID, infra.Role(customRole.Slug))- result := getProjectPermission(t, permission.ActorTypeIdentity, identity.ID)+ result := getProjectPermission(t, auth.ActorTypeIdentity, identity.ID)ability := result.Permission.Ability// CAN read secrets in "dev" environment@@ -535,7 +536,7 @@ func TestIdentityCustomRole_GlobSecretPath(t *testing.T) {identity := nodejs.CreateIdentity(t, "glob-path-identity")nodejs.AddIdentityToProject(t, proj.ID, identity.ID, infra.Role(customRole.Slug))- result := getProjectPermission(t, permission.ActorTypeIdentity, identity.ID)+ result := getProjectPermission(t, auth.ActorTypeIdentity, identity.ID)ability := result.Permission.Ability// CAN read secrets under /app/@@ -562,7 +563,7 @@ func TestGroupAdmin_UserInheritsFullAccess(t *testing.T) {nodejs.AddUserToGroup(t, group.ID, user.Email)nodejs.AddGroupToProject(t, proj.ID, group.ID, "admin")- result := getProjectPermission(t, permission.ActorTypeUser, user.ID)+ result := getProjectPermission(t, auth.ActorTypeUser, user.ID)ability := result.Permission.Ability// User inherits admin permissions through group@@ -585,7 +586,7 @@ func TestGroupViewer_UserInheritsReadOnly(t *testing.T) {nodejs.AddUserToGroup(t, group.ID, user.Email)nodejs.AddGroupToProject(t, proj.ID, group.ID, "viewer")- result := getProjectPermission(t, permission.ActorTypeUser, user.ID)+ result := getProjectPermission(t, auth.ActorTypeUser, user.ID)ability := result.Permission.Ability// User inherits viewer permissions through group (describeSecret + readValue, not combined "read")@@ -620,7 +621,7 @@ func TestGroupCustomRole_UserInheritsCustomPermissions(t *testing.T) {nodejs.AddUserToGroup(t, group.ID, user.Email)nodejs.AddGroupToProject(t, proj.ID, group.ID, customRole.Slug)- result := getProjectPermission(t, permission.ActorTypeUser, user.ID)+ result := getProjectPermission(t, auth.ActorTypeUser, user.ID)ability := result.Permission.Ability// CAN read secrets and folders through group's custom role@@ -654,7 +655,7 @@ func TestGroupNotMember_UserDenied(t *testing.T) {svc := newPermissionService()_, err := svc.GetProjectPermission(ctx, &permission.GetProjectPermissionArgs{- Actor: permission.ActorTypeUser,+ Actor: auth.ActorTypeUser,ActorID: uuid.MustParse(user.ID),ProjectID: proj.ID,ActorAuthMethod: "",@@ -682,7 +683,7 @@ func TestIdentityAdditionalPrivilege_ExtendsRole(t *testing.T) {},}, nil)- result := getProjectPermission(t, permission.ActorTypeIdentity, identity.ID)+ result := getProjectPermission(t, auth.ActorTypeIdentity, identity.ID)ability := result.Permission.Ability// Base viewer permissions still work@@ -714,7 +715,7 @@ func TestIdentityAdditionalPrivilege_WithConditions(t *testing.T) {},}, nil)- result := getProjectPermission(t, permission.ActorTypeIdentity, identity.ID)+ result := getProjectPermission(t, auth.ActorTypeIdentity, identity.ID)ability := result.Permission.Ability// CAN read secrets in dev via additional privilege@@ -748,7 +749,7 @@ func TestUserAdditionalPrivilege_ExtendsRole(t *testing.T) {// Use testProj.ID instead of the shared proj.IDsvc := newPermissionService()result, err := svc.GetProjectPermission(context.Background(), &permission.GetProjectPermissionArgs{- Actor: permission.ActorTypeUser,+ Actor: auth.ActorTypeUser,ActorID: uuid.MustParse(user.ID),ProjectID: testProj.ID,ActorAuthMethod: "",@@ -790,7 +791,7 @@ func TestIdentityMultipleAdditionalPrivileges_Merge(t *testing.T) {},}, nil)- result := getProjectPermission(t, permission.ActorTypeIdentity, identity.ID)+ result := getProjectPermission(t, auth.ActorTypeIdentity, identity.ID)ability := result.Permission.Ability// Both additional privileges are merged@@ -825,7 +826,7 @@ func TestIdentityTemporaryRole_ActiveGrantsAccess(t *testing.T) {},})- result := getProjectPermission(t, permission.ActorTypeIdentity, identity.ID)+ result := getProjectPermission(t, auth.ActorTypeIdentity, identity.ID)ability := result.Permission.Ability// Active temporary admin role grants full access@@ -859,7 +860,7 @@ func TestIdentityTemporaryRole_ExpiredDeniesAccess(t *testing.T) {ctx := context.Background()svc := newPermissionService()result, err := svc.GetProjectPermission(ctx, &permission.GetProjectPermissionArgs{- Actor: permission.ActorTypeIdentity,+ Actor: auth.ActorTypeIdentity,ActorID: uuid.MustParse(identity.ID),ProjectID: proj.ID,ActorAuthMethod: "",@@ -895,7 +896,7 @@ func TestIdentityTemporaryRole_MixedWithPermanent(t *testing.T) {},})- result := getProjectPermission(t, permission.ActorTypeIdentity, identity.ID)+ result := getProjectPermission(t, auth.ActorTypeIdentity, identity.ID)ability := result.Permission.Ability// Permanent viewer permissions still work@@ -925,7 +926,7 @@ func TestIdentityTemporaryAdditionalPrivilege_ActiveGrantsAccess(t *testing.T) {},}, &infra.IdentityPrivilegeOpts{TemporaryRange: "1h", TemporaryAccessStartTime: time.Now().UTC().Format(time.RFC3339)})- result := getProjectPermission(t, permission.ActorTypeIdentity, identity.ID)+ result := getProjectPermission(t, auth.ActorTypeIdentity, identity.ID)ability := result.Permission.Ability// Active temporary additional privilege grants read@@ -948,7 +949,7 @@ func TestIdentityTemporaryAdditionalPrivilege_ExpiredDeniesAccess(t *testing.T)},}, &infra.IdentityPrivilegeOpts{TemporaryRange: "1h", TemporaryAccessStartTime: time.Now().Add(-2 * time.Hour).UTC().Format(time.RFC3339)})- result := getProjectPermission(t, permission.ActorTypeIdentity, identity.ID)+ result := getProjectPermission(t, auth.ActorTypeIdentity, identity.ID)ability := result.Permission.Ability// Expired temporary additional privilege grants nothing (base role is no-access)diff --git a/backend-go/internal/services/secretmanager/secret/list_secrets.go b/backend-go/internal/services/secretmanager/secret/list_secrets.goindex b1ac3d1801..7a2df09672 100644--- a/backend-go/internal/services/secretmanager/secret/list_secrets.go+++ b/backend-go/internal/services/secretmanager/secret/list_secrets.go@@ -27,18 +27,18 @@ const (// ListSecretsOpts contains options for listing secrets.// Note: Imports are always loaded and included in the result.type ListSecretsOpts struct {- ProjectID string- Environment string- SecretPath string- UserID *uuid.UUID- ViewSecretValue bool- ExpandSecretReferences bool- Recursive bool- PersonalOverridesBehavior PersonalOverridesBehavior- ExpandPersonalOverrides bool- TagSlugs []string- MetadataFilter []MetadataFilter- Access AccessControl+ ProjectID string+ Environment string+ SecretPath string+ UserID *uuid.UUID+ ViewSecretValue bool+ ExpandSecretReferences bool+ Recursive bool+ PersonalOverridesBehavior PersonalOverridesBehavior+ ExpandPersonalOverrides bool+ TagSlugs []string+ MetadataFilter []MetadataFilter+ Access AccessControlThrowOnMissingReadValuePermission bool}