Skip to content
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

Fix: tedge connect c8y --test must not use a persistent MQTT session #2209

Merged

Conversation

didier-wenzek
Copy link
Contributor

@didier-wenzek didier-wenzek commented Sep 1, 2023

By using a persistent session, tedge connect c8y --test might return false positive, telling the connection with c8y is okay, while the received tokens were simply stalled and persisted by mistake. => All MQTT connections used to retrieve JWT token must set the clean session flag to true.

To Reproduce

Start as for #2207, but on a device that is actively connected for a while and where tedge connect c8y --test. has not been run during this period.

  1. Ensure that the used network interface is up.
  2. Run the command tedge connect c8y.
  3. Bring down the network interface sudo up link set wlan down or just disconnect your network cable.
  4. Run the command tedge connect c8y --test.
  5. Unexpectedly, the previous command tells everything is fine pretending that a token has just been received from c8y.

This token was simply persisted by mosquitto.

Simple way to reproduce the issue

tedge connect c8y --test must not be fooled by a token sent before the connection test.

  1. Ensure that the used network interface is up.
  2. Run the command tedge connect c8y.
  3. Bring down the network interface sudo tp link set wlan down or just disconnect your network cable.
  4. Publish a fake-token: tedge mqtt pub c8y/s/dat 71,fake-token --qos 1
  5. Run the test: tedge connect c8y --test.
  6. Issue: tedge connect wrongly tells the connection is up.
  7. Expected behavior: tedge connect ignores the fake token and tells that the device is in unknown status

Proposed changes

Clear the session flag of the MQTT connection used by tedge connect c8y --test

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

#2207 (comment)

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA (in all commits with git commit -s)
  • I ran cargo fmt as mentioned in CODING_GUIDELINES
  • I used cargo clippy 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

By using a persistent session, `tedge connect c8y --test` might return
false positive, telling the connection with c8y is okay, while the
received tokens were simply stalled and persisted by mistake.
=> All MQTT connections used to retrieve JWT token must set the clean
session flag to true.

Signed-off-by: Didier Wenzek <[email protected]>
@didier-wenzek didier-wenzek marked this pull request as ready for review September 1, 2023 14:59
@didier-wenzek didier-wenzek temporarily deployed to Test Pull Request September 1, 2023 15:08 — with GitHub Actions Inactive
@codecov
Copy link

codecov bot commented Sep 1, 2023

Codecov Report

Merging #2209 (7be4619) into main (c07cf47) will decrease coverage by 0.1%.
Report is 1 commits behind head on main.
The diff coverage is 33.3%.

Additional details and impacted files
Files Changed Coverage Δ
crates/core/c8y_api/src/smartrest/error.rs 0.0% <ø> (ø)
crates/core/c8y_api/src/smartrest/operations.rs 81.5% <0.0%> (-0.5%) ⬇️
crates/core/tedge/src/cli/connect/command.rs 0.0% <0.0%> (ø)
crates/core/tedge/src/cli/mqtt/cli.rs 61.5% <ø> (-3.0%) ⬇️
...tes/core/tedge_agent/src/state_repository/error.rs 0.0% <ø> (ø)
plugins/tedge_apt_plugin/src/main.rs 26.0% <ø> (+0.6%) ⬆️
...tes/core/tedge_agent/src/state_repository/state.rs 86.8% <50.0%> (ø)
crates/extensions/c8y_mapper_ext/src/tests.rs 92.9% <100.0%> (-0.1%) ⬇️

... and 7 files with indirect coverage changes

@github-actions
Copy link
Contributor

github-actions bot commented Sep 1, 2023

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
261 0 5 261 100 47m36.193s

@didier-wenzek didier-wenzek merged commit b645416 into thin-edge:main Sep 1, 2023
18 checks passed
@didier-wenzek didier-wenzek deleted the fix/tedge-connect-c8y-test branch September 1, 2023 15:35
@gligorisaev
Copy link
Contributor

QA has thoroughly checked the feature and here are the results:

  • Test for ticket exists in the test suite.
  • QA has tested the feature and it meets the required specifications.

@reubenmiller reubenmiller added this to the 0.13.0 milestone Sep 12, 2023
@reubenmiller reubenmiller added theme:mqtt Theme: mqtt and mosquitto related topics theme:cli Theme: cli related topics theme:c8y Theme: Cumulocity related topics labels Sep 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme:c8y Theme: Cumulocity related topics theme:cli Theme: cli related topics theme:mqtt Theme: mqtt and mosquitto related topics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants