mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-12 04:29:09 +00:00
review fixes
This commit is contained in:
@@ -516,6 +516,7 @@ export enum EventType {
|
||||
PAM_ACCOUNT_UPDATE = "pam-account-update",
|
||||
PAM_ACCOUNT_DELETE = "pam-account-delete",
|
||||
PAM_ACCOUNT_CREDENTIAL_ROTATION = "pam-account-credential-rotation",
|
||||
PAM_ACCOUNT_CREDENTIAL_ROTATION_FAILED = "pam-account-credential-rotation-failed",
|
||||
PAM_RESOURCE_LIST = "pam-resource-list",
|
||||
PAM_RESOURCE_GET = "pam-resource-get",
|
||||
PAM_RESOURCE_CREATE = "pam-resource-create",
|
||||
@@ -3834,6 +3835,16 @@ interface PamAccountCredentialRotationEvent {
|
||||
};
|
||||
}
|
||||
|
||||
interface PamAccountCredentialRotationFailedEvent {
|
||||
type: EventType.PAM_ACCOUNT_CREDENTIAL_ROTATION_FAILED;
|
||||
metadata: {
|
||||
accountName: string;
|
||||
accountId: string;
|
||||
resourceId: string;
|
||||
errorMessage: string;
|
||||
};
|
||||
}
|
||||
|
||||
interface PamResourceListEvent {
|
||||
type: EventType.PAM_RESOURCE_LIST;
|
||||
metadata: {
|
||||
@@ -4225,6 +4236,7 @@ export type Event =
|
||||
| PamAccountUpdateEvent
|
||||
| PamAccountDeleteEvent
|
||||
| PamAccountCredentialRotationEvent
|
||||
| PamAccountCredentialRotationFailedEvent
|
||||
| PamResourceListEvent
|
||||
| PamResourceGetEvent
|
||||
| PamResourceCreateEvent
|
||||
|
||||
@@ -18,7 +18,8 @@ export const pamAccountDALFactory = (db: TDbClient) => {
|
||||
.select(
|
||||
// resource
|
||||
db.ref("name").withSchema(TableName.PamResource).as("resourceName"),
|
||||
db.ref("resourceType").withSchema(TableName.PamResource)
|
||||
db.ref("resourceType").withSchema(TableName.PamResource),
|
||||
db.ref("encryptedRotationAccountCredentials").withSchema(TableName.PamResource)
|
||||
);
|
||||
|
||||
if (filter) {
|
||||
@@ -28,15 +29,18 @@ export const pamAccountDALFactory = (db: TDbClient) => {
|
||||
|
||||
const accounts = await query;
|
||||
|
||||
return accounts.map(({ resourceId, resourceName, resourceType, ...account }) => ({
|
||||
...account,
|
||||
resourceId,
|
||||
resource: {
|
||||
id: resourceId,
|
||||
name: resourceName,
|
||||
resourceType
|
||||
}
|
||||
}));
|
||||
return accounts.map(
|
||||
({ resourceId, resourceName, resourceType, encryptedRotationAccountCredentials, ...account }) => ({
|
||||
...account,
|
||||
resourceId,
|
||||
resource: {
|
||||
id: resourceId,
|
||||
name: resourceName,
|
||||
resourceType,
|
||||
encryptedRotationAccountCredentials
|
||||
}
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
const findAccountsDueForRotation = async (tx?: Knex) => {
|
||||
|
||||
@@ -330,7 +330,7 @@ export const pamAccountServiceFactory = ({
|
||||
|
||||
const decryptedAndPermittedAccounts: Array<
|
||||
TPamAccounts & {
|
||||
resource: Pick<TPamResources, "id" | "name" | "resourceType">;
|
||||
resource: Pick<TPamResources, "id" | "name" | "resourceType"> & { rotationCredentialsConfigured: boolean };
|
||||
credentials: TPamAccountCredentials;
|
||||
}
|
||||
> = [];
|
||||
@@ -360,7 +360,8 @@ export const pamAccountServiceFactory = ({
|
||||
resource: {
|
||||
id: account.resource.id,
|
||||
name: account.resource.name,
|
||||
resourceType: account.resource.resourceType
|
||||
resourceType: account.resource.resourceType,
|
||||
rotationCredentialsConfigured: !!account.resource.encryptedRotationAccountCredentials
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -608,6 +609,25 @@ export const pamAccountServiceFactory = ({
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
const errorMessage = error instanceof Error ? error.message : "An unknown error occurred";
|
||||
|
||||
await auditLogService.createAuditLog({
|
||||
projectId: account.projectId,
|
||||
actor: {
|
||||
type: ActorType.PLATFORM,
|
||||
metadata: {}
|
||||
},
|
||||
event: {
|
||||
type: EventType.PAM_ACCOUNT_CREDENTIAL_ROTATION_FAILED,
|
||||
metadata: {
|
||||
accountId: account.id,
|
||||
accountName: account.name,
|
||||
resourceId: account.resourceId,
|
||||
errorMessage
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
logger.error(error, `Failed to rotate credentials for account ${account.id}`);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -204,13 +204,26 @@ export const pamResourceServiceFactory = ({
|
||||
finalCredentials.password = decryptedCredentials.password;
|
||||
}
|
||||
|
||||
const validatedRotationAccountCredentials = await factory.validateAccountCredentials(finalCredentials);
|
||||
try {
|
||||
const validatedRotationAccountCredentials = await factory.validateAccountCredentials(finalCredentials);
|
||||
|
||||
updateDoc.encryptedRotationAccountCredentials = await encryptAccountCredentials({
|
||||
credentials: validatedRotationAccountCredentials,
|
||||
projectId: resource.projectId,
|
||||
kmsService
|
||||
});
|
||||
updateDoc.encryptedRotationAccountCredentials = await encryptAccountCredentials({
|
||||
credentials: validatedRotationAccountCredentials,
|
||||
projectId: resource.projectId,
|
||||
kmsService
|
||||
});
|
||||
} catch (err) {
|
||||
if (
|
||||
err instanceof BadRequestError &&
|
||||
err.message === "Account credentials invalid: Username or password incorrect"
|
||||
) {
|
||||
throw new BadRequestError({
|
||||
message: "Rotation Account credentials invalid: Username or password incorrect"
|
||||
});
|
||||
}
|
||||
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user