@shieldaai/agent-map 0.1.0-alpha.3 → 1.1.0

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.
Files changed (96) hide show
  1. package/README.md +652 -272
  2. package/dist/assets.js +16 -26
  3. package/dist/boundary-flags.d.ts +73 -0
  4. package/dist/boundary-flags.js +352 -0
  5. package/dist/boundary.d.ts +18 -3
  6. package/dist/boundary.js +71 -21
  7. package/dist/cli-entry.d.ts +11 -0
  8. package/dist/cli-entry.js +48 -0
  9. package/dist/cli.js +40 -43
  10. package/dist/common.d.ts +34 -0
  11. package/dist/common.js +94 -0
  12. package/dist/http.js +78 -51
  13. package/dist/identity-cli.js +93 -46
  14. package/dist/identity-http.js +226 -94
  15. package/dist/index.d.ts +4 -4
  16. package/dist/index.js +4 -4
  17. package/dist/mcp.js +40 -5
  18. package/dist/oidc.d.ts +5 -0
  19. package/dist/oidc.js +121 -38
  20. package/dist/policy-reader.d.ts +56 -3
  21. package/dist/policy-reader.js +823 -110
  22. package/dist/projection-fields.d.ts +4 -0
  23. package/dist/projection-fields.js +144 -0
  24. package/dist/service/changes.d.ts +5 -0
  25. package/dist/service/changes.js +255 -0
  26. package/dist/service/context.d.ts +33 -0
  27. package/dist/service/context.js +2 -0
  28. package/dist/service/discovery.d.ts +6 -0
  29. package/dist/service/discovery.js +31 -0
  30. package/dist/service/explain.d.ts +12 -0
  31. package/dist/service/explain.js +126 -0
  32. package/dist/service/flags.d.ts +20 -0
  33. package/dist/service/flags.js +70 -0
  34. package/dist/service/inventory.d.ts +4 -0
  35. package/dist/service/inventory.js +62 -0
  36. package/dist/service/json.d.ts +8 -0
  37. package/dist/service/json.js +7 -0
  38. package/dist/service/operations/discovery.d.ts +5 -0
  39. package/dist/service/operations/discovery.js +90 -0
  40. package/dist/service/operations/explain-access.d.ts +3 -0
  41. package/dist/service/operations/explain-access.js +25 -0
  42. package/dist/service/operations/find-agents-with-access.d.ts +3 -0
  43. package/dist/service/operations/find-agents-with-access.js +120 -0
  44. package/dist/service/operations/get-agent-access.d.ts +3 -0
  45. package/dist/service/operations/get-agent-access.js +75 -0
  46. package/dist/service/operations/get-agent-inventory.d.ts +3 -0
  47. package/dist/service/operations/get-agent-inventory.js +42 -0
  48. package/dist/service/operations/get-changes.d.ts +3 -0
  49. package/dist/service/operations/get-changes.js +11 -0
  50. package/dist/service/operations/get-inventory-health.d.ts +3 -0
  51. package/dist/service/operations/get-inventory-health.js +81 -0
  52. package/dist/service/operations/get-resource-access.d.ts +3 -0
  53. package/dist/service/operations/get-resource-access.js +48 -0
  54. package/dist/service/operations/list-agents.d.ts +3 -0
  55. package/dist/service/operations/list-agents.js +92 -0
  56. package/dist/service/operations/list-owners-resources.d.ts +5 -0
  57. package/dist/service/operations/list-owners-resources.js +69 -0
  58. package/dist/service/ordering.d.ts +9 -0
  59. package/dist/service/ordering.js +47 -0
  60. package/dist/service/outside-guard.d.ts +68 -0
  61. package/dist/service/outside-guard.js +313 -0
  62. package/dist/service/policy.d.ts +26 -0
  63. package/dist/service/policy.js +299 -0
  64. package/dist/service/schemas.d.ts +16 -0
  65. package/dist/service/schemas.js +192 -0
  66. package/dist/service/summaries.d.ts +32 -0
  67. package/dist/service/summaries.js +247 -0
  68. package/dist/service/work.d.ts +33 -0
  69. package/dist/service/work.js +116 -0
  70. package/dist/service.d.ts +5 -5
  71. package/dist/service.js +110 -645
  72. package/dist/store/ancestors.d.ts +9 -0
  73. package/dist/store/ancestors.js +86 -0
  74. package/dist/store/discovery.d.ts +8 -0
  75. package/dist/store/discovery.js +288 -0
  76. package/dist/store/evidence.d.ts +12 -0
  77. package/dist/store/evidence.js +90 -0
  78. package/dist/store/identity-scope.d.ts +9 -0
  79. package/dist/store/identity-scope.js +71 -0
  80. package/dist/store/nodes.d.ts +24 -0
  81. package/dist/store/nodes.js +237 -0
  82. package/dist/store/projection.d.ts +19 -0
  83. package/dist/store/projection.js +242 -0
  84. package/dist/store/queries.d.ts +48 -0
  85. package/dist/store/queries.js +302 -0
  86. package/dist/store/read.d.ts +81 -0
  87. package/dist/store/read.js +135 -0
  88. package/dist/store/selection.d.ts +3 -0
  89. package/dist/store/selection.js +102 -0
  90. package/dist/store.d.ts +15 -0
  91. package/dist/store.js +102 -395
  92. package/dist/transport.d.ts +42 -2
  93. package/dist/transport.js +144 -16
  94. package/dist/types.d.ts +184 -4
  95. package/dist/types.js +52 -11
  96. package/package.json +16 -3
@@ -1,13 +1,12 @@
1
1
  #!/usr/bin/env node
2
- import { constants } from 'node:fs';
3
- import { open } from 'node:fs/promises';
4
2
  import { dirname, resolve } from 'node:path';
5
3
  import { parseArgs } from 'node:util';
6
- import { isCliEntry } from './cli-entry.js';
4
+ import { PACKAGE_VERSION, STORE_LIMITS, isCliEntry, reportStartupFailure } from './cli-entry.js';
7
5
  import { createNeo4jMapStore } from './store.js';
8
6
  import { MapService } from './service.js';
9
7
  import { startMapIdentityServer } from './identity-http.js';
10
- import { fields, fail, parseRequest } from './boundary.js';
8
+ import { fail } from './common.js';
9
+ import { fields, parseRequest, readHostFile } from './boundary.js';
11
10
  function environment(value) {
12
11
  if (typeof value !== 'string' || !/^[A-Za-z_][A-Za-z0-9_]{0,127}$/.test(value))
13
12
  fail('MAP_CONFIG_INVALID');
@@ -16,43 +15,66 @@ function environment(value) {
16
15
  fail('MAP_CREDENTIAL_REQUIRED');
17
16
  return secret;
18
17
  }
19
- /** POSIX launcher: owned regular files only; private inputs exclude group/other access. */
18
+ /**
19
+ * The company launcher holds a TLS key and names secrets, so its files are this user's own
20
+ * regular files, never a link, and private inputs exclude group and other access.
21
+ */
20
22
  async function boundedFile(path, maximum, privateFile) {
21
- if (typeof process.getuid !== 'function' || !constants.O_NOFOLLOW)
22
- fail('MAP_CONFIG_INVALID');
23
- const file = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
24
- try {
25
- const info = await file.stat();
26
- if (!info.isFile() || info.nlink !== 1 || info.uid !== process.getuid() || info.size > maximum ||
27
- (privateFile && (info.mode & 0o077) !== 0) || (info.mode & 0o022) !== 0)
28
- fail('MAP_CONFIG_INVALID');
29
- const data = Buffer.alloc(maximum + 1);
30
- let bytes = 0;
31
- while (bytes < data.length) {
32
- const read = await file.read(data, bytes, data.length - bytes, null);
33
- if (!read.bytesRead)
34
- break;
35
- bytes += read.bytesRead;
36
- }
37
- if (bytes > maximum)
38
- fail('MAP_CONFIG_INVALID');
39
- return new TextDecoder('utf-8', { fatal: true }).decode(data.subarray(0, bytes));
40
- }
41
- finally {
42
- await file.close();
43
- }
23
+ const bytes = await readHostFile(path, maximum, {
24
+ noFollow: true,
25
+ owner: 'service',
26
+ singleLink: true,
27
+ private: privateFile,
28
+ });
29
+ return new TextDecoder('utf-8', { fatal: true }).decode(bytes);
44
30
  }
45
31
  export async function loadMapIdentityConfig(filename) {
46
32
  const path = resolve(filename), directory = dirname(path);
47
- const config = fields(parseRequest(Buffer.from(await boundedFile(path, 128 * 1024, true)), 128 * 1024), ['neo4j', 'publicOrigin', 'tls', 'oidc', 'companyId', 'bindings', 'listenHost', 'port', 'viewerDirectory',
48
- 'sessionTtlMs', 'loginTtlMs', 'maxSessions', 'maxLoginTransactions', 'requestTimeoutMs', 'maxRequestBytes',
49
- 'maxResponseBytes', 'maxConcurrentRequests', 'rateLimit'], ['neo4j', 'publicOrigin', 'tls', 'oidc', 'companyId', 'bindings']);
50
- const db = fields(config.neo4j, ['uri', 'username', 'passwordEnv', 'database'], ['uri', 'username', 'passwordEnv']);
51
- if (typeof db.uri !== 'string' || typeof db.username !== 'string' || (db.database !== undefined && typeof db.database !== 'string'))
33
+ const config = fields(parseRequest(Buffer.from(await boundedFile(path, 128 * 1024, true)), 128 * 1024), [
34
+ 'neo4j',
35
+ 'publicOrigin',
36
+ 'tls',
37
+ 'oidc',
38
+ 'companyId',
39
+ 'bindings',
40
+ 'listenHost',
41
+ 'port',
42
+ 'viewerDirectory',
43
+ 'sessionTtlMs',
44
+ 'loginTtlMs',
45
+ 'maxSessions',
46
+ 'maxLoginTransactions',
47
+ 'requestTimeoutMs',
48
+ 'maxRequestBytes',
49
+ 'maxResponseBytes',
50
+ 'maxConcurrentRequests',
51
+ 'rateLimit',
52
+ ], ['neo4j', 'publicOrigin', 'tls', 'oidc', 'companyId', 'bindings']);
53
+ const db = fields(config.neo4j, ['uri', 'username', 'passwordEnv', 'database', ...STORE_LIMITS], ['uri', 'username', 'passwordEnv']);
54
+ if (typeof db.uri !== 'string' ||
55
+ typeof db.username !== 'string' ||
56
+ (db.database !== undefined && typeof db.database !== 'string'))
52
57
  fail('MAP_CONFIG_INVALID');
53
- const database = { uri: db.uri, username: db.username, password: environment(db.passwordEnv), ...(db.database === undefined ? {} : { database: db.database }) };
58
+ const database = {
59
+ uri: db.uri,
60
+ username: db.username,
61
+ password: environment(db.passwordEnv),
62
+ ...(db.database === undefined ? {} : { database: db.database }),
63
+ // Optional read limits; the store checks their type and hard maximum.
64
+ ...Object.fromEntries(STORE_LIMITS.filter(key => db[key] !== undefined).map(key => [key, db[key]])),
65
+ };
54
66
  const tls = fields(config.tls, ['keyFile', 'certFile'], ['keyFile', 'certFile']);
55
- const oidc = fields(config.oidc, ['issuer', 'clientId', 'clientSecretEnv', 'clientAuthMethod', 'endpointOrigins', 'caFile', 'requestTimeoutMs', 'maxResponseBytes'], ['issuer', 'clientId', 'clientSecretEnv']);
67
+ const oidc = fields(config.oidc, [
68
+ 'issuer',
69
+ 'clientId',
70
+ 'clientSecretEnv',
71
+ 'clientAuthMethod',
72
+ 'endpointOrigins',
73
+ 'caFile',
74
+ 'requestTimeoutMs',
75
+ 'maxResponseBytes',
76
+ 'clockToleranceSeconds',
77
+ ], ['issuer', 'clientId', 'clientSecretEnv']);
56
78
  for (const value of [tls.keyFile, tls.certFile])
57
79
  if (typeof value !== 'string' || !value)
58
80
  fail('MAP_CONFIG_INVALID');
@@ -62,22 +84,43 @@ export async function loadMapIdentityConfig(filename) {
62
84
  fail('MAP_CONFIG_INVALID');
63
85
  const { neo4j: _database, tls: _tls, oidc: _oidc, ...server } = config;
64
86
  const { clientSecretEnv: _secret, caFile: _ca, ...provider } = oidc;
65
- return { database, server: { ...server,
66
- tls: { key: await boundedFile(resolve(directory, tls.keyFile), 256 * 1024, true),
67
- cert: await boundedFile(resolve(directory, tls.certFile), 256 * 1024, false) },
68
- oidc: { ...provider, clientSecret: environment(oidc.clientSecretEnv),
69
- ...(oidc.caFile === undefined ? {} : { ca: await boundedFile(resolve(directory, oidc.caFile), 256 * 1024, false) }) },
70
- ...(config.viewerDirectory === undefined ? {} : { viewerDirectory: resolve(directory, config.viewerDirectory) }), } };
87
+ return {
88
+ database,
89
+ server: {
90
+ ...server,
91
+ tls: {
92
+ key: await boundedFile(resolve(directory, tls.keyFile), 256 * 1024, true),
93
+ cert: await boundedFile(resolve(directory, tls.certFile), 256 * 1024, false),
94
+ },
95
+ oidc: {
96
+ ...provider,
97
+ clientSecret: environment(oidc.clientSecretEnv),
98
+ ...(oidc.caFile === undefined
99
+ ? {}
100
+ : { ca: await boundedFile(resolve(directory, oidc.caFile), 256 * 1024, false) }),
101
+ },
102
+ ...(config.viewerDirectory === undefined ? {} : { viewerDirectory: resolve(directory, config.viewerDirectory) }),
103
+ },
104
+ };
71
105
  }
106
+ const USAGE = 'agent-guard-map-identity --config PRIVATE_HOST_CONFIG.json | --help | --version';
72
107
  /** Restart reloads policy/secrets and invalidates sessions; credentials are never printed. */
73
108
  export async function runMapIdentityCli(argv = process.argv.slice(2)) {
74
- const { values } = parseArgs({ args: argv, options: { config: { type: 'string' }, help: { type: 'boolean' } }, strict: true });
109
+ const { values } = parseArgs({
110
+ args: argv,
111
+ options: { config: { type: 'string' }, help: { type: 'boolean' }, version: { type: 'boolean' } },
112
+ strict: true,
113
+ });
75
114
  if (values.help) {
76
- process.stdout.write('agent-guard-map-identity --config PRIVATE_HOST_CONFIG.json\n');
115
+ process.stdout.write(`${USAGE}\n`);
116
+ return;
117
+ }
118
+ if (values.version) {
119
+ process.stdout.write(`${PACKAGE_VERSION}\n`);
77
120
  return;
78
121
  }
79
122
  if (!values.config)
80
- fail('MAP_CONFIG_INVALID');
123
+ fail('MAP_ARGUMENT_INVALID');
81
124
  const config = await loadMapIdentityConfig(values.config);
82
125
  const store = createNeo4jMapStore(config.database);
83
126
  try {
@@ -85,7 +128,11 @@ export async function runMapIdentityCli(argv = process.argv.slice(2)) {
85
128
  try {
86
129
  process.stdout.write(`${JSON.stringify({ url: server.url, mode: 'oidc-read-only' })}\n`);
87
130
  await new Promise(done => {
88
- const stop = () => { process.off('SIGINT', stop); process.off('SIGTERM', stop); done(); };
131
+ const stop = () => {
132
+ process.off('SIGINT', stop);
133
+ process.off('SIGTERM', stop);
134
+ done();
135
+ };
89
136
  process.once('SIGINT', stop);
90
137
  process.once('SIGTERM', stop);
91
138
  });
@@ -99,5 +146,5 @@ export async function runMapIdentityCli(argv = process.argv.slice(2)) {
99
146
  }
100
147
  }
101
148
  if (isCliEntry(import.meta)) {
102
- void runMapIdentityCli().catch(() => { process.stderr.write('MAP_START_FAILED\n'); process.exitCode = 1; });
149
+ void runMapIdentityCli().catch(error => reportStartupFailure(error, USAGE));
103
150
  }