Skip to content

crypto: separate provider construction and routing policies - #356

Open
kssim wants to merge 2 commits into
eclipse-score:mainfrom
autocrypt-dot-io:feat/issue-143-provider-config-refactor
Open

kssim wants to merge 2 commits into
eclipse-score:mainfrom
autocrypt-dot-io:feat/issue-143-provider-config-refactor

Conversation

@kssim

@kssim kssim commented Oct 31, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Split provider configuration into independent construction and runtime routing policies.
  • Apply enabled/required provider policy in ProviderManagerFactory.
  • Move default and capability-based selection into ProviderRoutingPolicy.
  • Preserve detailed per-provider factory diagnostics and clean up partial startup state.
  • Add policy, startup, routing, fallback, deferred-initialization, and lifecycle tests.
  • Update provider architecture documentation.

Closes: #143

Design decisions

  • A required provider must be successfully constructed and registered, but its initialization may be deferred.
  • An empty construction policy allows all discovered providers; a non-empty policy acts as an allowlist.
  • Optional provider failures remain available for diagnostics and do not block startup when another usable registry exists.
  • ProviderFactoryResult is retained instead of reducing the result to Expected<monostate, ErrorCode>, because partial success and provider-specific failures are needed for diagnostics.
  • Capability routing first uses the configured category default, then other providers of that category in registration order, followed by configured fallback behavior.

Scope

Application-scoped provider resource resolution is handled by #290.
Provider-specific runtime configuration parsing remains under #149.

@github-actions

github-actions Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

License Check Results

🚀 The license check job ran with the Bazel command:

bazel run --lockfile_mode=error //:license-check

Status: ⚠️ Needs Review

Click to expand output
[License Check Output]
Extracting Bazel installation...
Starting local Bazel server (8.8.2) and connecting to it...
INFO: Invocation ID: 3fddfe74-831f-44c3-bfef-08933806f82a
Computing main repo mapping: 
Computing main repo mapping: 
Computing main repo mapping: 
WARNING: For repository 'rules_python', the root module requires module version rules_python@1.8.5, but got rules_python@1.9.0 in the resolved dependency graph. Please update the version in your MODULE.bazel or set --check_direct_dependencies=off
WARNING: For repository 'score_bazel_platforms', the root module requires module version score_bazel_platforms@0.1.2, but got score_bazel_platforms@1.3.0 in the resolved dependency graph. Please update the version in your MODULE.bazel or set --check_direct_dependencies=off
WARNING: For repository 'rules_cc', the root module requires module version rules_cc@0.2.22, but got rules_cc@0.2.26 in the resolved dependency graph. Please update the version in your MODULE.bazel or set --check_direct_dependencies=off
Computing main repo mapping: 
Computing main repo mapping: 
Computing main repo mapping: 
Loading: 
Loading: 1 packages loaded
Loading: 1 packages loaded
    currently loading: 
Loading: 1 packages loaded
    currently loading: 
Loading: 1 packages loaded
    currently loading: 
Loading: 1 packages loaded
    currently loading: 
Loading: 1 packages loaded
    currently loading: 
Loading: 1 packages loaded
    currently loading: 
Loading: 1 packages loaded
    currently loading: 
Loading: 1 packages loaded
    currently loading: 
WARNING: Target pattern parsing failed.
ERROR: Skipping '//:license-check': no such target '//:license-check': target 'license-check' not declared in package '' defined by /home/runner/work/crypto/crypto/BUILD
ERROR: no such target '//:license-check': target 'license-check' not declared in package '' defined by /home/runner/work/crypto/crypto/BUILD
INFO: Elapsed time: 17.052s
INFO: 0 processes.
ERROR: Build did NOT complete successfully
ERROR: Build failed. Not running target

@github-actions

Copy link
Copy Markdown
Contributor

Documentation preview for this pull request is available at:
pr-356: https://eclipse-score.github.io/inc_security_crypto/pr-356/

@GuruprasadBhatL

Copy link
Copy Markdown
Contributor

If I understand correctly, actually parsed values of ProviderConstructionPolicy , ProviderRoutingPolicy, and integration testing all cases of provider routing is part of #290 , Right ?

/// @brief Daemon-wide limits on key creation and key material per client connection.
///
/// Owned by daemon configuration, not by individual key slots.
/// Provider operational limits belong to the respective provider implementation;

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.

So the understanding here is, provider specific limits are not dictated by fbs/json config. is configured in provider. Max number of keys is limited by daemon wide limit.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, with one clarification: ResourceQuotaPolicy defines daemon-wide limits applied per client connection, such as the maximum number of ephemeral and loaded keys and the total key-material size. Provider-native capacity or operational limits are outside this general policy; if configurable, they belong to the provider-specific configuration and implementation.


[[nodiscard]] static bool IsProviderAllowed(const std::string& provider_name,
const config::ProviderInitConfig& provider_config);
friend class ProviderManagerFactoryTestPeer;

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.

Could we avoid adding a friend class solely for testing? Please check whether this behavior can be tested through the public Create() API instead. That would avoid exposing private implementation details to a test-only peer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I removed the test-only friend and moved the finalization helper into the implementation file. The factory tests now exercise the public ProviderManagerFactory::Create() API, while lower-level lifecycle and routing behavior remains covered by the ProviderManager unit tests.

/// @param is_enabled Whether provider construction is enabled.
/// @param is_required Whether startup requires provider registration.
ProviderConstructionEntry(const common::ProviderName& name, bool is_enabled = true, bool is_required = false)
: providerName{name}, enabled{is_enabled}, required{is_required}

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.

Why do we need is_enabled flag ? if some provider is not needed, it need not be specified in json config, what is the use case for having a provider configured in json but not enabling it ?

(of course this flag existed before)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You are right. Since a non-empty construction policy already acts as an allowlist, enabled=false was redundant with omitting the provider. I removed the flag. Listed providers are allowed, while required distinguishes mandatory providers from optional ones.

common::CryptoProviderType cryptoType{}; ///< Functional category
bool enabled{true}; ///< Whether this provider should be used
bool required{false}; ///< Whether startup must provide this provider
ResourceQuotaPolicy quota_policy{}; ///< Per-provider quota policy override

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.

Don't we need this as part of provider config and only part of general config ?

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.

Discussed with @ChansAlive , for now, we can have only global limit for now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Understood. I kept ResourceQuotaPolicy as a daemon-wide global policy for now. Provider-specific operational limits can remain within each provider implementation.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The fallback comment needs clarification because disabling allowFallback does not prevent trying SOFTWARE after HARDWARE fails when both appear in preference_order.

1 open issue
What changed in this PR

Separates provider construction policy from runtime routing in the crypto daemon, giving startup requirements and provider selection distinct responsibilities.

Changes:

  • Introduces independent construction and routing policies with validation.
  • Applies provider enablement and registration requirements in the factory, while refining routing, diagnostics, and shutdown behavior.
  • Adds policy and lifecycle tests, migrates existing callers, and updates architecture documentation.
File Description
score/​tests/​demo/​mac_multi_provider_demo.cpp Uses the routing-policy constructor.
score/​crypto/​tests/​cert_management/​test_cert_module_startup.cpp Migrates startup fixtures to routing policies.
score/​crypto/​src/​daemon/​provider/​src/​provider_manager.cpp Implements policy-based routing and shutdown safeguards.
score/​crypto/​src/​daemon/​provider/​src/​provider_manager_test.cpp Expands routing, deferred-initialization, and lifecycle coverage.
score/​crypto/​src/​daemon/​provider/​src/​provider_manager_factory.cpp Enforces construction policy and cleans up failed startup.
score/​crypto/​src/​daemon/​provider/​src/​provider_manager_factory_test.cpp Tests startup requirements, errors, and cleanup.
score/​crypto/​src/​daemon/​provider/​provider_manager.hpp Defines the routing-focused manager interface and state.
score/​crypto/​src/​daemon/​provider/​provider_manager_factory.hpp Declares startup finalization and test access.
score/​crypto/​src/​daemon/​provider/​BUILD Adds the factory unit-test target.
score/​crypto/​src/​daemon/​config/​src/​provider_policy_test.cpp Tests construction and routing policy validation.
score/​crypto/​src/​daemon/​config/​src/​config.cpp Validates both provider policies.
score/​crypto/​src/​daemon/​config/​inc/​config.hpp Defines separate policies and configuration accessors.
score/​crypto/​src/​daemon/​config/​BUILD Adds the policy unit-test target.
score/​crypto/​src/​daemon/​cert_management/​tests/​truststore/​test_trust_store_manager.cpp Migrates the trust-store fixture constructor.
score/​crypto/​src/​daemon/​cert_management/​tests/​service/​test_cert_management_service.cpp Migrates the service fixture constructor.
score/​crypto/​src/​daemon/​cert_management/​tests/​integration/​test_certificate_management_integration.cpp Migrates the integration fixture constructor.
score/​crypto/​src/​daemon/​cert_management/​slot/​slot_handler_factory_test.cpp Updates the provider-manager test helper.
score/​crypto/​src/​daemon/​cert_management/​query/​cert_object_response_builder_test.cpp Migrates the query fixture constructor.
score/​crypto/​docs/​architecture/​provider_architecture.rst Documents policy ownership, routing, and startup semantics.
score/​crypto/​docs/​architecture/​provider_architecture.puml Adds policy types and factory relationships.
score/​crypto/​docs/​architecture/​key_management_sequence_diagrams.puml Updates the provider startup sequence.

Review effort: Max (adaptive)

@kssim

kssim commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

If I understand correctly, actually parsed values of ProviderConstructionPolicy , ProviderRoutingPolicy, and integration testing all cases of provider routing is part of #290 , Right ?

Not exactly. #290 is limited to resolving application-scoped provider resource identifiers to configured providers. This PR owns the typed construction/routing policy model and its routing behavior tests. Generic deployment parsing of these policies is not currently part of #290, while #149 covers provider-specific backend configuration. If deployment parsing is required as part of #143, I think we should explicitly agree on that scope or track it separately.

@kssim
kssim force-pushed the feat/issue-143-provider-config-refactor branch from 7fa326a to c09dd29 Compare November 23, 2026 14:56
@kssim
kssim requested a deployment to workflow-approval November 23, 2026 14:56 — with GitHub Actions Waiting
@kssim
kssim requested a deployment to workflow-approval November 23, 2026 14:56 — with GitHub Actions Waiting
@kssim
kssim requested a deployment to workflow-approval November 23, 2026 14:56 — with GitHub Actions Waiting
@GuruprasadBhatL

Copy link
Copy Markdown
Contributor

Hi @kssim , unable to review the selectively the additional commits after last review. in PR history only 2 commits are shown now, did you change the commit history before the push ? may be you need to check the policy set in autocrypto fork repo.

@kssim

kssim commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Hi @kssim , unable to review the selectively the additional commits after last review. in PR history only 2 commits are shown now, did you change the commit history before the push ? may be you need to check the policy set in autocrypto fork repo.

Hi @GuruprasadBhatL, due to the rebase merge from master, I think the commits are updated.
You can check this one. c09dd29
These are the changes only for the comment review in this time.

@GuruprasadBhatL GuruprasadBhatL 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.

Reviewed git diff 5cc8ac06993b3757bf7c8c98d9e9ef07cd57c149 c09dd29dfbceb805eddfb4d66c376b3ccf6fc292 after the previous requested changes.

Assumption here is 5cc8ac0 reflects the original changes although there is a force push.

This branch is waiting to be deployed

1 waiting deployment
workflow-approval — c09dd29d Waiting Nov 23, 2026 by kssim via Build and Test aarch64-qnx / approval #1196
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

Provider Configuration Refactor

3 participants