Skip to content

Conversation

@badarghal
Copy link
Contributor

@badarghal badarghal commented Nov 13, 2025

What

Fixes race condition during setting config field of the DBCrypt struct in the dbcrypt package. In addition it adds New function to allow creating preconfigured DBCrypt struct instances, bypassing config loading altogether.

Why

Race condition that can crash the application. Also it potentially have security implications.

References

Checklist

  • Tests

@badarghal badarghal requested review from a team as code owners November 13, 2025 08:56
@greenbonebot
Copy link
Member

Scanning the following files:

pkg/dbcrypt/dbcrypt.go
pkg/dbcrypt/dbcrypt_test.go

Scan: 'pkg/dbcrypt/dbcrypt.go'

Nothing detected in pkg/dbcrypt/dbcrypt.go
Scan took 0.00 seconds

Scan: 'pkg/dbcrypt/dbcrypt_test.go'

Nothing detected in pkg/dbcrypt/dbcrypt_test.go
Scan took 0.00 seconds

@github-actions
Copy link

Conventional Commits Report

Type Number
Bug Fixes 1

🚀 Conventional commits found.

@codecov
Copy link

codecov bot commented Nov 13, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 56.11%. Comparing base (b2cf5fb) to head (608e37b).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #263      +/-   ##
==========================================
+ Coverage   55.90%   56.11%   +0.20%     
==========================================
  Files          61       61              
  Lines        3225     3231       +6     
==========================================
+ Hits         1803     1813      +10     
+ Misses       1293     1291       -2     
+ Partials      129      127       -2     
Flag Coverage Δ
opensearch-tests 95.66% <ø> (ø)
postgres-tests 91.96% <ø> (ø)
unit-tests 49.15% <100.00%> (+0.25%) ⬆️

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.

Comment on lines +132 to +145
dataEncrypted := dataClear
err := cryptCustom.EncryptStruct(&dataEncrypted)
require.NoError(t, err)
require.NotEqual(t, dataClear, dataEncrypted, "password was not encrypted")

dataDefaultDecrypted := dataEncrypted
err = cryptDefault.DecryptStruct(&dataDefaultDecrypted)
require.Error(t, err)
assert.Equal(t, dataEncrypted, dataDefaultDecrypted)

dataCustomDecrypted := dataEncrypted
err = cryptCustom.DecryptStruct(&dataCustomDecrypted)
require.NoError(t, err)
assert.Equal(t, dataClear, dataCustomDecrypted)
Copy link
Contributor

@llugin llugin Nov 18, 2025

Choose a reason for hiding this comment

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

I would at least add comments about each test case intention, I think it would make it easier to comprehend. For me it would be also more logical to read if it would be in order:

cryptCustom.EncryptStruct()
...
cryptCustom.DecryptStruct()
...
cryptDefault.DecryptStruct()

so dividing test cases per DBCrypt instance, which could be even separate t.Run() testcases.

@badarghal badarghal closed this Nov 20, 2025
@badarghal badarghal deleted the AT-2841-fix-dbcrypt-config-race branch November 20, 2025 08:57
@badarghal
Copy link
Contributor Author

We are going to use a different approach and re-implement the entire package. See #267 for more details.

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.

4 participants