Kerberos python lib for add/edit/delete a principal?

1k views Asked by At

I have found python-kerberos and pykadm5. python-kerberos can auth a user, but has no api for adding/editing/deleting a principal. pykadm5 hasn't updated in a long time. I can't use it to connect to the KDC. Can anyone point me to a python lib for adding/editing/deleting a principal? My OS is Ubuntu; my Python version is 2.6.

1

There are 1 answers

0
Yx.Ac On

you can refer to the repository https://github.com/russjancewicz/python-kadmin/, maybe this post can get you some idea:

def create_test_prinicipal():
  data = None
  if not os.path.isfile(TEST_KEYTAB):
    command = '''
      spawn kadmin.local -p [email protected]
      expect "kadmin.local:" {{ send "ank {0}\r" }}
      expect "Enter password for principal" {{ send "{1}\r" }}
      expect "Re-enter password for principal" {{ send "{1}\r" }}
      expect "kadmin.local:" {{ send "cpw {0}\r" }}
      expect "Enter password for principal" {{ send "{1}\r" }}
      expect "Re-enter password for principal" {{ send "{1}\r" }}
      expect "kadmin.local:" {{ send "ktadd -kt {2} -norandkey {0}\r"}}
      expect "kadmin.local:" {{ exit 1 }}
    '''.format(TEST_PRINCIPAL, TEST_PASSWORD, TEST_KEYTAB)

    expect = subprocess.Popen(['expect'], shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

    expect.communicate(command.encode())
    expect.wait()