improve error handling during re-registration#673
Open
AdamVB wants to merge 4 commits into
Open
Conversation
| if (Test-Path -Path "$configPath.bak") { | ||
| Remove-Item "$configPath.bak" -Force | ||
| } | ||
| if ($output) { |
Contributor
There was a problem hiding this comment.
should we throw $output if $loginFailed = true so we maintain the previous behaviour?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
non-zero exits without that keyword
Problem
Since commit b177c0c ("add reregister feature", Dec 2023), running the installer with a -RegistrationToken on a system that already has mondoo.yml triggers a logout → delete → login
cycle. If cnspec login fails for any reason (network issue, invalid token, API outage, DNS failure), the config file is already gone with no way to recover. This leaves the agent
unregistered and unable to communicate with the platform until someone manually re-registers.
The risk was increased by commit c930408 (Jan 2024), which removed the error check on the logout command — meaning a failed logout followed by a failed login still deleted the config.
This also runs on every installer invocation with a token, even when the installed version is already current, so scheduled updater tasks can trigger this path repeatedly.
Test plan
Also:
Add random delay for windows update scheduled task