class OpenShift::NsupdatePlugin

OpenShift DNS Plugin to interact with dynamic DNS using {www.ietf.org/rfc/rfc2136 RFC 2136} update protocol and {www.ietf.org/rfc/rfc2845 RFC 2845} DNS TSIG

Implements the OpenShift::DnsService interface

This class uses the nsupdate(8) program to communicate with the DNS service.

The object can be configured either by providing the access_info parameter or by pulling the settings from the Rails.application.config object (if it exists).

When pulling from the Rails configuration this plugin expects to find the #domain_suffix in

Rails.application.config.openshift[:domain_suffix]

and the rest of the parameters in a hash at

Rails.application.config.dns

@example nsupdate plugin configuration hash - HMAC-MD5 TSIG

{:server => "myserver",
 :port => portnumber,
 :keyname => "TSIG key name",
 :keyvalue => "TSIG key string",
 :keyalgorithm => ["HMAC-MD5"|"HMAC-SHA1"|"HMAC-SHA256"|"HMAC-SHA512"]
 :zone => "zone to update",
 # only when configuring with parameters
 :domain_suffix => "suffix for application domain names"
 }

@example nsupdate plugin configuration hash - KRB5 GSS-TSIG

{:server => "myserver",
 :port => portnumber,
 :krb_principal => "The authentication principal",
 :krb_keytab => "The authentication key",
 :zone => "zone to update",
 # only when configuring with parameters
 :domain_suffix => "suffix for application domain names"
 }

@!attribute [r] server

@return [String] IP address of the DNS update server

@!attribute [r] port

@return [Fixnum] UDP port for the DNS update server

@!attribute [r] keyname

@return [String] the TSIG key name

@!attribute [r] keyvalue

@return [String] the TSIG key value

@!attribute [r] keyalgorithm

@return [String] the TSIG key algorithm

@!attribute [r] #krb_principal

@return [String] A Kerberos 5 principal

@!attribute [r] #krb_keytab

@return [String] the Kerberos keytab

Attributes

domain_suffix[R]
keyalgorithm[R]
keyname[R]
keyvalue[R]
krb_keytab[R]
krb_principal[R]
port[R]
server[R]
zone[R]

Public Class Methods

new(access_info = nil) click to toggle source

Establish the parameters for a connection to the DNS update service

@param access_info [Hash] communication configuration settings @see NsupdatePlugin NsupdatePlugin class Examples

# File lib/openshift/nsupdate_plugin.rb, line 74
def initialize(access_info = nil)
  if access_info != nil
    @domain_suffix = access_info[:domain_suffix]
  elsif defined? Rails
    access_info = Rails.application.config.dns
    @domain_suffix = Rails.application.config.openshift[:domain_suffix]
  else
    raise DNSException.new("Nsupdate DNS updates are not initialized")
  end

  @server = access_info[:server]
  @port = access_info[:port].to_i
  @keyname = access_info[:keyname]
  @keyvalue = access_info[:keyvalue]
  @keyalgorithm = access_info[:keyalgorithm] || "HMAC-MD5"
  @krb_principal = access_info[:krb_principal]
  @krb_keytab = access_info[:krb_keytab]
  @zone = access_info[:zone]

  # verify that the plugin can read the keytab file, if specified
  if @krb_keytab
    if not File.exists? @krb_keytab
      raise DNSException.new "missing GSS keytab file: #{@krb_keytab}"
    
    elsif not File.readable? @krb_keytab
      raise DNSException.new(
          "keytab file #{@krb_keytab} is not readable by UID #{Process.uid}"
          )
    end
  end
     
end

Public Instance Methods

close() click to toggle source

close any persistent connection to the update server @return [nil]

# File lib/openshift/nsupdate_plugin.rb, line 246
def close
end
deregister_application(app_name, namespace) click to toggle source

Unpublish an application - remove DNS record

@param [String] app_name

The name of the application to publish

@param [String] namespace

The namespace which contains the application

@return [Object]

The response from the service provider in what ever form
that takes
# File lib/openshift/nsupdate_plugin.rb, line 211
def deregister_application(app_name, namespace)
  # delete the CNAME record for the application in the domain
  fqdn = "#{app_name}-#{namespace}.#{@domain_suffix}"

  cmd = del_cmd(fqdn)

  success = system cmd
  if not success
    raise DNSException.new("error deleting app record #{fqdn}")
  end  
end
modify_application(app_name, namespace, public_hostname) click to toggle source

Change the published location of an application - Modify DNS record

@param [String] app_name

The name of the application to publish

@param [String] namespace

The namespace which contains the application

@param [String] public_hostname

The name of the location where the application resides

@return [Object]

The response from the service provider in what ever form
that takes
# File lib/openshift/nsupdate_plugin.rb, line 234
def modify_application(app_name, namespace, public_hostname)
  deregister_application(app_name, namespace)
  register_application(app_name, namespace, public_hostname)
end
publish() click to toggle source

send any queued requests to the update server @return [nil]

# File lib/openshift/nsupdate_plugin.rb, line 241
def publish
end
register_application(app_name, namespace, public_hostname) click to toggle source

Publish an application - create DNS record

@param [String] app_name

The name of the application to publish

@param [String] namespace

The namespace which contains the application

@param [String] public_hostname

The name of the location where the application resides

@return [Object]

The response from the service provider in what ever form
that takes
# File lib/openshift/nsupdate_plugin.rb, line 190
def register_application(app_name, namespace, public_hostname)
  # create an A record for the application in the domain
  fqdn = "#{app_name}-#{namespace}.#{@domain_suffix}"
  
  cmd = add_cmd(fqdn, public_hostname)

  success = system cmd
  if not success
    raise DNSException.new("error adding app record #{fqdn}")
  end
end

Private Instance Methods

add_cmd(fqdn, value) click to toggle source

Generate an nsupdate add command string

@param fqdn [String] DNS record name to add @param value [String] DNS record value @return [String]

An nsupdate command sequence
# File lib/openshift/nsupdate_plugin.rb, line 116
    def add_cmd(fqdn, value)

      # authenticate if credentials have been given
      if @krb_principal
        cmd = "kinit -kt #{@krb_keytab} #{@krb_principal} && \\\n"
        else
        cmd = ""
      end

      # If the config gave a TSIG key, use it
      keystring = @keyname ? "key #{@keyalgorithm}:#{@keyname} #{keyvalue}" :
                  @krb_principal ?  "gsstsig" : ""

      zonestring = @zone ? "zone #{@zone}" : ""

      # compose the nsupdate add command
      cmd += %Q{nsupdate <<EOF
#{keystring}
server #{@server} #{@port}
#{zonestring}
update add #{fqdn} 60 CNAME #{value}
send
quit
EOF
}


    end
del_cmd(fqdn) click to toggle source

Generate an nsupdate delete command string

@param fqdn [String] DNS record name to delete @return [String]

An nsupdate command sequence
# File lib/openshift/nsupdate_plugin.rb, line 151
    def del_cmd(fqdn)
      # authenticate if credentials have been given
      if @krb_principal
        cmd = "kinit -kt #{@krb_keytab} #{@krb_principal} && \\\n"
        else
        cmd = ""
      end

      # If the config gave a TSIG key, use it
      keystring = @keyname ? "key #{@keyname} #{keyvalue}" :
                  @krb_principal ?  "gsstsig" : ""

      zonestring = @zone ? "zone #{@zone}" : ""

      # compose the nsupdate add command
      cmd += %Q{nsupdate <<EOF
#{keystring}
server #{@server} #{@port}
#{zonestring}
update delete #{fqdn}
send
quit
EOF
}
    end