openshift-origin-auth-kerberos 0.8.8

Sign up to get free protection for your applications and to get access to all the features.
data/COPYRIGHT ADDED
@@ -0,0 +1 @@
1
+ Copyright 2012 Red Hat, Inc. and/or its affiliates.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,11 @@
1
+ Licensed under the Apache License, Version 2.0 (the "License");
2
+ you may not use this file except in compliance with the License.
3
+ You may obtain a copy of the License at
4
+
5
+ http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ Notice of Export Control Law
2
+
3
+ This software distribution includes cryptographic software that is subject to the U.S. Export Administration Regulations (the "*EAR*") and other U.S. and foreign laws and may not be exported, re-exported or transferred (a) to any country listed in Country Group E:1 in Supplement No. 1 to part 740 of the EAR (currently, Cuba, Iran, North Korea, Sudan & Syria); (b) to any prohibited destination or to any end user who has been prohibited from participating in U.S. export transactions by any federal agency of the U.S. government; or (c) for use in connection with the design, development or production of nuclear, chemical or biological weapons, or rocket systems, space launch vehicles, or sounding rockets, or unmanned air vehicle systems.You may not download this software or technical information if you are located in one of these countries or otherwise subject to these restrictions. You may not provide this software or technical information to individuals or entities located in one of these countries or otherwise subject to these restrictions. You are also responsible for compliance with foreign law requirements applicable to the import, export and use of this software and technical information.
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ #require "bundler/gem_tasks"
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ sh "/usr/bin/mongo localhost/openshift_origin_broker_test --eval 'db.addUser(\"openshift\", \"mooo\")'"
7
+ t.libs << 'test'
8
+ t.warning = false
9
+ t.verbose = true
10
+ t.test_files = FileList['test/**/*_test.rb']
11
+ end
@@ -0,0 +1,8 @@
1
+ module Swingshift
2
+ module AuthService
3
+ require 'openshift-origin-auth-kerberos/engine/engine' if defined?(Rails) && Rails::VERSION::MAJOR == 3
4
+ end
5
+ end
6
+
7
+ require "openshift-origin-auth-kerberos/lib/openshift/kerberos_auth_service.rb"
8
+ OpenShift Origin::AuthService.provider=Swingshift::KerberosAuthService
@@ -0,0 +1,20 @@
1
+ class AccountController < BaseController
2
+ respond_to :xml, :json
3
+ before_filter :authenticate, :check_version
4
+
5
+ def create
6
+ username = params[:username]
7
+
8
+ auth_config = Rails.application.config.auth
9
+ auth_service = Swingshift::KerberosAuthService.new(auth_config)
10
+
11
+ Rails.logger.debug "username = #{username}"
12
+
13
+ log_action('nil', 'nil', username, "ADD_USER", false, "Cannot create account, managed by kerberos")
14
+ @reply = RestReply.new(:unprocessable_entity)
15
+ @reply.messages.push(Message.new(:error, "Cannot create account, managed by kerberos", 1001, "username"))
16
+ respond_with @reply, :status => @reply.status
17
+ return
18
+
19
+ end
20
+ end
@@ -0,0 +1,12 @@
1
+ class RestAccount < OpenShift Origin::Model
2
+ attr_accessor :username, :created_on
3
+
4
+ def initialize(username, created_on)
5
+ self.username, self.created_on = username, created_on
6
+ end
7
+
8
+ def to_xml(options={})
9
+ options[:tag_name] = "account"
10
+ super(options)
11
+ end
12
+ end
@@ -0,0 +1,7 @@
1
+ Rails.application.routes.draw do
2
+ scope "/rest" do
3
+ constraints(:ip => %r(127.0.\d+.\d+)) do
4
+ resource :accounts, :only => [:create], :controller => :account
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ require 'openshift-origin-controller'
2
+ require 'rails'
3
+
4
+ module OpenShift Origin
5
+ class KerberosAuthServiceEngine < Rails::Engine
6
+ paths.app.controllers << "lib/openshift-kerberos-plugin/app/controllers"
7
+ paths.lib << "lib/openshift-kerberos-plugin/lib"
8
+ paths.config << "lib/openshift-kerberos-plugin/config"
9
+ paths.app.models << "lib/openshift-kerberos-plugin/app/models"
10
+ config.autoload_paths += %W(#{config.root}/lib)
11
+ end
12
+ end
@@ -0,0 +1,117 @@
1
+ require 'rubygems'
2
+ require 'digest/md5'
3
+ require 'openshift-origin-controller'
4
+ require 'date'
5
+ require 'krb5_auth'
6
+
7
+ include Krb5Auth
8
+
9
+ module Swingshift
10
+ class KerberosAuthService < OpenShift Origin::AuthService
11
+
12
+ def initialize(auth_info = nil)
13
+ Rails.logger.debug "Initializing KerberosAuthService"
14
+ if auth_info != nil
15
+ # no-op
16
+ elsif defined? Rails
17
+ auth_info = Rails.application.config.auth
18
+ else
19
+ raise Exception.new("Error initilizing KerberosAuthService")
20
+ end
21
+
22
+ @salt = auth_info[:salt]
23
+ @privkeyfile = auth_info[:privkeyfile]
24
+ @privkeypass = auth_info[:privkeypass]
25
+ @pubkeyfile = auth_info[:pubkeyfile]
26
+ end
27
+
28
+ def generate_broker_key(app)
29
+ cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
30
+ cipher.encrypt
31
+ cipher.key = OpenSSL::Digest::SHA512.new(@salt).digest
32
+ cipher.iv = iv = cipher.random_iv
33
+ token = {:app_name => app.name,
34
+ :login => app.user.login,
35
+ :creation_time => app.creation_time}
36
+ encrypted_token = cipher.update(token.to_json)
37
+ encrypted_token << cipher.final
38
+
39
+ public_key = OpenSSL::PKey::RSA.new(File.read(@pubkeyfile), @privkeypass)
40
+ encrypted_iv = public_key.public_encrypt(iv)
41
+
42
+ # Base64 encode the iv and token
43
+ encoded_iv = Base64::encode64(encrypted_iv)
44
+ encoded_token = Base64::encode64(encrypted_token)
45
+
46
+ [encoded_iv, encoded_token]
47
+ end
48
+
49
+ def validate_broker_key(iv, key)
50
+ key = key.gsub(" ", "+")
51
+ iv = iv.gsub(" ", "+")
52
+ begin
53
+ encrypted_token = Base64::decode64(key)
54
+ cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
55
+ cipher.decrypt
56
+ cipher.key = OpenSSL::Digest::SHA512.new(@salt).digest
57
+ private_key = OpenSSL::PKey::RSA.new(File.read(@privkeyfile), @privkeypass)
58
+ cipher.iv = private_key.private_decrypt(Base64::decode64(iv))
59
+ json_token = cipher.update(encrypted_token)
60
+ json_token << cipher.final
61
+ rescue => e
62
+ Rails.logger.debug "Broker key authentication failed. #{e.backtrace.inspect}"
63
+ raise OpenShift Origin::AccessDeniedException.new
64
+ end
65
+
66
+ token = JSON.parse(json_token)
67
+ username = token['login']
68
+ app_name = token['app_name']
69
+ creation_time = token['creation_time']
70
+
71
+ user = CloudUser.find(username)
72
+ raise OpenShift Origin::AccessDeniedException.new if user.nil?
73
+ app = Application.find(user, app_name)
74
+
75
+ raise OpenShift Origin::AccessDeniedException.new if app.nil? or creation_time != app.creation_time
76
+ return {:username => username, :auth_method => :broker_auth}
77
+ end
78
+
79
+ def authenticate(request, login, password)
80
+ params = request.request_parameters()
81
+ if params['broker_auth_key'] && params['broker_auth_iv']
82
+ validate_broker_key(params['broker_auth_iv'], params['broker_auth_key'])
83
+ else
84
+ raise OpenShift Origin::AccessDeniedException if login.nil? || login.empty? || password.nil? || password.empty?
85
+ krb5 = Krb5.new
86
+
87
+ # get the default realm
88
+ default_realm = krb5.get_default_realm
89
+ Rails.logger.debug "Default realm is: " + default_realm
90
+ # try to cache non-existant data (this should fail and throw an exception)
91
+ begin
92
+ krb5.cache
93
+ rescue Krb5Auth::Krb5::Exception
94
+ Rails.logger.debug "Failed caching credentials before obtaining them. Continuing..."
95
+ end
96
+
97
+ if krb5.get_init_creds_password(login,password)
98
+ krb5.close
99
+ return {:username => login, :auth_method => :login}
100
+ else
101
+ krb5.close
102
+ raise OpenShift Origin::AccessDeniedException
103
+ end
104
+
105
+ end
106
+ end
107
+
108
+ def login(request, params, cookies)
109
+ if params['broker_auth_key'] && params['broker_auth_iv']
110
+ validate_broker_key(params['broker_auth_iv'], params['broker_auth_key'])
111
+ else
112
+ data = JSON.parse(params['json_data'])
113
+ return authenticate(request, data['rhlogin'], params['password'])
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ lib_dir = File.join(File.join("lib", "**"), "*")
4
+ test_dir = File.join(File.join("test", "**"), "*")
5
+ bin_dir = File.join("bin","*")
6
+ spec_file = "rubygem-openshift-origin-auth-kerberos.spec"
7
+
8
+ Gem::Specification.new do |s|
9
+ s.name = "openshift-origin-auth-kerberos"
10
+ s.version = `rpm -q --qf "%{version}\n" --specfile #{spec_file}`.split[0]
11
+ s.license = `rpm -q --qf "%{license}\n" --specfile #{spec_file}`.split[0]
12
+ s.authors = ["Jason DeTiberus"]
13
+ s.email = ["jdetiber@redhat.com"]
14
+ s.homepage = `rpm -q --qf "%{url}\n" --specfile #{spec_file}`.split[0]
15
+ s.summary = `rpm -q --qf "%{description}\n" --specfile #{spec_file}`.split[0]
16
+ s.description = `rpm -q --qf "%{description}\n" --specfile #{spec_file}`.split[0]
17
+
18
+ s.files = Dir[lib_dir] + Dir[bin_dir]
19
+ s.test_files = Dir[test_dir]
20
+ s.executables = Dir[bin_dir].map {|binary| File.basename(binary)}
21
+ s.files += %w(README.md Rakefile Gemfile rubygem-openshift-origin-auth-kerberos.spec openshift-origin-auth-kerberos.gemspec LICENSE COPYRIGHT)
22
+ s.require_paths = ["lib"]
23
+
24
+ s.add_dependency('openshift-origin-controller')
25
+ s.add_dependency('json')
26
+ s.add_dependency('krb5-auth')
27
+ s.add_development_dependency('rake')
28
+ s.add_development_dependency('bundler')
29
+ s.add_development_dependency('mocha')
30
+ end
@@ -0,0 +1,112 @@
1
+ %global ruby_sitelib %(ruby -rrbconfig -e "puts Config::CONFIG['sitelibdir']")
2
+ %global gemdir %(ruby -rubygems -e 'puts Gem::dir' 2>/dev/null)
3
+ %global gemname openshift-origin-auth-kerberos
4
+ %global geminstdir %{gemdir}/gems/%{gemname}-%{version}
5
+
6
+ Summary: OpenShift Origin plugin for kerberos auth service
7
+ Name: rubygem-%{gemname}
8
+ Version: 0.8.8
9
+ Release: 1%{?dist}
10
+ Group: Development/Languages
11
+ License: ASL 2.0
12
+ URL: http://openshift.redhat.com
13
+ Source0: rubygem-%{gemname}-%{version}.tar.gz
14
+ BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
15
+ Requires: ruby(abi) = 1.8
16
+ Requires: rubygems
17
+ Requires: rubygem(openshift-origin-common)
18
+ Requires: rubygem(json)
19
+ Requires: rubygem(mocha)
20
+ Requires: openshift-origin-broker
21
+ Requires: selinux-policy-targeted
22
+ Requires: policycoreutils-python
23
+ Requires: rubygem(krb5-auth)
24
+
25
+ BuildRequires: ruby
26
+ BuildRequires: rubygems
27
+ BuildArch: noarch
28
+ Provides: rubygem(%{gemname}) = %version
29
+
30
+ %package -n ruby-%{gemname}
31
+ Summary: OpenShift Origin plugin for kerberos auth service
32
+ Requires: rubygem(%{gemname}) = %version
33
+ Provides: ruby(%{gemname}) = %version
34
+ Obsoletes: rubygem-swingshift-kerberos-plugin
35
+
36
+ %description
37
+ Provides a kerberos auth service based plugin
38
+
39
+ %description -n ruby-%{gemname}
40
+ Provides a kerberos auth service based plugin
41
+
42
+ %prep
43
+ %setup -q
44
+
45
+ %build
46
+
47
+ %install
48
+ rm -rf %{buildroot}
49
+ mkdir -p %{buildroot}%{gemdir}
50
+ mkdir -p %{buildroot}%{ruby_sitelib}
51
+
52
+ # Build and install into the rubygem structure
53
+ gem build %{gemname}.gemspec
54
+ gem install --local --install-dir %{buildroot}%{gemdir} --force %{gemname}-%{version}.gem
55
+
56
+ # Symlink into the ruby site library directories
57
+ ln -s %{geminstdir}/lib/%{gemname} %{buildroot}%{ruby_sitelib}
58
+ ln -s %{geminstdir}/lib/%{gemname}.rb %{buildroot}%{ruby_sitelib}
59
+
60
+ mkdir -p %{buildroot}/var/www/openshift/broker/config/environments/plugin-config
61
+ cat <<EOF > %{buildroot}/var/www/openshift/broker/config/environments/plugin-config/openshift-origin-auth-kerberos.rb
62
+ Broker::Application.configure do
63
+ config.auth = {
64
+ :salt => "ClWqe5zKtEW4CJEMyjzQ",
65
+ :privkeyfile => "/var/www/openshift/broker/config/server_priv.pem",
66
+ :privkeypass => "",
67
+ :pubkeyfile => "/var/www/openshift/broker/config/server_pub.pem",
68
+ }
69
+ end
70
+ EOF
71
+
72
+ %clean
73
+ rm -rf %{buildroot}
74
+
75
+ %post
76
+ /usr/bin/openssl genrsa -out /var/www/openshift/broker/config/server_priv.pem 2048
77
+ /usr/bin/openssl rsa -in /var/www/openshift/broker/config/server_priv.pem -pubout > /var/www/openshift/broker/config/server_pub.pem
78
+
79
+ echo "The following variables need to be set in your rails config to use openshift-origin-auth-kerberos:"
80
+ echo "auth[:salt] - salt for the password hash"
81
+ echo "auth[:privkeyfile] - RSA private key file for node-broker authentication"
82
+ echo "auth[:privkeypass] - RSA private key password"
83
+ echo "auth[:pubkeyfile] - RSA public key file for node-broker authentication"
84
+
85
+ %files
86
+ %defattr(-,root,root,-)
87
+ %dir %{geminstdir}
88
+ %doc %{geminstdir}/Gemfile
89
+ %{gemdir}/doc/%{gemname}-%{version}
90
+ %{gemdir}/gems/%{gemname}-%{version}
91
+ %{gemdir}/cache/%{gemname}-%{version}.gem
92
+ %{gemdir}/specifications/%{gemname}-%{version}.gemspec
93
+
94
+ %attr(0440,apache,apache) /var/www/openshift/broker/config/environments/plugin-config/openshift-origin-auth-kerberos.rb
95
+
96
+ %files -n ruby-%{gemname}
97
+ %{ruby_sitelib}/%{gemname}
98
+ %{ruby_sitelib}/%{gemname}.rb
99
+
100
+ %changelog
101
+ * Fri Oct 05 2012 Krishna Raman <kraman@gmail.com> 0.8.8-1
102
+ - new package built with tito
103
+
104
+ * Thu Aug 16 2012 Brenton Leanhardt <bleanhar@redhat.com> 0.8.7-1
105
+ - new package built with tito
106
+
107
+ * Wed Aug 15 2012 Jason DeTiberus <jason.detiberus@redhat.com> 0.8.6-1
108
+ - kerberos auth plugin (jason.detiberus@redhat.com)
109
+
110
+ * Wed Aug 15 2012 Jason DeTiberus <jason.detiberus@redhat.com> 0.8.5-1
111
+ - new package built with tito
112
+
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: openshift-origin-auth-kerberos
3
+ version: !ruby/object:Gem::Version
4
+ hash: 47
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 8
9
+ - 8
10
+ version: 0.8.8
11
+ platform: ruby
12
+ authors:
13
+ - Jason DeTiberus
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-10-22 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: openshift-origin-controller
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: json
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: krb5-auth
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :runtime
62
+ version_requirements: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ name: rake
65
+ prerelease: false
66
+ requirement: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ type: :development
76
+ version_requirements: *id004
77
+ - !ruby/object:Gem::Dependency
78
+ name: bundler
79
+ prerelease: false
80
+ requirement: &id005 !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ type: :development
90
+ version_requirements: *id005
91
+ - !ruby/object:Gem::Dependency
92
+ name: mocha
93
+ prerelease: false
94
+ requirement: &id006 !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ hash: 3
100
+ segments:
101
+ - 0
102
+ version: "0"
103
+ type: :development
104
+ version_requirements: *id006
105
+ description: Provides
106
+ email:
107
+ - jdetiber@redhat.com
108
+ executables: []
109
+
110
+ extensions: []
111
+
112
+ extra_rdoc_files: []
113
+
114
+ files:
115
+ - lib/openshift-kerberos-plugin.rb
116
+ - lib/openshift-kerberos-plugin/engine/engine.rb
117
+ - lib/openshift-kerberos-plugin/app/models/rest_account.rb
118
+ - lib/openshift-kerberos-plugin/app/controllers/account_controller.rb
119
+ - lib/openshift-kerberos-plugin/config/routes.rb
120
+ - lib/openshift-kerberos-plugin/lib/openshift/kerberos_auth_service.rb
121
+ - README.md
122
+ - Rakefile
123
+ - Gemfile
124
+ - rubygem-openshift-origin-auth-kerberos.spec
125
+ - openshift-origin-auth-kerberos.gemspec
126
+ - LICENSE
127
+ - COPYRIGHT
128
+ has_rdoc: true
129
+ homepage: http://openshift.redhat.com
130
+ licenses:
131
+ - ASL
132
+ post_install_message:
133
+ rdoc_options: []
134
+
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ hash: 3
143
+ segments:
144
+ - 0
145
+ version: "0"
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ none: false
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ hash: 3
152
+ segments:
153
+ - 0
154
+ version: "0"
155
+ requirements: []
156
+
157
+ rubyforge_project:
158
+ rubygems_version: 1.3.7
159
+ signing_key:
160
+ specification_version: 3
161
+ summary: Provides
162
+ test_files: []
163
+