From a285fe41296cf786b21f637ebe9e5f265eddaa8a Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Wed, 3 Jun 2020 09:59:36 -0600 Subject: [PATCH] caddypki: Add 'acme_server' Caddyfile directive --- caddyconfig/httpcaddyfile/directives.go | 3 +- modules/caddypki/acmeserver/acmeserver.go | 9 +++++- modules/caddypki/acmeserver/caddyfile.go | 38 +++++++++++++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 modules/caddypki/acmeserver/caddyfile.go diff --git a/caddyconfig/httpcaddyfile/directives.go b/caddyconfig/httpcaddyfile/directives.go index cde97438..c9f4ad96 100644 --- a/caddyconfig/httpcaddyfile/directives.go +++ b/caddyconfig/httpcaddyfile/directives.go @@ -56,14 +56,15 @@ var directiveOrder = []string{ // special routing directives "handle", - "route", "handle_path", + "route", // handlers that typically respond to requests "respond", "reverse_proxy", "php_fastcgi", "file_server", + "acme_server", } // directiveIsOrdered returns true if dir is diff --git a/modules/caddypki/acmeserver/acmeserver.go b/modules/caddypki/acmeserver/acmeserver.go index 8dc0f01b..6023e064 100644 --- a/modules/caddypki/acmeserver/acmeserver.go +++ b/modules/caddypki/acmeserver/acmeserver.go @@ -48,13 +48,20 @@ type Handler struct { // The hostname or IP address by which ACME clients // will access the server. This is used to populate // the ACME directory endpoint. Default: localhost. - // TODO: this is probably not needed - check with smallstep + // COMPATIBILITY NOTE / TODO: This property may go away in the + // future, as it is currently only required due to + // limitations in the underlying library. Do not rely + // on this property long-term; check release notes. Host string `json:"host,omitempty"` // The path prefix under which to serve all ACME // endpoints. All other requests will not be served // by this handler and will be passed through to // the next one. Default: "/acme/" + // COMPATIBILITY NOTE / TODO: This property may go away in the + // future, as it is currently only required due to + // limitations in the underlying library. Do not rely + // on this property long-term; check release notes. PathPrefix string `json:"path_prefix,omitempty"` acmeEndpoints http.Handler diff --git a/modules/caddypki/acmeserver/caddyfile.go b/modules/caddypki/acmeserver/caddyfile.go new file mode 100644 index 00000000..66874604 --- /dev/null +++ b/modules/caddypki/acmeserver/caddyfile.go @@ -0,0 +1,38 @@ +// Copyright 2015 Matthew Holt and The Caddy Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package acmeserver + +import ( + "github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile" + "github.com/caddyserver/caddy/v2/modules/caddyhttp" +) + +func init() { + httpcaddyfile.RegisterHandlerDirective("acme_server", parseACMEServer) +} + +// parseACMEServer sets up an ACME server handler from Caddyfile tokens. +// +// acme_server [] +// +func parseACMEServer(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error) { + var as Handler + for h.Next() { + if h.NextArg() { + return nil, h.ArgErr() + } + } + return as, nil +}