main.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. package main
  2. import (
  3. "context"
  4. "crypto/sha256"
  5. "encoding/hex"
  6. "encoding/json"
  7. "fmt"
  8. "io/ioutil"
  9. "net/http"
  10. "os"
  11. "strings"
  12. "time"
  13. "github.com/ghodss/yaml"
  14. "github.com/pkg/errors"
  15. log "github.com/sirupsen/logrus"
  16. "github.com/smallstep/certificates/ca"
  17. "github.com/smallstep/cli/crypto/pemutil"
  18. "k8s.io/api/admission/v1beta1"
  19. corev1 "k8s.io/api/core/v1"
  20. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  21. "k8s.io/apimachinery/pkg/runtime"
  22. "k8s.io/apimachinery/pkg/runtime/serializer"
  23. )
  24. var (
  25. runtimeScheme = runtime.NewScheme()
  26. codecs = serializer.NewCodecFactory(runtimeScheme)
  27. deserializer = codecs.UniversalDeserializer()
  28. // GetRootCAPath() is broken; points to secrets not certs. So
  29. // we'll hard code instead for now.
  30. //rootCAPath = pki.GetRootCAPath()
  31. rootCAPath = "/home/step/.step/certs/root_ca.crt"
  32. )
  33. const (
  34. admissionWebhookAnnotationKey = "autocert.step.sm/name"
  35. admissionWebhookStatusKey = "autocert.step.sm/status"
  36. provisionerPasswordFile = "/home/step/password/password"
  37. volumeMountPath = "/var/run/autocert.step.sm"
  38. tokenSecretKey = "token"
  39. tokenSecretLabel = "autocert.step.sm/token"
  40. )
  41. // Config options for the autocert admission controller.
  42. type Config struct {
  43. LogFormat string `yaml:"logFormat"`
  44. CaURL string `yaml:"caUrl"`
  45. CertLifetime string `yaml:"certLifetime"`
  46. Bootstrapper corev1.Container `yaml:"bootstrapper"`
  47. Renewer corev1.Container `yaml:"renewer"`
  48. CertsVolume corev1.Volume `yaml:"certsVolume"`
  49. RestrictCertificatesToNamespace bool `yaml:"restrictCertificatesToNamespace"`
  50. ClusterDomain string `yaml:"clusterDomain"`
  51. }
  52. // GetClusterDomain returns the Kubernetes cluster domain, defaults to
  53. // "cluster.local" if not specified in the configuration.
  54. func (c Config) GetClusterDomain() string {
  55. if c.ClusterDomain != "" {
  56. return c.ClusterDomain
  57. }
  58. return "cluster.local"
  59. }
  60. // PatchOperation represents a RFC6902 JSONPatch Operation
  61. type PatchOperation struct {
  62. Op string `json:"op"`
  63. Path string `json:"path"`
  64. Value interface{} `json:"value,omitempty"`
  65. }
  66. // RFC6901 JSONPath Escaping -- https://tools.ietf.org/html/rfc6901
  67. func escapeJSONPath(path string) string {
  68. // Replace`~` with `~0` then `/` with `~1`. Note that the order
  69. // matters otherwise we'll turn a `/` into a `~/`.
  70. path = strings.Replace(path, "~", "~0", -1)
  71. path = strings.Replace(path, "/", "~1", -1)
  72. return path
  73. }
  74. func loadConfig(file string) (*Config, error) {
  75. data, err := ioutil.ReadFile(file)
  76. if err != nil {
  77. return nil, err
  78. }
  79. var cfg Config
  80. if err := yaml.Unmarshal(data, &cfg); err != nil {
  81. return nil, err
  82. }
  83. return &cfg, nil
  84. }
  85. // createTokenSecret generates a kubernetes Secret object containing a bootstrap token
  86. // in the specified namespce. The secret name is randomly generated with a given prefix.
  87. // A goroutine is scheduled to cleanup the secret after the token expires. The secret
  88. // is also labelled for easy identification and manual cleanup.
  89. func createTokenSecret(prefix, namespace, token string) (string, error) {
  90. secret := corev1.Secret{
  91. TypeMeta: metav1.TypeMeta{
  92. Kind: "Secret",
  93. APIVersion: "v1",
  94. },
  95. ObjectMeta: metav1.ObjectMeta{
  96. GenerateName: prefix,
  97. Namespace: namespace,
  98. Labels: map[string]string{
  99. tokenSecretLabel: "true",
  100. },
  101. },
  102. StringData: map[string]string{
  103. tokenSecretKey: token,
  104. },
  105. Type: corev1.SecretTypeOpaque,
  106. }
  107. client, err := NewInClusterK8sClient()
  108. if err != nil {
  109. return "", err
  110. }
  111. body, err := json.Marshal(secret)
  112. if err != nil {
  113. return "", err
  114. }
  115. log.WithField("secret", string(body)).Debug("Creating secret")
  116. req, err := client.PostRequest(fmt.Sprintf("api/v1/namespaces/%s/secrets", namespace), string(body), "application/json")
  117. if err != nil {
  118. return "", err
  119. }
  120. resp, err := client.Do(req)
  121. if err != nil {
  122. log.Errorf("Secret creation error. Response: %v", resp)
  123. return "", errors.Wrap(err, "secret creation")
  124. }
  125. if resp.StatusCode < 200 || resp.StatusCode >= 300 {
  126. log.Errorf("Secret creation error (!2XX). Response: %v", resp)
  127. var rbody []byte
  128. if resp.Body != nil {
  129. if data, err := ioutil.ReadAll(resp.Body); err == nil {
  130. rbody = data
  131. }
  132. }
  133. log.Error("Error body: ", string(rbody))
  134. return "", errors.New("Not 200")
  135. }
  136. var rbody []byte
  137. if resp.Body != nil {
  138. if data, err := ioutil.ReadAll(resp.Body); err == nil {
  139. rbody = data
  140. }
  141. }
  142. if len(rbody) == 0 {
  143. return "", errors.New("Empty response body")
  144. }
  145. var created *corev1.Secret
  146. if err := json.Unmarshal(rbody, &created); err != nil {
  147. return "", errors.Wrap(err, "Error unmarshalling secret response")
  148. }
  149. // Clean up after ourselves by deleting the Secret after the bootstrap
  150. // token expires. This is best effort -- obviously we'll miss some stuff
  151. // if this process goes away -- but the secrets are also labelled so
  152. // it's also easy to clean them up in bulk using kubectl if we miss any.
  153. go func() {
  154. time.Sleep(tokenLifetime)
  155. req, err := client.DeleteRequest(fmt.Sprintf("api/v1/namespaces/%s/secrets/%s", namespace, created.Name))
  156. ctxLog := log.WithFields(log.Fields{
  157. "name": created.Name,
  158. "namespace": namespace,
  159. })
  160. if err != nil {
  161. ctxLog.WithField("error", err).Error("Error deleting expired boostrap token secret")
  162. return
  163. }
  164. resp, err := client.Do(req)
  165. if err != nil {
  166. ctxLog.WithField("error", err).Error("Error deleting expired boostrap token secret")
  167. return
  168. }
  169. if resp.StatusCode < 200 || resp.StatusCode >= 300 {
  170. ctxLog.WithFields(log.Fields{
  171. "status": resp.Status,
  172. "statusCode": resp.StatusCode,
  173. }).Error("Error deleting expired boostrap token secret")
  174. return
  175. }
  176. ctxLog.Info("Deleted expired bootstrap token secret")
  177. }()
  178. return created.Name, err
  179. }
  180. // mkBootstrapper generates a bootstrap container based on the template defined in Config. It
  181. // generates a new bootstrap token and mounts it, along with other required coniguration, as
  182. // environment variables in the returned bootstrap container.
  183. func mkBootstrapper(config *Config, commonName string, namespace string, provisioner Provisioner) (corev1.Container, error) {
  184. b := config.Bootstrapper
  185. token, err := provisioner.Token(commonName)
  186. if err != nil {
  187. return b, errors.Wrap(err, "token generation")
  188. }
  189. // Generate CA fingerprint
  190. crt, err := pemutil.ReadCertificate(rootCAPath)
  191. if err != nil {
  192. return b, errors.Wrap(err, "CA fingerprint")
  193. }
  194. sum := sha256.Sum256(crt.Raw)
  195. fingerprint := strings.ToLower(hex.EncodeToString(sum[:]))
  196. secretName, err := createTokenSecret(commonName+"-", namespace, token)
  197. if err != nil {
  198. return b, errors.Wrap(err, "create token secret")
  199. }
  200. log.Infof("Secret name is: %s", secretName)
  201. b.Env = append(b.Env, corev1.EnvVar{
  202. Name: "COMMON_NAME",
  203. Value: commonName,
  204. })
  205. b.Env = append(b.Env, corev1.EnvVar{
  206. Name: "STEP_TOKEN",
  207. ValueFrom: &corev1.EnvVarSource{
  208. SecretKeyRef: &corev1.SecretKeySelector{
  209. LocalObjectReference: corev1.LocalObjectReference{
  210. Name: secretName,
  211. },
  212. Key: tokenSecretKey,
  213. },
  214. },
  215. })
  216. b.Env = append(b.Env, corev1.EnvVar{
  217. Name: "STEP_CA_URL",
  218. Value: config.CaURL,
  219. })
  220. b.Env = append(b.Env, corev1.EnvVar{
  221. Name: "STEP_FINGERPRINT",
  222. Value: fingerprint,
  223. })
  224. b.Env = append(b.Env, corev1.EnvVar{
  225. Name: "STEP_NOT_AFTER",
  226. Value: config.CertLifetime,
  227. })
  228. return b, nil
  229. }
  230. // mkRenewer generates a new renewer based on the template provided in Config.
  231. func mkRenewer(config *Config) corev1.Container {
  232. r := config.Renewer
  233. r.Env = append(r.Env, corev1.EnvVar{
  234. Name: "STEP_CA_URL",
  235. Value: config.CaURL,
  236. })
  237. return r
  238. }
  239. func addContainers(existing, new []corev1.Container, path string) (ops []PatchOperation) {
  240. if len(existing) == 0 {
  241. return []PatchOperation{
  242. {
  243. Op: "add",
  244. Path: path,
  245. Value: new,
  246. },
  247. }
  248. }
  249. for _, add := range new {
  250. ops = append(ops, PatchOperation{
  251. Op: "add",
  252. Path: path + "/-",
  253. Value: add,
  254. })
  255. }
  256. return ops
  257. }
  258. func addVolumes(existing, new []corev1.Volume, path string) (ops []PatchOperation) {
  259. if len(existing) == 0 {
  260. return []PatchOperation{
  261. {
  262. Op: "add",
  263. Path: path,
  264. Value: new,
  265. },
  266. }
  267. }
  268. for _, add := range new {
  269. ops = append(ops, PatchOperation{
  270. Op: "add",
  271. Path: path + "/-",
  272. Value: add,
  273. })
  274. }
  275. return ops
  276. }
  277. func addCertsVolumeMount(volumeName string, containers []corev1.Container) (ops []PatchOperation) {
  278. volumeMount := corev1.VolumeMount{
  279. Name: volumeName,
  280. MountPath: volumeMountPath,
  281. ReadOnly: true,
  282. }
  283. for i, container := range containers {
  284. if len(container.VolumeMounts) == 0 {
  285. ops = append(ops, PatchOperation{
  286. Op: "add",
  287. Path: fmt.Sprintf("/spec/containers/%v/volumeMounts", i),
  288. Value: []corev1.VolumeMount{volumeMount},
  289. })
  290. } else {
  291. ops = append(ops, PatchOperation{
  292. Op: "add",
  293. Path: fmt.Sprintf("/spec/containers/%v/volumeMounts/-", i),
  294. Value: volumeMount,
  295. })
  296. }
  297. }
  298. return ops
  299. }
  300. func addAnnotations(existing, new map[string]string) (ops []PatchOperation) {
  301. if len(existing) == 0 {
  302. return []PatchOperation{
  303. {
  304. Op: "add",
  305. Path: "/metadata/annotations",
  306. Value: new,
  307. },
  308. }
  309. }
  310. for k, v := range new {
  311. if existing[k] == "" {
  312. ops = append(ops, PatchOperation{
  313. Op: "add",
  314. Path: "/metadata/annotations/" + escapeJSONPath(k),
  315. Value: v,
  316. })
  317. } else {
  318. ops = append(ops, PatchOperation{
  319. Op: "replace",
  320. Path: "/metadata/annotations/" + escapeJSONPath(k),
  321. Value: v,
  322. })
  323. }
  324. }
  325. return ops
  326. }
  327. // patch produces a list of patches to apply to a pod to inject a certificate. In particular,
  328. // we patch the pod in order to:
  329. // - Mount the `certs` volume in existing containers defined in the pod
  330. // - Add the autocert-renewer as a container (a sidecar)
  331. // - Add the autocert-bootstrapper as an initContainer
  332. // - Add the `certs` volume definition
  333. // - Annotate the pod to indicate that it's been processed by this controller
  334. // The result is a list of serialized JSONPatch objects (or an error).
  335. func patch(pod *corev1.Pod, namespace string, config *Config, provisioner Provisioner) ([]byte, error) {
  336. var ops []PatchOperation
  337. annotations := pod.ObjectMeta.GetAnnotations()
  338. commonName := annotations[admissionWebhookAnnotationKey]
  339. renewer := mkRenewer(config)
  340. bootstrapper, err := mkBootstrapper(config, commonName, namespace, provisioner)
  341. if err != nil {
  342. return nil, err
  343. }
  344. ops = append(ops, addCertsVolumeMount(config.CertsVolume.Name, pod.Spec.Containers)...)
  345. ops = append(ops, addContainers(pod.Spec.Containers, []corev1.Container{renewer}, "/spec/containers")...)
  346. ops = append(ops, addContainers(pod.Spec.InitContainers, []corev1.Container{bootstrapper}, "/spec/initContainers")...)
  347. ops = append(ops, addVolumes(pod.Spec.Volumes, []corev1.Volume{config.CertsVolume}, "/spec/volumes")...)
  348. ops = append(ops, addAnnotations(pod.Annotations, map[string]string{admissionWebhookStatusKey: "injected"})...)
  349. return json.Marshal(ops)
  350. }
  351. // shouldMutate checks whether a pod is subject to mutation by this admission controller. A pod
  352. // is subject to mutation if it's annotated with the `admissionWebhookAnnotationKey` and if it
  353. // has not already been processed (indicated by `admissionWebhookStatusKey` set to `injected`).
  354. // If the pod requests a certificate with a subject matching a namespace other than its own
  355. // and restrictToNamespace is true, then shouldMutate will return a validation error
  356. // that should be returned to the client.
  357. func shouldMutate(metadata *metav1.ObjectMeta, namespace string, clusterDomain string, restrictToNamespace bool) (bool, error) {
  358. annotations := metadata.GetAnnotations()
  359. if annotations == nil {
  360. annotations = map[string]string{}
  361. }
  362. // Only mutate if the object is annotated appropriately (annotation key set) and we haven't
  363. // mutated already (status key isn't set).
  364. if annotations[admissionWebhookAnnotationKey] == "" || annotations[admissionWebhookStatusKey] == "injected" {
  365. return false, nil
  366. }
  367. if !restrictToNamespace {
  368. return true, nil
  369. }
  370. subject := strings.Trim(annotations[admissionWebhookAnnotationKey], ".")
  371. err := fmt.Errorf("subject \"%s\" matches a namespace other than \"%s\" and is not permitted. This check can be disabled by setting restrictCertificatesToNamespace to false in the autocert-config ConfigMap", subject, namespace)
  372. if strings.HasSuffix(subject, ".svc") && !strings.HasSuffix(subject, fmt.Sprintf(".%s.svc", namespace)) {
  373. return false, err
  374. }
  375. if strings.HasSuffix(subject, fmt.Sprintf(".svc.%s", clusterDomain)) && !strings.HasSuffix(subject, fmt.Sprintf(".%s.svc.%s", namespace, clusterDomain)) {
  376. return false, err
  377. }
  378. return true, nil
  379. }
  380. // mutate takes an `AdmissionReview`, determines whether it is subject to mutation, and returns
  381. // an appropriate `AdmissionResponse` including patches or any errors that occurred.
  382. func mutate(review *v1beta1.AdmissionReview, config *Config, provisioner Provisioner) *v1beta1.AdmissionResponse {
  383. ctxLog := log.WithField("uid", review.Request.UID)
  384. request := review.Request
  385. var pod corev1.Pod
  386. if err := json.Unmarshal(request.Object.Raw, &pod); err != nil {
  387. ctxLog.WithField("error", err).Error("Error unmarshalling pod")
  388. return &v1beta1.AdmissionResponse{
  389. Allowed: false,
  390. UID: request.UID,
  391. Result: &metav1.Status{
  392. Message: err.Error(),
  393. },
  394. }
  395. }
  396. ctxLog = ctxLog.WithFields(log.Fields{
  397. "kind": request.Kind,
  398. "operation": request.Operation,
  399. "name": pod.Name,
  400. "generateName": pod.GenerateName,
  401. "namespace": request.Namespace,
  402. "user": request.UserInfo,
  403. })
  404. mutationAllowed, validationErr := shouldMutate(&pod.ObjectMeta, request.Namespace, config.GetClusterDomain(), config.RestrictCertificatesToNamespace)
  405. if validationErr != nil {
  406. ctxLog.WithField("error", validationErr).Info("Validation error")
  407. return &v1beta1.AdmissionResponse{
  408. Allowed: false,
  409. UID: request.UID,
  410. Result: &metav1.Status{
  411. Message: validationErr.Error(),
  412. },
  413. }
  414. }
  415. if !mutationAllowed {
  416. ctxLog.WithField("annotations", pod.Annotations).Info("Skipping mutation")
  417. return &v1beta1.AdmissionResponse{
  418. Allowed: true,
  419. UID: request.UID,
  420. }
  421. }
  422. patchBytes, err := patch(&pod, request.Namespace, config, provisioner)
  423. if err != nil {
  424. ctxLog.WithField("error", err).Error("Error generating patch")
  425. return &v1beta1.AdmissionResponse{
  426. Allowed: false,
  427. UID: request.UID,
  428. Result: &metav1.Status{
  429. Message: err.Error(),
  430. },
  431. }
  432. }
  433. ctxLog.WithField("patch", string(patchBytes)).Info("Generated patch")
  434. return &v1beta1.AdmissionResponse{
  435. Allowed: true,
  436. Patch: patchBytes,
  437. UID: request.UID,
  438. PatchType: func() *v1beta1.PatchType {
  439. pt := v1beta1.PatchTypeJSONPatch
  440. return &pt
  441. }(),
  442. }
  443. }
  444. func main() {
  445. if len(os.Args) != 2 {
  446. log.Errorf("Usage: %s <config>\n", os.Args[0])
  447. os.Exit(1)
  448. }
  449. config, err := loadConfig(os.Args[1])
  450. if err != nil {
  451. panic(err)
  452. }
  453. log.SetOutput(os.Stdout)
  454. if config.LogFormat == "json" {
  455. log.SetFormatter(&log.JSONFormatter{})
  456. }
  457. if config.LogFormat == "text" {
  458. log.SetFormatter(&log.TextFormatter{})
  459. }
  460. log.WithFields(log.Fields{
  461. "config": config,
  462. }).Info("Loaded config")
  463. provisionerName := os.Getenv("PROVISIONER_NAME")
  464. provisionerKid := os.Getenv("PROVISIONER_KID")
  465. log.WithFields(log.Fields{
  466. "provisionerName": provisionerName,
  467. "provisionerKid": provisionerKid,
  468. }).Info("Loaded provisioner configuration")
  469. provisioner, err := NewProvisioner(provisionerName, provisionerKid, config.CaURL, rootCAPath, provisionerPasswordFile)
  470. if err != nil {
  471. log.Errorf("Error loading provisioner: %v", err)
  472. os.Exit(1)
  473. }
  474. log.WithFields(log.Fields{
  475. "name": provisioner.Name(),
  476. "kid": provisioner.Kid(),
  477. }).Info("Loaded provisioner")
  478. namespace := os.Getenv("NAMESPACE")
  479. if namespace == "" {
  480. log.Errorf("$NAMESPACE not set")
  481. os.Exit(1)
  482. }
  483. name := fmt.Sprintf("autocert.%s.svc", namespace)
  484. token, err := provisioner.Token(name)
  485. if err != nil {
  486. log.WithField("error", err).Errorf("Error generating bootstrap token during controller startup")
  487. os.Exit(1)
  488. }
  489. log.WithField("name", name).Infof("Generated bootstrap token for controller")
  490. // make sure to cancel the renew goroutine
  491. ctx, cancel := context.WithCancel(context.Background())
  492. defer cancel()
  493. srv, err := ca.BootstrapServer(ctx, token, &http.Server{
  494. Addr: ":4443",
  495. Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  496. if r.URL.Path == "/healthz" {
  497. log.Info("/healthz")
  498. fmt.Fprintf(w, "ok")
  499. w.WriteHeader(http.StatusOK)
  500. return
  501. }
  502. /*
  503. var name string
  504. if r.TLS != nil && len(r.TLS.PeerCertificates) > 0 {
  505. name = r.TLS.PeerCertificates[0].Subject.CommonName
  506. }
  507. */
  508. if r.URL.Path != "/mutate" {
  509. log.WithField("path", r.URL.Path).Error("Bad Request: 404 Not Found")
  510. http.NotFound(w, r)
  511. return
  512. }
  513. var body []byte
  514. if r.Body != nil {
  515. if data, err := ioutil.ReadAll(r.Body); err == nil {
  516. body = data
  517. }
  518. }
  519. if len(body) == 0 {
  520. log.Error("Bad Request: 400 (Empty Body)")
  521. http.Error(w, "Bad Request (Empty Body)", http.StatusBadRequest)
  522. return
  523. }
  524. contentType := r.Header.Get("Content-Type")
  525. if contentType != "application/json" {
  526. log.WithField("Content-Type", contentType).Error("Bad Request: 415 (Unsupported Media Type)")
  527. http.Error(w, fmt.Sprintf("Bad Request: 415 Unsupported Media Type (Expected Content-Type 'application/json' but got '%s')", contentType), http.StatusUnsupportedMediaType)
  528. return
  529. }
  530. var response *v1beta1.AdmissionResponse
  531. review := v1beta1.AdmissionReview{}
  532. if _, _, err := deserializer.Decode(body, nil, &review); err != nil {
  533. log.WithFields(log.Fields{
  534. "body": body,
  535. "error": err,
  536. }).Error("Can't decode body")
  537. response = &v1beta1.AdmissionResponse{
  538. Allowed: false,
  539. Result: &metav1.Status{
  540. Message: err.Error(),
  541. },
  542. }
  543. } else {
  544. response = mutate(&review, config, provisioner)
  545. }
  546. resp, err := json.Marshal(v1beta1.AdmissionReview{
  547. Response: response,
  548. })
  549. if err != nil {
  550. log.WithFields(log.Fields{
  551. "uid": review.Request.UID,
  552. "error": err,
  553. }).Info("Marshal error")
  554. http.Error(w, fmt.Sprintf("Marshal Error: %v", err), http.StatusInternalServerError)
  555. } else {
  556. log.WithFields(log.Fields{
  557. "uid": review.Request.UID,
  558. "response": string(resp),
  559. }).Info("Returning review")
  560. if _, err := w.Write(resp); err != nil {
  561. log.WithFields(log.Fields{
  562. "uid": review.Request.UID,
  563. "error": err,
  564. }).Info("Write error")
  565. }
  566. }
  567. }),
  568. }, ca.VerifyClientCertIfGiven())
  569. if err != nil {
  570. panic(err)
  571. }
  572. log.Info("Listening on :4443 ...")
  573. if err := srv.ListenAndServeTLS("", ""); err != nil {
  574. panic(err)
  575. }
  576. }