@j-schreiber/sf-cli-security-audit 0.8.2 → 0.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/lib/commands/org/audit/init.d.ts +19 -0
- package/lib/commands/org/audit/init.js +72 -0
- package/lib/commands/org/audit/init.js.map +1 -0
- package/lib/commands/org/audit/run.d.ts +23 -0
- package/lib/commands/org/audit/run.js +124 -0
- package/lib/commands/org/audit/run.js.map +1 -0
- package/lib/commands/org/scan/user-perms.d.ts +20 -0
- package/lib/commands/org/scan/user-perms.js +87 -0
- package/lib/commands/org/scan/user-perms.js.map +1 -0
- package/lib/libs/conf-init/auditConfig.d.ts +35 -0
- package/lib/libs/conf-init/auditConfig.js +41 -0
- package/lib/libs/conf-init/auditConfig.js.map +1 -0
- package/lib/libs/conf-init/permissionsClassification.d.ts +17 -0
- package/lib/libs/conf-init/permissionsClassification.js +80 -0
- package/lib/libs/conf-init/permissionsClassification.js.map +1 -0
- package/lib/libs/conf-init/policyConfigs.d.ts +31 -0
- package/lib/libs/conf-init/policyConfigs.js +91 -0
- package/lib/libs/conf-init/policyConfigs.js.map +1 -0
- package/lib/libs/conf-init/presets/loose.d.ts +6 -0
- package/lib/libs/conf-init/presets/loose.js +85 -0
- package/lib/libs/conf-init/presets/loose.js.map +1 -0
- package/lib/libs/conf-init/presets/none.d.ts +30 -0
- package/lib/libs/conf-init/presets/none.js +54 -0
- package/lib/libs/conf-init/presets/none.js.map +1 -0
- package/lib/libs/conf-init/presets/strict.d.ts +4 -0
- package/lib/libs/conf-init/presets/strict.js +79 -0
- package/lib/libs/conf-init/presets/strict.js.map +1 -0
- package/lib/libs/conf-init/presets.d.ts +7 -0
- package/lib/libs/conf-init/presets.js +20 -0
- package/lib/libs/conf-init/presets.js.map +1 -0
- package/lib/libs/core/auditRun.d.ts +36 -0
- package/lib/libs/core/auditRun.js +86 -0
- package/lib/libs/core/auditRun.js.map +1 -0
- package/lib/libs/core/classification-types.d.ts +20 -0
- package/lib/libs/core/classification-types.js +23 -0
- package/lib/libs/core/classification-types.js.map +1 -0
- package/lib/libs/core/constants.d.ts +10 -0
- package/lib/libs/core/constants.js +20 -0
- package/lib/libs/core/constants.js.map +1 -0
- package/lib/libs/core/file-mgmt/auditConfigFileManager.d.ts +48 -0
- package/lib/libs/core/file-mgmt/auditConfigFileManager.js +145 -0
- package/lib/libs/core/file-mgmt/auditConfigFileManager.js.map +1 -0
- package/lib/libs/core/file-mgmt/schema.d.ts +123 -0
- package/lib/libs/core/file-mgmt/schema.js +69 -0
- package/lib/libs/core/file-mgmt/schema.js.map +1 -0
- package/lib/libs/core/mdapi/mdapiRetriever.d.ts +54 -0
- package/lib/libs/core/mdapi/mdapiRetriever.js +123 -0
- package/lib/libs/core/mdapi/mdapiRetriever.js.map +1 -0
- package/lib/libs/core/mdapi/metadataRegistryEntry.d.ts +40 -0
- package/lib/libs/core/mdapi/metadataRegistryEntry.js +46 -0
- package/lib/libs/core/mdapi/metadataRegistryEntry.js.map +1 -0
- package/lib/libs/core/mdapi/namedMetadataToolingQueryable.d.ts +33 -0
- package/lib/libs/core/mdapi/namedMetadataToolingQueryable.js +41 -0
- package/lib/libs/core/mdapi/namedMetadataToolingQueryable.js.map +1 -0
- package/lib/libs/core/mdapi/namedMetadataType.d.ts +20 -0
- package/lib/libs/core/mdapi/namedMetadataType.js +41 -0
- package/lib/libs/core/mdapi/namedMetadataType.js.map +1 -0
- package/lib/libs/core/mdapi/singletonMetadataType.d.ts +21 -0
- package/lib/libs/core/mdapi/singletonMetadataType.js +37 -0
- package/lib/libs/core/mdapi/singletonMetadataType.js.map +1 -0
- package/lib/libs/core/mdapi/usersRepository.d.ts +85 -0
- package/lib/libs/core/mdapi/usersRepository.js +126 -0
- package/lib/libs/core/mdapi/usersRepository.js.map +1 -0
- package/lib/libs/core/policies/connectedAppPolicy.d.ts +10 -0
- package/lib/libs/core/policies/connectedAppPolicy.js +78 -0
- package/lib/libs/core/policies/connectedAppPolicy.js.map +1 -0
- package/lib/libs/core/policies/permissionSetPolicy.d.ts +11 -0
- package/lib/libs/core/policies/permissionSetPolicy.js +62 -0
- package/lib/libs/core/policies/permissionSetPolicy.js.map +1 -0
- package/lib/libs/core/policies/policy.d.ts +31 -0
- package/lib/libs/core/policies/policy.js +100 -0
- package/lib/libs/core/policies/policy.js.map +1 -0
- package/lib/libs/core/policies/profilePolicy.d.ts +11 -0
- package/lib/libs/core/policies/profilePolicy.js +64 -0
- package/lib/libs/core/policies/profilePolicy.js.map +1 -0
- package/lib/libs/core/policies/salesforceStandardTypes.d.ts +58 -0
- package/lib/libs/core/policies/salesforceStandardTypes.js +2 -0
- package/lib/libs/core/policies/salesforceStandardTypes.js.map +1 -0
- package/lib/libs/core/policies/userPolicy.d.ts +11 -0
- package/lib/libs/core/policies/userPolicy.js +60 -0
- package/lib/libs/core/policies/userPolicy.js.map +1 -0
- package/lib/libs/core/policy-types.d.ts +18 -0
- package/lib/libs/core/policy-types.js +28 -0
- package/lib/libs/core/policy-types.js.map +1 -0
- package/lib/libs/core/policyRegistry.d.ts +23 -0
- package/lib/libs/core/policyRegistry.js +38 -0
- package/lib/libs/core/policyRegistry.js.map +1 -0
- package/lib/libs/core/registries/connectedApps.d.ts +13 -0
- package/lib/libs/core/registries/connectedApps.js +13 -0
- package/lib/libs/core/registries/connectedApps.js.map +1 -0
- package/lib/libs/core/registries/helpers/permissionsScanning.d.ts +29 -0
- package/lib/libs/core/registries/helpers/permissionsScanning.js +69 -0
- package/lib/libs/core/registries/helpers/permissionsScanning.js.map +1 -0
- package/lib/libs/core/registries/permissionSets.d.ts +11 -0
- package/lib/libs/core/registries/permissionSets.js +11 -0
- package/lib/libs/core/registries/permissionSets.js.map +1 -0
- package/lib/libs/core/registries/profiles.d.ts +11 -0
- package/lib/libs/core/registries/profiles.js +11 -0
- package/lib/libs/core/registries/profiles.js.map +1 -0
- package/lib/libs/core/registries/ruleRegistry.d.ts +37 -0
- package/lib/libs/core/registries/ruleRegistry.js +48 -0
- package/lib/libs/core/registries/ruleRegistry.js.map +1 -0
- package/lib/libs/core/registries/rules/allUsedAppsUnderManagement.d.ts +7 -0
- package/lib/libs/core/registries/rules/allUsedAppsUnderManagement.js +23 -0
- package/lib/libs/core/registries/rules/allUsedAppsUnderManagement.js.map +1 -0
- package/lib/libs/core/registries/rules/enforcePermissionPresets.d.ts +7 -0
- package/lib/libs/core/registries/rules/enforcePermissionPresets.js +58 -0
- package/lib/libs/core/registries/rules/enforcePermissionPresets.js.map +1 -0
- package/lib/libs/core/registries/rules/enforcePermissionsOnProfileLike.d.ts +7 -0
- package/lib/libs/core/registries/rules/enforcePermissionsOnProfileLike.js +26 -0
- package/lib/libs/core/registries/rules/enforcePermissionsOnProfileLike.js.map +1 -0
- package/lib/libs/core/registries/rules/enforcePermissionsOnUser.d.ts +8 -0
- package/lib/libs/core/registries/rules/enforcePermissionsOnUser.js +42 -0
- package/lib/libs/core/registries/rules/enforcePermissionsOnUser.js.map +1 -0
- package/lib/libs/core/registries/rules/noInactiveUsers.d.ts +9 -0
- package/lib/libs/core/registries/rules/noInactiveUsers.js +44 -0
- package/lib/libs/core/registries/rules/noInactiveUsers.js.map +1 -0
- package/lib/libs/core/registries/rules/noOtherApexApiLogins.d.ts +7 -0
- package/lib/libs/core/registries/rules/noOtherApexApiLogins.js +27 -0
- package/lib/libs/core/registries/rules/noOtherApexApiLogins.js.map +1 -0
- package/lib/libs/core/registries/rules/noUserCanSelfAuthorize.d.ts +7 -0
- package/lib/libs/core/registries/rules/noUserCanSelfAuthorize.js +31 -0
- package/lib/libs/core/registries/rules/noUserCanSelfAuthorize.js.map +1 -0
- package/lib/libs/core/registries/rules/policyRule.d.ts +19 -0
- package/lib/libs/core/registries/rules/policyRule.js +32 -0
- package/lib/libs/core/registries/rules/policyRule.js.map +1 -0
- package/lib/libs/core/registries/types.d.ts +37 -0
- package/lib/libs/core/registries/types.js +11 -0
- package/lib/libs/core/registries/types.js.map +1 -0
- package/lib/libs/core/registries/users.d.ts +10 -0
- package/lib/libs/core/registries/users.js +17 -0
- package/lib/libs/core/registries/users.js.map +1 -0
- package/lib/libs/core/result-types.d.ts +172 -0
- package/lib/libs/core/result-types.js +2 -0
- package/lib/libs/core/result-types.js.map +1 -0
- package/lib/libs/core/utils.d.ts +12 -0
- package/lib/libs/core/utils.js +31 -0
- package/lib/libs/core/utils.js.map +1 -0
- package/lib/libs/quick-scan/types.d.ts +17 -0
- package/lib/libs/quick-scan/types.js +2 -0
- package/lib/libs/quick-scan/types.js.map +1 -0
- package/lib/libs/quick-scan/userPermissionScanner.d.ts +22 -0
- package/lib/libs/quick-scan/userPermissionScanner.js +75 -0
- package/lib/libs/quick-scan/userPermissionScanner.js.map +1 -0
- package/lib/ux/auditRunMultiStage.d.ts +65 -0
- package/lib/ux/auditRunMultiStage.js +120 -0
- package/lib/ux/auditRunMultiStage.js.map +1 -0
- package/oclif.lock +13606 -10113
- package/oclif.manifest.json +253 -2
- package/package.json +13 -41
package/README.md
CHANGED
|
@@ -79,7 +79,7 @@ FLAG DESCRIPTIONS
|
|
|
79
79
|
essentially control, if a permission is allowed in a certain profile / permission set.
|
|
80
80
|
```
|
|
81
81
|
|
|
82
|
-
_See code: [src/commands/org/audit/init.ts](https://github.com/j-schreiber/js-sf-cli-security-audit/blob/v0.
|
|
82
|
+
_See code: [src/commands/org/audit/init.ts](https://github.com/j-schreiber/js-sf-cli-security-audit/blob/v0.8.4/src/commands/org/audit/init.ts)_
|
|
83
83
|
|
|
84
84
|
## `sf org audit run`
|
|
85
85
|
|
|
@@ -110,7 +110,7 @@ EXAMPLES
|
|
|
110
110
|
$ sf org audit run -o MyTargetOrg -d configs/prod
|
|
111
111
|
```
|
|
112
112
|
|
|
113
|
-
_See code: [src/commands/org/audit/run.ts](https://github.com/j-schreiber/js-sf-cli-security-audit/blob/v0.
|
|
113
|
+
_See code: [src/commands/org/audit/run.ts](https://github.com/j-schreiber/js-sf-cli-security-audit/blob/v0.8.4/src/commands/org/audit/run.ts)_
|
|
114
114
|
|
|
115
115
|
## `sf org scan user-perms`
|
|
116
116
|
|
|
@@ -149,7 +149,7 @@ FLAG DESCRIPTIONS
|
|
|
149
149
|
retun 0 results).
|
|
150
150
|
```
|
|
151
151
|
|
|
152
|
-
_See code: [src/commands/org/scan/user-perms.ts](https://github.com/j-schreiber/js-sf-cli-security-audit/blob/v0.
|
|
152
|
+
_See code: [src/commands/org/scan/user-perms.ts](https://github.com/j-schreiber/js-sf-cli-security-audit/blob/v0.8.4/src/commands/org/scan/user-perms.ts)_
|
|
153
153
|
|
|
154
154
|
<!-- commandsstop -->
|
|
155
155
|
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { SfCommand } from '@salesforce/sf-plugins-core';
|
|
2
|
+
import { AuditRunConfig } from '../../../libs/core/file-mgmt/schema.js';
|
|
3
|
+
import { AuditInitPresets } from '../../../libs/conf-init/presets.js';
|
|
4
|
+
export type OrgAuditInitResult = AuditRunConfig;
|
|
5
|
+
export default class OrgAuditInit extends SfCommand<OrgAuditInitResult> {
|
|
6
|
+
static readonly summary: string;
|
|
7
|
+
static readonly description: string;
|
|
8
|
+
static readonly examples: string[];
|
|
9
|
+
static readonly flags: {
|
|
10
|
+
'target-org': import("@oclif/core/interfaces").OptionFlag<import("@salesforce/core").Org, import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
+
'output-dir': import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
preset: import("@oclif/core/interfaces").OptionFlag<AuditInitPresets, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
|
+
'api-version': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
14
|
+
};
|
|
15
|
+
run(): Promise<OrgAuditInitResult>;
|
|
16
|
+
private printResults;
|
|
17
|
+
private printClassifications;
|
|
18
|
+
private printPolicies;
|
|
19
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
|
|
2
|
+
import { Messages } from '@salesforce/core';
|
|
3
|
+
import AuditConfig from '../../../libs/conf-init/auditConfig.js';
|
|
4
|
+
import { isPermissionsConfig, isPolicyConfig, } from '../../../libs/core/file-mgmt/schema.js';
|
|
5
|
+
import { AuditInitPresets } from '../../../libs/conf-init/presets.js';
|
|
6
|
+
import { capitalize } from '../../../libs/core/utils.js';
|
|
7
|
+
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
|
|
8
|
+
const messages = Messages.loadMessages('@j-schreiber/sf-cli-security-audit', 'org.audit.init');
|
|
9
|
+
const presetFlag = Flags.custom({
|
|
10
|
+
char: 'p',
|
|
11
|
+
summary: messages.getMessage('flags.preset.summary'),
|
|
12
|
+
description: messages.getMessage('flags.preset.description'),
|
|
13
|
+
options: Object.values(AuditInitPresets),
|
|
14
|
+
default: AuditInitPresets.strict,
|
|
15
|
+
})();
|
|
16
|
+
export default class OrgAuditInit extends SfCommand {
|
|
17
|
+
static summary = messages.getMessage('summary');
|
|
18
|
+
static description = messages.getMessage('description');
|
|
19
|
+
static examples = messages.getMessages('examples');
|
|
20
|
+
static flags = {
|
|
21
|
+
'target-org': Flags.requiredOrg({
|
|
22
|
+
summary: messages.getMessage('flags.target-org.summary'),
|
|
23
|
+
char: 'o',
|
|
24
|
+
required: true,
|
|
25
|
+
}),
|
|
26
|
+
'output-dir': Flags.directory({
|
|
27
|
+
required: false,
|
|
28
|
+
char: 'd',
|
|
29
|
+
summary: messages.getMessage('flags.output-dir.summary'),
|
|
30
|
+
default: '',
|
|
31
|
+
}),
|
|
32
|
+
preset: presetFlag,
|
|
33
|
+
'api-version': Flags.orgApiVersion(),
|
|
34
|
+
};
|
|
35
|
+
async run() {
|
|
36
|
+
const { flags } = await this.parse(OrgAuditInit);
|
|
37
|
+
const auditConfig = await AuditConfig.init(flags['target-org'].getConnection(flags['api-version']), {
|
|
38
|
+
targetDir: flags['output-dir'],
|
|
39
|
+
preset: flags.preset,
|
|
40
|
+
});
|
|
41
|
+
this.printResults(auditConfig);
|
|
42
|
+
return auditConfig;
|
|
43
|
+
}
|
|
44
|
+
printResults(config) {
|
|
45
|
+
this.printClassifications(config.classifications);
|
|
46
|
+
this.printPolicies(config.policies);
|
|
47
|
+
}
|
|
48
|
+
printClassifications(classifications) {
|
|
49
|
+
Object.values(classifications).forEach((def) => {
|
|
50
|
+
if (isPermissionsConfig(def)) {
|
|
51
|
+
const perms = def.content.permissions ? Object.entries(def.content.permissions) : [];
|
|
52
|
+
if (perms.length > 0) {
|
|
53
|
+
this.logSuccess(messages.getMessage('success.perm-classification-summary', [perms.length ?? 0, def.filePath]));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
printPolicies(policies) {
|
|
59
|
+
Object.entries(policies).forEach(([name, def]) => {
|
|
60
|
+
if (isPolicyConfig(def)) {
|
|
61
|
+
if (def.filePath) {
|
|
62
|
+
this.logSuccess(messages.getMessage('success.policy-summary', [
|
|
63
|
+
capitalize(name),
|
|
64
|
+
Object.keys(def.content.rules).length ?? 0,
|
|
65
|
+
def.filePath,
|
|
66
|
+
]));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=init.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../../../src/commands/org/audit/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,WAAW,MAAM,wCAAwC,CAAC;AACjE,OAAO,EAIL,mBAAmB,EACnB,cAAc,GACf,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC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AM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,EAAE;YAC/C,IAAI,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC;gBACxB,IAAI,GAAG,CAAC,QAAQ,EAAE,CAAC;oBACjB,IAAI,CAAC,UAAU,CACb,QAAQ,CAAC,UAAU,CAAC,wBAAwB,EAAE;wBAC5C,UAAU,CAAC,IAAI,CAAC;wBAChB,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,IAAI,CAAC;wBAC1C,GAAG,CAAC,QAAQ;qBACb,CAAC,CACH,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Interfaces } from '@oclif/core';
|
|
2
|
+
import { SfCommand } from '@salesforce/sf-plugins-core';
|
|
3
|
+
import { AuditResult } from '../../../libs/core/result-types.js';
|
|
4
|
+
export declare const MERGE_CHAR = " \u2022 ";
|
|
5
|
+
export type OrgAuditRunResult = AuditResult & {
|
|
6
|
+
filePath: string;
|
|
7
|
+
};
|
|
8
|
+
export default class OrgAuditRun extends SfCommand<OrgAuditRunResult> {
|
|
9
|
+
static readonly summary: string;
|
|
10
|
+
static readonly description: string;
|
|
11
|
+
static readonly examples: string[];
|
|
12
|
+
static readonly flags: {
|
|
13
|
+
'target-org': Interfaces.OptionFlag<import("@salesforce/core").Org, Interfaces.CustomOptions>;
|
|
14
|
+
'source-dir': Interfaces.OptionFlag<string, Interfaces.CustomOptions>;
|
|
15
|
+
'api-version': Interfaces.OptionFlag<string | undefined, Interfaces.CustomOptions>;
|
|
16
|
+
};
|
|
17
|
+
run(): Promise<OrgAuditRunResult>;
|
|
18
|
+
private printResults;
|
|
19
|
+
private printPoliciesSummary;
|
|
20
|
+
private printExecutedRulesSummary;
|
|
21
|
+
private printRuleViolations;
|
|
22
|
+
private writeReport;
|
|
23
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { writeFileSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { SfCommand, Flags, StandardColors } from '@salesforce/sf-plugins-core';
|
|
4
|
+
import { Messages } from '@salesforce/core';
|
|
5
|
+
import { startAuditRun } from '../../../libs/core/auditRun.js';
|
|
6
|
+
import AuditRunMultiStageOutput from '../../../ux/auditRunMultiStage.js';
|
|
7
|
+
import { capitalize } from '../../../libs/core/utils.js';
|
|
8
|
+
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
|
|
9
|
+
const messages = Messages.loadMessages('@j-schreiber/sf-cli-security-audit', 'org.audit.run');
|
|
10
|
+
export const MERGE_CHAR = ' \u2022 ';
|
|
11
|
+
export default class OrgAuditRun extends SfCommand {
|
|
12
|
+
static summary = messages.getMessage('summary');
|
|
13
|
+
static description = messages.getMessage('description');
|
|
14
|
+
static examples = messages.getMessages('examples');
|
|
15
|
+
static flags = {
|
|
16
|
+
'target-org': Flags.requiredOrg({
|
|
17
|
+
summary: messages.getMessage('flags.target-org.summary'),
|
|
18
|
+
char: 'o',
|
|
19
|
+
required: true,
|
|
20
|
+
}),
|
|
21
|
+
'source-dir': Flags.directory({
|
|
22
|
+
required: false,
|
|
23
|
+
char: 'd',
|
|
24
|
+
summary: messages.getMessage('flags.source-dir.summary'),
|
|
25
|
+
default: '',
|
|
26
|
+
}),
|
|
27
|
+
'api-version': Flags.orgApiVersion(),
|
|
28
|
+
};
|
|
29
|
+
async run() {
|
|
30
|
+
const { flags } = await this.parse(OrgAuditRun);
|
|
31
|
+
const stageOutput = AuditRunMultiStageOutput.create({
|
|
32
|
+
directoryRootPath: flags['source-dir'],
|
|
33
|
+
targetOrg: flags['target-org'].getUsername() ?? flags['target-org'].getOrgId(),
|
|
34
|
+
jsonEnabled: flags.json,
|
|
35
|
+
});
|
|
36
|
+
stageOutput.start();
|
|
37
|
+
const auditRun = startAuditRun(flags['source-dir']);
|
|
38
|
+
stageOutput.startPolicyResolve(auditRun);
|
|
39
|
+
await auditRun.resolve(flags['target-org'].getConnection(flags['api-version']));
|
|
40
|
+
stageOutput.startRuleExecution();
|
|
41
|
+
const partialResult = await auditRun.execute(flags['target-org'].getConnection(flags['api-version']));
|
|
42
|
+
const result = { orgId: flags['target-org'].getOrgId(), ...partialResult };
|
|
43
|
+
stageOutput.finish();
|
|
44
|
+
this.printResults(result);
|
|
45
|
+
const filePath = this.writeReport(result, flags);
|
|
46
|
+
return { ...result, filePath };
|
|
47
|
+
}
|
|
48
|
+
printResults(result) {
|
|
49
|
+
this.printPoliciesSummary(result);
|
|
50
|
+
for (const [policyName, policyDetails] of Object.entries(result.policies)) {
|
|
51
|
+
this.printExecutedRulesSummary(policyName, policyDetails);
|
|
52
|
+
this.printRuleViolations(policyDetails.executedRules);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
printPoliciesSummary(result) {
|
|
56
|
+
const polSummaries = transposePoliciesToTable(result);
|
|
57
|
+
if (result.isCompliant) {
|
|
58
|
+
this.logSuccess(messages.getMessage('success.all-policies-compliant'));
|
|
59
|
+
this.log('');
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
this.log(StandardColors.error(messages.getMessage('summary-non-compliant')));
|
|
63
|
+
this.log('');
|
|
64
|
+
}
|
|
65
|
+
this.table({ data: polSummaries, title: '=== Summary ===', titleOptions: { bold: true } });
|
|
66
|
+
}
|
|
67
|
+
printExecutedRulesSummary(policyName, policyDetails) {
|
|
68
|
+
if (!policyDetails.enabled) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const rulesSummary = transposeExecutedPolicyRules(policyDetails);
|
|
72
|
+
if (rulesSummary.length > 0) {
|
|
73
|
+
this.table({
|
|
74
|
+
data: rulesSummary,
|
|
75
|
+
title: `--- Executed Rules for ${capitalize(policyName)} ---`,
|
|
76
|
+
titleOptions: { underline: true },
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
printRuleViolations(executedRules) {
|
|
81
|
+
for (const uncompliantRule of Object.values(executedRules).filter((ruleDetails) => !ruleDetails.isCompliant)) {
|
|
82
|
+
this.table({
|
|
83
|
+
data: uncompliantRule.violations.map((viol) => ({
|
|
84
|
+
...viol,
|
|
85
|
+
identifier: typeof viol.identifier === 'string' ? viol.identifier : viol.identifier.join(MERGE_CHAR),
|
|
86
|
+
})),
|
|
87
|
+
title: `Violations for ${uncompliantRule.ruleName}`,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
writeReport(result, flags) {
|
|
92
|
+
const fileName = `report_${flags['target-org'].getOrgId()}_${Date.now()}.json`;
|
|
93
|
+
const fullPath = path.join(flags['source-dir'], fileName);
|
|
94
|
+
writeFileSync(fullPath, JSON.stringify(result, null, 2));
|
|
95
|
+
this.info(messages.getMessage('info.report-file-location', [fullPath]));
|
|
96
|
+
return fullPath;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function transposePoliciesToTable(result) {
|
|
100
|
+
return Object.entries(result.policies)
|
|
101
|
+
.filter(([, policyDetails]) => policyDetails.enabled)
|
|
102
|
+
.map(([policyName, policyDetails]) => {
|
|
103
|
+
const rulesExecuted = policyDetails?.executedRules ? Object.keys(policyDetails.executedRules).length : 0;
|
|
104
|
+
return {
|
|
105
|
+
policy: capitalize(policyName),
|
|
106
|
+
isCompliant: policyDetails.isCompliant,
|
|
107
|
+
rulesExecuted,
|
|
108
|
+
auditedEntities: policyDetails.auditedEntities?.length ?? 0,
|
|
109
|
+
ignoredEntities: policyDetails.ignoredEntities?.length ?? 0,
|
|
110
|
+
};
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
function transposeExecutedPolicyRules(result) {
|
|
114
|
+
return Object.entries(result.executedRules).map(([ruleName, ruleDetails]) => ({
|
|
115
|
+
rule: ruleName,
|
|
116
|
+
isCompliant: ruleDetails.isCompliant,
|
|
117
|
+
compliantEntities: ruleDetails.compliantEntities?.length ?? 0,
|
|
118
|
+
violatedEntities: ruleDetails.violatedEntities?.length ?? 0,
|
|
119
|
+
violations: ruleDetails.violations.length,
|
|
120
|
+
warnings: ruleDetails.warnings.length,
|
|
121
|
+
errors: ruleDetails.errors.length,
|
|
122
|
+
}));
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=run.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.js","sourceRoot":"","sources":["../../../../src/commands/org/audit/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC/E,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAC/D,OAAO,wBAAwB,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAEzD,QAAQ,CAAC,kCAAkC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC7D,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,CAAC,oCAAoC,EAAE,eAAe,CAAC,CAAC;AAE9F,MAAM,CAAC,MAAM,UAAU,GAAG,UAAU,CAAC;AAQrC,MAAM,CAAC,OAAO,OAAO,WAAY,SAAQ,SAA4B;IAC5D,MAAM,CAAU,OAAO,GAAG,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IACzD,MAAM,CAAU,WAAW,GAAG,QAAQ,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;IACjE,MAAM,CAAU,QAAQ,GAAG,QAAQ,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;IAE5D,MAAM,CAAU,KAAK,GAAG;QA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AAW,EAAE,WAAW,CAAC,WAAW;QACpC,iBAAiB,EAAE,WAAW,CAAC,iBAAiB,EAAE,MAAM,IAAI,CAAC;QAC7D,gBAAgB,EAAE,WAAW,CAAC,gBAAgB,EAAE,MAAM,IAAI,CAAC;QAC3D,UAAU,EAAE,WAAW,CAAC,UAAU,CAAC,MAAM;QACzC,QAAQ,EAAE,WAAW,CAAC,QAAQ,CAAC,MAAM;QACrC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,MAAM;KAClC,CAAC,CAAC,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { SfCommand } from '@salesforce/sf-plugins-core';
|
|
2
|
+
import { QuickScanResult } from '../../../libs/quick-scan/types.js';
|
|
3
|
+
import { EntityScanStatus } from '../../../libs/quick-scan/userPermissionScanner.js';
|
|
4
|
+
export type OrgUserPermScanResult = QuickScanResult;
|
|
5
|
+
export default class OrgUserPermScan extends SfCommand<OrgUserPermScanResult> {
|
|
6
|
+
static readonly summary: string;
|
|
7
|
+
static readonly description: string;
|
|
8
|
+
static readonly examples: string[];
|
|
9
|
+
static readonly flags: {
|
|
10
|
+
name: import("@oclif/core/interfaces").OptionFlag<string[], import("@oclif/core/interfaces").CustomOptions>;
|
|
11
|
+
'target-org': import("@oclif/core/interfaces").OptionFlag<import("@salesforce/core").Org, import("@oclif/core/interfaces").CustomOptions>;
|
|
12
|
+
'api-version': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
13
|
+
};
|
|
14
|
+
run(): Promise<OrgUserPermScanResult>;
|
|
15
|
+
private reportProgress;
|
|
16
|
+
private print;
|
|
17
|
+
private printSummary;
|
|
18
|
+
private printPermissionResults;
|
|
19
|
+
}
|
|
20
|
+
export declare function isEntityStatus(cls: unknown): cls is EntityScanStatus;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
|
|
2
|
+
import { Messages } from '@salesforce/core';
|
|
3
|
+
import UserPermissionScanner from '../../../libs/quick-scan/userPermissionScanner.js';
|
|
4
|
+
import { capitalize } from '../../../libs/core/utils.js';
|
|
5
|
+
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
|
|
6
|
+
const messages = Messages.loadMessages('@j-schreiber/sf-cli-security-audit', 'org.scan.user-perms');
|
|
7
|
+
export default class OrgUserPermScan extends SfCommand {
|
|
8
|
+
static summary = messages.getMessage('summary');
|
|
9
|
+
static description = messages.getMessage('description');
|
|
10
|
+
static examples = messages.getMessages('examples');
|
|
11
|
+
static flags = {
|
|
12
|
+
name: Flags.string({
|
|
13
|
+
summary: messages.getMessage('flags.name.summary'),
|
|
14
|
+
description: messages.getMessage('flags.name.description'),
|
|
15
|
+
char: 'n',
|
|
16
|
+
multiple: true,
|
|
17
|
+
required: true,
|
|
18
|
+
}),
|
|
19
|
+
'target-org': Flags.requiredOrg({
|
|
20
|
+
summary: messages.getMessage('flags.target-org.summary'),
|
|
21
|
+
char: 'o',
|
|
22
|
+
required: true,
|
|
23
|
+
}),
|
|
24
|
+
'api-version': Flags.orgApiVersion(),
|
|
25
|
+
};
|
|
26
|
+
async run() {
|
|
27
|
+
const { flags } = await this.parse(OrgUserPermScan);
|
|
28
|
+
const scanner = new UserPermissionScanner();
|
|
29
|
+
scanner.on('progress', this.reportProgress);
|
|
30
|
+
const result = await scanner.quickScan({
|
|
31
|
+
targetOrg: flags['target-org'].getConnection(flags['api-version']),
|
|
32
|
+
permissions: flags.name,
|
|
33
|
+
});
|
|
34
|
+
this.print(result);
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
reportProgress = (event) => {
|
|
38
|
+
if (event.status === 'Pending') {
|
|
39
|
+
this.spinner.start('Scanning');
|
|
40
|
+
}
|
|
41
|
+
const counters = [];
|
|
42
|
+
Object.entries(event).forEach(([propName, entityStatus]) => {
|
|
43
|
+
if (isEntityStatus(entityStatus)) {
|
|
44
|
+
counters.push(`${capitalize(propName)} (${entityStatus.resolved}/${entityStatus.total})`);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
this.spinner.status = counters.join(' | ');
|
|
48
|
+
if (event.status === 'Completed') {
|
|
49
|
+
this.spinner.stop();
|
|
50
|
+
this.logSuccess(messages.getMessage('success.scanned-entities-count', [event.profiles.total, event.permissionSets.total]));
|
|
51
|
+
this.log();
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
print(result) {
|
|
55
|
+
this.printSummary(result);
|
|
56
|
+
Object.entries(result.permissions).forEach(([permName, permResult]) => {
|
|
57
|
+
this.printPermissionResults(permName, permResult);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
printSummary(result) {
|
|
61
|
+
const data = [];
|
|
62
|
+
Object.entries(result.permissions).forEach(([permissionName, permResult]) => {
|
|
63
|
+
data.push({
|
|
64
|
+
permissionName,
|
|
65
|
+
profiles: permResult.profiles.length,
|
|
66
|
+
permissionSets: permResult.permissionSets.length,
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
this.table({ data, title: '=== Summary ===', titleOptions: { bold: true } });
|
|
70
|
+
}
|
|
71
|
+
printPermissionResults(permissionName, result) {
|
|
72
|
+
const data = [];
|
|
73
|
+
result.profiles.forEach((entityName) => {
|
|
74
|
+
data.push({ entityName, type: 'Profile' });
|
|
75
|
+
});
|
|
76
|
+
result.permissionSets.forEach((entityName) => {
|
|
77
|
+
data.push({ entityName, type: 'Permission Set' });
|
|
78
|
+
});
|
|
79
|
+
if (data.length > 0) {
|
|
80
|
+
this.table({ data, title: permissionName, titleOptions: { underline: true } });
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
export function isEntityStatus(cls) {
|
|
85
|
+
return cls.total !== undefined && cls.resolved !== undefined;
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=user-perms.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-perms.js","sourceRoot":"","s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CAAC,CAAC;QACH,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE;YAC3C,IAAI,CAAC,IAAI,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,gBAAgB,EAAE,CAAC,CAAC;QACpD,CAAC,CAAC,CAAC;QACH,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACpB,IAAI,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC;QACjF,CAAC;IACH,CAAC;;AAGH,MAAM,UAAU,cAAc,CAAC,GAAY;IACzC,OAAQ,GAAwB,CAAC,KAAK,KAAK,SAAS,IAAK,GAAwB,CAAC,QAAQ,KAAK,SAAS,CAAC;AAC3G,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Connection } from '@salesforce/core';
|
|
2
|
+
import { AuditRunConfig } from '../core/file-mgmt/schema.js';
|
|
3
|
+
import { AuditInitPresets } from './presets.js';
|
|
4
|
+
/**
|
|
5
|
+
* Additional options how the config should be initialised.
|
|
6
|
+
*/
|
|
7
|
+
export type AuditInitOptions = {
|
|
8
|
+
/**
|
|
9
|
+
* When set, config files are created at the target location.
|
|
10
|
+
*/
|
|
11
|
+
targetDir?: string;
|
|
12
|
+
/**
|
|
13
|
+
* An optional preset to initialise classifications and policies.
|
|
14
|
+
*/
|
|
15
|
+
preset?: AuditInitPresets;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Exposes key functionality to load an audit config as static methods. This makes
|
|
19
|
+
* it easy to mock the results during tests.
|
|
20
|
+
*/
|
|
21
|
+
export default class AuditConfig {
|
|
22
|
+
/**
|
|
23
|
+
* Initialise a new audit config from target org and writes
|
|
24
|
+
* files to the destination directory.
|
|
25
|
+
*
|
|
26
|
+
* @param con
|
|
27
|
+
*/
|
|
28
|
+
static init(targetCon: Connection, opts?: AuditInitOptions): Promise<AuditRunConfig>;
|
|
29
|
+
/**
|
|
30
|
+
* Loads an existing audit config from a source directory
|
|
31
|
+
*
|
|
32
|
+
* @param sourceDir
|
|
33
|
+
*/
|
|
34
|
+
static load(sourceDir: string): AuditRunConfig;
|
|
35
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { DefaultFileManager } from '../core/file-mgmt/auditConfigFileManager.js';
|
|
2
|
+
import { initCustomPermissions, initUserPermissions } from './permissionsClassification.js';
|
|
3
|
+
import { initConnectedApps, initPermissionSets, initProfiles, initUsers } from './policyConfigs.js';
|
|
4
|
+
/**
|
|
5
|
+
* Exposes key functionality to load an audit config as static methods. This makes
|
|
6
|
+
* it easy to mock the results during tests.
|
|
7
|
+
*/
|
|
8
|
+
export default class AuditConfig {
|
|
9
|
+
/**
|
|
10
|
+
* Initialise a new audit config from target org and writes
|
|
11
|
+
* files to the destination directory.
|
|
12
|
+
*
|
|
13
|
+
* @param con
|
|
14
|
+
*/
|
|
15
|
+
static async init(targetCon, opts) {
|
|
16
|
+
const conf = { classifications: {}, policies: {} };
|
|
17
|
+
conf.classifications.userPermissions = { content: await initUserPermissions(targetCon, opts?.preset) };
|
|
18
|
+
const customPerms = await initCustomPermissions(targetCon);
|
|
19
|
+
if (customPerms) {
|
|
20
|
+
conf.classifications.customPermissions = { content: customPerms };
|
|
21
|
+
}
|
|
22
|
+
conf.policies.profiles = { content: await initProfiles(targetCon) };
|
|
23
|
+
conf.policies.permissionSets = { content: await initPermissionSets(targetCon) };
|
|
24
|
+
conf.policies.users = { content: await initUsers(targetCon) };
|
|
25
|
+
conf.policies.connectedApps = { content: initConnectedApps() };
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
|
27
|
+
if (opts?.targetDir || opts?.targetDir === '') {
|
|
28
|
+
DefaultFileManager.save(opts.targetDir, conf);
|
|
29
|
+
}
|
|
30
|
+
return conf;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Loads an existing audit config from a source directory
|
|
34
|
+
*
|
|
35
|
+
* @param sourceDir
|
|
36
|
+
*/
|
|
37
|
+
static load(sourceDir) {
|
|
38
|
+
return DefaultFileManager.parse(sourceDir);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=auditConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auditConfig.js","sourceRoot":"","sources":["../../../src/libs/conf-init/auditConfig.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,6CAA6C,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAC5F,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAiBpG;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,WAAW;IAC9B;;;;;OAKG;IACI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAqB,EAAE,IAAuB;QACrE,MAAM,IAAI,GAAmB,EAAE,eAAe,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;QACnE,IAAI,CAAC,eAAe,CAAC,eAAe,GAAG,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC,SAAS,EAAE,IAAI,EAAE,MAAM,CAAC,EAAE,CAAC;QACvG,MAAM,WAAW,GAAG,MAAM,qBAAqB,CAAC,SAAS,CAAC,CAAC;QAC3D,IAAI,WAAW,EAAE,CAAC;YAChB,IAAI,CAAC,eAAe,CAAC,iBAAiB,GAAG,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;QACpE,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,QAAQ,GAAG,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC,SAAS,CAAC,EAAE,CAAC;QACpE,IAAI,CAAC,QAAQ,CAAC,cAAc,GAAG,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC,SAAS,CAAC,EAAE,CAAC;QAChF,IAAI,CAAC,QAAQ,CAAC,KAAK,GAAG,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC,SAAS,CAAC,EAAE,CAAC;QAC9D,IAAI,CAAC,QAAQ,CAAC,aAAa,GAAG,EAAE,OAAO,EAAE,iBAAiB,EAAE,EAAE,CAAC;QAC/D,wEAAwE;QACxE,IAAI,IAAI,EAAE,SAAS,IAAI,IAAI,EAAE,SAAS,KAAK,EAAE,EAAE,CAAC;YAC9C,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;QAChD,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,IAAI,CAAC,SAAiB;QAClC,OAAO,kBAAkB,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAC7C,CAAC;CACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Connection } from '@salesforce/core';
|
|
2
|
+
import { PermissionsConfig } from '../core/file-mgmt/schema.js';
|
|
3
|
+
import { AuditInitPresets } from './presets.js';
|
|
4
|
+
/**
|
|
5
|
+
* Initialises a fresh set of user permissions from target org connection.
|
|
6
|
+
*
|
|
7
|
+
* @param con
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export declare function initUserPermissions(con: Connection, preset?: AuditInitPresets): Promise<PermissionsConfig>;
|
|
11
|
+
/**
|
|
12
|
+
* Initialises a fresh set of custom permissions from the target org
|
|
13
|
+
*
|
|
14
|
+
* @param con
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
export declare function initCustomPermissions(con: Connection): Promise<PermissionsConfig | undefined>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { CUSTOM_PERMS_QUERY, PROFILES_QUERY } from '../core/constants.js';
|
|
2
|
+
import MDAPI from '../core/mdapi/mdapiRetriever.js';
|
|
3
|
+
import { classificationSorter, PermissionRiskLevel } from '../core/classification-types.js';
|
|
4
|
+
import { loadPreset } from './presets.js';
|
|
5
|
+
/**
|
|
6
|
+
* Initialises a fresh set of user permissions from target org connection.
|
|
7
|
+
*
|
|
8
|
+
* @param con
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
export async function initUserPermissions(con, preset) {
|
|
12
|
+
const describePerms = await parsePermsFromDescribe(con);
|
|
13
|
+
const assignedPerms = await findAssignedPerms(con);
|
|
14
|
+
const allPerms = { ...describePerms, ...assignedPerms };
|
|
15
|
+
const presConfig = loadPreset(preset);
|
|
16
|
+
const perms = presConfig.classifyUserPermissions(Object.values(allPerms));
|
|
17
|
+
perms.sort(classificationSorter);
|
|
18
|
+
const result = { permissions: {} };
|
|
19
|
+
perms.forEach((perm) => (result.permissions[perm.name] = {
|
|
20
|
+
label: sanitiseLabel(perm.label),
|
|
21
|
+
classification: perm.classification,
|
|
22
|
+
reason: perm.reason,
|
|
23
|
+
}));
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Initialises a fresh set of custom permissions from the target org
|
|
28
|
+
*
|
|
29
|
+
* @param con
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
export async function initCustomPermissions(con) {
|
|
33
|
+
const result = { permissions: {} };
|
|
34
|
+
const customPerms = await con.query(CUSTOM_PERMS_QUERY);
|
|
35
|
+
if (customPerms.records.length === 0) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
const perms = customPerms.records.map((cp) => ({
|
|
39
|
+
name: cp.DeveloperName,
|
|
40
|
+
label: cp.MasterLabel,
|
|
41
|
+
classification: PermissionRiskLevel.UNKNOWN,
|
|
42
|
+
}));
|
|
43
|
+
perms.forEach((perm) => (result.permissions[perm.name] = {
|
|
44
|
+
label: perm.label,
|
|
45
|
+
classification: perm.classification,
|
|
46
|
+
}));
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
async function parsePermsFromDescribe(con) {
|
|
50
|
+
const permSet = await con.describe('PermissionSet');
|
|
51
|
+
const describeAvailablePerms = {};
|
|
52
|
+
permSet.fields
|
|
53
|
+
.filter((field) => field.name.startsWith('Permissions'))
|
|
54
|
+
.forEach((field) => {
|
|
55
|
+
const permName = field.name.replace('Permissions', '');
|
|
56
|
+
describeAvailablePerms[permName] = {
|
|
57
|
+
label: field.label,
|
|
58
|
+
name: permName,
|
|
59
|
+
};
|
|
60
|
+
});
|
|
61
|
+
return describeAvailablePerms;
|
|
62
|
+
}
|
|
63
|
+
async function findAssignedPerms(con) {
|
|
64
|
+
const assignedPerms = {};
|
|
65
|
+
const profiles = await con.query(PROFILES_QUERY);
|
|
66
|
+
if (profiles.records?.length > 0) {
|
|
67
|
+
const mdapi = new MDAPI(con);
|
|
68
|
+
const resolvedProfiles = await mdapi.resolve('Profile', profiles.records.map((p) => p.Profile.Name));
|
|
69
|
+
Object.values(resolvedProfiles).forEach((profile) => {
|
|
70
|
+
profile.userPermissions.forEach((userPerm) => {
|
|
71
|
+
assignedPerms[userPerm.name] = { name: userPerm.name };
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return assignedPerms;
|
|
76
|
+
}
|
|
77
|
+
function sanitiseLabel(rawLabel) {
|
|
78
|
+
return rawLabel?.replace(/[ \t]+$|[\r\n]+/g, '');
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=permissionsClassification.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permissionsClassification.js","sourceRoot":"","sources":["../../../src/libs/conf-init/permissionsClassification.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC1E,OAAO,KAAK,MAAM,iCAAiC,CAAC;AAEpD,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAC5F,OAAO,EAAoB,UAA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QACjC,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;QAC7B,MAAM,gBAAgB,GAAG,MAAM,KAAK,CAAC,OAAO,CAC1C,SAAS,EACT,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAC5C,CAAC;QACF,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAClD,OAAO,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;gBAC3C,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC;YACzD,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC;AAED,SAAS,aAAa,CAAC,QAAiB;IACtC,OAAO,QAAQ,EAAE,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Connection } from '@salesforce/core';
|
|
2
|
+
import { BasePolicyFileContent, PermSetsPolicyFileContent, ProfilesPolicyFileContent, UsersPolicyFileContent } from '../core/file-mgmt/schema.js';
|
|
3
|
+
/**
|
|
4
|
+
* Initialises a new profiles policy with the local org's
|
|
5
|
+
* profiles and all default rules enabled.
|
|
6
|
+
*
|
|
7
|
+
* @param targetOrgCon
|
|
8
|
+
* @param targetDir
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
export declare function initProfiles(targetOrgCon: Connection): Promise<ProfilesPolicyFileContent>;
|
|
12
|
+
/**
|
|
13
|
+
* Initialises a new permission sets policy with the local org's custom
|
|
14
|
+
* permissions and all default rules enabled.
|
|
15
|
+
*
|
|
16
|
+
* @param targetOrgCon
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
export declare function initPermissionSets(targetOrgCon: Connection): Promise<PermSetsPolicyFileContent>;
|
|
20
|
+
/**
|
|
21
|
+
* Initialises a new connected apps policy with default rules enabled.
|
|
22
|
+
*
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
export declare function initConnectedApps(): BasePolicyFileContent;
|
|
26
|
+
/**
|
|
27
|
+
* Initialises a users policy with all users flagged as standard user
|
|
28
|
+
*
|
|
29
|
+
* @param targetOrgCon
|
|
30
|
+
*/
|
|
31
|
+
export declare function initUsers(targetOrgCon: Connection): Promise<UsersPolicyFileContent>;
|