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: Fix to make mender-connect request a new JWT token on its own, so its not dependent on mender-update to do so #134

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SebOpsahl
Copy link

@SebOpsahl SebOpsahl commented Feb 29, 2024

Changelog: Fix to make mender-connect request a new JWT token on its own, so its not dependent on mender-update to do so. Previously, mender-connect relied the Mender client to request new JWT tokens. Since the split of mender into mender-update and mender-auth, it is theoretically possible to run mender-connect without mender-update, in which case it wouldn't request JWT tokens without this fix.

Ticket: MEN-6877

@mender-test-bot
Copy link

@SebOpsahl, Let me know if you want to start the integration pipeline by mentioning me and the command "start pipeline".


my commands and options

You can trigger a pipeline on multiple prs with:

  • mentioning me and start pipeline --pr mender/127 --pr mender-connect/255

You can start a fast pipeline, disabling full integration tests with:

  • mentioning me and start pipeline --fast

You can trigger GitHub->GitLab branch sync with:

  • mentioning me and sync

You can cherry pick to a given branch or branches with:

  • mentioning me and:
 cherry-pick to:
 * 1.0.x
 * 2.0.x

@SebOpsahl SebOpsahl requested a review from a user March 1, 2024 00:05
@lluiscampos lluiscampos self-requested a review March 1, 2024 10:19
Copy link
Contributor

@lluiscampos lluiscampos left a comment

Choose a reason for hiding this comment

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

The fix looks good to me. Have you experimented a bit with the fix on a QEMU run? I think this deserves some manual testing also on top of our tests, for good measure.

See my comments below.

One other thing: the changelog deserves a bit more info. I would keep the commit title short, and write a longer entry that describes more of the historical reason for this. For example:

Fix bla bla bla.
Previously, mender-connect relied the Mender client to request new JWT tokens. Since the split of mender into mender-update and mender-auth, it is theoretically possible to run mender-connect without mender-update, in which case it wouldn't request JWT tokens without this fix.

@@ -33,7 +33,7 @@ const (

var timeout = 10 * time.Second

// AuthClient is the interface for the Mender Authentication Manager clilents
// AuthClient is the interface for the Mender Authentication Manager clients
Copy link
Contributor

Choose a reason for hiding this comment

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

This should go on a different commit.

Specially for fixes, where we might need to cherry-pick the fix to supported branches, we don't want a typo fix to be in the way.

app/daemon_test.go Outdated Show resolved Hide resolved
app/daemon_test.go Show resolved Hide resolved
app/daemon_test.go Outdated Show resolved Hide resolved
@SebOpsahl SebOpsahl force-pushed the master branch 2 times, most recently from ac6db0c to d7063f8 Compare March 4, 2024 21:12
@SebOpsahl
Copy link
Author

SebOpsahl commented Mar 4, 2024

The fix looks good to me. Have you experimented a bit with the fix on a QEMU run? I think this deserves some manual testing also on top of our tests, for good measure.

Yes I have manually tested it with a QEMU run with yocto on mender integration to ensure it behaves as it should during running.

@SebOpsahl
Copy link
Author

I fixed the requests you made, so it should look good now. Good catches, thanks :)

@lluiscampos
Copy link
Contributor

@SebOpsahl

  • You still haven't split the typo into a different commit (ref here)
  • For the changelog, we are still missing to say what have we fixed. "Fix bla bla bla" was meant to symbolize the text you had, and then extend it with the historical note. So please prepend something more explicit like "Fix logic for mender-connect to request a new JTW token on its own"
    • Also note that our changelogs are in markdown format, so a nice-to-have thing is to quote the binaries like mender-connect or mender-auth 😃

@SebOpsahl SebOpsahl force-pushed the master branch 2 times, most recently from 4521af3 to d8556ae Compare March 5, 2024 09:49
@SebOpsahl
Copy link
Author

@mender-test-bot start pipeline

@mender-test-bot
Copy link

Hello 😺 I created a pipeline for you here: Pipeline-1201262197

Build Configuration Matrix

Key Value
AUDITLOGS_REV master
BUILD_BEAGLEBONEBLACK true
BUILD_CLIENT true
BUILD_QEMUX86_64_BIOS_GRUB true
BUILD_QEMUX86_64_BIOS_GRUB_GPT true
BUILD_QEMUX86_64_UEFI_GRUB true
BUILD_VEXPRESS_QEMU true
BUILD_VEXPRESS_QEMU_FLASH true
BUILD_VEXPRESS_QEMU_UBOOT_UEFI_GRUB true
CREATE_ARTIFACT_WORKER_REV master
DEPLOYMENTS_ENTERPRISE_REV master
DEPLOYMENTS_REV master
DEVICEAUTH_ENTERPRISE_REV master
DEVICEAUTH_REV master
DEVICECONFIG_REV master
DEVICECONNECT_REV master
DEVICEMONITOR_REV master
GENERATE_DELTA_WORKER_REV master
GUI_REV master
INTEGRATION_REV master
INVENTORY_ENTERPRISE_REV master
INVENTORY_REV master
IOT_MANAGER_REV master
MENDER_ARTIFACT_REV master
MENDER_BINARY_DELTA_REV master
MENDER_CLI_REV master
MENDER_CONFIGURE_MODULE_REV master
MENDER_CONNECT_REV pull/134/head
MENDER_CONVERT_REV master
MENDER_GATEWAY_REV master
MENDER_REV master
MENDER_SETUP_REV master
MENDER_SNAPSHOT_REV master
MONITOR_CLIENT_REV master
MTLS_AMBASSADOR_REV master
RUN_BACKEND_INTEGRATION_TESTS true
RUN_INTEGRATION_TESTS true
TENANTADM_REV master
TEST_QEMUX86_64_BIOS_GRUB true
TEST_QEMUX86_64_BIOS_GRUB_GPT true
TEST_QEMUX86_64_UEFI_GRUB true
TEST_VEXPRESS_QEMU true
TEST_VEXPRESS_QEMU_FLASH true
TEST_VEXPRESS_QEMU_UBOOT_UEFI_GRUB true
USERADM_ENTERPRISE_REV master
USERADM_REV master
WORKFLOWS_ENTERPRISE_REV master
WORKFLOWS_REV master

@SebOpsahl
Copy link
Author

When running the big test the “test:acceptance:qemux86_64:uefi_grub:cross-platform” test fails, even though “test:acceptance:qemux86_64:uefi_grub” does not. So some of the cross-platform tests fail and returns the following errors, which seems to be due to loss of connection.

How may it be that it works for the other tests, but not testing for cross platform?

@SebOpsahl SebOpsahl requested a review from lluiscampos March 8, 2024 00:04
@lluiscampos
Copy link
Contributor

(...) How may it be that it works for the other tests, but not testing for cross platform?

The test is only run for that platform. If you look into the details of the test report you will find them mark as skip.

The name might be confusing, but the "cross platform" tests are the ones that are independent of the platform so we run them only once. The tests at hand are runtime tests for the mender-connect software, so these we consider "cross platform" because it doesn't matter how you integrate Mender on the platform, the software will run the same way once on the device. (Does this explanation make sense?)

We need to figure out if the tests are failing due to a failure in the software or is the test that needs some modification. For example if we have modified the text in the logs or the order of them it is possible that the test expectations are not met but the software is still fine.

@SebOpsahl
Copy link
Author

Oh okey, I understand now. Will look into it 👍

@SebOpsahl
Copy link
Author

@mender-test-bot start pipeline

@mender-test-bot
Copy link

Hello 😺 I created a pipeline for you here: Pipeline-1206911451

Build Configuration Matrix

Key Value
AUDITLOGS_REV master
BUILD_BEAGLEBONEBLACK true
BUILD_CLIENT true
BUILD_QEMUX86_64_BIOS_GRUB true
BUILD_QEMUX86_64_BIOS_GRUB_GPT true
BUILD_QEMUX86_64_UEFI_GRUB true
BUILD_VEXPRESS_QEMU true
BUILD_VEXPRESS_QEMU_FLASH true
BUILD_VEXPRESS_QEMU_UBOOT_UEFI_GRUB true
CREATE_ARTIFACT_WORKER_REV master
DEPLOYMENTS_ENTERPRISE_REV master
DEPLOYMENTS_REV master
DEVICEAUTH_ENTERPRISE_REV master
DEVICEAUTH_REV master
DEVICECONFIG_REV master
DEVICECONNECT_REV master
DEVICEMONITOR_REV master
GENERATE_DELTA_WORKER_REV master
GUI_REV master
INTEGRATION_REV master
INVENTORY_ENTERPRISE_REV master
INVENTORY_REV master
IOT_MANAGER_REV master
MENDER_ARTIFACT_REV master
MENDER_BINARY_DELTA_REV master
MENDER_CLI_REV master
MENDER_CONFIGURE_MODULE_REV master
MENDER_CONNECT_REV pull/134/head
MENDER_CONVERT_REV master
MENDER_GATEWAY_REV master
MENDER_REV master
MENDER_SETUP_REV master
MENDER_SNAPSHOT_REV master
MONITOR_CLIENT_REV master
MTLS_AMBASSADOR_REV master
RUN_BACKEND_INTEGRATION_TESTS true
RUN_INTEGRATION_TESTS true
TENANTADM_REV master
TEST_QEMUX86_64_BIOS_GRUB true
TEST_QEMUX86_64_BIOS_GRUB_GPT true
TEST_QEMUX86_64_UEFI_GRUB true
TEST_VEXPRESS_QEMU true
TEST_VEXPRESS_QEMU_FLASH true
TEST_VEXPRESS_QEMU_UBOOT_UEFI_GRUB true
USERADM_ENTERPRISE_REV master
USERADM_REV master
WORKFLOWS_ENTERPRISE_REV master
WORKFLOWS_REV master

@SebOpsahl SebOpsahl force-pushed the master branch 3 times, most recently from 515506c to 9c8b3a8 Compare March 10, 2024 19:54
@mender-test-bot
Copy link

Merging these commits will result in the following changelog entries:

Changelogs

@SebOpsahl
Copy link
Author

@mender-test-bot start pipeline

@mender-test-bot
Copy link

Hello 😺 I created a pipeline for you here: Pipeline-1208047869

Build Configuration Matrix

Key Value
AUDITLOGS_REV master
BUILD_BEAGLEBONEBLACK true
BUILD_CLIENT true
BUILD_QEMUX86_64_BIOS_GRUB true
BUILD_QEMUX86_64_BIOS_GRUB_GPT true
BUILD_QEMUX86_64_UEFI_GRUB true
BUILD_VEXPRESS_QEMU true
BUILD_VEXPRESS_QEMU_FLASH true
BUILD_VEXPRESS_QEMU_UBOOT_UEFI_GRUB true
CREATE_ARTIFACT_WORKER_REV master
DEPLOYMENTS_ENTERPRISE_REV master
DEPLOYMENTS_REV master
DEVICEAUTH_ENTERPRISE_REV master
DEVICEAUTH_REV master
DEVICECONFIG_REV master
DEVICECONNECT_REV master
DEVICEMONITOR_REV master
GENERATE_DELTA_WORKER_REV master
GUI_REV master
INTEGRATION_REV master
INVENTORY_ENTERPRISE_REV master
INVENTORY_REV master
IOT_MANAGER_REV master
MENDER_ARTIFACT_REV master
MENDER_BINARY_DELTA_REV master
MENDER_CLI_REV master
MENDER_CONFIGURE_MODULE_REV master
MENDER_CONNECT_REV pull/134/head
MENDER_CONVERT_REV master
MENDER_GATEWAY_REV master
MENDER_REV master
MENDER_SETUP_REV master
MENDER_SNAPSHOT_REV master
MONITOR_CLIENT_REV master
MTLS_AMBASSADOR_REV master
RUN_BACKEND_INTEGRATION_TESTS true
RUN_INTEGRATION_TESTS true
TENANTADM_REV master
TEST_QEMUX86_64_BIOS_GRUB true
TEST_QEMUX86_64_BIOS_GRUB_GPT true
TEST_QEMUX86_64_UEFI_GRUB true
TEST_VEXPRESS_QEMU true
TEST_VEXPRESS_QEMU_FLASH true
TEST_VEXPRESS_QEMU_UBOOT_UEFI_GRUB true
USERADM_ENTERPRISE_REV master
USERADM_REV master
WORKFLOWS_ENTERPRISE_REV master
WORKFLOWS_REV master

@SebOpsahl SebOpsahl force-pushed the master branch 2 times, most recently from ac207fb to f7bff76 Compare March 11, 2024 08:27
@SebOpsahl SebOpsahl force-pushed the master branch 5 times, most recently from 4db0a34 to 2e6bd05 Compare March 11, 2024 15:12
@SebOpsahl SebOpsahl closed this Apr 15, 2024
@SebOpsahl SebOpsahl reopened this Apr 15, 2024
@SebOpsahl
Copy link
Author

@kacf Problem to fix:
Make mender-connect request a new JWT token on its own, so its not dependent on mender-update to do so.

Proposed solution (PR):
Previously FetchJWTToken() wasn’t called which wouldn’t let it call the JWT token independently, which made it dependent on mender-update. The PR proposes a solution where FetchJWTToken() is used to fetch the token, to then for WaitForJwtTokenStateChange() to retrieve it in it’s waiting. I and Lluis have talked an the solution should look good.

Proposed change in test:
Since the tests is based on mocks it is proposed to set the token, wait for a connection and then send a signal, simulating the task of FetchJWTToken()

With these changes the test_mender_connect_auth_changes() which previously didn’t work now is successful. This test case however from the test_mender_connect_reconnect() test function fails. All the other test cases from the function is successful. The one thing separating the failing test case from the others is that this test case focuses on killing the server and then waiting for the error.
Any idea as to what might be causing the error? The error returned is Failed: Timed out waiting for 'error reconnecting:'

SebOpsahl added a commit to SebOpsahl/meta-mender that referenced this pull request May 26, 2024
…on its own, so its not dependent on `mender-update` to do so. Previously `FetchJWTToken()` wasn’t called which wouldn’t let it call the JWT token independently, which made it dependent on `mender-update`. The PR to do this 👉 mendersoftware/mender-connect#134 proposed to fix this issue using `FetchJWTToken()` to fetch the token, to then for `WaitForJwtTokenStateChange()` to retrieve it in it’s waiting. The old mocks for the tests seemed to be more tailored to test the functionality with `GetJWTToken()`. This PR proposes a change in the mocks and test flow to better test the new implementation (where the 'new implementation' is the one proposed in the other PR for ticket MEN-6877)

Changelog: None

Ticket: MEN-6877
Signed-off-by: Sebastian Opsahl <sebastian.opsahl@northern.tech>
@@ -312,57 +312,49 @@ func (d *MenderShellDaemon) dbusEventLoop(client mender.AuthClient) {
break
}

if d.needsReconnect() {
Copy link
Author

Choose a reason for hiding this comment

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

In this newest commit I removed this extra check "if d.needsReconnect" early in the function which set the needsReconnect value to True. Rather the code now only have one check. Having these two checks doing the same thing must have delayed the tests and made it fail.


// If the server (Mender client proxy) closed the connection, it is likely that
// both messageLoop is asking for a reconnection and we got JwtTokenStateChange
// signal. So drain here the reconnect channel and reconnect only once
if d.needsReconnect() {
log.Debug("dbusEventLoop: drained reconnect req channel")
log.Trace("dbusEventLoop: daemon needs to reconnect")
Copy link
Author

Choose a reason for hiding this comment

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

Reference point for message above. Only now one check for setting needsReconnect to True

Copy link
Contributor

Choose a reason for hiding this comment

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

Okey. But I think now the comment above with regards to "draining" the channel is obsolete, as with the current code this is the only point where the message loop can signal a re-connection.

I think the code is good but we need to adjust the miss-leading comment (or remove?)

SebOpsahl added a commit to SebOpsahl/meta-mender that referenced this pull request May 26, 2024
…connect

This PR is made to change the mocks and testflow in tests to better fit the new implementation of the PR 👉 mendersoftware/mender-connect#134. This PR fixes it so `mender-connect` requests a new JWT token on its own, so its not dependent on `mender-update` to do so. Previously `FetchJWTToken()` wasn’t called which wouldn’t let it call the JWT token independently, which made it dependent on `mender-update`. The proposed fix is using `FetchJWTToken()` to fetch the token, to then for `WaitForJwtTokenStateChange()` to retrieve it in it’s waiting. The old mocks and test flow for the tests seemed to be more tailored to test the functionality with `GetJWTToken()`. This PR proposes a change in the mocks and test flow to better test the new implementation.

Changelog: None

Ticket: MEN-6877
Signed-off-by: Sebastian Opsahl <sebastian.opsahl@northern.tech>
SebOpsahl added a commit to SebOpsahl/meta-mender that referenced this pull request May 26, 2024
…connect

This PR is made to change the mocks and testflow in tests to better fit the new implementation of the PR 👉 mendersoftware/mender-connect#134. This PR fixes it so `mender-connect` requests a new JWT token on its own, so its not dependent on `mender-update` to do so. Previously `FetchJWTToken()` wasn’t called which wouldn’t let it call the JWT token independently, which made it dependent on `mender-update`. The proposed fix is using `FetchJWTToken()` to fetch the token, to then for `WaitForJwtTokenStateChange()` to retrieve it in it’s waiting. The old mocks and test flow for the tests seemed to be more tailored to test the functionality with `GetJWTToken()`. This PR proposes a change in the mocks and test flow to better test the new implementation.

Changelog: None

Ticket: MEN-6877
Signed-off-by: Sebastian Opsahl <sebastian.opsahl@northern.tech>
SebOpsahl added a commit to SebOpsahl/meta-mender that referenced this pull request May 26, 2024
…connect

This PR is made to change the mocks and testflow in tests to better fit the new implementation of the PR 👉 mendersoftware/mender-connect#134. This PR fixes it so `mender-connect` requests a new JWT token on its own, so its not dependent on `mender-update` to do so. Previously `FetchJWTToken()` wasn’t called which wouldn’t let it call the JWT token independently, which made it dependent on `mender-update`. The proposed fix is using `FetchJWTToken()` to fetch the token, to then for `WaitForJwtTokenStateChange()` to retrieve it in it’s waiting. The old mocks and test flow for the tests seemed to be more tailored to test the functionality with `GetJWTToken()`. This PR proposes a change in the mocks and test flow to better test the new implementation.

Changelog: None

Ticket: MEN-6877
Signed-off-by: Sebastian Opsahl <sebastian.opsahl@northern.tech>
d.serverJwt = token
d.serverUrl = serverURL
d.postEvent(e)
log.Tracef("(dbusEventLoop) posting Event: %s", e.event)
Copy link
Contributor

Choose a reason for hiding this comment

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

Either we move this entry to before the d.postEvent(e) line or we change the text for something like "posted Event: ..."


// If the server (Mender client proxy) closed the connection, it is likely that
// both messageLoop is asking for a reconnection and we got JwtTokenStateChange
// signal. So drain here the reconnect channel and reconnect only once
if d.needsReconnect() {
log.Debug("dbusEventLoop: drained reconnect req channel")
log.Trace("dbusEventLoop: daemon needs to reconnect")
Copy link
Contributor

Choose a reason for hiding this comment

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

Okey. But I think now the comment above with regards to "draining" the channel is obsolete, as with the current code this is the only point where the message loop can signal a re-connection.

I think the code is good but we need to adjust the miss-leading comment (or remove?)

@SebOpsahl SebOpsahl force-pushed the master branch 2 times, most recently from 620e97f to e8ac42f Compare May 29, 2024 21:08
Fix to make `mender-connect` request a new JWT token on its own, so its not dependent on `mender-update` to do so. Previously, `mender-connect` relied the Mender client to request new JWT tokens. Since the split of `mender` into `mender-update` and `mender-auth`, it is theoretically possible to run `mender-connect` without `mender-update`, in which case it wouldn't request JWT tokens without this fix.

Changelog: None

Ticket: MEN-6877
Signed-off-by: Sebastian Opsahl <sebastian.opsahl@northern.tech>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants