-
Notifications
You must be signed in to change notification settings - Fork 71
Fix agent handling of 403 Forbidden registration responses #1154
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 agent handling of 403 Forbidden registration responses #1154
Conversation
300d1a3 to
052b1b5
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
052b1b5 to
7ecb4ae
Compare
keylime-agent/src/main.rs
Outdated
| error!("Failed to register agent: Registration forbidden - {message}"); | ||
| error!("This indicates a security rejection (403 Forbidden), likely due to TPM identity mismatch or UUID spoofing attempt."); | ||
| error!("The existing agent record must be deleted before re-registering with a different TPM."); | ||
| std::process::exit(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling process::exit directly in the business logic is problematic because it skips resource cleanup (e.g. drop handles will not run, leaving TPM handles, file locks, network connections and other resources unreleased), and it also makes it not testable. You should likely use a more idiomatic pattern of propagating the error via Result and have main() decide to exit.
Something like this (change main() signature to return Result):
async fn main() -> Result<()> {
// ... existing code ...
match keylime::agent_registration::register_agent(aa, &mut ctx).await {
Ok(()) => (),
Err(Error::RegistrarClient(
RegistrarClientError::RegistrationForbidden { message },
)) => {
error!("Failed to register agent: Registration forbidden - {message}");
error!("This indicates a security rejection (403 Forbidden), likely due to TPM identity mismatch or UUID
spoofing attempt.");
error!("The existing agent record must be deleted before re-registering with a different TPM.");
return Err(Error::RegistrarClient(
RegistrarClientError::RegistrationForbidden { message },
));
}
Err(e) => {
error!("Failed to register agent: {e:?}");
// Decide: should other registration errors also be fatal?
return Err(e);
}
}
// ... remaining of main ...
Ok(())
}
Note: The Rust runtime automatically converts Err from main() to a non-zero exit code, so the external behavior (process exits with error) remains the same while ensuring proper cleanup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the rest of the registration issues, I just wanted to be "as less aggressive as possible". I am not sure we should change Pull Mode agent behavior for registration issues not related to registry duplicate UUID issue.
7ecb4ae to
ede0932
Compare
sergio-correia
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this looks good to me. In the future we can add some testing to cover the new RegistrationForbidden path.
ede0932 to
70a0b23
Compare
70a0b23 to
d638060
Compare
d638060 to
2bc9d13
Compare
The agent was incorrectly interpreting 403 Forbidden responses from the registrar as API version incompatibility errors. This caused two problems: 1. The agent would try all enabled API versions, even though 403 indicates a permanent security rejection (e.g., TPM identity mismatch during re-registration) 2. The agent would continue running after registration failure, making it appear operational when it was not properly registered This issue became apparent with the Python keylime registrar security fix for CVE-2025-13609 (duplicate UUID vulnerability), which returns 403 Forbidden when an agent attempts to re-register with a different TPM identity. The agent will now correctly fail fast when the registrar rejects registration for security reasons. Related: keylime/keylime#1820 (Python registrar UUID spoofing fix) Co-Authored-By: Claude <[email protected]> Signed-off-by: Sergio Arroutbi <[email protected]>
2bc9d13 to
eab1619
Compare
The agent was incorrectly interpreting 403 Forbidden responses from the registrar as API version incompatibility errors. This caused two problems:
The agent would try all enabled API versions, even though 403 indicates a permanent security rejection (e.g., TPM identity mismatch during re-registration)
The agent would continue running after registration failure, making it appear operational when it was not properly registered
This issue became apparent with the Python keylime registrar security fix for CVE-2025-13609 (duplicate UUID vulnerability), which returns 403 Forbidden when an agent attempts to re-register with a different TPM identity.
The agent will now correctly fail fast when the registrar rejects registration for security reasons, allowing proper error detection in tests and production deployments.
Related: keylime/keylime#1820 (Python registrar UUID spoofing fix)