linkerd2/pkg
Alejandro Pedraza 578d4a19e9
Have the tap APIServer refresh its cert automatically (#5388)
Followup to #5282, fixes #5272 in its totality.

This follows the same pattern as the injector/sp-validator webhooks, leveraging `FsCredsWatcher` to watch for changes in the cert files.

To reuse code from the webhooks, we moved `updateCert()` to `creds_watcher.go`, and `run()` as well (which now is called `ProcessEvents()`).

The `TestNewAPIServer` test in `apiserver_test.go` was removed as it really was just testing two things: (1) that `apiServerAuth` doesn't error which is already covered in the following test, and (2) that the golib call `net.Listen("tcp", addr)` doesn't error, which we're not interested in testing here.

## How to test

To test that the injector/sp-validator functionality is still correct, you can refer to #5282

The steps below are similar, but focused towards the tap component:

```bash
# Create some root cert
$ step certificate create linkerd-tap.linkerd.svc ca.crt ca.key   --profile root-ca --no-password --insecure

# configure tap's caBundle to be that root cert
$ cat > linkerd-overrides.yml << EOF
tap:
  externalSecret: true
  caBundle: |
    < ca.crt contents>
EOF

# Install linkerd
$ bin/linkerd install --config linkerd-overrides.yml | k apply -f -

# Generate an intermediatery cert with short lifespan
$ step certificate create linkerd-tap.linkerd.svc ca-int.crt ca-int.key --ca ca.crt --ca-key ca.key --profile intermediate-ca --not-after 4m --no-password --insecure --san linkerd-tap.linkerd.svc

# Create the secret using that intermediate cert
$ kubectl create secret tls \
  linkerd-tap-k8s-tls \
   --cert=ca-int.crt \
   --key=ca-int.key \
   --namespace=linkerd

# Rollout the tap pod for it to pick the new secret
$ k -n linkerd rollout restart deploy/linkerd-tap

# Tap should work
$ bin/linkerd tap -n linkerd deploy/linkerd-web
req id=0:0 proxy=in  src=10.42.0.15:33040 dst=10.42.0.11:9994 tls=true :method=GET :authority=10.42.0.11:9994 :path=/metrics
rsp id=0:0 proxy=in  src=10.42.0.15:33040 dst=10.42.0.11:9994 tls=true :status=200 latency=1779µs
end id=0:0 proxy=in  src=10.42.0.15:33040 dst=10.42.0.11:9994 tls=true duration=65µs response-length=1709B

# Wait 5 minutes and rollout tap again
$ k -n linkerd rollout restart deploy/linkerd-tap

# You'll see in the logs that the cert expired:
$ k -n linkerd logs -f deploy/linkerd-tap tap
2020/12/15 16:03:41 http: TLS handshake error from 127.0.0.1:45866: remote error: tls: bad certificate
2020/12/15 16:03:41 http: TLS handshake error from 127.0.0.1:45870: remote error: tls: bad certificate

# Recreate the secret
$ step certificate create linkerd-tap.linkerd.svc ca-int.crt ca-int.key --ca ca.crt --ca-key ca.key --profile intermediate-ca --not-after 4m --no-password --insecure --san linkerd-tap.linkerd.svc
$ k -n linkerd delete secret linkerd-tap-k8s-tls
$ kubectl create secret tls \
  linkerd-tap-k8s-tls \
   --cert=ca-int.crt \
   --key=ca-int.key \
   --namespace=linkerd

# Wait a few moments and you'll see the certs got reloaded and tap is working again
time="2020-12-15T16:03:42Z" level=info msg="Updated certificate" addr=":8089" component=apiserver
```
2020-12-16 17:46:14 -05:00
..
addr Add some unit test (#4853) 2020-08-18 16:10:13 -07:00
admin remove admin server timeouts (#4350) 2020-05-08 12:59:43 -07:00
charts upgrades: make webhooks restart if TLS creds are updated (#5349) 2020-12-10 11:56:53 -05:00
config Add safe accessor for Global in linkerd-config (#5269) 2020-11-23 12:45:58 -08:00
filesonly Enable lint check for comments (#2023) 2019-01-02 14:03:59 -08:00
flags jaeger: Add support for override flags (#5304) 2020-12-04 16:35:39 -08:00
healthcheck jaeger: add check sub command (#5295) 2020-12-17 00:26:34 +05:30
identity cli: Don't check for SAN in root and intermediate certs (#5237) 2020-11-18 15:30:39 -08:00
inject Use linkerd-jaeger extension for control plane tracing (#5299) 2020-12-08 14:34:26 -08:00
issuercerts cli: Don't check for SAN in root and intermediate certs (#5237) 2020-11-18 15:30:39 -08:00
k8s jaeger: add check sub command (#5295) 2020-12-17 00:26:34 +05:30
multicluster Bump k8s client-go to v0.19.2 (#5002) 2020-09-28 12:45:18 -05:00
profiles Use errors.Is instead of checking underlying err messages (#5140) 2020-10-28 21:33:17 +05:30
prometheus Trace Control plane Components with OC (#3495) 2019-10-18 12:19:13 -07:00
protohttp Use errors.Is instead of checking underlying err messages (#5140) 2020-10-28 21:33:17 +05:30
servicemirror Add support for service-mirror selectors (#4795) 2020-07-30 10:07:14 -07:00
tap Use errors.Is instead of checking underlying err messages (#5140) 2020-10-28 21:33:17 +05:30
tls Have the tap APIServer refresh its cert automatically (#5388) 2020-12-16 17:46:14 -05:00
trace Trace Control plane Components with OC (#3495) 2019-10-18 12:19:13 -07:00
tree Expose namespaceSelector for admission webhooks in helm chart (#5074) 2020-10-13 16:08:56 -07:00
util Add unit test for pkg/util/http.go (#4770) 2020-07-21 14:08:53 -07:00
version Bump proxy-init to v1.3.8 (#5283) 2020-11-27 09:07:34 -05:00