Skip to content

feat: Connect summary cryptoki show mode and key URI#3623

Merged
Bravo555 merged 2 commits intothin-edge:mainfrom
Bravo555:feat/connect-summary-key-uri
May 20, 2025
Merged

feat: Connect summary cryptoki show mode and key URI#3623
Bravo555 merged 2 commits intothin-edge:mainfrom
Bravo555:feat/connect-summary-key-uri

Conversation

@Bravo555
Copy link
Copy Markdown
Member

@Bravo555 Bravo555 commented May 14, 2025

Proposed changes

Change cryptoki: line in connection summary from simple true/false to display mode and key URI:

  • If mode is off: cryptoki: off
  • If mode is not off and key_uri is not set: cryptoki: MODE
  • If mode is not off and key_uri is set: cryptoki: MODE (key: KEY)

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Improvement (general improvements like code refactoring that doesn't explicitly fix a bug or add any new functionality)
  • Documentation Update (if none of the other choices apply)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Paste Link to the issue


Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA (in all commits with git commit -s. You can activate automatic signing by running just prepare-dev once)
  • I ran just format as mentioned in CODING_GUIDELINES
  • I used just check as mentioned in CODING_GUIDELINES
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Further comments

I'm not sure if this is the best way to format the information in the summary, I'm open to suggestions for changes.

An alternative would be to instead of separate cryptoki: line, to add a private key: line, and put there key_uri and key_path config settings, depending whether cryptoki is enabled or not.

@Bravo555 Bravo555 had a problem deploying to Test Pull Request May 14, 2025 14:58 — with GitHub Actions Failure
@codecov
Copy link
Copy Markdown

codecov bot commented May 14, 2025

Codecov Report

Attention: Patch coverage is 21.42857% with 22 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/core/tedge/src/cli/connect/command.rs 0.00% 18 Missing ⚠️
...common/tedge_config/src/tedge_toml/tedge_config.rs 75.00% 2 Missing ⚠️
crates/core/tedge/src/cli/log.rs 0.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@reubenmiller
Copy link
Copy Markdown
Contributor

If mode is off: cryptoki: disabled

It might make more sense to show the same value as used in the tedge.toml, e.g. off, socket or module...this would be more consistent, and also easier to debug (e.g. are you using a module or socket etc.)

@Bravo555 Bravo555 had a problem deploying to Test Pull Request May 16, 2025 08:34 — with GitHub Actions Failure
@Bravo555 Bravo555 force-pushed the feat/connect-summary-key-uri branch from 7184394 to f29ff36 Compare May 16, 2025 09:52
@Bravo555 Bravo555 temporarily deployed to Test Pull Request May 16, 2025 09:52 — with GitHub Actions Inactive
@Bravo555 Bravo555 marked this pull request as ready for review May 16, 2025 09:52
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented May 16, 2025

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
634 0 3 634 100 1h49m39.863169999s

Copy link
Copy Markdown
Contributor

@didier-wenzek didier-wenzek left a comment

Choose a reason for hiding this comment

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

Approved, with minor comments.

Comment on lines +112 to +121
let cryptoki_key_uri = config.device.cryptoki_config(cloud)?.map(|c| match c {
CryptokiConfig::Direct(d) => d.uri,
CryptokiConfig::SocketService { uri, .. } => uri,
});
let cryptoki_mode = config.device.cryptoki.mode.clone();
let cryptoki_status = match cryptoki_key_uri {
None => "off".to_string(),
Some(None) => format!("{cryptoki_mode} (key: unspecified)"),
Some(Some(key)) => format!("{cryptoki_mode} (key: {key})"),
};
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.

This is working but I'm surprised by the mode extracted twice via two different paths (indirectly with config.device.cryptoki_config and then explicitly with config.device.cryptoki.mode). Isn't there a risk of inconsistency?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

fixed in c057753

Yeah, I've overengineered it a bit, I was using cryptoki_config to get the correct URI, but I could simply get URI from cloud.key_uri. It should now be much simpler.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I had to revert this because I forgot why I did that originally: cloud.device.key_uri is empty if we use device.key_uri, and .cryptoki_config() actually read both and applied device.key_uri if the one from cloud was None.

@reubenmiller
Copy link
Copy Markdown
Contributor

@Bravo555 I noticed that we currently don't have a system test (which is run by default) for setting the device.key_uri (since the only place it is being used is the AWS test which is currently marked as on_demand only).

It would make sense adding a new system tests which just uses Cumulocity and sets the PKCS11 URI on the client side (and not on the tedge-p11-server)...having this test would also make it easier to see a real example of how the tedge connect xx info looks like in a real-world scenario.

@Bravo555 Bravo555 force-pushed the feat/connect-summary-key-uri branch from f29ff36 to c057753 Compare May 19, 2025 08:47
@Bravo555 Bravo555 had a problem deploying to Test Pull Request May 19, 2025 08:47 — with GitHub Actions Failure
@Bravo555 Bravo555 requested a review from a team as a code owner May 19, 2025 11:23
@Bravo555 Bravo555 temporarily deployed to Test Pull Request May 19, 2025 11:23 — with GitHub Actions Inactive
@Bravo555
Copy link
Copy Markdown
Member Author

Bravo555 commented May 19, 2025

It would make sense adding a new system tests which just uses Cumulocity and sets the PKCS11 URI on the client side

@reubenmiller New test added in f3ac02b. Is it sufficient?

@reubenmiller reubenmiller added the theme:hsm Hardware Security Module related topics label May 19, 2025
@Bravo555 Bravo555 temporarily deployed to Test Pull Request May 19, 2025 12:53 — with GitHub Actions Inactive
@Bravo555 Bravo555 had a problem deploying to Test Pull Request May 19, 2025 16:57 — with GitHub Actions Failure
@Bravo555 Bravo555 force-pushed the feat/connect-summary-key-uri branch from a21f01b to a309757 Compare May 20, 2025 09:02
@Bravo555 Bravo555 temporarily deployed to Test Pull Request May 20, 2025 09:02 — with GitHub Actions Inactive
Copy link
Copy Markdown
Contributor

@reubenmiller reubenmiller left a comment

Choose a reason for hiding this comment

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

Approved. Nice improvement to make it more transparent about the settings being used.

Bravo555 added 2 commits May 20, 2025 11:44
Change `cryptoki:` line in connection summary from simple `true/false`
to display mode and key URI:

- If mode is off: `cryptoki: off`
- If mode is not off and `key_uri` is not set: `cryptoki: MODE`
- If mode is not off and `key_uri` is set: `cryptoki: MODE (key: KEY)`

Signed-off-by: Marcel Guzik <marcel.guzik@cumulocity.com>
Signed-off-by: Marcel Guzik <marcel.guzik@cumulocity.com>
@Bravo555 Bravo555 force-pushed the feat/connect-summary-key-uri branch from 094c495 to a2de92a Compare May 20, 2025 11:45
@Bravo555 Bravo555 temporarily deployed to Test Pull Request May 20, 2025 11:45 — with GitHub Actions Inactive
@Bravo555 Bravo555 added this pull request to the merge queue May 20, 2025
Merged via the queue into thin-edge:main with commit 3c9a06c May 20, 2025
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

theme:hsm Hardware Security Module related topics

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants