Skip to content
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

Pass ServerName in the ConnInfo packet #9

Merged
merged 1 commit into from
Jun 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions elastic-agent-client.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ option go_package = "pkg/proto;proto";
message ConnInfo {
// GRPC connection address.
string addr = 1;
// Server name to use when connecting over TLS.
string server_name = 2;
// Token that the application should send as the unique identifier when connecting over the GRPC.
string token = 2;
string token = 3;
// CA certificate.
bytes ca_cert = 3;
bytes ca_cert = 4;
// Peer certificate.
bytes peer_cert = 4;
bytes peer_cert = 5;
// Peer private key.
bytes peer_key = 5;
bytes peer_key = 6;
}

// A status observed message is streamed from the application to Elastic Agent.
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ package client
import (
"crypto/tls"
"crypto/x509"
"google.golang.org/grpc/credentials"
"io"
"io/ioutil"

protobuf "github.com/golang/protobuf/proto"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"

"github.com/elastic/elastic-agent-client/v7/pkg/proto"
)
Expand All @@ -35,7 +35,7 @@ func NewFromReader(reader io.Reader, impl StateInterface, actions ...Action) (*C
caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(connInfo.CaCert)
trans := credentials.NewTLS(&tls.Config{
ServerName: "localhost",
ServerName: connInfo.ServerName,
Certificates: []tls.Certificate{cert},
RootCAs: caCertPool,
})
Expand Down
11 changes: 6 additions & 5 deletions pkg/client/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,12 @@ func TestNewFromReader_Connects(t *testing.T) {
defer srv.Stop()

connInfo := &proto.ConnInfo{
Addr: fmt.Sprintf(":%d", srv.Port),
Token: token,
CaCert: ca.caPEM,
PeerCert: peer.Crt,
PeerKey: peer.Key,
Addr: fmt.Sprintf(":%d", srv.Port),
ServerName: "localhost",
Token: token,
CaCert: ca.caPEM,
PeerCert: peer.Crt,
PeerKey: peer.Key,
}
connInfoBytes, err := protobuf.Marshal(connInfo)
require.NoError(t, err)
Expand Down
141 changes: 76 additions & 65 deletions pkg/proto/elastic-agent-client.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.