Skip to content

Deactivate agents via security config - #851

Open
FHatCSW wants to merge 2 commits into
mainfrom
deactivate_agents_config
Open

Deactivate agents via security config#851
FHatCSW wants to merge 2 commits into
mainfrom
deactivate_agents_config

Conversation

@FHatCSW

@FHatCSW FHatCSW commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Legal

  • I certify that I have all necessary rights to publish this contribution under the MIT license. I agree to the Trustpoint CLA and have added my name to the AUTHORS.md file.

Copilot AI review requested due to automatic review settings July 29, 2026 08:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the existing security configuration allow-listing of onboarding protocols to support the new OnboardingProtocol.AGENT (value 9), and uses that configuration to disable agent functionality (UI + API) when the AGENT protocol is not permitted.

Changes:

  • Extend SecurityConfig defaults to include onboarding protocol value 9 (Agent).
  • Filter device onboarding protocol form choices based on SecurityConfig.permitted_onboarding_protocols.
  • Gate agent web views and agent API endpoints behind a security-config check (403 for API, redirect for web UI).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
trustpoint/management/models/security.py Adds AGENT (9) to the default onboarding protocol allow-lists used by security modes.
trustpoint/devices/forms.py Adds SecurityConfig-driven filtering of onboarding protocol choices; updates onboarding protocol widget setup.
trustpoint/agents/web_views.py Wraps multiple agent UI views with AgentSecurityMixin gating.
trustpoint/agents/security.py Introduces shared helper/mixin to enforce “AGENT protocol must be permitted” policy.
trustpoint/agents/api_views.py Returns 403 from agent API endpoints when AGENT protocol is disabled by security config.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 216 to +219
#: All OnboardingProtocol values
_ALL_ONBOARDING_PROTOCOLS: ClassVar[list[int]] = [0, 1, 2, 3, 4, 5, 6, 7, 8]
_ALL_ONBOARDING_PROTOCOLS: ClassVar[list[int]] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
#: All OnboardingProtocol values except MANUAL (0)
_ONBOARDING_PROTOCOLS_NO_MANUAL: ClassVar[list[int]] = [1, 2, 3, 4, 5, 6, 7, 8]
_ONBOARDING_PROTOCOLS_NO_MANUAL: ClassVar[list[int]] = [1, 2, 3, 4, 5, 6, 7, 8, 9]
Comment thread trustpoint/devices/forms.py Outdated
Comment on lines +525 to +535
all_protocol_values = {proto[0] for proto in permitted_protocols}
disabled_options = [
proto for proto in [
OnboardingProtocol.MANUAL,
OnboardingProtocol.AOKI,
OnboardingProtocol.BRSKI,
OnboardingProtocol.OPC_GDS_PUSH,
]
if proto.value in all_protocol_values
]
self.fields['onboarding_protocol'].widget = DisableOptionsSelect(disabled_options=disabled_options)
Comment on lines +264 to +268
if not AgentSecurity.is_agent_protocol_permitted():
return Response(
{'detail': 'Agent functionality is disabled by the current security configuration.'},
status=status.HTTP_403_FORBIDDEN,
)
Comment on lines +33 to +35
class AgentProfileDefinitionTableView(
AgentSecurityMixin, PageContextMixin, LoggerMixin, ListView[AgentProfileDefinition]
):
Comment on lines +75 to +79
try:
cfg: SecurityConfig = SecurityConfig.objects.get()
permitted: list[int] = cfg.permitted_onboarding_protocols or []
except SecurityConfig.DoesNotExist:
return ONBOARDING_PROTOCOLS_ALLOWED_FOR_FORMS
@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 64.86486% with 26 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
trustpoint/devices/forms.py 45.16% 17 Missing ⚠️
trustpoint/agents/security.py 72.00% 7 Missing ⚠️
trustpoint/agents/api_views.py 60.00% 2 Missing ⚠️
Files with missing lines Coverage Δ
trustpoint/agents/web_views.py 62.38% <100.00%> (+0.11%) ⬆️
trustpoint/management/models/security.py 46.73% <100.00%> (ø)
trustpoint/agents/api_views.py 89.14% <60.00%> (-0.86%) ⬇️
trustpoint/agents/security.py 72.00% <72.00%> (ø)
trustpoint/devices/forms.py 86.50% <45.16%> (-2.24%) ⬇️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI review requested due to automatic review settings July 29, 2026 09:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (5)

trustpoint/management/models/security.py:219

  • permitted_onboarding_protocols help_text is now missing the new AGENT=9 value, and the default allow-list constants are hard-coded integer arrays that have to be manually kept in sync with OnboardingProtocol. Deriving these lists from OnboardingProtocol.values avoids future drift when new protocols are added.
    #: All OnboardingProtocol values
    _ALL_ONBOARDING_PROTOCOLS: ClassVar[list[int]] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    #: All OnboardingProtocol values except MANUAL (0)
    _ONBOARDING_PROTOCOLS_NO_MANUAL: ClassVar[list[int]] = [1, 2, 3, 4, 5, 6, 7, 8, 9]

trustpoint/agents/web_views.py:35

  • These web views are now gated by AgentSecurityMixin. The existing web view tests in trustpoint/agents/tests/test_views.py cover the happy path but don’t cover the disabled-by-security-config redirect/message behavior; adding a negative test would help ensure agents can be reliably deactivated via SecurityConfig.
class AgentProfileDefinitionTableView(
    AgentSecurityMixin, PageContextMixin, LoggerMixin, ListView[AgentProfileDefinition]
):

trustpoint/agents/api_views.py:268

  • New behavior: when the AGENT protocol is not permitted by SecurityConfig, this endpoint now returns 403. There are already comprehensive tests for AgentJobsView in trustpoint/agents/tests/test_views.py, but none exercise the “agent disabled by security config” path; adding a test would prevent regressions.
        if not AgentSecurity.is_agent_protocol_permitted():
            return Response(
                {'detail': 'Agent functionality is disabled by the current security configuration.'},
                status=status.HTTP_403_FORBIDDEN,
            )

trustpoint/devices/forms.py:538

  • DisableOptionsSelect compares the rendered option value (typically a string) against widget.disabled_options. Here disabled_options is built from OnboardingProtocol enum members, so the comparison can fail and the options won’t be disabled even when intended. Normalize both the permitted protocol values and disabled_options to strings before passing them to the widget.
        disabled_options = [
            proto for proto in [
                OnboardingProtocol.MANUAL,
                OnboardingProtocol.AOKI,
                OnboardingProtocol.BRSKI,

trustpoint/agents/api_views.py:407

  • New behavior: when the AGENT protocol is not permitted by SecurityConfig, this endpoint now returns 403. The existing AgentJobResultView tests do not cover the “agent disabled by security config” path; please add a test to lock in the expected 403 behavior.
        if not AgentSecurity.is_agent_protocol_permitted():
            return Response(
                {'detail': 'Agent functionality is disabled by the current security configuration.'},
                status=status.HTTP_403_FORBIDDEN,
            )

@github-actions

Copy link
Copy Markdown
filepath passed skipped SUBTOTAL
trustpoint/agents/tests/test_views.py 40 0 40
trustpoint/appsecrets/tests/test_service.py 11 0 11
trustpoint/cmp/tests/test_views.py 29 0 29
trustpoint/crypto/tests/test_application_backend.py 9 0 9
trustpoint/crypto/tests/test_local_development_backend.py 4 0 4
trustpoint/crypto/tests/test_managed_key_repository.py 4 0 4
trustpoint/crypto/tests/test_repositories.py 5 0 5
trustpoint/devices/tests/test_api/test_device_viewset.py 30 0 30
trustpoint/devices/tests/test_credential_download.py 4 0 4
trustpoint/devices/tests/test_forms/test_base_credential_forms.py 31 0 31
trustpoint/devices/tests/test_forms/test_browser_login.py 5 0 5
trustpoint/devices/tests/test_forms/test_clm_forms.py 23 0 23
trustpoint/devices/tests/test_forms/test_create_device_form.py 3 0 3
trustpoint/devices/tests/test_forms/test_credential_download_form.py 3 0 3
trustpoint/devices/tests/test_forms/test_credential_forms.py 16 0 16
trustpoint/devices/tests/test_forms/test_device_creation_forms.py 28 0 28
trustpoint/devices/tests/test_forms/test_forms_coverage_boost.py 9 0 9
trustpoint/devices/tests/test_issuer/test_domain_credential.py 1 0 1
trustpoint/devices/tests/test_issuer/test_issuer_extended.py 24 0 24
trustpoint/devices/tests/test_issuer/test_opcua_client_credential.py 1 0 1
trustpoint/devices/tests/test_issuer/test_opcua_server_credential.py 1 0 1
trustpoint/devices/tests/test_issuer/test_tls_client_credential.py 2 0 2
trustpoint/devices/tests/test_issuer/test_tls_server_credential.py 1 0 1
trustpoint/devices/tests/test_model_delete.py 4 0 4
trustpoint/devices/tests/test_models/test_device_model.py 8 0 8
trustpoint/devices/tests/test_models/test_remote_device_credential.py 14 0 14
trustpoint/devices/tests/test_revocation/test_device_credential_revocation.py 3 0 3
trustpoint/devices/tests/test_tasks.py 19 0 19
trustpoint/devices/tests/test_urls/test_urls.py 10 0 10
trustpoint/devices/tests/test_utils.py 6 0 6
trustpoint/devices/tests/test_views/test_device_views.py 29 0 29
trustpoint/devices/tests/test_views/test_device_views_clm.py 11 0 11
trustpoint/devices/tests/test_views/test_device_views_extended.py 26 0 26
trustpoint/help_pages/tests/test_base.py 20 0 20
trustpoint/help_pages/tests/test_devices_help_views.py 27 0 27
trustpoint/help_pages/tests/test_pki_help_views.py 12 0 12
trustpoint/home/tests/test_filters.py 11 0 11
trustpoint/home/tests/test_integration.py 6 0 6
trustpoint/home/tests/test_views.py 27 0 27
trustpoint/management/tests/test_api/test_backup_viewset.py 13 0 13
trustpoint/management/tests/test_api/test_health_viewset.py 3 0 3
trustpoint/management/tests/test_api/test_logging_viewset.py 19 0 19
trustpoint/management/tests/test_api/test_tls_viewset.py 12 0 12
trustpoint/management/tests/test_commands.py 26 0 26
trustpoint/management/tests/test_filters/test_audit_log.py 2 0 2
trustpoint/management/tests/test_forms/test_backup.py 5 0 5
trustpoint/management/tests/test_forms/test_ipv4_address_form.py 5 0 5
trustpoint/management/tests/test_forms/test_pkcs11configform.py 4 0 4
trustpoint/management/tests/test_forms/test_security_config.py 15 0 15
trustpoint/management/tests/test_forms/test_tls_import.py 27 0 27
trustpoint/management/tests/test_models/test_audit_log.py 2 0 2
trustpoint/management/tests/test_models/test_backup.py 7 0 7
trustpoint/management/tests/test_models/test_notifications.py 15 0 15
trustpoint/management/tests/test_security_decorators.py 14 0 14
trustpoint/management/tests/test_security_features.py 21 0 21
trustpoint/management/tests/test_security_manager.py 22 0 22
trustpoint/management/tests/test_security_mixins.py 17 0 17
trustpoint/management/tests/test_urls.py 25 0 25
trustpoint/management/tests/test_util/test_output_wrapper.py 11 0 11
trustpoint/management/tests/test_util/test_startup_context.py 5 0 5
trustpoint/management/tests/test_util/test_startup_strategies.py 6 0 6
trustpoint/management/tests/test_views/test_audit_log.py 5 0 5
trustpoint/management/tests/test_views/test_backend_configuration.py 15 0 15
trustpoint/management/tests/test_views/test_backup.py 40 0 40
trustpoint/management/tests/test_views/test_help_support.py 10 0 10
trustpoint/management/tests/test_views/test_logging.py 32 0 32
trustpoint/management/tests/test_views/test_notifications.py 8 0 8
trustpoint/management/tests/test_views/test_organization_management.py 6 0 6
trustpoint/management/tests/test_views/test_pkcs11.py 4 0 4
trustpoint/management/tests/test_views/test_role_management.py 8 0 8
trustpoint/management/tests/test_views/test_settings.py 43 0 43
trustpoint/management/tests/test_views/test_tls.py 38 0 38
trustpoint/management/tests/test_views/test_user_management.py 12 0 12
trustpoint/pki/tests/test_auto_gen_pki.py 2 0 2
trustpoint/pki/tests/test_ca_rollover_model.py 18 0 18
trustpoint/pki/tests/test_ca_rollover_service.py 17 0 17
trustpoint/pki/tests/test_cert_profiles.py 42 0 42
trustpoint/pki/tests/test_crl.py 48 0 48
trustpoint/pki/tests/test_crl_cycle.py 12 0 12
trustpoint/pki/tests/test_crl_cycle_form.py 9 0 9
trustpoint/pki/tests/test_crl_cycle_signals.py 5 0 5
trustpoint/pki/tests/test_crl_cycle_views.py 4 0 4
trustpoint/pki/tests/test_crl_on_revocation.py 5 0 5
trustpoint/pki/tests/test_filters.py 16 0 16
trustpoint/pki/tests/test_forms_extended.py 77 0 77
trustpoint/pki/tests/test_idevid_authenticator.py 6 0 6
trustpoint/pki/tests/test_idevid_verifier.py 10 0 10
trustpoint/pki/tests/test_issued_credential.py 5 0 5
trustpoint/pki/tests/test_models/test_certificate_extensions.py 17 0 17
trustpoint/pki/tests/test_models/test_certificate_model.py 2 0 2
trustpoint/pki/tests/test_models/test_certificate_values.py 17 0 17
trustpoint/pki/tests/test_models/test_credential.py 9 0 9
trustpoint/pki/tests/test_models/test_domain_model.py 1 0 1
trustpoint/pki/tests/test_models/test_extension_models.py 90 0 90
trustpoint/pki/tests/test_models/test_issuing_ca_model.py 8 0 8
trustpoint/pki/tests/test_owner_credential_forms.py 30 0 30
trustpoint/pki/tests/test_owner_credential_models.py 13 0 13
trustpoint/pki/tests/test_owner_credential_views.py 48 0 48
trustpoint/pki/tests/test_rollover_import_ca.py 25 0 25
trustpoint/pki/tests/test_rollover_tasks.py 8 0 8
trustpoint/pki/tests/test_serializer_truststore.py 16 0 16
trustpoint/pki/tests/test_services.py 19 0 19
trustpoint/pki/tests/test_util_cert_req_converter.py 37 0 37
trustpoint/pki/tests/test_util_keys.py 13 0 13
trustpoint/pki/tests/test_views_certificates.py 28 0 28
trustpoint/pki/tests/test_views_domains.py 27 0 27
trustpoint/pki/tests/test_views_issuing_cas.py 2 0 2
trustpoint/pki/tests/test_views_truststores.py 21 0 21
trustpoint/request/tests/test_authentication_extended.py 18 0 18
trustpoint/request/tests/test_cmp_authorization.py 30 0 30
trustpoint/request/tests/test_cmp_transaction_pipeline.py 4 0 4
trustpoint/request/tests/test_message_responder.py 26 0 26
trustpoint/request/tests/test_profile_validator.py 7 0 7
trustpoint/request/tests/test_workflow2_issuance.py 8 0 8
trustpoint/request/tests/test_workflows2_handler.py 13 0 13
trustpoint/setup_wizard/tests/test_forms/test_fresh_install_backend_config_form.py 17 0 17
trustpoint/setup_wizard/tests/test_forms/test_fresh_install_forms.py 41 0 41
trustpoint/setup_wizard/tests/test_models.py 29 0 29
trustpoint/setup_wizard/tests/test_restore_backup.py 5 0 5
trustpoint/setup_wizard/tests/test_urls.py 6 0 6
trustpoint/setup_wizard/tests/test_views/test_fresh_install_views.py 11 0 11
trustpoint/setup_wizard/tests/test_views/test_utility_functions.py 9 0 9
trustpoint/signer/tests/test_api_views.py 22 0 22
trustpoint/signer/tests/test_forms.py 43 0 43
trustpoint/signer/tests/test_models.py 21 0 21
trustpoint/signer/tests/test_views.py 38 0 38
trustpoint/trustpoint/tests/test_forms.py 8 0 8
trustpoint/trustpoint/tests/test_middleware.py 13 0 13
trustpoint/trustpoint/tests/test_page_context.py 9 0 9
trustpoint/trustpoint/tests/test_views/test_bulk_delete.py 13 0 13
trustpoint/trustpoint/tests/test_views/test_context_data.py 4 0 4
trustpoint/trustpoint/tests/test_views/test_index_view.py 2 0 2
trustpoint/trustpoint/tests/test_views/test_list_in_detail_view.py 5 0 5
trustpoint/trustpoint/tests/test_views/test_logged_response.py 7 0 7
trustpoint/trustpoint/tests/test_views/test_sortable_is_active.py 2 0 2
trustpoint/trustpoint/tests/test_views/test_sortable_table.py 5 0 5
trustpoint/users/tests/test_integration.py 12 0 12
trustpoint/users/tests/test_views.py 3 0 3
trustpoint/util/tests/test_email.py 6 0 6
trustpoint/util/tests/test_email_service.py 19 0 19
trustpoint/util/tests/test_encrypted_fields.py 18 0 18
trustpoint/util/tests/test_sftp.py 18 0 18
trustpoint/workflows2/tests/test_adapters.py 7 1 8
trustpoint/workflows2/tests/test_api_views.py 7 0 7
trustpoint/workflows2/tests/test_crash_recovery.py 3 0 3
trustpoint/workflows2/tests/test_dispatch.py 16 0 16
trustpoint/workflows2/tests/test_dispatch_signal.py 2 0 2
trustpoint/workflows2/tests/test_jobs.py 2 0 2
trustpoint/workflows2/tests/test_persistence.py 1 0 1
trustpoint/workflows2/tests/test_views_http.py 20 0 20
trustpoint/workflows2/tests/test_worker.py 2 0 2
trustpoint/workflows2/tests/test_workflow2_bundle_approval_reject.py 14 0 14
trustpoint/workflows2/tests/test_worker_heartbeat.py 1 0 1
trustpoint/agents/tests/test_agent.py 137 0 137
trustpoint/aoki/tests/test_apps.py 3 0 3
trustpoint/aoki/tests/test_management_commands.py 8 0 8
trustpoint/aoki/tests/test_urls.py 2 0 2
trustpoint/aoki/tests/test_views.py 14 0 14
trustpoint/cmp/tests/test_apps.py 3 0 3
trustpoint/cmp/tests/test_urls.py 9 0 9
trustpoint/cmp/tests/test_util.py 22 0 22
trustpoint/crypto/tests/test_backend.py 11 0 11
trustpoint/crypto/tests/test_backend_placeholders.py 2 0 2
trustpoint/crypto/tests/test_capability_probe.py 4 0 4
trustpoint/crypto/tests/test_config.py 9 0 9
trustpoint/crypto/tests/test_error_map.py 7 0 7
trustpoint/crypto/tests/test_mechanisms.py 11 0 11
trustpoint/crypto/tests/test_session_pool.py 1 0 1
trustpoint/discovery/tests/test_discovery_views.py 18 0 18
trustpoint/discovery/tests/test_scanner.py 10 0 10
trustpoint/est/tests/test_est_interface.py 7 0 7
trustpoint/est/tests/test_urls.py 24 0 24
trustpoint/est/tests/test_views.py 33 0 33
trustpoint/help_pages/tests/test_commands.py 17 0 17
trustpoint/help_pages/tests/test_help_section.py 11 0 11
trustpoint/home/tests/test_urls.py 5 0 5
trustpoint/management/tests/test_pkcs11_aes_key.py 34 0 34
trustpoint/management/tests/test_pkcs11_private_key.py 23 0 23
trustpoint/request/tests/test_authentication.py 11 0 11
trustpoint/request/tests/test_authorization.py 44 0 44
trustpoint/request/tests/test_certificate_request_processors.py 2 0 2
trustpoint/request/tests/test_cmp_client.py 24 0 24
trustpoint/request/tests/test_cmp_message_builder.py 29 0 29
trustpoint/request/tests/test_cmp_workflow.py 3 0 3
trustpoint/request/tests/test_est_workflow.py 2 0 2
trustpoint/request/tests/test_gds_push_service.py 45 0 45
trustpoint/request/tests/test_http_request_validator.py 44 0 44
trustpoint/request/tests/test_message_builder_base.py 13 0 13
trustpoint/request/tests/test_operation_processors_csr.py 33 0 33
trustpoint/request/tests/test_pki_message_parser.py 46 0 46
trustpoint/request/tests/test_request_context.py 10 0 10
trustpoint/request/tests/test_rest_message_parser.py 30 0 30
trustpoint/request/tests/test_template_vars.py 18 0 18
trustpoint/rest_pki/tests/test_views.py 4 0 4
trustpoint/setup_wizard/tests/test_operational_attach.py 15 0 15
trustpoint/setup_wizard/tests/test_operational_handoff.py 2 0 2
trustpoint/setup_wizard/tests/test_tls_credential.py 22 0 22
trustpoint/setup_wizard/tests/test_tls_credential_parser.py 33 0 33
trustpoint/shared/tests/test_templatetags.py 22 0 22
trustpoint/trustpoint/tests/test_asgi.py 1 0 1
trustpoint/trustpoint/tests/test_logger.py 4 0 4
trustpoint/trustpoint/tests/test_settings.py 25 0 25
trustpoint/trustpoint/tests/test_urls.py 8 0 8
trustpoint/trustpoint/tests/test_wsgi.py 1 0 1
trustpoint/users/tests/test_urls.py 5 0 5
trustpoint/util/tests/test_field.py 17 0 17
trustpoint/util/tests/test_mult_obj_views.py 15 0 15
trustpoint/util/tests/test_validation.py 21 0 21
trustpoint/workflows2/tests/test_certificate_integration.py 3 0 3
trustpoint/workflows2/tests/test_compiler.py 34 0 34
trustpoint/workflows2/tests/test_device_integration.py 4 0 4
trustpoint/workflows2/tests/test_eval.py 2 0 2
trustpoint/workflows2/tests/test_executor.py 4 0 4
trustpoint/crypto/tests/test_pkcs11_integration_keys.py 0 2 2
trustpoint/crypto/tests/test_pkcs11_integration_probe.py 0 2 2
trustpoint/crypto/tests/test_pkcs11_integration_signing_contract.py 0 4 4
trustpoint/crypto/tests/test_pkcs11_integration_verify.py 0 3 3
TOTAL 3309 12 3321

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants