DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • API and Security: From IT to Cyber
  • The Impact of Biometric Authentication on User Privacy and the Role of Blockchain in Preserving Secure Data
  • The Role of Zero-Knowledge Proofs in LLM Chains for Data Privacy
  • Navigating the API Seas: A Product Manager's Guide to Authentication

Trending

  • The Cypress Edge: Next-Level Testing Strategies for React Developers
  • How AI Agents Are Transforming Enterprise Automation Architecture
  • AI’s Role in Everyday Development
  • Article Moderation: Your Questions, Answered
  1. DZone
  2. Data Engineering
  3. Data
  4. Import Data Into CockroachDB With Kerberos Authentication

Import Data Into CockroachDB With Kerberos Authentication

A customer had asked how to leverage bulk utilities in CockroachDB while authenticated via Kerberos.

By 
Artem Ervits user avatar
Artem Ervits
DZone Core CORE ·
Jan. 26, 22 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
5.1K Views

Join the DZone community and get the full member experience.

Join For Free

Articles Covering CockroachDB and Kerberos

I find the topic of Kerberos very interesting and my colleagues commonly refer to me for help with this complex topic. I am by no means an expert at Kerberos, I am however familiar enough with it to be dangerous. That said, I've written multiple articles on the topic which you may find below:

  • Part 1: CockroachDB with MIT Kerberos
  • Part 2: CockroachDB With Active Directory
  • Part 3: CockroachDB With MIT Kerberos and Docker Compose

I was recently asked by a customer whether GSSAPI gets in the way of doing a table import in CockroachDB. The short answer is it shouldn't as GSSAPI is abstracted from any bulk-io operations. I've previously written articles on doing an import into Cockroach, here and here and encourage you to review those articles. So today we're going to focus on specifically the import with Kerberos.

We will need an instance of CockroachDB, Kerberos and a GSSAPI compatible client like psql. If you've read my previous articles in the series, I already have a repo with docker compose environment where we can demo this.

  1. Copy the cockroach-gssapi directory to your machine:
 
git clone https://github.com/dbist/cockroach-docker


  1. Create a directory called import in the root of the project and map it in docker-compose.

We need to map a directory locally to iterate through creating a working import sql file, it makes it easier to develop sql on your host and make it visible in Docker.

So under the volumes in the psql service in my docker-compose.yml, I added an entry for import.

 
cd cockroach-docker/cockroach-gssapi
mkdir import


 
volumes:
      - ./kdc/krb5.conf:/etc/krb5.conf
      - ./psql/start.sh:/start.sh
      - certs-client:/certs
      - keytab:/keytab
      - ${PWD}/import:/import


  1. Run ./up.sh script to start the environment.
 
./up.sh
cockroach uses an image, skipping
Building roach-cert
Step 1/15 : FROM cockroachdb/cockroach:v20.1.3 AS generator
 ---> 25bee4f016c4
...
Creating roach-cert ... done
Creating kdc        ... done
Creating cockroach  ... done
Creating psql       ... done
CREATE ROLE

Time: 8.8429ms

GRANT

Time: 7.2032ms

SET CLUSTER SETTING

Time: 12.1494ms

SET CLUSTER SETTING

Time: 9.583ms

SET CLUSTER SETTING

Time: 8.3226ms

SET CLUSTER SETTING

Time: 8.1053ms


     4. Check to make sure all containers are up.

 
docker-compose ps


 
   Name                 Command               State                Ports
--------------------------------------------------------------------------------------
cockroach    /cockroach/cockroach.sh st ...   Up      0.0.0.0:26257->26257/tcp,
                                                      0.0.0.0:8080->8080/tcp
kdc          /start.sh                        Up
psql         /start.sh                        Up      5432/tcp
roach-cert   /bin/sh -c tail -f /dev/null     Up

     

      5. Create an import file in the import directory on your host.

It is easier to split your terminal window. On my host, I created a file called import.sql and placed it in my import directory.

 
DROP TABLE IF EXISTS countries;

IMPORT
TABLE
    countries (
        id INT8 PRIMARY KEY, country STRING,
        INDEX country_idx (country)
    )
CSV
    DATA ('https://api.mockaroo.com/api/3b3df050?count=1000&key=02f7f490');


    6. Validate this file is available in the psql container.

 
docker exec -it psql bin/sh
# ls /import
import.sql


    7. Add user tester adminprivileges to perform import.

We can stay in the psql instance or use the cockroach instance directly to do so. Keep in mind that I only have one admin user currently and it's root. The only way to login with root is by using certs.

 
docker exec -it psql bin/sh 


 
psql "postgresql://cockroach:26257?sslcert=/certs%2Fclient.root.crt&sslkey=/certs%2Fclient.root.key&sslmode=verify-full&sslrootcert=/certs%2Fca.crt"


 
# psql "postgresql://cockroach:26257?sslcert=/certs%2Fclient.root.crt&sslkey=/certs%2Fclient.root.key&sslmode=verify-full&sslrootcert=/certs%2Fca.crt"
psql (9.5.22, server 9.5.0)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES128-GCM-SHA256, bits: 128, compression: off)
Type "help" for help.

root=# GRANT ADMIN TO tester;
GRANT
root=# \q


    8. Make sure the user performing the import is authenticated with Kerberos.

 
# kinit tester
Password for tester@EXAMPLE.COM:
# klist
Ticket cache: FILE:/tmp/krb5cc_0
Default principal: tester@EXAMPLE.COM

Valid starting       Expires              Service principal
07/24/2020 15:34:06  07/25/2020 15:34:06  krbtgt/EXAMPLE.COM@EXAMPLE.COM
    renew until 07/24/2020 15:34:06


    9. Perform the import as user tester

 
psql "postgresql://cockroach:26257/defaultdb?sslmode=verify-full&sslrootcert=/certs/ca.crt" -U tester -f /import/import.sql


 
DROP TABLE
       job_id       |  status   | fraction_completed | rows | index_entries | bytes
--------------------+-----------+--------------------+------+---------------+-------
 575191699644153857 | succeeded |                  1 | 1000 |          1000 | 41220
(1 row)

#


We can look at the data now.

 
psql "postgresql://cockroach:26257/defaultdb?sslmode=verify-full&sslrootcert=/certs/ca.crt" -U tester


 
defaultdb=> select count(*) from countries;
 count
-------
  1000
(1 row)

defaultdb=> select * from countries limit 5;
 id |   country
----+-------------
  1 | Philippines
  2 | Indonesia
  3 | Indonesia
  4 | Cape Verde
  5 | Ecuador
(5 rows)

defaultdb=>


And that's that, we validated that user tester was able to perform an import over GSSAPI. Until next time!

Kerberos (protocol) CockroachDB Data (computing) authentication

Published at DZone with permission of Artem Ervits. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • API and Security: From IT to Cyber
  • The Impact of Biometric Authentication on User Privacy and the Role of Blockchain in Preserving Secure Data
  • The Role of Zero-Knowledge Proofs in LLM Chains for Data Privacy
  • Navigating the API Seas: A Product Manager's Guide to Authentication

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!