Skip to content

Commit

Permalink
More ignored audit trail elements (#490)
Browse files Browse the repository at this point in the history
* More ignored audit trail elements

* Display package.xml content in logs when backup failed

* ignore scratch orgs actions

* Exclude 2FA stuff

* exclude more user actions

* cspell

* [Mega-Linter] Apply linters fixes

---------

Co-authored-by: nvuillam <nvuillam@users.noreply.github.com>
  • Loading branch information
nvuillam and nvuillam authored Nov 19, 2023
1 parent f1434ca commit 45d2eb4
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 5 deletions.
13 changes: 13 additions & 0 deletions .github/linters/.cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
"accordionsources",
"accordiontarget",
"accordionuse",
"activateduser",
"activateinvalid",
"administratif",
"allowfullscreen",
Expand Down Expand Up @@ -190,7 +191,18 @@
"canmodify",
"caseentitlement",
"certaines",
"changedcommunitynickname",
"changedinteractionuseroffon",
"changedinteractionuseronoff",
"changedmarketinguseroffon",
"changedmarketinguseronoff",
"changedpassword",
"changedprofileforuser",
"changedprofileforusercusttostd",
"changedprofileforuserstdtocust",
"changedroleforuser",
"changedroleforuserfromnone",
"changedroleforusertonone",
"changemgmt",
"checkcoverage",
"checkcoverage) -- endArgs.indexOf(\"--checkcoverage\"",
Expand Down Expand Up @@ -437,6 +449,7 @@
"lcov",
"legacyapi",
"legetz",
"lightningloginenroll",
"liste",
"listview",
"listviewmine",
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
Note: Can be used with `sfdx plugins:install sfdx-hardis@beta` and docker image `hardisgroupcom/sfdx-hardis@beta`

- Monitoring
- Display package.xml content in logs when backup failed
- Update default **package-skip-items.xml**
- Call **hardis:lint:access** by default
- Handle empty sections
- **hardis:org:diagnose:audittrail** enhancements:
- Add PerSetUnassign in not suspect monitored actions in Setup Audit Trail
- Allow to append more allowed Setup Audit Trail sections & actions using `.sfdx-hardis.yml` property **monitoringAllowedSectionsActions**
Expand Down
2 changes: 2 additions & 0 deletions defaults/monitoring/manifest/package-skip-items.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,12 @@
</types>
-->

<!-- Uncomment if you have too many metadatas
<types>
<members>*</members>
<name>ReportType</name>
</types>
-->

<!-- Uncomment if you have too many metadatas
<types>
Expand Down
55 changes: 51 additions & 4 deletions src/commands/hardis/org/diagnose/audittrail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,41 @@ export default class DiagnoseAuditTrail extends SfdxCommand {
Regular setup actions performed in major orgs are filtered.
- ""
- createScratchOrg
- deleteScratchOrg
- Certificate and Key Management
- insertCertificate
- Groups
- groupMembership
- Manage Users
- activateduser
- createduser
- changedcommunitynickname
- changedpassword
- changedinteractionuseroffon
- changedinteractionuseronoff
- changedmarketinguseroffon
- changedmarketinguseronoff
- changedprofileforuser
- changedprofileforusercusttostd
- changedprofileforuserstdtocust
- changedroleforusertonone
- changedroleforuser
- changedroleforuserfromnone
- changedUserEmailVerifiedStatusVerified
- deactivateduser
- deleteAuthenticatorPairing
- deleteTwoFactorInfo2
- deleteTwoFactorTempCode
- insertAuthenticatorPairing
- insertTwoFactorInfo2
- insertTwoFactorTempCode
- lightningloginenroll
- PermSetAssign
- PermSetLicenseAssign
- PermSetUnassign
- PermSetLicenseUnassign
- resetpassword
- suOrgAdminLogin
- suOrgAdminLogout
Expand Down Expand Up @@ -148,15 +172,37 @@ monitoringAllowedSectionsActions:
}

this.allowedSectionsActions = {
"": ["createScratchOrg", "deleteScratchOrg"],
"Certificate and Key Management": ["insertCertificate"],
Groups: ["groupMembership"],
"Manage Users": [
"activateduser",
"createduser",
"changedcommunitynickname",
"changedinteractionuseroffon",
"changedinteractionuseronoff",
"changedmarketinguseroffon",
"changedmarketinguseronoff",
"changedprofileforuser",
"changedprofileforusercusttostd",
"changedprofileforuserstdtocust",
"changedroleforusertonone",
"changedroleforuser",
"changedroleforuserfromnone",
"changedpassword",
"changedUserEmailVerifiedStatusVerified",
"deactivateduser",
"deleteAuthenticatorPairing",
"deleteTwoFactorInfo2",
"deleteTwoFactorTempCode",
"insertAuthenticatorPairing",
"insertTwoFactorInfo2",
"insertTwoFactorTempCode",
"lightningloginenroll",
"PermSetAssign",
"PermSetLicenseAssign",
"PermSetUnassign",
"PermSetLicenseUnassign",
"resetpassword",
"suOrgAdminLogin",
"suOrgAdminLogout",
Expand Down Expand Up @@ -200,17 +246,18 @@ monitoringAllowedSectionsActions:
let suspectUsers = [];
let suspectActions = [];
const auditTrailRecords = queryRes.records.map((record) => {
const section = record?.Section || "";
record.Suspect = false;
// Unallowed actions
if (
(this.allowedSectionsActions[record.Section] && !this.allowedSectionsActions[record.Section].includes(record.Action)) ||
!this.allowedSectionsActions[record.Section]
(this.allowedSectionsActions[section] && !this.allowedSectionsActions[section].includes(record.Action)) ||
!this.allowedSectionsActions[section]
) {
record.Suspect = true;
record.SuspectReason = `Manual config in unallowed section ${record.Section} with action ${record.Action}`;
record.SuspectReason = `Manual config in unallowed section ${section} with action ${record.Action}`;
suspectRecords.push(record);
suspectUsers.push(record["CreatedBy.Username"]);
suspectActions.push(`${record.Section} - ${record.Action}`);
suspectActions.push(`${section} - ${record.Action}`);
return record;
}
return record;
Expand Down
7 changes: 6 additions & 1 deletion src/commands/hardis/org/monitor/backup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@ export default class MonitorBackup extends SfdxCommand {
debug: this.debugMode,
});
} catch (e) {
uxLog(this, c.yellow("Crash during backup. You may exclude more items by customizing file manifest/package-skip-items.xml"));
const failedPackageXmlContent = await fs.readFile(packageXmlBackUpItemsFile, "utf8");
uxLog(this, c.yellow("BackUp package.xml that failed to be retrieved:\n" + c.grey(failedPackageXmlContent)));
uxLog(
this,
c.red("Crash during backup. You may exclude more metadata types by updating file manifest/package-skip-items.xml then commit and push it"),
);
throw e;
}

Expand Down

0 comments on commit 45d2eb4

Please sign in to comment.