Skip to content

Commit 9906c0d

Browse files
committed
Add feature gate for ValidateCAA functionality and default it to off
To help avoid issues with the ValidateCAA functionality, this disables the CAA check by default and adds a new --feature-gates=ValidateCAA=true option to cert-manager-controller to allow enabling the previous behaviour in v0.7.0 and v0.7.1. Once issues with CNAMEd DNS names pointing to internal nameservers are resolved, this option will be defaulted to on. Signed-off-by: James Munnelly <[email protected]>
1 parent 076ecb4 commit 9906c0d

File tree

8 files changed

+91
-16
lines changed

8 files changed

+91
-16
lines changed

BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ filegroup(
6363
"//pkg/client/informers/externalversions:all-srcs",
6464
"//pkg/client/listers/certmanager/v1alpha1:all-srcs",
6565
"//pkg/controller:all-srcs",
66+
"//pkg/feature:all-srcs",
6667
"//pkg/issuer:all-srcs",
6768
"//pkg/logs:all-srcs",
6869
"//pkg/metrics:all-srcs",

cmd/controller/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ go_library(
3333
"//pkg/util:go_default_library",
3434
"//vendor/github.com/spf13/cobra:go_default_library",
3535
"//vendor/k8s.io/apimachinery/pkg/util/errors:go_default_library",
36+
"//vendor/k8s.io/apiserver/pkg/util/feature:go_default_library",
3637
"//vendor/k8s.io/client-go/plugin/pkg/client/auth:go_default_library",
3738
"//vendor/k8s.io/klog:go_default_library",
3839
],

cmd/controller/start.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121

2222
"github.com/spf13/cobra"
2323
utilerrors "k8s.io/apimachinery/pkg/util/errors"
24+
"k8s.io/apiserver/pkg/util/feature"
2425
_ "k8s.io/client-go/plugin/pkg/client/auth"
2526

2627
"github.com/jetstack/cert-manager/cmd/controller/app"
@@ -36,7 +37,6 @@ import (
3637
_ "github.com/jetstack/cert-manager/pkg/issuer/selfsigned"
3738
_ "github.com/jetstack/cert-manager/pkg/issuer/vault"
3839
_ "github.com/jetstack/cert-manager/pkg/issuer/venafi"
39-
4040
logf "github.com/jetstack/cert-manager/pkg/logs"
4141
"github.com/jetstack/cert-manager/pkg/util"
4242
)
@@ -80,6 +80,7 @@ to renew certificates at an appropriate time before expiry.`,
8080

8181
flags := cmd.Flags()
8282
o.ControllerOptions.AddFlags(flags)
83+
feature.DefaultMutableFeatureGate.AddFlag(flags)
8384

8485
return cmd
8586
}

pkg/controller/acmechallenges/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ go_library(
1616
"//pkg/client/listers/certmanager/v1alpha1:go_default_library",
1717
"//pkg/controller:go_default_library",
1818
"//pkg/controller/acmechallenges/scheduler:go_default_library",
19+
"//pkg/feature:go_default_library",
1920
"//pkg/issuer:go_default_library",
2021
"//pkg/issuer/acme/dns:go_default_library",
2122
"//pkg/issuer/acme/dns/util:go_default_library",
@@ -26,6 +27,7 @@ go_library(
2627
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
2728
"//vendor/k8s.io/apimachinery/pkg/util/errors:go_default_library",
2829
"//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library",
30+
"//vendor/k8s.io/apiserver/pkg/util/feature:go_default_library",
2931
"//vendor/k8s.io/client-go/listers/core/v1:go_default_library",
3032
"//vendor/k8s.io/client-go/tools/cache:go_default_library",
3133
"//vendor/k8s.io/client-go/util/workqueue:go_default_library",

pkg/controller/acmechallenges/sync.go

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ import (
2424

2525
corev1 "k8s.io/api/core/v1"
2626
utilerrors "k8s.io/apimachinery/pkg/util/errors"
27+
utilfeature "k8s.io/apiserver/pkg/util/feature"
2728

2829
"github.com/jetstack/cert-manager/pkg/acme"
2930
acmecl "github.com/jetstack/cert-manager/pkg/acme/client"
3031
cmapi "github.com/jetstack/cert-manager/pkg/apis/certmanager/v1alpha1"
3132
controllerpkg "github.com/jetstack/cert-manager/pkg/controller"
33+
"github.com/jetstack/cert-manager/pkg/feature"
3234
dnsutil "github.com/jetstack/cert-manager/pkg/issuer/acme/dns/util"
3335
logf "github.com/jetstack/cert-manager/pkg/logs"
3436
acmeapi "github.com/jetstack/cert-manager/third_party/crypto/acme"
@@ -134,24 +136,26 @@ func (c *Controller) Sync(ctx context.Context, ch *cmapi.Challenge) (err error)
134136
return nil
135137
}
136138

137-
// check for CAA records.
138-
// CAA records are static, so we don't have to present anything
139-
// before we check for them.
139+
if utilfeature.DefaultFeatureGate.Enabled(feature.ValidateCAA) {
140+
// check for CAA records.
141+
// CAA records are static, so we don't have to present anything
142+
// before we check for them.
140143

141-
// Find out which identity the ACME server says it will use.
142-
dir, err := cl.Discover(ctx)
143-
if err != nil {
144-
return err
145-
}
146-
// TODO(dmo): figure out if missing CAA identity in directory
147-
// means no CAA check is performed by ACME server or if any valid
148-
// CAA would stop issuance (strongly suspect the former)
149-
if len(dir.CAA) != 0 {
150-
err := dnsutil.ValidateCAA(ch.Spec.DNSName, dir.CAA, ch.Spec.Wildcard, c.Context.DNS01Nameservers)
144+
// Find out which identity the ACME server says it will use.
145+
dir, err := cl.Discover(ctx)
151146
if err != nil {
152-
ch.Status.Reason = fmt.Sprintf("CAA self-check failed: %s", err)
153147
return err
154148
}
149+
// TODO(dmo): figure out if missing CAA identity in directory
150+
// means no CAA check is performed by ACME server or if any valid
151+
// CAA would stop issuance (strongly suspect the former)
152+
if len(dir.CAA) != 0 {
153+
err := dnsutil.ValidateCAA(ch.Spec.DNSName, dir.CAA, ch.Spec.Wildcard, c.Context.DNS01Nameservers)
154+
if err != nil {
155+
ch.Status.Reason = fmt.Sprintf("CAA self-check failed: %s", err)
156+
return err
157+
}
158+
}
155159
}
156160

157161
solver, err := c.solverFor(ch.Spec.Type)

pkg/feature/BUILD.bazel

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
load("@io_bazel_rules_go//go:def.bzl", "go_library")
2+
3+
go_library(
4+
name = "go_default_library",
5+
srcs = ["features.go"],
6+
importpath = "github.com/jetstack/cert-manager/pkg/feature",
7+
visibility = ["//visibility:public"],
8+
deps = [
9+
"//vendor/k8s.io/apimachinery/pkg/util/runtime:go_default_library",
10+
"//vendor/k8s.io/apiserver/pkg/util/feature:go_default_library",
11+
],
12+
)
13+
14+
filegroup(
15+
name = "package-srcs",
16+
srcs = glob(["**"]),
17+
tags = ["automanaged"],
18+
visibility = ["//visibility:private"],
19+
)
20+
21+
filegroup(
22+
name = "all-srcs",
23+
srcs = [":package-srcs"],
24+
tags = ["automanaged"],
25+
visibility = ["//visibility:public"],
26+
)

pkg/feature/features.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
Copyright 2019 The Jetstack cert-manager contributors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package feature
18+
19+
import (
20+
"k8s.io/apimachinery/pkg/util/runtime"
21+
"k8s.io/apiserver/pkg/util/feature"
22+
)
23+
24+
const (
25+
// alpha: v0.7.2
26+
//
27+
// ValidateCAA enables CAA checking when issuing certificates
28+
ValidateCAA feature.Feature = "ValidateCAA"
29+
)
30+
31+
func init() {
32+
runtime.Must(feature.DefaultMutableFeatureGate.Add(defaultKubernetesFeatureGates))
33+
}
34+
35+
// defaultKubernetesFeatureGates consists of all known Kubernetes-specific feature keys.
36+
// To add a new feature, define a key for it above and add it here. The features will be
37+
// available throughout Kubernetes binaries.
38+
var defaultKubernetesFeatureGates = map[feature.Feature]feature.FeatureSpec{
39+
ValidateCAA: {Default: false, PreRelease: feature.Alpha},
40+
}

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,14 +521,14 @@ k8s.io/apimachinery/pkg/api/equality
521521
k8s.io/apimachinery/pkg/util/rand
522522
k8s.io/apimachinery/pkg/apis/meta/v1beta1/validation
523523
# k8s.io/apiserver v0.0.0-20190413053200-5b6ebd80335e
524+
k8s.io/apiserver/pkg/util/feature
524525
k8s.io/apiserver/pkg/registry/rest
525526
k8s.io/apiserver/pkg/server
526527
k8s.io/apiserver/pkg/server/options
527528
k8s.io/apiserver/pkg/admission
528529
k8s.io/apiserver/pkg/endpoints/request
529530
k8s.io/apiserver/pkg/features
530531
k8s.io/apiserver/pkg/storage/names
531-
k8s.io/apiserver/pkg/util/feature
532532
k8s.io/apiserver/pkg/admission/plugin/namespace/lifecycle
533533
k8s.io/apiserver/pkg/admission/plugin/webhook/mutating
534534
k8s.io/apiserver/pkg/admission/plugin/webhook/validating

0 commit comments

Comments
 (0)