Skip to content

Commit 68a5ae0

Browse files
Merge branch 'main' of https://github.com/Infisical/infisical into chore/unify-license-key
2 parents b242ec4 + 4bff4ca commit 68a5ae0

File tree

71 files changed

+3264
-1413
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+3264
-1413
lines changed

backend/package-lock.json

Lines changed: 72 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
"@types/resolve": "^1.20.6",
111111
"@types/safe-regex": "^1.1.6",
112112
"@types/sjcl": "^1.0.34",
113+
"@types/ssh2": "^1.15.5",
113114
"@types/uuid": "^9.0.7",
114115
"@typescript-eslint/eslint-plugin": "^6.20.0",
115116
"@typescript-eslint/parser": "^6.20.0",
@@ -257,6 +258,7 @@
257258
"sjcl": "^1.0.8",
258259
"smee-client": "^2.0.0",
259260
"snowflake-sdk": "^1.14.0",
261+
"ssh2": "^1.17.0",
260262
"tedious": "^18.2.1",
261263
"tweetnacl": "^1.0.3",
262264
"tweetnacl-util": "^0.15.1",

backend/src/ee/routes/v1/pam-account-routers/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ import {
99
SanitizedPostgresAccountWithResourceSchema,
1010
UpdatePostgresAccountSchema
1111
} from "@app/ee/services/pam-resource/postgres/postgres-resource-schemas";
12+
import {
13+
CreateSSHAccountSchema,
14+
SanitizedSSHAccountWithResourceSchema,
15+
UpdateSSHAccountSchema
16+
} from "@app/ee/services/pam-resource/ssh/ssh-resource-schemas";
1217

1318
import { registerPamResourceEndpoints } from "./pam-account-endpoints";
1419

@@ -30,5 +35,14 @@ export const PAM_ACCOUNT_REGISTER_ROUTER_MAP: Record<PamResource, (server: Fasti
3035
createAccountSchema: CreateMySQLAccountSchema,
3136
updateAccountSchema: UpdateMySQLAccountSchema
3237
});
38+
},
39+
[PamResource.SSH]: async (server: FastifyZodProvider) => {
40+
registerPamResourceEndpoints({
41+
server,
42+
resourceType: PamResource.SSH,
43+
accountResponseSchema: SanitizedSSHAccountWithResourceSchema,
44+
createAccountSchema: CreateSSHAccountSchema,
45+
updateAccountSchema: UpdateSSHAccountSchema
46+
});
3347
}
3448
};

backend/src/ee/routes/v1/pam-account-routers/pam-account-router.ts

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,21 @@ import { z } from "zod";
22

33
import { PamFoldersSchema } from "@app/db/schemas";
44
import { EventType } from "@app/ee/services/audit-log/audit-log-types";
5+
import { PamAccountOrderBy, PamAccountView } from "@app/ee/services/pam-account/pam-account-enums";
56
import { SanitizedMySQLAccountWithResourceSchema } from "@app/ee/services/pam-resource/mysql/mysql-resource-schemas";
67
import { PamResource } from "@app/ee/services/pam-resource/pam-resource-enums";
78
import { SanitizedPostgresAccountWithResourceSchema } from "@app/ee/services/pam-resource/postgres/postgres-resource-schemas";
9+
import { SanitizedSSHAccountWithResourceSchema } from "@app/ee/services/pam-resource/ssh/ssh-resource-schemas";
810
import { BadRequestError } from "@app/lib/errors";
11+
import { removeTrailingSlash } from "@app/lib/fn";
912
import { ms } from "@app/lib/ms";
13+
import { OrderByDirection } from "@app/lib/types";
1014
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
1115
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
1216
import { AuthMode } from "@app/services/auth/auth-type";
1317

1418
const SanitizedAccountSchema = z.union([
19+
SanitizedSSHAccountWithResourceSchema, // ORDER MATTERS
1520
SanitizedPostgresAccountWithResourceSchema,
1621
SanitizedMySQLAccountWithResourceSchema
1722
]);
@@ -26,33 +31,69 @@ export const registerPamAccountRouter = async (server: FastifyZodProvider) => {
2631
schema: {
2732
description: "List PAM accounts",
2833
querystring: z.object({
29-
projectId: z.string().uuid()
34+
projectId: z.string().uuid(),
35+
accountPath: z.string().trim().default("/").transform(removeTrailingSlash),
36+
accountView: z.nativeEnum(PamAccountView).default(PamAccountView.Flat),
37+
offset: z.coerce.number().min(0).default(0),
38+
limit: z.coerce.number().min(1).max(100).default(100),
39+
orderBy: z.nativeEnum(PamAccountOrderBy).default(PamAccountOrderBy.Name),
40+
orderDirection: z.nativeEnum(OrderByDirection).default(OrderByDirection.ASC),
41+
search: z.string().trim().optional(),
42+
filterResourceIds: z
43+
.string()
44+
.transform((val) =>
45+
val
46+
.split(",")
47+
.map((s) => s.trim())
48+
.filter(Boolean)
49+
)
50+
.optional()
3051
}),
3152
response: {
3253
200: z.object({
3354
accounts: SanitizedAccountSchema.array(),
34-
folders: PamFoldersSchema.array()
55+
folders: PamFoldersSchema.array(),
56+
totalCount: z.number().default(0),
57+
folderId: z.string().optional(),
58+
folderPaths: z.record(z.string(), z.string())
3559
})
3660
}
3761
},
3862
onRequest: verifyAuth([AuthMode.JWT]),
3963
handler: async (req) => {
40-
const response = await server.services.pamAccount.list(req.query.projectId, req.permission);
64+
const { projectId, accountPath, accountView, limit, offset, search, orderBy, orderDirection, filterResourceIds } =
65+
req.query;
66+
67+
const { accounts, folders, totalCount, folderId, folderPaths } = await server.services.pamAccount.list({
68+
actorId: req.permission.id,
69+
actor: req.permission.type,
70+
actorAuthMethod: req.permission.authMethod,
71+
actorOrgId: req.permission.orgId,
72+
projectId,
73+
accountPath,
74+
accountView,
75+
limit,
76+
offset,
77+
search,
78+
orderBy,
79+
orderDirection,
80+
filterResourceIds
81+
});
4182

4283
await server.services.auditLog.createAuditLog({
4384
...req.auditLogInfo,
4485
orgId: req.permission.orgId,
45-
projectId: req.query.projectId,
86+
projectId,
4687
event: {
4788
type: EventType.PAM_ACCOUNT_LIST,
4889
metadata: {
49-
accountCount: response.accounts.length,
50-
folderCount: response.folders.length
90+
accountCount: accounts.length,
91+
folderCount: folders.length
5192
}
5293
}
5394
});
5495

55-
return response;
96+
return { accounts, folders, totalCount, folderId, folderPaths };
5697
}
5798
});
5899

@@ -93,7 +134,7 @@ export const registerPamAccountRouter = async (server: FastifyZodProvider) => {
93134
gatewayClientPrivateKey: z.string(),
94135
gatewayServerCertificateChain: z.string(),
95136
relayHost: z.string(),
96-
metadata: z.record(z.string(), z.string()).optional()
137+
metadata: z.record(z.string(), z.string().optional()).optional()
97138
})
98139
}
99140
},

backend/src/ee/routes/v1/pam-resource-routers/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ import {
99
SanitizedPostgresResourceSchema,
1010
UpdatePostgresResourceSchema
1111
} from "@app/ee/services/pam-resource/postgres/postgres-resource-schemas";
12+
import {
13+
CreateSSHResourceSchema,
14+
SanitizedSSHResourceSchema,
15+
UpdateSSHResourceSchema
16+
} from "@app/ee/services/pam-resource/ssh/ssh-resource-schemas";
1217

1318
import { registerPamResourceEndpoints } from "./pam-resource-endpoints";
1419

@@ -30,5 +35,14 @@ export const PAM_RESOURCE_REGISTER_ROUTER_MAP: Record<PamResource, (server: Fast
3035
createResourceSchema: CreateMySQLResourceSchema,
3136
updateResourceSchema: UpdateMySQLResourceSchema
3237
});
38+
},
39+
[PamResource.SSH]: async (server: FastifyZodProvider) => {
40+
registerPamResourceEndpoints({
41+
server,
42+
resourceType: PamResource.SSH,
43+
resourceResponseSchema: SanitizedSSHResourceSchema,
44+
createResourceSchema: CreateSSHResourceSchema,
45+
updateResourceSchema: UpdateSSHResourceSchema
46+
});
3347
}
3448
};

backend/src/ee/routes/v1/pam-resource-routers/pam-resource-router.ts

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,30 @@ import {
55
MySQLResourceListItemSchema,
66
SanitizedMySQLResourceSchema
77
} from "@app/ee/services/pam-resource/mysql/mysql-resource-schemas";
8+
import { PamResourceOrderBy } from "@app/ee/services/pam-resource/pam-resource-enums";
89
import {
910
PostgresResourceListItemSchema,
1011
SanitizedPostgresResourceSchema
1112
} from "@app/ee/services/pam-resource/postgres/postgres-resource-schemas";
13+
import {
14+
SanitizedSSHResourceSchema,
15+
SSHResourceListItemSchema
16+
} from "@app/ee/services/pam-resource/ssh/ssh-resource-schemas";
17+
import { OrderByDirection } from "@app/lib/types";
1218
import { readLimit } from "@app/server/config/rateLimiter";
1319
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
1420
import { AuthMode } from "@app/services/auth/auth-type";
1521

16-
const SanitizedResourceSchema = z.union([SanitizedPostgresResourceSchema, SanitizedMySQLResourceSchema]);
22+
const SanitizedResourceSchema = z.union([
23+
SanitizedPostgresResourceSchema,
24+
SanitizedMySQLResourceSchema,
25+
SanitizedSSHResourceSchema
26+
]);
1727

1828
const ResourceOptionsSchema = z.discriminatedUnion("resource", [
1929
PostgresResourceListItemSchema,
20-
MySQLResourceListItemSchema
30+
MySQLResourceListItemSchema,
31+
SSHResourceListItemSchema
2132
]);
2233

2334
export const registerPamResourceRouter = async (server: FastifyZodProvider) => {
@@ -52,17 +63,46 @@ export const registerPamResourceRouter = async (server: FastifyZodProvider) => {
5263
schema: {
5364
description: "List PAM resources",
5465
querystring: z.object({
55-
projectId: z.string().uuid()
66+
projectId: z.string().uuid(),
67+
offset: z.coerce.number().min(0).default(0),
68+
limit: z.coerce.number().min(1).max(100).default(100),
69+
orderBy: z.nativeEnum(PamResourceOrderBy).default(PamResourceOrderBy.Name),
70+
orderDirection: z.nativeEnum(OrderByDirection).default(OrderByDirection.ASC),
71+
search: z.string().trim().optional(),
72+
filterResourceTypes: z
73+
.string()
74+
.transform((val) =>
75+
val
76+
.split(",")
77+
.map((s) => s.trim())
78+
.filter(Boolean)
79+
)
80+
.optional()
5681
}),
5782
response: {
5883
200: z.object({
59-
resources: SanitizedResourceSchema.array()
84+
resources: SanitizedResourceSchema.array(),
85+
totalCount: z.number().default(0)
6086
})
6187
}
6288
},
6389
onRequest: verifyAuth([AuthMode.JWT]),
6490
handler: async (req) => {
65-
const response = await server.services.pamResource.list(req.query.projectId, req.permission);
91+
const { projectId, limit, offset, search, orderBy, orderDirection, filterResourceTypes } = req.query;
92+
93+
const { resources, totalCount } = await server.services.pamResource.list({
94+
actorId: req.permission.id,
95+
actor: req.permission.type,
96+
actorAuthMethod: req.permission.authMethod,
97+
actorOrgId: req.permission.orgId,
98+
projectId,
99+
limit,
100+
offset,
101+
search,
102+
orderBy,
103+
orderDirection,
104+
filterResourceTypes
105+
});
66106

67107
await server.services.auditLog.createAuditLog({
68108
...req.auditLogInfo,
@@ -71,12 +111,12 @@ export const registerPamResourceRouter = async (server: FastifyZodProvider) => {
71111
event: {
72112
type: EventType.PAM_RESOURCE_LIST,
73113
metadata: {
74-
count: response.resources.length
114+
count: resources.length
75115
}
76116
}
77117
});
78118

79-
return response;
119+
return { resources, totalCount };
80120
}
81121
});
82122
};

0 commit comments

Comments
 (0)