Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support SAML 2.0 as IdP #7

Merged
merged 2 commits into from
Apr 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ gem 'jbuilder', '~> 2.5'

gem 'devise'
gem 'doorkeeper-openid_connect'
# bundle config local.saml_idp /Users/guochunzhong/git/sso/saml_idp/
gem 'saml_idp', git: 'https://github.com/thape-cn/saml_idp', branch: :master
# Encrypted Assertions require the xmlenc gem in saml_idp
# gem 'xmlenc'
gem 'pundit'

# Use ActiveStorage variant
Expand Down
21 changes: 19 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
GIT
remote: https://github.com/thape-cn/saml_idp
revision: 26d83c43a5fac763ff06babe1fc95866e8eb09fa
branch: master
specs:
saml_idp (0.8.0)
activesupport (>= 3.2)
builder (>= 3.0)
nokogiri (>= 1.6.2)
uuid (>= 2.3)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -79,7 +90,7 @@ GEM
capistrano (~> 3.7)
capistrano-bundler
puma (~> 3.4)
capybara (3.16.2)
capybara (3.17.0)
addressable
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
Expand Down Expand Up @@ -136,6 +147,8 @@ GEM
loofah (2.2.3)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
macaddr (1.7.1)
systemu (~> 2.6.2)
mail (2.7.1)
mini_mime (>= 0.1.1)
marcel (0.3.3)
Expand Down Expand Up @@ -218,7 +231,7 @@ GEM
sprockets (> 3.0)
sprockets-rails
tilt
selenium-webdriver (3.141.592)
selenium-webdriver (3.141.5926)
childprocess (>= 0.5, < 2.0)
rubyzip (~> 1.2, >= 1.2.2)
simplecov (0.16.1)
Expand All @@ -245,6 +258,7 @@ GEM
sshkit (1.18.2)
net-scp (>= 1.1.2)
net-ssh (>= 2.8.0)
systemu (2.6.5)
thor (0.20.3)
thread_safe (0.3.6)
thread_safe (0.3.6-java)
Expand All @@ -258,6 +272,8 @@ GEM
tzinfo (>= 1.0.0)
uglifier (4.1.20)
execjs (>= 0.3.0, < 3)
uuid (2.3.9)
macaddr (~> 1.0)
warden (1.2.8)
rack (>= 2.0.6)
web-console (3.7.0)
Expand Down Expand Up @@ -308,6 +324,7 @@ DEPENDENCIES
puma (~> 3.11)
pundit
rails (~> 5.2.2)
saml_idp!
sassc-rails
selenium-webdriver
simplecov
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ cp /usr/local/etc/openssl/cert.pem /usr/local/lib/ruby/gems/2.6.0/gems/httpclien
```


# Open ID Connect signing_key
# Generate signing key

## Open ID Connect

Just following [doorkeeper-openid_connect gem readme](https://github.com/doorkeeper-gem/doorkeeper-openid_connect#configuration):

Expand All @@ -37,3 +39,12 @@ openssl rsa -pubout -in oauth2id_oidc_private_key.pem -out oauth2id_oidc_public_
```

Notice replace oauth2id with your new site name, notice you can get public key from [/oauth/discovery/keys](https://oauth2id.dev/oauth/discovery/keys) as well.


## SAML 2.0

```bash
openssl req -x509 -sha256 -nodes -days 3650 -newkey rsa:2048 -keyout oauth2id_saml_key.key -out oauth2id_saml_cert.crt
# Show SHA1 Fingerprint
openssl x509 -in oauth2id_saml_cert.crt -noout -sha256 -fingerprint
```
22 changes: 22 additions & 0 deletions app/controllers/saml_idp_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class SamlIdpController < SamlIdp::IdpController
before_action :authenticate_user!, except: [:show]

# override create and make sure to set both "GET" and "POST" requests to /saml/auth to #create
def create
if user_signed_in?
@saml_response = idp_make_saml_response(current_user)
render :template => "saml_idp/idp/saml_post", :layout => false
return
else
# it shouldn't be possible to get here, but lets render 403 just in case
render :status => :forbidden
end
end

# NOT USED def idp_authenticate(email, password)

def idp_make_saml_response(found_user) # not using params intentionally
encode_response found_user
end
private :idp_make_saml_response
end
2 changes: 1 addition & 1 deletion config/credentials.yml.enc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Zi0l3qTRKl6027eFAaB/VNAPXeHFS1eX/MD9filQFggwhYnrGFfeQd3DYN8PTCgfLjipZb6NBlBhne3wMxPz0jLSj15LsCJ99eXCCvwaGGqRrNLv3ymPjAPVPXBvOOtnepJmn2/Vc/YEf/GNASU10CiNT6ioRY0DopHRdq08hfqm/NRYXYl0285pvvABz0YGMiBzhRrBGp4NQWFeECfFDWRFfvYvpDMjIHP0MM4avPOhbh73CHD2jDNhoPWRAsY22RQHDBRXHXVfNzyIOViHhW+VndIpGVK4SuYADjnPwFB/fhDeZ7/lhn00oOkvZAaOqzFOGDdZiGEAhnIMScFITOy4Y3o0vAqBlScfG2VdhncDl8NYqBKuKNNUdnDsqLSCFcu7aMAGXMD8md1cy+1IF7bVxWMP8WU/oaGR6v5L0KfBNHPX04qPHekIS7U3ZqFiw4+wc/IYt6rfwE/6N722Umbdk7cVr9c4DRhIIN0pfrMW77YAzZS/hymE7ygWij+uHkp3gx7Iah9cX0noIdTR2WR9to6JvGg8DNp7HJuMwKLhBpGCv2wsgz6KMy7kkzzTIDgbYNXF7Pi+710W6w3wsbLp7rhsne5Zo5/r25puZOZPyK/lJOIptyU5X0rRejtn6kgxfQa5cPS9sWU3O+3Mg7ijRlKTqCakTX0t8ke5S3S+rXevTx5hl3BL388dM/r/R6rvUHfZobgapTdVpqJrNHupu9GZjrKyhN0FCBsdgZoq1ZN3TrY85xU5jZa1q8CN2FkuqNnpn2fQx/PV8WWqAHo9Zj3g34ZHKkkV6dfArwVQMouNeWwvpK3XKOEqQwx3Nx9apX0J74aOVzYsxR9ciQaY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csbKj4t+05A0PUTByLmiriHE1UgVdBuTX3B4aFnoEGx9mjF1+aV8epMUdMDmna9XjcAt8Pcvajdsm7E9ExGyiHptpECTjH1Pg3fAe52jO8Aruhn5ZBxVa9lSbsYhYQzc7qvoMba+1JX/1RTKRtr/dg2ez1Xd5xbsVtxahmYRIaVdHM1gSdNB5weQfvroGKranQFDH5Mxnr/SJPfQRg+5bnSNACBkMMt4I5HkdknwOdEr9LkEdrCebaXt+KH5zdi6LwvHrA4bZY90V5aXBoW2AnJoSyiYyuVFoOsDZnu5Ty1Ijjf5mLWWB6xX6CYIDUocG60oakKFPGp6HO/B1GjoPDtJFTAxt3Oywi5MWDYh4X5y5zcxzGnip5dAEdltVgr7w3VR5/ZEK5Hna7MFEarpbeEseaKLfUafvtBTJ2717vIK4PWVPswE1+/bXD+pdP6US9gfBD8ilILQXu7ZgcB8YGDoaNO6Ef7Omhsfp1drEkV7evYQ9LTBp2ICSbRv6j4mKOumyEr2i7BSp3mhwDQ==--eCt64NCUxaif3the--CoRHjhLz0u7G5XwtKlPZAA==
53 changes: 53 additions & 0 deletions config/initializers/saml_idp.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
SamlIdp.configure do |config|
if Rails.env.development?
base = 'https://oauth2id.test'
else
base = 'https://oauth2id.dev'
end

config.x509_certificate = Rails.application.credentials.oauth2id_x509_certificate!

config.secret_key = Rails.application.credentials.oauth2id_x509_secret_key!

# NameIDFormat
config.name_id.formats = {
email_address: -> (principal) { principal.email },
transient: -> (principal) { principal.id },
persistent: -> (p) { p.id },
}

service_providers = {
"https://saml-example.test/saml/metadata" => {
fingerprint: Rails.application.credentials.oauth2id_x509_sha256_fingerprint!,
metadata_url: "https://saml-example.test/saml/metadata"
},
}

# `identifier` is the entity_id or issuer of the Service Provider,
# settings is an IncomingMetadata object which has a to_h method that needs to be persisted
config.service_provider.metadata_persister = ->(identifier, settings) {
fname = identifier.to_s.gsub(/\/|:/,"_")
FileUtils.mkdir_p(Rails.root.join('cache', 'saml', 'metadata').to_s)
File.open Rails.root.join("cache/saml/metadata/#{fname}"), "r+b" do |f|
Marshal.dump settings.to_h, f
end
}

# `service_provider` is a ServiceProvider object. Based on the `identifier` or the
# `service_provider` you should return the settings.to_h from above
config.service_provider.persisted_metadata_getter = ->(identifier, service_provider){
fname = identifier.to_s.gsub(/\/|:/,"_")
FileUtils.mkdir_p(Rails.root.join('cache', 'saml', 'metadata').to_s)
full_filename = Rails.root.join("cache/saml/metadata/#{fname}")
if File.file?(full_filename)
File.open full_filename, "rb" do |f|
Marshal.load f
end
end
}

# Find ServiceProvider metadata_url and fingerprint based on our settings
config.service_provider.finder = ->(issuer_or_entity_id) do
service_providers[issuer_or_entity_id]
end
end
5 changes: 5 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
use_doorkeeper
use_doorkeeper_openid_connect
resources :oauth2_applications, only: %i[update create]

get '/saml/auth' => 'saml_idp#create'
get '/saml/metadata' => 'saml_idp#show'
post '/saml/auth' => 'saml_idp#create'

devise_for :users, controllers: { sessions: 'user/sessions',
passwords: 'user/passwords',
confirmations: 'user/confirmations',
Expand Down