-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2950 from Infisical/feat/secret-access-list
feat: secret access list
- Loading branch information
Showing
14 changed files
with
1,026 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import z from "zod"; | ||
|
||
import { ProjectPermissionActions } from "@app/ee/services/permission/project-permission"; | ||
import { RAW_SECRETS } from "@app/lib/api-docs"; | ||
import { removeTrailingSlash } from "@app/lib/fn"; | ||
import { readLimit } from "@app/server/config/rateLimiter"; | ||
import { verifyAuth } from "@app/server/plugins/auth/verify-auth"; | ||
import { AuthMode } from "@app/services/auth/auth-type"; | ||
|
||
const AccessListEntrySchema = z | ||
.object({ | ||
allowedActions: z.nativeEnum(ProjectPermissionActions).array(), | ||
id: z.string(), | ||
membershipId: z.string(), | ||
name: z.string() | ||
}) | ||
.array(); | ||
|
||
export const registerSecretRouter = async (server: FastifyZodProvider) => { | ||
server.route({ | ||
method: "GET", | ||
url: "/:secretName/access-list", | ||
config: { | ||
rateLimit: readLimit | ||
}, | ||
schema: { | ||
description: "Get list of users, machine identities, and groups with access to a secret", | ||
security: [ | ||
{ | ||
bearerAuth: [] | ||
} | ||
], | ||
params: z.object({ | ||
secretName: z.string().trim().describe(RAW_SECRETS.GET_ACCESS_LIST.secretName) | ||
}), | ||
querystring: z.object({ | ||
workspaceId: z.string().trim().describe(RAW_SECRETS.GET_ACCESS_LIST.workspaceId), | ||
environment: z.string().trim().describe(RAW_SECRETS.GET_ACCESS_LIST.environment), | ||
secretPath: z | ||
.string() | ||
.trim() | ||
.default("/") | ||
.transform(removeTrailingSlash) | ||
.describe(RAW_SECRETS.GET_ACCESS_LIST.secretPath) | ||
}), | ||
response: { | ||
200: z.object({ | ||
groups: AccessListEntrySchema, | ||
identities: AccessListEntrySchema, | ||
users: AccessListEntrySchema | ||
}) | ||
} | ||
}, | ||
onRequest: verifyAuth([AuthMode.JWT]), | ||
handler: async (req) => { | ||
const { secretName } = req.params; | ||
const { secretPath, environment, workspaceId: projectId } = req.query; | ||
|
||
return server.services.secret.getSecretAccessList({ | ||
actorId: req.permission.id, | ||
actor: req.permission.type, | ||
actorAuthMethod: req.permission.authMethod, | ||
actorOrgId: req.permission.orgId, | ||
secretPath, | ||
environment, | ||
projectId, | ||
secretName | ||
}); | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.