Commit Graph

91 Commits

Author SHA1 Message Date
Antonio Ojea
7cf3125431 add new metrics for the internal client-go transport generator
Add two new metrics to monitor the client-go logic that
generate http.Transports for the clients.

- rest_client_transport_cache_entries is a gauge metrics
with the number of existin entries in the internal cache

- rest_client_transport_create_calls_total is a counter
that increments each time a new transport is created, storing
the result of the operation needed to generate it: hit, miss
or uncacheable

Change-Id: I2d8bde25281153d8f8e8faa249385edde3c1cb39

Kubernetes-commit: 3f3e1d507d081528ce8081f0daf4446d8a3b9bc0
2023-05-10 22:40:13 +00:00
Monis Khan
d8b14dc089 kubelet/client: collapse transport wiring onto standard approach
Signed-off-by: Monis Khan <mok@microsoft.com>

Kubernetes-commit: 754cb3d601a820180d19567c3600a789d77b0f07
2023-02-05 20:51:54 -05:00
Monis Khan
cc2441c02c transport/cache: statically assert that tlsCacheKey is comparable
Signed-off-by: Monis Khan <mok@microsoft.com>

Kubernetes-commit: a6d0f483002926f075009e69d533e244dec3cd2b
2022-09-22 13:14:38 -04:00
Monis Khan
5dab9a0b84 client-go/transport: drop Dial and GetCert fields in favor of Holders
Signed-off-by: Monis Khan <mok@microsoft.com>

Kubernetes-commit: 3313a70d5bcc40a39f99f482c18effc9de6072ba
2022-09-09 08:06:01 -04:00
Monis Khan
6a008ec216 exec auth: support TLS config caching
This change updates the transport.Config .Dial and .TLS.GetCert fields
to use a struct wrapper.  This indirection via a pointer allows the
functions to be compared and thus makes them valid to use as map keys.
This change is then leveraged by the existing global exec auth and TLS
config caches to return the same authenticator and TLS config even when
distinct but identical rest configs were used to create distinct
clientsets.

Signed-off-by: Monis Khan <mok@microsoft.com>

Kubernetes-commit: 831d95b6a021c2767effe85e461309cb6a0fdcec
2022-08-24 16:04:19 +00:00
cndoit18
bcd2e6c7da style: remove redundant judgment
Signed-off-by: cndoit18 <cndoit18@outlook.com>

Kubernetes-commit: ec43037d0f57fdfc2fdc4960fdb8a7e31ac79fae
2022-07-29 18:25:05 +08:00
inosato
27de641f75 Remove ioutil from client-go
Signed-off-by: inosato <si17_21@yahoo.co.jp>

Kubernetes-commit: 88dfa51b6003c90e8f0a0508939a1d79950a40df
2022-07-30 20:54:41 +09:00
Wojciech Tyczyński
9dde02d660 Clean shutdown of client integration tests
Kubernetes-commit: f673c262bdc2f3f0f060a2ed4349b723a088f36a
2022-07-18 21:13:33 +02:00
HaoJie Liu
f295032991 fix static-check for staging/src/k8s.io/client-go/
Signed-off-by: HaoJie Liu <liuhaojie@beyondcent.com>

Kubernetes-commit: 6022b69dfd1c6e9454d4aa79012803c749706f6d
2022-07-07 18:58:25 +08:00
Ricardo Katz
9c049623c2 Reintroduce response status and header on kubectl verbose debug
Kubernetes-commit: 04b240ac0d16f0d5c8cc0c06ebd8ff1433ca8469
2022-03-04 11:39:53 -03:00
Tim Allclair
8c38cf359a Don't follow redirects with spdy
Kubernetes-commit: e1069c64956a43f628d8ae2fcd9107959747c1c6
2022-03-04 16:08:58 -08:00
Davanum Srinivas
73f2731e23 Cleanup OWNERS files (No Activity in the last year)
Signed-off-by: Davanum Srinivas <davanum@gmail.com>

Kubernetes-commit: 497e9c1971c9e7d0193bc6d11503ec4ad527f1d5
2021-12-10 15:18:50 -05:00
Davanum Srinivas
70f09c4943 Check in OWNERS modified by update-yamlfmt.sh
Signed-off-by: Davanum Srinivas <davanum@gmail.com>

Kubernetes-commit: 9405e9b55ebcd461f161859a698b949ea3bde31d
2021-12-09 21:31:26 -05:00
Antonio Ojea
06eaec4d00 assert RoundTripperWrapper interface
Kubernetes-commit: 938cc5445dc6e8b723542036e97e1d2023bb3002
2021-11-05 14:53:22 +01:00
Antonio Ojea
26d331c399 client-go token source transport implement RoundTripperWrapper interface
Kubernetes-commit: ef190f860a90df36b415e16f0de16bfeedc17d21
2021-11-05 12:22:23 +01:00
Antonio Ojea
3a10028e85 client-go httpstats
enhance client-go DebugURLTiming roundtripper using golang httptrace
to provide timing statistics for:
- dns lookup
- tcp dialing
- tls handshake
- time to get a connection from the pool
- time to process a request

Kubernetes-commit: 72c35be086fed5f70fd11dc96ca34298573bff05
2021-09-21 10:38:43 +02:00
Margo Crawford
e0129e64d4 Introduces Impersonate-Uid to client-go.
* Updates ImpersonationConfig in rest/config.go to include UID
  attribute, and pass it through when copying the config
* Updates ImpersonationConfig in transport/config.go to include UID
  attribute
* In transport/round_tripper.go, Set the "Impersonate-Uid" header in
  requests based on the UID value in the config
* Update auth_test.go integration test to specify a UID through the new
  rest.ImpersonationConfig field rather than manually setting the
  Impersonate-Uid header

Signed-off-by: Margo Crawford <margaretc@vmware.com>

Kubernetes-commit: d9ddfb26e10ee353fc4617b66d2c9274bf6d1c08
2021-07-30 15:50:51 -07:00
Jon Zeolla
a3215d72fd Remove -k from toCurl output
Kubernetes-commit: 5bf7bb52fe4c95e09b812e6c43eeed7abdd6d90f
2021-06-03 15:11:03 -04:00
Monis Khan
776e602643 client-go transport: assert that final CA data is valid
Signed-off-by: Monis Khan <mok@vmware.com>

Kubernetes-commit: 440ea3ef49e0ac77353ceeaebc2aad6c995d5b35
2021-05-03 10:11:54 -04:00
c00522440
ca138c86e8 Change time.Now().Sub(x) to time.Since(x) for cleanup
Kubernetes-commit: 878548ceac9c109881c379911b8b0d8fce5ea68e
2021-04-12 10:27:54 +08:00
Huang Huang
0cfeb7fda9 Fix staticcheck failures for vendor/k8s.io/client-go/transport (#100429)
* Fix staticcheck failures for vendor/k8s.io/client-go/transport

* avoid the possibility of a hang

Kubernetes-commit: 02d20442a5a5f5e1d3f1ef8e6fb14945462bc36c
2021-04-11 11:29:15 +08:00
Shihang Zhang
3d6ec322f2 reset token if got Unauthorized in KCM
Kubernetes-commit: 5e7b60ba5fe218d8ac59496350dfdb9f43785d98
2021-02-22 15:38:18 -08:00
Andrea Tosatto
ef84e47785 Re-run gofmt against staging/src/k8s.io/client-go/transport/
Kubernetes-commit: 1449af17555eb5148d11556ee205c42b83821af0
2021-01-27 00:08:07 +00:00
Andrea Tosatto
e87f4d8d19 Remove unexpected updates to go.mod and go.sum
Kubernetes-commit: 961fa25dd4468cad40274258c701e5d48fa02c5e
2021-01-26 23:49:25 +00:00
Andrea Tosatto
84db31c178 Address golint warnings
Kubernetes-commit: 675cefa1d15cadc5d1772d0ced16a3e843488347
2021-01-26 23:29:32 +00:00
Andrea Tosatto
8d3dc9e9ef Run gofmt against staging/src/k8s.io/client-go/transport/round_trippers_test.go
Kubernetes-commit: e87349f3caa810b96ed86fac7aec6bd0e73dacb1
2021-01-26 23:14:56 +00:00
Andrea Tosatto
2bce1731eb Run gofmt against staging/src/k8s.io/client-go/transport/round_trippers.go
Kubernetes-commit: 9cb5580ac6584cc787a2b2061c6c61656d065392
2021-01-26 22:04:52 +00:00
Andrea Tosatto
5c01a03456 client-go: export NewDebuggingRoundTripper function and DebugLevel
`debuggingRoundTripper` is a useful throbleshooting tool to debug of Kubernetes API requests and their timing.

Unfortunately, as of today, it can only be used via the `DebugWrappers` function, which automatically adjust the amount of debug information exposed by the roundTripper based on the configured `klog` verbosity.

While `DebugWrappers` definitely fits the purpose for clients using `klog`, this is currently hard to be used for controllers using `controller-runtime`, which uses `github.com/go-logr/logr` for logging.

In this PR we change the visibility of `newDebuggingRoundTripper` and `debugLevel` in order to be directly accessible from users of the `k8s.io/client-go/transport` package.

In particular, the changes proposed in this PR allow users of `controller-runtime` to use the `debuggingRoundTripper` to intercept Kubernetes API requests as follows

```go
import (
        ctrl "sigs.k8s.io/controller-runtime"
)

func init() {
	ctrl.SetLogger(zap.New())
}

func main() {
        // wrap the http transport used by the Kubernetes client
	restConfig, err := ctrl.GetConfig()
	checkError(setupLog, err, "unable to get kubernetes client config")

        restConfig.Wrap(func(rt http.RoundTripper) http.RoundTripper {
		return transport.NewDebuggingRoundTripper(rt, transport.DebugJustURL)
	})

        ...
}
```

Kubernetes-commit: 8de53ce96cb58d56fd00e91d8bcf7761ab498b83
2021-01-22 14:57:14 +01:00
xiongzhongliang
d7ba1f2e01 use klog.Info and klog.Warning when had no format
Kubernetes-commit: 90f4aeeea4cc5f96caa6ed87c67ca7e62d1ba21c
2020-11-14 00:55:06 +08:00
Jian Zeng
479dd01de2 feat: enable SPDY pings on connections
Signed-off-by: Jian Zeng <zengjian.zj@bytedance.com>

Kubernetes-commit: d0dce7035832f0673d87ae44503560204f3d3d46
2020-12-05 22:31:52 +08:00
Wilson Husin
d6281e9d1e Fix golint failures in client-go/transport
Signed-off-by: Wilson Husin <whusin@vmware.com>

Kubernetes-commit: 889ffb04d03e49cdbb481b86ea233d0aa3143db6
2020-10-15 11:06:24 -07:00
Marek Siarkowicz
e93788d387 Add datapolicy tags to staging/src/k8s.io/client-go/
Kubernetes-commit: e29c568c4a9cd45d15665345aa015e21bcff52dd
2020-10-29 18:15:52 +01:00
Haowei Cai
a3299cf8e9 don't cache transports for incomparable configs
Co-authored-by: Jordan Liggitt <liggitt@google.com>

Kubernetes-commit: 0765ba8e54f0c9e5f221e505a24759fa18beaf2e
2020-10-07 15:44:27 -07:00
Sam Fowler
e8f871a2e5 Mask bearer token in logs when logLevel >= 9
Kubernetes-commit: f0f52255412cbc6834bd225a59608ebb4a0d399b
2020-10-06 11:10:38 +10:00
phillc
8ea16c1919 find . -type f \( -name "*.go" -or -name "*.md" \) -print0 | xargs -0 gsed -i 's/the the /the /g'
Kubernetes-commit: adbc7c2172ea622db7399f41e893063b00ca1a87
2020-09-21 16:37:12 -04:00
Davanum Srinivas
48c3485ab5 Drop tests that break with newer oauth2
The bazel test failures are caused by (oauth2: turn Transport.CancelRequest into a no-op)[858c2ad4c8]:
0f29369cfe...858c2ad4c8

Signed-off-by: Davanum Srinivas <davanum@gmail.com>

Kubernetes-commit: eea0fea657e5955dedcb6e39bad4dca57d70553c
2020-05-12 11:51:13 -04:00
Davanum Srinivas
75fea27a27 switch over k/k to use klog v2
Signed-off-by: Davanum Srinivas <davanum@gmail.com>

Kubernetes-commit: 442a69c3bdf6fe8e525b05887e57d89db1e2f3a5
2020-04-17 15:25:06 -04:00
Mike Danese
2ff3b163f5 wire up proxier in spdy transport
and delete useless function

Kubernetes-commit: 652a48d2e7af76783cf08b5b1922da925e3d2a46
2020-05-06 10:51:52 -07:00
Mike Danese
0caa50056a rest.Config: support configuring an explict proxy URL
With support of http, https, and socks5 proxy support. We already
support configuring this via environmnet variables, but this approach
becomes inconvenient dealing with multiple clusters on different
networks, that require different proxies to connect to. Most solutions
require wrapping clients (like kubectl) in bash scripts.

Part of: https://github.com/kubernetes/client-go/issues/351

Kubernetes-commit: f3f666d5f1f6f74a8c948a5c64af993696178244
2019-05-03 13:50:17 -07:00
Lubomir I. Ivanov
38dc9a8fb0 client-go: use klog.V(3) for the cert-rotation controller start/stop
Introduce a verbosity level for the start and stop notifications,
so that regular calls to commands such as:
  "kubectl auth ..."
would only contain the "yes" / "no" output.

Kubernetes-commit: b2677b1e572ae1cd8b823683e88005b7857d8938
2020-03-04 01:35:17 +02:00
Jack Kleeman
a493c8da9a Add ReloadCertFromDisk flag to rest.Config and to kubeconfig which allows the provided client certificate files to be reloaded from disk (currently on every use)
Close outbound connections when using a cert callback and certificates rotate. This means that we won't get into a situation where we have open TLS connections using expires certs, which would get unauthorized errors at the apiserver

Attempt to retrieve a new certificate if open connections near expiry, to prevent the case where the cert expires but we haven't yet opened a new TLS connection and so GetClientCertificate hasn't been called.

Move certificate rotation logic to a separate function

Rely on generic transport approach to handle closing TLS client connections in exec plugin; no need to use a custom dialer as this is now the default behaviour of the transport when faced with a cert callback. As a result of handling this case, it is now safe to apply the transport approach even in cases where there is a custom Dialer (this will not affect kubelet connrotation behaviour, because that uses a custom transport, not just a dialer).

Check expiry of the full TLS certificate chain that will be presented, not only the leaf. Only do this check when the certificate actually rotates. Start the certificate as a zero value, not nil, so that we don't see a rotation when there is in fact no client certificate

Drain the timer when we first initialize it, to prevent immediate rotation. Additionally, calling Stop() on the timer isn't necessary.

Don't close connections on the first 'rotation'

Remove RotateCertFromDisk and RotateClientCertFromDisk flags.

Instead simply default to rotating certificates from disk whenever files are exclusively provided.

Add integration test for client certificate rotation

Simplify logic; rotate every 5 mins

Instead of trying to be clever and checking for rotation just before an
expiry, let's match the logic of the new apiserver cert rotation logic
as much as possible. We write a controller that checks for rotation
every 5 mins. We also check on every new connection.

Respond to review

Fix kubelet certificate rotation logic

The kubelet rotation logic seems to be broken because it expects its
cert files to end up as cert data whereas in fact they end up as a
callback. We should just call the tlsConfig GetCertificate callback
as this obtains a current cert even in cases where a static cert is
provided, and check that for validity.

Later on we can refactor all of the kubelet logic so that all it does is
write files to disk, and the cert rotation work does the rest.

Only read certificates once a second at most

Respond to review

1) Don't blat the cert file names
2) Make it more obvious where we have a neverstop
3) Naming
4) Verbosity

Avoid cache busting

Use filenames as cache keys when rotation is enabled, and add the
rotation later in the creation of the transport.

Caller should start the rotating dialer

Add continuous request rotation test

Rebase: use context in List/Watch

Swap goroutine around

Retry GETs on net.IsProbableEOF

Refactor certRotatingDialer

For simplicity, don't affect cert callbacks

To reduce change surface, lets not try to handle the case of a changing
GetCert callback in this PR. Reverting this commit should be sufficient
to handle that case in a later PR.

This PR will focus only on rotating certificate and key files.
Therefore, we don't need to modify the exec auth plugin.

Fix copyright year

Kubernetes-commit: 929b1559a0b855d996257ab3ad5364605edc253d
2019-06-14 22:08:58 +01:00
Jordan Liggitt
696c159e45 Plumb NextProtos to TLS client config, honor http/2 client preference
Kubernetes-commit: aef05c8dca2c1a9967ebd9a2f67a0bf7fb16f079
2019-08-28 09:55:37 -04:00
Mike Danese
cdbf1c4b62 implement request cancellation in token transport
Kubernetes-commit: a42e029e6905bee5b9d5489610c4fbe5988eeac6
2018-12-05 12:36:48 -08:00
Ted Yu
689d090711 Hide bearer token in logs
Kubernetes-commit: 010d8382642119c73cb2405286b347c08d704287
2019-08-13 09:36:13 -07:00
Clayton Coleman
40d852a94d Allow gzip compression to be disabled from rest.Config
Golang automatically enables transport level gzip, but local network
clients may wish to disable it for better CPU usage and lower latency
(scheduler, controller-manager). Allow DisableCompression on rest.Config
to modify the underlying transport. This impacts the transport cache,
but it is expected that most clients connecting to the same servers
within a process will have the same compression config.

Kubernetes-commit: dee6de70d0e4ad381bd5de01b6d1fbd4fde004bc
2019-08-02 14:23:33 -04:00
WanLinghao
0dbf86afcf Migrate the controller to use TokenRequest and rotate token periodically
Kubernetes-commit: 244b244f9d84c56ad3a5af255b70c793f6bfd39c
2019-02-19 11:42:05 +08:00
Justin SB
931e6a04ad Remove executable file permission from OWNERS files
Kubernetes-commit: dd19b923b7c26420af39fcf4eedfa213b236c8d3
2019-01-03 12:18:20 -05:00
Roy Lenferink
94093d2527 Updated OWNERS files to include link to docs
Kubernetes-commit: b43c04452f3b563473b5c2a765d4ac18cc0ff58f
2019-01-30 20:05:00 +01:00
Clayton Coleman
77dfa9569a Add transport wrapper that blocks api calls after context close
The ContextCanceller transport wrapper blocks all API requests
after the provided context is closed. Used with the leader election
step down, a controller can ensure that new requests are not made
after the client has stepped down.

Kubernetes-commit: fe74efb1f90826b1903d2908ff9e528329bebea0
2018-12-27 12:29:34 -05:00
Clayton Coleman
615e8e2492 Make wrapping a client transport more pleasant
Properly wrapping a transport can be tricky. Make the normal case
(adding a non-nil transport wrapper to a config) easier with a helper.
Also enforce a rough ordering, which in the future we can use to
simplify the WrapTransport mechanism down into an array of functions
we execute in order and avoid wrapping altogether.

Kubernetes-commit: 1f590e697ef64812620c787720b4b5942027e4a1
2018-12-27 11:47:50 -05:00