revbits_pam_cicd 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 52f46e4654c3559f2ab572ceb651453270a2f554c1e296b14a506611561171f9
4
+ data.tar.gz: cd0e51451883e9e91848ec30558920b2270b9bb77759a50f41042d7472a9d2c1
5
+ SHA512:
6
+ metadata.gz: 20cc7a9016fcab0cd5e48b2a434783cd0971e2e59894ce997ae33b30164ba572b0018910a2d23634a118a35ca3218b98c3e06e71ee63148287699abbd7dd74fc
7
+ data.tar.gz: f9797824c82b48eaca7e13458f47800a09b4587d408d67d41ac4a83a8682a197e34bc588244bfb10bb9eb5159ab7a0f16171c566e4aa126167d86ad7ac206f35
@@ -0,0 +1,18 @@
1
+ name: Ruby
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 3.0.1
14
+ - name: Run the default task
15
+ run: |
16
+ gem install bundler -v 2.2.15
17
+ bundle install
18
+ bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ .idea/*
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.4
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-09-15
4
+
5
+ - Initial release
6
+
7
+ ## [0.1.1] - 2022-01-14
8
+
9
+ - Fixed URLs in different files
10
+ ## [0.1.2] - 2022-01-26
11
+
12
+ - Rename Gem
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at sajjad.umar@invozone.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in revbits_pam_cicd.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.7"
data/Gemfile.lock ADDED
@@ -0,0 +1,57 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ revbits_pam_cicd (0.1.2)
5
+ aes-everywhere (~> 1.2, >= 1.2.5)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ aes-everywhere (1.2.5)
11
+ ast (2.4.2)
12
+ diff-lcs (1.5.0)
13
+ parallel (1.21.0)
14
+ parser (3.1.0.0)
15
+ ast (~> 2.4.1)
16
+ rainbow (3.1.1)
17
+ rake (13.0.6)
18
+ regexp_parser (2.2.0)
19
+ rexml (3.2.5)
20
+ rspec (3.10.0)
21
+ rspec-core (~> 3.10.0)
22
+ rspec-expectations (~> 3.10.0)
23
+ rspec-mocks (~> 3.10.0)
24
+ rspec-core (3.10.1)
25
+ rspec-support (~> 3.10.0)
26
+ rspec-expectations (3.10.2)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.10.0)
29
+ rspec-mocks (3.10.2)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.10.0)
32
+ rspec-support (3.10.3)
33
+ rubocop (1.25.0)
34
+ parallel (~> 1.10)
35
+ parser (>= 3.1.0.0)
36
+ rainbow (>= 2.2.2, < 4.0)
37
+ regexp_parser (>= 1.8, < 3.0)
38
+ rexml
39
+ rubocop-ast (>= 1.15.1, < 2.0)
40
+ ruby-progressbar (~> 1.7)
41
+ unicode-display_width (>= 1.4.0, < 3.0)
42
+ rubocop-ast (1.15.1)
43
+ parser (>= 3.0.1.1)
44
+ ruby-progressbar (1.11.0)
45
+ unicode-display_width (2.1.0)
46
+
47
+ PLATFORMS
48
+ x86_64-darwin-20
49
+
50
+ DEPENDENCIES
51
+ rake (~> 13.0)
52
+ revbits_pam_cicd!
53
+ rspec (~> 3.0)
54
+ rubocop (~> 1.7)
55
+
56
+ BUNDLED WITH
57
+ 2.2.3
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 sumar7
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,90 @@
1
+ # Revbits PAM
2
+
3
+ This gem give you programmatic access to securely fetch secrets form RevBits PAM.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'revbits_pam'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install revbits_pam
20
+
21
+ ## Usage
22
+
23
+ ### Configuration
24
+
25
+ RevBits PAM supports the following configurations
26
+
27
+ - [Basic Configuration](#basic-configuration)
28
+ - [ENV Configuration](#env-configuration)
29
+ - [Block Configuration](#block-configuration)
30
+
31
+ #### Basic Configuration
32
+
33
+ The simplest configuration is to supply required attributes to configuration object as follows:
34
+
35
+ ```ruby
36
+ # Authentication Type (Optional), default (and only available option for now) is :pam
37
+ RevbitsPamCicd.configuration.auth_type = :pam
38
+
39
+ # 'appliance_url' required
40
+ RevbitsPamCicd.configuration.appliance_url = "https://your-appliance-url.com"
41
+
42
+ # 'api_key' required
43
+ RevbitsPamCicd.configuration.api_key = "YourRevBitsPamApiKey"
44
+ ```
45
+
46
+ #### ENV Configuration
47
+
48
+ RevBits PAM will automatically fetch the configuration if the following ENV variables are set.
49
+
50
+ - `REVBITS_AUTH_TYPE` (Optional)
51
+ - `REVBITS_APPLIANCE_URL` (Required)
52
+ - `REVBITS_API_KAY` (Required)
53
+
54
+ #### Block Configuration
55
+
56
+ RevBits PAM also supports configuration via block as follows:
57
+
58
+ ```ruby
59
+ RevbitsPamCicd.configure do |c|
60
+ c.auth_type = :pam (Optional)
61
+ c.appliance_url = "https://your-appliance-url.com"
62
+ c.api_key = "YourRevBitsPamApiKey"
63
+ end
64
+ ```
65
+
66
+ > :warning: Beware of adding your credentials directly into code always use secrets or ENV to fetch them dynamically.
67
+
68
+ ### Example Usage
69
+
70
+ ```ruby
71
+ # Configuration
72
+ RevbitsPamCicd.configuration.auth_type = :pam
73
+ RevbitsPamCicd.configuration.appliance_url = "https://your-appliance-url.com"
74
+ RevbitsPamCicd.configuration.api_key = "YourRevbitsPamCicdApiKey"
75
+
76
+ # Fetching secrets form RevBits PAM
77
+ db_password = RevbitsPamCicd::API.fetch_secret('DB_PASSWORD')
78
+ ```
79
+
80
+ ## Contributing
81
+
82
+ Bug reports and pull requests are welcome on GitHub at https://github.com/RevBits/PAM-SDK/tree/main/revbits-secrets-ruby. 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/RevBits/PAM-SDK/tree/main/revbits-secrets-ruby/CODE_OF_CONDUCT.md).
83
+
84
+ ## License
85
+
86
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
87
+
88
+ ## Code of Conduct
89
+
90
+ Everyone interacting in the RevbitsPamCicd project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/RevBits/PAM-SDK/blob/main/revbits-secrets-ruby/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "revbits_pam_cicd"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'configuration'
4
+ require_relative 'secure'
5
+ require_relative 'http'
6
+ require_relative 'validators/configuration'
7
+ require_relative 'managers/auth_manager'
8
+ require_relative 'authenticators/pam'
9
+ require_relative 'authenticators/aws'
10
+
11
+ module RevbitsPamCicd
12
+ class API
13
+ class << self
14
+ def fetch_secret(variable_id)
15
+
16
+ secret_creators = {
17
+ prime: 23,
18
+ generated: 9,
19
+ }
20
+
21
+ private_key_a, private_key_b = Secure.private_keys
22
+
23
+ public_key_a, public_key_b = Secure.public_keys(private_key_a, private_key_b, secret_creators)
24
+
25
+ encrypted_values = Managers::AuthManager.fetch_secret(variable_id, public_key_a, public_key_b)
26
+
27
+ secret = Secure.secret(encrypted_values, private_key_a, private_key_b, secret_creators)
28
+
29
+ Secure.decrypt(secret, encrypted_values.dig('value'))
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RevbitsPamCicd
4
+ module Authenticators
5
+ class AWS < HTTP
6
+ class << self
7
+ # @param variable_id variable you want to fetch from RevBits PAM.
8
+ # @param public_key_a public key to encrypt data
9
+ # @param public_key_b public key to encrypt data
10
+ # @param options valid values are [:appliance_url, :api_key].
11
+ def get(variable_id, public_key_a, public_key_b, options = {})
12
+ # TODO: Need to implement when server is ready to handle AWS requests
13
+ raise 'TODO: AWS authenticator is not implemented yet.'
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RevbitsPamCicd
4
+ module Authenticators
5
+ class PAM < HTTP
6
+ class << self
7
+ # @param variable_id variable you want to fetch from RevBits PAM.
8
+ # @param public_key_a public key to encrypt data
9
+ # @param public_key_b public key to encrypt data
10
+ # @param options valid values are [:appliance_url, :api_key].
11
+ def get(variable_id, public_key_a, public_key_b, options = {})
12
+ uri = URI.parse("#{options[:appliance_url]&.chomp}/api/v1/secretman/GetSecretV2/#{variable_id}")
13
+ request = Net::HTTP::Get.new(uri)
14
+ request['Apikey'] = options[:api_key]
15
+ request['Publickeya'] = public_key_a.to_s
16
+ request['Publickeyb'] = public_key_b.to_s
17
+
18
+ req_options = {
19
+ use_ssl: uri.scheme == 'https',
20
+ }
21
+
22
+ super(uri, request, req_options)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,107 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RevbitsPamCicd
4
+ class << self
5
+ def with_configuration(config)
6
+ old_value = Thread.current[:revbits_configuration]
7
+ Thread.current[:revbits_configuration] = config
8
+ yield
9
+ ensure
10
+ Thread.current[:revbits_configuration] = old_value
11
+ end
12
+
13
+ def configuration
14
+ Thread.current[:revbits_configuration] || (@config ||= Configuration.new)
15
+ end
16
+
17
+ def configuration=(config)
18
+ @config = config
19
+ end
20
+
21
+ alias config configuration
22
+ alias config= configuration=
23
+
24
+ def configure
25
+ yield configuration
26
+ end
27
+ end
28
+
29
+ class Configuration
30
+ attr_reader :explicit
31
+ attr_reader :supplied
32
+ attr_reader :computed
33
+
34
+ def initialize(options = {})
35
+ @explicit = options.dup
36
+ @supplied = options.dup
37
+ @computed = Hash.new
38
+ end
39
+
40
+ class << self
41
+ def accepted_options
42
+ require 'set'
43
+ @options ||= Set.new
44
+ end
45
+
46
+ def add_option(name, options = {}, &def_proc)
47
+ accepted_options << name
48
+ allow_env = options[:env].nil? || options[:env]
49
+ env_var = options[:env] || "REVBITS_#{name.to_s.upcase}"
50
+ def_val = options[:default]
51
+ opt_name = name
52
+
53
+ def_proc ||= if def_val.respond_to?(:call)
54
+ def_val
55
+ elsif options[:required]
56
+ proc { raise "Missing required option #{opt_name}" }
57
+ else
58
+ proc { def_val }
59
+ end
60
+
61
+ convert = options[:convert] || ->(x) { x }
62
+ convert = convert.to_proc if convert.respond_to?(:to_proc)
63
+
64
+ define_method("#{name}=") do |value|
65
+ set name, value
66
+ end
67
+
68
+ define_method("#{name}_env_var") do
69
+ allow_env ? env_var : nil
70
+ end
71
+
72
+ define_method(name) do
73
+ value = computed[name]
74
+ return value unless value.nil?
75
+
76
+ if supplied.member?(name)
77
+ supplied[name]
78
+ elsif allow_env && ENV.member?(env_var)
79
+ instance_exec(ENV[env_var], &convert)
80
+ else
81
+ instance_eval(&def_proc)
82
+ end.tap do |value|
83
+ computed[name] = value
84
+ end
85
+ end
86
+
87
+ alias_method("#{name}?", name) if options[:boolean]
88
+ end
89
+ end
90
+
91
+ def clone(override_options = {})
92
+ self.class.new self.explicit.dup.merge(override_options)
93
+ end
94
+
95
+ def set(key, value)
96
+ if self.class.accepted_options.include?(key.to_sym)
97
+ explicit[key.to_sym] = value
98
+ supplied[key.to_sym] = value
99
+ computed.clear
100
+ end
101
+ end
102
+
103
+ add_option :appliance_url, required: true
104
+ add_option :api_key, required: true
105
+ add_option :auth_type, default: :pam
106
+ end
107
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/http'
4
+ require 'json'
5
+
6
+ # Root Module for Namespace management
7
+ module RevbitsPamCicd
8
+ # Module responsible for fetching data from 'PAM'.
9
+ class HTTP
10
+ class << self
11
+ def get(uri, request, req_options)
12
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
13
+ http.request(request)
14
+ end
15
+
16
+ unless response.code.match?(%r{^2})
17
+ raise Net::HTTPError.new("Server error: #{JSON.parse(response.body).dig('errorMessage')}", response)
18
+ end
19
+
20
+ JSON.parse(response.body)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RevbitsPamCicd
4
+ module Managers
5
+ module AuthManager
6
+ class << self
7
+ include Validators::Configuration
8
+
9
+ def fetch_secret(variable_id, public_key_a, public_key_b)
10
+ case RevbitsPamCicd.config.auth_type
11
+ when :pam
12
+ Authenticators::PAM.get(variable_id, public_key_a, public_key_b,
13
+ validated_options_for(:pam))
14
+ when :aws
15
+ Authenticators::AWS.get(variable_id, public_key_a, public_key_b,
16
+ validated_options_for(:aws))
17
+ else
18
+ raise "Invalid 'auth_type'"
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'aes-everywhere'
4
+
5
+ module RevbitsPamCicd
6
+ module Secure
7
+ class << self
8
+ # @return [Array] `private_keys`
9
+ def private_keys
10
+ # key_a, key_b
11
+ [rand(2..9), rand(2..9)]
12
+ end
13
+
14
+ # @return [Array] `public_keys`
15
+ def public_keys(private_key_a, private_key_b, secret_creators)
16
+ [public_key_a(private_key_a, secret_creators), public_key_b(private_key_b, secret_creators)]
17
+ end
18
+
19
+ # @return [Integer] `secret`
20
+ def secret(encrypted_values, private_key_a, private_key_b, secret_creators)
21
+ shared_key_a = shared_key_a(encrypted_values.dig('keyA'), private_key_a, secret_creators.dig(:prime))
22
+ shared_key_b = shared_key_b(encrypted_values.dig('keyB'), private_key_b, secret_creators.dig(:prime))
23
+
24
+ shared_key_a ** shared_key_b
25
+ end
26
+
27
+ # @return [String] decrypted value
28
+ def decrypt(secret, encrypted_value)
29
+ AES256.decrypt(encrypted_value.to_s, secret.to_s)
30
+ end
31
+
32
+ private
33
+
34
+ def shared_key_a(key_a, private_key_a, prime)
35
+ (key_a ** private_key_a) % prime
36
+ end
37
+
38
+ def shared_key_b(key_b, private_key_b, prime)
39
+ (key_b ** private_key_b) % prime
40
+ end
41
+
42
+ def public_key_a(public_key_a, secret_creators)
43
+ (secret_creators.dig(:generated) ** public_key_a) % secret_creators.dig(:prime)
44
+ end
45
+
46
+ def public_key_b(public_key_b, secret_creators)
47
+ (secret_creators.dig(:generated) ** public_key_b) % secret_creators.dig(:prime)
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RevbitsPamCicd
4
+ module Validators
5
+ module Configuration
6
+ def validated_options_for(type)
7
+ case type
8
+ when :pam
9
+ pam_validated_options
10
+ when :aws
11
+ # TODO: need to implement this part when server is ready to handle AWS request
12
+ {}
13
+ else
14
+ raise "Invalid 'auth_type' provided"
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def pam_validated_options
21
+ validate_appliance_url
22
+ validate_api_key
23
+
24
+ {
25
+ appliance_url: RevbitsPamCicd.config.appliance_url,
26
+ api_key: RevbitsPamCicd.config.api_key
27
+ }
28
+ end
29
+
30
+ def validate_appliance_url
31
+ if RevbitsPamCicd.config.appliance_url.nil? || RevbitsPamCicd.config.appliance_url.empty?
32
+ raise "No 'appliance_url' provided"
33
+ end
34
+ end
35
+
36
+ def validate_api_key
37
+ if RevbitsPamCicd.config.api_key.nil? || RevbitsPamCicd.config.api_key.empty?
38
+ raise "No 'api_key' provided"
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RevbitsPamCicd
4
+ VERSION = "0.1.2"
5
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "revbits_pam_cicd/version"
4
+ require_relative 'revbits_pam_cicd/configuration'
5
+ require_relative 'revbits_pam_cicd/api'
6
+
7
+ module RevbitsPamCicd
8
+ class Error < StandardError; end
9
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/revbits_pam_cicd/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "revbits_pam_cicd"
7
+ spec.version = RevbitsPamCicd::VERSION
8
+
9
+ spec.summary = "Programmatic access to securely fetch secrets form RevBits PAM."
10
+ spec.description = "This gem give you programmatic access to securely fetch secrets form RevBits PAM"
11
+ spec.homepage = "https://github.com/RevBits/PAM-SDK/tree/main/revbits-secrets-ruby"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = "https://github.com/RevBits/PAM-SDK/tree/main/revbits-secrets-ruby"
17
+ spec.metadata["changelog_uri"] = "https://github.com/RevBits/PAM-SDK/blob/main/revbits-secrets-ruby/CHANGELOG.md"
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+ spec.authors = ["RevBits"]
28
+ spec.email = ["info@revbits.com"]
29
+
30
+ # For more information and examples about making a new gem, checkout our
31
+ # guide at: https://bundler.io/guides/creating_gem.html
32
+
33
+ spec.add_dependency 'aes-everywhere', '~> 1.2', '>= 1.2.5'
34
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: revbits_pam_cicd
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - RevBits
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-01-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aes-everywhere
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.2'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.2.5
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.2'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.2.5
33
+ description: This gem give you programmatic access to securely fetch secrets form
34
+ RevBits PAM
35
+ email:
36
+ - info@revbits.com
37
+ executables: []
38
+ extensions: []
39
+ extra_rdoc_files: []
40
+ files:
41
+ - ".github/workflows/main.yml"
42
+ - ".gitignore"
43
+ - ".rspec"
44
+ - ".rubocop.yml"
45
+ - CHANGELOG.md
46
+ - CODE_OF_CONDUCT.md
47
+ - Gemfile
48
+ - Gemfile.lock
49
+ - LICENSE.txt
50
+ - README.md
51
+ - Rakefile
52
+ - bin/console
53
+ - bin/setup
54
+ - lib/revbits_pam_cicd.rb
55
+ - lib/revbits_pam_cicd/api.rb
56
+ - lib/revbits_pam_cicd/authenticators/aws.rb
57
+ - lib/revbits_pam_cicd/authenticators/pam.rb
58
+ - lib/revbits_pam_cicd/configuration.rb
59
+ - lib/revbits_pam_cicd/http.rb
60
+ - lib/revbits_pam_cicd/managers/auth_manager.rb
61
+ - lib/revbits_pam_cicd/secure.rb
62
+ - lib/revbits_pam_cicd/validators/configuration.rb
63
+ - lib/revbits_pam_cicd/version.rb
64
+ - revbits_pam_cicd.gemspec
65
+ homepage: https://github.com/RevBits/PAM-SDK/tree/main/revbits-secrets-ruby
66
+ licenses:
67
+ - MIT
68
+ metadata:
69
+ homepage_uri: https://github.com/RevBits/PAM-SDK/tree/main/revbits-secrets-ruby
70
+ source_code_uri: https://github.com/RevBits/PAM-SDK/tree/main/revbits-secrets-ruby
71
+ changelog_uri: https://github.com/RevBits/PAM-SDK/blob/main/revbits-secrets-ruby/CHANGELOG.md
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: 2.4.0
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubygems_version: 3.2.3
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: Programmatic access to securely fetch secrets form RevBits PAM.
91
+ test_files: []