cybercinch / certbot-dns-directadmin

certbot plugin to allow acme dns-01 authentication of a name managed in DirectAdmin
Other
9 stars 5 forks source link

UnboundLocalError: local variable 'directadmin_name' referenced before assignment #10

Closed ralvaradof closed 1 year ago

ralvaradof commented 1 year ago

Hi!

I'm getting the following error with the plugin, can you help me with this, thanks!

Encountered exception during recovery: UnboundLocalError: local variable 'directadmin_name' referenced before assignment An unexpected error occurred: UnboundLocalError: local variable 'directadmin_name' referenced before assignment

2022-12-09 00:15:28,195:DEBUG:certbot._internal.error_handler:Encountered exception:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/certbot/_internal/auth_handler.py", line 70, in handle_authorizations
    resps = self.auth.perform(achalls)
  File "/usr/lib/python3/dist-packages/certbot/plugins/dns_common.py", line 57, in perform
    self._perform(domain, validation_domain_name, validation)
  File "/usr/local/lib/python3.9/dist-packages/certbot_dns_directadmin/dns_directadmin.py", line 56, in _perform
    self._get_directadmin_client().add_txt_record(validation_domain_name, validation)
  File "/usr/local/lib/python3.9/dist-packages/certbot_dns_directadmin/dns_directadmin.py", line 82, in add_txt_record
    (directadmin_zone, directadmin_name) = self._get_zone_and_name(record_name)
  File "/usr/local/lib/python3.9/dist-packages/certbot_dns_directadmin/dns_directadmin.py", line 126, in _get_zone_and_name
    logger.debug('Subdomain: ' + directadmin_name)
UnboundLocalError: local variable 'directadmin_name' referenced before assignment

2022-12-09 00:15:28,195:DEBUG:certbot._internal.error_handler:Calling registered functions
2022-12-09 00:15:28,195:INFO:certbot._internal.auth_handler:Cleaning up challenges
2022-12-09 00:15:28,229:DEBUG:certbot_dns_directadmin.dns_directadmin:Record Domain: _acme-challenge.mydomain.com
2022-12-09 00:15:28,230:ERROR:certbot._internal.error_handler:Encountered exception during recovery: UnboundLocalError: local variable 'directadmin_name' referenced before assignment
2022-12-09 00:15:28,230:DEBUG:certbot._internal.log:Exiting abnormally:
Traceback (most recent call last):
  File "/usr/bin/certbot", line 33, in <module>
    sys.exit(load_entry_point('certbot==1.12.0', 'console_scripts', 'certbot')())
  File "/usr/lib/python3/dist-packages/certbot/main.py", line 15, in main
    return internal_main.main(cli_args)
  File "/usr/lib/python3/dist-packages/certbot/_internal/main.py", line 1413, in main
    return config.func(config, plugins)
  File "/usr/lib/python3/dist-packages/certbot/_internal/main.py", line 1293, in certonly
    lineage = _get_and_save_cert(le_client, config, domains, certname, lineage)
  File "/usr/lib/python3/dist-packages/certbot/_internal/main.py", line 134, in _get_and_save_cert
    lineage = le_client.obtain_and_enroll_certificate(domains, certname)
  File "/usr/lib/python3/dist-packages/certbot/_internal/client.py", line 441, in obtain_and_enroll_certificate
    cert, chain, key, _ = self.obtain_certificate(domains)
  File "/usr/lib/python3/dist-packages/certbot/_internal/client.py", line 374, in obtain_certificate
    orderr = self._get_order_and_authorizations(csr.data, self.config.allow_subset_of_names)
  File "/usr/lib/python3/dist-packages/certbot/_internal/client.py", line 421, in _get_order_and_authorizations
    authzr = self.auth_handler.handle_authorizations(orderr, best_effort)
  File "/usr/lib/python3/dist-packages/certbot/_internal/auth_handler.py", line 70, in handle_authorizations
    resps = self.auth.perform(achalls)
  File "/usr/lib/python3/dist-packages/certbot/plugins/dns_common.py", line 57, in perform
    self._perform(domain, validation_domain_name, validation)
  File "/usr/local/lib/python3.9/dist-packages/certbot_dns_directadmin/dns_directadmin.py", line 56, in _perform
    self._get_directadmin_client().add_txt_record(validation_domain_name, validation)
  File "/usr/local/lib/python3.9/dist-packages/certbot_dns_directadmin/dns_directadmin.py", line 82, in add_txt_record
    (directadmin_zone, directadmin_name) = self._get_zone_and_name(record_name)
  File "/usr/local/lib/python3.9/dist-packages/certbot_dns_directadmin/dns_directadmin.py", line 126, in _get_zone_and_name
    logger.debug('Subdomain: ' + directadmin_name)
UnboundLocalError: local variable 'directadmin_name' referenced before assignment
2022-12-09 00:15:28,231:ERROR:certbot._internal.log:An unexpected error occurred:
2022-12-09 00:15:28,231:ERROR:certbot._internal.log:UnboundLocalError: local variable 'directadmin_name' referenced before assignment
guisea commented 1 year ago

Thanks for reporting this. Currently investing time on unit tests to nail this down. Should have it fixed and new version published correcting the issue tomorrow sometime. p.s. In tracing the code it is often because your credentials are invalid so might be a place to start.

Will also be dropping some additional debug info to make troubleshooting easier.

guisea commented 1 year ago

Hi @ralvaradof @nemchik this issue is now resolved. New version 1.0.3 is available on pypi

pip install --upgrade certbot-dns-directadmin

This has been a work of much improvement to align closer to internal certbot plugins.

nemchik commented 1 year ago

Sounds amazing! I'll ask the original user who reported https://github.com/linuxserver/docker-swag/issues/307 to test after I push a build with your new version tomorrow. It looks like I'll also be able to roll in some changes to align usage of this plugin with the rest of the other certbot plugins. I'll report back if I have any issues. Thanks!

nemchik commented 1 year ago

@guisea just an FYI, your new changes are perfect and working correctly, but your documentation now needs to be updated.

For CLI arguments, previously I was using:

--authenticator directadmin
--directadmin-credentials /path/to/directadmin.ini

Now I have to use (dns- prefix):

--authenticator dns-directadmin
--dns-directadmin-credentials /path/to/directadmin.ini

Also, in the ini file, previously I was using

directadmin_url = https://my.directadminserver.com:2222
directadmin_username = username
directadmin_password = aSuperStrongPassword

Now I have to use (dns_ prefix):

dns_directadmin_url = https://my.directadminserver.com:2222
dns_directadmin_username = username
dns_directadmin_password = aSuperStrongPassword

These changes are great because they bring your plugin in-line with how the official plugins use CLI arguments and ini values, so it should just be a matter of updating your docs to reflect these new changes.

guisea commented 1 year ago

That is odd,  when running my end to end test via my docker container I do not have to prefix the variables like that.

It works exactly as per the documentation.

Weird On 15 Dec 2022 at 3:26 AM +1300, Eric Nemchik @.***>, wrote:

@guisea just an FYI, your new changes are perfect and working correctly, but your documentation now needs to be updated. For CLI arguments, previously I was using: --authenticator directadmin --directadmin-credentials /path/to/directadmin.ini Now I have to use (dns- prefix): --authenticator dns-directadmin --dns-directadmin-credentials /path/to/directadmin.ini Also, in the ini file, previously I was using directadmin_url = https://my.directadminserver.com:2222 directadmin_username = username directadminpassword = aSuperStrongPassword Now I have to use (dns prefix): dns_directadmin_url = https://my.directadminserver.com:2222 dns_directadmin_username = username dns_directadmin_password = aSuperStrongPassword These changes are great because they bring your plugin in-line with how the official plugins use CLI arguments and ini values, so it should just be a matter of updating your docs to reflect these new changes. — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

guisea commented 1 year ago

Further research @nemchik ,

I have found that there is a version discrepancy between the certbot running in swag container vs the latest one which is what the docs cover.

    swag:
    root@9b75a0525e44:/# certbot --version
    certbot 1.32.0
    cybercinch/certbot-dns-directadmin:
    /opt/certbot # certbot --version
    certbot 2.1.0

I removed the dns_ prefix from the docs as is no longer required in upstream versions.

nemchik commented 1 year ago

Indeed. Swag cannot update certbot until all plugins we package support 2.x. Currently I believe we're waiting on the ghandi plugin.

guisea commented 1 year ago

Cool,  I only generally keep the documentation for current certbot supported.

I might consider time permitting putting a note on the docs for the configuration on certbot < 2.x

But time is slim on the ground atm On 15 Dec 2022 at 8:01 AM +1300, Eric Nemchik @.***>, wrote:

Indeed. Swag cannot update certbot until all plugins we package support 2.x. Currently I believe we're waiting on the ghandi plugin. — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

nemchik commented 1 year ago

No worries. I was unaware certbot 2.x allowed the syntax you have in your documentation.

p.s. that syntax (without the prefixes) might still work with 1.x but may require a different combination of cli flag usage and/or ini file variables. I have only recently (while investigating 2.0 and 2.1) found the dns prefixes to be near universally adopted by most plugins (1st party and 3rd party). Either way the dns prefixed syntax seems to work in all cases in my early testing.

guisea commented 1 year ago

Closing issue as now working as at 1.0.3.