-
Notifications
You must be signed in to change notification settings - Fork 208
Adding support for agent authenticate server by using kubeapi-server ca #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # Build the client binary | ||
| FROM golang:1.12.1 as builder | ||
|
|
||
| # Copy in the go src | ||
| WORKDIR /go/src/sigs.k8s.io/apiserver-network-proxy | ||
| COPY pkg/ pkg/ | ||
| COPY cmd/ cmd/ | ||
| COPY proto/ proto/ | ||
| COPY vendor/ vendor/ | ||
|
|
||
| # Build | ||
| ARG ARCH | ||
| RUN CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -a -ldflags '-extldflags "-static"' -o proxy-test-client sigs.k8s.io/apiserver-network-proxy/cmd/client | ||
|
|
||
| # Copy the loader into a thin image | ||
| FROM scratch | ||
| WORKDIR / | ||
| COPY --from=builder /go/src/sigs.k8s.io/apiserver-network-proxy/proxy-test-client . | ||
| ENTRYPOINT ["/proxy-test-client"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,6 @@ import ( | |
| "bufio" | ||
| "context" | ||
| "crypto/tls" | ||
| "crypto/x509" | ||
| "flag" | ||
| "fmt" | ||
| "io/ioutil" | ||
|
|
@@ -57,6 +56,7 @@ func main() { | |
| klog.Flush() | ||
| os.Exit(1) | ||
| } | ||
| klog.Flush() | ||
| } | ||
|
|
||
| type GrpcProxyClientOptions struct { | ||
|
|
@@ -84,7 +84,7 @@ func (o *GrpcProxyClientOptions) Flags() *pflag.FlagSet { | |
| flags.IntVar(&o.requestPort, "request-port", o.requestPort, "The port the request server is listening on.") | ||
| flags.StringVar(&o.proxyHost, "proxy-host", o.proxyHost, "The host of the proxy server.") | ||
| flags.IntVar(&o.proxyPort, "proxy-port", o.proxyPort, "The port the proxy server is listening on.") | ||
| flags.StringVar(&o.proxyUdsName, "proxy-uds", o.proxyHost, "The UDS name to connect to.") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch |
||
| flags.StringVar(&o.proxyUdsName, "proxy-uds", o.proxyUdsName, "The UDS name to connect to.") | ||
| flags.StringVar(&o.mode, "mode", o.mode, "Mode can be either 'grpc' or 'http-connect'.") | ||
|
|
||
| return flags | ||
|
|
@@ -142,6 +142,9 @@ func (o *GrpcProxyClientOptions) Validate() error { | |
| return fmt.Errorf("please do not try to use reserved port %d for the proxy server port", o.proxyPort) | ||
| } | ||
| if o.proxyUdsName != "" { | ||
| if o.proxyHost != "" { | ||
| return fmt.Errorf("please do set proxy host when using UDS") | ||
| } | ||
| if o.proxyPort != 0 { | ||
| return fmt.Errorf("please do set proxy server port to 0 not %d when using UDS", o.proxyPort) | ||
| } | ||
|
|
@@ -305,25 +308,12 @@ func (c *Client) getUDSDialer(o *GrpcProxyClientOptions) (func(ctx context.Conte | |
| } | ||
|
|
||
| func (c *Client) getMTLSDialer(o *GrpcProxyClientOptions) (func(ctx context.Context, network, addr string) (net.Conn, error), error) { | ||
| clientCert, err := tls.LoadX509KeyPair(o.clientCert, o.clientKey) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to read key pair %s & %s, got %v", o.clientCert, o.clientKey, err) | ||
| } | ||
| certPool := x509.NewCertPool() | ||
| caCert, err := ioutil.ReadFile(o.caCert) | ||
| var tlsConfig *tls.Config | ||
| var err error | ||
| tlsConfig, err = util.GetClientTLSConfig(o.caCert, o.clientCert, o.clientKey, o.proxyHost) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to read cert file %s, got %v", o.caCert, err) | ||
| return nil, err | ||
| } | ||
| ok := certPool.AppendCertsFromPEM(caCert) | ||
| if !ok { | ||
| return nil, fmt.Errorf("failed to append CA cert to the cert pool") | ||
| } | ||
|
|
||
| transportCreds := credentials.NewTLS(&tls.Config{ | ||
| ServerName: "127.0.0.1", | ||
| Certificates: []tls.Certificate{clientCert}, | ||
| RootCAs: certPool, | ||
| }) | ||
|
|
||
| var proxyConn net.Conn | ||
|
|
||
|
|
@@ -339,6 +329,7 @@ func (c *Client) getMTLSDialer(o *GrpcProxyClientOptions) (func(ctx context.Cont | |
|
|
||
| switch o.mode { | ||
| case "grpc": | ||
| transportCreds := credentials.NewTLS(tlsConfig) | ||
| dialOption := grpc.WithTransportCredentials(transportCreds) | ||
| serverAddress := fmt.Sprintf("%s:%d", o.proxyHost, o.proxyPort) | ||
| tunnel, err := client.CreateGrpcTunnel(serverAddress, dialOption) | ||
|
|
@@ -355,13 +346,7 @@ func (c *Client) getMTLSDialer(o *GrpcProxyClientOptions) (func(ctx context.Cont | |
| proxyAddress := fmt.Sprintf("%s:%d", o.proxyHost, o.proxyPort) | ||
| requestAddress := fmt.Sprintf("%s:%d", o.requestHost, o.requestPort) | ||
|
|
||
| proxyConn, err = tls.Dial("tcp", proxyAddress, | ||
| &tls.Config{ | ||
| ServerName: o.proxyHost, | ||
| Certificates: []tls.Certificate{clientCert}, | ||
| RootCAs: certPool, | ||
| }, | ||
| ) | ||
| proxyConn, err = tls.Dial("tcp", proxyAddress, tlsConfig) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("dialing proxy %q failed: %v", proxyAddress, err) | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it's copied from somewhere, but what does "fat manifest" mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://developer.ibm.com/linuxonpower/2017/07/27/create-multi-architecture-docker-image/ suggest a "fat manifest" is a mutli-architecture manifest.