{"id":9325,"date":"2020-09-10T08:38:59","date_gmt":"2020-09-10T15:38:59","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=9325"},"modified":"2021-01-31T13:04:38","modified_gmt":"2021-01-31T21:04:38","slug":"authentication-using-server-side-x-509-certificates-with-n1ql","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/authentication-using-server-side-x-509-certificates-with-n1ql\/","title":{"rendered":"Authentication Using Server-Side X.509 Certificates And N1QL"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">Authentication and authorization to the N1QL query service in Couchbase works in multiple ways &#8211;\u00a0<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Passing credentials through a rest request &#8211; curl https:\/\/localhost:8093\/query\/service?pretty=true -d &#8220;statement=select * from system:keyspaces&#8221; -u Admin:pwd<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Passing credentials using the creds named parameter and\/or query parameter &#8211;\u00a0<\/span>curl https:\/\/localhost:8093\/query\/service?pretty=true -d &#8220;statement=select * from system:keyspaces&amp;creds=[{user:\u201cAdministrator\u201d,\u201dpassword\u201d:\u201dpass\u201d}]&#8221;<\/li>\n<li><span style=\"font-weight: 400;\">Using basic auth in the request\u00a0<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Request from cbq (similar to 1,2) using the -u -p -creds options and \\SET command.\u00a0<\/span><\/li>\n<li><span style=\"font-weight: 400;\">X.509 Certificates for TLS<\/span><\/li>\n<li>Node to Node encryption<\/li>\n<\/ol>\n<p>With the addition of RBAC, the creds query parameter was made redundant but is still supported for backward compatibility.<\/p>\n<p>The goal of adding X509 certificates support is to enhance client-server encryption using a certificate that is trusted by the certificate authority.<\/p>\n<p><span style=\"font-weight: 400;\">X.509 certificates enable server authentication and encryption for client-server communications. Couchbase supports both server and client authentication using X509 certificates and you have to be a full Admin or Security Admin to manage certificates. This article talks about server-side X.509 certificate support for authorization in Couchbase. Clients can also verify the identity of Couchbase Server but that will be discussed in another article.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The most common scenarios for which X509 certificates are used are when clients have to go through the internet, <\/span><span style=\"font-weight: 400;\">when transferring sensitive data on the wire between application and Couchbase Server, or between data centers (XDCR) or when mandated by compliance regulations.\u00a0<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">What is an X.509 Certificate ? <\/span><\/h2>\n<p><span style=\"font-weight: 400;\">It is a public key certificate that is used to distribute a public key, signed by a trusted certificate authority verifying the identity of the server. Using it a client is assured that the request is not being sent to an unknown server. These certificates are signed by a third party also known as a Certificate authority. <\/span><span style=\"font-weight: 400;\">CAs are entities that issue digital certificates. A CA is actually made up of a series of CAs called a CA hierarchy. This CA hierarchy constructs a chain of trust that all node or end entity certificates rely on. The chain does not contain the root CA public key.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In a hierarchical public key infrastructure (PKI) there are typically 3 kinds of hierarchy. One-tier, Two-tier and N-tier. The CA at the top of this hierarchy is known as the Root-CA. All subsequent CA\u2019s are the Intermediate CA, and the nth (last) CA is known as the Node CA.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">An important point to note is <\/span><span style=\"font-weight: 400;\">that to trust a certificate used to establish a secure connection it must have been issued by a CA that is included in the trusted store of the device that is connecting.<\/span><\/p>\n<h3><b>One-tier \/ Single-tier CA authority <\/b><\/h3>\n<p><span style=\"font-weight: 400;\">This consists of a single CA is the simplest form of CA hierarchy but is not usually used in production as a<\/span><span style=\"font-weight: 400;\"> compromise of this root CA results in a compromise of the entire PKI. <\/span><span style=\"font-weight: 400;\">Here the root CA is the issuing CA as well and <\/span><span style=\"font-weight: 400;\">all certificates immediately below the root certificate inherit its trustworthiness.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-9327 aligncenter\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2020\/09\/Screen-Shot-2020-09-08-at-2.46.34-PM-300x206.png\" alt=\"\" width=\"129\" height=\"89\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2020\/09\/Screen-Shot-2020-09-08-at-2.46.34-PM-300x206.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2020\/09\/Screen-Shot-2020-09-08-at-2.46.34-PM-235x160.png 235w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2020\/09\/Screen-Shot-2020-09-08-at-2.46.34-PM-20x14.png 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2020\/09\/Screen-Shot-2020-09-08-at-2.46.34-PM.png 358w\" sizes=\"auto, (max-width: 129px) 100vw, 129px\" \/><\/p>\n<h3><b>Two-tier CA authority<\/b><span style=\"font-weight: 400;\">\u00a0<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">This consists of a Root CA that has issued a certificate for one subordinate known as the Intermediate CA. The difference here is that the issued certificates are trusted as they come from a trusted authority via the intermediate CA.\u00a0<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-9329 \" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2020\/09\/Screen-Shot-2020-09-08-at-2.46.43-PM-1-1024x574.png\" alt=\"\" width=\"525\" height=\"294\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2020\/09\/Screen-Shot-2020-09-08-at-2.46.43-PM-1-1024x574.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2020\/09\/Screen-Shot-2020-09-08-at-2.46.43-PM-1-300x168.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2020\/09\/Screen-Shot-2020-09-08-at-2.46.43-PM-1-768x430.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2020\/09\/Screen-Shot-2020-09-08-at-2.46.43-PM-1-20x11.png 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2020\/09\/Screen-Shot-2020-09-08-at-2.46.43-PM-1.png 1028w\" sizes=\"auto, (max-width: 525px) 100vw, 525px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Root CA signs-&gt;<\/span><span style=\"font-weight: 400;\"> Intermediate CA signs<\/span><span style=\"font-weight: 400;\"> -&gt; Issuing CA \/ Cluster CA<\/span><\/p>\n<h3><b>N-Tier CA authority <\/b><\/h3>\n<p><span style=\"font-weight: 400;\">\u00a0In most production deployments, a hierarchy has multiple CAs.<\/span> <span style=\"font-weight: 400;\">The root CA issues certificates to the intermediate CAs, which in turn generate <\/span><i><span style=\"font-weight: 400;\">intermediate certificates<\/span><\/i><span style=\"font-weight: 400;\">: these are used to sign client certificates, such as a cluster certificate:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Trusted root CA &gt; Intermediate CA &gt; Cluster certificate<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Trusted root CA &gt; Intermediate CA 1 &gt; Intermediate CA 2&#8230;. &gt; Intermediate CA <\/span><i><span style=\"font-weight: 400;\">n<\/span><\/i><span style=\"font-weight: 400;\"> &gt; Cluster certificate<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">The Two-tier hierarchy is a subtype of the N Tier hierarchy.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0<\/span><span style=\"font-weight: 400;\">In all the above cases the certificate chain needs to be verified up unto the root CA. The trust chain contains your certificate, concatenated with all intermediate certificates.<\/span><\/p>\n<p><b>Note here &#8211;<\/b> <b>All intermediate certificates should be installed on your server: otherwise, some clients will assume that the connection is not secure. This results in &#8216;untrusted&#8217; warnings.\u00a0<\/b><\/p>\n<h2><b>Setting up X.509 on a couchbase cluster<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Some prerequisites before setting up the certificates &#8211;\u00a0<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">The certificate should be an RSA key certificate in a valid .pem format<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">The certificate should not be invalid &#8211; Current time should fall between <\/span><span style=\"font-weight: 400;\">valid from<\/span><span style=\"font-weight: 400;\"> and <\/span><span style=\"font-weight: 400;\">valid to <\/span><span style=\"font-weight: 400;\">as set in the cert.<\/span><span style=\"font-weight: 400;\">\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Use an RSA key-length of 2048 bits or higher. (As computing capabilities increase, longer RSA keys provide increased security.)<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">With a single node cluster you will have 1 directory corresponding to the node certs. With a multi node cluster, create multiple dir corresponding to each node in the cluster &#8211; node1, node2 etc.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">If you have multiple Intermediate CAs, be sure to stack them in the correct order in the certificate chain.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">The private node key and the chain need to be put in ..\/<\/span><i><span style=\"font-weight: 400;\">var\/lib\/couchbase\/inbox <\/span><\/i><span style=\"font-weight: 400;\">relative to your os bin dir from where the service\/cluster exes are deployed.\u00a0<\/span><\/li>\n<\/ul>\n<h3><b>Naming conventions<\/b><\/h3>\n<p><b>ca.pem<\/b><span style=\"font-weight: 400;\"> &#8211; Root CA\u2019s public key\u00a0<\/span><\/p>\n<p><b>int1.pem<\/b><span style=\"font-weight: 400;\"> &#8211; Intermediate CA\u2019s public key (no 1. If you have multiple intermediate CAs, name them appropriately to add to the chain in correct order. This shows which int CA is closest to the node)<\/span><\/p>\n<p><b>node1.pem<\/b><span style=\"font-weight: 400;\"> &#8211; Node 1 CA\u2019s public key ( node2.pem &#8211; Node 2 CA\u2019s public key and so on )<\/span><\/p>\n<p><b>node1.key<\/b><span style=\"font-weight: 400;\"> &#8211; Node 1 CA\u2019s private key<\/span><\/p>\n<p><b>chain.pem<\/b><span style=\"font-weight: 400;\"> &#8211; Certificate chain containing the nodes public key and the intermediate public keys that signed the node public key.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">We use the openssl tool to create our certificates. See its documentation for more details on the commands itself.\u00a0<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Steps to setup X.509 Certs<\/span><\/h3>\n<h4><span style=\"font-weight: 400;\"><strong>Step 1<\/strong> &#8211; Create the root private key\u00a0<\/span><\/h4>\n<p><b>openssl genrsa -out ca.key 2048 2&gt;\/dev\/null<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Generate an RSA private key called <\/span><b>ca.key <\/b><span style=\"font-weight: 400;\">(-out filename) that is the 2048 bits.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">When generating the key, the . or + symbol will be seen. This indicates progress in the key generation. The . represents each number that passes the test and + means a number has passed a single round of the Miller-Rabin primality test. When the newline is seen it means the key was successfully generated and the number (2 prime numbers) has passed all the prime tests. See the documentation of openssl-genrsa for more details.\u00a0<\/span><\/p>\n<h4><span style=\"font-weight: 400;\"><strong>Step 2<\/strong> &#8211; Generate the root public key used as the cluster CA<\/span><\/h4>\n<p><b>openssl req -new -x509\u00a0 -days 365 -sha256 -key ca.key -out ca.pem -subj &#8216;\/C=US\/O=Couchbase\/CN=Couchbase Root CA&#8217; 2&gt;\/dev\/null<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Generate a new self signed root certificate\u00a0 (-x509 option) request with a sha256 signature (-sha256. This means higher security) that is valid for 1 year (-days 365 in days). The public key ca.pem (-out) is derived from the private key using the -key option to specify the private key.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">X.509 certificates have a Subject Distinguished Name (DN) field and can also have multiple names in the Subject Alternative Name extension. It is made of relative DNs.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">CN = COmmon Name, O = Organization, C = Country Name<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The certificate\u2019s issuer is specified to have the CN (Common Name) of Couchbase Root CA: as this name indicates, the certificate will be the root certificate for the Couchbase\u00a0<\/span><\/p>\n<h4><span style=\"font-weight: 400;\"><strong>Step 3<\/strong> &#8211; Generate Intermediate private key (or keys if using an N tier hierarchy as described above )<\/span><\/h4>\n<p><b>openssl genrsa -out int1.key 2048 2&gt;\/dev\/null<\/b><\/p>\n<h4><span style=\"font-weight: 400;\"><strong>Step 4<\/strong> &#8211; Generate the intermediate certificate signing request<\/span><\/h4>\n<p><b>openssl req -new -key int1.key -out int1.csr -subj &#8216;\/C=US\/O=Couchbase\/CN=Couchbase Intermediate CA&#8217; 2&gt;\/dev\/null<\/b><\/p>\n<p><span style=\"font-weight: 400;\">A CSR or certificate signing request is a request sent from an applicant to a CA to apply for a certificate.\u00a0<\/span><span style=\"font-weight: 400;\">You can customize: add to or limit the capabilities of the X.509 certificate using an extension file. This information will be used on all the nodes in the cluster. For example &#8211;\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">cat &gt; v3.ext &lt;&lt;EOF<\/span><\/p>\n<p><span style=\"font-weight: 400;\">basicConstraints = CA:FALSE<\/span><\/p>\n<p><span style=\"font-weight: 400;\">subjectKeyIdentifier = hash<\/span><\/p>\n<p><span style=\"font-weight: 400;\">authorityKeyIdentifier = keyid,issuer:always<\/span><\/p>\n<p><span style=\"font-weight: 400;\">EOF<\/span><\/p>\n<p><span style=\"font-weight: 400;\">For an extensive list of all the standard extensions see section 4.2 of RFC 5280 on X509 PKI and CRL profile. &#8211;<\/span><a href=\"https:\/\/tools.ietf.org\/html\/rfc5280\"> <span style=\"font-weight: 400;\">https:\/\/tools.ietf.org\/html\/rfc5280<\/span><\/a><span style=\"font-weight: 400;\">\u00a0<\/span><\/p>\n<h4><span style=\"font-weight: 400;\"><strong>Step 5<\/strong> &#8211; Create the intermediate Certificate\u00a0<\/span><\/h4>\n<p><b>openssl x509 -req -in int1.csr -CA ca.pem -CAkey ca.key -CAcreateserial -CAserial rootCA.srl -extfile v3.ext -out int1.pem -days 365 2&gt;\/dev\/null<\/b><span style=\"font-weight: 400;\">\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Read from the csr file and pass in the Root CA keys to <\/span><span style=\"font-weight: 400;\">establish the root certificate\u2019s authority. The root CA encrypted key is used to sign the intermediate CSR.\u00a0 Before we sign anything, a serial number file needs to be setup for the Root CA. This is so that each certificate can have a unique serial number. This is done using the -CAcreateserial -CAserial &lt;name of file&gt; options. The rootCA.srl is the serial number file. It is a simple text file with ASCII numbers in it. The certificate is customized using the extensions we defined earlier and is valid for a year. <\/span><span style=\"font-weight: 400;\">When <\/span><span style=\"font-weight: 400;\">prompts appear, asking for a passphrase for the certificate. Enter an appropriate phrase in response to the prompts.<\/span><span style=\"font-weight: 400;\"> Remember this phrase.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Finally we have the root and intermediate CA certificates. Now it&#8217;s time to set up the node certificate and sign it with the root CA and intermediate key.\u00a0<\/span><\/p>\n<h4><span style=\"font-weight: 400;\"><strong>Step 6<\/strong> &#8211; Setup node key and CSR\u00a0<\/span><\/h4>\n<p><b>openssl genrsa -out node1.key 2048 2&gt;\/dev\/null<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Once the encrypted key for the node is generated, setup the node csr.\u00a0<\/span><\/p>\n<p><b>openssl req -new -key node1.key -out node1.csr -subj &#8220;\/C=US\/O=Couchbase\/CN=server1_linux&#8221; 2&gt;\/dev\/null<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Here the Common name defined in the certificate subject is the node name as defined and mapped in \/etc\/hosts.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">When setting up the node csr use the nodename(preferable), IP address or URI with a SAN (subject alternative name) certificate.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The usual way to specify the certificate identity is through the Common Name (CN) in the subject DN of the certificate. If you deploy a certificate on a multi-homed host, it is necessary to define a certificate with alternative identities using the <\/span><span style=\"font-weight: 400;\">subjectAltName<\/span><span style=\"font-weight: 400;\"> certificate-extension.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8220;subjectAltName = IP:172.23.99.49&#8221;<\/span><\/p>\n<h4><span style=\"font-weight: 400;\"><strong>Step 7<\/strong> &#8211; Generate the node certificate using the appropriate extensions<\/span><\/h4>\n<p><b>openssl x509 -req -in node1.csr -CA int1.pem -CAkey int1.key -CAcreateserial \\<\/b><\/p>\n<p><b>-CAserial intermediateCA.srl -out node1.pem -days 365\u00a0<\/b><\/p>\n<p><span style=\"font-weight: 400;\">This is similar to the steps above for generating intermediate certificate.\u00a0<\/span><\/p>\n<h4><span style=\"font-weight: 400;\"><strong>Step 8<\/strong> &#8211; <\/span><span style=\"font-weight: 400;\">Generate the certificate chain\u00a0<\/span><\/h4>\n<p><b>cat node1.pem int1.pem &gt; chain.pem<\/b><span style=\"font-weight: 400;\">\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Concatenate all the intermediate and node certificates in the correct order. The root certificate is never included in the chain. This chain will allow the client to verify the intermediate certificate against the root certificate.\u00a0<\/span><span style=\"font-weight: 400;\">\u00a0<\/span><\/p>\n<h4><span style=\"font-weight: 400;\"><strong>Step 9<\/strong> &#8211; Deploy the certificates\u00a0<\/span><\/h4>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Copy the node encrypted certificate and chain certificate into the inbox folder within <\/span><b>..\/var\/lib\/couchbase\/inbox <\/b><span style=\"font-weight: 400;\">relative to where your binaries are run from for your OS and give them the appropriate permissions using chmod a+x<\/span>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">node1.key and chain.pem are copied into ..\/inbox\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">chmod a+x node1.key\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">chmod a+x chain.pem<\/span><\/li>\n<\/ul>\n<\/li>\n<li><span style=\"font-weight: 400;\">Upload these to the server<\/span>\n<ul>\n<li><span style=\"font-weight: 400;\">curl -X POST &#8211;data-binary ca.pem https:\/\/Administrator:password@172.23.99.49:8091\/controller\/uploadClusterCA<\/span><\/li>\n<li><span style=\"font-weight: 400;\">curl -X POST https:\/\/Administrator:password@172.23.99.49:8091\/node\/controller\/reloadCertificate<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">When you load the cluster certificate into Couchbase, it is first checked to make sure it is a valid X.509 certificate. Next, if the per-node certificates are not signed by the cluster certificate, a warning is shown for each node during configuration. As the per-node certificates are updated, such that they are signed by the cluster certificate, the warning for each node goes away.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Using certs in your N1QL CURL() query or the cbq shell\u00a0<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">In order to verify certificates that have been signed by a third party, the library uses the certificates stored on the local machine. For each query node in a Couchbase cluster, the ..\/\/var\/lib\/couchbase\/n1qlcerts folder contains certs needed by CURL(). If the certs are not found in this folder an error is thrown.\u00a0 The cacert option is used to pass a certificate name to the function. Passing in a path will cause an error.<\/span><\/p>\n<p><b>select CURL(\u201chttps:\/\/127.0.0.1:18091\/pools\u201d,{<\/b><b>\u201crequest\u201d:\u201cGET\u201d<\/b><b>,\u201duser\u201d:\u201dBucketuser:password\u201d,\u201ccacert\u201d:\u201cca.pem\u201d})<\/b><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0For connecting using the shell use the cacert, cert and the key options.<\/span><\/p>\n<p><b>.\/cbq &#8211;cacert ca.pem &#8211;cert chain.pem &#8211;key node1.key &#8211;engine https:\/\/172.23.99.49:18091<\/b><\/p>\n<p><span style=\"font-weight: 400;\">With this article, we now know how to setup X509 certificates on our server and use them with the N1QL query and CBQ shell. With the next article we will go in depth into Client side certificates.\u00a0<\/span><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Authentication and authorization to the N1QL query service in Couchbase works in multiple ways &#8211;\u00a0 Passing credentials through a rest request &#8211; curl https:\/\/localhost:8093\/query\/service?pretty=true -d &#8220;statement=select * from system:keyspaces&#8221; -u Admin:pwd Passing credentials using the creds named parameter and\/or query [&hellip;]<\/p>\n","protected":false},"author":6882,"featured_media":13873,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[1815,1813,1812],"tags":[],"ppma_author":[9057],"class_list":["post-9325","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-best-practices-and-tutorials","category-security","category-n1ql-query"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.8 (Yoast SEO v25.8) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Authentication Using Server-Side X.509 Certificates And N1QL<\/title>\n<meta name=\"description\" content=\"Learn how to setup X509 certificates on Couchbase Server and use them with the N1QL query and CBQ shell for authentication and authorization.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.couchbase.com\/blog\/authentication-using-server-side-x-509-certificates-with-n1ql\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Authentication Using Server-Side X.509 Certificates And N1QL\" \/>\n<meta property=\"og:description\" content=\"Learn how to setup X509 certificates on Couchbase Server and use them with the N1QL query and CBQ shell for authentication and authorization.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/authentication-using-server-side-x-509-certificates-with-n1ql\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2020-09-10T15:38:59+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-01-31T21:04:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2020\/09\/Authentication-using-Server-side-X.509-Certificates-with-N1QL.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"627\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Isha Kandaswamy\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Isha Kandaswamy\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/authentication-using-server-side-x-509-certificates-with-n1ql\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/authentication-using-server-side-x-509-certificates-with-n1ql\/\"},\"author\":{\"name\":\"Isha Kandaswamy\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/f236f76f209f447fbc8fd46d91eb7e52\"},\"headline\":\"Authentication Using Server-Side X.509 Certificates And N1QL\",\"datePublished\":\"2020-09-10T15:38:59+00:00\",\"dateModified\":\"2021-01-31T21:04:38+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/authentication-using-server-side-x-509-certificates-with-n1ql\/\"},\"wordCount\":2094,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/authentication-using-server-side-x-509-certificates-with-n1ql\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"articleSection\":[\"Best Practices and Tutorials\",\"Security\",\"SQL++ \/ N1QL Query\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/authentication-using-server-side-x-509-certificates-with-n1ql\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/authentication-using-server-side-x-509-certificates-with-n1ql\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/authentication-using-server-side-x-509-certificates-with-n1ql\/\",\"name\":\"Authentication Using Server-Side X.509 Certificates And N1QL\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/authentication-using-server-side-x-509-certificates-with-n1ql\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/authentication-using-server-side-x-509-certificates-with-n1ql\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"datePublished\":\"2020-09-10T15:38:59+00:00\",\"dateModified\":\"2021-01-31T21:04:38+00:00\",\"description\":\"Learn how to setup X509 certificates on Couchbase Server and use them with the N1QL query and CBQ shell for authentication and authorization.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/authentication-using-server-side-x-509-certificates-with-n1ql\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/authentication-using-server-side-x-509-certificates-with-n1ql\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/authentication-using-server-side-x-509-certificates-with-n1ql\/#primaryimage\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"width\":1800,\"height\":630},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/authentication-using-server-side-x-509-certificates-with-n1ql\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.couchbase.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Authentication Using Server-Side X.509 Certificates And N1QL\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"name\":\"The Couchbase Blog\",\"description\":\"Couchbase, the NoSQL Database\",\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\",\"name\":\"The Couchbase Blog\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"width\":218,\"height\":34,\"caption\":\"The Couchbase Blog\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/f236f76f209f447fbc8fd46d91eb7e52\",\"name\":\"Isha Kandaswamy\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/e8464106b598ad96e4e1446687ce93f6\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/9c28181876ed38a9634b77ddbe73ada95b0f82838c0cce722be73968630d41e1?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/9c28181876ed38a9634b77ddbe73ada95b0f82838c0cce722be73968630d41e1?s=96&d=mm&r=g\",\"caption\":\"Isha Kandaswamy\"},\"description\":\"Isha Kandaswamy is a Senior Software Engineer at Couchbase. Isha is responsible for the development of designing the different features and tools for the N1QL Query Language -SQL for Json. Also, Designing and implementing features and tools for the N1QL query language.\",\"url\":\"https:\/\/www.couchbase.com\/blog\/author\/isha-kandaswamy\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Authentication Using Server-Side X.509 Certificates And N1QL","description":"Learn how to setup X509 certificates on Couchbase Server and use them with the N1QL query and CBQ shell for authentication and authorization.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.couchbase.com\/blog\/authentication-using-server-side-x-509-certificates-with-n1ql\/","og_locale":"en_US","og_type":"article","og_title":"Authentication Using Server-Side X.509 Certificates And N1QL","og_description":"Learn how to setup X509 certificates on Couchbase Server and use them with the N1QL query and CBQ shell for authentication and authorization.","og_url":"https:\/\/www.couchbase.com\/blog\/authentication-using-server-side-x-509-certificates-with-n1ql\/","og_site_name":"The Couchbase Blog","article_published_time":"2020-09-10T15:38:59+00:00","article_modified_time":"2021-01-31T21:04:38+00:00","og_image":[{"width":1200,"height":627,"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2020\/09\/Authentication-using-Server-side-X.509-Certificates-with-N1QL.png","type":"image\/png"}],"author":"Isha Kandaswamy","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Isha Kandaswamy","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/authentication-using-server-side-x-509-certificates-with-n1ql\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/authentication-using-server-side-x-509-certificates-with-n1ql\/"},"author":{"name":"Isha Kandaswamy","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/f236f76f209f447fbc8fd46d91eb7e52"},"headline":"Authentication Using Server-Side X.509 Certificates And N1QL","datePublished":"2020-09-10T15:38:59+00:00","dateModified":"2021-01-31T21:04:38+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/authentication-using-server-side-x-509-certificates-with-n1ql\/"},"wordCount":2094,"commentCount":0,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/authentication-using-server-side-x-509-certificates-with-n1ql\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","articleSection":["Best Practices and Tutorials","Security","SQL++ \/ N1QL Query"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/authentication-using-server-side-x-509-certificates-with-n1ql\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/authentication-using-server-side-x-509-certificates-with-n1ql\/","url":"https:\/\/www.couchbase.com\/blog\/authentication-using-server-side-x-509-certificates-with-n1ql\/","name":"Authentication Using Server-Side X.509 Certificates And N1QL","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/authentication-using-server-side-x-509-certificates-with-n1ql\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/authentication-using-server-side-x-509-certificates-with-n1ql\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","datePublished":"2020-09-10T15:38:59+00:00","dateModified":"2021-01-31T21:04:38+00:00","description":"Learn how to setup X509 certificates on Couchbase Server and use them with the N1QL query and CBQ shell for authentication and authorization.","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/authentication-using-server-side-x-509-certificates-with-n1ql\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/authentication-using-server-side-x-509-certificates-with-n1ql\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/authentication-using-server-side-x-509-certificates-with-n1ql\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","width":1800,"height":630},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/authentication-using-server-side-x-509-certificates-with-n1ql\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Authentication Using Server-Side X.509 Certificates And N1QL"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/blog\/#website","url":"https:\/\/www.couchbase.com\/blog\/","name":"The Couchbase Blog","description":"Couchbase, the NoSQL Database","publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/blog\/#organization","name":"The Couchbase Blog","url":"https:\/\/www.couchbase.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","width":218,"height":34,"caption":"The Couchbase Blog"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/f236f76f209f447fbc8fd46d91eb7e52","name":"Isha Kandaswamy","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/e8464106b598ad96e4e1446687ce93f6","url":"https:\/\/secure.gravatar.com\/avatar\/9c28181876ed38a9634b77ddbe73ada95b0f82838c0cce722be73968630d41e1?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9c28181876ed38a9634b77ddbe73ada95b0f82838c0cce722be73968630d41e1?s=96&d=mm&r=g","caption":"Isha Kandaswamy"},"description":"Isha Kandaswamy is a Senior Software Engineer at Couchbase. Isha is responsible for the development of designing the different features and tools for the N1QL Query Language -SQL for Json. Also, Designing and implementing features and tools for the N1QL query language.","url":"https:\/\/www.couchbase.com\/blog\/author\/isha-kandaswamy\/"}]}},"authors":[{"term_id":9057,"user_id":6882,"is_guest":0,"slug":"isha-kandaswamy","display_name":"Isha Kandaswamy","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/9c28181876ed38a9634b77ddbe73ada95b0f82838c0cce722be73968630d41e1?s=96&d=mm&r=g","author_category":"","last_name":"Kandaswamy","first_name":"Isha","job_title":"","user_url":"","description":"Isha Kandaswamy is a Senior Software Engineer at Couchbase. Isha is responsible for the development of designing the different features and tools for the N1QL Query Language -SQL for Json. Also, Designing and implementing features and tools for the N1QL query language."}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/9325","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/users\/6882"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/comments?post=9325"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/9325\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media\/13873"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media?parent=9325"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/categories?post=9325"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/tags?post=9325"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=9325"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}