-
Notifications
You must be signed in to change notification settings - Fork 294
[Auth] Enhance secret token handling with user ID filtering #9154
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
Conversation
….py` to streamline the mocking of HTTPRunDB connection flow for OAuth tests, enhancing test maintainability and clarity.
elbamit
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.
#8823
Please see this PR, it does the same thing at a different place. You can maybe use your function there
| return secret_tokens | ||
|
|
||
|
|
||
| def validate_secret_tokens( |
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.
validate_secret_tokens checks for:
nameexistencetokenexistencesub= user- looks for duplicates
extract_and_validate_tokens_info checks for:
nameexistencesubexistenceexpexistencesub= user- looks for duplicates
I think they can be merged into a single function.
If we do decide to keep it separate, let's rename it since it doesn't do just validation, but it actually filters the list of tokens.
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.
I will do it on a following pr
elbamit
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.
Looks good
### 📝 Description Follow-up to #9154. Refactors secret token validation by removing the standalone `validate_secret_tokens` function and unifying validation logic into `extract_and_validate_tokens_info`. --- ### 🛠️ Changes Made - Removed redundant `validate_secret_tokens` function from `mlrun/auth/utils.py` - Unified token validation into `extract_and_validate_tokens_info` with a new `filter_by_authenticated_id` parameter - Updated `load_and_prepare_secret_tokens` to use the unified validation function - Updated tests to reflect the refactored validation logic --- ### ✅ Checklist - [ ] I updated the documentation (if applicable) - [x] I have tested the changes in this PR - [ ] I confirmed whether my changes are covered by system tests - [ ] If yes, I ran all relevant system tests and ensured they passed before submitting this PR - [ ] I updated existing system tests and/or added new ones if needed to cover my changes - [ ] If I introduced a deprecation: - [ ] I followed the [Deprecation Guidelines](./DEPRECATION.md) - [ ] I updated the relevant Jira ticket for documentation --- ### 🧪 Testing - Unit tests updated to cover the refactored validation logic - Tests verify token filtering by authenticated user ID with the new `filter_by_authenticated_id` parameter --- ### 🔗 References - Ticket link: N/A - Related PR: #9154 --- ### 🚨 Breaking Changes? - [ ] Yes (explain below) - [x] No --- ### 🔍️ Additional Notes This is a code cleanup PR that consolidates duplicate validation logic introduced in #9154.
📝 Description
This update introduces the ability to filter secret tokens based on the authenticated user ID. The
load_and_prepare_secret_tokensfunction now accepts an optionalauth_user_idparameter, allowing for more granular control over which tokens are loaded.🛠️ Changes Made
load_and_prepare_secret_tokensto acceptauth_user_idand filter tokens accordingly.get_jwt_subjectto extract the 'sub' claim from JWT tokens.sync_secret_tokensfunction to utilize the authenticated user ID when loading secret tokens.✅ Checklist
🧪 Testing
with/without tokens belong to my user
🔗 References
🚨 Breaking Changes?
🔍️ Additional Notes