Skip to content

Switch password hashing algorithm to argon2#2608

Merged
ryan-pratt merged 16 commits intorelease/v7.0.0from
maint/argon2
Dec 15, 2025
Merged

Switch password hashing algorithm to argon2#2608
ryan-pratt merged 16 commits intorelease/v7.0.0from
maint/argon2

Conversation

@ryan-pratt
Copy link
Copy Markdown
Contributor

@ryan-pratt ryan-pratt commented Dec 9, 2025

This change in practice:

  1. run COSMOS with a version prior to this branch and set a password
  2. check out this branch
  3. try to log in and see an error telling you to finish the migration to COSMOS 7
  4. run OPENC3_API_PASSWORD=password openc3.sh cli migratepassword
  5. login now works

@codecov
Copy link
Copy Markdown

codecov bot commented Dec 9, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.10%. Comparing base (435b45d) to head (72d576a).
⚠️ Report is 97 commits behind head on release/v7.0.0.

Additional details and impacted files
@@                Coverage Diff                 @@
##           release/v7.0.0    #2608      +/-   ##
==================================================
- Coverage           79.15%   78.10%   -1.05%     
==================================================
  Files                 661      473     -188     
  Lines               51740    33660   -18080     
  Branches              735      735              
==================================================
- Hits                40953    26289   -14664     
+ Misses              10707     7291    -3416     
  Partials               80       80              
Flag Coverage Δ
python 96.03% <ø> (+14.75%) ⬆️
ruby-api 84.40% <100.00%> (+0.04%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

return true if @@session_cache and (time - @@session_cache_time) < SESSION_CACHE_TIMEOUT and @@session_cache[token]
token_hash = hash(token)
return true if @@token_cache and (time - @@token_cache_time) < TOKEN_CACHE_TIMEOUT and @@token_cache == token_hash
unless no_password
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Missing this unless no_password is actually a bug in my last PR

return false
# Check stored password hash
pw_hash = Store.get(PRIMARY_KEY)
raise "invalid password hash" unless pw_hash.start_with?("$argon2") # Catch users who didn't run the migration utility when upgrading to COSMOS 7
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This triggers an alert on the login page that tells them to look at the migration guide, which tells them to run the password migration utility

Comment on lines +122 to +123
@@session_cache = nil
@@session_cache_time = nil
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sessions_cache typo was a bug that allowed sessions to persist for 5min after logging out

@ryan-pratt
Copy link
Copy Markdown
Contributor Author

Same as my last PR, only remaining test failure is pre-existing on v7 branch since we merged main

@ryan-pratt ryan-pratt marked this pull request as ready for review December 10, 2025 16:06
class AuthModel
PRIMARY_KEY = 'OPENC3__TOKEN'
SESSIONS_KEY = 'OPENC3__SESSIONS'
ARGON2_PROFILE = ENV["OPENC3_ARGON2_PROFILE"]&.to_sym || :rfc_9106_high_memory # More secure than default (:rfc_9106_low_memory)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The argon2 gem defaults to rfc_9106_low_memory, but we probably usually want to use rfc_9106_high_memory since it's the most secure built-in profile. This environment variable lets people override that with a less secure but faster profile (e.g. for github runners)

Copy link
Copy Markdown
Contributor

@clayandgen clayandgen left a comment

Choose a reason for hiding this comment

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

Tested and validated 👍
Only comment I'd make, is maybe in the migration documentation, mention that the OPENC3_API_PASSWORD can be in the .env as well -- I think most users won't want to type the API Password on the command line

s.add_runtime_dependency 'rubyzip', '~> 3.0'
s.add_runtime_dependency 'uuidtools', '~> 2.2'
s.add_runtime_dependency 'yard', '~> 0.9'
s.add_runtime_dependency 'argon2', '~> 2.3'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@ryanmelt if the dependency is here does it also have to be the Gemfile? I think no because of the gemspec line in the Gemfile. But maybe the Gemfile has support the >= 2.3.2 and that's why it's in both? I also see that tzinfo-data is in both ... is that an oversight? We should probably add some comments one way or another.

@ryan-pratt ryan-pratt merged commit 43d4d2f into release/v7.0.0 Dec 15, 2025
34 of 39 checks passed
@ryan-pratt ryan-pratt deleted the maint/argon2 branch December 15, 2025 19:05
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