forked from scylladb/python-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsecurity.html
More file actions
964 lines (914 loc) · 70 KB
/
Copy pathsecurity.html
File metadata and controls
964 lines (914 loc) · 70 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
<!DOCTYPE html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width initial-scale=1" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title> Security | Scylla Docs
</title>
<meta name="description" content="Scylla is an Apache Cassandra-compatible NoSQL data store that can handle 1 million transactions per second on a single server." />
<link
rel="icon"
href="_static/img/favicon.ico"
type="image/x-icon"
/>
<link
rel="icon"
href="_static/img/favicon-32x32.png"
sizes="32x32"
/>
<link
rel="icon"
href="_static/img/favicon-228x228.png"
sizes="192x192"
/>
<link
rel="apple-touch-icon"
href="_static/img/favicon-228x228.png"
/>
<meta
name="msapplication-TileImage"
href="_static/img/favicon-228x228.png"
/>
<link rel="canonical" href="https://docs.scylladb.com/" />
<link rel="author" href="mailto:info@scylladb.com" />
<!-- connect to domain of font files -->
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<!-- optionally increase loading priority -->
<link
rel="preload"
as="style"
href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,400;0,500;0,700;1,400&display=swap"
/>
<!-- async CSS -->
<link
rel="stylesheet"
media="print"
onload="this.onload=null;this.removeAttribute('media');"
href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,400;0,500;0,700;1,400&display=swap"
/>
<!-- no-JS fallback -->
<noscript>
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,400;0,500;0,700;1,400&display=swap"
/>
</noscript>
<link
rel="stylesheet"
href="_static/css/main.css"
type="text/css"
/>
<link
rel="stylesheet"
href="_static/pygments.css"
type="text/css"
/> <link rel="stylesheet" type="text/css" href="_static/copybutton.css" />
<script
type="text/javascript"
id="documentation_options"
data-url_root="./"
src="_static/documentation_options.js"
></script>
<script
type="text/javascript"
src="_static/js/runtime.bundle.js"
></script>
<script
type="text/javascript"
src="_static/js/main.bundle.js"
></script> <script src="_static/underscore.js"></script> <script src="_static/doctools.js"></script> <script src="_static/language_data.js"></script> <script src="_static/clipboard.min.js"></script> <script src="_static/copybutton.js"></script>
<!-- Google Tag Manager -->
<script>
(function (w, d, s, l, i) {
w[l] = w[l] || [];
w[l].push({ "gtm.start": new Date().getTime(), event: "gtm.js" });
var f = d.getElementsByTagName(s)[0],
j = d.createElement(s),
dl = l != "dataLayer" ? "&l=" + l : "";
j.async = true;
j.src = "https://www.googletagmanager.com/gtm.js?id=" + i + dl;
f.parentNode.insertBefore(j, f);
})(window, document, "script", "dataLayer", "GTM-T8P2JP");
</script>
<!-- End Google Tag Manager -->
<!-- Marketo -->
<script type="text/javascript">
(function () {
var didInit = false;
function initMunchkin() {
if (didInit === false) {
didInit = true;
Munchkin.init("791-QBF-350");
}
}
var s = document.createElement("script");
s.type = "text/javascript";
s.async = true;
s.src = "//munchkin.marketo.net/munchkin.js";
s.onreadystatechange = function () {
if (this.readyState == "complete" || this.readyState == "loaded") {
initMunchkin();
}
};
s.onload = initMunchkin;
document.getElementsByTagName("head")[0].appendChild(s);
})();
</script>
<!-- End Marketo -->
<!-- Expertrec -->
<script>
var id = "e2077224-9ccf-11e9-a0c9-0242ac130002";
var ci_search = document.createElement("script");
ci_search.type = "text/javascript";
ci_search.async = true;
ci_search.src = "https://cse.expertrec.com/api/js/ci_common.js?id=" + id;
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(ci_search, s);
</script>
<!-- End Expertrec -->
<!-- Font Awesome -->
<script
src="https://kit.fontawesome.com/b1870adf6a.js"
crossorigin="anonymous"
></script>
<!-- End Font Awesome -->
</head>
<body>
<header class="header">
<div class="header-logo">
<a class="header-logo__img" href="https://scylladb.com/">
<img
src="_static/img/logo-scylla-docs.svg"
alt="Scylla Documentation Logo"
/>
</a>
<span class="header-logo__bar"></span>
<a class="header-logo__text" href="https://docs.scylladb.com/">
Documentation
</a>
</div>
<div class="header-navigation">
<ul
class="dropdown menu scylla-dropdown scylla-dropdown--header"
data-dropdown-menu
>
<li class="scylla-dropdown__item">
<a href="#" class="scylla-dropdown__title"
>Server <i class="chevron scylla-icon scylla-icon--triangle-down"></i
></a>
<ul class="menu scylla-dropdown__content">
<li>
<a href="https://docs.scylladb.com/"
><i class="scylla-icon scylla-icon--about-us"></i>Scylla Open
Source</a
>
</li>
<li>
<a href="https://docs.scylladb.com/"
><i class="scylla-icon scylla-icon--enterprise"></i>Scylla
Enterprise</a
>
</li>
<li>
<a
href="https://scylla.docs.scylladb.com/master/alternator/alternator.html"
>
<i class="scylla-icon scylla-icon--overview"></i>Scylla
Alternator</a
>
</li>
</ul>
</li>
<li class="scylla-dropdown__item">
<a href="#" class="scylla-dropdown__title"
>Cloud <i class="chevron scylla-icon scylla-icon--triangle-down"></i
></a>
<ul class="menu scylla-dropdown__content">
<li>
<a href="https://cloud.scylladb.com/">
<i class="scylla-icon scylla-icon--cloud"></i>Scylla Cloud</a
>
</li>
<li>
<a href="https://docs.scylladb.com/scylla-cloud/">
<i class="scylla-icon scylla-icon--cloud-docs"></i>Scylla Cloud
Docs</a
>
</li>
</ul>
</li>
<li class="scylla-dropdown__item">
<a href="#" class="scylla-dropdown__title"
>Tools <i class="chevron scylla-icon scylla-icon--triangle-down"></i
></a>
<ul class="menu scylla-dropdown__content">
<li>
<a href="https://manager.docs.scylladb.com/">
<i class="scylla-icon scylla-icon--manager"></i>Scylla Manager</a
>
</li>
<li>
<a href="https://monitoring.docs.scylladb.com/">
<i class="scylla-icon scylla-icon--monitoring"></i>Scylla
Monitoring Stack</a
>
</li>
<li>
<a href="https://operator.docs.scylladb.com/">
<i class="scylla-icon scylla-icon--operator"></i>Scylla Operator
</a>
</li>
</ul>
</li>
<li class="scylla-dropdown__item">
<a href="#" class="scylla-dropdown__title"
>Drivers <i class="chevron scylla-icon scylla-icon--triangle-down"></i
></a>
<ul class="menu scylla-dropdown__content">
<li>
<a
href="https://docs.scylladb.com/using-scylla/drivers/cql-drivers/"
>
<i class="scylla-icon scylla-icon--nsql-guides"></i>CQL Drivers
</a>
</li>
<li>
<a
href="https://docs.scylladb.com/using-scylla/drivers/dynamo-drivers/"
>
<i class="scylla-icon scylla-icon--overview"></i>DynamoDB Drivers
</a>
</li>
</ul>
</li>
</ul>
<div class="header-button">
<a href="https://www.scylladb.com/download/" class="button">Download</a>
</div>
</div>
<div class="header-search-box">
<div class="search-box">
<ci-search></ci-search>
</div>
</div>
<div class="side-nav-toggle" data-toggle="side-nav">
<div class="side-nav-toggle__button">
<img src="_static/img/menu.svg" alt="Menu" />
</div>
</div>
</header>
<section class="layout ">
<div class="content large-order-2">
<div class="admonition caution">
<p class="admonition-title">Caution</p>
<p>
You are not reading the latest stable version of this documentation.
If you want up-to-date information, please have a look at
<a href="../stable/security.html">
3.25.1</a
>.
</p>
</div>
<div class="pre-content">
<div class="pre-content__left"><div class="breadcrumbs">
<span class="bread__item">
<a
href="index.html"
class="bread__highlight"
>
<i class="fas fa-home"></i> Cassandra Driver</a
></span
>
<span class="bread__item bread__item--last">Security</span>
</div></div>
<div class="pre-content__right"><ul
class="dropdown menu scylla-dropdown scylla-dropdown--contribute"
data-dropdown-menu
>
<li class="scylla-dropdown__item">
<a class="scylla-dropdown__title" href="#">
<div class="scylla-dropdown__title--body">
<i class="icon fa fa-github" aria-hidden="true"></i>
Contribute
</div>
<i class="chevron scylla-icon scylla-icon--chevron-right"></i>
</a>
<ul class="menu scylla-dropdown__content">
<li>
<a
href="https://github.com/scylladb/python-driver/issues/new?title=Issue in page Security&&body=I%20would%20like%20to%20report%20an%20issue%20in%20page%20https://python-driver.docs.scylladb.com/master/security%0A%0A%23%23%23%20Problem%0A%0A%23%23%23%20%20Suggest%20a%20fix"
target="_blank"
>Report a doc issue
<i class="icon fa fa-external-link" aria-hidden="true"></i
></a>
</li>
<li>
<a
href="https://github.com/scylladb/python-driver/edit/master/docs/security.rst"
target="_blank"
>Edit this page
<i class="icon fa fa-external-link" aria-hidden="true"></i
></a>
</li>
<li>
<a href="https://docs.scylladb.com/contribute/" target="_blank"
>Learn how to contribute
<i class="icon fa fa-external-link" aria-hidden="true"></i
></a>
</li>
</ul>
</li>
</ul></div>
</div>
<div class="section" id="security">
<span id="id1"></span><h1>Security<a class="headerlink" href="#security" title="Permalink to this headline">¶</a></h1>
<p>The two main security components you will use with the
Python driver are Authentication and SSL.</p>
<div class="section" id="authentication">
<h2>Authentication<a class="headerlink" href="#authentication" title="Permalink to this headline">¶</a></h2>
<p>Versions 2.0 and higher of the driver support a SASL-based
authentication mechanism when <a class="reference internal" href="api/cassandra/cluster.html#cassandra.cluster.Cluster.protocol_version" title="cassandra.cluster.Cluster.protocol_version"><code class="xref py py-attr docutils literal notranslate"><span class="pre">protocol_version</span></code></a>
is set to 2 or higher. To use this authentication, set
<a class="reference internal" href="api/cassandra/cluster.html#cassandra.cluster.Cluster.auth_provider" title="cassandra.cluster.Cluster.auth_provider"><code class="xref py py-attr docutils literal notranslate"><span class="pre">auth_provider</span></code></a> to an instance of a subclass
of <a class="reference internal" href="api/cassandra/auth.html#cassandra.auth.AuthProvider" title="cassandra.auth.AuthProvider"><code class="xref py py-class docutils literal notranslate"><span class="pre">AuthProvider</span></code></a>. When working
with Cassandra’s <code class="docutils literal notranslate"><span class="pre">PasswordAuthenticator</span></code>, you can use
the <a class="reference internal" href="api/cassandra/auth.html#cassandra.auth.PlainTextAuthProvider" title="cassandra.auth.PlainTextAuthProvider"><code class="xref py py-class docutils literal notranslate"><span class="pre">PlainTextAuthProvider</span></code></a> class.</p>
<p>For example, suppose Cassandra is setup with its default
‘cassandra’ user with a password of ‘cassandra’:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">cassandra.cluster</span> <span class="kn">import</span> <span class="n">Cluster</span>
<span class="kn">from</span> <span class="nn">cassandra.auth</span> <span class="kn">import</span> <span class="n">PlainTextAuthProvider</span>
<span class="n">auth_provider</span> <span class="o">=</span> <span class="n">PlainTextAuthProvider</span><span class="p">(</span><span class="n">username</span><span class="o">=</span><span class="s1">'cassandra'</span><span class="p">,</span> <span class="n">password</span><span class="o">=</span><span class="s1">'cassandra'</span><span class="p">)</span>
<span class="n">cluster</span> <span class="o">=</span> <span class="n">Cluster</span><span class="p">(</span><span class="n">auth_provider</span><span class="o">=</span><span class="n">auth_provider</span><span class="p">,</span> <span class="n">protocol_version</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
</pre></div>
</div>
<div class="section" id="custom-authenticators">
<h3>Custom Authenticators<a class="headerlink" href="#custom-authenticators" title="Permalink to this headline">¶</a></h3>
<p>If you’re using something other than Cassandra’s <code class="docutils literal notranslate"><span class="pre">PasswordAuthenticator</span></code>,
<a class="reference internal" href="api/cassandra/auth.html#cassandra.auth.SaslAuthProvider" title="cassandra.auth.SaslAuthProvider"><code class="xref py py-class docutils literal notranslate"><span class="pre">SaslAuthProvider</span></code></a> is provided for generic SASL authentication mechanisms,
utilizing the <code class="docutils literal notranslate"><span class="pre">pure-sasl</span></code> package.
If these do not suit your needs, you may need to create your own subclasses of
<a class="reference internal" href="api/cassandra/auth.html#cassandra.auth.AuthProvider" title="cassandra.auth.AuthProvider"><code class="xref py py-class docutils literal notranslate"><span class="pre">AuthProvider</span></code></a> and <a class="reference internal" href="api/cassandra/auth.html#cassandra.auth.Authenticator" title="cassandra.auth.Authenticator"><code class="xref py py-class docutils literal notranslate"><span class="pre">Authenticator</span></code></a>. You can use the Sasl classes
as example implementations.</p>
</div>
<div class="section" id="protocol-v1-authentication">
<h3>Protocol v1 Authentication<a class="headerlink" href="#protocol-v1-authentication" title="Permalink to this headline">¶</a></h3>
<p>When working with Cassandra 1.2 (or a higher version with
<a class="reference internal" href="api/cassandra/cluster.html#cassandra.cluster.Cluster.protocol_version" title="cassandra.cluster.Cluster.protocol_version"><code class="xref py py-attr docutils literal notranslate"><span class="pre">protocol_version</span></code></a> set to <code class="docutils literal notranslate"><span class="pre">1</span></code>), you will not pass in
an <a class="reference internal" href="api/cassandra/auth.html#cassandra.auth.AuthProvider" title="cassandra.auth.AuthProvider"><code class="xref py py-class docutils literal notranslate"><span class="pre">AuthProvider</span></code></a> instance. Instead, you should pass in a
function that takes one argument, the IP address of a host, and returns
a dict of credentials with a <code class="docutils literal notranslate"><span class="pre">username</span></code> and <code class="docutils literal notranslate"><span class="pre">password</span></code> key:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">cassandra.cluster</span> <span class="kn">import</span> <span class="n">Cluster</span>
<span class="k">def</span> <span class="nf">get_credentials</span><span class="p">(</span><span class="n">host_address</span><span class="p">):</span>
<span class="k">return</span> <span class="p">{</span><span class="s1">'username'</span><span class="p">:</span> <span class="s1">'joe'</span><span class="p">,</span> <span class="s1">'password'</span><span class="p">:</span> <span class="s1">'1234'</span><span class="p">}</span>
<span class="n">cluster</span> <span class="o">=</span> <span class="n">Cluster</span><span class="p">(</span><span class="n">auth_provider</span><span class="o">=</span><span class="n">get_credentials</span><span class="p">,</span> <span class="n">protocol_version</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="ssl">
<h2>SSL<a class="headerlink" href="#ssl" title="Permalink to this headline">¶</a></h2>
<p>SSL should be used when client encryption is enabled in Cassandra.</p>
<p>To give you as much control as possible over your SSL configuration, our SSL
API takes a user-created <cite>SSLContext</cite> instance from the Python standard library.
These docs will include some examples for how to achieve common configurations,
but the <a class="reference external" href="https://docs.python.org/3/library/ssl.html#ssl.SSLContext">ssl.SSLContext</a> documentation
gives a more complete description of what is possible.</p>
<p>To enable SSL with version 3.17.0 and higher, you will need to set <a class="reference internal" href="api/cassandra/cluster.html#cassandra.cluster.Cluster.ssl_context" title="cassandra.cluster.Cluster.ssl_context"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Cluster.ssl_context</span></code></a> to a
<code class="docutils literal notranslate"><span class="pre">ssl.SSLContext</span></code> instance to enable SSL. Optionally, you can also set <a class="reference internal" href="api/cassandra/cluster.html#cassandra.cluster.Cluster.ssl_options" title="cassandra.cluster.Cluster.ssl_options"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Cluster.ssl_options</span></code></a>
to a dict of options. These will be passed as kwargs to <code class="docutils literal notranslate"><span class="pre">ssl.SSLContext.wrap_socket()</span></code>
when new sockets are created.</p>
<p>If you create your SSLContext using <a class="reference external" href="https://docs.python.org/3/library/ssl.html#ssl.create_default_context">ssl.create_default_context</a>,
be aware that SSLContext.check_hostname is set to True by default, so the hostname validation will be done
by Python and not the driver. For this reason, we need to set the server_hostname at best effort, which is the
resolved ip address. If this validation needs to be done against the FQDN, consider enabling it using the ssl_options
as described in the following examples or implement your own <a class="reference internal" href="api/cassandra/connection.html#cassandra.connection.EndPoint" title="cassandra.connection.EndPoint"><code class="xref py py-class docutils literal notranslate"><span class="pre">EndPoint</span></code></a> and
<a class="reference internal" href="api/cassandra/connection.html#cassandra.connection.EndPointFactory" title="cassandra.connection.EndPointFactory"><code class="xref py py-class docutils literal notranslate"><span class="pre">EndPointFactory</span></code></a>.</p>
<p>The following examples assume you have generated your Cassandra certificate and
keystore files with these intructions:</p>
<ul class="simple">
<li><p><a class="reference external" href="https://docs.datastax.com/en/dse/6.7/dse-admin/datastax_enterprise/security/secSetUpSSLCert.html">Setup SSL Cert</a></p></li>
</ul>
<p>It might be also useful to learn about the different levels of identity verification to understand the examples:</p>
<ul class="simple">
<li><p><a class="reference external" href="https://docs.datastax.com/en/dse/6.7/dse-dev/datastax_enterprise/appDevGuide/sslDrivers.html">Using SSL in DSE drivers</a></p></li>
</ul>
<div class="section" id="ssl-with-twisted-or-eventlet">
<h3>SSL with Twisted or Eventlet<a class="headerlink" href="#ssl-with-twisted-or-eventlet" title="Permalink to this headline">¶</a></h3>
<p>Twisted and Eventlet both use an alternative SSL implementation called pyOpenSSL, so if your <cite>Cluster</cite>’s connection class is
<a class="reference internal" href="api/cassandra/io/twistedreactor.html#cassandra.io.twistedreactor.TwistedConnection" title="cassandra.io.twistedreactor.TwistedConnection"><code class="xref py py-class docutils literal notranslate"><span class="pre">TwistedConnection</span></code></a> or <a class="reference internal" href="api/cassandra/io/eventletreactor.html#cassandra.io.eventletreactor.EventletConnection" title="cassandra.io.eventletreactor.EventletConnection"><code class="xref py py-class docutils literal notranslate"><span class="pre">EventletConnection</span></code></a>, you must pass a
<a class="reference external" href="https://www.pyopenssl.org/en/stable/api/ssl.html#context-objects">pyOpenSSL context</a> instead.
An example is provided in these docs, and more details can be found in the
<a class="reference external" href="https://www.pyopenssl.org/en/stable/api/ssl.html#context-objects">documentation</a>.
pyOpenSSL is not installed by the driver and must be installed separately.</p>
</div>
<div class="section" id="ssl-configuration-examples">
<h3>SSL Configuration Examples<a class="headerlink" href="#ssl-configuration-examples" title="Permalink to this headline">¶</a></h3>
<p>Here, we’ll describe the server and driver configuration necessary to set up SSL to meet various goals, such as the client verifying the server and the server verifying the client. We’ll also include Python code demonstrating how to use servers and drivers configured in these ways.</p>
<div class="section" id="no-identity-verification">
<span id="ssl-no-identify-verification"></span><h4>No identity verification<a class="headerlink" href="#no-identity-verification" title="Permalink to this headline">¶</a></h4>
<p>No identity verification at all. Note that this is not recommended for for production deployments.</p>
<p>The Cassandra configuration:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">client_encryption_options</span><span class="p">:</span>
<span class="n">enabled</span><span class="p">:</span> <span class="n">true</span>
<span class="n">keystore</span><span class="p">:</span> <span class="o">/</span><span class="n">path</span><span class="o">/</span><span class="n">to</span><span class="o">/</span><span class="mf">127.0.0.1</span><span class="o">.</span><span class="n">keystore</span>
<span class="n">keystore_password</span><span class="p">:</span> <span class="n">myStorePass</span>
<span class="n">require_client_auth</span><span class="p">:</span> <span class="n">false</span>
</pre></div>
</div>
<p>The driver configuration:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">cassandra.cluster</span> <span class="kn">import</span> <span class="n">Cluster</span><span class="p">,</span> <span class="n">Session</span>
<span class="kn">from</span> <span class="nn">ssl</span> <span class="kn">import</span> <span class="n">SSLContext</span><span class="p">,</span> <span class="n">PROTOCOL_TLS</span>
<span class="n">ssl_context</span> <span class="o">=</span> <span class="n">SSLContext</span><span class="p">(</span><span class="n">PROTOCOL_TLS</span><span class="p">)</span>
<span class="n">cluster</span> <span class="o">=</span> <span class="n">Cluster</span><span class="p">([</span><span class="s1">'127.0.0.1'</span><span class="p">],</span> <span class="n">ssl_context</span><span class="o">=</span><span class="n">ssl_context</span><span class="p">)</span>
<span class="n">session</span> <span class="o">=</span> <span class="n">cluster</span><span class="o">.</span><span class="n">connect</span><span class="p">()</span>
</pre></div>
</div>
</div>
<div class="section" id="client-verifies-server">
<span id="ssl-client-verifies-server"></span><h4>Client verifies server<a class="headerlink" href="#client-verifies-server" title="Permalink to this headline">¶</a></h4>
<p>Ensure the python driver verifies the identity of the server.</p>
<p>The Cassandra configuration:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">client_encryption_options</span><span class="p">:</span>
<span class="n">enabled</span><span class="p">:</span> <span class="n">true</span>
<span class="n">keystore</span><span class="p">:</span> <span class="o">/</span><span class="n">path</span><span class="o">/</span><span class="n">to</span><span class="o">/</span><span class="mf">127.0.0.1</span><span class="o">.</span><span class="n">keystore</span>
<span class="n">keystore_password</span><span class="p">:</span> <span class="n">myStorePass</span>
<span class="n">require_client_auth</span><span class="p">:</span> <span class="n">false</span>
</pre></div>
</div>
<p>For the driver configuration, it’s very important to set <cite>ssl_context.verify_mode</cite>
to <cite>CERT_REQUIRED</cite>. Otherwise, the loaded verify certificate will have no effect:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">cassandra.cluster</span> <span class="kn">import</span> <span class="n">Cluster</span><span class="p">,</span> <span class="n">Session</span>
<span class="kn">from</span> <span class="nn">ssl</span> <span class="kn">import</span> <span class="n">SSLContext</span><span class="p">,</span> <span class="n">PROTOCOL_TLS</span><span class="p">,</span> <span class="n">CERT_REQUIRED</span>
<span class="n">ssl_context</span> <span class="o">=</span> <span class="n">SSLContext</span><span class="p">(</span><span class="n">PROTOCOL_TLS</span><span class="p">)</span>
<span class="n">ssl_context</span><span class="o">.</span><span class="n">load_verify_locations</span><span class="p">(</span><span class="s1">'/path/to/rootca.crt'</span><span class="p">)</span>
<span class="n">ssl_context</span><span class="o">.</span><span class="n">verify_mode</span> <span class="o">=</span> <span class="n">CERT_REQUIRED</span>
<span class="n">cluster</span> <span class="o">=</span> <span class="n">Cluster</span><span class="p">([</span><span class="s1">'127.0.0.1'</span><span class="p">],</span> <span class="n">ssl_context</span><span class="o">=</span><span class="n">ssl_context</span><span class="p">)</span>
<span class="n">session</span> <span class="o">=</span> <span class="n">cluster</span><span class="o">.</span><span class="n">connect</span><span class="p">()</span>
</pre></div>
</div>
<p>Additionally, you can also force the driver to verify the <cite>hostname</cite> of the server by passing additional options to <cite>ssl_context.wrap_socket</cite> via the <cite>ssl_options</cite> kwarg:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">cassandra.cluster</span> <span class="kn">import</span> <span class="n">Cluster</span><span class="p">,</span> <span class="n">Session</span>
<span class="kn">from</span> <span class="nn">ssl</span> <span class="kn">import</span> <span class="n">SSLContext</span><span class="p">,</span> <span class="n">PROTOCOL_TLS</span><span class="p">,</span> <span class="n">CERT_REQUIRED</span>
<span class="n">ssl_context</span> <span class="o">=</span> <span class="n">SSLContext</span><span class="p">(</span><span class="n">PROTOCOL_TLS</span><span class="p">)</span>
<span class="n">ssl_context</span><span class="o">.</span><span class="n">load_verify_locations</span><span class="p">(</span><span class="s1">'/path/to/rootca.crt'</span><span class="p">)</span>
<span class="n">ssl_context</span><span class="o">.</span><span class="n">verify_mode</span> <span class="o">=</span> <span class="n">CERT_REQUIRED</span>
<span class="n">ssl_context</span><span class="o">.</span><span class="n">check_hostname</span> <span class="o">=</span> <span class="kc">True</span>
<span class="n">ssl_options</span> <span class="o">=</span> <span class="p">{</span><span class="s1">'server_hostname'</span><span class="p">:</span> <span class="s1">'127.0.0.1'</span><span class="p">}</span>
<span class="n">cluster</span> <span class="o">=</span> <span class="n">Cluster</span><span class="p">([</span><span class="s1">'127.0.0.1'</span><span class="p">],</span> <span class="n">ssl_context</span><span class="o">=</span><span class="n">ssl_context</span><span class="p">,</span> <span class="n">ssl_options</span><span class="o">=</span><span class="n">ssl_options</span><span class="p">)</span>
<span class="n">session</span> <span class="o">=</span> <span class="n">cluster</span><span class="o">.</span><span class="n">connect</span><span class="p">()</span>
</pre></div>
</div>
</div>
<div class="section" id="server-verifies-client">
<span id="ssl-server-verifies-client"></span><h4>Server verifies client<a class="headerlink" href="#server-verifies-client" title="Permalink to this headline">¶</a></h4>
<p>If Cassandra is configured to verify clients (<code class="docutils literal notranslate"><span class="pre">require_client_auth</span></code>), you need to generate
SSL key and certificate files.</p>
<p>The cassandra configuration:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">client_encryption_options</span><span class="p">:</span>
<span class="n">enabled</span><span class="p">:</span> <span class="n">true</span>
<span class="n">keystore</span><span class="p">:</span> <span class="o">/</span><span class="n">path</span><span class="o">/</span><span class="n">to</span><span class="o">/</span><span class="mf">127.0.0.1</span><span class="o">.</span><span class="n">keystore</span>
<span class="n">keystore_password</span><span class="p">:</span> <span class="n">myStorePass</span>
<span class="n">require_client_auth</span><span class="p">:</span> <span class="n">true</span>
<span class="n">truststore</span><span class="p">:</span> <span class="o">/</span><span class="n">path</span><span class="o">/</span><span class="n">to</span><span class="o">/</span><span class="n">dse</span><span class="o">-</span><span class="n">truststore</span><span class="o">.</span><span class="n">jks</span>
<span class="n">truststore_password</span><span class="p">:</span> <span class="n">myStorePass</span>
</pre></div>
</div>
<p>The Python <code class="docutils literal notranslate"><span class="pre">ssl</span></code> APIs require the certificate in PEM format. First, create a certificate
conf file:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>cat > gen_client_cert.conf <span class="s"><<EOF</span>
<span class="s">[ req ]</span>
<span class="s">distinguished_name = req_distinguished_name</span>
<span class="s">prompt = no</span>
<span class="s">output_password = ${ROOT_CERT_PASS}</span>
<span class="s">default_bits = 2048</span>
<span class="s">[ req_distinguished_name ]</span>
<span class="s">C = ${CERT_COUNTRY}</span>
<span class="s">O = ${CERT_ORG_NAME}</span>
<span class="s">OU = ${CERT_OU}</span>
<span class="s">CN = client</span>
<span class="s">EOF</span>
</pre></div>
</div>
<p>Make sure you replaced the variables with the same values you used for the initial
root CA certificate. Then, generate the key:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>openssl req -newkey rsa:2048 -nodes -keyout client.key -out client.csr -config gen_client_cert.conf
</pre></div>
</div>
<p>And generate the client signed certificate:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>openssl x509 -req -CA <span class="si">${</span><span class="nv">ROOT_CA_BASE_NAME</span><span class="si">}</span>.crt -CAkey <span class="si">${</span><span class="nv">ROOT_CA_BASE_NAME</span><span class="si">}</span>.key -passin pass:<span class="si">${</span><span class="nv">ROOT_CERT_PASS</span><span class="si">}</span> <span class="se">\</span>
-in client.csr -out client.crt_signed -days <span class="si">${</span><span class="nv">CERT_VALIDITY</span><span class="si">}</span> -CAcreateserial
</pre></div>
</div>
<p>Finally, you can use that configuration with the following driver code:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">cassandra.cluster</span> <span class="kn">import</span> <span class="n">Cluster</span><span class="p">,</span> <span class="n">Session</span>
<span class="kn">from</span> <span class="nn">ssl</span> <span class="kn">import</span> <span class="n">SSLContext</span><span class="p">,</span> <span class="n">PROTOCOL_TLS</span>
<span class="n">ssl_context</span> <span class="o">=</span> <span class="n">SSLContext</span><span class="p">(</span><span class="n">PROTOCOL_TLS</span><span class="p">)</span>
<span class="n">ssl_context</span><span class="o">.</span><span class="n">load_cert_chain</span><span class="p">(</span>
<span class="n">certfile</span><span class="o">=</span><span class="s1">'/path/to/client.crt_signed'</span><span class="p">,</span>
<span class="n">keyfile</span><span class="o">=</span><span class="s1">'/path/to/client.key'</span><span class="p">)</span>
<span class="n">cluster</span> <span class="o">=</span> <span class="n">Cluster</span><span class="p">([</span><span class="s1">'127.0.0.1'</span><span class="p">],</span> <span class="n">ssl_context</span><span class="o">=</span><span class="n">ssl_context</span><span class="p">)</span>
<span class="n">session</span> <span class="o">=</span> <span class="n">cluster</span><span class="o">.</span><span class="n">connect</span><span class="p">()</span>
</pre></div>
</div>
</div>
<div class="section" id="server-verifies-client-and-client-verifies-server">
<span id="ssl-server-client-verification"></span><h4>Server verifies client and client verifies server<a class="headerlink" href="#server-verifies-client-and-client-verifies-server" title="Permalink to this headline">¶</a></h4>
<p>See the previous section for examples of Cassandra configuration and preparing
the client certificates.</p>
<p>The following driver code specifies that the connection should use two-way verification:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">cassandra.cluster</span> <span class="kn">import</span> <span class="n">Cluster</span><span class="p">,</span> <span class="n">Session</span>
<span class="kn">from</span> <span class="nn">ssl</span> <span class="kn">import</span> <span class="n">SSLContext</span><span class="p">,</span> <span class="n">PROTOCOL_TLS</span><span class="p">,</span> <span class="n">CERT_REQUIRED</span>
<span class="n">ssl_context</span> <span class="o">=</span> <span class="n">SSLContext</span><span class="p">(</span><span class="n">PROTOCOL_TLS</span><span class="p">)</span>
<span class="n">ssl_context</span><span class="o">.</span><span class="n">load_verify_locations</span><span class="p">(</span><span class="s1">'/path/to/rootca.crt'</span><span class="p">)</span>
<span class="n">ssl_context</span><span class="o">.</span><span class="n">verify_mode</span> <span class="o">=</span> <span class="n">CERT_REQUIRED</span>
<span class="n">ssl_context</span><span class="o">.</span><span class="n">load_cert_chain</span><span class="p">(</span>
<span class="n">certfile</span><span class="o">=</span><span class="s1">'/path/to/client.crt_signed'</span><span class="p">,</span>
<span class="n">keyfile</span><span class="o">=</span><span class="s1">'/path/to/client.key'</span><span class="p">)</span>
<span class="n">cluster</span> <span class="o">=</span> <span class="n">Cluster</span><span class="p">([</span><span class="s1">'127.0.0.1'</span><span class="p">],</span> <span class="n">ssl_context</span><span class="o">=</span><span class="n">ssl_context</span><span class="p">)</span>
<span class="n">session</span> <span class="o">=</span> <span class="n">cluster</span><span class="o">.</span><span class="n">connect</span><span class="p">()</span>
</pre></div>
</div>
<p>The driver uses <code class="docutils literal notranslate"><span class="pre">SSLContext</span></code> directly to give you many other options in configuring SSL. Consider reading the <a class="reference external" href="https://docs.python.org/library/ssl.html#ssl.SSLContext">Python SSL documentation</a>
for more details about <code class="docutils literal notranslate"><span class="pre">SSLContext</span></code> configuration.</p>
<p><strong>Server verifies client and client verifies server using Twisted and pyOpenSSL</strong></p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">OpenSSL</span> <span class="kn">import</span> <span class="n">SSL</span><span class="p">,</span> <span class="n">crypto</span>
<span class="kn">from</span> <span class="nn">cassandra.cluster</span> <span class="kn">import</span> <span class="n">Cluster</span>
<span class="kn">from</span> <span class="nn">cassandra.io.twistedreactor</span> <span class="kn">import</span> <span class="n">TwistedConnection</span>
<span class="n">ssl_context</span> <span class="o">=</span> <span class="n">SSL</span><span class="o">.</span><span class="n">Context</span><span class="p">(</span><span class="n">SSL</span><span class="o">.</span><span class="n">TLSv1_2_METHOD</span><span class="p">)</span>
<span class="n">ssl_context</span><span class="o">.</span><span class="n">set_verify</span><span class="p">(</span><span class="n">SSL</span><span class="o">.</span><span class="n">VERIFY_PEER</span><span class="p">,</span> <span class="n">callback</span><span class="o">=</span><span class="k">lambda</span> <span class="n">_1</span><span class="p">,</span> <span class="n">_2</span><span class="p">,</span> <span class="n">_3</span><span class="p">,</span> <span class="n">_4</span><span class="p">,</span> <span class="n">ok</span><span class="p">:</span> <span class="n">ok</span><span class="p">)</span>
<span class="n">ssl_context</span><span class="o">.</span><span class="n">use_certificate_file</span><span class="p">(</span><span class="s1">'/path/to/client.crt_signed'</span><span class="p">)</span>
<span class="n">ssl_context</span><span class="o">.</span><span class="n">use_privatekey_file</span><span class="p">(</span><span class="s1">'/path/to/client.key'</span><span class="p">)</span>
<span class="n">ssl_context</span><span class="o">.</span><span class="n">load_verify_locations</span><span class="p">(</span><span class="s1">'/path/to/rootca.crt'</span><span class="p">)</span>
<span class="n">cluster</span> <span class="o">=</span> <span class="n">Cluster</span><span class="p">(</span>
<span class="n">contact_points</span><span class="o">=</span><span class="p">[</span><span class="s1">'127.0.0.1'</span><span class="p">],</span>
<span class="n">connection_class</span><span class="o">=</span><span class="n">TwistedConnection</span><span class="p">,</span>
<span class="n">ssl_context</span><span class="o">=</span><span class="n">ssl_context</span><span class="p">,</span>
<span class="n">ssl_options</span><span class="o">=</span><span class="p">{</span><span class="s1">'check_hostname'</span><span class="p">:</span> <span class="kc">True</span><span class="p">}</span>
<span class="p">)</span>
<span class="n">session</span> <span class="o">=</span> <span class="n">cluster</span><span class="o">.</span><span class="n">connect</span><span class="p">()</span>
</pre></div>
</div>
<p>Connecting using Eventlet would look similar except instead of importing and using <code class="docutils literal notranslate"><span class="pre">TwistedConnection</span></code>, you would
import and use <code class="docutils literal notranslate"><span class="pre">EventletConnection</span></code>, including the appropriate monkey-patching.</p>
</div>
</div>
<div class="section" id="versions-3-16-0-and-lower">
<h3>Versions 3.16.0 and lower<a class="headerlink" href="#versions-3-16-0-and-lower" title="Permalink to this headline">¶</a></h3>
<p>To enable SSL you will need to set <a class="reference internal" href="api/cassandra/cluster.html#cassandra.cluster.Cluster.ssl_options" title="cassandra.cluster.Cluster.ssl_options"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Cluster.ssl_options</span></code></a> to a
dict of options. These will be passed as kwargs to <code class="docutils literal notranslate"><span class="pre">ssl.wrap_socket()</span></code>
when new sockets are created. Note that this use of ssl_options will be
deprecated in the next major release.</p>
<p>By default, a <code class="docutils literal notranslate"><span class="pre">ca_certs</span></code> value should be supplied (the value should be
a string pointing to the location of the CA certs file), and you probably
want to specify <code class="docutils literal notranslate"><span class="pre">ssl_version</span></code> as <code class="docutils literal notranslate"><span class="pre">ssl.PROTOCOL_TLS</span></code> to match
Cassandra’s default protocol.</p>
<p>For example:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">cassandra.cluster</span> <span class="kn">import</span> <span class="n">Cluster</span>
<span class="kn">from</span> <span class="nn">ssl</span> <span class="kn">import</span> <span class="n">PROTOCOL_TLS</span><span class="p">,</span> <span class="n">CERT_REQUIRED</span>
<span class="n">ssl_opts</span> <span class="o">=</span> <span class="p">{</span>
<span class="s1">'ca_certs'</span><span class="p">:</span> <span class="s1">'/path/to/my/ca.certs'</span><span class="p">,</span>
<span class="s1">'ssl_version'</span><span class="p">:</span> <span class="n">PROTOCOL_TLS</span><span class="p">,</span>
<span class="s1">'cert_reqs'</span><span class="p">:</span> <span class="n">CERT_REQUIRED</span> <span class="c1"># Certificates are required and validated</span>
<span class="p">}</span>
<span class="n">cluster</span> <span class="o">=</span> <span class="n">Cluster</span><span class="p">(</span><span class="n">ssl_options</span><span class="o">=</span><span class="n">ssl_opts</span><span class="p">)</span>
</pre></div>
</div>
<p>This is only an example to show how to pass the ssl parameters. Consider reading
the <a class="reference external" href="https://docs.python.org/2/library/ssl.html#ssl.wrap_socket">python ssl documentation</a> for
your configuration. For further reading, Andrew Mussey has published a thorough guide on
<a class="reference external" href="http://blog.amussey.com/post/64036730812/cassandra-2-0-client-server-ssl-with-datastax-python">Using SSL with the DataStax Python driver</a>.</p>
<div class="section" id="ssl-with-twisted">
<h4>SSL with Twisted<a class="headerlink" href="#ssl-with-twisted" title="Permalink to this headline">¶</a></h4>
<p>In case the twisted event loop is used pyOpenSSL must be installed or an exception will be risen. Also
to set the <code class="docutils literal notranslate"><span class="pre">ssl_version</span></code> and <code class="docutils literal notranslate"><span class="pre">cert_reqs</span></code> in <code class="docutils literal notranslate"><span class="pre">ssl_opts</span></code> the appropriate constants from pyOpenSSL are expected.</p>
</div>
</div>
</div>
<div class="section" id="dse-authentication">
<h2>DSE Authentication<a class="headerlink" href="#dse-authentication" title="Permalink to this headline">¶</a></h2>
<p>When authenticating against DSE, the Cassandra driver provides two auth providers that work both with legacy kerberos and Cassandra authenticators,
as well as the new DSE Unified Authentication. This allows client to configure this auth provider independently,
and in advance of any server upgrade. These auth providers are configured in the same way as any previous implementation:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">cassandra.auth</span> <span class="kn">import</span> <span class="n">DSEGSSAPIAuthProvider</span>
<span class="n">auth_provider</span> <span class="o">=</span> <span class="n">DSEGSSAPIAuthProvider</span><span class="p">(</span><span class="n">service</span><span class="o">=</span><span class="s1">'dse'</span><span class="p">,</span> <span class="n">qops</span><span class="o">=</span><span class="p">[</span><span class="s2">"auth"</span><span class="p">])</span>
<span class="n">cluster</span> <span class="o">=</span> <span class="n">Cluster</span><span class="p">(</span><span class="n">auth_provider</span><span class="o">=</span><span class="n">auth_provider</span><span class="p">)</span>
<span class="n">session</span> <span class="o">=</span> <span class="n">cluster</span><span class="o">.</span><span class="n">connect</span><span class="p">()</span>
</pre></div>
</div>
<p>Implementations are <code class="xref py py-attr docutils literal notranslate"><span class="pre">DSEPlainTextAuthProvider</span></code>, <code class="xref py py-class docutils literal notranslate"><span class="pre">DSEGSSAPIAuthProvider</span></code> and <a class="reference internal" href="api/cassandra/auth.html#cassandra.auth.SaslAuthProvider" title="cassandra.auth.SaslAuthProvider"><code class="xref py py-class docutils literal notranslate"><span class="pre">SaslAuthProvider</span></code></a>.</p>
<div class="section" id="dse-unified-authentication">
<h3>DSE Unified Authentication<a class="headerlink" href="#dse-unified-authentication" title="Permalink to this headline">¶</a></h3>
<p>With DSE (>=5.1), unified Authentication allows you to:</p>
<ul class="simple">
<li><p>Proxy Login: Authenticate using a fixed set of authentication credentials but allow authorization of resources based another user id.</p></li>
<li><p>Proxy Execute: Authenticate using a fixed set of authentication credentials but execute requests based on another user id.</p></li>
</ul>
<div class="section" id="proxy-login">
<h4>Proxy Login<a class="headerlink" href="#proxy-login" title="Permalink to this headline">¶</a></h4>
<p>Proxy login allows you to authenticate with a user but act as another one. You need to ensure the authenticated user has the permission to use the authorization of resources of the other user. ie. this example will allow the <cite>server</cite> user to authenticate as usual but use the authorization of <cite>user1</cite>:</p>
<div class="highlight-text notranslate"><div class="highlight"><pre><span></span>GRANT PROXY.LOGIN on role user1 to server
</pre></div>
</div>
<p>then you can do the proxy authentication….</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">cassandra.cluster</span> <span class="kn">import</span> <span class="n">Cluster</span>
<span class="kn">from</span> <span class="nn">cassandra.auth</span> <span class="kn">import</span> <span class="n">SaslAuthProvider</span>
<span class="n">sasl_kwargs</span> <span class="o">=</span> <span class="p">{</span>
<span class="s2">"service"</span><span class="p">:</span> <span class="s1">'dse'</span><span class="p">,</span>
<span class="s2">"mechanism"</span><span class="p">:</span><span class="s2">"PLAIN"</span><span class="p">,</span>
<span class="s2">"username"</span><span class="p">:</span> <span class="s1">'server'</span><span class="p">,</span>
<span class="s1">'password'</span><span class="p">:</span> <span class="s1">'server'</span><span class="p">,</span>
<span class="s1">'authorization_id'</span><span class="p">:</span> <span class="s1">'user1'</span>
<span class="p">}</span>
<span class="n">auth_provider</span> <span class="o">=</span> <span class="n">SaslAuthProvider</span><span class="p">(</span><span class="o">**</span><span class="n">sasl_kwargs</span><span class="p">)</span>
<span class="n">c</span> <span class="o">=</span> <span class="n">Cluster</span><span class="p">(</span><span class="n">auth_provider</span><span class="o">=</span><span class="n">auth_provider</span><span class="p">)</span>
<span class="n">s</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">connect</span><span class="p">()</span>
<span class="n">s</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="o">...</span><span class="p">)</span> <span class="c1"># all requests will be executed as 'user1'</span>
</pre></div>
</div>
<p>If you are using kerberos, you can use directly <code class="xref py py-class docutils literal notranslate"><span class="pre">DSEGSSAPIAuthProvider</span></code> and pass the authorization_id, like this:</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">cassandra.cluster</span> <span class="kn">import</span> <span class="n">Cluster</span>
<span class="kn">from</span> <span class="nn">cassandra.auth</span> <span class="kn">import</span> <span class="n">DSEGSSAPIAuthProvider</span>
<span class="c1"># Ensure the kerberos ticket of the server user is set with the kinit utility.</span>
<span class="n">auth_provider</span> <span class="o">=</span> <span class="n">DSEGSSAPIAuthProvider</span><span class="p">(</span><span class="n">service</span><span class="o">=</span><span class="s1">'dse'</span><span class="p">,</span> <span class="n">qops</span><span class="o">=</span><span class="p">[</span><span class="s2">"auth"</span><span class="p">],</span> <span class="n">principal</span><span class="o">=</span><span class="s2">"server@DATASTAX.COM"</span><span class="p">,</span>
<span class="n">authorization_id</span><span class="o">=</span><span class="s1">'user1@DATASTAX.COM'</span><span class="p">)</span>
<span class="n">c</span> <span class="o">=</span> <span class="n">Cluster</span><span class="p">(</span><span class="n">auth_provider</span><span class="o">=</span><span class="n">auth_provider</span><span class="p">)</span>
<span class="n">s</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">connect</span><span class="p">()</span>
<span class="n">s</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="o">...</span><span class="p">)</span> <span class="c1"># all requests will be executed as 'user1'</span>
</pre></div>
</div>
</div>
<div class="section" id="proxy-execute">
<h4>Proxy Execute<a class="headerlink" href="#proxy-execute" title="Permalink to this headline">¶</a></h4>
<p>Proxy execute allows you to execute requests as another user than the authenticated one. You need to ensure the authenticated user has the permission to use the authorization of resources of the specified user. ie. this example will allow the <cite>server</cite> user to execute requests as <cite>user1</cite>:</p>
<div class="highlight-text notranslate"><div class="highlight"><pre><span></span>GRANT PROXY.EXECUTE on role user1 to server
</pre></div>
</div>
<p>then you can do a proxy execute…</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">cassandra.cluster</span> <span class="kn">import</span> <span class="n">Cluster</span>
<span class="kn">from</span> <span class="nn">cassandra.auth</span> <span class="kn">import</span> <span class="n">DSEPlainTextAuthProvider</span><span class="p">,</span>
<span class="n">auth_provider</span> <span class="o">=</span> <span class="n">DSEPlainTextAuthProvider</span><span class="p">(</span><span class="s1">'server'</span><span class="p">,</span> <span class="s1">'server'</span><span class="p">)</span>
<span class="n">c</span> <span class="o">=</span> <span class="n">Cluster</span><span class="p">(</span><span class="n">auth_provider</span><span class="o">=</span><span class="n">auth_provider</span><span class="p">)</span>
<span class="n">s</span> <span class="o">=</span> <span class="n">c</span><span class="o">.</span><span class="n">connect</span><span class="p">()</span>
<span class="n">s</span><span class="o">.</span><span class="n">execute</span><span class="p">(</span><span class="s1">'select * from k.t;'</span><span class="p">,</span> <span class="n">execute_as</span><span class="o">=</span><span class="s1">'user1'</span><span class="p">)</span> <span class="c1"># the request will be executed as 'user1'</span>
</pre></div>
</div>
<p>Please see the <a class="reference external" href="https://docs.datastax.com/en/latest-dse/datastax_enterprise/unifiedAuth/unifiedAuthTOC.html">official documentation</a> for more details on the feature and configuration process.</p>
</div>
</div>
</div>
</div>
<div class="content-navigation">
<div class="navigation navigation--prev">
<a class="navigation__link" href="lwt.html">
<button class="navigation__button">
<i class="scylla-icon scylla-icon--chevron-left"></i>
</button>
<div class="navigation__title">
<span class="colored">PREVIOUS</span> <br />Lightweight Transactions (Compare-and-set)
</div>
</a>
</div>
<div class="navigation navigation--next">
<a class="navigation__link" href="user_defined_types.html">
<div class="navigation__title">
<span class="colored">NEXT</span> <br />User Defined Types
</div>
<button class="navigation__button">
<i class="scylla-icon scylla-icon--chevron-right"></i>
</button>
</a>
</div>
</div>
</div>
<div
class="sidebar-left large-order-1"
> <div id="side-nav" class="side-nav custom-scroll-bar" data-closable data-toggler=".show">
<button class="collapsible-button">
<i class="scylla-icon scylla-icon--chevron-left"></i>
</button>
<div class="side-nav-content">
<div class="side-nav__search">
<div class="search-box">
<ci-search></ci-search>
</div>
</div>
<div class="side-nav__versions">
<ul
class="dropdown menu scylla-dropdown scylla-dropdown--versions "
data-dropdown-menu
>
<li class="scylla-dropdown__item">
<a class="scylla-dropdown__title" href="#">
master
<i class="chevron scylla-icon scylla-icon--chevron-right"></i>
</a>
<ul class="menu scylla-dropdown__content">
<li>
<a href="../stable/security.html"
>3.25.1</a
>
</li>
<li>
<a href="../3.24.8-scylla/security.html"
>3.24.8</a
>
</li>
<li>
<a href="../3.22.3-scylla/security.html"
>3.22.3</a
>
</li>
<li>
<a href="../3.21.0-scylla/security.html"
>3.21.0</a
>
</li>
</ul>
</li>
</ul>
</div>
<div class="side-nav__content">
<ul class="current">
<li class="toctree-l1 has-children"><a class="reference internal" href="api/index.html">API Documentation</a><input class="toctree-checkbox" id="toctree-checkbox-1" name="toctree-checkbox-1" type="checkbox"/><label for="toctree-checkbox-1"><i class="scylla-icon scylla-icon--expand"></i></label><div class="break"></div><ul>
<li class="toctree-l2"><a class="reference internal" href="api/cassandra.html"><code class="xref py py-mod docutils literal notranslate"><span class="pre">cassandra</span></code> - Exceptions and Enums</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/cassandra/cluster.html"><code class="docutils literal notranslate"><span class="pre">cassandra.cluster</span></code> - Clusters and Sessions</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/cassandra/policies.html"><code class="docutils literal notranslate"><span class="pre">cassandra.policies</span></code> - Load balancing and Failure Handling Policies</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/cassandra/auth.html"><code class="docutils literal notranslate"><span class="pre">cassandra.auth</span></code> - Authentication</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/cassandra/graph.html"><code class="docutils literal notranslate"><span class="pre">cassandra.graph</span></code> - Graph Statements, Options, and Row Factories</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/cassandra/metadata.html"><code class="docutils literal notranslate"><span class="pre">cassandra.metadata</span></code> - Schema and Ring Topology</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/cassandra/metrics.html"><code class="docutils literal notranslate"><span class="pre">cassandra.metrics</span></code> - Performance Metrics</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/cassandra/query.html"><code class="docutils literal notranslate"><span class="pre">cassandra.query</span></code> - Prepared Statements, Batch Statements, Tracing, and Row Factories</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/cassandra/pool.html"><code class="docutils literal notranslate"><span class="pre">cassandra.pool</span></code> - Hosts and Connection Pools</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/cassandra/protocol.html"><code class="docutils literal notranslate"><span class="pre">cassandra.protocol</span></code> - Protocol Features</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/cassandra/encoder.html"><code class="docutils literal notranslate"><span class="pre">cassandra.encoder</span></code> - Encoders for non-prepared Statements</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/cassandra/decoder.html"><code class="docutils literal notranslate"><span class="pre">cassandra.decoder</span></code> - Data Return Formats</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/cassandra/concurrent.html"><code class="docutils literal notranslate"><span class="pre">cassandra.concurrent</span></code> - Utilities for Concurrent Statement Execution</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/cassandra/connection.html"><code class="docutils literal notranslate"><span class="pre">cassandra.connection</span></code> - Low Level Connection Info</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/cassandra/util.html"><code class="docutils literal notranslate"><span class="pre">cassandra.util</span></code> - Utilities</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/cassandra/timestamps.html"><code class="docutils literal notranslate"><span class="pre">cassandra.timestamps</span></code> - Timestamp Generation</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/cassandra/io/asyncioreactor.html"><code class="docutils literal notranslate"><span class="pre">cassandra.io.asyncioreactor</span></code> - <code class="docutils literal notranslate"><span class="pre">asyncio</span></code> Event Loop</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/cassandra/io/asyncorereactor.html"><code class="docutils literal notranslate"><span class="pre">cassandra.io.asyncorereactor</span></code> - <code class="docutils literal notranslate"><span class="pre">asyncore</span></code> Event Loop</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/cassandra/io/eventletreactor.html"><code class="docutils literal notranslate"><span class="pre">cassandra.io.eventletreactor</span></code> - <code class="docutils literal notranslate"><span class="pre">eventlet</span></code>-compatible Connection</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/cassandra/io/libevreactor.html"><code class="docutils literal notranslate"><span class="pre">cassandra.io.libevreactor</span></code> - <code class="docutils literal notranslate"><span class="pre">libev</span></code> Event Loop</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/cassandra/io/geventreactor.html"><code class="docutils literal notranslate"><span class="pre">cassandra.io.geventreactor</span></code> - <code class="docutils literal notranslate"><span class="pre">gevent</span></code>-compatible Event Loop</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/cassandra/io/twistedreactor.html"><code class="docutils literal notranslate"><span class="pre">cassandra.io.twistedreactor</span></code> - Twisted Event Loop</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/cassandra/cqlengine/models.html"><code class="docutils literal notranslate"><span class="pre">cassandra.cqlengine.models</span></code> - Table models for object mapping</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/cassandra/cqlengine/columns.html"><code class="docutils literal notranslate"><span class="pre">cassandra.cqlengine.columns</span></code> - Column types for object mapping models</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/cassandra/cqlengine/query.html"><code class="docutils literal notranslate"><span class="pre">cassandra.cqlengine.query</span></code> - Query and filter model objects</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/cassandra/cqlengine/connection.html"><code class="docutils literal notranslate"><span class="pre">cassandra.cqlengine.connection</span></code> - Connection management for cqlengine</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/cassandra/cqlengine/management.html"><code class="docutils literal notranslate"><span class="pre">cassandra.cqlengine.management</span></code> - Schema management for cqlengine</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/cassandra/cqlengine/usertype.html"><code class="docutils literal notranslate"><span class="pre">cassandra.cqlengine.usertype</span></code> - Model classes for User Defined Types</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/cassandra/datastax/graph/index.html"><code class="docutils literal notranslate"><span class="pre">cassandra.datastax.graph</span></code> - Graph Statements, Options, and Row Factories</a></li>
<li class="toctree-l2"><a class="reference internal" href="api/cassandra/datastax/graph/fluent/index.html"><code class="xref py py-mod docutils literal notranslate"><span class="pre">cassandra.datastax.graph.fluent</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="api/cassandra/datastax/graph/fluent/query.html"><code class="xref py py-mod docutils literal notranslate"><span class="pre">cassandra.datastax.graph.fluent.query</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="api/cassandra/datastax/graph/fluent/predicates.html"><code class="xref py py-mod docutils literal notranslate"><span class="pre">cassandra.datastax.graph.fluent.predicates</span></code></a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="installation.html">Installation</a></li>
<li class="toctree-l1"><a class="reference internal" href="getting_started.html">Getting Started</a></li>
<li class="toctree-l1"><a class="reference internal" href="scylla_specific.html">Scylla Specific Features</a></li>
<li class="toctree-l1 has-children"><a class="reference internal" href="upgrading.html">Upgrading</a><input class="toctree-checkbox" id="toctree-checkbox-2" name="toctree-checkbox-2" type="checkbox"/><label for="toctree-checkbox-2"><i class="scylla-icon scylla-icon--expand"></i></label><div class="break"></div><ul class="simple">
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="execution_profiles.html">Execution Profiles</a></li>
<li class="toctree-l1"><a class="reference internal" href="performance.html">Performance Notes</a></li>
<li class="toctree-l1"><a class="reference internal" href="query_paging.html">Paging Large Queries</a></li>
<li class="toctree-l1"><a class="reference internal" href="lwt.html">Lightweight Transactions (Compare-and-set)</a></li>
<li class="toctree-l1 current current-page"><a class="current reference internal" href="#">Security</a></li>
<li class="toctree-l1"><a class="reference internal" href="user_defined_types.html">User Defined Types</a></li>
<li class="toctree-l1 has-children"><a class="reference internal" href="object_mapper.html">Object Mapper</a><input class="toctree-checkbox" id="toctree-checkbox-3" name="toctree-checkbox-3" type="checkbox"/><label for="toctree-checkbox-3"><i class="scylla-icon scylla-icon--expand"></i></label><div class="break"></div><ul>
<li class="toctree-l2"><a class="reference internal" href="cqlengine/upgrade_guide.html">Upgrade Guide</a></li>
<li class="toctree-l2"><a class="reference internal" href="cqlengine/models.html">Models</a></li>
<li class="toctree-l2"><a class="reference internal" href="cqlengine/queryset.html">Making Queries</a></li>
<li class="toctree-l2"><a class="reference internal" href="cqlengine/batches.html">Batch Queries</a></li>
<li class="toctree-l2"><a class="reference internal" href="cqlengine/connections.html">Connections</a></li>
<li class="toctree-l2"><a class="reference internal" href="cqlengine/third_party.html">Third party integrations</a></li>
<li class="toctree-l2"><a class="reference internal" href="cqlengine/faq.html">Frequently Asked Questions</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="dates_and_times.html">Working with Dates and Times</a></li>
<li class="toctree-l1"><a class="reference internal" href="scylla_cloud.html">Scylla Cloud</a></li>
<li class="toctree-l1"><a class="reference internal" href="faq.html">Frequently Asked Questions</a></li>
</ul>
</div>
</div>
</div>
</div>
<div class="sidebar-right large-order-3">
<div class="secondary-side-nav custom-scroll-bar">
<div class="secondary-side-nav__content">
<p class="topic-title">On this page</p>
<ul>
<li><a class="reference internal" href="#">Security</a><ul>
<li><a class="reference internal" href="#authentication">Authentication</a><ul>
<li><a class="reference internal" href="#custom-authenticators">Custom Authenticators</a></li>
<li><a class="reference internal" href="#protocol-v1-authentication">Protocol v1 Authentication</a></li>
</ul>
</li>
<li><a class="reference internal" href="#ssl">SSL</a><ul>
<li><a class="reference internal" href="#ssl-with-twisted-or-eventlet">SSL with Twisted or Eventlet</a></li>
<li><a class="reference internal" href="#ssl-configuration-examples">SSL Configuration Examples</a><ul>
<li><a class="reference internal" href="#no-identity-verification">No identity verification</a></li>
<li><a class="reference internal" href="#client-verifies-server">Client verifies server</a></li>
<li><a class="reference internal" href="#server-verifies-client">Server verifies client</a></li>
<li><a class="reference internal" href="#server-verifies-client-and-client-verifies-server">Server verifies client and client verifies server</a></li>
</ul>
</li>
<li><a class="reference internal" href="#versions-3-16-0-and-lower">Versions 3.16.0 and lower</a><ul>
<li><a class="reference internal" href="#ssl-with-twisted">SSL with Twisted</a></li>
</ul>
</li>
</ul>
</li>
<li><a class="reference internal" href="#dse-authentication">DSE Authentication</a><ul>
<li><a class="reference internal" href="#dse-unified-authentication">DSE Unified Authentication</a><ul>
<li><a class="reference internal" href="#proxy-login">Proxy Login</a></li>
<li><a class="reference internal" href="#proxy-execute">Proxy Execute</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
</div>
</section>
<footer class="footer">
<div class="footer-group">
<div class="footer-top">
<a class="footer-logo" href="https://www.scylladb.com"
><img
src="_static/img/logo-scylla-horizontal-RGB.svg"
alt="Logo"
/></a>
<div class="footer-links">
<a class="footer-links__link" href="https://docs.scylladb.com/">Docs</a>
<a
class="footer-links__link"
href="https://www.scylladb.com/company/contact-us/"
>Contact Us</a
>
<a class="footer-links__link" href="https://www.scylladb.com/company/"
>About Us</a
>
</div>
<div class="footer-actions">
<a
class="footer-actions__link"
href="https://groups.google.com/g/scylladb-users"
target="_blank"
><span
data-tooltip
tabindex="1"
title="User mailing list"
data-position="bottom"
>
<img
src="_static/img/icons/icon-mail-list.svg"
alt="Mail List Icon"
/>
</span>
</a>
<a
class="footer-actions__link"
href="http://slack.scylladb.com/"
target="_blank"
><span
data-tooltip
tabindex="1"
title="User Slack channel"
data-position="bottom"
>
<img
src="_static/img/icons/icon-slack.svg"
alt="Slack Icon"
/></span>
</a>
</div>
</div>
<div class="footer-bottom">
<div class="footer-bottom__copyright"> © ScyllaDB 2021 and © DataStax 2013-2017
</div>
<div class="footer-bottom__version">
Powered by
<a href="http://sphinx-doc.org/">Sphinx 2.4.4</a> &
<a href="https://sphinx-theme.scylladb.com/"
>ScyllaDB Theme 1.0.6</a
>
</div>
</div>
</div>
</footer>
<noscript>
<iframe
src="https://www.googletagmanager.com/ns.html?id=GTM-T8P2JP"
height="0"
width="0"
style="display: none; visibility: hidden"
></iframe>
</noscript>
</body>
</html>