- 
                Notifications
    
You must be signed in to change notification settings  - Fork 367
 
Upgrade Encryption: Argon2id KDF & Per-Record Salts #1373
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
          
     Open
      
      
            madhav165
  wants to merge
  13
  commits into
  main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
oauth-encrypt-minor-fix
  
      
      
   
  
    
  
  
  
 
  
      
    base: main
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          Conversation
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
    Signed-off-by: Madhav Kandukuri <[email protected]>
Signed-off-by: Madhav Kandukuri <[email protected]>
Signed-off-by: Madhav Kandukuri <[email protected]>
Signed-off-by: Madhav Kandukuri <[email protected]>
Signed-off-by: Madhav Kandukuri <[email protected]>
Signed-off-by: Madhav Kandukuri <[email protected]>
Signed-off-by: Madhav Kandukuri <[email protected]>
Signed-off-by: Madhav Kandukuri <[email protected]>
Signed-off-by: Madhav Kandukuri <[email protected]>
Signed-off-by: Madhav Kandukuri <[email protected]>
Signed-off-by: Madhav Kandukuri <[email protected]>
Signed-off-by: Madhav Kandukuri <[email protected]>
60b7516    to
    e6be950      
    Compare
  
    Signed-off-by: Madhav Kandukuri <[email protected]>
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
      
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
✨ Feature / Enhancement PR
🚀 Summary (1-2 sentences)
Migrated encryption logic from
mcpgateway/utils/oauth_encryption.pytomcpgateway/services/encryption_service.py, upgraded key derivation from PBKDF2-HMAC to Argon2id with a per-record random salt, refactoredsso_service.pyto use the new encryption service, removed the cached Fernet instance, and added an Alembic migration (with downgrade support) to re‑encrypt existing data.🧪 Checks
make lintpassesmake testpasses🔧 Detailed Changes
Relocation & Renaming
mcpgateway/utils/oauth_encryption.py➜mcpgateway/services/encryption_service.py.services/and clarifies usage scope beyond OAuth.Key Derivation: PBKDF2-HMAC ➜ Argon2id
Salt Strategy: Single Global Salt ➜ Per‑Record Random Salt
Runtime Change: Remove Cached Fernet Instance
Fernetobject is no longer valid. The service derives per‑record and encrypts/decrypts accordingly.SSO Service Refactor
mcpgateway/services/sso_service.pyto use the new centralizedEncryptionServiceinstead of its legacy inline encryption code.Database Migration (Alembic) – Re‑encrypt Existing Fields
Added a forward migration that reads legacy encrypted values, derives new Argon2id keys with per‑record salts, and writes back in the new format.
Includes a downgrade script that reverses the migration, re‑encrypting with the legacy PBKDF2-HMAC method for rollback safety.
Updated fields (by table):
gatewaysoauth_config.client_secretoauth_configis a dict; theclient_secretvalue is re‑encrypted.a2a_agentsoauth_config.client_secretgateways.oauth_tokensaccess_tokenoauth_tokensrefresh_tokenregistered_oauth_clientsclient_secret_encryptedregistered_oauth_clientsregistration_access_token_encryptedsso_providersclient_secret_encryptedCross‑DB Validation
📎 Notes & Compatibility
TEXT— ciphertext continues to be Base64‑encoded and safe forTEXT NOT NULLcolumns.✅ Outcome