4

I am trying to connect to SQL server from my .net core app deployed in PCF. I am able to connect when I use username and password. But Unable to configure Windows authentication. My app has a requirement to use windows authentication

This link ( https://github.com/Microsoft/vscode-mssql/issues/985#issuecomment-345408856) says enable Kerberos authentication in SQL .

I have configured SQL server with kerberos. Still unable to connect. What else is required?

Exception I get while connecting:

Cannot access Kerberos ticket. Ensure Kerberos has been initialized with 'kinit'.

halfer
  • 19,824
  • 17
  • 99
  • 186
SNA
  • 7,528
  • 12
  • 44
  • 60

1 Answers1

0

This answer is not correct. I was able to connect to SQL server from PCF, using kerberos.
First I created a user id and password for connecting to the database and checked with Windows authentication whether I am able to connect to the DB.
Then I created a krb5.config.
A sample file

[libdefaults]
    renew_lifetime = 7d
    forwardable = false
    default_realm = ABC.NET
    ticket_lifetime = 24h
    dns_lookup_realm = false
    dns_lookup_kdc = false
    #default_tgs_enctypes = aes des3-cbc-sha1 rc4 des-cbc-md5
    #default_tkt_enctypes = aes des3-cbc-sha1 rc4 des-cbc-md5
    #hortonworks hive jdbc troubleshooting
    udp_preference_limit = 1
    
    
    [domain_realm]
        abc.net = ABC.NET
    
    [logging]
        default = FILE:/var/log/krb5kdc.log
        admin_server = FILE:/var/log/kadmind.log
        kdc = FILE:/var/log/krb5kdc.log
    
    [realms]
        ABC.NET = {
            admin_server = server.abc.net
            kdc = server.abc.net
        }

Followed by this I created a SQLDriver Config file:

SQLJDBCDriver {
    com.sun.security.auth.module.Krb5LoginModule required
    debug=true
    useTicketCache=true
    renewTGT=true
    ticketCache="/home/vcap/app/krb_ticket"
    useKeyTab=true
    keyTab="/home/vcap/app/BOOT-INF/classes/test.keytab"
    principal="userid@ABC.NET"
    useFirstPass=true
    tryFirstPass=true
    storePass=true
    storeKey=true
    serviceName="database-host-name"
}
    
JAVA_OPTS: -XX:ParallelGCThreads=8 -XX:MaxPermSize=2048m -XX:+UseConcMarkSweepGC -XX:+UseCompressedOops -XX:MaxDirectMemorySize=512m -Duser.timezone="America/Chicago" -DLOG_FILE="/home/vcap/logs/activity.log" -Djava.security.krb5.conf=/home/vcap/app/BOOT-INF/classes/krb5-test.conf -Dsun.security.krb5.debug=true -Djava.security.krb5.realm=ABC.NET -Djava.security.krb5.kdc=server.abc.net -Djavax.security.auth.useSubjectCredsOnly=false -Djava.security.auth.login.config=/home/vcap/app/BOOT-INF/classes/mssql-jdbc-test.conf
    doNotPrompt=true;
};

DataSource config

I included all the config files in the resources folder.

It worked for me

Tyler2P
  • 2,324
  • 26
  • 22
  • 31
Aneesh
  • 1
  • 2