feat: add ALLOW_SUPPORT_LOGIN to Dockerfile - #7399
Conversation
There was a problem hiding this comment.
Currently1, the security of this approach heavily relies on the SECRET_KEY to be kept a secret.
If the SECRET_KEY is leaked, a malicious user could very easily compromise any user account on the system at any time without having to use the python manage.py support_login command.
In the internal Specify Vault, I've put a video demonstrating exploiting this vulnerability: https://drive.google.com/file/d/1P7zpPiUAxYQnSvhzfXn4UyJ3UkJPpi3h/view?usp=sharing
I know the SECRET_KEY should be kept secret, but this presents a major risk to institutions.
There might be other ways to accomplish this, but I think we can make this more secure by adding a psuedo one-time salt/pad argument to the manage.py support_login command (or we can generate a key for the user at the time they run the command).
We can then hash the token with this generated or provided key.
The user-provided or generated key would then need to be provided when logging in via the /accounts/support_login endpoint.
That way, a malicious agent would require both the SECRET_KEY and the key generated (or provided) when running the support_login command to accomplish the exploit.
I can make the changes to this PR if needed.
On a couple much smaller notes:
Can we remove the following line? 😅
Or add a comment linking to documentation.
Also, there's another option that's currently accepted by the manage.py support_login command: --list!
specify7/specifyweb/specify/management/commands/support_login.py
Lines 20 to 26 in b45cef2
It lists out all of the users, their user types, and whether they are a Specify 6 admin or not:
The output isn't very clean imo, and there's no way to view Specify 7 admins, so I'd be down to remove the option or clean it up and extend it!
Footnotes
-
This is not related to the changes in this PR, but with how the feature was initially implemented ↩
Triggered by 2d91cbd on branch refs/heads/issue-7398
|
This is ready for review and testing! I've made a number of improvements behind the scenes and have hopefully made this feature a little more secure. Redis Primarily we are utilizing redis as an in-memory cache to store information required to process a support login attempt.
More Specify-specific applications might include:
Cryptography Put simply, the support login process is now as follows: Currently, a symmetric encryption algorithm is used (AES-GCM with a randomly generated 256 bit key and 256 bit salt) to handle encryption and decryption. Token Generation/Encryption:
Token Parsing/Decryption:
Let me know if you have any ideas about this current implementation and setup! I'm considering using an asymmetric algorithm to handle encryption/decrpytion (the current implementation kind of follows the asymmetric approach anyways), although finding a way to secure a generated private key is notably difficult (and it may not be worth the potential performance hit). Further Improvements If we wish to make this more secure, I would suggest prompting the user for a one-time password - or generate a password for the user and write it to stdout - which will act as the key, and would be used for encryption when they are generating a token. The difference with the current implementation is that the private keys used for cryptography and verification will be strictly separated from the structure of the endpoint: they will only exist while the required message is being encrypted / decrypted after having been obtained by the user. Previously, a malicious agent really only needed to know the SECRET_KEY to compromise any SpecifyUser account. Now, the goal is that each of the following must hold true for a malicious agent to compromise a SpecifyUser account:
As such, a system administrator should generally follow the following steps to secure their instance:
|
️✅ There are no secrets present in this pull request anymore.If these secrets were true positive and are still valid, we highly recommend you to revoke them. 🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request. |
Triggered by 83aa9c2 on branch refs/heads/issue-7398
|
@melton-jason Consider this my testing approval ✅ It works as expected and I love it! |
Triggered by 9c0238d on branch refs/heads/issue-7398
Fixes #7398
Checklist
self-explanatory (or properly documented)
Testing instructions
https://discourse.specifysoftware.org/t/allow-support-login-documentation/2838/1
In your
.envfile, add the following:Usage steps:
docker exec -it specify7 /bin/bashve/bin/python manage.py support_login --username ${username}${username}with the desired account.SUPPORT_LOGIN_TTLenvironment variable (e.g., 300 seconds).Example output:
base_url+/accounts/support_login/?token=...to access the user's account.