puppet-sec-lint 0.1.1

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: eaf96b63a536fffdcad382d9cdd36aeb315217f9b3ddac70de1858bc898cd793
4
+ data.tar.gz: d4a15a04b437dd4e9eca7478a99094e5c3c3bf1ca59e082dbe05e1f037b910fe
5
+ SHA512:
6
+ metadata.gz: f598081277fc495c326dbc814483f39f5df0975a5e55055386664b5daa3dd97577a4701cb5bf40fb589b4bf0b22285b4226de83ae97f206c8372e014da4e6515
7
+ data.tar.gz: f02c510e8a2017bb28a73278676a043ae2b094837288711e5e54d2a4f29bdc34ec5b47cebd0b0a2f28d3df79818fe88b04b0c3b219e132b99d7bee6d7d39513d
@@ -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.0
14
+ - name: Run the default task
15
+ run: |
16
+ gem install bundler -v 2.2.3
17
+ bundle install
18
+ bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.idea/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ # Default ignored files
2
+ /shelf/
3
+ /workspace.xml
4
+ # Datasource local storage ignored files
5
+ /dataSources/
6
+ /dataSources.local.xml
7
+ # Editor-based HTTP Client requests
8
+ /httpRequests/
data/.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/puppet-sec-lint.iml" filepath="$PROJECT_DIR$/.idea/puppet-sec-lint.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
@@ -0,0 +1,52 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="ModuleRunConfigurationManager">
4
+ <shared />
5
+ </component>
6
+ <component name="NewModuleRootManager">
7
+ <content url="file://$MODULE_DIR$">
8
+ <sourceFolder url="file://$MODULE_DIR$/features" isTestSource="true" />
9
+ <sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
10
+ <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
11
+ </content>
12
+ <orderEntry type="inheritedJdk" />
13
+ <orderEntry type="sourceFolder" forTests="false" />
14
+ <orderEntry type="library" scope="PROVIDED" name="bundler (v2.2.3, RVM: ruby-3.0.0 [global]) [gem]" level="application" />
15
+ <orderEntry type="library" scope="PROVIDED" name="daemons (v1.3.1, RVM: ruby-3.0.0 [global]) [gem]" level="application" />
16
+ <orderEntry type="library" scope="PROVIDED" name="eventmachine (v1.2.7, RVM: ruby-3.0.0 [global]) [gem]" level="application" />
17
+ <orderEntry type="library" scope="PROVIDED" name="inifile (v3.0.0, RVM: ruby-3.0.0 [global]) [gem]" level="application" />
18
+ <orderEntry type="library" scope="PROVIDED" name="minitest (v5.14.4, RVM: ruby-3.0.0 [global]) [gem]" level="application" />
19
+ <orderEntry type="library" scope="PROVIDED" name="puppet-lint (v2.4.2, RVM: ruby-3.0.0 [global]) [gem]" level="application" />
20
+ <orderEntry type="library" scope="PROVIDED" name="rack (v2.2.3, RVM: ruby-3.0.0 [global]) [gem]" level="application" />
21
+ <orderEntry type="library" scope="PROVIDED" name="rake (v13.0.3, RVM: ruby-3.0.0 [global]) [gem]" level="application" />
22
+ <orderEntry type="library" scope="PROVIDED" name="thin (v1.8.0, RVM: ruby-3.0.0 [global]) [gem]" level="application" />
23
+ </component>
24
+ <component name="RakeTasksCache">
25
+ <option name="myRootTask">
26
+ <RakeTaskImpl id="rake">
27
+ <subtasks>
28
+ <RakeTaskImpl description="Build puppet-sec-lint-0.1.0.gem into the pkg directory" fullCommand="build" id="build" />
29
+ <RakeTaskImpl description="Remove any temporary products" fullCommand="clean" id="clean" />
30
+ <RakeTaskImpl description="Remove any generated files" fullCommand="clobber" id="clobber" />
31
+ <RakeTaskImpl description="Build and install puppet-sec-lint-0.1.0.gem into system gems" fullCommand="install" id="install" />
32
+ <RakeTaskImpl id="install">
33
+ <subtasks>
34
+ <RakeTaskImpl description="Build and install puppet-sec-lint-0.1.0.gem into system gems without network access" fullCommand="install:local" id="local" />
35
+ </subtasks>
36
+ </RakeTaskImpl>
37
+ <RakeTaskImpl description="Create tag v0.1.0 and build and push puppet-sec-lint-0.1.0.gem to TODO: Set to 'http://mygemserver.com'" fullCommand="release[remote]" id="release[remote]" />
38
+ <RakeTaskImpl description="Run tests" fullCommand="test" id="test" />
39
+ <RakeTaskImpl description="" fullCommand="default" id="default" />
40
+ <RakeTaskImpl description="" fullCommand="release" id="release" />
41
+ <RakeTaskImpl id="release">
42
+ <subtasks>
43
+ <RakeTaskImpl description="" fullCommand="release:guard_clean" id="guard_clean" />
44
+ <RakeTaskImpl description="" fullCommand="release:rubygem_push" id="rubygem_push" />
45
+ <RakeTaskImpl description="" fullCommand="release:source_control_push" id="source_control_push" />
46
+ </subtasks>
47
+ </RakeTaskImpl>
48
+ </subtasks>
49
+ </RakeTaskImpl>
50
+ </option>
51
+ </component>
52
+ </module>
data/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
+ </component>
6
+ </project>
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -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 TiagoJose.Ribeiro@ctw.bmwgroup.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,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in puppet-sec-lint.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
11
+
12
+ gem "puppet-lint"
13
+
14
+ gem "rack"
15
+
16
+ gem 'thin'
17
+
18
+ gem 'inifile'
data/Gemfile.lock ADDED
@@ -0,0 +1,34 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ puppet-sec-lint (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ daemons (1.3.1)
10
+ eventmachine (1.2.7)
11
+ inifile (3.0.0)
12
+ minitest (5.14.4)
13
+ puppet-lint (2.4.2)
14
+ rack (2.2.3)
15
+ rake (13.0.3)
16
+ thin (1.8.0)
17
+ daemons (~> 1.0, >= 1.0.9)
18
+ eventmachine (~> 1.0, >= 1.0.4)
19
+ rack (>= 1, < 3)
20
+
21
+ PLATFORMS
22
+ x86_64-linux
23
+
24
+ DEPENDENCIES
25
+ inifile
26
+ minitest (~> 5.0)
27
+ puppet-lint
28
+ puppet-sec-lint!
29
+ rack
30
+ rake (~> 13.0)
31
+ thin
32
+
33
+ BUNDLED WITH
34
+ 2.2.3
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Tiago Ribeiro
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,43 @@
1
+ # Puppet::Sec::Lint
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/puppet/sec/lint`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'puppet-sec-lint'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install puppet-sec-lint
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/puppet-sec-lint. 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/[USERNAME]/puppet-sec-lint/blob/master/CODE_OF_CONDUCT.md).
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Puppet::Sec::Lint project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/puppet-sec-lint/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ task default: :test
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 "puppet-sec-lint"
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,35 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/rule_engine'
4
+ require 'json'
5
+ require 'optparse'
6
+ require 'optparse/uri'
7
+ require_relative '../lib/visitors/configuration_visitor'
8
+ require_relative '../lib/facades/configuration_file_facade'
9
+ require_relative '../lib/language_server'
10
+
11
+ options = {}
12
+ OptionParser.new do |opts|
13
+ opts.banner = "Usage: puppet-sec-lint [options]"
14
+
15
+ opts.on("-f", "--file FILE",URI, "Path of puppet file to be analyzed") do |file|
16
+ options[:file] = file
17
+ end
18
+ end.parse!
19
+
20
+ if options[:file].nil?
21
+ LanguageServer
22
+ end
23
+
24
+ ConfigurationVisitor.GenerateIDs
25
+ ConfigurationFileFacade.LoadConfigurations
26
+
27
+ File.open(options[:file].to_s, 'rb:UTF-8') do |f|
28
+ code = f.read
29
+
30
+ result = RuleEngine.analyzeDocument(code)
31
+
32
+ result.each do |sin|
33
+ puts sin.ToString
34
+ end
35
+ end
@@ -0,0 +1,10 @@
1
+ require_relative 'configuration'
2
+
3
+ class BooleanConfiguration < Configuration
4
+
5
+ def initialize(name, value, description)
6
+ super
7
+ @displayfield=DisplayField[:CheckBox]
8
+ end
9
+
10
+ end
@@ -0,0 +1,19 @@
1
+ require 'securerandom'
2
+
3
+ class Configuration
4
+ attr_accessor :name,:value,:description,:id,:displayfield
5
+
6
+ def initialize(name, value, description)
7
+ @name = name
8
+ @value = value
9
+ @description = description
10
+ end
11
+
12
+ end
13
+
14
+ DisplayField = {
15
+ TextBox: "textbox",
16
+ CheckBox: "checkbox",
17
+ NumericBox: "numericbox",
18
+ SelectBox: "selectbox"
19
+ }
@@ -0,0 +1,9 @@
1
+ require_relative 'configuration'
2
+
3
+ class ListConfiguration < Configuration
4
+
5
+ def initialize(name, value, description)
6
+ super
7
+ @displayfield=DisplayField[:SelectBox]
8
+ end
9
+ end
@@ -0,0 +1,43 @@
1
+ require 'inifile'
2
+
3
+ class ConfigurationFileFacade
4
+
5
+ def self.SaveConfigurations
6
+ @configurations_hash = ConfigurationVisitor.Visit
7
+
8
+ ini = IniFile.new( :filename => 'settings.ini', :encoding => 'UTF-8' )
9
+
10
+ @configurations_hash.each do |rule, configurations|
11
+ configurations.each do |configuration|
12
+ case configuration.displayfield
13
+ when DisplayField[:SelectBox]
14
+ ini[rule][configuration.id] = configuration.value.join(',')
15
+ else
16
+ ini[rule][configuration.id] = configuration.value
17
+ end
18
+ end
19
+ end
20
+
21
+ ini.save
22
+ end
23
+
24
+ def self.LoadConfigurations
25
+ @configurations_hash = ConfigurationVisitor.Visit
26
+
27
+ ini = IniFile.new( :filename => 'settings.ini')
28
+
29
+ @configurations_hash.each do |rule, configurations|
30
+ configurations.each do |configuration|
31
+ if(not ini[rule][configuration.id].nil?)
32
+ case configuration.displayfield
33
+ when DisplayField[:SelectBox]
34
+ configuration.value = ini[rule][configuration.id].split(',')
35
+ else
36
+ configuration.value = ini[rule][configuration.id]
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ end
@@ -0,0 +1,83 @@
1
+ require_relative '../visitors/configuration_visitor'
2
+
3
+ class ConfigurationPageFacade
4
+
5
+ @configurations_hash=""
6
+
7
+ def self.AssemblePage
8
+ @configurations_hash = ConfigurationVisitor.Visit
9
+
10
+ final_html = self.Title
11
+ final_html += self.ConfigurationsForm
12
+ return final_html
13
+ end
14
+
15
+ def self.Title
16
+ return "<h1>Configurations Page</h1>\n"
17
+ end
18
+
19
+ def self.ConfigurationsForm
20
+ final_html = "<form action=\"/configuration\" method=\"post\">\n"
21
+ @configurations_hash.each do |rule, configurations|
22
+ final_html += self.RuleConfigurations(rule,configurations)
23
+ end
24
+ final_html += "<input type=\"submit\" value=\"Submit\">\n"
25
+ final_html += "</form>\n"
26
+
27
+ return final_html
28
+ end
29
+
30
+ def self.RuleConfigurations(rule,configurations)
31
+ final_html = "<h2>#{rule.name}</h2>\n"
32
+
33
+ configurations.each do |configuration|
34
+ final_html += self.Input(configuration)
35
+ end
36
+
37
+ return final_html
38
+ end
39
+
40
+ def self.Input(configuration)
41
+ return_value = "<label for=\"#{configuration.class.name}\">#{configuration.name}:</label>\n"
42
+
43
+ case configuration.displayfield
44
+ when DisplayField[:CheckBox]
45
+ return_value += "<input type=\"checkbox\" id=\"#{configuration.id}\" name=\"#{configuration.id}\""+if configuration.value then "checked" else "" end+"><br>\n"
46
+
47
+ when DisplayField[:SelectBox]
48
+ return_value += "<br><textarea id=\"#{configuration.id}\" name=\"#{configuration.id}\" rows=\"#{configuration.value.length()+2}\">\n"
49
+ configuration.value.each do |option|
50
+ return_value+="#{option}\n"
51
+ end
52
+ return_value += "</textarea>"
53
+ end
54
+
55
+ return_value += "<p style=\"color:gray\">#{configuration.description}</p>\n<br>\n"
56
+
57
+ return return_value
58
+ end
59
+
60
+ def self.ApplyConfigurations(new_conf)
61
+ @configurations_hash.each do |rule, configurations|
62
+ configurations.each do |configuration|
63
+
64
+ case configuration.displayfield
65
+ when DisplayField[:CheckBox]
66
+ if new_conf.has_key?(configuration.id)
67
+ configuration.value = true
68
+ else
69
+ configuration.value = false
70
+ end
71
+
72
+ when DisplayField[:SelectBox]
73
+ configuration.value = new_conf[configuration.id].split(/\r?\n/).delete_if(&:empty?)
74
+ else
75
+ configuration.value = new_conf[configuration.id]
76
+ end
77
+
78
+ end
79
+ end
80
+ end
81
+
82
+ private_class_method :Title,:ConfigurationsForm, :RuleConfigurations, :Input
83
+ end
@@ -0,0 +1,78 @@
1
+ require "rack"
2
+ require "thin"
3
+ require 'json'
4
+ require 'uri'
5
+ require_relative 'rule_engine'
6
+ require_relative 'visitors/configuration_visitor'
7
+ require_relative 'facades/configuration_page_facade'
8
+ require_relative 'facades/configuration_file_facade'
9
+
10
+ class LanguageServer
11
+ ConfigurationVisitor.GenerateIDs
12
+ ConfigurationFileFacade.LoadConfigurations
13
+
14
+ def call(env)
15
+ req = Rack::Request.new(env)
16
+
17
+ case req.path
18
+ when "/"
19
+ if req.post?
20
+ process_analysis(req)
21
+ end
22
+ when "/configuration"
23
+ if req.post?
24
+ process_form(req)
25
+ elsif req.get?
26
+ configurations_page
27
+ end
28
+ end
29
+
30
+ end
31
+
32
+ def process_form(req)
33
+ new_conf = URI.decode_www_form(req.body.read)
34
+ new_conf_hash = Hash[new_conf.map {|key, value| [key, value]}]
35
+
36
+ ConfigurationPageFacade.ApplyConfigurations(new_conf_hash)
37
+ ConfigurationFileFacade.SaveConfigurations
38
+
39
+ return [200, { 'Content-Type' => 'text/plain' }, ["Changes saved successfully"]]
40
+ end
41
+
42
+ def process_analysis(req)
43
+ body = JSON.parse(req.body.read)
44
+
45
+ if body['documentContent']
46
+ code = body['documentContent']
47
+
48
+ result_json = []
49
+
50
+ result = RuleEngine.analyzeDocument(code) #convert to json
51
+
52
+ result.each do |sin|
53
+ result_json.append(JSON.generate({
54
+ 'name' => sin.type[:name],
55
+ 'message' => sin.type[:message],
56
+ 'recommendation' => sin.type[:recommendation],
57
+ 'begin_line' => sin.begin_line,
58
+ 'begin_char' => sin.begin_char,
59
+ 'end_line' => sin.end_line,
60
+ 'end_char' => sin.end_char
61
+ }))
62
+ end
63
+
64
+ return [200, { 'Content-Type' => 'application/json' }, [result_json.to_json]]
65
+ end
66
+
67
+ [401, { 'Content-Type' => 'text/html' }, ['Invalid Request']]
68
+ end
69
+
70
+ def configurations_page
71
+ configuration_page = ConfigurationPageFacade.AssemblePage
72
+
73
+ return [200, { 'Content-Type' => 'text/html' }, [configuration_page]]
74
+ end
75
+
76
+ end
77
+
78
+ Rack::Handler::Thin.run(LanguageServer.new, :Port => 9292)
data/lib/lol.pp ADDED
@@ -0,0 +1,83 @@
1
+ #class path_attribute {
2
+ # file { 'ssh_config_file':
3
+ # path => '/etc/ssh/sshd_config',
4
+ # content => 'Bad path attribute, bad.',
5
+ # }
6
+ #}
7
+
8
+ # the following code addresses the bug: https://bugs.launchpad.net/keystone/+bug/1472285 .
9
+
10
+ class consul_template::service (
11
+ $rpc_password = '{6ad470ec62b0511b63340dca2950d750181598efnHKvN1ge',
12
+ $admin_username = 'admin',
13
+ $password = 'ceilometer',
14
+ $admin_password = 'admin',
15
+ ) {
16
+ exec { 'network-restart':
17
+ command => 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDM release-runner key',
18
+ path => '/usr/bin:/usr/sbin:/bin:/sbin',
19
+ refreshonly => true,
20
+ vmware_md5 => 'LOL',
21
+ autho => 'MD5',
22
+ cmd => 'virsh secret-define --file ${secret_xml} && virsh secret-set-value --secret ${rbd_secret_uuid} --base64 $(ceph auth get-key client.${user})',
23
+ $auth_uri => 'http://127.0.0.1:5000',
24
+ 'bind_address' => '0.0.0.0',
25
+ password => '',
26
+ }
27
+ case $::osfamily {
28
+ 'RedHat': {
29
+ exec { 'upload-img':
30
+ command => "/usr/bin/glance -N ${os_auth_url} -T ${os_tenant_name} -I ${os_username} -K ${os_password} add name=${img_name} is_public=${public} container_format=${container_format} disk_format=${disk_format} distro=${os_name} < /opt/vm/cirros-x86_64-disk.img",
31
+ unless => "/usr/bin/glance -N ${os_auth_url} -T ${os_tenant_name} -I ${os_username} -K ${os_password} index && (/usr/bin/glance -N ${os_auth_url} -T ${os_tenant_name} -I ${os_username} -K ${os_password} index | grep ${img_name})",
32
+
33
+ }
34
+ }
35
+ 'Debian': {
36
+ exec { 'upload-img':
37
+ command => "/usr/bin/glance -N ${os_auth_url} -T ${os_tenant_name} -I ${os_username} -K ${os_password} add name=${img_name} is_public=${public} container_format=${container_format} disk_format=${disk_format} distro=${os_name} < /usr/share/cirros-testvm/cirros-x86_64-disk.img",
38
+ unless => "/usr/bin/glance -N ${os_auth_url} -T ${os_tenant_name} -I ${os_username} -K ${os_password} index && (/usr/bin/glance -N ${os_auth_url} -T ${os_tenant_name} -I ${os_username} -K ${os_password} index | grep ${img_name})",
39
+ key => "E8CC67053ED3B199",
40
+ key_content => '-----BEGIN PGP PUBLIC KEY BLOCK-----
41
+ Version: GnuPG v1.4.11 (GNU/Linux)
42
+
43
+ mQENBE/oXVkBCACcjAcV7lRGskECEHovgZ6a2robpBroQBW+tJds7B+qn/DslOAN
44
+ 1hm0UuGQsi8pNzHDE29FMO3yOhmkenDd1V/T6tHNXqhHvf55nL6anlzwMmq3syIS
45
+ uqVjeMMXbZ4d+Rh0K/rI4TyRbUiI2DDLP+6wYeh1pTPwrleHm5FXBMDbU/OZ5vKZ
46
+ 67j99GaARYxHp8W/be8KRSoV9wU1WXr4+GA6K7ENe2A8PT+jH79Sr4kF4uKC3VxD
47
+ BF5Z0yaLqr+1V2pHU3AfmybOCmoPYviOqpwj3FQ2PhtObLs+hq7zCviDTX2IxHBb
48
+ Q3mGsD8wS9uyZcHN77maAzZlL5G794DEr1NLABEBAAG0NU9wZW5TdGFja0BDaXNj
49
+ byBBUFQgcmVwbyA8b3BlbnN0YWNrLWJ1aWxkZEBjaXNjby5jb20+iQE4BBMBAgAi
50
+ BQJP6F1ZAhsDBgsJCAcDAgYVCAIJCgsEFgIDAQIeAQIXgAAKCRDozGcFPtOxmXcK
51
+ B/9WvQrBwxmIMV2M+VMBhQqtipvJeDX2Uv34Ytpsg2jldl0TS8XheGlUNZ5djxDy
52
+ u3X0hKwRLeOppV09GVO3wGizNCV1EJjqQbCMkq6VSJjD1B/6Tg+3M/XmNaKHK3Op
53
+ zSi+35OQ6xXc38DUOrigaCZUU40nGQeYUMRYzI+d3pPlNd0+nLndrE4rNNFB91dM
54
+ BTeoyQMWd6tpTwz5MAi+I11tCIQAPCSG1qR52R3bog/0PlJzilxjkdShl1Cj0RmX
55
+ 7bHIMD66uC1FKCpbRaiPR8XmTPLv29ZTk1ABBzoynZyFDfliRwQi6TS20TuEj+ZH
56
+ xq/T6MM6+rpdBVz62ek6/KBcuQENBE/oXVkBCACgzyyGvvHLx7g/Rpys1WdevYMH
57
+ THBS24RMaDHqg7H7xe0fFzmiblWjV8V4Yy+heLLV5nTYBQLS43MFvFbnFvB3ygDI
58
+ IdVjLVDXcPfcp+Np2PE8cJuDEE4seGU26UoJ2pPK/IHbnmGWYwXJBbik9YepD61c
59
+ NJ5XMzMYI5z9/YNupeJoy8/8uxdxI/B66PL9QN8wKBk5js2OX8TtEjmEZSrZrIuM
60
+ rVVXRU/1m732lhIyVVws4StRkpG+D15Dp98yDGjbCRREzZPeKHpvO/Uhn23hVyHe
61
+ PIc+bu1mXMQ+N/3UjXtfUg27hmmgBDAjxUeSb1moFpeqLys2AAY+yXiHDv57ABEB
62
+ AAGJAR8EGAECAAkFAk/oXVkCGwwACgkQ6MxnBT7TsZng+AgAnFogD90f3ByTVlNp
63
+ Sb+HHd/cPqZ83RB9XUxRRnkIQmOozUjw8nq8I8eTT4t0Sa8G9q1fl14tXIJ9szzz
64
+ BUIYyda/RYZszL9rHhucSfFIkpnp7ddfE9NDlnZUvavnnyRsWpIZa6hJq8hQEp92
65
+ IQBF6R7wOws0A0oUmME25Rzam9qVbywOh9ZQvzYPpFaEmmjpCRDxJLB1DYu8lnC4
66
+ h1jP1GXFUIQDbcznrR2MQDy5fNt678HcIqMwVp2CJz/2jrZlbSKfMckdpbiWNns/
67
+ xKyLYs5m34d4a0it6wsMem3YCefSYBjyLGSd/kCI/CgOdGN1ZY1HSdLmmjiDkQPQ
68
+ UcXHbA==
69
+ =v6jg
70
+ -----END PGP PUBLIC KEY BLOCK-----',
71
+
72
+ }
73
+ }
74
+ }
75
+ file { '/var/lib/gerrit/.ssh/id_rsa' :
76
+ owner => 'gerrit',
77
+ group => 'gerrit',
78
+ mode => '0600',
79
+ content => $ssh_replication_rsa_key_contents,
80
+ replace => true,
81
+ require => File['/var/lib/gerrit/.ssh']
82
+ }
83
+ }
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PuppetSecLint
4
+ VERSION = "0.1.1"
5
+ end
@@ -0,0 +1,33 @@
1
+ require 'puppet-lint'
2
+ require_relative 'rules/rule'
3
+ require_relative 'rules/hard_coded_credentials_rule'
4
+ require_relative 'rules/no_http_rule'
5
+
6
+
7
+ class RuleEngine
8
+ @rules=[HardCodedCredentialsRule,NoHTTPRule]
9
+
10
+ class << self
11
+ attr_accessor :rules
12
+ end
13
+
14
+ def self.getTokens(code)
15
+ lexer = PuppetLint::Lexer.new
16
+ tokens = lexer.tokenise(code)
17
+ return tokens
18
+ end
19
+
20
+ def self.analyzeDocument(code)
21
+ result=[]
22
+ tokens = self.getTokens(code)
23
+
24
+ @rules.each do |rule|
25
+ if rule.configurations[0].value
26
+ (result << rule.AnalyzeTokens(tokens)).flatten!
27
+ end
28
+ end
29
+
30
+ return result
31
+ end
32
+
33
+ end
@@ -0,0 +1,48 @@
1
+ require_relative '../configurations/list_configuration'
2
+
3
+ class HardCodedCredentialsRule < Rule
4
+ @default_trigger_words = %w[pwd password pass uuid key crypt secret certificate id cert token ssh_key md5 rsa ssl]
5
+ @trigger_words_conf = ListConfiguration.new("List of trigger words", @default_trigger_words, "List of words that identify a variable with credentials")
6
+ @test_conf = BooleanConfiguration.new("Test configuration", true, "This is just a test configuration")
7
+
8
+ @name = "Hard Coded Credentials"
9
+ @configurations+=[@trigger_words_conf,@test_conf]
10
+
11
+ def self.AnalyzeTokens(tokens)
12
+ result = []
13
+
14
+ tokens.each do |indi_token|
15
+ nxt_token = indi_token.next_code_token # next token which is not a white space
16
+ if (!nxt_token.nil?) && (!indi_token.nil?)
17
+ token_type = indi_token.type.to_s ### this gives type for current token
18
+
19
+ token_line = indi_token.line ### this gives type for current token
20
+ nxt_tok_line = nxt_token.line
21
+
22
+ nxt_nxt_token = nxt_token.next_code_token # get the next next token to get key value pair
23
+
24
+ if (!nxt_nxt_token.nil?)
25
+ nxt_nxt_line = nxt_nxt_token.line
26
+ if (token_type.eql? 'NAME') || (token_type.eql? 'VARIABLE')
27
+ # puts "Token type: #{token_type}"
28
+ if (token_line==nxt_nxt_line)
29
+ token_valu = indi_token.value.downcase
30
+ nxt_nxt_val = nxt_nxt_token.value.downcase
31
+ nxt_nxt_type = nxt_nxt_token.type.to_s ## to handle false positives,
32
+
33
+ if (self.TriggerWordInString(token_valu)) && ((nxt_nxt_val.length > 0)) && ((!nxt_nxt_type.eql? 'VARIABLE') && (!token_valu.include? "("))
34
+ result.append(Sin.new(SinType::HardCodedCred, indi_token.line, indi_token.column, nxt_nxt_token.line, nxt_nxt_token.column+nxt_nxt_token.value.length))
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ return result
43
+ end
44
+
45
+ def self.TriggerWordInString(string)
46
+ return @trigger_words_conf.value.any? { |word| string.include?(word) }
47
+ end
48
+ end
@@ -0,0 +1,23 @@
1
+ require_relative '../configurations/list_configuration'
2
+ require_relative '../sin'
3
+ require_relative '../sin_type'
4
+
5
+ class NoHTTPRule < Rule
6
+ @name="No HTTP Connections"
7
+
8
+ def self.AnalyzeTokens(tokens)
9
+ result = []
10
+
11
+ tokens.each do |indi_token|
12
+ token_valu = indi_token.value ### this gives each token
13
+ token_valu = token_valu.downcase
14
+ token_type = indi_token.type.to_s
15
+ if (token_valu.include? "http://" ) && (!token_type.eql? "COMMENT")
16
+ result.append(Sin.new(SinType::HttpWithoutTLS, indi_token.line, indi_token.column, indi_token.line, indi_token.column+indi_token.value.length))
17
+ end
18
+ end
19
+
20
+ return result
21
+ end
22
+
23
+ end
data/lib/rules/rule.rb ADDED
@@ -0,0 +1,17 @@
1
+ require_relative '../configurations/boolean_configuration'
2
+
3
+ class Rule
4
+
5
+ def self.inherited(subclass)
6
+ subclass.configurations = [BooleanConfiguration.new("Enable Configuration", true, "Enable or disable the evaluation of the rules")]
7
+ end
8
+
9
+ class << self
10
+ attr_accessor :name, :configurations
11
+ end
12
+
13
+ def self.AnalyzeTokens(tokens)
14
+ puts "Implement this"
15
+ return
16
+ end
17
+ end
data/lib/sin.rb ADDED
@@ -0,0 +1,15 @@
1
+ class Sin
2
+ attr_accessor :type,:begin_line,:begin_char,:end_line,:end_char
3
+
4
+ def initialize(type, begin_line, begin_char, end_line, end_char)
5
+ @type = type
6
+ @begin_line = begin_line
7
+ @begin_char = begin_char
8
+ @end_line = end_line
9
+ @end_char = end_char
10
+ end
11
+
12
+ def ToString
13
+ return "<Sin:#{@type[:name]}, Line:#{@begin_line}, Char:#{@begin_char}, Message:#{@type[:message]}, Recommendation:#{@type[:recommendation]}>"
14
+ end
15
+ end
data/lib/sin_type.rb ADDED
@@ -0,0 +1,12 @@
1
+ module SinType
2
+ HardCodedCred = {
3
+ name: "Hard Coded Credentials",
4
+ message: "Do not hard code secrets. This may help an attacker to attack the system.",
5
+ recommendation: "You can use hiera to avoid this issue."
6
+ }
7
+ HttpWithoutTLS = {
8
+ name: "HTTP without TLS",
9
+ message: "Do not use HTTP without TLS. This may cause a man in the middle attack.",
10
+ recommendation: "Use TLS with HTTP"
11
+ }
12
+ end
@@ -0,0 +1,27 @@
1
+ require_relative '../rule_engine'
2
+
3
+ class ConfigurationVisitor
4
+ def self.Visit
5
+ configurationsHash = {}
6
+
7
+ rules = RuleEngine.rules
8
+ rules.each do |rule|
9
+ configurationsHash[rule] = []
10
+ rule.configurations.each do |configuration|
11
+ configurationsHash[rule].append(configuration)
12
+ end
13
+ end
14
+
15
+ return configurationsHash
16
+ end
17
+
18
+ def self.GenerateIDs
19
+ configurationsHash = self.Visit
20
+
21
+ configurationsHash.each do |rule,configurations|
22
+ configurations.each do |configuration|
23
+ configuration.id = "#{rule}-#{configuration.name.downcase.gsub! ' ', '_'}"
24
+ end
25
+ end
26
+ end
27
+ end
Binary file
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/puppet-sec-lint/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "puppet-sec-lint"
7
+ spec.version = PuppetSecLint::VERSION
8
+ spec.authors = ["Tiago Ribeiro"]
9
+ spec.email = ["tiago7b27@gmail.com"]
10
+
11
+ spec.summary = "This is a security linter for the puppet language"
12
+ spec.description = "This is a more complete security linter for the puppet language"
13
+ spec.homepage = "https://github.com/TiagoR98/puppet-sec-lint"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
16
+
17
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/TiagoR98/puppet-sec-lint"
21
+ spec.metadata["changelog_uri"] = "https://github.com/TiagoR98/puppet-sec-lint"
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ # Uncomment to register a new dependency of your gem
33
+ # spec.add_dependency "example-gem", "~> 1.0"
34
+
35
+ # For more information and examples about making a new gem, checkout our
36
+ # guide at: https://bundler.io/guides/creating_gem.html
37
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: puppet-sec-lint
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Tiago Ribeiro
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-04-11 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: This is a more complete security linter for the puppet language
14
+ email:
15
+ - tiago7b27@gmail.com
16
+ executables:
17
+ - puppet-sec-lint
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".github/workflows/main.yml"
22
+ - ".gitignore"
23
+ - ".idea/.gitignore"
24
+ - ".idea/modules.xml"
25
+ - ".idea/puppet-sec-lint.iml"
26
+ - ".idea/vcs.xml"
27
+ - Architecture/Architecture.eap
28
+ - Architecture/Class Model.png
29
+ - Architecture/Component Model.png
30
+ - Architecture/See settings.png
31
+ - Architecture/VSCode Analyze.png
32
+ - CODE_OF_CONDUCT.md
33
+ - Gemfile
34
+ - Gemfile.lock
35
+ - LICENSE.txt
36
+ - README.md
37
+ - Rakefile
38
+ - bin/console
39
+ - bin/setup
40
+ - exe/puppet-sec-lint
41
+ - lib/configurations/boolean_configuration.rb
42
+ - lib/configurations/configuration.rb
43
+ - lib/configurations/list_configuration.rb
44
+ - lib/facades/configuration_file_facade.rb
45
+ - lib/facades/configuration_page_facade.rb
46
+ - lib/language_server.rb
47
+ - lib/lol.pp
48
+ - lib/puppet-sec-lint/version.rb
49
+ - lib/rule_engine.rb
50
+ - lib/rules/hard_coded_credentials_rule.rb
51
+ - lib/rules/no_http_rule.rb
52
+ - lib/rules/rule.rb
53
+ - lib/sin.rb
54
+ - lib/sin_type.rb
55
+ - lib/visitors/configuration_visitor.rb
56
+ - puppet-sec-lint-0.1.0.gem
57
+ - puppet-sec-lint.gemspec
58
+ homepage: https://github.com/TiagoR98/puppet-sec-lint
59
+ licenses:
60
+ - MIT
61
+ metadata:
62
+ allowed_push_host: https://rubygems.org
63
+ homepage_uri: https://github.com/TiagoR98/puppet-sec-lint
64
+ source_code_uri: https://github.com/TiagoR98/puppet-sec-lint
65
+ changelog_uri: https://github.com/TiagoR98/puppet-sec-lint
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 2.3.0
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubygems_version: 3.2.3
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: This is a security linter for the puppet language
85
+ test_files: []