ssolo 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/README.md +96 -0
- data/exe/ssolo +30 -0
- data/lib/ssolo/certificate.rb +57 -0
- data/lib/ssolo/controller.rb +57 -0
- data/lib/ssolo/server.rb +114 -0
- data/lib/ssolo/templates/entry.rb +32 -0
- data/lib/ssolo/templates/metadata.rb +28 -0
- data/lib/ssolo/templates/response.rb +88 -0
- data/lib/ssolo/version.rb +5 -0
- data/lib/ssolo.rb +14 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0ccb40eda9b6ea1d0b4252545669ee1e966d4774c07d55eaa014a8af959a210a
|
4
|
+
data.tar.gz: 1a410aa070099ce4fe6caa8de8d11fdc0b0328a8d4dc723f18eddaf84e24d438
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a0ccf3bf281fe538b3417eb31a73dd38dd539e572ae9ed1b9c9f4fb2b040f9a628b2745f76b0a9cf1d01b6a7afedfd551c7d75e40693c65616062c35634715de
|
7
|
+
data.tar.gz: 81628f37ae67bfb4dba9c3ed1fe226c29b816f787b8f4f2b7a2361f03c796b3261b879a038de6c6ece69d471434d4c8acee86ad657874efb8f87b39eb86efe8c
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
10
|
+
identity and orientation.
|
11
|
+
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
13
|
+
diverse, inclusive, and healthy community.
|
14
|
+
|
15
|
+
## Our Standards
|
16
|
+
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
18
|
+
community include:
|
19
|
+
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
24
|
+
and learning from the experience
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
26
|
+
community
|
27
|
+
|
28
|
+
Examples of unacceptable behavior include:
|
29
|
+
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
31
|
+
any kind
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
33
|
+
* Public or private harassment
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
35
|
+
without their explicit permission
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
37
|
+
professional setting
|
38
|
+
|
39
|
+
## Enforcement Responsibilities
|
40
|
+
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
44
|
+
or harmful.
|
45
|
+
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
49
|
+
decisions when appropriate.
|
50
|
+
|
51
|
+
## Scope
|
52
|
+
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
54
|
+
an individual is officially representing the community in public spaces.
|
55
|
+
Examples of representing our community include using an official email address,
|
56
|
+
posting via an official social media account, or acting as an appointed
|
57
|
+
representative at an online or offline event.
|
58
|
+
|
59
|
+
## Enforcement
|
60
|
+
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
62
|
+
reported to the community leaders responsible for enforcement at
|
63
|
+
[INSERT CONTACT METHOD].
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
65
|
+
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
67
|
+
reporter of any incident.
|
68
|
+
|
69
|
+
## Enforcement Guidelines
|
70
|
+
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
73
|
+
|
74
|
+
### 1. Correction
|
75
|
+
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
77
|
+
unprofessional or unwelcome in the community.
|
78
|
+
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
82
|
+
|
83
|
+
### 2. Warning
|
84
|
+
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
86
|
+
actions.
|
87
|
+
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
93
|
+
ban.
|
94
|
+
|
95
|
+
### 3. Temporary Ban
|
96
|
+
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
98
|
+
sustained inappropriate behavior.
|
99
|
+
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
101
|
+
communication with the community for a specified period of time. No public or
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
104
|
+
Violating these terms may lead to a permanent ban.
|
105
|
+
|
106
|
+
### 4. Permanent Ban
|
107
|
+
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
111
|
+
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
113
|
+
community.
|
114
|
+
|
115
|
+
## Attribution
|
116
|
+
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
118
|
+
version 2.1, available at
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
120
|
+
|
121
|
+
Community Impact Guidelines were inspired by
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
123
|
+
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
127
|
+
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 Covidence
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
# SSOlo
|
2
|
+
|
3
|
+
SSOlo is a small SAML identity provider (IdP), for use in test and development environments in applications which operate as service providers - particularly for use with feature tests.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Install the gem and add to the application's Gemfile by executing:
|
8
|
+
|
9
|
+
```bash
|
10
|
+
bundle add ssolo
|
11
|
+
```
|
12
|
+
|
13
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
14
|
+
|
15
|
+
```bash
|
16
|
+
gem install ssolo
|
17
|
+
```
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Test Environments
|
22
|
+
|
23
|
+
Using SSOlo within a test suite can be done via an instance of `SSOlo::Controller`, where you can start the server with an immediately-returned Name ID/email address:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
controller = SSOlo::Controller.new
|
27
|
+
controller.start(
|
28
|
+
sp_certificate: <<~CERT,
|
29
|
+
-----BEGIN CERTIFICATE-----
|
30
|
+
...
|
31
|
+
-----END CERTIFICATE-----
|
32
|
+
CERT
|
33
|
+
name_id: "test@example.com"
|
34
|
+
)
|
35
|
+
|
36
|
+
# connect up the appropriate SAML settings via an
|
37
|
+
# OneLogin::RubySaml::Settings instance:
|
38
|
+
controller.settings #=> OneLogin::RubySaml::Settings
|
39
|
+
controller.settings.idp_entity_id
|
40
|
+
controller.settings.idp_sso_service_url
|
41
|
+
controller.settings.idp_cert
|
42
|
+
|
43
|
+
# These details are also available via a URL:
|
44
|
+
controller.metadata_url
|
45
|
+
|
46
|
+
# initiate a SAML request, and the following
|
47
|
+
# SAML response will be returned immediately with
|
48
|
+
# the specified name_id in the above `start` call.
|
49
|
+
|
50
|
+
# And then when you're done:
|
51
|
+
controller.stop
|
52
|
+
```
|
53
|
+
|
54
|
+
The SSOlo server will use ephemeral certificates and private keys, and the port will also change on every boot (following the behaviour of a standard Capybara server).
|
55
|
+
|
56
|
+
### Development Environments
|
57
|
+
|
58
|
+
To run SSOlo for a development environment, use the provided executable and manage settings via environment variables:
|
59
|
+
|
60
|
+
```sh
|
61
|
+
bundle exec ssolo \
|
62
|
+
SSOLO_PERSISTENCE=~/.ssolo.json \
|
63
|
+
SSOLO_SP_CERTIFICATE="-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----" \
|
64
|
+
SSOLO_HOST=127.0.0.1 \
|
65
|
+
SSOLO_PORT=9292 \
|
66
|
+
SSOLO_SILENT=true
|
67
|
+
```
|
68
|
+
|
69
|
+
`SSOLO_PERSISTENCE` can either be a file path, or "true" or "false". `SSOLO_SP_CERTIFICATE` must be specified with the certificate in PEM format. The other variables are optional (and the above values are the defaults).
|
70
|
+
|
71
|
+
You can also specify `SSOLO_NAME_ID` to keep the supplied name ID as a fixed value. But otherwise, you will be prompted for a value when you're going through the SAML flow.
|
72
|
+
|
73
|
+
The IdP server has two endpoints:
|
74
|
+
|
75
|
+
* `GET /metadata` which returns the XML metadata
|
76
|
+
* `GET /saml` which is the URL to initiate SAML requests
|
77
|
+
|
78
|
+
So, if you're running the server with the default environment variables, you should be able to see the metadata via [http://127.0.0.1:9292/metadata](http://127.0.0.1:9292/metadata).
|
79
|
+
|
80
|
+
## Development
|
81
|
+
|
82
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
83
|
+
|
84
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
85
|
+
|
86
|
+
## Contributing
|
87
|
+
|
88
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/pat/ssolo. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/pat/ssolo/blob/main/CODE_OF_CONDUCT.md).
|
89
|
+
|
90
|
+
## License
|
91
|
+
|
92
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
93
|
+
|
94
|
+
## Code of Conduct
|
95
|
+
|
96
|
+
Everyone interacting in the SSOlo project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/pat/ssolo/blob/main/CODE_OF_CONDUCT.md).
|
data/exe/ssolo
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- mode: ruby -*-
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
5
|
+
require "bundler/setup"
|
6
|
+
require "logger"
|
7
|
+
require "rack/handler/puma"
|
8
|
+
require "ssolo"
|
9
|
+
|
10
|
+
persistence = case ENV.fetch("SSOLO_PERSISTENCE", nil)
|
11
|
+
when "true"
|
12
|
+
true
|
13
|
+
when "false"
|
14
|
+
false
|
15
|
+
else
|
16
|
+
ENV.fetch("SSOLO_PERSISTENCE", nil)
|
17
|
+
end
|
18
|
+
|
19
|
+
Rack::Handler::Puma.run(
|
20
|
+
SSOlo::Server.new(
|
21
|
+
sp_certificate: ENV.fetch("SSOLO_SP_CERTIFICATE"),
|
22
|
+
default_name_id: ENV.fetch("SSOLO_NAME_ID", nil),
|
23
|
+
persistence:
|
24
|
+
),
|
25
|
+
Host: ENV.fetch("SSOLO_HOST", "127.0.0.1"),
|
26
|
+
Port: ENV.fetch("SSOLO_PORT", 9292),
|
27
|
+
Silent: ENV.fetch("SSOLO_SILENT", "true") == "true",
|
28
|
+
daemon: false,
|
29
|
+
config_files: ["-"]
|
30
|
+
)
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "openssl"
|
4
|
+
|
5
|
+
module SSOlo
|
6
|
+
# Generates an X509 certificate with the given private key. These certificates
|
7
|
+
# are not meant for production use.
|
8
|
+
class Certificate
|
9
|
+
def self.call(...)
|
10
|
+
new(...).call
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(private_key)
|
14
|
+
@private_key = private_key
|
15
|
+
end
|
16
|
+
|
17
|
+
# rubocop:disable Metrics/AbcSize
|
18
|
+
def call
|
19
|
+
OpenSSL::X509::Certificate.new.tap do |certificate|
|
20
|
+
certificate.version = 2
|
21
|
+
certificate.serial = 0
|
22
|
+
certificate.not_before = not_before
|
23
|
+
certificate.not_after = not_after
|
24
|
+
certificate.public_key = public_key
|
25
|
+
certificate.subject = name
|
26
|
+
certificate.issuer = name
|
27
|
+
certificate.sign(private_key, digest)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
# rubocop:enable Metrics/AbcSize
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
attr_reader :private_key
|
35
|
+
|
36
|
+
def digest
|
37
|
+
OpenSSL::Digest.new("SHA256")
|
38
|
+
end
|
39
|
+
|
40
|
+
def name
|
41
|
+
@name ||= OpenSSL::X509::Name.parse "/CN=nobody/DC=example"
|
42
|
+
end
|
43
|
+
|
44
|
+
# ~10 years
|
45
|
+
def not_after
|
46
|
+
Time.now + (10 * 365 * 24 * 60 * 60)
|
47
|
+
end
|
48
|
+
|
49
|
+
def not_before
|
50
|
+
Time.now
|
51
|
+
end
|
52
|
+
|
53
|
+
def public_key
|
54
|
+
private_key.public_key
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SSOlo
|
4
|
+
# Manages the external process of a SSOlo server
|
5
|
+
class Controller
|
6
|
+
MAXIMUM_ATTEMPTS = 20
|
7
|
+
|
8
|
+
def metadata_url
|
9
|
+
@metadata_url ||= "http://127.0.0.1:#{port}/metadata"
|
10
|
+
end
|
11
|
+
|
12
|
+
def settings
|
13
|
+
@settings ||= begin
|
14
|
+
wait_until_booted
|
15
|
+
|
16
|
+
OneLogin::RubySaml::IdpMetadataParser.new.parse_remote(
|
17
|
+
metadata_url
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def start(sp_certificate:, name_id: nil)
|
23
|
+
@pid = Process.spawn(
|
24
|
+
{
|
25
|
+
"SSOLO_PORT" => port.to_s,
|
26
|
+
"SSOLO_NAME_ID" => name_id,
|
27
|
+
"SSOLO_SP_CERTIFICATE" => sp_certificate
|
28
|
+
},
|
29
|
+
"bundle exec ssolo"
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
def stop
|
34
|
+
Process.kill("KILL", @pid)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def port
|
40
|
+
@port ||= Addrinfo.tcp("", 0).bind { |s| s.local_address.ip_port }
|
41
|
+
end
|
42
|
+
|
43
|
+
def wait_until_booted
|
44
|
+
attempts = 0
|
45
|
+
|
46
|
+
begin
|
47
|
+
Net::HTTP.get(URI(metadata_url))
|
48
|
+
rescue Errno::ECONNREFUSED
|
49
|
+
attempts += 1
|
50
|
+
raise if attempts > MAXIMUM_ATTEMPTS
|
51
|
+
|
52
|
+
sleep 0.1
|
53
|
+
retry
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/ssolo/server.rb
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rack"
|
4
|
+
require "saml_idp"
|
5
|
+
|
6
|
+
require_relative "certificate"
|
7
|
+
|
8
|
+
module SSOlo
|
9
|
+
# A rack app that operates as an extremely minimal SAML Identity Provider.
|
10
|
+
# There are two endpoints:
|
11
|
+
#
|
12
|
+
# - GET /metadata -- which returns the SAML IdP metadata as XML
|
13
|
+
# - GET /saml -- which, if there's a default name ID, renders a HTML form that
|
14
|
+
# submits immediately. Otherwise, renders a form asking for a name ID/email
|
15
|
+
# address
|
16
|
+
class Server
|
17
|
+
attr_reader :sp_certificate
|
18
|
+
|
19
|
+
def initialize(sp_certificate:, default_name_id: nil, persistence: false)
|
20
|
+
@sp_certificate = certificate_from_string(sp_certificate)
|
21
|
+
@default_name_id = default_name_id
|
22
|
+
@persistence = persistence
|
23
|
+
end
|
24
|
+
|
25
|
+
def call(env)
|
26
|
+
request = Rack::Request.new(env)
|
27
|
+
return four_oh_four unless request.get?
|
28
|
+
|
29
|
+
case request.path_info
|
30
|
+
when "/metadata"
|
31
|
+
metadata(request)
|
32
|
+
when "/saml"
|
33
|
+
saml(request)
|
34
|
+
else
|
35
|
+
[200, {}, [""]]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def certificate
|
40
|
+
@certificate ||= certificate_from_string(persisted_settings["certificate"])
|
41
|
+
end
|
42
|
+
|
43
|
+
def private_key
|
44
|
+
@private_key ||= OpenSSL::PKey::RSA.new(persisted_settings["private_key"])
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
attr_reader :default_name_id, :persistence
|
50
|
+
|
51
|
+
def certificate_from_string(value)
|
52
|
+
case value
|
53
|
+
when String
|
54
|
+
OpenSSL::X509::Certificate.new(value)
|
55
|
+
when OpenSSL::X509::Certificate
|
56
|
+
value
|
57
|
+
else
|
58
|
+
raise ArgumentError, "Invalid certificate: #{value}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def four_oh_four
|
63
|
+
[404, {}, ["Not Found"]]
|
64
|
+
end
|
65
|
+
|
66
|
+
def metadata(request)
|
67
|
+
[
|
68
|
+
200,
|
69
|
+
{ "Content-Type" => "application/xml; charset=utf-8" },
|
70
|
+
[SSOlo::Templates::Metadata.call(request, certificate)]
|
71
|
+
]
|
72
|
+
end
|
73
|
+
|
74
|
+
def new_settings
|
75
|
+
key = OpenSSL::PKey::RSA.new(2048)
|
76
|
+
|
77
|
+
{
|
78
|
+
"certificate" => SSOlo::Certificate.call(key).to_pem,
|
79
|
+
"private_key" => key.to_pem
|
80
|
+
}
|
81
|
+
end
|
82
|
+
|
83
|
+
def persistence_path
|
84
|
+
case persistence
|
85
|
+
when String
|
86
|
+
persistence
|
87
|
+
else
|
88
|
+
"~/.ssolo.json"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def persisted_settings
|
93
|
+
@persisted_settings ||= begin
|
94
|
+
settings = File.exist?(persistence_path) ? JSON.parse(File.read(persistence_path)) : new_settings
|
95
|
+
|
96
|
+
File.write(persistence_path, JSON.generate(settings)) if persistence
|
97
|
+
|
98
|
+
settings
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def saml(request)
|
103
|
+
name_id = default_name_id || request.params["name_id"]
|
104
|
+
|
105
|
+
html = if name_id && name_id.strip.length.positive?
|
106
|
+
SSOlo::Templates::Response.call(self, request, name_id)
|
107
|
+
else
|
108
|
+
SSOlo::Templates::Entry.call(request)
|
109
|
+
end
|
110
|
+
|
111
|
+
[200, { "Content-Type" => "text/html; charset=utf-8" }, [html]]
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SSOlo
|
4
|
+
module Templates
|
5
|
+
# Returns HTML for a form that contains an in-progress SAML request, with
|
6
|
+
# a field to specify a custom Name ID/email address.
|
7
|
+
class Entry
|
8
|
+
def self.call(request)
|
9
|
+
<<~HTML
|
10
|
+
<!DOCTYPE html>
|
11
|
+
<html>
|
12
|
+
<head>
|
13
|
+
<meta charset="utf-8">
|
14
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
15
|
+
</head>
|
16
|
+
<body>
|
17
|
+
<form method="get" action="#{request.base_url}/saml">
|
18
|
+
<input type="hidden" name="SAMLRequest" value="#{request.params['SAMLRequest']}">
|
19
|
+
<input type="hidden" name="RelayState" value="#{request.params['RelayState']}">
|
20
|
+
|
21
|
+
<label for="name_id">Email / Name ID</label>
|
22
|
+
<input type="text" name="name_id" id="name_id">
|
23
|
+
|
24
|
+
<input type="submit" value="Submit">
|
25
|
+
</form>
|
26
|
+
</body>
|
27
|
+
</html>
|
28
|
+
HTML
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SSOlo
|
4
|
+
module Templates
|
5
|
+
# Renders the XML details of the Identity Provider
|
6
|
+
class Metadata
|
7
|
+
def self.call(request, certificate)
|
8
|
+
<<~XML
|
9
|
+
<?xml version="1.0" encoding="utf-8"?>
|
10
|
+
<EntityDescriptor xmlns="urn:oasis:names:tc:SAML:2.0:metadata" entityID="#{request.base_url}/saml">
|
11
|
+
<IDPSSODescriptor protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
|
12
|
+
<KeyDescriptor>
|
13
|
+
<ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
|
14
|
+
<ds:X509Data>
|
15
|
+
<ds:X509Certificate>
|
16
|
+
#{certificate.to_pem.lines.grep_v(/BEGIN|END/).join.strip}
|
17
|
+
</ds:X509Certificate>
|
18
|
+
</ds:X509Data>
|
19
|
+
</ds:KeyInfo>
|
20
|
+
</KeyDescriptor>
|
21
|
+
<SingleSignOnService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect" Location="#{request.base_url}/saml" />
|
22
|
+
</IDPSSODescriptor>
|
23
|
+
</EntityDescriptor>
|
24
|
+
XML
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SSOlo
|
4
|
+
module Templates
|
5
|
+
# Returns the HTML output of an auto-submitting form, to post the SAML
|
6
|
+
# response through to the service provider.
|
7
|
+
class Response
|
8
|
+
def self.call(...)
|
9
|
+
new(...).call
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(server, request, name_id)
|
13
|
+
@server = server
|
14
|
+
@request = request
|
15
|
+
@name_id = name_id
|
16
|
+
end
|
17
|
+
|
18
|
+
# rubocop:disable Metrics/MethodLength
|
19
|
+
def call
|
20
|
+
configure_idp
|
21
|
+
|
22
|
+
<<~HTML
|
23
|
+
<!DOCTYPE html>
|
24
|
+
<html>
|
25
|
+
<head>
|
26
|
+
<meta charset="utf-8">
|
27
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
28
|
+
</head>
|
29
|
+
<body onload="document.forms[0].submit();" style="visibility:hidden;">
|
30
|
+
<form method="post" action="#{saml_request.acs_url}">
|
31
|
+
<input type="hidden" name="SAMLResponse" value="#{saml_response}" />
|
32
|
+
<input type="hidden" name="RelayState" value="#{request.params['RelayState']}" />
|
33
|
+
<input type="submit" value="Submit" />
|
34
|
+
</form>
|
35
|
+
</body>
|
36
|
+
</html>
|
37
|
+
HTML
|
38
|
+
end
|
39
|
+
# rubocop:enable Metrics/MethodLength
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
attr_reader :server, :request, :name_id
|
44
|
+
|
45
|
+
def configure_idp
|
46
|
+
SamlIdp.configure do |config|
|
47
|
+
config.base_saml_location = "#{request.base_url}/saml"
|
48
|
+
config.x509_certificate = server.certificate
|
49
|
+
config.secret_key = server.private_key
|
50
|
+
config.algorithm = :sha256
|
51
|
+
config.name_id.formats = {
|
52
|
+
email_address: ->(principal) { principal }
|
53
|
+
}
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def saml_request
|
58
|
+
@saml_request ||= SamlIdp::Request.from_deflated_request(
|
59
|
+
request.params["SAMLRequest"]
|
60
|
+
)
|
61
|
+
end
|
62
|
+
|
63
|
+
# rubocop:disable Metrics/MethodLength
|
64
|
+
def saml_response
|
65
|
+
SamlIdp::SamlResponse.new(
|
66
|
+
SecureRandom.uuid, # reference_id
|
67
|
+
SecureRandom.uuid, # response_id
|
68
|
+
"#{request.base_url}/saml", # issuer_uri
|
69
|
+
name_id, # principal / name ID
|
70
|
+
saml_request.issuer,
|
71
|
+
saml_request.request_id,
|
72
|
+
saml_request.acs_url,
|
73
|
+
OpenSSL::Digest::SHA256,
|
74
|
+
Saml::XML::Namespaces::AuthnContext::ClassRef::PASSWORD,
|
75
|
+
60 * 60, # expiry
|
76
|
+
{
|
77
|
+
# This is the service provider's certificate, so we can encrypt the
|
78
|
+
# response in a manner that only the service provider can decrypt.
|
79
|
+
cert: server.sp_certificate,
|
80
|
+
block_encryption: "aes256-cbc",
|
81
|
+
key_transport: "rsa-oaep-mgf1p"
|
82
|
+
}
|
83
|
+
).build
|
84
|
+
end
|
85
|
+
# rubocop:enable Metrics/MethodLength
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
data/lib/ssolo.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "ssolo/certificate"
|
4
|
+
require_relative "ssolo/controller"
|
5
|
+
require_relative "ssolo/server"
|
6
|
+
require_relative "ssolo/templates/entry"
|
7
|
+
require_relative "ssolo/templates/metadata"
|
8
|
+
require_relative "ssolo/templates/response"
|
9
|
+
require_relative "ssolo/version"
|
10
|
+
|
11
|
+
# This gem provides a minimal SAML Identity Provider (IdP) server, which can be
|
12
|
+
# used in development or test environments.
|
13
|
+
module SSOlo
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ssolo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pat Allan
|
8
|
+
bindir: exe
|
9
|
+
cert_chain: []
|
10
|
+
date: 2025-05-15 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: json
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ">="
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '0'
|
19
|
+
type: :runtime
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - ">="
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '0'
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: puma
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: rack
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
type: :runtime
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
name: ruby-saml
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
type: :runtime
|
62
|
+
prerelease: false
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: saml_idp
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
type: :runtime
|
76
|
+
prerelease: false
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
email:
|
83
|
+
- pat@freelancing-gods.com
|
84
|
+
executables:
|
85
|
+
- ssolo
|
86
|
+
extensions: []
|
87
|
+
extra_rdoc_files: []
|
88
|
+
files:
|
89
|
+
- CHANGELOG.md
|
90
|
+
- CODE_OF_CONDUCT.md
|
91
|
+
- LICENSE.txt
|
92
|
+
- README.md
|
93
|
+
- exe/ssolo
|
94
|
+
- lib/ssolo.rb
|
95
|
+
- lib/ssolo/certificate.rb
|
96
|
+
- lib/ssolo/controller.rb
|
97
|
+
- lib/ssolo/server.rb
|
98
|
+
- lib/ssolo/templates/entry.rb
|
99
|
+
- lib/ssolo/templates/metadata.rb
|
100
|
+
- lib/ssolo/templates/response.rb
|
101
|
+
- lib/ssolo/version.rb
|
102
|
+
homepage: https://github.com/pat/ssolo
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
metadata:
|
106
|
+
homepage_uri: https://github.com/pat/ssolo
|
107
|
+
source_code_uri: https://github.com/pat/ssolo
|
108
|
+
changelog_uri: https://github.com/pat/ssolo/blob/main/CHANGELOG.md
|
109
|
+
rubygems_mfa_required: 'true'
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 3.1.0
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubygems_version: 3.6.4
|
125
|
+
specification_version: 4
|
126
|
+
summary: A micro SAML IdP for development/test environments
|
127
|
+
test_files: []
|