Renew failed: The client lacks sufficient authorization

My domain is: laurdan.co.uk

I ran this command: sudo certbot renew --dry-run

It produced this output:

Cert is due for renewal, auto-renewing...
Plugins selected: Authenticator webroot, Installer None
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for laurdan.co.uk
http-01 challenge for www.laurdan.co.uk
Waiting for verification...
Cleaning up challenges
Attempting to renew cert (laurdan.co.uk) from /etc/letsencrypt/renewal/laurdan.co.uk.conf produced an unexpected error: Failed authorization procedure. www.laurdan.co.uk (http-01): urn:ietf:params:acme:error:unauthorized :: The client lacks sufficient authorization :: Invalid response from https://www.laurdan.co.uk/.well-known/acme-challenge/RUOYuaAhD450S7RCYoMPYAgHL3vV7g7wSUlY5ajfRec [46.101.88.208]: "<!doctype html>\n<html lang=\"en\">\n\n<head>\n    <meta charset=\"UTF-8\">\n    <meta name=\"viewport\" content=\"width=device-width, user-", laurdan.co.uk (http-01): urn:ietf:params:acme:error:unauthorized :: The client lacks sufficient authorization :: Invalid response from https://laurdan.co.uk/.well-known/acme-challenge/zwtEMGKgw9jkVuRnB9qHV-yUNkz_hepwqyQLdvAQhuw [46.101.88.208]: "<!doctype html>\n<html lang=\"en\">\n\n<head>\n    <meta charset=\"UTF-8\">\n    <meta name=\"viewport\" content=\"width=device-width, user-". Skipping.
All renewal attempts failed. The following certs could not be renewed:
  /etc/letsencrypt/live/laurdan.co.uk/fullchain.pem (failure)

My web server is (include version): Nginx 1.15.5

The operating system my web server runs on is (include version): Ubuntu 16.04

My hosting provider, if applicable, is: DigitalOcean

I can login to a root shell on my machine (yes or no, or I don’t know): Yes

I’m using a control panel to manage my site (no, or provide the name and version of the control panel): No

The version of my client is (e.g. output of certbot --version or certbot-auto --version if you’re using Certbot): certbot 0.26.1

Hi @damianlewis

you use the webroot authenticator:

If that doesn't work, your webroot may be wrong.

What's the content of your config file:

/etc/letsencrypt/renewal

What says

nginx -T

Your main configuration looks ok ( https://check-your-website.server-daten.de/?q=laurdan.co.uk ):

Domainname Http-Status redirect Sec. G
http://laurdan.co.uk/
46.101.88.208 301 https://laurdan.co.uk/ 0.047 A
http://www.laurdan.co.uk/
46.101.88.208 301 https://www.laurdan.co.uk/ 0.063 A
https://laurdan.co.uk/
46.101.88.208 200 3.767 N
Certificate error: RemoteCertificateChainErrors
https://www.laurdan.co.uk/
46.101.88.208 200 3.390 N
Certificate error: RemoteCertificateChainErrors
http://laurdan.co.uk/.well-known/acme-challenge/check-your-website-dot-server-daten-dot-de
46.101.88.208 301 https://laurdan.co.uk/.well-known/acme-challenge/check-your-website-dot-server-daten-dot-de 0.063 A
Visible Content: 301 Moved Permanently nginx/1.15.5
http://www.laurdan.co.uk/.well-known/acme-challenge/check-your-website-dot-server-daten-dot-de
46.101.88.208 301 https://www.laurdan.co.uk/.well-known/acme-challenge/check-your-website-dot-server-daten-dot-de 0.064 A
Visible Content: 301 Moved Permanently nginx/1.15.5
https://laurdan.co.uk/.well-known/acme-challenge/check-your-website-dot-server-daten-dot-de 404 3.296 N
Not Found
Certificate error: RemoteCertificateChainErrors
Visible Content:
https://www.laurdan.co.uk/.well-known/acme-challenge/check-your-website-dot-server-daten-dot-de 404 3.283 N
Not Found
Certificate error: RemoteCertificateChainErrors

But you have a redirect http -> https. So you have to use the https - webroot.

Nginx’s error.log will likely also show where it’s looking for the file.

# renew_before_expiry = 30 days
version = 0.26.1
archive_dir = /etc/letsencrypt/archive/laurdan.co.uk
cert = /etc/letsencrypt/live/laurdan.co.uk/cert.pem
privkey = /etc/letsencrypt/live/laurdan.co.uk/privkey.pem
chain = /etc/letsencrypt/live/laurdan.co.uk/chain.pem
fullchain = /etc/letsencrypt/live/laurdan.co.uk/fullchain.pem

# Options used in the renewal process
[renewalparams]
authenticator = webroot
account = 6a30cd98d24f190491765affd7b57b03
server = https://acme-v02.api.letsencrypt.org/directory
[[webroot_map]]
laurdan.co.uk = /var/www/public
www.laurdan.co.uk = /var/www/public
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
# configuration file /etc/nginx/nginx.conf:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
	worker_connections 768;
	# multi_accept on;
}

http {

	##
	# Basic Settings
	##

	sendfile on;
	tcp_nopush on;
	tcp_nodelay on;
	keepalive_timeout 65;
	types_hash_max_size 2048;
	# server_tokens off;

	# server_names_hash_bucket_size 64;
	# server_name_in_redirect off;

	include /etc/nginx/mime.types;
	default_type application/octet-stream;

	##
	# SSL Settings
	##

	ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
	ssl_prefer_server_ciphers on;

	##
	# Logging Settings
	##

	access_log /var/log/nginx/access.log;
	error_log /var/log/nginx/error.log;

	##
	# Gzip Settings
	##

	gzip on;
	gzip_disable "msie6";

	# gzip_vary on;
	# gzip_proxied any;
	# gzip_comp_level 6;
	# gzip_buffers 16 8k;
	# gzip_http_version 1.1;
	# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

	##
	# Virtual Host Configs
	##

	include /etc/nginx/conf.d/*.conf;
	include /etc/nginx/sites-enabled/*;


        # List of bad user agents
        # Use within server section of site configuration
        include /etc/nginx/useragents.rules;
}


#mail {
#	# See sample authentication script at:
#	# http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
#	# auth_http localhost/auth.php;
#	# pop3_capabilities "TOP" "USER";
#	# imap_capabilities "IMAP4rev1" "UIDPLUS";
#
#	server {
#		listen     localhost:110;
#		protocol   pop3;
#		proxy      on;
#	}
#
#	server {
#		listen     localhost:143;
#		protocol   imap;
#		proxy      on;
#	}
#}

# configuration file /etc/nginx/modules-enabled/50-mod-http-auth-pam.conf:
load_module modules/ngx_http_auth_pam_module.so;

# configuration file /etc/nginx/modules-enabled/50-mod-http-dav-ext.conf:
load_module modules/ngx_http_dav_ext_module.so;

# configuration file /etc/nginx/modules-enabled/50-mod-http-echo.conf:
load_module modules/ngx_http_echo_module.so;

# configuration file /etc/nginx/modules-enabled/50-mod-http-geoip.conf:
load_module modules/ngx_http_geoip_module.so;

# configuration file /etc/nginx/modules-enabled/50-mod-http-image-filter.conf:
load_module modules/ngx_http_image_filter_module.so;

# configuration file /etc/nginx/modules-enabled/50-mod-http-subs-filter.conf:
load_module modules/ngx_http_subs_filter_module.so;

# configuration file /etc/nginx/modules-enabled/50-mod-http-upstream-fair.conf:
load_module modules/ngx_http_upstream_fair_module.so;

# configuration file /etc/nginx/modules-enabled/50-mod-http-xslt-filter.conf:
load_module modules/ngx_http_xslt_filter_module.so;

# configuration file /etc/nginx/modules-enabled/50-mod-mail.conf:
load_module modules/ngx_mail_module.so;

# configuration file /etc/nginx/modules-enabled/50-mod-stream.conf:
load_module modules/ngx_stream_module.so;

# configuration file /etc/nginx/mime.types:

types {
    text/html                             html htm shtml;
    text/css                              css;
    text/xml                              xml;
    image/gif                             gif;
    image/jpeg                            jpeg jpg;
    application/javascript                js;
    application/atom+xml                  atom;
    application/rss+xml                   rss;

    text/mathml                           mml;
    text/plain                            txt;
    text/vnd.sun.j2me.app-descriptor      jad;
    text/vnd.wap.wml                      wml;
    text/x-component                      htc;

    image/png                             png;
    image/tiff                            tif tiff;
    image/vnd.wap.wbmp                    wbmp;
    image/x-icon                          ico;
    image/x-jng                           jng;
    image/x-ms-bmp                        bmp;
    image/svg+xml                         svg svgz;
    image/webp                            webp;

    application/font-woff                 woff;
    application/java-archive              jar war ear;
    application/json                      json;
    application/mac-binhex40              hqx;
    application/msword                    doc;
    application/pdf                       pdf;
    application/postscript                ps eps ai;
    application/rtf                       rtf;
    application/vnd.apple.mpegurl         m3u8;
    application/vnd.ms-excel              xls;
    application/vnd.ms-fontobject         eot;
    application/vnd.ms-powerpoint         ppt;
    application/vnd.wap.wmlc              wmlc;
    application/vnd.google-earth.kml+xml  kml;
    application/vnd.google-earth.kmz      kmz;
    application/x-7z-compressed           7z;
    application/x-cocoa                   cco;
    application/x-java-archive-diff       jardiff;
    application/x-java-jnlp-file          jnlp;
    application/x-makeself                run;
    application/x-perl                    pl pm;
    application/x-pilot                   prc pdb;
    application/x-rar-compressed          rar;
    application/x-redhat-package-manager  rpm;
    application/x-sea                     sea;
    application/x-shockwave-flash         swf;
    application/x-stuffit                 sit;
    application/x-tcl                     tcl tk;
    application/x-x509-ca-cert            der pem crt;
    application/x-xpinstall               xpi;
    application/xhtml+xml                 xhtml;
    application/xspf+xml                  xspf;
    application/zip                       zip;

    application/octet-stream              bin exe dll;
    application/octet-stream              deb;
    application/octet-stream              dmg;
    application/octet-stream              iso img;
    application/octet-stream              msi msp msm;

    application/vnd.openxmlformats-officedocument.wordprocessingml.document    docx;
    application/vnd.openxmlformats-officedocument.spreadsheetml.sheet          xlsx;
    application/vnd.openxmlformats-officedocument.presentationml.presentation  pptx;

    audio/midi                            mid midi kar;
    audio/mpeg                            mp3;
    audio/ogg                             ogg;
    audio/x-m4a                           m4a;
    audio/x-realaudio                     ra;

    video/3gpp                            3gpp 3gp;
    video/mp2t                            ts;
    video/mp4                             mp4;
    video/mpeg                            mpeg mpg;
    video/quicktime                       mov;
    video/webm                            webm;
    video/x-flv                           flv;
    video/x-m4v                           m4v;
    video/x-mng                           mng;
    video/x-ms-asf                        asx asf;
    video/x-ms-wmv                        wmv;
    video/x-msvideo                       avi;
}

# configuration file /etc/nginx/sites-enabled/laurdan.co.uk:
# laurdan.co.uk server configuration
#
# Redirect non SSL traffic (port 80) to SSL (port 443)
server {
	listen 80 default_server;
	listen [::]:80 default_server;

	server_name laurdan.co.uk www.laurdan.co.uk;

	if ($badagent) {
            return 444;
        }

	if ($request_method !~ ^(GET|POST)$ ) {
            return 444;
        }

	return 301 https://$host$request_uri;
}

server {
        listen 443 ssl default_server;
        listen [::]:443 ssl default_server;

        if ($badagent) {
            return 444;
        }

        if ($request_method !~ ^(GET|POST)$ ) {
            return 444;
        }

        ssl_certificate	/etc/letsencrypt/live/laurdan.co.uk/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/laurdan.co.uk/privkey.pem;

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

        ssl_ciphers ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS;
        ssl_prefer_server_ciphers on;

        ssl_session_cache shared:SSL:10m; # a 1mb cache can hold about 4000 sessions, so we can hold 40000 sessions
        ssl_session_timeout 24h;

        # Use a higher keepalive timeout to reduce the need for repeated handshakes
        keepalive_timeout 300; # up from 75 secs default

        add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload;";
        add_header X-Frame-Options DENY;
        add_header X-Content-Type-Options nosniff;
        add_header X-XSS-Protection "1; mode=block";
        add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://www.google-analytics.com https://cdnjs.cloudflare.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com https://cdnjs.cloudflare.com; img-src 'self' data: https://www.google-analytics.com https://cdnjs.cloudflare.com https://www.gravatar.com; font-src 'self' https://fonts.gstatic.com";

	root /var/www/public;

	charset utf-8;
	index index.html index.htm index.php;

	client_max_body_size 16M;

	location / {
		# Let OctoberCMS handle everything by default.
		# The path not resolved by OctoberCMS router will return OctoberCMS's 404 page.
    		# Everything that does not match with the whitelist below will fall into this.
    		rewrite ^/.*$ /index.php last;
	}

	location ~ ^/index.php {
		include snippets/fastcgi-php.conf;
		fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
	}

	# Whitelist
	## Let October handle if static file not exists
	location ~ ^/favicon\.ico { try_files $uri /index.php; }
	location ~ ^/sitemap\.xml { try_files $uri /index.php; }
	location ~ ^/robots\.txt { try_files $uri /index.php; }
	location ~ ^/humans\.txt { try_files $uri /index.php; }

	## Let nginx return 404 if static file not exists
	location ~ ^/storage/app/uploads/public { try_files $uri 404; }
	location ~ ^/storage/app/media { try_files $uri 404; }
	location ~ ^/storage/temp/public { try_files $uri 404; }

	location ~ ^/modules/.*/assets { try_files $uri 404; }
	location ~ ^/modules/.*/resources { try_files $uri 404; }
	location ~ ^/modules/.*/behaviors/.*/assets { try_files $uri 404; }
	location ~ ^/modules/.*/behaviors/.*/resources { try_files $uri 404; }
	location ~ ^/modules/.*/widgets/.*/assets { try_files $uri 404; }
	location ~ ^/modules/.*/widgets/.*/resources { try_files $uri 404; }
	location ~ ^/modules/.*/formwidgets/.*/assets { try_files $uri 404; }
	location ~ ^/modules/.*/formwidgets/.*/resources { try_files $uri 404; }
	location ~ ^/modules/.*/reportwidgets/.*/assets { try_files $uri 404; }
	location ~ ^/modules/.*/reportwidgets/.*/resources { try_files $uri 404; }

	location ~ ^/plugins/.*/.*/assets { try_files $uri 404; }
	location ~ ^/plugins/.*/.*/resources { try_files $uri 404; }
	location ~ ^/plugins/.*/.*/behaviors/.*/assets { try_files $uri 404; }
	location ~ ^/plugins/.*/.*/behaviors/.*/resources { try_files $uri 404; }
	location ~ ^/plugins/.*/.*/reportwidgets/.*/assets { try_files $uri 404; }
	location ~ ^/plugins/.*/.*/reportwidgets/.*/resources { try_files $uri 404; }
	location ~ ^/plugins/.*/.*/formwidgets/.*/assets { try_files $uri 404; }
	location ~ ^/plugins/.*/.*/formwidgets/.*/resources { try_files $uri 404; }
	location ~ ^/plugins/.*/.*/widgets/.*/assets { try_files $uri 404; }
	location ~ ^/plugins/.*/.*/widgets/.*/resources { try_files $uri 404; }

	location ~ ^/themes/.*/assets { try_files $uri 404; }
	location ~ ^/themes/.*/resources { try_files $uri 404; }
}

# configuration file /etc/nginx/snippets/fastcgi-php.conf:
# regex to split $uri to $fastcgi_script_name and $fastcgi_path
fastcgi_split_path_info ^(.+\.php)(/.+)$;

# Check that the PHP script exists before passing it
try_files $fastcgi_script_name =404;

# Bypass the fact that try_files resets $fastcgi_path_info
# see: http://trac.nginx.org/nginx/ticket/321
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;

fastcgi_index index.php;
include fastcgi.conf;

# configuration file /etc/nginx/fastcgi.conf:

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  REQUEST_SCHEME     $scheme;
fastcgi_param  HTTPS              $https if_not_empty;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

# configuration file /etc/nginx/useragents.rules:
map $http_user_agent $badagent {
        default         0;
        ~Jorgee         1;
        ~Wget           1;
        ~ZmEu           1;
}

The first row

looks good, so you use the correct webroot.

But your location definition looks like all is managed by the /index.php. That can't work with the validation file.

Create the two subdirectories

/var/www/public/.well-known/acme-challenge

there a file (file name 1234), then try to load that file via

https://www.laurdan.co.uk/.well-known/acme-challenge/1234

and recheck the complete folder + file with the online tool.

That

may be an additional problem.

The HTTP server block redirects to HTTPS.

The HTTPS server block handles certain static files in Nginx – a long list of regular expression location blocks – and passes everything else to the CMS.

^/\.well-known/acme-challenge/ isn’t in the list.

You should exclude /.well-known/acme-challenge/ from the redirect, or add it to the list of static directories.

(Or reorganize everything.)

What online tool are you referring to?

Should have mentioned that the site has been using this certificate for over 2 years without any issues. Any reason why it’s stopped renewing?

Best guess is that something changed with the Nginx configuration or the web application.

Fixed the issue by adding the following to the nginx config just before the location / {...} block:

location ^~ /.well-known/acme-challenge/ {
    allow all;
    default_type "text/plain";
}

location = /.well-known/acme-challenge/ {
    return 404;
}

Not sure why this hasn’t caused an issue before.

Thanks for all your help

2 Likes

Already shared - Renew failed: The client lacks sufficient authorization - #2 by JuergenAuer

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.