Skip to content

Commit 24dbe49

Browse files
committed
GRPC: Add --force-ssl option to the GRPC client commands to be able to connect
to an SSL enabled GRPC server even if no client certificate is supplied. In this case the grpc::SslCredentials needs to be used but without any options supplied. Trying to connect a clietn with grcp::InsecureChannelCredentials to an SSL enabled server will not work, even if the following option is enabled on the server side: GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE
1 parent 62a9cee commit 24dbe49

File tree

9 files changed

+147
-108
lines changed

9 files changed

+147
-108
lines changed

client/grpc/Find.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ int usage(const char* prog)
99
fprintf(stderr, "usage: %s [--key <ssl-key-file> "
1010
"--cert <ssl-cert-file> "
1111
"--ca <ca-cert-file>] "
12-
"[--endpoint <host:port>] [--token <auth-token>] [--export <exportfs>] [--depth <depth>] [--select <filter-string>] [-f | -d] <path>\n",
12+
"[--endpoint <host:port>] [--token <auth-token>] [--export <exportfs>] [--depth <depth>] [--select <filter-string>] [--force-ssl] [-f | -d] <path>\n",
1313
prog);
1414
fprintf(stderr,
1515
" <filter-string> is setup as \"key1:val1,key2:val2,key3:val3 ... where keyN:valN is one of \n");
@@ -69,6 +69,7 @@ int main(int argc, const char* argv[])
6969
bool dirs = false;
7070
uint64_t depth = 1024;
7171
std::string exportfs = "";
72+
bool force_ssl = false;
7273

7374
for (auto i = 1; i < argc; ++i) {
7475
std::string option = argv[i];
@@ -163,6 +164,11 @@ int main(int argc, const char* argv[])
163164
continue;
164165
}
165166

167+
if (option == "--force-ssl") {
168+
force_ssl = true;
169+
continue;
170+
}
171+
166172
path = option;
167173

168174
if (argc > (i + 1)) {
@@ -195,7 +201,8 @@ int main(int argc, const char* argv[])
195201
token,
196202
keyfile,
197203
certfile,
198-
cafile);
204+
cafile,
205+
force_ssl);
199206

200207
if (!eosgrpc) {
201208
return usage(argv[0]);

client/grpc/GrpcClient.cc

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -543,24 +543,21 @@ GrpcClient::ContainerInsert(const std::vector<std::string>& paths)
543543

544544

545545
std::unique_ptr<GrpcClient>
546-
GrpcClient::Create(std::string endpoint,
547-
std::string token,
548-
std::string keyfile,
549-
std::string certfile,
550-
std::string cafile
551-
)
546+
GrpcClient::Create(std::string endpoint, std::string token, std::string keyfile,
547+
std::string certfile, std::string cafile, bool force_ssl)
552548
{
553549
std::string key;
554550
std::string cert;
555551
std::string ca;
556-
bool ssl = false;
552+
bool ssl_cred = false;
557553

558554
if (keyfile.length() || certfile.length() || cafile.length()) {
559555
if (!keyfile.length() || !certfile.length() || !cafile.length()) {
560556
return 0;
561557
}
562558

563-
ssl = true;
559+
force_ssl = true;
560+
ssl_cred = true;
564561

565562
if (eos::common::StringConversion::LoadFileIntoString(certfile.c_str(),
566563
cert) && !cert.length()) {
@@ -582,17 +579,20 @@ GrpcClient::Create(std::string endpoint,
582579
}
583580
}
584581

585-
grpc::SslCredentialsOptions opts = {
586-
ca,
587-
key,
588-
cert
589-
};
582+
grpc::SslCredentialsOptions opts;
583+
584+
if (ssl_cred) {
585+
opts.pem_root_certs = ca;
586+
opts.pem_private_key = key;
587+
opts.pem_cert_chain = cert;
588+
}
589+
590590
std::unique_ptr<eos::client::GrpcClient> p(new eos::client::GrpcClient(
591591
grpc::CreateChannel(
592592
endpoint,
593-
ssl ? grpc::SslCredentials(opts)
594-
: grpc::InsecureChannelCredentials())));
595-
p->set_ssl(ssl);
593+
(force_ssl ?
594+
grpc::SslCredentials(opts) :
595+
grpc::InsecureChannelCredentials()))));
596596
p->set_token(token);
597597
return p;
598598
}
@@ -693,4 +693,3 @@ GrpcClient::ExportFs(const eos::rpc::MDResponse& response,
693693

694694

695695
EOSCLIENTNAMESPACE_END
696-

client/grpc/GrpcClient.hh

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@ public:
5353
: stub_(eos::rpc::Eos::NewStub(channel)) { }
5454

5555
// convenience factory function
56-
static std::unique_ptr<GrpcClient> Create(std::string endpoint =
57-
"localhost:50051",
58-
std::string token = "",
59-
std::string keyfile = "",
60-
std::string certfile = "",
61-
std::string cafile = "");
56+
static std::unique_ptr<GrpcClient>
57+
Create(std::string endpoint = "localhost:50051",
58+
std::string token = "",
59+
std::string keyfile = "",
60+
std::string certfile = "",
61+
std::string cafile = "",
62+
bool force_ssl = false);
6263

6364
std::string Ping(const std::string& payload);
6465

@@ -82,16 +83,6 @@ public:
8283
int FileInsert(const std::vector<std::string>& paths);
8384
int ContainerInsert(const std::vector<std::string>& paths);
8485

85-
void set_ssl(bool onoff)
86-
{
87-
mSSL = onoff;
88-
}
89-
90-
bool ssl() const
91-
{
92-
return mSSL;
93-
}
94-
9586
void set_token(const std::string& _token)
9687
{
9788
mToken = _token;
@@ -104,12 +95,10 @@ public:
10495

10596
private:
10697
std::unique_ptr<eos::rpc::Eos::Stub> stub_;
107-
bool mSSL;
10898
std::string mToken;
10999
std::map<uint64_t, std::string> tree;
110100
};
111101

112102
#endif
113103

114104
EOSCLIENTNAMESPACE_END
115-

client/grpc/Insert.cc

Lines changed: 53 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,19 @@ int usage(const char* prog)
1111
"--cert <ssl-cert-file> "
1212
"--ca <ca-cert-file>] "
1313
"[--endpoint <host:port>] [--token <auth-token>] "
14-
"[--prefix prefix] "
15-
"[--treefile <treefile>] \n", prog);
16-
17-
fprintf(stderr,
18-
"treefile format providing inodes: \n"
19-
"----------------------------------\n"
20-
"ino:000000000000ffff:/eos/mydir/\n"
21-
"ino:000000000000ff01:/eos/mydir/myfile\n\n");
22-
23-
fprintf(stderr,
24-
"treefile format without inodes: \n"
25-
"----------------------------------\n"
26-
"/eos/mydir/\n"
27-
"/eos/mydir/myfile\n\n");
28-
14+
"[--prefix prefix] "
15+
"[--treefile <treefile>] "
16+
"[--force-ssl] \n", prog);
17+
fprintf(stderr,
18+
"treefile format providing inodes: \n"
19+
"----------------------------------\n"
20+
"ino:000000000000ffff:/eos/mydir/\n"
21+
"ino:000000000000ff01:/eos/mydir/myfile\n\n");
22+
fprintf(stderr,
23+
"treefile format without inodes: \n"
24+
"----------------------------------\n"
25+
"/eos/mydir/\n"
26+
"/eos/mydir/myfile\n\n");
2927
return -1;
3028
}
3129

@@ -39,8 +37,9 @@ int main(int argc, const char* argv[])
3937
std::string keyfile;
4038
std::string certfile;
4139
std::string cafile;
42-
std::string prefix="/grpc";
40+
std::string prefix = "/grpc";
4341
std::string treefile = "namespace.txt";
42+
bool force_ssl = false;
4443

4544
for (auto i = 1; i < argc; ++i) {
4645
std::string option = argv[i];
@@ -115,6 +114,11 @@ int main(int argc, const char* argv[])
115114
}
116115
}
117116

117+
if (option == "--force-ssl") {
118+
force_ssl = true;
119+
continue;
120+
}
121+
118122
return usage(argv[0]);
119123
}
120124

@@ -130,69 +134,71 @@ int main(int argc, const char* argv[])
130134
token,
131135
keyfile,
132136
certfile,
133-
cafile);
137+
cafile,
138+
force_ssl);
134139

135140
if (!eosgrpc) {
136141
return usage(argv[0]);
137142
}
138143

139-
std::cout << "=> settings: prefix=" << prefix << " treefile=" << treefile << std::endl;
140-
141-
144+
std::cout << "=> settings: prefix=" << prefix << " treefile=" << treefile <<
145+
std::endl;
142146
std::ifstream input(treefile);
143-
144147
size_t n = 0;
145148
size_t bulk = 1000;
146149
bool dirmode = true;
147150
std::vector<std::string> paths;
148-
149151
std::chrono::steady_clock::time_point watch_global =
150152
std::chrono::steady_clock::now();
151153

152-
for ( std::string line ; std::getline ( input, line ); ) {
154+
for (std::string line ; std::getline(input, line);) {
153155
n++;
154-
if (line.substr(0,4) == "ino:") {
156+
157+
if (line.substr(0, 4) == "ino:") {
155158
line.insert(21, prefix);
156159
} else {
157-
line.insert(0,prefix);
160+
line.insert(0, prefix);
158161
}
162+
159163
std::cout << n << " " << line << std::endl;
164+
160165
if (line.back() == '/') {
161166
// dir
162167
if (dirmode) {
163-
paths.push_back(line);
168+
paths.push_back(line);
164169
} else {
165-
// SEND OFF DIRS
166-
int retc = eosgrpc->FileInsert(paths);
167-
std::cout << "::send::files" << " retc=" << retc << std::endl;
168-
paths.clear();
169-
paths.push_back(line);
170-
dirmode = true;
170+
// SEND OFF DIRS
171+
int retc = eosgrpc->FileInsert(paths);
172+
std::cout << "::send::files" << " retc=" << retc << std::endl;
173+
paths.clear();
174+
paths.push_back(line);
175+
dirmode = true;
171176
}
172177
} else {
173178
// file
174179
if (dirmode) {
175-
// SEND OFF FILES
176-
int retc = eosgrpc->ContainerInsert(paths);
177-
std::cout << "::send::dirs " << " retc=" << retc << std::endl;
178-
paths.clear();
179-
paths.push_back(line);
180-
dirmode = false;
180+
// SEND OFF FILES
181+
int retc = eosgrpc->ContainerInsert(paths);
182+
std::cout << "::send::dirs " << " retc=" << retc << std::endl;
183+
paths.clear();
184+
paths.push_back(line);
185+
dirmode = false;
181186
} else {
182-
paths.push_back(line);
187+
paths.push_back(line);
183188
}
184189
}
190+
185191
if (paths.size() >= bulk) {
186192
if (dirmode) {
187-
// SEND OF DIRS
188-
int retc = eosgrpc->ContainerInsert(paths);
189-
std::cout << "::send::dirs" << " retc=" << retc << std::endl;
190-
paths.clear();
193+
// SEND OF DIRS
194+
int retc = eosgrpc->ContainerInsert(paths);
195+
std::cout << "::send::dirs" << " retc=" << retc << std::endl;
196+
paths.clear();
191197
} else {
192-
// SEND OF FILES
193-
int retc = eosgrpc->FileInsert(paths);
194-
std::cout << "::send::files" << " retc=" << retc << std::endl;
195-
paths.clear();
198+
// SEND OF FILES
199+
int retc = eosgrpc->FileInsert(paths);
200+
std::cout << "::send::files" << " retc=" << retc << std::endl;
201+
paths.clear();
196202
}
197203
}
198204
}

client/grpc/Md.cc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ int usage(const char* prog)
99
fprintf(stderr, "usage: %s [--key <ssl-key-file> "
1010
"--cert <ssl-cert-file> "
1111
"--ca <ca-cert-file>] "
12-
"[--endpoint <host:port>] [--token <auth-token>] [-l] <path>\n", prog);
12+
"[--endpoint <host:port>] [--token <auth-token>] [-l] [--force-ssl] <path>\n",
13+
prog);
1314
return -1;
1415
}
1516

@@ -25,6 +26,7 @@ int main(int argc, const char* argv[])
2526
std::string cafile;
2627
std::string path = "";
2728
bool listing = false;
29+
bool force_ssl = false;
2830

2931
for (auto i = 1; i < argc; ++i) {
3032
std::string option = argv[i];
@@ -84,6 +86,11 @@ int main(int argc, const char* argv[])
8486
continue;
8587
}
8688

89+
if (option == "--force-ssl") {
90+
force_ssl = true;
91+
continue;
92+
}
93+
8794
path = option;
8895

8996
if (argc > (i + 1)) {
@@ -96,7 +103,7 @@ int main(int argc, const char* argv[])
96103
return usage(argv[0]);
97104
}
98105
}
99-
106+
100107
if (path.empty()) {
101108
return usage(argv[0]);
102109
}
@@ -107,7 +114,8 @@ int main(int argc, const char* argv[])
107114
token,
108115
keyfile,
109116
certfile,
110-
cafile);
117+
cafile,
118+
force_ssl);
111119

112120
if (!eosgrpc) {
113121
return usage(argv[0]);

0 commit comments

Comments
 (0)