@evomap/evolver-adapter-public 2.0.33 → 2.0.34
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.
|
@@ -2,7 +2,7 @@ import { randomBytes } from 'node:crypto';
|
|
|
2
2
|
import { execFileSync } from 'node:child_process';
|
|
3
3
|
import { constants, closeSync, fchmodSync, fstatSync, fsyncSync, linkSync, lstatSync, mkdirSync, openSync, readFileSync, renameSync, unlinkSync, writeFileSync, } from 'node:fs';
|
|
4
4
|
import { basename, dirname, resolve, win32 } from 'node:path';
|
|
5
|
-
import {
|
|
5
|
+
import { POWERSHELL_ENV_SCRIPT_COMMAND, windowsAclFailureDetail, } from './windowsPowerShell.js';
|
|
6
6
|
const DIRECTORY_MODE = 0o700;
|
|
7
7
|
const FILE_MODE = 0o600;
|
|
8
8
|
export class CredentialStoreError extends Error {
|
|
@@ -805,17 +805,22 @@ function Assert-TrustedParent([string]$ParentPath, [bool]$StrictCreate) {
|
|
|
805
805
|
$finalParent,
|
|
806
806
|
[System.StringComparison]::OrdinalIgnoreCase
|
|
807
807
|
)
|
|
808
|
-
$
|
|
809
|
-
if (-
|
|
810
|
-
(($
|
|
808
|
+
$attributes = [System.IO.File]::GetAttributes($current)
|
|
809
|
+
if ((($attributes -band [System.IO.FileAttributes]::Directory) -eq 0) -or
|
|
810
|
+
(($attributes -band [System.IO.FileAttributes]::ReparsePoint) -ne 0)) {
|
|
811
811
|
Throw-CredentialAclFailure -Reason 'Credential parent contains a reparse point or non-directory' -Path $current
|
|
812
812
|
}
|
|
813
|
-
$parentAcl =
|
|
813
|
+
$parentAcl = [System.IO.Directory]::GetAccessControl($current)
|
|
814
814
|
$ownerSid = $parentAcl.GetOwner([System.Security.Principal.SecurityIdentifier])
|
|
815
815
|
if ($trustedSids -notcontains $ownerSid.Value) {
|
|
816
816
|
Throw-CredentialAclFailure -Reason 'Credential parent has an untrusted owner' -Path $current -Sid $ownerSid.Value
|
|
817
817
|
}
|
|
818
|
-
|
|
818
|
+
$parentRules = @($parentAcl.GetAccessRules(
|
|
819
|
+
$true,
|
|
820
|
+
$true,
|
|
821
|
+
[System.Security.Principal.SecurityIdentifier]
|
|
822
|
+
))
|
|
823
|
+
foreach ($parentRule in $parentRules) {
|
|
819
824
|
if ($parentRule.AccessControlType -ne [System.Security.AccessControl.AccessControlType]::Allow) {
|
|
820
825
|
continue
|
|
821
826
|
}
|
|
@@ -845,11 +850,8 @@ function Assert-TrustedParent([string]$ParentPath, [bool]$StrictCreate) {
|
|
|
845
850
|
$dangerousGrant = $hasGranularDanger -or ($isCreateParent -and $hasCreateDanger)
|
|
846
851
|
}
|
|
847
852
|
if (-not $dangerousGrant) { continue }
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
[System.Security.Principal.SecurityIdentifier]
|
|
851
|
-
)
|
|
852
|
-
} catch {
|
|
853
|
+
$parentRuleSid = $parentRule.IdentityReference
|
|
854
|
+
if (-not ($parentRuleSid -is [System.Security.Principal.SecurityIdentifier])) {
|
|
853
855
|
Throw-CredentialAclFailure -Reason 'Credential parent contains an unresolvable write principal' -Path $current -Principal $parentRule.IdentityReference.Value -Rights $rights
|
|
854
856
|
}
|
|
855
857
|
if ($trustedSids -notcontains $parentRuleSid.Value) {
|
|
@@ -860,17 +862,22 @@ function Assert-TrustedParent([string]$ParentPath, [bool]$StrictCreate) {
|
|
|
860
862
|
}
|
|
861
863
|
|
|
862
864
|
function Assert-TrustedFile([string]$FilePath) {
|
|
863
|
-
$
|
|
864
|
-
if ($
|
|
865
|
-
(($
|
|
865
|
+
$attributes = [System.IO.File]::GetAttributes($FilePath)
|
|
866
|
+
if ((($attributes -band [System.IO.FileAttributes]::Directory) -ne 0) -or
|
|
867
|
+
(($attributes -band [System.IO.FileAttributes]::ReparsePoint) -ne 0)) {
|
|
866
868
|
Throw-CredentialAclFailure -Reason 'Credential file is a reparse point or not a regular file' -Path $FilePath
|
|
867
869
|
}
|
|
868
|
-
$fileAcl =
|
|
870
|
+
$fileAcl = [System.IO.File]::GetAccessControl($FilePath)
|
|
869
871
|
$ownerSid = $fileAcl.GetOwner([System.Security.Principal.SecurityIdentifier])
|
|
870
872
|
if ($trustedSids -notcontains $ownerSid.Value) {
|
|
871
873
|
Throw-CredentialAclFailure -Reason 'Credential file has an untrusted owner' -Path $FilePath -Sid $ownerSid.Value
|
|
872
874
|
}
|
|
873
|
-
|
|
875
|
+
$fileRules = @($fileAcl.GetAccessRules(
|
|
876
|
+
$true,
|
|
877
|
+
$true,
|
|
878
|
+
[System.Security.Principal.SecurityIdentifier]
|
|
879
|
+
))
|
|
880
|
+
foreach ($fileRule in $fileRules) {
|
|
874
881
|
if ($fileRule.AccessControlType -ne [System.Security.AccessControl.AccessControlType]::Allow) {
|
|
875
882
|
continue
|
|
876
883
|
}
|
|
@@ -884,11 +891,8 @@ function Assert-TrustedFile([string]$FilePath) {
|
|
|
884
891
|
(($rights -band [System.Security.AccessControl.FileSystemRights]::FullControl) -eq
|
|
885
892
|
[System.Security.AccessControl.FileSystemRights]::FullControl)
|
|
886
893
|
if (-not ($hasGranularDanger -or $hasCompositeDanger)) { continue }
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
[System.Security.Principal.SecurityIdentifier]
|
|
890
|
-
)
|
|
891
|
-
} catch {
|
|
894
|
+
$fileRuleSid = $fileRule.IdentityReference
|
|
895
|
+
if (-not ($fileRuleSid -is [System.Security.Principal.SecurityIdentifier])) {
|
|
892
896
|
Throw-CredentialAclFailure -Reason 'Credential file contains an unresolvable write principal' -Path $FilePath -Principal $fileRule.IdentityReference.Value -Rights $rights
|
|
893
897
|
}
|
|
894
898
|
if ($trustedSids -notcontains $fileRuleSid.Value) {
|
|
@@ -903,15 +907,17 @@ function Test-CanonicalCredentialAcl(
|
|
|
903
907
|
[System.Security.AccessControl.InheritanceFlags]$ExpectedInheritance
|
|
904
908
|
) {
|
|
905
909
|
try {
|
|
906
|
-
$candidateRules = @($CandidateAcl.
|
|
910
|
+
$candidateRules = @($CandidateAcl.GetAccessRules(
|
|
911
|
+
$true,
|
|
912
|
+
$true,
|
|
913
|
+
[System.Security.Principal.SecurityIdentifier]
|
|
914
|
+
))
|
|
907
915
|
if (-not $CandidateAcl.AreAccessRulesProtected -or $candidateRules.Count -ne 1) {
|
|
908
916
|
return $false
|
|
909
917
|
}
|
|
910
918
|
$candidateOwner = $CandidateAcl.GetOwner([System.Security.Principal.SecurityIdentifier])
|
|
911
919
|
$candidateRule = $candidateRules[0]
|
|
912
|
-
$candidateRuleSid = $candidateRule.IdentityReference
|
|
913
|
-
[System.Security.Principal.SecurityIdentifier]
|
|
914
|
-
)
|
|
920
|
+
$candidateRuleSid = $candidateRule.IdentityReference
|
|
915
921
|
return (
|
|
916
922
|
$candidateOwner.Value -eq $ExpectedOwner.Value -and
|
|
917
923
|
$candidateRuleSid.Value -eq $ExpectedOwner.Value -and
|
|
@@ -945,13 +951,21 @@ $expectedInheritance = if ($Kind -eq 'directory') {
|
|
|
945
951
|
} else {
|
|
946
952
|
[System.Security.AccessControl.InheritanceFlags]::None
|
|
947
953
|
}
|
|
948
|
-
$acl =
|
|
954
|
+
$acl = if ($Kind -eq 'directory') {
|
|
955
|
+
[System.IO.Directory]::GetAccessControl($Target)
|
|
956
|
+
} else {
|
|
957
|
+
[System.IO.File]::GetAccessControl($Target)
|
|
958
|
+
}
|
|
949
959
|
if (Test-CanonicalCredentialAcl $acl $sid $expectedInheritance) {
|
|
950
960
|
exit 0
|
|
951
961
|
}
|
|
952
962
|
$acl.SetOwner($sid)
|
|
953
963
|
$acl.SetAccessRuleProtection($true, $false)
|
|
954
|
-
foreach ($rule in @($acl.
|
|
964
|
+
foreach ($rule in @($acl.GetAccessRules(
|
|
965
|
+
$true,
|
|
966
|
+
$true,
|
|
967
|
+
[System.Security.Principal.SecurityIdentifier]
|
|
968
|
+
))) { [void]$acl.RemoveAccessRuleSpecific($rule) }
|
|
955
969
|
$access = [System.Security.AccessControl.FileSystemAccessRule]::new(
|
|
956
970
|
$sid,
|
|
957
971
|
[System.Security.AccessControl.FileSystemRights]::FullControl,
|
|
@@ -960,8 +974,13 @@ $access = [System.Security.AccessControl.FileSystemAccessRule]::new(
|
|
|
960
974
|
[System.Security.AccessControl.AccessControlType]::Allow
|
|
961
975
|
)
|
|
962
976
|
[void]$acl.AddAccessRule($access)
|
|
963
|
-
|
|
964
|
-
$
|
|
977
|
+
if ($Kind -eq 'directory') {
|
|
978
|
+
[System.IO.Directory]::SetAccessControl($Target, $acl)
|
|
979
|
+
$verified = [System.IO.Directory]::GetAccessControl($Target)
|
|
980
|
+
} else {
|
|
981
|
+
[System.IO.File]::SetAccessControl($Target, $acl)
|
|
982
|
+
$verified = [System.IO.File]::GetAccessControl($Target)
|
|
983
|
+
}
|
|
965
984
|
if (-not (Test-CanonicalCredentialAcl $verified $sid $expectedInheritance)) {
|
|
966
985
|
Throw-CredentialAclFailure -Reason 'Credential ACL verification failed' -Path $Target -Sid $sid.Value
|
|
967
986
|
}
|
|
@@ -996,23 +1015,23 @@ class PowerShellWindowsAclOps {
|
|
|
996
1015
|
'-NoProfile',
|
|
997
1016
|
'-NonInteractive',
|
|
998
1017
|
'-ExecutionPolicy', 'Bypass',
|
|
999
|
-
//
|
|
1000
|
-
//
|
|
1001
|
-
'-Command',
|
|
1018
|
+
// Keep the trusted constant script out of stdin: Windows PowerShell 5.1
|
|
1019
|
+
// can wait indefinitely for redirected stdin on hosted runners.
|
|
1020
|
+
'-Command', POWERSHELL_ENV_SCRIPT_COMMAND,
|
|
1002
1021
|
], {
|
|
1003
1022
|
encoding: 'utf8',
|
|
1004
1023
|
env: {
|
|
1005
1024
|
SystemRoot: this.systemRoot,
|
|
1006
1025
|
EVOMAP_CREDENTIAL_ACL_TARGET: path,
|
|
1007
1026
|
EVOMAP_CREDENTIAL_ACL_KIND: kind,
|
|
1027
|
+
EVOMAP_CREDENTIAL_ACL_SCRIPT: WINDOWS_ACL_SCRIPT,
|
|
1008
1028
|
},
|
|
1009
1029
|
shell: false,
|
|
1010
1030
|
// Capture both streams rather than discarding them: the script's own
|
|
1011
1031
|
// message names which path level and which SID failed, and without it
|
|
1012
1032
|
// every rejection is indistinguishable from "PowerShell is missing".
|
|
1013
1033
|
// The script prints nothing on success, so this stays quiet normally.
|
|
1014
|
-
|
|
1015
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
1034
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
1016
1035
|
timeout: 15_000,
|
|
1017
1036
|
windowsHide: true,
|
|
1018
1037
|
});
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const POWERSHELL_ENV_SCRIPT_COMMAND = "& ([scriptblock]::Create($env:EVOMAP_CREDENTIAL_ACL_SCRIPT))";
|
|
2
2
|
export declare function windowsAclFailureDetail(cause: unknown): string;
|
|
3
3
|
export declare function stripPowerShellClixml(text: string): string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const
|
|
1
|
+
export const POWERSHELL_ENV_SCRIPT_COMMAND = '& ([scriptblock]::Create($env:EVOMAP_CREDENTIAL_ACL_SCRIPT))';
|
|
2
2
|
export function windowsAclFailureDetail(cause) {
|
|
3
3
|
const error = cause;
|
|
4
4
|
const parts = [];
|
|
@@ -10,12 +10,12 @@ export function windowsAclFailureDetail(cause) {
|
|
|
10
10
|
if (typeof error?.signal === 'string' && error.signal) {
|
|
11
11
|
parts.push('signal ' + normalizePowerShellDiagnostic(error.signal));
|
|
12
12
|
}
|
|
13
|
-
const
|
|
13
|
+
const [stderr, stdout] = [error?.stderr, error?.stdout]
|
|
14
14
|
.map((stream) => (typeof stream === 'string'
|
|
15
15
|
? stream
|
|
16
16
|
: Buffer.isBuffer(stream) ? stream.toString('utf8') : ''))
|
|
17
|
-
.map(stripPowerShellClixml)
|
|
18
|
-
|
|
17
|
+
.map(stripPowerShellClixml);
|
|
18
|
+
const streams = stderr ? [stderr] : stdout ? [stdout] : [];
|
|
19
19
|
if (streams.length > 0) {
|
|
20
20
|
parts.push(streams.join(' | '));
|
|
21
21
|
}
|
package/dist/connect.js
CHANGED
|
@@ -21,13 +21,20 @@ export function connectPublicHub(opts) {
|
|
|
21
21
|
case 'keypair':
|
|
22
22
|
if (!opts.registerPublicKey)
|
|
23
23
|
throw new Error('keypair 模式需 registerPublicKey');
|
|
24
|
-
auth = new KeypairProvider({
|
|
24
|
+
auth = new KeypairProvider({
|
|
25
|
+
credPath: join(dir, 'keys', 'keypair.json'),
|
|
26
|
+
registerPublicKey: opts.registerPublicKey,
|
|
27
|
+
});
|
|
25
28
|
break;
|
|
26
29
|
case 'oauth': {
|
|
27
30
|
// Default to the real HTTP device-flow transport derived from hubUrl;
|
|
28
31
|
// tests/embedders may still inject their own.
|
|
29
32
|
const transport = opts.oauthTransport ?? createOAuthHttpTransport({ hubUrl: opts.hubUrl, fetchFn });
|
|
30
|
-
auth = new PublicOAuthProvider({
|
|
33
|
+
auth = new PublicOAuthProvider({
|
|
34
|
+
credPath: join(dir, 'token.json'),
|
|
35
|
+
machine: { softIdPath: join(dir, 'machine-id') },
|
|
36
|
+
transport,
|
|
37
|
+
});
|
|
31
38
|
break;
|
|
32
39
|
}
|
|
33
40
|
default: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evomap/evolver-adapter-public",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.34",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@evomap/atp-sdk": "^0.1.0",
|
|
20
|
-
"@evomap/evolver-core": "2.0.
|
|
20
|
+
"@evomap/evolver-core": "2.0.34",
|
|
21
21
|
"undici": "^6.27.0"
|
|
22
22
|
},
|
|
23
23
|
"optionalDependencies": {
|