Code Monkey home page Code Monkey logo

docker-kdc's Introduction

docker-kdc

Docker container generator for a Heimdal Kerberos 5 KDC.

The intension here is to ease the first steps with Kerberos while also allowing a customized, automated setup for development or test integration. Usable on plain Linux as well as on OSX.


Dependencies

  • Docker
  • jq 1.4

Linux specific dependency

  • Heimdal Kerberos 5

OSX specific dependency

  • boot2docker

Usage

Check your configuration

The default configuration is likely to be fine for your first steps, validate it using the config command.

./kdc config

You will receive a list of relevant configuration information. The defaults are derived from your hosts' configuration to allow for a quick test setup.

Example output: ./kdc config

System
  fqdn:      hostname.domain.name
KDC
  nat:       127.0.0.1
  port:      48088
Kerberos
  domain:    domain.name
  realm:     DOMAIN.NAME
  principal: tillt/[email protected], password: matilda

Build the docker image

./kdc build

This will render the image which is based on plain ubuntu 14.04. Additionally the packages heimdal-kdc as well as libsasl2-modules-gssapi-heimdal are installed. The latter is useful only if you extend this container image by further applications making use of Kerberos authentication via SASL2's GSSAPI.

Run the container

./kdc start

On OSX, this step starts by setting up the VM (via boot2docker). Then, on all host systems, the container is started in detached mode, allowing you to keep on working with this shell without having to fork another process. The container name is directly derived from the hostname supplied via the configuration (see Configuration).

Watch the KDC server log file

docker exec -it kdc tail -f /var/log/heimdal-kdc.log

Run a quick test

./kdc test

On OSX, this first checks if the VM is active. Then, on all hosts systems, a network connection to the KDC is attempted.

Prepare the environment

$(./kdc shellinit)

A Kerberos client needs access to a configuration file. To prevent having to edit the system wide configuration file (/etc/krb5.conf) a local, minimal version is rendered and supplied once the container has gotten started. Additionally, the keytab also gets exported and hence needs to be accessible for clients making use of password-less authentication. To make use of the files, environment variables that are interpreted by Kerberos clients are prepared.

Render a ticket supplying the principal password

kinit tillt/[email protected]

Password: matilda

Check the ticket

klist

On OSX you could also use the Ticket Viewer to check the details of the issued ticket (open "/System/Library/CoreServices/Ticket Viewer.app").

Example output: klist

Credentials cache: API:42926CE1-63E2-4C66-B2D7-00B2F198182F
        Principal: tillt/[email protected]

  Issued                Expires               Principal
Nov 26 11:06:25 2014  Nov 26 21:06:25 2014  krbtgt/[email protected]

Remove the ticket

kdestroy

Check the content of the keytab

ktutil --keytab=krb5.keytab list

Example output: ktutil --keytab=krb5.keytab list

krb5.keytab:

Vno  Type                     Principal                              Aliases
  1  aes256-cts-hmac-sha1-96  tillt/[email protected]
  1  des3-cbc-sha1            tillt/[email protected]
  1  arcfour-hmac-md5         tillt/[email protected]

Render a ticket using keytab based authentication

kinit -kt krb5.keytab tillt/[email protected]

Check the ticket

klist

[...]

Stop the container

./kdc stop

This will stop the KDC server, stop and remove the container and additionally remove the temporary keytab and configuration files.

Customize your configuration

You may use environment variables and/or a JSON configuration file for customizing the setup. The default filename for the JSON file is kdc.json but may be configured by the environment variable KDC_CONFIG.

The default configuration is most likely good enough for your first experiments.

Kerberos principal

env. variable config node default
KDC_PRINCIPAL id tillt

Note: using a configuration file allows setting up multiple principals (via principals[ ].id).

Kerberos password

env. variable config node default
KDC_PASSWORD password matilda

Note: using a configuration file allows setting up multiple passwords (via principals[ ].password).

Kerberos client

env. variable config node default
KDC_CLIENT n/a oufput of hostname -s

Note: when no principals are defined via configuration file, KDC_CLIENT is used to create a full service principal (schema: KDC_PRINCIPAL / KDC_CLIENT . KDC_DOMAIN_NAME @ KDC_REALM_NAME ).

KDC hostname

env. variable config node default
KDC_HOST_NAME n/a kdc

External KDC IP

env. variable config node default
KDC_NATHOST nat 127.0.0.1

Note: this value gets overridden by the kdc script on OSX to allow for connecting to the boot2docker VM. You shouldn't really need to override this in any case.

External KDC port

env. variable config node default
KDC_PORT port 48088

Kerberos domain name

env. variable config node default
KDC_DOMAIN_NAME domain hostname cut off output of hostname -f

Kerberos realm name

env. variable config node default
KDC_REALM_NAME realm capitalized value of KDC_DOMAIN_NAME

Note: it is common practice to simply use the domain-name but all capitalized for this.

Configuration filename

env. variable config node default
KDC_CONFIG n/a kdc.json

templates/kdc.json

{
  "principals": [
    {
      "id": "tillt/[email protected]",
      "password": "herbert"
    },
    {
      "id": "[email protected]",
      "password": "herbert"
    }
  ],
  "domain": "example.com",
  "realm": "EXAMPLE.COM",
  "ip": "127.0.0.1",
  "port": 48088
}

Reference

./kdc start|stop|build|clean|config|shellinit

build

Builds the docker image.

start

Starts the container in detached mode while also producing a Kerberos configuration file (krb5.conf) as well as a Kerberos keytab (krb5.keytab) locally.

Note that the keytab is only readable/usable by the current user unless you change its access rights which is not recommended for production environments.

stop

Stops the container and deletes krb5.conf as well as krb5.keytab.

clean

Removes the docker image.

config

Shows relevant configuration information.

test

Checks if the KDC is reachable and accepting connections.

shellinit

Renders the environment variables needed for using the KDC. KRB5_CONFIG points towards the temporary configuration file. KRB5_KTNAME points towards the temporary keytab file.


TODO

  • strip down base image to squeeze out some space
  • refactor code into something less convoluted
  • allow for an admin server, not just the KDC

Credits

This script was inspired by some work of a co-worker of mine, Matthias Veit. Matthias did the hard work of finding out how to properly route docker ports on boot2docker hosts.


Author

docker-kdc's People

Contributors

mikethomsen avatar pka avatar rayburgemeestre avatar seanf avatar tillt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

docker-kdc's Issues

use docker compose

I'd love to see docker-compose.yml substituting the bash script (./kdc) as much as possible

Unable to build the container: Errors were encountered while processing: heimdal-kdc

I am building the container to give it a try. The ./kdc build fails for me with following:

...
Setting up krb5-config (2.3) ...
debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (This frontend requires a controlling tty.)
debconf: falling back to frontend: Teletype
Setting up libfile-copy-recursive-perl (0.38-1) ...
Setting up tcpd (7.6.q-25) ...
Setting up update-inetd (4.43) ...
debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (This frontend requires a controlling tty.)
debconf: falling back to frontend: Teletype
Setting up heimdal-clients (1.6~git20131207+dfsg-1ubuntu1.1) ...
update-alternatives: using /usr/bin/kftp to provide /usr/bin/ftp (ftp) in auto mode
update-alternatives: using /usr/bin/ktelnet to provide /usr/bin/telnet (telnet) in auto mode
update-alternatives: using /usr/bin/krsh to provide /usr/bin/rsh (rsh) in auto mode
update-alternatives: using /usr/bin/krcp to provide /usr/bin/rcp (rcp) in auto mode
update-alternatives: using /usr/bin/kpagsh to provide /usr/bin/pagsh (pagsh) in auto mode
Setting up openbsd-inetd (0.20091229-2ubuntu3) ...
invoke-rc.d: policy-rc.d denied execution of stop.
invoke-rc.d: policy-rc.d denied execution of start.
Processing triggers for ureadahead (0.100.0-16) ...
Setting up heimdal-kdc (1.6~git20131207+dfsg-1ubuntu1.1) ...
debconf: unable to initialize frontend: Dialog
debconf: (TERM is not set, so the dialog frontend is not usable.)
debconf: falling back to frontend: Readline
debconf: unable to initialize frontend: Readline
debconf: (This frontend requires a controlling tty.)
debconf: falling back to frontend: Teletype
kstash: writing key to `/var/lib/heimdal-kdc/m-key'
kstash: writing master key file: No such file or directory
dpkg: error processing package heimdal-kdc (--configure):
 subprocess installed post-installation script returned error exit status 1
Processing triggers for libc-bin (2.19-0ubuntu6.7) ...
Processing triggers for sgml-base (1.26+nmu4ubuntu1) ...
Processing triggers for ureadahead (0.100.0-16) ...
Errors were encountered while processing:
 heimdal-kdc
E: Sub-process /usr/bin/dpkg returned an error code (1)
The command '/bin/sh -c apt-get -y install heimdal-kdc' returned a non-zero code: 100
  • Docker version 1.12.1, build 23cf638
  • Commit 3c80d27

kdc + ldap

any chance for providing sample having kdc with ldap integrated on the server side?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.