-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(pam): windows discovery base #5517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
ef6efff
feat(pam): windows discovery base
x032205 3a65a82
finalize discovery base + other minor tweaks
x032205 3261f60
tweaks
x032205 de68c5b
audit logs
x032205 6b712df
indicator for empty auto-import passwords
x032205 c580183
Merge branch 'main' into pam/windows/discovery
x032205 5e2bec2
restrict gateway deletion
x032205 a90e678
re2 for regex
x032205 c77ef5b
rename discovery run
x032205 eb81f92
Merge branch 'main' into pam/windows/discovery
x032205 4b15672
address reviews
x032205 5d54fe5
improve audit logs
x032205 a7295f3
audit logs for frontend
x032205 9251bfd
swap path
x032205 37889e9
add re2
x032205 1a0ee7d
use transactions
x032205 b47a13e
use enum
x032205 3a5faf1
tx
x032205 c98332c
One scan per time
x032205 6148247
Rename reason to status message.
x032205 41d9808
Remove unused check.
x032205 0a554fe
use re2
x032205 a1b03c2
Remove unnecessary collate
x032205 88ba364
Check permission before attaching gateway.
x032205 da9e120
add badge for when the passwords are not configured
x032205 06dcc92
header update
x032205 909b263
tooltips on form + auto select manual by default
x032205 0936cb1
nit fixes
x032205 ec23398
fingerprinting + nit
x032205 abcd0e0
improve logging
x032205 bbaab97
rename metadata to internal metadata
x032205 059fce3
Merge branch 'main' into pam/windows/discovery
x032205 9371e83
address lint errors
x032205 8e11349
generate schema
x032205 263b4f7
feedback and fixes
x032205 ddd5df8
show internal metadata
x032205 46387f7
lint
x032205 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
199 changes: 199 additions & 0 deletions
199
backend/src/db/migrations/20260219070359_pam-discovery.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,199 @@ | ||
| import { Knex } from "knex"; | ||
|
|
||
| import { TableName } from "../schemas"; | ||
| import { createOnUpdateTrigger, dropOnUpdateTrigger } from "../utils"; | ||
|
|
||
| export async function up(knex: Knex): Promise<void> { | ||
| // PAM Discovery Sources | ||
| if (!(await knex.schema.hasTable(TableName.PamDiscoverySource))) { | ||
| await knex.schema.createTable(TableName.PamDiscoverySource, (t) => { | ||
| t.uuid("id", { primaryKey: true }).defaultTo(knex.fn.uuid()); | ||
|
|
||
| t.string("projectId").notNullable(); | ||
| t.foreign("projectId").references("id").inTable(TableName.Project).onDelete("CASCADE"); | ||
|
|
||
| t.string("name").notNullable(); | ||
| t.unique(["projectId", "name"], { indexName: "uidx_pam_discovery_source_project_name" }); | ||
|
|
||
| t.string("discoveryType").notNullable(); | ||
|
|
||
| t.uuid("gatewayId").notNullable(); | ||
| t.foreign("gatewayId").references("id").inTable(TableName.GatewayV2).onDelete("RESTRICT"); | ||
| t.index("gatewayId"); | ||
|
|
||
| t.binary("encryptedDiscoveryCredentials").notNullable(); | ||
| t.jsonb("discoveryConfiguration").notNullable(); | ||
|
|
||
| t.string("schedule").notNullable().defaultTo("manual"); | ||
| t.datetime("lastRunAt").nullable(); | ||
|
|
||
| t.string("status").notNullable().defaultTo("active"); | ||
|
|
||
| t.timestamps(true, true, true); | ||
| }); | ||
| } | ||
|
|
||
| // PAM Discovery Runs | ||
| if (!(await knex.schema.hasTable(TableName.PamDiscoverySourceRun))) { | ||
| await knex.schema.createTable(TableName.PamDiscoverySourceRun, (t) => { | ||
| t.uuid("id", { primaryKey: true }).defaultTo(knex.fn.uuid()); | ||
|
|
||
| t.uuid("discoverySourceId").notNullable(); | ||
| t.foreign("discoverySourceId").references("id").inTable(TableName.PamDiscoverySource).onDelete("CASCADE"); | ||
| t.index("discoverySourceId"); | ||
|
|
||
| t.string("status").notNullable(); | ||
| t.string("triggeredBy").notNullable(); | ||
|
|
||
| t.integer("resourcesDiscoveredCount").defaultTo(0); | ||
| t.integer("accountsDiscoveredCount").defaultTo(0); | ||
| t.integer("dependenciesDiscoveredCount").defaultTo(0); | ||
| t.integer("newResourcesCount").defaultTo(0); | ||
| t.integer("staleResourcesCount").defaultTo(0); | ||
| t.integer("newAccountsCount").defaultTo(0); | ||
| t.integer("staleAccountsCount").defaultTo(0); | ||
| t.integer("newDependenciesCount").defaultTo(0); | ||
| t.integer("staleDependenciesCount").defaultTo(0); | ||
|
|
||
| t.jsonb("progress").notNullable(); | ||
| t.text("errorMessage").nullable(); | ||
|
|
||
| t.datetime("startedAt").nullable(); | ||
| t.datetime("completedAt").nullable(); | ||
|
|
||
| t.timestamps(true, true, true); | ||
| }); | ||
| } | ||
|
|
||
| // PAM Account Dependencies | ||
| if (!(await knex.schema.hasTable(TableName.PamAccountDependency))) { | ||
| await knex.schema.createTable(TableName.PamAccountDependency, (t) => { | ||
| t.uuid("id", { primaryKey: true }).defaultTo(knex.fn.uuid()); | ||
|
|
||
| t.uuid("accountId").notNullable(); | ||
| t.foreign("accountId").references("id").inTable(TableName.PamAccount).onDelete("CASCADE"); | ||
| t.index("accountId"); | ||
|
|
||
| t.uuid("resourceId").notNullable(); | ||
| t.foreign("resourceId").references("id").inTable(TableName.PamResource).onDelete("CASCADE"); | ||
| t.index("resourceId"); | ||
|
|
||
| t.string("dependencyType").notNullable(); | ||
sheensantoscapadngan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| t.string("name").notNullable(); | ||
| t.string("displayName").nullable(); | ||
|
|
||
| t.string("state").nullable(); | ||
| t.jsonb("data").notNullable(); | ||
|
|
||
| t.string("source").notNullable(); // "discovery" or "manual" | ||
| t.boolean("isEnabled").defaultTo(false); | ||
|
|
||
| t.unique(["accountId", "resourceId", "dependencyType", "name"], { | ||
| indexName: "uidx_pam_account_dependency" | ||
| }); | ||
|
|
||
| t.timestamps(true, true, true); | ||
| }); | ||
| } | ||
|
|
||
| // PAM Discovery Source Resources (junction) | ||
| if (!(await knex.schema.hasTable(TableName.PamDiscoverySourceResource))) { | ||
| await knex.schema.createTable(TableName.PamDiscoverySourceResource, (t) => { | ||
| t.uuid("id", { primaryKey: true }).defaultTo(knex.fn.uuid()); | ||
|
|
||
| t.uuid("discoverySourceId").notNullable(); | ||
| t.foreign("discoverySourceId").references("id").inTable(TableName.PamDiscoverySource).onDelete("CASCADE"); | ||
| t.index("discoverySourceId"); | ||
|
|
||
| t.uuid("resourceId").notNullable(); | ||
| t.foreign("resourceId").references("id").inTable(TableName.PamResource).onDelete("CASCADE"); | ||
| t.index("resourceId"); | ||
|
|
||
| t.datetime("lastDiscoveredAt").notNullable(); | ||
|
|
||
| t.uuid("lastDiscoveredRunId").nullable(); | ||
| t.foreign("lastDiscoveredRunId").references("id").inTable(TableName.PamDiscoverySourceRun).onDelete("SET NULL"); | ||
|
|
||
| t.boolean("isStale").defaultTo(false); | ||
|
|
||
| t.timestamp("createdAt", { useTz: true }).defaultTo(knex.fn.now()); | ||
|
|
||
| t.unique(["discoverySourceId", "resourceId"], { | ||
| indexName: "uidx_pam_discovery_source_resource" | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| // PAM Discovery Source Accounts (junction) | ||
| if (!(await knex.schema.hasTable(TableName.PamDiscoverySourceAccount))) { | ||
| await knex.schema.createTable(TableName.PamDiscoverySourceAccount, (t) => { | ||
| t.uuid("id", { primaryKey: true }).defaultTo(knex.fn.uuid()); | ||
|
|
||
| t.uuid("discoverySourceId").notNullable(); | ||
| t.foreign("discoverySourceId").references("id").inTable(TableName.PamDiscoverySource).onDelete("CASCADE"); | ||
| t.index("discoverySourceId"); | ||
|
|
||
| t.uuid("accountId").notNullable(); | ||
| t.foreign("accountId").references("id").inTable(TableName.PamAccount).onDelete("CASCADE"); | ||
| t.index("accountId"); | ||
|
|
||
| t.datetime("lastDiscoveredAt").notNullable(); | ||
|
|
||
| t.uuid("lastDiscoveredRunId").nullable(); | ||
| t.foreign("lastDiscoveredRunId").references("id").inTable(TableName.PamDiscoverySourceRun).onDelete("SET NULL"); | ||
|
|
||
| t.boolean("isStale").defaultTo(false); | ||
|
|
||
| t.timestamp("createdAt", { useTz: true }).defaultTo(knex.fn.now()); | ||
|
|
||
| t.unique(["discoverySourceId", "accountId"], { | ||
| indexName: "uidx_pam_discovery_source_account" | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| // PAM Discovery Source Dependencies (junction) | ||
| if (!(await knex.schema.hasTable(TableName.PamDiscoverySourceDependency))) { | ||
| await knex.schema.createTable(TableName.PamDiscoverySourceDependency, (t) => { | ||
| t.uuid("id", { primaryKey: true }).defaultTo(knex.fn.uuid()); | ||
|
|
||
| t.uuid("discoverySourceId").notNullable(); | ||
| t.foreign("discoverySourceId").references("id").inTable(TableName.PamDiscoverySource).onDelete("CASCADE"); | ||
| t.index("discoverySourceId"); | ||
|
|
||
| t.uuid("dependencyId").notNullable(); | ||
| t.foreign("dependencyId").references("id").inTable(TableName.PamAccountDependency).onDelete("CASCADE"); | ||
| t.index("dependencyId"); | ||
|
|
||
| t.datetime("lastSeenAt").notNullable(); | ||
|
|
||
| t.uuid("lastSeenRunId").nullable(); | ||
| t.foreign("lastSeenRunId").references("id").inTable(TableName.PamDiscoverySourceRun).onDelete("SET NULL"); | ||
|
|
||
| t.boolean("isStale").defaultTo(false); | ||
|
|
||
| t.timestamp("createdAt", { useTz: true }).defaultTo(knex.fn.now()); | ||
|
|
||
| t.unique(["discoverySourceId", "dependencyId"], { | ||
| indexName: "uidx_pam_discovery_source_dependency" | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| await createOnUpdateTrigger(knex, TableName.PamDiscoverySource); | ||
| await createOnUpdateTrigger(knex, TableName.PamDiscoverySourceRun); | ||
| await createOnUpdateTrigger(knex, TableName.PamAccountDependency); | ||
| } | ||
|
|
||
| export async function down(knex: Knex): Promise<void> { | ||
| await knex.schema.dropTableIfExists(TableName.PamDiscoverySourceDependency); | ||
| await knex.schema.dropTableIfExists(TableName.PamDiscoverySourceAccount); | ||
| await knex.schema.dropTableIfExists(TableName.PamDiscoverySourceResource); | ||
| await knex.schema.dropTableIfExists(TableName.PamAccountDependency); | ||
| await knex.schema.dropTableIfExists(TableName.PamDiscoverySourceRun); | ||
| await knex.schema.dropTableIfExists(TableName.PamDiscoverySource); | ||
|
|
||
| await dropOnUpdateTrigger(knex, TableName.PamAccountDependency); | ||
| await dropOnUpdateTrigger(knex, TableName.PamDiscoverySourceRun); | ||
| await dropOnUpdateTrigger(knex, TableName.PamDiscoverySource); | ||
| } | ||
35 changes: 35 additions & 0 deletions
35
backend/src/db/migrations/20260305073334_pam-discovery-fingerprint.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { Knex } from "knex"; | ||
|
|
||
| import { TableName } from "../schemas"; | ||
|
|
||
| export async function up(knex: Knex): Promise<void> { | ||
| const hasResourceCol = await knex.schema.hasColumn(TableName.PamResource, "discoveryFingerprint"); | ||
| if (!hasResourceCol) { | ||
| await knex.schema.alterTable(TableName.PamResource, (t) => { | ||
| t.string("discoveryFingerprint").nullable(); | ||
| }); | ||
| } | ||
|
|
||
| const hasAccountCol = await knex.schema.hasColumn(TableName.PamAccount, "discoveryFingerprint"); | ||
| if (!hasAccountCol) { | ||
| await knex.schema.alterTable(TableName.PamAccount, (t) => { | ||
| t.string("discoveryFingerprint").nullable(); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| export async function down(knex: Knex): Promise<void> { | ||
| const hasResourceCol = await knex.schema.hasColumn(TableName.PamResource, "discoveryFingerprint"); | ||
| if (hasResourceCol) { | ||
| await knex.schema.alterTable(TableName.PamResource, (t) => { | ||
| t.dropColumn("discoveryFingerprint"); | ||
| }); | ||
| } | ||
|
|
||
| const hasAccountCol = await knex.schema.hasColumn(TableName.PamAccount, "discoveryFingerprint"); | ||
| if (hasAccountCol) { | ||
| await knex.schema.alterTable(TableName.PamAccount, (t) => { | ||
| t.dropColumn("discoveryFingerprint"); | ||
| }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // Code generated by automation script, DO NOT EDIT. | ||
| // Automated by pulling database and generating zod schema | ||
| // To update. Just run npm run generate:schema | ||
| // Written by akhilmhdh. | ||
|
|
||
| import { z } from "zod"; | ||
|
|
||
| import { TImmutableDBKeys } from "./models"; | ||
|
|
||
| export const PamAccountDependenciesSchema = z.object({ | ||
| id: z.string().uuid(), | ||
| accountId: z.string().uuid(), | ||
| resourceId: z.string().uuid(), | ||
| dependencyType: z.string(), | ||
| name: z.string(), | ||
| displayName: z.string().nullable().optional(), | ||
| state: z.string().nullable().optional(), | ||
| data: z.unknown(), | ||
| source: z.string(), | ||
| isEnabled: z.boolean().default(false).nullable().optional(), | ||
| createdAt: z.date(), | ||
| updatedAt: z.date() | ||
| }); | ||
|
|
||
| export type TPamAccountDependencies = z.infer<typeof PamAccountDependenciesSchema>; | ||
| export type TPamAccountDependenciesInsert = Omit<z.input<typeof PamAccountDependenciesSchema>, TImmutableDBKeys>; | ||
| export type TPamAccountDependenciesUpdate = Partial< | ||
| Omit<z.input<typeof PamAccountDependenciesSchema>, TImmutableDBKeys> | ||
| >; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.