Skip to content

acme.cert state falsely reports about renewed certificate #42763

Closed

Description

@xuhcc

Description of Issue/Question

Execution of salt.states.acme.cert with renew parameter always reports about renewed certificate, even when certificate is not changed:

          ID: my_cert
    Function: acme.cert
        Name: domain.tld
      Result: True
     Comment: Certificate domain.tld renewed.
     Started: 17:38:31.068335
    Duration: 6203.158 ms
     Changes:   
              ----------
              new:
                  ----------
                  ...
                  not_after:
                      1509594480
                  not_before:
                      1501818480
                  ...
              old:
                  ----------
                  ...
                  not_after:
                      1509594480
                  not_before:
                      1501818480
                  ...

Setup

my_cert:
  acme.cert:
    - name: domain.tld
    - email: [email protected]
    - webroot: /var/lib/letsencrypt/
    - renew: 20

Versions Report

$ salt-ssh --versions-report
Salt Version:
           Salt: 2017.7.0
 
Dependency Versions:
           cffi: 1.10.0
       cherrypy: 8.9.1
       dateutil: 2.6.1
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.9.6
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: 0.26.0
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.8
   mysql-python: Not Installed
      pycparser: 2.18
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.13 (default, Jul 21 2017, 03:24:34)
   python-gnupg: Not Installed
         PyYAML: 3.12
          PyZMQ: 16.0.2
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.5.1
            ZMQ: 4.2.2
 
System Versions:
           dist:   
         locale: UTF-8
        machine: x86_64
        release: 4.12.3-1-ARCH
         system: Linux
        version: Not Installed

Activity

  1. Ch3LL commented on Aug 8, 2017

    @Ch3LL
    Contributor

    Seems the acme state module it checks to see res['result'] is None here

    Seems your result is returning True if you look at the module here you can see it returns True if it was able to check the perms of the cert file correctly.

    I'm guessing this state would always return changes regardless of having renew set or not. Seems we need to add some more logic here

  2. added
    bug
    severity-medium
    P3
    RIoT
    on Aug 8, 2017
  3. added this to the Approved milestone on Aug 8, 2017
  4. oarmstrong commented on Nov 20, 2017

    @oarmstrong
    Contributor

    I hit this and as it seems to have been silent for some time I'm looking at it now. I'll update this comment with findings as I go to prevent multiple notifications going out.


    I believe the issue to be here, as the certbot command is run with the --quiet argument there never is any stdout. Presumably with the correct set of arguments we would be able to see this output and thus determine whether the run actually did anything.


    Looks like bf8f373 is the commit that added --quiet. I'll try using the --non-interactive option instead which should also have the same effect that that commit had.


    0e99a59 has already resolved this. It doesn't appear to be released though despite being before the 2017.7.2 tag? There is still, however, a related issue about running this state in test mode that it always returns as unchanged.

  5. oarmstrong commented on Nov 20, 2017

    @oarmstrong
    Contributor

    That above PR fixes the issue I mentioned in my final comment above. It does not close this issue.

    However, the commit 0e99a59 does appear to fix this issue and as such it can probably be closed.

  6. Ch3LL commented on Nov 22, 2017

    @Ch3LL
    Contributor

    ping @xuhcc can you give that a try and report back?

  7. xuhcc commented on Nov 22, 2017

    @xuhcc
    ContributorAuthor

    @Ch3LL

    Latest salt is throwning error during execution:

    Certificate mydomain renewal failed with:
    Saving debug log to /var/log/letsencrypt/letsencrypt.log
    Plugins selected: Authenticator webroot, Installer None
    Cert not yet due for renewal
    An unexpected error occurred:
    Please see the logfiles in /var/log/letsencrypt for more details.
    

    I tried to reconstruct the exact command and found that certbot asks for user input and this causes a salt failure (after 0e99a59):

    Cert not yet due for renewal
    You have an existing certificate that has exactly the same domains or certificate name you requested and isn't close to expiry.
    What would you like to do?
    -------------------------------------------------------------------------------
    1: Keep the existing certificate for now
    2: Renew & replace the cert (limit ~5 per 7 days)
    -------------------------------------------------------------------------------
    Select the appropriate number [1-2] then [enter] (press 'c' to cancel):
    

    I think that --non-interactive flag should be used as @oarmstrong suggested.

  8. oarmstrong commented on Nov 23, 2017

    @oarmstrong
    Contributor

    For some reason it was definitely the addition of --quiet which caused this issue and the commit that reverted that resolved this for me. I do agree though that adding --non-interactive is probably a decent safety as there's no reason we should ever be in an interactive mode.

    The only concern is if --non-interactive selects a particular option for these prompt by default instead of exiting. I'm concerned by adding the flag we may be changing functionality in more ways than I'd be able to test in a reasonable time period.

    But, I definitely don't hit this after my patch, even without that extra flag and an identical state. There may be something deeper at work here.


    Edit: fuck. I checked out my source and I was using --non-interactive, which I must have added during my testing at some point. Well I'll send a PR with that patch and we'll see what the maintainers make of whether it has too much potential for regressions.

  9. oarmstrong commented on Nov 23, 2017

    @oarmstrong
    Contributor

    @xuhcc can you test with my patch? My fork is at https://github.com/oarmstrong/salt if you want to just pull that.

  10. xuhcc commented on Nov 25, 2017

    @xuhcc
    ContributorAuthor

    @oarmstrong

    Thanks! Now certificate renewal works as expected.

  11. added a commit that references this issue on Nov 28, 2017
    3d85a26
  12. xuhcc commented on Oct 27, 2018

    @xuhcc
    ContributorAuthor

    The problem appeared again in 2018.3.3.

  13. Ch3LL commented on Oct 30, 2018

    @Ch3LL
    Contributor

    @xuhcc can you please open a new issues with the details of the issue

  14. xuhcc commented on Oct 30, 2018

    @xuhcc
    ContributorAuthor

    Done #50310

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3RIoTState-Modulebugseverity-medium

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions