]>
git.proxmox.com Git - ceph.git/blob - ceph/src/mon/MonCap.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2013 Inktank
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
15 #include <boost/config/warning_disable.hpp>
16 #include <boost/spirit/include/qi_uint.hpp>
17 #include <boost/spirit/include/qi.hpp>
18 #include <boost/fusion/include/std_pair.hpp>
19 #include <boost/spirit/include/phoenix.hpp>
20 #include <boost/fusion/adapted/struct/adapt_struct.hpp>
21 #include <boost/fusion/include/adapt_struct.hpp>
22 #include <boost/algorithm/string/predicate.hpp>
25 #include "include/stringify.h"
26 #include "include/ipaddr.h"
27 #include "common/debug.h"
28 #include "common/Formatter.h"
33 #include "include/ceph_assert.h"
35 static inline bool is_not_alnum_space(char c
)
37 return !(isalpha(c
) || isdigit(c
) || (c
== '-') || (c
== '_'));
40 static string
maybe_quote_string(const std::string
& str
)
42 if (find_if(str
.begin(), str
.end(), is_not_alnum_space
) == str
.end())
44 return string("\"") + str
+ string("\"");
50 #define dout_subsys ceph_subsys_mon
52 ostream
& operator<<(ostream
& out
, const mon_rwxa_t
& p
)
66 ostream
& operator<<(ostream
& out
, const StringConstraint
& c
)
68 switch (c
.match_type
) {
69 case StringConstraint::MATCH_TYPE_EQUAL
:
70 return out
<< "value " << c
.value
;
71 case StringConstraint::MATCH_TYPE_PREFIX
:
72 return out
<< "prefix " << c
.value
;
73 case StringConstraint::MATCH_TYPE_REGEX
:
74 return out
<< "regex " << c
.value
;
81 ostream
& operator<<(ostream
& out
, const MonCapGrant
& m
)
84 if (m
.service
.length()) {
85 out
<< " service " << maybe_quote_string(m
.service
);
87 if (m
.command
.length()) {
88 out
<< " command " << maybe_quote_string(m
.command
);
89 if (!m
.command_args
.empty()) {
91 for (map
<string
,StringConstraint
>::const_iterator p
= m
.command_args
.begin();
92 p
!= m
.command_args
.end();
94 switch (p
->second
.match_type
) {
95 case StringConstraint::MATCH_TYPE_EQUAL
:
96 out
<< " " << maybe_quote_string(p
->first
) << "="
97 << maybe_quote_string(p
->second
.value
);
99 case StringConstraint::MATCH_TYPE_PREFIX
:
100 out
<< " " << maybe_quote_string(p
->first
) << " prefix "
101 << maybe_quote_string(p
->second
.value
);
103 case StringConstraint::MATCH_TYPE_REGEX
:
104 out
<< " " << maybe_quote_string(p
->first
) << " regex "
105 << maybe_quote_string(p
->second
.value
);
113 if (m
.profile
.length()) {
114 out
<< " profile " << maybe_quote_string(m
.profile
);
117 out
<< " " << m
.allow
;
118 if (m
.network
.size())
119 out
<< " network " << m
.network
;
125 // fusion lets us easily populate structs via the qi parser.
127 typedef map
<string
,StringConstraint
> kvmap
;
129 BOOST_FUSION_ADAPT_STRUCT(MonCapGrant
,
130 (std::string
, service
)
131 (std::string
, profile
)
132 (std::string
, command
)
133 (kvmap
, command_args
)
135 (std::string
, network
))
137 BOOST_FUSION_ADAPT_STRUCT(StringConstraint
,
138 (StringConstraint::MatchType
, match_type
)
139 (std::string
, value
))
143 void MonCapGrant::parse_network()
145 network_valid
= ::parse_network(network
.c_str(), &network_parsed
,
149 void MonCapGrant::expand_profile(int daemon_type
, const EntityName
& name
) const
151 // only generate this list once
152 if (!profile_grants
.empty())
155 if (profile
== "read-only") {
156 // grants READ-ONLY caps monitor-wide
157 // 'auth' requires MON_CAP_X even for RO, which we do not grant here.
158 profile_grants
.push_back(mon_rwxa_t(MON_CAP_R
));
162 if (profile
== "read-write") {
163 // grants READ-WRITE caps monitor-wide
164 // 'auth' requires MON_CAP_X for all operations, which we do not grant.
165 profile_grants
.push_back(mon_rwxa_t(MON_CAP_R
| MON_CAP_W
));
169 switch (daemon_type
) {
170 case CEPH_ENTITY_TYPE_MON
:
171 expand_profile_mon(name
);
173 case CEPH_ENTITY_TYPE_MGR
:
174 expand_profile_mgr(name
);
179 void MonCapGrant::expand_profile_mgr(const EntityName
& name
) const
181 if (profile
== "crash") {
182 profile_grants
.push_back(MonCapGrant("crash post"));
186 void MonCapGrant::expand_profile_mon(const EntityName
& name
) const
188 if (profile
== "mon") {
189 profile_grants
.push_back(MonCapGrant("mon", MON_CAP_ALL
));
190 profile_grants
.push_back(MonCapGrant("log", MON_CAP_ALL
));
192 if (profile
== "osd") {
193 profile_grants
.push_back(MonCapGrant("osd", MON_CAP_ALL
));
194 profile_grants
.push_back(MonCapGrant("mon", MON_CAP_R
));
195 profile_grants
.push_back(MonCapGrant("pg", MON_CAP_R
| MON_CAP_W
));
196 profile_grants
.push_back(MonCapGrant("log", MON_CAP_W
));
198 if (profile
== "mds") {
199 profile_grants
.push_back(MonCapGrant("mds", MON_CAP_ALL
));
200 profile_grants
.push_back(MonCapGrant("mon", MON_CAP_R
));
201 profile_grants
.push_back(MonCapGrant("osd", MON_CAP_R
));
202 // This command grant is checked explicitly in MRemoveSnaps handling
203 profile_grants
.push_back(MonCapGrant("osd pool rmsnap"));
204 profile_grants
.push_back(MonCapGrant("osd blacklist"));
205 profile_grants
.push_back(MonCapGrant("log", MON_CAP_W
));
207 if (profile
== "mgr") {
208 profile_grants
.push_back(MonCapGrant("mgr", MON_CAP_ALL
));
209 profile_grants
.push_back(MonCapGrant("log", MON_CAP_R
| MON_CAP_W
));
210 profile_grants
.push_back(MonCapGrant("mon", MON_CAP_R
| MON_CAP_W
));
211 profile_grants
.push_back(MonCapGrant("mds", MON_CAP_R
| MON_CAP_W
));
212 profile_grants
.push_back(MonCapGrant("fs", MON_CAP_R
| MON_CAP_W
));
213 profile_grants
.push_back(MonCapGrant("osd", MON_CAP_R
| MON_CAP_W
));
214 profile_grants
.push_back(MonCapGrant("auth", MON_CAP_R
| MON_CAP_X
));
215 profile_grants
.push_back(MonCapGrant("config-key", MON_CAP_R
| MON_CAP_W
));
216 profile_grants
.push_back(MonCapGrant("config", MON_CAP_R
| MON_CAP_W
));
218 if (profile
== "osd" || profile
== "mds" || profile
== "mon" ||
220 StringConstraint
constraint(StringConstraint::MATCH_TYPE_PREFIX
,
221 string("daemon-private/") + stringify(name
) +
223 string prefix
= string("daemon-private/") + stringify(name
) + string("/");
224 profile_grants
.push_back(MonCapGrant("config-key get", "key", constraint
));
225 profile_grants
.push_back(MonCapGrant("config-key put", "key", constraint
));
226 profile_grants
.push_back(MonCapGrant("config-key set", "key", constraint
));
227 profile_grants
.push_back(MonCapGrant("config-key exists", "key", constraint
));
228 profile_grants
.push_back(MonCapGrant("config-key delete", "key", constraint
));
230 if (profile
== "bootstrap-osd") {
231 profile_grants
.push_back(MonCapGrant("mon", MON_CAP_R
)); // read monmap
232 profile_grants
.push_back(MonCapGrant("osd", MON_CAP_R
)); // read osdmap
233 profile_grants
.push_back(MonCapGrant("mon getmap"));
234 profile_grants
.push_back(MonCapGrant("osd new"));
235 profile_grants
.push_back(MonCapGrant("osd purge-new"));
237 if (profile
== "bootstrap-mds") {
238 profile_grants
.push_back(MonCapGrant("mon", MON_CAP_R
)); // read monmap
239 profile_grants
.push_back(MonCapGrant("osd", MON_CAP_R
)); // read osdmap
240 profile_grants
.push_back(MonCapGrant("mon getmap"));
241 profile_grants
.push_back(MonCapGrant("auth get-or-create")); // FIXME: this can expose other mds keys
242 profile_grants
.back().command_args
["entity"] = StringConstraint(
243 StringConstraint::MATCH_TYPE_PREFIX
, "mds.");
244 profile_grants
.back().command_args
["caps_mon"] = StringConstraint(
245 StringConstraint::MATCH_TYPE_EQUAL
, "allow profile mds");
246 profile_grants
.back().command_args
["caps_osd"] = StringConstraint(
247 StringConstraint::MATCH_TYPE_EQUAL
, "allow rwx");
248 profile_grants
.back().command_args
["caps_mds"] = StringConstraint(
249 StringConstraint::MATCH_TYPE_EQUAL
, "allow");
251 if (profile
== "bootstrap-mgr") {
252 profile_grants
.push_back(MonCapGrant("mon", MON_CAP_R
)); // read monmap
253 profile_grants
.push_back(MonCapGrant("osd", MON_CAP_R
)); // read osdmap
254 profile_grants
.push_back(MonCapGrant("mon getmap"));
255 profile_grants
.push_back(MonCapGrant("auth get-or-create")); // FIXME: this can expose other mgr keys
256 profile_grants
.back().command_args
["entity"] = StringConstraint(
257 StringConstraint::MATCH_TYPE_PREFIX
, "mgr.");
258 profile_grants
.back().command_args
["caps_mon"] = StringConstraint(
259 StringConstraint::MATCH_TYPE_EQUAL
, "allow profile mgr");
261 if (profile
== "bootstrap-rgw") {
262 profile_grants
.push_back(MonCapGrant("mon", MON_CAP_R
)); // read monmap
263 profile_grants
.push_back(MonCapGrant("osd", MON_CAP_R
)); // read osdmap
264 profile_grants
.push_back(MonCapGrant("mon getmap"));
265 profile_grants
.push_back(MonCapGrant("auth get-or-create")); // FIXME: this can expose other mds keys
266 profile_grants
.back().command_args
["entity"] = StringConstraint(
267 StringConstraint::MATCH_TYPE_PREFIX
, "client.rgw.");
268 profile_grants
.back().command_args
["caps_mon"] = StringConstraint(
269 StringConstraint::MATCH_TYPE_EQUAL
, "allow rw");
270 profile_grants
.back().command_args
["caps_osd"] = StringConstraint(
271 StringConstraint::MATCH_TYPE_EQUAL
, "allow rwx");
273 if (profile
== "bootstrap-rbd" || profile
== "bootstrap-rbd-mirror") {
274 profile_grants
.push_back(MonCapGrant("mon", MON_CAP_R
)); // read monmap
275 profile_grants
.push_back(MonCapGrant("auth get-or-create")); // FIXME: this can expose other rbd keys
276 profile_grants
.back().command_args
["entity"] = StringConstraint(
277 StringConstraint::MATCH_TYPE_PREFIX
, "client.");
278 profile_grants
.back().command_args
["caps_mon"] = StringConstraint(
279 StringConstraint::MATCH_TYPE_EQUAL
,
280 (profile
== "bootstrap-rbd-mirror" ? "profile rbd-mirror" :
282 profile_grants
.back().command_args
["caps_osd"] = StringConstraint(
283 StringConstraint::MATCH_TYPE_REGEX
,
284 "^([ ,]*profile(=|[ ]+)['\"]?rbd[^ ,'\"]*['\"]?([ ]+pool(=|[ ]+)['\"]?[^,'\"]+['\"]?)?)+$");
286 if (profile
== "fs-client") {
287 profile_grants
.push_back(MonCapGrant("mon", MON_CAP_R
));
288 profile_grants
.push_back(MonCapGrant("mds", MON_CAP_R
));
289 profile_grants
.push_back(MonCapGrant("osd", MON_CAP_R
));
290 profile_grants
.push_back(MonCapGrant("pg", MON_CAP_R
));
292 if (profile
== "simple-rados-client") {
293 profile_grants
.push_back(MonCapGrant("mon", MON_CAP_R
));
294 profile_grants
.push_back(MonCapGrant("osd", MON_CAP_R
));
295 profile_grants
.push_back(MonCapGrant("pg", MON_CAP_R
));
297 if (boost::starts_with(profile
, "rbd")) {
298 profile_grants
.push_back(MonCapGrant("mon", MON_CAP_R
));
299 profile_grants
.push_back(MonCapGrant("osd", MON_CAP_R
));
300 profile_grants
.push_back(MonCapGrant("pg", MON_CAP_R
));
302 // exclusive lock dead-client blacklisting (IP+nonce required)
303 profile_grants
.push_back(MonCapGrant("osd blacklist"));
304 profile_grants
.back().command_args
["blacklistop"] = StringConstraint(
305 StringConstraint::MATCH_TYPE_EQUAL
, "add");
306 profile_grants
.back().command_args
["addr"] = StringConstraint(
307 StringConstraint::MATCH_TYPE_REGEX
, "^[^/]+/[0-9]+$");
310 if (profile
== "rbd-mirror") {
311 StringConstraint
constraint(StringConstraint::MATCH_TYPE_PREFIX
,
313 profile_grants
.push_back(MonCapGrant("config-key get", "key", constraint
));
314 } else if (profile
== "rbd-mirror-peer") {
315 StringConstraint
constraint(StringConstraint::MATCH_TYPE_REGEX
,
317 profile_grants
.push_back(MonCapGrant("config-key get", "key", constraint
));
319 constraint
= StringConstraint(StringConstraint::MATCH_TYPE_PREFIX
,
321 profile_grants
.push_back(MonCapGrant("config-key set", "key", constraint
));
323 else if (profile
== "crash") {
324 // TODO: we could limit this to getting the monmap and mgrmap...
325 profile_grants
.push_back(MonCapGrant("mon", MON_CAP_R
));
327 if (profile
== "role-definer") {
328 // grants ALL caps to the auth subsystem, read-only on the
329 // monitor subsystem and nothing else.
330 profile_grants
.push_back(MonCapGrant("mon", MON_CAP_R
));
331 profile_grants
.push_back(MonCapGrant("auth", MON_CAP_ALL
));
335 mon_rwxa_t
MonCapGrant::get_allowed(CephContext
*cct
,
338 const std::string
& s
, const std::string
& c
,
339 const map
<string
,string
>& c_args
) const
341 if (profile
.length()) {
342 expand_profile(daemon_type
, name
);
344 for (list
<MonCapGrant
>::const_iterator p
= profile_grants
.begin();
345 p
!= profile_grants
.end(); ++p
)
346 a
= a
| p
->get_allowed(cct
, daemon_type
, name
, s
, c
, c_args
);
349 if (service
.length()) {
354 if (command
.length()) {
357 for (map
<string
,StringConstraint
>::const_iterator p
= command_args
.begin(); p
!= command_args
.end(); ++p
) {
358 map
<string
,string
>::const_iterator q
= c_args
.find(p
->first
);
359 // argument must be present if a constraint exists
360 if (q
== c_args
.end())
362 switch (p
->second
.match_type
) {
363 case StringConstraint::MATCH_TYPE_EQUAL
:
364 if (p
->second
.value
!= q
->second
)
367 case StringConstraint::MATCH_TYPE_PREFIX
:
368 if (q
->second
.find(p
->second
.value
) != 0)
371 case StringConstraint::MATCH_TYPE_REGEX
:
374 p
->second
.value
, std::regex::extended
);
375 if (!std::regex_match(q
->second
, pattern
))
377 } catch(const std::regex_error
&) {
387 // we don't allow config-key service to be accessed with blanket caps other
388 // than '*' (i.e., 'any'), and that should have been checked by the caller
389 // via 'is_allow_all()'.
390 if (s
== "config-key") {
396 ostream
& operator<<(ostream
&out
, const MonCap
& m
)
398 for (vector
<MonCapGrant
>::const_iterator p
= m
.grants
.begin(); p
!= m
.grants
.end(); ++p
) {
399 if (p
!= m
.grants
.begin())
406 bool MonCap::is_allow_all() const
408 for (vector
<MonCapGrant
>::const_iterator p
= grants
.begin(); p
!= grants
.end(); ++p
)
409 if (p
->is_allow_all())
414 void MonCap::set_allow_all()
417 grants
.push_back(MonCapGrant(MON_CAP_ANY
));
421 bool MonCap::is_capable(
425 const string
& service
,
426 const string
& command
, const map
<string
,string
>& command_args
,
427 bool op_may_read
, bool op_may_write
, bool op_may_exec
,
428 const entity_addr_t
& addr
) const
431 ldout(cct
, 20) << "is_capable service=" << service
<< " command=" << command
432 << (op_may_read
? " read":"")
433 << (op_may_write
? " write":"")
434 << (op_may_exec
? " exec":"")
436 << " on cap " << *this
439 mon_rwxa_t allow
= 0;
440 for (vector
<MonCapGrant
>::const_iterator p
= grants
.begin();
441 p
!= grants
.end(); ++p
) {
443 ldout(cct
, 20) << " allow so far " << allow
<< ", doing grant " << *p
446 if (p
->network
.size() &&
447 (!p
->network_valid
||
448 !network_contains(p
->network_parsed
,
454 if (p
->is_allow_all()) {
456 ldout(cct
, 20) << " allow all" << dendl
;
460 // check enumerated caps
461 allow
= allow
| p
->get_allowed(cct
, daemon_type
, name
, service
, command
,
463 if ((!op_may_read
|| (allow
& MON_CAP_R
)) &&
464 (!op_may_write
|| (allow
& MON_CAP_W
)) &&
465 (!op_may_exec
|| (allow
& MON_CAP_X
))) {
467 ldout(cct
, 20) << " match" << dendl
;
474 void MonCap::encode(bufferlist
& bl
) const
476 ENCODE_START(4, 4, bl
); // legacy MonCaps was 3, 3
481 void MonCap::decode(bufferlist::const_iterator
& bl
)
490 void MonCap::dump(Formatter
*f
) const
492 f
->dump_string("text", text
);
495 void MonCap::generate_test_instances(list
<MonCap
*>& ls
)
497 ls
.push_back(new MonCap
);
498 ls
.push_back(new MonCap
);
499 ls
.back()->parse("allow *");
500 ls
.push_back(new MonCap
);
501 ls
.back()->parse("allow rwx");
502 ls
.push_back(new MonCap
);
503 ls
.back()->parse("allow service foo x");
504 ls
.push_back(new MonCap
);
505 ls
.back()->parse("allow command bar x");
506 ls
.push_back(new MonCap
);
507 ls
.back()->parse("allow service foo r, allow command bar x");
508 ls
.push_back(new MonCap
);
509 ls
.back()->parse("allow command bar with k1=v1 x");
510 ls
.push_back(new MonCap
);
511 ls
.back()->parse("allow command bar with k1=v1 k2=v2 x");
515 namespace qi
= boost::spirit::qi
;
516 namespace ascii
= boost::spirit::ascii
;
517 namespace phoenix
= boost::phoenix
;
520 template <typename Iterator
>
521 struct MonCapParser
: qi::grammar
<Iterator
, MonCap()>
523 MonCapParser() : MonCapParser::base_type(moncap
)
527 using qi::ulong_long
;
538 lexeme
['"' >> +(char_
- '"') >> '"'] |
539 lexeme
['\'' >> +(char_
- '\'') >> '\''];
540 unquoted_word
%= +char_("a-zA-Z0-9_./-");
541 str
%= quoted_string
| unquoted_word
;
542 network_str
%= +char_("/.:a-fA-F0-9][");
544 spaces
= +(lit(' ') | lit('\n') | lit('\t'));
546 // command := command[=]cmd [k1=v1 k2=v2 ...]
547 str_match
= '=' >> qi::attr(StringConstraint::MATCH_TYPE_EQUAL
) >> str
;
548 str_prefix
= spaces
>> lit("prefix") >> spaces
>>
549 qi::attr(StringConstraint::MATCH_TYPE_PREFIX
) >> str
;
550 str_regex
= spaces
>> lit("regex") >> spaces
>>
551 qi::attr(StringConstraint::MATCH_TYPE_REGEX
) >> str
;
552 kv_pair
= str
>> (str_match
| str_prefix
| str_regex
);
553 kv_map
%= kv_pair
>> *(spaces
>> kv_pair
);
554 command_match
= -spaces
>> lit("allow") >> spaces
>> lit("command") >> (lit('=') | spaces
)
555 >> qi::attr(string()) >> qi::attr(string())
557 >> -(spaces
>> lit("with") >> spaces
>> kv_map
)
559 >> -(spaces
>> lit("network") >> spaces
>> network_str
);
562 service_match
%= -spaces
>> lit("allow") >> spaces
>> lit("service") >> (lit('=') | spaces
)
563 >> str
>> qi::attr(string()) >> qi::attr(string())
564 >> qi::attr(map
<string
,StringConstraint
>())
566 >> -(spaces
>> lit("network") >> spaces
>> network_str
);
569 profile_match
%= -spaces
>> -(lit("allow") >> spaces
)
570 >> lit("profile") >> (lit('=') | spaces
)
571 >> qi::attr(string())
573 >> qi::attr(string())
574 >> qi::attr(map
<string
,StringConstraint
>())
576 >> -(spaces
>> lit("network") >> spaces
>> network_str
);
579 rwxa_match
%= -spaces
>> lit("allow") >> spaces
580 >> qi::attr(string()) >> qi::attr(string()) >> qi::attr(string())
581 >> qi::attr(map
<string
,StringConstraint
>())
583 >> -(spaces
>> lit("network") >> spaces
>> network_str
);
585 // rwxa := * | [r][w][x]
587 (lit("*")[_val
= MON_CAP_ANY
]) |
588 (lit("all")[_val
= MON_CAP_ANY
]) |
590 ( lit('r')[_val
|= MON_CAP_R
] ||
591 lit('w')[_val
|= MON_CAP_W
] ||
592 lit('x')[_val
|= MON_CAP_X
]
596 // grant := allow ...
597 grant
= -spaces
>> (rwxa_match
| profile_match
| service_match
| command_match
) >> -spaces
;
599 // moncap := grant [grant ...]
600 grants
%= (grant
% (*lit(' ') >> (lit(';') | lit(',')) >> *lit(' ')));
601 moncap
= grants
[_val
= phoenix::construct
<MonCap
>(_1
)];
604 qi::rule
<Iterator
> spaces
;
605 qi::rule
<Iterator
, unsigned()> rwxa
;
606 qi::rule
<Iterator
, string()> quoted_string
;
607 qi::rule
<Iterator
, string()> unquoted_word
;
608 qi::rule
<Iterator
, string()> str
, network_str
;
610 qi::rule
<Iterator
, StringConstraint()> str_match
, str_prefix
, str_regex
;
611 qi::rule
<Iterator
, pair
<string
, StringConstraint
>()> kv_pair
;
612 qi::rule
<Iterator
, map
<string
, StringConstraint
>()> kv_map
;
614 qi::rule
<Iterator
, MonCapGrant()> rwxa_match
;
615 qi::rule
<Iterator
, MonCapGrant()> command_match
;
616 qi::rule
<Iterator
, MonCapGrant()> service_match
;
617 qi::rule
<Iterator
, MonCapGrant()> profile_match
;
618 qi::rule
<Iterator
, MonCapGrant()> grant
;
619 qi::rule
<Iterator
, std::vector
<MonCapGrant
>()> grants
;
620 qi::rule
<Iterator
, MonCap()> moncap
;
623 bool MonCap::parse(const string
& str
, ostream
*err
)
625 auto iter
= str
.begin();
626 auto end
= str
.end();
628 MonCapParser
<string::const_iterator
> exp
;
629 bool r
= qi::parse(iter
, end
, exp
, *this);
630 if (r
&& iter
== end
) {
632 for (auto& g
: grants
) {
638 // Make sure no grants are kept after parsing failed!
643 *err
<< "mon capability parse failed, stopped at '"
644 << std::string(iter
, end
)
645 << "' of '" << str
<< "'";
647 *err
<< "mon capability parse failed, stopped at end of '" << str
<< "'";