@smythos/sre 1.5.0 → 1.5.2
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/CHANGELOG +62 -0
- package/LICENSE +18 -0
- package/package.json +127 -115
- package/src/Components/APICall/APICall.class.ts +155 -0
- package/src/Components/APICall/AccessTokenManager.ts +130 -0
- package/src/Components/APICall/ArrayBufferResponse.helper.ts +58 -0
- package/src/Components/APICall/OAuth.helper.ts +294 -0
- package/src/Components/APICall/mimeTypeCategories.ts +46 -0
- package/src/Components/APICall/parseData.ts +167 -0
- package/src/Components/APICall/parseHeaders.ts +41 -0
- package/src/Components/APICall/parseProxy.ts +68 -0
- package/src/Components/APICall/parseUrl.ts +91 -0
- package/src/Components/APIEndpoint.class.ts +234 -0
- package/src/Components/APIOutput.class.ts +58 -0
- package/src/Components/AgentPlugin.class.ts +102 -0
- package/src/Components/Async.class.ts +155 -0
- package/src/Components/Await.class.ts +90 -0
- package/src/Components/Classifier.class.ts +158 -0
- package/src/Components/Component.class.ts +94 -0
- package/src/Components/ComponentHost.class.ts +38 -0
- package/src/Components/DataSourceCleaner.class.ts +92 -0
- package/src/Components/DataSourceIndexer.class.ts +181 -0
- package/src/Components/DataSourceLookup.class.ts +141 -0
- package/src/Components/FEncDec.class.ts +29 -0
- package/src/Components/FHash.class.ts +33 -0
- package/src/Components/FSign.class.ts +80 -0
- package/src/Components/FSleep.class.ts +25 -0
- package/src/Components/FTimestamp.class.ts +25 -0
- package/src/Components/FileStore.class.ts +75 -0
- package/src/Components/ForEach.class.ts +97 -0
- package/src/Components/GPTPlugin.class.ts +70 -0
- package/src/Components/GenAILLM.class.ts +395 -0
- package/src/Components/HuggingFace.class.ts +314 -0
- package/src/Components/Image/imageSettings.config.ts +70 -0
- package/src/Components/ImageGenerator.class.ts +407 -0
- package/src/Components/JSONFilter.class.ts +54 -0
- package/src/Components/LLMAssistant.class.ts +213 -0
- package/src/Components/LogicAND.class.ts +28 -0
- package/src/Components/LogicAtLeast.class.ts +85 -0
- package/src/Components/LogicAtMost.class.ts +86 -0
- package/src/Components/LogicOR.class.ts +29 -0
- package/src/Components/LogicXOR.class.ts +34 -0
- package/src/Components/MCPClient.class.ts +112 -0
- package/src/Components/PromptGenerator.class.ts +122 -0
- package/src/Components/ScrapflyWebScrape.class.ts +159 -0
- package/src/Components/TavilyWebSearch.class.ts +98 -0
- package/src/Components/index.ts +77 -0
- package/src/Core/AgentProcess.helper.ts +240 -0
- package/src/Core/Connector.class.ts +123 -0
- package/src/Core/ConnectorsService.ts +192 -0
- package/src/Core/DummyConnector.ts +49 -0
- package/src/Core/HookService.ts +105 -0
- package/src/Core/SmythRuntime.class.ts +292 -0
- package/src/Core/SystemEvents.ts +15 -0
- package/src/Core/boot.ts +55 -0
- package/src/config.ts +15 -0
- package/src/constants.ts +125 -0
- package/src/data/hugging-face.params.json +580 -0
- package/src/helpers/BinaryInput.helper.ts +324 -0
- package/src/helpers/Conversation.helper.ts +1094 -0
- package/src/helpers/JsonContent.helper.ts +97 -0
- package/src/helpers/LocalCache.helper.ts +97 -0
- package/src/helpers/Log.helper.ts +234 -0
- package/src/helpers/OpenApiParser.helper.ts +150 -0
- package/src/helpers/S3Cache.helper.ts +129 -0
- package/src/helpers/SmythURI.helper.ts +5 -0
- package/src/helpers/TemplateString.helper.ts +243 -0
- package/src/helpers/TypeChecker.helper.ts +329 -0
- package/src/index.ts +179 -0
- package/src/index.ts.bak +179 -0
- package/src/subsystems/AgentManager/Agent.class.ts +1108 -0
- package/src/subsystems/AgentManager/Agent.helper.ts +3 -0
- package/src/subsystems/AgentManager/AgentData.service/AgentDataConnector.ts +230 -0
- package/src/subsystems/AgentManager/AgentData.service/connectors/CLIAgentDataConnector.class.ts +66 -0
- package/src/subsystems/AgentManager/AgentData.service/connectors/LocalAgentDataConnector.class.ts +142 -0
- package/src/subsystems/AgentManager/AgentData.service/connectors/NullAgentData.class.ts +39 -0
- package/src/subsystems/AgentManager/AgentData.service/index.ts +18 -0
- package/src/subsystems/AgentManager/AgentLogger.class.ts +297 -0
- package/src/subsystems/AgentManager/AgentRequest.class.ts +51 -0
- package/src/subsystems/AgentManager/AgentRuntime.class.ts +559 -0
- package/src/subsystems/AgentManager/AgentSSE.class.ts +101 -0
- package/src/subsystems/AgentManager/AgentSettings.class.ts +52 -0
- package/src/subsystems/AgentManager/Component.service/ComponentConnector.ts +32 -0
- package/src/subsystems/AgentManager/Component.service/connectors/LocalComponentConnector.class.ts +59 -0
- package/src/subsystems/AgentManager/Component.service/index.ts +11 -0
- package/src/subsystems/AgentManager/EmbodimentSettings.class.ts +47 -0
- package/src/subsystems/AgentManager/ForkedAgent.class.ts +153 -0
- package/src/subsystems/AgentManager/OSResourceMonitor.ts +77 -0
- package/src/subsystems/ComputeManager/Code.service/CodeConnector.ts +99 -0
- package/src/subsystems/ComputeManager/Code.service/connectors/AWSLambdaCode.class.ts +63 -0
- package/src/subsystems/ComputeManager/Code.service/index.ts +11 -0
- package/src/subsystems/IO/CLI.service/CLIConnector.ts +47 -0
- package/src/subsystems/IO/CLI.service/index.ts +9 -0
- package/src/subsystems/IO/Log.service/LogConnector.ts +32 -0
- package/src/subsystems/IO/Log.service/connectors/ConsoleLog.class.ts +28 -0
- package/src/subsystems/IO/Log.service/index.ts +13 -0
- package/src/subsystems/IO/NKV.service/NKVConnector.ts +41 -0
- package/src/subsystems/IO/NKV.service/connectors/NKVRAM.class.ts +204 -0
- package/src/subsystems/IO/NKV.service/connectors/NKVRedis.class.ts +182 -0
- package/src/subsystems/IO/NKV.service/index.ts +12 -0
- package/src/subsystems/IO/Router.service/RouterConnector.ts +21 -0
- package/src/subsystems/IO/Router.service/connectors/ExpressRouter.class.ts +48 -0
- package/src/subsystems/IO/Router.service/connectors/NullRouter.class.ts +40 -0
- package/src/subsystems/IO/Router.service/index.ts +11 -0
- package/src/subsystems/IO/Storage.service/SmythFS.class.ts +472 -0
- package/src/subsystems/IO/Storage.service/StorageConnector.ts +66 -0
- package/src/subsystems/IO/Storage.service/connectors/LocalStorage.class.ts +305 -0
- package/src/subsystems/IO/Storage.service/connectors/S3Storage.class.ts +418 -0
- package/src/subsystems/IO/Storage.service/index.ts +13 -0
- package/src/subsystems/IO/VectorDB.service/VectorDBConnector.ts +108 -0
- package/src/subsystems/IO/VectorDB.service/connectors/MilvusVectorDB.class.ts +450 -0
- package/src/subsystems/IO/VectorDB.service/connectors/PineconeVectorDB.class.ts +373 -0
- package/src/subsystems/IO/VectorDB.service/connectors/RAMVecrtorDB.class.ts +420 -0
- package/src/subsystems/IO/VectorDB.service/embed/BaseEmbedding.ts +106 -0
- package/src/subsystems/IO/VectorDB.service/embed/OpenAIEmbedding.ts +109 -0
- package/src/subsystems/IO/VectorDB.service/embed/index.ts +21 -0
- package/src/subsystems/IO/VectorDB.service/index.ts +14 -0
- package/src/subsystems/LLMManager/LLM.helper.ts +221 -0
- package/src/subsystems/LLMManager/LLM.inference.ts +335 -0
- package/src/subsystems/LLMManager/LLM.service/LLMConnector.ts +374 -0
- package/src/subsystems/LLMManager/LLM.service/LLMCredentials.helper.ts +145 -0
- package/src/subsystems/LLMManager/LLM.service/connectors/Anthropic.class.ts +632 -0
- package/src/subsystems/LLMManager/LLM.service/connectors/Bedrock.class.ts +405 -0
- package/src/subsystems/LLMManager/LLM.service/connectors/Echo.class.ts +81 -0
- package/src/subsystems/LLMManager/LLM.service/connectors/GoogleAI.class.ts +689 -0
- package/src/subsystems/LLMManager/LLM.service/connectors/Groq.class.ts +257 -0
- package/src/subsystems/LLMManager/LLM.service/connectors/OpenAI.class.ts +848 -0
- package/src/subsystems/LLMManager/LLM.service/connectors/Perplexity.class.ts +255 -0
- package/src/subsystems/LLMManager/LLM.service/connectors/VertexAI.class.ts +193 -0
- package/src/subsystems/LLMManager/LLM.service/index.ts +43 -0
- package/src/subsystems/LLMManager/ModelsProvider.service/ModelsProviderConnector.ts +281 -0
- package/src/subsystems/LLMManager/ModelsProvider.service/connectors/SmythModelsProvider.class.ts +229 -0
- package/src/subsystems/LLMManager/ModelsProvider.service/index.ts +11 -0
- package/src/subsystems/LLMManager/custom-models.ts +854 -0
- package/src/subsystems/LLMManager/models.ts +2539 -0
- package/src/subsystems/LLMManager/paramMappings.ts +69 -0
- package/src/subsystems/MemoryManager/Cache.service/CacheConnector.ts +86 -0
- package/src/subsystems/MemoryManager/Cache.service/connectors/LocalStorageCache.class.ts +297 -0
- package/src/subsystems/MemoryManager/Cache.service/connectors/RAMCache.class.ts +201 -0
- package/src/subsystems/MemoryManager/Cache.service/connectors/RedisCache.class.ts +252 -0
- package/src/subsystems/MemoryManager/Cache.service/connectors/S3Cache.class.ts +373 -0
- package/src/subsystems/MemoryManager/Cache.service/index.ts +15 -0
- package/src/subsystems/MemoryManager/LLMCache.ts +72 -0
- package/src/subsystems/MemoryManager/LLMContext.ts +125 -0
- package/src/subsystems/MemoryManager/RuntimeContext.ts +249 -0
- package/src/subsystems/Security/AccessControl/ACL.class.ts +208 -0
- package/src/subsystems/Security/AccessControl/AccessCandidate.class.ts +76 -0
- package/src/subsystems/Security/AccessControl/AccessRequest.class.ts +52 -0
- package/src/subsystems/Security/Account.service/AccountConnector.ts +41 -0
- package/src/subsystems/Security/Account.service/connectors/AWSAccount.class.ts +76 -0
- package/src/subsystems/Security/Account.service/connectors/DummyAccount.class.ts +130 -0
- package/src/subsystems/Security/Account.service/connectors/JSONFileAccount.class.ts +159 -0
- package/src/subsystems/Security/Account.service/index.ts +14 -0
- package/src/subsystems/Security/Credentials.helper.ts +62 -0
- package/src/subsystems/Security/ManagedVault.service/ManagedVaultConnector.ts +34 -0
- package/src/subsystems/Security/ManagedVault.service/connectors/NullManagedVault.class.ts +57 -0
- package/src/subsystems/Security/ManagedVault.service/connectors/SecretManagerManagedVault.ts +154 -0
- package/src/subsystems/Security/ManagedVault.service/index.ts +12 -0
- package/src/subsystems/Security/SecureConnector.class.ts +110 -0
- package/src/subsystems/Security/Vault.service/Vault.helper.ts +30 -0
- package/src/subsystems/Security/Vault.service/VaultConnector.ts +26 -0
- package/src/subsystems/Security/Vault.service/connectors/HashicorpVault.class.ts +46 -0
- package/src/subsystems/Security/Vault.service/connectors/JSONFileVault.class.ts +166 -0
- package/src/subsystems/Security/Vault.service/connectors/NullVault.class.ts +54 -0
- package/src/subsystems/Security/Vault.service/connectors/SecretsManager.class.ts +140 -0
- package/src/subsystems/Security/Vault.service/index.ts +12 -0
- package/src/types/ACL.types.ts +104 -0
- package/src/types/AWS.types.ts +9 -0
- package/src/types/Agent.types.ts +61 -0
- package/src/types/AgentLogger.types.ts +17 -0
- package/src/types/Cache.types.ts +1 -0
- package/src/types/Common.types.ts +3 -0
- package/src/types/LLM.types.ts +419 -0
- package/src/types/Redis.types.ts +8 -0
- package/src/types/SRE.types.ts +64 -0
- package/src/types/Security.types.ts +18 -0
- package/src/types/Storage.types.ts +5 -0
- package/src/types/VectorDB.types.ts +78 -0
- package/src/utils/base64.utils.ts +275 -0
- package/src/utils/cli.utils.ts +68 -0
- package/src/utils/data.utils.ts +263 -0
- package/src/utils/date-time.utils.ts +22 -0
- package/src/utils/general.utils.ts +238 -0
- package/src/utils/index.ts +12 -0
- package/src/utils/numbers.utils.ts +13 -0
- package/src/utils/oauth.utils.ts +35 -0
- package/src/utils/string.utils.ts +414 -0
- package/src/utils/url.utils.ts +19 -0
- package/src/utils/validation.utils.ts +74 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ConnectorService } from '@sre/Core/ConnectorsService';
|
|
2
|
+
import { Logger } from '@sre/helpers/Log.helper';
|
|
3
|
+
//import { SmythRuntime } from '@sre/Core/SmythRuntime.class';
|
|
4
|
+
import { AccessCandidate } from '@sre/Security/AccessControl/AccessCandidate.class';
|
|
5
|
+
import { AccessRequest } from '@sre/Security/AccessControl/AccessRequest.class';
|
|
6
|
+
import { ACL } from '@sre/Security/AccessControl/ACL.class';
|
|
7
|
+
import { SecureConnector } from '@sre/Security/SecureConnector.class';
|
|
8
|
+
import { IAccessCandidate, TAccessLevel, TAccessRole } from '@sre/types/ACL.types';
|
|
9
|
+
import { OAuthConfig, SmythConfigs } from '@sre/types/Security.types';
|
|
10
|
+
|
|
11
|
+
import { getM2MToken } from '@sre/utils/oauth.utils';
|
|
12
|
+
import axios, { AxiosInstance } from 'axios';
|
|
13
|
+
import { ManagedVaultConnector } from '../ManagedVaultConnector';
|
|
14
|
+
|
|
15
|
+
const console = Logger('NullManagedVault');
|
|
16
|
+
export class NullManagedVault extends ManagedVaultConnector {
|
|
17
|
+
public name: string = 'NullManagedVault';
|
|
18
|
+
|
|
19
|
+
constructor(protected _settings: any) {
|
|
20
|
+
super(_settings);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@SecureConnector.AccessControl
|
|
24
|
+
protected async get(acRequest: AccessRequest, keyId: string) {
|
|
25
|
+
console.debug(`Ignored operation:NullManagedVault.get: ${keyId}`);
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@SecureConnector.AccessControl
|
|
30
|
+
protected async set(acRequest: AccessRequest, keyId: string, value: string) {
|
|
31
|
+
console.debug(`Ignored operation:NullManagedVault.set: ${keyId} = ${value}`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@SecureConnector.AccessControl
|
|
35
|
+
protected async delete(acRequest: AccessRequest, keyId: string) {
|
|
36
|
+
console.debug(`Ignored operation:NullManagedVault.delete: ${keyId}`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@SecureConnector.AccessControl
|
|
40
|
+
protected async exists(acRequest: AccessRequest, keyId: string) {
|
|
41
|
+
console.debug(`Ignored operation:NullManagedVault.exists: ${keyId}`);
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public async getResourceACL(resourceId: string, candidate: IAccessCandidate) {
|
|
46
|
+
const accountConnector = ConnectorService.getAccountConnector();
|
|
47
|
+
const teamId = await accountConnector.getCandidateTeam(candidate);
|
|
48
|
+
|
|
49
|
+
const acl = new ACL();
|
|
50
|
+
|
|
51
|
+
//give just read access by default
|
|
52
|
+
//Cannot write to null vault
|
|
53
|
+
acl.addAccess(candidate.role, candidate.id, TAccessLevel.Read);
|
|
54
|
+
|
|
55
|
+
return acl;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { ConnectorService } from '@sre/Core/ConnectorsService';
|
|
2
|
+
import { Logger } from '@sre/helpers/Log.helper';
|
|
3
|
+
//import { SmythRuntime } from '@sre/Core/SmythRuntime.class';
|
|
4
|
+
import { AccessRequest } from '@sre/Security/AccessControl/AccessRequest.class';
|
|
5
|
+
import { ACL } from '@sre/Security/AccessControl/ACL.class';
|
|
6
|
+
import { SecureConnector } from '@sre/Security/SecureConnector.class';
|
|
7
|
+
import { IAccessCandidate, TAccessLevel, TAccessRole } from '@sre/types/ACL.types';
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
CreateSecretCommand,
|
|
11
|
+
DeleteSecretCommand,
|
|
12
|
+
GetSecretValueCommand,
|
|
13
|
+
GetSecretValueCommandOutput,
|
|
14
|
+
ListSecretsCommand,
|
|
15
|
+
ListSecretsCommandOutput,
|
|
16
|
+
PutSecretValueCommand,
|
|
17
|
+
SecretsManagerClient,
|
|
18
|
+
} from '@aws-sdk/client-secrets-manager';
|
|
19
|
+
import { randomUUID } from 'crypto';
|
|
20
|
+
import { ManagedVaultConnector } from '../ManagedVaultConnector';
|
|
21
|
+
import { SecretsManagerConfig } from '../../Vault.service/connectors/SecretsManager.class';
|
|
22
|
+
|
|
23
|
+
const console = Logger('SecretManagerManagedVault');
|
|
24
|
+
|
|
25
|
+
export class SecretManagerManagedVault extends ManagedVaultConnector {
|
|
26
|
+
public name: string = 'SecretManagerManagedVault';
|
|
27
|
+
public scope: string = 'smyth-managed-vault';
|
|
28
|
+
private secretsManager: SecretsManagerClient;
|
|
29
|
+
|
|
30
|
+
constructor(protected _settings: SecretsManagerConfig & { vaultName: string }) {
|
|
31
|
+
super(_settings);
|
|
32
|
+
//if (!SmythRuntime.Instance) throw new Error('SRE not initialized');
|
|
33
|
+
|
|
34
|
+
this.secretsManager = new SecretsManagerClient({
|
|
35
|
+
region: _settings.region,
|
|
36
|
+
...(_settings.awsAccessKeyId && _settings.awsSecretAccessKey
|
|
37
|
+
? {
|
|
38
|
+
accessKeyId: _settings.awsAccessKeyId,
|
|
39
|
+
secretAccessKey: _settings.awsSecretAccessKey,
|
|
40
|
+
}
|
|
41
|
+
: {}),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@SecureConnector.AccessControl
|
|
46
|
+
protected async get(acRequest: AccessRequest, secretName: string) {
|
|
47
|
+
const secret = await this.getSecretByName(secretName);
|
|
48
|
+
return secret?.SecretString;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@SecureConnector.AccessControl
|
|
52
|
+
protected async set(acRequest: AccessRequest, secretName: string, value: string) {
|
|
53
|
+
const secret = await this.getSecretByName(secretName);
|
|
54
|
+
if (secret) {
|
|
55
|
+
await this.secretsManager.send(new PutSecretValueCommand({ SecretId: secret.ARN, SecretString: value }));
|
|
56
|
+
} else {
|
|
57
|
+
await this.secretsManager.send(
|
|
58
|
+
new CreateSecretCommand({
|
|
59
|
+
Name: `smyth/${randomUUID()}`,
|
|
60
|
+
SecretString: JSON.stringify({ [secretName]: value }),
|
|
61
|
+
Tags: [{ Key: this.scope, Value: 'true' }],
|
|
62
|
+
})
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@SecureConnector.AccessControl
|
|
68
|
+
protected async delete(acRequest: AccessRequest, secretName: string) {
|
|
69
|
+
const secret = await this.getSecretByName(secretName);
|
|
70
|
+
if (secret) {
|
|
71
|
+
await this.secretsManager.send(new DeleteSecretCommand({ SecretId: secret.ARN }));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@SecureConnector.AccessControl
|
|
76
|
+
protected async exists(acRequest: AccessRequest, secretName: string) {
|
|
77
|
+
const secret = await this.get(acRequest, secretName);
|
|
78
|
+
return !!secret;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
public async getResourceACL(resourceId: string, candidate: IAccessCandidate) {
|
|
82
|
+
const accountConnector = ConnectorService.getAccountConnector();
|
|
83
|
+
const teamId = await accountConnector.getCandidateTeam(candidate);
|
|
84
|
+
|
|
85
|
+
const acl = new ACL();
|
|
86
|
+
|
|
87
|
+
acl.addAccess(TAccessRole.Team, teamId, TAccessLevel.Owner)
|
|
88
|
+
.addAccess(TAccessRole.Team, teamId, TAccessLevel.Read)
|
|
89
|
+
.addAccess(TAccessRole.Team, teamId, TAccessLevel.Write);
|
|
90
|
+
|
|
91
|
+
return acl;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
private async getSecretByName(secretName: string) {
|
|
95
|
+
try {
|
|
96
|
+
const secrets = [];
|
|
97
|
+
let nextToken: string | undefined;
|
|
98
|
+
do {
|
|
99
|
+
const listResponse: ListSecretsCommandOutput = await this.secretsManager.send(
|
|
100
|
+
new ListSecretsCommand({ NextToken: nextToken, Filters: [{ Key: 'tag-key', Values: [this.scope] }] })
|
|
101
|
+
);
|
|
102
|
+
if (listResponse.SecretList) {
|
|
103
|
+
for (const secret of listResponse.SecretList) {
|
|
104
|
+
if (secret.Name) {
|
|
105
|
+
secrets.push({
|
|
106
|
+
ARN: secret.ARN,
|
|
107
|
+
Name: secret.Name,
|
|
108
|
+
CreatedDate: secret.CreatedDate,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
nextToken = listResponse.NextToken;
|
|
114
|
+
} while (nextToken);
|
|
115
|
+
|
|
116
|
+
const formattedSecrets = [];
|
|
117
|
+
const $promises = [];
|
|
118
|
+
for (const secret of secrets) {
|
|
119
|
+
$promises.push(getSpecificSecret(secret, this.secretsManager));
|
|
120
|
+
}
|
|
121
|
+
const results = await Promise.all($promises);
|
|
122
|
+
for (const result of results) {
|
|
123
|
+
formattedSecrets.push(result);
|
|
124
|
+
}
|
|
125
|
+
const secret = formattedSecrets.find((s) => s.Name === secretName);
|
|
126
|
+
return secret;
|
|
127
|
+
} catch (error) {
|
|
128
|
+
console.error(error);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async function getSpecificSecret(secret, secretsManager: SecretsManagerClient) {
|
|
132
|
+
const data: GetSecretValueCommandOutput = await secretsManager.send(new GetSecretValueCommand({ SecretId: secret.ARN }));
|
|
133
|
+
let secretString = data.SecretString;
|
|
134
|
+
let secretName = secret.Name;
|
|
135
|
+
|
|
136
|
+
if (secretString) {
|
|
137
|
+
try {
|
|
138
|
+
let parsedSecret = JSON.parse(secretString);
|
|
139
|
+
if (Object.keys(parsedSecret).length === 1) {
|
|
140
|
+
secretName = Object.keys(parsedSecret)[0];
|
|
141
|
+
secretString = parsedSecret[secretName];
|
|
142
|
+
}
|
|
143
|
+
} catch (error) {}
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
Name: secretName,
|
|
147
|
+
ARN: secret.ARN,
|
|
148
|
+
CreatedDate: secret.CreatedDate,
|
|
149
|
+
SecretId: secret.Name,
|
|
150
|
+
SecretString: secretString,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ConnectorService, ConnectorServiceProvider } from '@sre/Core/ConnectorsService';
|
|
2
|
+
import { TConnectorService } from '@sre/types/SRE.types';
|
|
3
|
+
|
|
4
|
+
import { SecretManagerManagedVault } from './connectors/SecretManagerManagedVault';
|
|
5
|
+
import { NullManagedVault } from './connectors/NullManagedVault.class';
|
|
6
|
+
|
|
7
|
+
export class ManagedVaultService extends ConnectorServiceProvider {
|
|
8
|
+
public register() {
|
|
9
|
+
ConnectorService.register(TConnectorService.ManagedVault, 'SecretManagerManagedVault', SecretManagerManagedVault);
|
|
10
|
+
ConnectorService.register(TConnectorService.ManagedVault, 'NullManagedVault', NullManagedVault);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Connector } from '@sre/Core/Connector.class';
|
|
2
|
+
import { ConnectorService } from '@sre/Core/ConnectorsService';
|
|
3
|
+
import { Logger } from '@sre/helpers/Log.helper';
|
|
4
|
+
import { ACLAccessDeniedError, IAccessCandidate, TAccessLevel, TAccessResult, TAccessTicket } from '@sre/types/ACL.types';
|
|
5
|
+
import { ACL } from './AccessControl/ACL.class';
|
|
6
|
+
import { AccessCandidate } from './AccessControl/AccessCandidate.class';
|
|
7
|
+
import { AccessRequest } from './AccessControl/AccessRequest.class';
|
|
8
|
+
|
|
9
|
+
const console = Logger('SecureConnector');
|
|
10
|
+
|
|
11
|
+
export abstract class SecureConnector<TRequest = any> extends Connector<TRequest> {
|
|
12
|
+
public abstract name: string;
|
|
13
|
+
|
|
14
|
+
//this determines the access rights for the requested resource
|
|
15
|
+
//the connector should check if the resource exists or not
|
|
16
|
+
//if the resource exists we read its ACL and return it
|
|
17
|
+
//if the resource does not exist we return an write access ACL for the candidate
|
|
18
|
+
public abstract getResourceACL(resourceId: string, candidate: IAccessCandidate): Promise<ACL>;
|
|
19
|
+
|
|
20
|
+
public async start() {
|
|
21
|
+
console.info(`Starting ${this.name} connector ...`);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public async stop() {
|
|
25
|
+
console.info(`Stopping ${this.name} connector ...`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
protected async hasAccess(acRequest: AccessRequest) {
|
|
29
|
+
const aclHelper = await this.getResourceACL(acRequest.resourceId, acRequest.candidate).catch((error) => {
|
|
30
|
+
console.error(`Error getting ACL for ${acRequest.resourceId}: ${error}`);
|
|
31
|
+
return null;
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
if (!aclHelper) return false;
|
|
35
|
+
|
|
36
|
+
//const aclHelper = ACLHelper.from(acl);
|
|
37
|
+
|
|
38
|
+
const exactAccess = aclHelper.checkExactAccess(acRequest);
|
|
39
|
+
if (exactAccess) return true;
|
|
40
|
+
|
|
41
|
+
// if the exact access is denied, we check if the candidate has a higher access
|
|
42
|
+
const ownerRequest = AccessRequest.clone(acRequest).setLevel(TAccessLevel.Owner);
|
|
43
|
+
const ownerAccess = aclHelper.checkExactAccess(ownerRequest);
|
|
44
|
+
if (ownerAccess) return true;
|
|
45
|
+
|
|
46
|
+
// if the exact access is denied, we check if the requested resource has a public access
|
|
47
|
+
const publicRequest = AccessRequest.clone(acRequest).setCandidate(AccessCandidate.public());
|
|
48
|
+
const publicAccess = aclHelper.checkExactAccess(publicRequest);
|
|
49
|
+
if (publicAccess) return true;
|
|
50
|
+
|
|
51
|
+
// if the public access is denied, we check if the candidate's team has access
|
|
52
|
+
const accountConnector = ConnectorService.getAccountConnector();
|
|
53
|
+
const teamId = await accountConnector.getCandidateTeam(acRequest.candidate);
|
|
54
|
+
const teamRequest = AccessRequest.clone(acRequest).setCandidate(AccessCandidate.team(teamId));
|
|
55
|
+
const teamAccess = aclHelper.checkExactAccess(teamRequest);
|
|
56
|
+
if (teamAccess) return true;
|
|
57
|
+
|
|
58
|
+
// if the team access is denied, we check if the team has a higher access
|
|
59
|
+
const teamOwnerRequest = AccessRequest.clone(teamRequest).setLevel(TAccessLevel.Owner);
|
|
60
|
+
const teamOwnerAccess = aclHelper.checkExactAccess(teamOwnerRequest);
|
|
61
|
+
if (teamOwnerAccess) return true;
|
|
62
|
+
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
public async getAccessTicket(resourceId: string, request: AccessRequest): Promise<TAccessTicket> {
|
|
66
|
+
const sysAcRequest = AccessRequest.clone(request).resource(resourceId);
|
|
67
|
+
const accessTicket = {
|
|
68
|
+
request,
|
|
69
|
+
access: (await this.hasAccess(sysAcRequest)) ? TAccessResult.Granted : TAccessResult.Denied,
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
return accessTicket as TAccessTicket;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
//#region [ Decorators ]==========================
|
|
76
|
+
|
|
77
|
+
//AccessControl decorator
|
|
78
|
+
//This decorator will inject the access control logic into storage connector methods
|
|
79
|
+
// in order to work properly, the connector expects the resourceId to be the first argument and the access request to be the second argument
|
|
80
|
+
|
|
81
|
+
static AccessControl(target: any, propertyKey: string, descriptor: PropertyDescriptor) {
|
|
82
|
+
// Store the original method in a variable
|
|
83
|
+
const originalMethod = descriptor.value;
|
|
84
|
+
|
|
85
|
+
// Modify the descriptor's value to wrap the original method
|
|
86
|
+
descriptor.value = async function (...args: any[]) {
|
|
87
|
+
// Extract the method arguments
|
|
88
|
+
const [acRequest, resourceId] = args;
|
|
89
|
+
|
|
90
|
+
if (resourceId !== undefined) {
|
|
91
|
+
//: getAccessTicket requires a resourceId
|
|
92
|
+
//FIXME: implement different access control for resources listing and methods that do not require a resourceId
|
|
93
|
+
// Inject the access control logic
|
|
94
|
+
const accessTicket = await this.getAccessTicket(resourceId, acRequest);
|
|
95
|
+
if (accessTicket.access !== TAccessResult.Granted) {
|
|
96
|
+
console.error(`Access denied for ${acRequest.candidate.id} on ${resourceId}`);
|
|
97
|
+
throw new ACLAccessDeniedError('Access Denied');
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Call the original method with the original arguments
|
|
102
|
+
return originalMethod.apply(this, args);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
// Return the modified descriptor
|
|
106
|
+
return descriptor;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
//#endregion
|
|
110
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ConnectorService } from '@sre/Core/ConnectorsService';
|
|
2
|
+
import { AccessCandidate } from '../AccessControl/AccessCandidate.class';
|
|
3
|
+
import axios from 'axios';
|
|
4
|
+
import config from '@sre/config';
|
|
5
|
+
import qs from 'qs';
|
|
6
|
+
|
|
7
|
+
export class VaultHelper {
|
|
8
|
+
static async getTeamKey(key: string, teamId: string): Promise<string> {
|
|
9
|
+
const vaultConnector = ConnectorService.getVaultConnector();
|
|
10
|
+
return await vaultConnector.requester(AccessCandidate.team(teamId)).get(key);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static async getUserKey(key: string, userId: string): Promise<string> {
|
|
14
|
+
const vaultConnector = ConnectorService.getVaultConnector();
|
|
15
|
+
const accountConnector = ConnectorService.getAccountConnector();
|
|
16
|
+
|
|
17
|
+
const teamId = await accountConnector.getCandidateTeam(AccessCandidate.user(userId));
|
|
18
|
+
|
|
19
|
+
return await vaultConnector.requester(AccessCandidate.team(teamId)).get(key);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static async getAgentKey(key: string, agentId: string): Promise<string> {
|
|
23
|
+
const vaultConnector = ConnectorService.getVaultConnector();
|
|
24
|
+
const accountConnector = ConnectorService.getAccountConnector();
|
|
25
|
+
|
|
26
|
+
const teamId = await accountConnector.getCandidateTeam(AccessCandidate.agent(agentId));
|
|
27
|
+
|
|
28
|
+
return await vaultConnector.requester(AccessCandidate.team(teamId)).get(key);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ACL } from '@sre/Security/AccessControl/ACL.class';
|
|
2
|
+
import { AccessCandidate } from '@sre/Security/AccessControl/AccessCandidate.class';
|
|
3
|
+
import { AccessRequest } from '@sre/Security/AccessControl/AccessRequest.class';
|
|
4
|
+
import { SecureConnector } from '@sre/Security/SecureConnector.class';
|
|
5
|
+
import { IAccessCandidate, IACL } from '@sre/types/ACL.types';
|
|
6
|
+
|
|
7
|
+
export interface IVaultRequest {
|
|
8
|
+
get(keyId: string): Promise<string>;
|
|
9
|
+
exists(keyId: string): Promise<boolean>;
|
|
10
|
+
listKeys(): Promise<string[]>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export abstract class VaultConnector extends SecureConnector {
|
|
14
|
+
requester(candidate: AccessCandidate): IVaultRequest {
|
|
15
|
+
return {
|
|
16
|
+
get: async (keyId: string) => this.get(candidate.readRequest, keyId),
|
|
17
|
+
exists: async (keyId: string) => this.exists(candidate.readRequest, keyId),
|
|
18
|
+
listKeys: async () => this.listKeys(candidate.readRequest),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public abstract getResourceACL(resourceId: string, candidate: IAccessCandidate): Promise<ACL>;
|
|
23
|
+
protected abstract get(acRequest: AccessRequest, keyId: string): Promise<string>;
|
|
24
|
+
protected abstract exists(acRequest: AccessRequest, keyId: string): Promise<boolean>;
|
|
25
|
+
protected abstract listKeys(acRequest: AccessRequest): Promise<string[]>;
|
|
26
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ConnectorService } from '@sre/Core/ConnectorsService';
|
|
2
|
+
import { Logger } from '@sre/helpers/Log.helper';
|
|
3
|
+
import { AccessCandidate } from '@sre/Security/AccessControl/AccessCandidate.class';
|
|
4
|
+
import { AccessRequest } from '@sre/Security/AccessControl/AccessRequest.class';
|
|
5
|
+
import { ACL } from '@sre/Security/AccessControl/ACL.class';
|
|
6
|
+
import { SecureConnector } from '@sre/Security/SecureConnector.class';
|
|
7
|
+
import { IAccessCandidate, TAccessLevel, TAccessRole } from '@sre/types/ACL.types';
|
|
8
|
+
import { IVaultRequest, VaultConnector } from '../VaultConnector';
|
|
9
|
+
|
|
10
|
+
const console = Logger('HashicorpVault');
|
|
11
|
+
export class HashicorpVault extends VaultConnector {
|
|
12
|
+
public name: string = 'HashicorpVault';
|
|
13
|
+
|
|
14
|
+
constructor(protected _settings: any) {
|
|
15
|
+
super(_settings);
|
|
16
|
+
//hashicorp client/api
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@SecureConnector.AccessControl
|
|
20
|
+
protected async get(acRequest: AccessRequest, keyId: string) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@SecureConnector.AccessControl
|
|
25
|
+
protected async exists(acRequest: AccessRequest, keyId: string) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@SecureConnector.AccessControl
|
|
30
|
+
protected async listKeys(acRequest: AccessRequest) {
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public async getResourceACL(resourceId: string, candidate: IAccessCandidate) {
|
|
35
|
+
//FIXME : this is for dev, it always give full access, we must update the logic
|
|
36
|
+
const accountConnector = ConnectorService.getAccountConnector();
|
|
37
|
+
const teamId = await accountConnector.getCandidateTeam(candidate);
|
|
38
|
+
const acl = new ACL();
|
|
39
|
+
|
|
40
|
+
acl.addAccess(TAccessRole.Team, teamId, TAccessLevel.Owner)
|
|
41
|
+
.addAccess(TAccessRole.Team, teamId, TAccessLevel.Read)
|
|
42
|
+
.addAccess(TAccessRole.Team, teamId, TAccessLevel.Write);
|
|
43
|
+
|
|
44
|
+
return acl;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { ConnectorService } from '@sre/Core/ConnectorsService';
|
|
2
|
+
import { Logger } from '@sre/helpers/Log.helper';
|
|
3
|
+
import { SmythRuntime } from '@sre/Core/SmythRuntime.class';
|
|
4
|
+
import { AccessCandidate } from '@sre/Security/AccessControl/AccessCandidate.class';
|
|
5
|
+
import { AccessRequest } from '@sre/Security/AccessControl/AccessRequest.class';
|
|
6
|
+
import { ACL } from '@sre/Security/AccessControl/ACL.class';
|
|
7
|
+
import { SecureConnector } from '@sre/Security/SecureConnector.class';
|
|
8
|
+
import { IAccessCandidate, TAccessLevel, TAccessRole } from '@sre/types/ACL.types';
|
|
9
|
+
import { EncryptionSettings } from '@sre/types/Security.types';
|
|
10
|
+
import { IVaultRequest, VaultConnector } from '../VaultConnector';
|
|
11
|
+
import os from 'os';
|
|
12
|
+
import crypto from 'crypto';
|
|
13
|
+
import fs from 'fs';
|
|
14
|
+
import * as readlineSync from 'readline-sync';
|
|
15
|
+
import path from 'path';
|
|
16
|
+
|
|
17
|
+
const console = Logger('JSONFileVault');
|
|
18
|
+
|
|
19
|
+
export type JSONFileVaultConfig = {
|
|
20
|
+
file?: string;
|
|
21
|
+
fileKey?: string;
|
|
22
|
+
shared?: boolean;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export class JSONFileVault extends VaultConnector {
|
|
26
|
+
public name: string = 'JSONFileVault';
|
|
27
|
+
private vaultData: any;
|
|
28
|
+
private index: any;
|
|
29
|
+
private sharedVault: boolean;
|
|
30
|
+
|
|
31
|
+
constructor(protected _settings: JSONFileVaultConfig) {
|
|
32
|
+
super(_settings);
|
|
33
|
+
//if (!SmythRuntime.Instance) throw new Error('SRE not initialized');
|
|
34
|
+
|
|
35
|
+
this.sharedVault = _settings.shared || false; //if config.shared, all keys are accessible to all teams, and they are set under the 'shared' teamId
|
|
36
|
+
|
|
37
|
+
let vaultFile = this.findVaultFile(_settings.file);
|
|
38
|
+
this.vaultData = {};
|
|
39
|
+
if (fs.existsSync(vaultFile)) {
|
|
40
|
+
try {
|
|
41
|
+
if (_settings.fileKey && fs.existsSync(_settings.fileKey)) {
|
|
42
|
+
try {
|
|
43
|
+
const privateKey = fs.readFileSync(_settings.fileKey, 'utf8');
|
|
44
|
+
const encryptedVault = fs.readFileSync(vaultFile, 'utf8').toString();
|
|
45
|
+
const decryptedBuffer = crypto.privateDecrypt(
|
|
46
|
+
{
|
|
47
|
+
key: privateKey,
|
|
48
|
+
padding: crypto.constants.RSA_PKCS1_OAEP_PADDING,
|
|
49
|
+
},
|
|
50
|
+
Buffer.from(encryptedVault, 'base64')
|
|
51
|
+
);
|
|
52
|
+
this.vaultData = JSON.parse(decryptedBuffer.toString('utf8'));
|
|
53
|
+
} catch (error) {
|
|
54
|
+
throw new Error('Failed to decrypt vault');
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
this.vaultData = JSON.parse(fs.readFileSync(vaultFile).toString());
|
|
58
|
+
}
|
|
59
|
+
} catch (e) {
|
|
60
|
+
this.vaultData = {};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (this.vaultData?.encrypted && this.vaultData?.algorithm && this.vaultData?.data) {
|
|
64
|
+
//this is an encrypted vault we need to request the master key
|
|
65
|
+
this.setInteraction(this.getMasterKeyInteractive.bind(this));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
for (let teamId in this.vaultData) {
|
|
69
|
+
for (let resourceId in this.vaultData[teamId]) {
|
|
70
|
+
if (!this.index) this.index = {};
|
|
71
|
+
if (!this.index[resourceId]) this.index[resourceId] = {};
|
|
72
|
+
const value = this.vaultData[teamId][resourceId];
|
|
73
|
+
this.index[resourceId][teamId] = value;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
private findVaultFile(vaultFile) {
|
|
80
|
+
let _vaultFile = vaultFile;
|
|
81
|
+
|
|
82
|
+
if (fs.existsSync(_vaultFile)) {
|
|
83
|
+
return _vaultFile;
|
|
84
|
+
}
|
|
85
|
+
console.warn('Vault file not found in:', _vaultFile, 'trying to find in local .smyth directory');
|
|
86
|
+
|
|
87
|
+
//try local directory
|
|
88
|
+
_vaultFile = path.join(process.cwd(), '.smyth', '.sre', 'vault.json');
|
|
89
|
+
if (fs.existsSync(_vaultFile)) {
|
|
90
|
+
console.warn('Using alternative vault file found in : ', _vaultFile);
|
|
91
|
+
return _vaultFile;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
console.warn('Vault file not found in:', _vaultFile, 'trying to find in user home directory');
|
|
95
|
+
//try to find the vault file in the .smyth directory
|
|
96
|
+
_vaultFile = path.join(os.homedir(), '.smyth', '.sre', 'vault.json');
|
|
97
|
+
if (fs.existsSync(_vaultFile)) {
|
|
98
|
+
console.warn('Using alternative vault file found in : ', _vaultFile);
|
|
99
|
+
return _vaultFile;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
console.warn('Vault file not found in:', _vaultFile);
|
|
103
|
+
console.warn('!!! All attempts to find the vault file failed !!!');
|
|
104
|
+
console.warn('!!! Will continue without vault !!!');
|
|
105
|
+
console.warn('!!! Many features might not work !!!');
|
|
106
|
+
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
private getMasterKeyInteractive(): string {
|
|
111
|
+
//read master key using readline-sync (blocking)
|
|
112
|
+
|
|
113
|
+
process.stdout.write('\x1b[1;37m===[ Encrypted Vault Detected ]=================================\x1b[0m\n');
|
|
114
|
+
const masterKey = readlineSync.question('Enter master key: ', {
|
|
115
|
+
hideEchoBack: true,
|
|
116
|
+
mask: '*',
|
|
117
|
+
});
|
|
118
|
+
console.info('Master key entered');
|
|
119
|
+
return masterKey;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
@SecureConnector.AccessControl
|
|
123
|
+
protected async get(acRequest: AccessRequest, keyId: string) {
|
|
124
|
+
const accountConnector = ConnectorService.getAccountConnector();
|
|
125
|
+
const teamId = await accountConnector.getCandidateTeam(acRequest.candidate);
|
|
126
|
+
|
|
127
|
+
return this.vaultData?.[teamId]?.[keyId] || this.vaultData?.['shared']?.[keyId];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
@SecureConnector.AccessControl
|
|
131
|
+
protected async exists(acRequest: AccessRequest, keyId: string) {
|
|
132
|
+
const accountConnector = ConnectorService.getAccountConnector();
|
|
133
|
+
const teamId = await accountConnector.getCandidateTeam(acRequest.candidate);
|
|
134
|
+
return !!(this.vaultData?.[teamId]?.[keyId] || this.vaultData?.['shared']?.[keyId]);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
@SecureConnector.AccessControl
|
|
138
|
+
protected async listKeys(acRequest: AccessRequest) {
|
|
139
|
+
return Object.keys(this.vaultData);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
public async getResourceACL(resourceId: string, candidate: IAccessCandidate) {
|
|
143
|
+
const accountConnector = ConnectorService.getAccountConnector();
|
|
144
|
+
const teamId = /*this.sharedVault ? 'shared' : */ await accountConnector.getCandidateTeam(candidate);
|
|
145
|
+
|
|
146
|
+
const acl = new ACL();
|
|
147
|
+
|
|
148
|
+
if (resourceId && typeof this.vaultData?.[teamId]?.[resourceId] !== 'string') {
|
|
149
|
+
if (this.sharedVault && typeof this.vaultData?.['shared']?.[resourceId] === 'string') {
|
|
150
|
+
acl.addAccess(candidate.role, candidate.id, TAccessLevel.Read);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return acl;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
acl.addAccess(TAccessRole.Team, teamId, TAccessLevel.Owner)
|
|
157
|
+
.addAccess(TAccessRole.Team, teamId, TAccessLevel.Read)
|
|
158
|
+
.addAccess(TAccessRole.Team, teamId, TAccessLevel.Write);
|
|
159
|
+
|
|
160
|
+
if (this.sharedVault && typeof this.vaultData?.['shared']?.[resourceId] === 'string') {
|
|
161
|
+
acl.addAccess(candidate.role, candidate.id, TAccessLevel.Read);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return acl;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ConnectorService } from '@sre/Core/ConnectorsService';
|
|
2
|
+
import { Logger } from '@sre/helpers/Log.helper';
|
|
3
|
+
import { SmythRuntime } from '@sre/Core/SmythRuntime.class';
|
|
4
|
+
import { AccessCandidate } from '@sre/Security/AccessControl/AccessCandidate.class';
|
|
5
|
+
import { AccessRequest } from '@sre/Security/AccessControl/AccessRequest.class';
|
|
6
|
+
import { ACL } from '@sre/Security/AccessControl/ACL.class';
|
|
7
|
+
import { SecureConnector } from '@sre/Security/SecureConnector.class';
|
|
8
|
+
import { IAccessCandidate, TAccessLevel, TAccessRole } from '@sre/types/ACL.types';
|
|
9
|
+
|
|
10
|
+
import { IVaultRequest, VaultConnector } from '../VaultConnector';
|
|
11
|
+
import crypto from 'crypto';
|
|
12
|
+
import fs from 'fs';
|
|
13
|
+
import * as readlineSync from 'readline-sync';
|
|
14
|
+
|
|
15
|
+
const console = Logger('NullVault');
|
|
16
|
+
export class NullVault extends VaultConnector {
|
|
17
|
+
public name: string = 'NullVault';
|
|
18
|
+
private vaultData: any;
|
|
19
|
+
private index: any;
|
|
20
|
+
private sharedVault: boolean;
|
|
21
|
+
|
|
22
|
+
constructor(protected _settings: any) {
|
|
23
|
+
super(_settings);
|
|
24
|
+
console.warn('NullVault is used : Vault features will not be available');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@SecureConnector.AccessControl
|
|
28
|
+
protected async get(acRequest: AccessRequest, keyId: string) {
|
|
29
|
+
console.debug(`Ignored operation:NullVault.get: ${keyId}`);
|
|
30
|
+
return 'NULLKEY';
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@SecureConnector.AccessControl
|
|
34
|
+
protected async exists(acRequest: AccessRequest, keyId: string) {
|
|
35
|
+
console.debug(`Ignored operation:NullVault.exists: ${keyId}`);
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@SecureConnector.AccessControl
|
|
40
|
+
protected async listKeys(acRequest: AccessRequest) {
|
|
41
|
+
console.debug(`Ignored operation:NullVault.listKeys`);
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public async getResourceACL(resourceId: string, candidate: IAccessCandidate) {
|
|
46
|
+
const acl = new ACL();
|
|
47
|
+
|
|
48
|
+
//give just read access by default
|
|
49
|
+
//Cannot write to null vault
|
|
50
|
+
acl.addAccess(candidate.role, candidate.id, TAccessLevel.Read);
|
|
51
|
+
|
|
52
|
+
return acl;
|
|
53
|
+
}
|
|
54
|
+
}
|