Commit Graph

80 Commits

Author SHA1 Message Date
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
Jordan Liggitt
f46a378f78 Shorten re-read period for token files to work with ProjectedTokenVolumeSource
Kubernetes-commit: a432a7cf683e4ea304ae8e39e191a438e37a813e
2018-12-29 22:18:28 -05:00
Jordan Liggitt
66e83da33c Plumb token and token file through rest.Config
Kubernetes-commit: dba85e58debadfcb66aff2b68ba8bcc2eafeac2d
2018-12-04 11:24:29 -05:00
Davanum Srinivas
74cd8bbeee Move from glog to klog
- Move from the old github.com/golang/glog to k8s.io/klog
- klog as explicit InitFlags() so we add them as necessary
- we update the other repositories that we vendor that made a similar
change from glog to klog
  * github.com/kubernetes/repo-infra
  * k8s.io/gengo/
  * k8s.io/kube-openapi/
  * github.com/google/cadvisor
- Entirely remove all references to glog
- Fix some tests by explicit InitFlags in their init() methods

Change-Id: I92db545ff36fcec83afe98f550c9e630098b3135

Kubernetes-commit: 954996e231074dc7429f7be1256a579bedd8344c
2018-11-09 13:49:10 -05:00
Jordan Liggitt
63eb0a3a1f Add system root unit test
Kubernetes-commit: fbd5597e9914fc24ece3b21e6015748ed865de7b
2018-10-23 13:48:05 -04:00
Christoph Blecker
7f1c01699a Update gofmt for go1.11
Kubernetes-commit: 97b2992dc191a357e2167eff5035ce26237a4799
2018-10-05 12:59:38 -07:00
Tim Allclair
a6d1c60475 Only allow apiserver to follow redriects to the same host
Kubernetes-commit: 4ee9f007cbc88cca5fa3e8576ff951a52a248e3c
2018-07-23 13:16:25 -07:00
David Eads
5f3a23fd53 add logging to find offending transports
Kubernetes-commit: 8b61c5a08846221503ad039a53e3f38328c9c127
2018-08-02 15:14:27 -04:00
Jake Sanders
cce189a67e Escape illegal characters in remote extra keys
Signed-off-by: Jake Sanders <jsand@google.com>

Kubernetes-commit: f35e3d07c9898f8ec156209a868fa4451eb9afe2
2018-07-03 21:19:15 -07:00
Andrew Lytvynov
c669580288 Add TLS support to exec authenticator plugin
https://github.com/kubernetes/community/blob/master/contributors/design-proposals/auth/kubectl-exec-plugins.md#tls-client-certificate-support

Allows exec plugin to return raw TLS key/cert data. This data populates
transport.Config.TLS fields.
transport.Config.TLS propagates custom credentials using
tls.Config.GetClientCertificate callback.
On key/cert rotation, all connections using old credentials are
closed

Kubernetes-commit: cd89f9473faa60c15b8e9d223e5c4f9dab53627a
2018-05-30 14:03:32 -07:00
Mikhail Mazurskiy
4a75b93cb4 Use Dial with context
Kubernetes-commit: 5e8e570dbda6ed89af9bc2e0a05e3d94bfdfcb61
2018-05-19 08:14:37 +10:00
Cao Shufeng
f71f3da0d1 fix curl header
Kubernetes-commit: 084eb9b42906736002c285ac88c0dfcfbfb87a63
2018-04-27 15:56:03 +08:00