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

Improve logging and validation for license keys. #2982

Merged
merged 9 commits into from
Feb 7, 2025

Conversation

jaffinito
Copy link
Member

@jaffinito jaffinito commented Feb 3, 2025

BEGIN_COMMIT_OVERRIDE
feat: Improve logging and validation for license keys. (#2982)
END_COMMIT_OVERRIDE

Description

Adds an additional warning when the agent receives a HTTP 401 Unauthorized response from the collector. This occurs when the key is not valid (for many reasons).

Expands the validation logic from the license key in DefaultConfiguration to:

  • Still perform the checks once and save the value if one is found. If nothing is found save string.Empty to prevent further checks.
  • Check for empty/missing keys
  • Check if the value contains "license". Our default key and keys used in unit test use values that contain that word.
  • Check if it is the correct length - 40 characters
  • Check if the characters are valid for a key - ASCII characters from 0x21 to 0x7E
  • Check each of the different key locations and work through them in priority order to find a key without issues.
    • When a location has a value, but that value is invalid log a Warn message letting you know that a bad key was found and where.
    • If a valid key is found, report a Info message including where. Happens once since value is cached.
    • If no valid key is found log a Warn message to let us know. Happens each time the key is request from config.

Unit tests have been expanded to cover the new logic.

Note: valid in this context means that it is not null or whitespace, exactly 40 ASCII characters from 0x21 to 0x7E, or string contains "license" (case insensitive)).

Fixes #2969
Fixes #2783

Author Checklist

  • Unit tests, Integration tests, and Unbounded tests completed
  • Performance testing completed with satisfactory results (if required)

Reviewer Checklist

  • Perform code review
  • Pull request was adequately tested (new/existing tests, performance tests)

@jaffinito jaffinito requested a review from a team as a code owner February 3, 2025 18:14
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.17%. Comparing base (15f88c7) to head (6c36735).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2982      +/-   ##
==========================================
- Coverage   82.19%   82.17%   -0.02%     
==========================================
  Files         473      473              
  Lines       30362    30391      +29     
  Branches     3388     3392       +4     
==========================================
+ Hits        24955    24975      +20     
- Misses       4606     4617      +11     
+ Partials      801      799       -2     
Flag Coverage Δ
Agent 83.15% <100.00%> (-0.02%) ⬇️
Profiler 73.13% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...c/Agent/Core/Configuration/DefaultConfiguration.cs 89.90% <100.00%> (+0.15%) ⬆️
...elic/Agent/Core/DataTransport/ConnectionManager.cs 78.14% <100.00%> (+0.59%) ⬆️

... and 3 files with indirect coverage changes

Copy link
Member

@chynesNR chynesNR left a comment

Choose a reason for hiding this comment

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

Very nice!

@jaffinito jaffinito merged commit 19e8387 into main Feb 7, 2025
97 checks passed
@jaffinito jaffinito deleted the other/expanded-license-key-validation branch February 7, 2025 00:27
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.

Improve logging around invalid license key Do some sanity checking on license keys
4 participants