User key not saved #1782

Closed
opened 2025-12-29 17:19:03 +01:00 by adam · 2 comments
Owner

Originally created by @aventrax on GitHub (Jun 11, 2018).

Issue type

[ ] Feature request
[x] Bug report
[ ] Documentation

Environment

  • Ubuntu 18.04 LTS
  • Django 1.11
  • Python version: 3.6.5
  • NetBox version: 2.3.4

Description

First, many thanks because this is an awesome project, nothing I could desire is missing from it!

Anyway. I have a small issue.

I just installed netbox on a newly Ubuntu 18.04 LTS virtual machine, following the guide on https://netbox.readthedocs.io/en/latest/, and everything has gone well, even the LDAP integration.

The problem arised testing the app (in Django terms) "secrets", particulary when I try to generate the first key, it does correctly and I save it on my pc. Then i confirm it pushing the red button "I have saved my new private key" and finally I clicked on "Save", the request arrives to my server (nginx->uwsgi but I tried also with the django integrated server with the same result), but it do not seems to save anything, indeed I haven't any "confirmation" about it. Browsing away and returning on my profile, I see the message "You don't have a user key on file.". So something went wrong with the saving of my key.

Anyway, nothing on the log files except the http requests:

"GET /user/password/ HTTP/1.1" 200 30603
"GET /user/user-key/ HTTP/1.1" 200 29068
"GET /user/user-key/edit/ HTTP/1.1" 200 31412
"GET /api/secrets/generate-rsa-key-pair/ HTTP/1.1" 200 2192
"POST /user/user-key/edit/ HTTP/1.1" 200 31870

Here we are. No erros but key not saved. No logs except this one.

Any help would be very appreciated.

Originally created by @aventrax on GitHub (Jun 11, 2018). <!-- Before opening a new issue, please search through the existing issues to see if your topic has already been addressed. Note that you may need to remove the "is:open" filter from the search bar to include closed issues. Check the appropriate type for your issue below by placing an x between the brackets. For assistance with installation issues, or for any other issues other than those listed below, please raise your topic for discussion on our mailing list: https://groups.google.com/forum/#!forum/netbox-discuss Please note that issues which do not fall under any of the below categories will be closed. Due to an excessive backlog of feature requests, we are not currently accepting any proposals which extend NetBox's feature scope. Do not prepend any sort of tag to your issue's title. An administrator will review your issue and assign labels as appropriate. ---> ### Issue type [ ] Feature request <!-- An enhancement of existing functionality --> [x] Bug report <!-- Unexpected or erroneous behavior --> [ ] Documentation <!-- A modification to the documentation --> <!-- Please describe the environment in which you are running NetBox. (Be sure to verify that you are running the latest stable release of NetBox before submitting a bug report.) If you are submitting a bug report and have made any changes to the code base, please first validate that your bug can be recreated while running an official release. --> ### Environment * Ubuntu 18.04 LTS * Django 1.11 * Python version: 3.6.5 * NetBox version: 2.3.4 <!-- BUG REPORTS must include: * A list of the steps needed for someone else to reproduce the bug * A description of the expected and observed behavior * Any relevant error messages (screenshots may also help) FEATURE REQUESTS must include: * A detailed description of the proposed functionality * A use case for the new feature * A rough description of any necessary changes to the database schema * Any relevant third-party libraries which would be needed --> ### Description First, many thanks because this is an awesome project, nothing I could desire is missing from it! Anyway. I have a small issue. I just installed netbox on a newly Ubuntu 18.04 LTS virtual machine, following the guide on https://netbox.readthedocs.io/en/latest/, and everything has gone well, even the LDAP integration. The problem arised testing the app (in Django terms) "secrets", particulary when I try to generate the first key, it does correctly and I save it on my pc. Then i confirm it pushing the red button "I have saved my new private key" and finally I clicked on "Save", the request arrives to my server (nginx->uwsgi but I tried also with the django integrated server with the same result), but it do not seems to save anything, indeed I haven't any "confirmation" about it. Browsing away and returning on my profile, I see the message "You don't have a user key on file.". So something went wrong with the saving of my key. Anyway, nothing on the log files except the http requests: "GET /user/password/ HTTP/1.1" 200 30603 "GET /user/user-key/ HTTP/1.1" 200 29068 "GET /user/user-key/edit/ HTTP/1.1" 200 31412 "GET /api/secrets/generate-rsa-key-pair/ HTTP/1.1" 200 2192 "POST /user/user-key/edit/ HTTP/1.1" 200 31870 Here we are. No erros but key not saved. No logs except this one. Any help would be very appreciated.
adam closed this issue 2025-12-29 17:19:03 +01:00
Author
Owner

@aventrax commented on GitHub (Jun 12, 2018):

netbox/users/views.py, class UserKeyEditView(View), method post (line 151):

def post(self, request): form = UserKeyForm(data=request.POST, instance=self.userkey) if form.is_valid(): uk = form.save(commit=False) uk.user = request.user uk.save() messages.success(request, "Your user key has been saved.") return redirect('user:userkey')

I noticed form.is_valid() returns False, so the next code is never executed.
I tried to print out form.errors and it showed this message:
__all__ Something went wrong while trying to save your key. Please ensure that you're uploading a valid RSA public key in PEM format (no SSH/PGP).

I tried to understand what is done by UserKeyForm on netbox/secrets/forms.py but I can't understand it. Can you help me? I tried with auto generated keys and also with RSA keys generated by me. No luck.

@aventrax commented on GitHub (Jun 12, 2018): netbox/users/views.py, class UserKeyEditView(View), method post (line 151): ` def post(self, request): form = UserKeyForm(data=request.POST, instance=self.userkey) if form.is_valid(): uk = form.save(commit=False) uk.user = request.user uk.save() messages.success(request, "Your user key has been saved.") return redirect('user:userkey') ` I noticed form.is_valid() returns False, so the next code is never executed. I tried to print out form.errors and it showed this message: ` __all__ Something went wrong while trying to save your key. Please ensure that you're uploading a valid RSA public key in PEM format (no SSH/PGP).` I tried to understand what is done by UserKeyForm on netbox/secrets/forms.py but I can't understand it. Can you help me? I tried with auto generated keys and also with RSA keys generated by me. No luck.
Author
Owner

@aventrax commented on GitHub (Jun 12, 2018):

Solved. Totally my fault!

I had issues with pycryptodome on Ubuntu 18.04 LTS (pycryptodome Version: 3.4.7-1ubuntu1) but on requirements.txt the minimum version is 3.4.11.

Trying to manually import the key resulted in:

Traceback (most recent call last): File "test.py", line 13, in <module> pubkey = RSA.import_key(data['public_key'][0]) AttributeError: module 'Crypto.PublicKey.RSA' has no attribute 'import_key'

@aventrax commented on GitHub (Jun 12, 2018): Solved. Totally my fault! I had issues with pycryptodome on Ubuntu 18.04 LTS (pycryptodome Version: 3.4.7-1ubuntu1) but on requirements.txt the minimum version is 3.4.11. Trying to manually import the key resulted in: ` Traceback (most recent call last): File "test.py", line 13, in <module> pubkey = RSA.import_key(data['public_key'][0]) AttributeError: module 'Crypto.PublicKey.RSA' has no attribute 'import_key'`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#1782