ffddorf / netbox-vault-secrets

Work In Progress!
BSD 2-Clause "Simplified" License
78 stars 13 forks source link

Add support for secret attachment on configurable object types ( fixes ffddorf/netbox-vault-secrets#14 ) #49

Closed ghost closed 6 months ago

ghost commented 2 years ago

Add support for configurable list of object types where secrets can be attached. ( fixes #14 ) Default config reflects the currently supported Device, VM, Service types. Readme updated with info on how to configure.

Tested on Netbox 3.3.7 / Vault 1.12.1 (no changes to the front-end code in this PR, so vault version shouldn't matter) Tested with the following plugin_config:

PLUGINS_CONFIG = {
    "netbox_vault_secrets": {
        "api_url": "https://vault.mikkle.io/",
        "kv_mount_path": "/mikkle.io",
        "secret_path_prefix": "/netbox",
        "login_methods": ["oidc"],
        "oidc": {
            "mount_path": "/auth/mikkle.io"
        },
        "content_types": [
            {
                "model": 'dcim.device'
            },
            {
                "model": 'ipam.service'
            },
            {
                "model": 'virtualization.virtualmachine',
                "vault_path_slug": 'vm'
            },
            {
                "model": 'tenancy.tenant'
            },
            {
                "model": 'tenancy.tenantgroup',
                "vault_path_slug": 'tenant_group'
            },
            {
                "model": 'circuits.circuit'
            },
            {
                "model": 'virtualization.clustergroup',
                "vault_path_slug": 'cluster_group'
            },
            {
                "model": 'virtualization.clustertype',
                "vault_path_slug": 'clusterType'
            },
            {
                "model": 'auth.user'
            },
        ]
    }
}

which works as expected (all except "auth.user" are set up) Log (with debug enabled) tells what's going on:

DEBUG 2022-11-15 22:18:24,127 template_content netbox_vault_secrets 21 139918999255360 Allowed apps: circuits, dcim, extras, ipam, tenancy, virtualization, wireless
DEBUG 2022-11-15 22:18:24,128 template_content netbox_vault_secrets 21 139918999255360 Configured content_types: dcim.device, ipam.service, virtualization.virtualmachine, tenancy.tenant, tenancy.tenantgroup, circuits.circuit, virtualization.clustergroup, virtualization.clustertype, auth.user
INFO 2022-11-15 22:18:24,128 template_content netbox_vault_secrets 21 139918999255360 ignored dis-allowed content_types: auth.user
DEBUG 2022-11-15 22:18:24,128 template_content netbox_vault_secrets 21 139918999255360 Inferred slug 'device' for model dcim.device
DEBUG 2022-11-15 22:18:24,128 template_content netbox_vault_secrets 21 139918999255360 Creating VaultSecretInserter sub-class VaultDcimDeviceSecrets
DEBUG 2022-11-15 22:18:24,128 template_content netbox_vault_secrets 21 139918999255360 Inferred slug 'service' for model ipam.service
DEBUG 2022-11-15 22:18:24,128 template_content netbox_vault_secrets 21 139918999255360 Creating VaultSecretInserter sub-class VaultIpamServiceSecrets
DEBUG 2022-11-15 22:18:24,128 template_content netbox_vault_secrets 21 139918999255360 Using overridden slug 'vm' for model virtualization.virtualmachine
DEBUG 2022-11-15 22:18:24,128 template_content netbox_vault_secrets 21 139918999255360 Creating VaultSecretInserter sub-class VaultVirtualizationVirtualmachineSecrets
DEBUG 2022-11-15 22:18:24,128 template_content netbox_vault_secrets 21 139918999255360 Inferred slug 'tenant' for model tenancy.tenant
DEBUG 2022-11-15 22:18:24,128 template_content netbox_vault_secrets 21 139918999255360 Creating VaultSecretInserter sub-class VaultTenancyTenantSecrets
DEBUG 2022-11-15 22:18:24,128 template_content netbox_vault_secrets 21 139918999255360 Using overridden slug 'tenant_group' for model tenancy.tenantgroup
DEBUG 2022-11-15 22:18:24,128 template_content netbox_vault_secrets 21 139918999255360 Creating VaultSecretInserter sub-class VaultTenancyTenantgroupSecrets
DEBUG 2022-11-15 22:18:24,128 template_content netbox_vault_secrets 21 139918999255360 Inferred slug 'circuit' for model circuits.circuit
DEBUG 2022-11-15 22:18:24,128 template_content netbox_vault_secrets 21 139918999255360 Creating VaultSecretInserter sub-class VaultCircuitsCircuitSecrets
DEBUG 2022-11-15 22:18:24,128 template_content netbox_vault_secrets 21 139918999255360 Using overridden slug 'cluster_group' for model virtualization.clustergroup
DEBUG 2022-11-15 22:18:24,128 template_content netbox_vault_secrets 21 139918999255360 Creating VaultSecretInserter sub-class VaultVirtualizationClustergroupSecrets
DEBUG 2022-11-15 22:18:24,129 template_content netbox_vault_secrets 21 139918999255360 Using overridden slug 'clusterType' for model virtualization.clustertype
DEBUG 2022-11-15 22:18:24,129 template_content netbox_vault_secrets 21 139918999255360 Creating VaultSecretInserter sub-class VaultVirtualizationClustertypeSecrets
balpoint commented 1 year ago

can we please implement this pull request ?!