rack-saml 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock ADDED
@@ -0,0 +1,24 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rack-saml (0.0.3)
5
+ ruby-saml (~> 0.4.7)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ canonix (0.1.5)
11
+ macaddr (1.5.0)
12
+ systemu (>= 2.4.0)
13
+ ruby-saml (0.4.7)
14
+ canonix (~> 0.1)
15
+ uuid (~> 2.3)
16
+ systemu (2.5.0)
17
+ uuid (2.3.5)
18
+ macaddr (~> 1.0)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ rack-saml!
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # SAML (Shibboleth SP) middleware for Rack
1
+ # SAML (Shibboleth) SP middleware for Rack
2
2
 
3
- This project is deeply inspired by rack-shibboleth and ruby-saml. It is recommended to use the defact SAML implementation such as OpenSAML from the security or the functional aspect. However, there are also requirements to use SAML for light weight applications implemented by Ruby. rack-shibboleth may be a candidate to support such kind of objective. However it lacks the configurability to fit OmniAuth and OmniAuth Shibboleth Strategy. It also lacks the upgrade path to the secure and the stable SAML implementation like OpenSAML. So thus I just implemented a prototype to support SAML (Shibboleth SP) for Rack middleware.
3
+ This project is deeply inspired by rack-shibboleth and ruby-saml. It is recommended to use the de facto SAML implementation such as OpenSAML from the security or the functional aspect. However, there are also requirements to use SAML for light weight applications implemented by Ruby. rack-shibboleth may be a candidate to support such kind of objective. However it lacks the configurability to fit OmniAuth and OmniAuth Shibboleth Strategy. It also lacks the upgrade path to the secure and the stable SAML implementation like OpenSAML. So thus I just implemented a prototype to support SAML (Shibboleth SP) for Rack middleware.
4
4
 
5
5
  OmniAuth Shibboleth Strategy
6
6
  https://github.com/toyokazu/omniauth-shibboleth
@@ -33,7 +33,7 @@ Current implementation supports only Onelogin SAML assertion handler. It does no
33
33
 
34
34
  Rack::Saml uses Rack::Session functions. You have to insert Rack::Session before Rack::Saml middleware. Rack::Session::Cookie is used in the following examples because it is easiest to setup and scale. You can use the other Rack::Session implementation. In a Rails application, it uses ActionDispatch::Session which is compatible with Rack::Session by default. So thus, you do not need to add Rack::Session in the Rails application.
35
35
 
36
- #### For Rack applicaitons
36
+ **For Rack applicaitons**
37
37
 
38
38
  In the following example, config.ru is used to add Rack::Saml middleware into a Rails application.
39
39
 
@@ -43,7 +43,7 @@ In the following example, config.ru is used to add Rack::Saml middleware into a
43
43
  :metadata => "#{Rails.root}/config/metadata.yml",
44
44
  :attribute_map => "#{Rails.root}/config/attribute-map.yml"}
45
45
 
46
- #### For Ralis applications
46
+ **For Ralis applications**
47
47
 
48
48
  In the following example, config/application.rb is used to Rack::Saml middleware into a Rails application.
49
49
 
@@ -55,11 +55,11 @@ In the following example, config/application.rb is used to Rack::Saml middleware
55
55
  :attribute_map => "#{Rails.root}/config/attribute-map.yml"}
56
56
  ...
57
57
 
58
- #### Middleware options
58
+ **Middleware options**
59
59
 
60
- * *:config* path to rack-saml.yml file
61
- * *:metadata* path to metadata.yml file
62
- * *:attribute_map* path to attribute-map.yml file
60
+ * *:config*: path to rack-saml.yml file
61
+ * *:metadata*: path to metadata.yml file
62
+ * *:attribute_map*: path to attribute-map.yml file
63
63
 
64
64
  If you just want to test Rack::Saml, you can ommit middleware options in the both example (config.ru or config/application.rb).
65
65
 
@@ -73,25 +73,25 @@ Rack::Saml uses default configurations located in the rack-saml gem path.
73
73
 
74
74
  Please copy them to an arbitrary directory and edit them if you need. If you want to use your customized configuration file, do not forget to specify the configuration file path by middleware options.
75
75
 
76
- #### Configuration files
76
+ **Configuration files**
77
77
 
78
78
  You can find default configuration files at
79
79
 
80
80
  $GEM_HOME/rack-saml-x.x.x/config/xxx.yml
81
81
 
82
- ##### rack-saml.yml
82
+ **rack-saml.yml**
83
83
 
84
84
  Configuration to set SAML parameters. At least, you must configure saml_idp or shib_ds. They depends on your environments.
85
85
 
86
- * *protected_path* path name where rack-saml protects, e.g. /auth/shibboleth/callback (default path for OmniAuth Shibboleth Strategy)
87
- * *metadata_path* the path name where SP's metadata is generated
88
- * *assertion_handler* 'onelogin' / 'opensaml' (not implemented yet)
89
- * *saml_idp* IdP's entity ID which is used to authenticate user. This parameter can be omitted when you use Shibboleth Discovery Service (shib_ds).
90
- * *saml_sess_timeout* SP session timeout (default: 1800 seconds)
91
- * *shib_app_id* If you want to use the middleware as Shibboleth SP, you should specify an application ID. In the Shibboleth SP default configuration, 'default' is used as the application ID.
92
- * *shib_ds* If you want to use the middleware as Shibboleth SP and use discovery service, specify the uri of the Discovery Service.
93
- * *sp_cert* path to the SAML SP's certificate file, e.g. cert.pem (AuthnRequest Signing and Response Encryption are not supported yet)
94
- * *sp_key* path to the SAML SP's key file, e.g. key.pem (AuthnRequest Signing and Response Encryption are not supported yet)
86
+ * *protected_path*: path name where rack-saml protects, e.g. /auth/shibboleth/callback (default path for OmniAuth Shibboleth Strategy)
87
+ * *metadata_path*: the path name where SP's metadata is generated
88
+ * *assertion_handler*: 'onelogin' / 'opensaml' (not implemented yet)
89
+ * *saml_idp*: IdP's entity ID which is used to authenticate user. This parameter can be omitted when you use Shibboleth Discovery Service (shib_ds).
90
+ * *saml_sess_timeout*: SP session timeout (default: 1800 seconds)
91
+ * *shib_app_id*: If you want to use the middleware as Shibboleth SP, you should specify an application ID. In the Shibboleth SP default configuration, 'default' is used as the application ID.
92
+ * *shib_ds*: If you want to use the middleware as Shibboleth SP and use discovery service, specify the uri of the Discovery Service.
93
+ * *sp_cert*: path to the SAML SP's certificate file, e.g. cert.pem (AuthnRequest Signing and Response Encryption are not supported yet)
94
+ * *sp_key*: path to the SAML SP's key file, e.g. key.pem (AuthnRequest Signing and Response Encryption are not supported yet)
95
95
 
96
96
  SAML SP's entity ID (saml_sp) is automatically generated from request URI and /rack-saml-sp (fixed path name). The Assertion Consumer Service URI is generated from request URI and protected_path.
97
97
 
@@ -99,30 +99,30 @@ SAML SP's entity ID (saml_sp) is automatically generated from request URI and /r
99
99
  @config['saml_sp'] = "#{saml_sp_prefix}/rack-saml-sp"
100
100
  @config['assertion_consumer_service_uri'] = "#{saml_sp_prefix}#{@config['protected_path']}"
101
101
 
102
- ##### metadata.yml
102
+ **metadata.yml**
103
103
 
104
104
  To connect to an IdP, you must describe IdP's specification. In rack-saml, it should be written in metadata.yml. metadata.yml file include the following lists. You must generate your own metadata.yml by using conv_metadata.rb.
105
105
 
106
- * *idp_lists* list of IdP metadata
107
- * *sp_lists* list of SP metadata
106
+ * *idp_lists*: list of IdP metadata
107
+ * *sp_lists*: list of SP metadata
108
108
 
109
109
  idp_lists and sp_lists are hashes which have entity ids as key values.
110
110
 
111
111
  parameters of the idp_lists:
112
112
 
113
- * *certificate* base64 encoded certificate of IdP
114
- * *saml2_http_redirect* Location attribute of the IdP's assertion handler uri with HTTP Redirect Binding
113
+ * *certificate*: base64 encoded certificate of IdP
114
+ * *saml2_http_redirect*: Location attribute of the IdP's assertion handler uri with HTTP Redirect Binding
115
115
 
116
116
  parameters of the sp_lists (currently not used):
117
117
 
118
- * *certificate* base64 encoded certificate of SP
119
- * *saml2_http_post* Location attribute of the SP's assertion consumer uri with HTTP POST Binding
118
+ * *certificate*: base64 encoded certificate of SP
119
+ * *saml2_http_post*: Location attribute of the SP's assertion consumer uri with HTTP POST Binding
120
120
 
121
121
  These parameters are automatically extracted from SAML metadata (XML). You can use conv_metadata.rb command for extraction.
122
122
 
123
123
  % $GEM_HOME/rack-saml-x.x.x/bin/conv_metadata.rb metadata.xml > metadata.yml
124
124
 
125
- ##### attribute-map.yml
125
+ **attribute-map.yml**
126
126
 
127
127
  attribute-map.yml can extract attributes from SAML Response and put attributes on request environment variables. It is useful to pass attributes into applications. The configuration file format is as follows:
128
128
 
@@ -134,15 +134,15 @@ You can use default attribute-map.yml file. If you want to add new attributes, p
134
134
 
135
135
  ### Setup IdP to accept rack-saml SP
136
136
 
137
- #### SP Metadata generation
137
+ **SP Metadata generation**
138
138
 
139
139
  To connect a new SP to the existing IdP, you need to import SP's metadata into the IdP. rack-saml provides metadata generation function. It is generated at '/Shibboleth.sso/Metadata' by default.
140
140
 
141
- #### IdP configuration examples not to encrypt assertion
141
+ **IdP configuration examples not to encrypt assertion**
142
142
 
143
143
  Current rack-saml implementation does not support assertion encryption because Onelogin::Saml does not support AuthnRequest signing and Response encryption. So thus, in the followings, we would like to show sample configurations to disable encryption in IdP assertion processing. These are not recommended for sensitive applications.
144
144
 
145
- ##### Shibboleth IdP example
145
+ **Shibboleth IdP example**
146
146
 
147
147
  Add the following configuration after <rp:DefaultRelyingParty> in relying-party.xml. You should specify sp entity id at the 'id' and the 'provider' attributes.
148
148
 
@@ -157,7 +157,7 @@ Add the following configuration after <rp:DefaultRelyingParty> in relying-party.
157
157
  * write spec files
158
158
  * ruby-opensaml (I hope someone implement it :)
159
159
 
160
- ## License
160
+ ## License (MIT License)
161
161
 
162
162
  Copyright (C) 2011 by Toyokazu Akiyama.
163
163
 
data/bin/conv_metadata.rb CHANGED
@@ -15,7 +15,7 @@ file = File.new(ARGV[0])
15
15
  doc = REXML::Document.new(file)
16
16
 
17
17
  def get_list_type(elem)
18
- if !elem.elements["IDPSSODescriptor"].nil?
18
+ if elem.elements.any? {|el| el.has_name?("IDPSSODescriptor")}
19
19
  return "idp_lists"
20
20
  end
21
21
  "sp_lists"
@@ -24,11 +24,17 @@ end
24
24
  def create_entity_hash(elem, list_type)
25
25
  case list_type
26
26
  when "idp_lists"
27
- idp_elem = elem.elements["IDPSSODescriptor"]
27
+ idp_elem = elem.elements.find {|el| el.has_name?("IDPSSODescriptor")}
28
28
  # the first certificate is used
29
- certificate = "-----BEGIN CERTIFICATE-----#{REXML::XPath.first(idp_elem, './/ds:X509Certificate', 'ds' => DS).text.gsub(/\s*$/, "")}\n-----END CERTIFICATE-----"
29
+ cert_elem = REXML::XPath.first(idp_elem, './/ds:X509Certificate', 'ds' => DS)
30
+ # reject an IdP without a certificate
31
+ if cert_elem.nil?
32
+ puts "specified metadata has an IdP without certificate!"
33
+ exit 1
34
+ end
35
+ certificate = "-----BEGIN CERTIFICATE-----#{cert_elem.text.gsub(/\s+$/, "")}\n-----END CERTIFICATE-----"
30
36
  saml2_http_redirect = nil
31
- idp_elem.elements.each("SingleSignOnService") do |e|
37
+ idp_elem.elements.find_all {|el| el.has_name?("SingleSignOnService")}.each do |e|
32
38
  if e.attributes["Binding"] == "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect"
33
39
  saml2_http_redirect = e.attributes["Location"]
34
40
  end
@@ -36,11 +42,14 @@ def create_entity_hash(elem, list_type)
36
42
  return {"certificate" => certificate,
37
43
  "saml2_http_redirect" => saml2_http_redirect}
38
44
  when "sp_lists"
39
- sp_elem = elem.elements["SPSSODescriptor"]
45
+ sp_elem = elem.elements.find {|el| el.has_name?("SPSSODescriptor")}
46
+ #puts sp_elem.attributes["entityID"]
40
47
  # the first certificate is used
41
- certificate = REXML::XPath.first(sp_elem, './/ds:X509Certificate', 'ds' => DS).text
48
+ # permit a SP without a certificate
49
+ cert_elem = REXML::XPath.first(sp_elem, './/ds:X509Certificate', 'ds' => DS)
50
+ certificate = cert_elem.nil? ? "" : "-----BEGIN CERTIFICATE-----\n#{cert_elem.text.gsub(/\s+$/, "")}\n-----END CERTIFICATE-----"
42
51
  saml2_http_post = nil
43
- sp_elem.elements.each("AssertionConsumerService") do |e|
52
+ sp_elem.elements.find_all {|el| el.has_name?("AssertionConsumerService")}.each do |e|
44
53
  if e.attributes["Binding"] == "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
45
54
  saml2_http_post = e.attributes["Location"]
46
55
  end
@@ -57,12 +66,14 @@ def add_entities(entities, elem)
57
66
  end
58
67
 
59
68
  entities = {"idp_lists" => {}, "sp_lists" => {}}
60
- doc.elements.each("EntityDescriptor") do |elem|
69
+ doc.elements.find_all {|el| el.has_name?("EntityDescriptor")}.each do |elem|
61
70
  add_entities(entities, elem)
62
71
  end
63
72
 
64
- doc.elements.each("EntitiesDescriptor/EntityDescriptor") do |elem|
65
- add_entities(entities, elem)
73
+ doc.elements.find_all {|el| el.has_name?("EntitiesDescriptor")}.each do |elem1|
74
+ elem1.elements.find_all {|el| el.has_name?("EntityDescriptor")}.each do |elem2|
75
+ add_entities(entities, elem2)
76
+ end
66
77
  end
67
78
 
68
79
  puts entities.to_yaml
@@ -1,6 +1,6 @@
1
1
  require 'rack'
2
2
  module Rack
3
3
  module Saml
4
- VERSION = "0.0.2"
4
+ VERSION = "0.0.3"
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-saml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-06 00:00:00.000000000Z
12
+ date: 2012-04-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ruby-saml
16
- requirement: &2154954560 !ruby/object:Gem::Requirement
16
+ requirement: &70354144248580 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 0.4.7
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2154954560
24
+ version_requirements: *70354144248580
25
25
  description: SAML middleware for Rack (using ruby-saml)
26
26
  email:
27
27
  - toyokazu@gmail.com
@@ -29,13 +29,13 @@ executables: []
29
29
  extensions: []
30
30
  extra_rdoc_files: []
31
31
  files:
32
- - .README.md.swp
33
32
  - bin/conv_metadata.rb
34
33
  - config/attribute-map.yml
35
34
  - config/attribute-map.yml.sample
36
35
  - config/metadata.yml
37
36
  - config/rack-saml.yml
38
37
  - Gemfile
38
+ - Gemfile.lock
39
39
  - lib/rack/saml/metadata/abstract_metadata.rb
40
40
  - lib/rack/saml/metadata/onelogin_metadata.rb
41
41
  - lib/rack/saml/metadata/opensaml_metadata.rb
@@ -75,9 +75,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  version: '0'
76
76
  requirements: []
77
77
  rubyforge_project:
78
- rubygems_version: 1.8.12
78
+ rubygems_version: 1.8.17
79
79
  signing_key:
80
80
  specification_version: 3
81
81
  summary: SAML middleware for Rack (using ruby-saml)
82
82
  test_files: []
83
- has_rdoc:
data/.README.md.swp DELETED
Binary file