train-k8s-container-mitre 2.0.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.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/.expeditor/buildkite/coverage.sh +46 -0
  3. data/.expeditor/buildkite/run_linux_tests.sh +16 -0
  4. data/.expeditor/config.yml +61 -0
  5. data/.expeditor/coverage.pipeline.yml +19 -0
  6. data/.expeditor/update_version.sh +12 -0
  7. data/.expeditor/verify.pipeline.yml +44 -0
  8. data/.rspec +4 -0
  9. data/.rubocop.yml +57 -0
  10. data/CHANGELOG.md +158 -0
  11. data/CODE_OF_CONDUCT.md +13 -0
  12. data/CONTRIBUTING.md +161 -0
  13. data/DEVELOPMENT.md +315 -0
  14. data/Gemfile +23 -0
  15. data/LICENSE.md +9 -0
  16. data/NOTICE.md +9 -0
  17. data/README.md +237 -0
  18. data/Rakefile +37 -0
  19. data/SECURITY.md +100 -0
  20. data/VERSION +1 -0
  21. data/cliff.toml +80 -0
  22. data/docs/README.md +1 -0
  23. data/lib/train-k8s-container/ansi_sanitizer.rb +31 -0
  24. data/lib/train-k8s-container/connection.rb +102 -0
  25. data/lib/train-k8s-container/errors.rb +22 -0
  26. data/lib/train-k8s-container/kubectl_command_builder.rb +87 -0
  27. data/lib/train-k8s-container/kubectl_exec_client.rb +176 -0
  28. data/lib/train-k8s-container/kubernetes_name_validator.rb +44 -0
  29. data/lib/train-k8s-container/platform.rb +93 -0
  30. data/lib/train-k8s-container/pty_session.rb +156 -0
  31. data/lib/train-k8s-container/result_processor.rb +94 -0
  32. data/lib/train-k8s-container/retry_handler.rb +35 -0
  33. data/lib/train-k8s-container/session_manager.rb +95 -0
  34. data/lib/train-k8s-container/shell_detector.rb +198 -0
  35. data/lib/train-k8s-container/transport.rb +30 -0
  36. data/lib/train-k8s-container/version.rb +7 -0
  37. data/lib/train-k8s-container.rb +12 -0
  38. data/sonar-project.properties +17 -0
  39. data/train-k8s-container.gemspec +49 -0
  40. metadata +107 -0
data/DEVELOPMENT.md ADDED
@@ -0,0 +1,315 @@
1
+ # Development Guide
2
+
3
+ This guide covers local development and testing for train-k8s-container.
4
+
5
+ ## Prerequisites
6
+
7
+ - Ruby 3.1+ (3.3 recommended)
8
+ - Bundler
9
+ - Docker (for integration testing)
10
+ - [kind](https://kind.sigs.k8s.io/) (Kubernetes IN Docker)
11
+ - kubectl
12
+
13
+ ## Quick Start
14
+
15
+ ```bash
16
+ # Clone the repository
17
+ git clone https://github.com/mitre/train-k8s-container.git
18
+ cd train-k8s-container
19
+
20
+ # Install dependencies
21
+ bundle install
22
+
23
+ # Run unit tests (no Kubernetes required)
24
+ bundle exec rspec spec/train-k8s-container
25
+
26
+ # Run linting
27
+ bundle exec rake style
28
+ ```
29
+
30
+ ## Project Structure
31
+
32
+ ```
33
+ train-k8s-container/
34
+ ├── lib/
35
+ │ └── train-k8s-container/
36
+ │ ├── connection.rb # Main connection class
37
+ │ ├── kubectl_exec_client.rb # kubectl command execution
38
+ │ ├── platform.rb # Platform detection (Detect+Context)
39
+ │ ├── retry_handler.rb # Retry logic for transient failures
40
+ │ ├── transport.rb # Train transport plugin registration
41
+ │ └── version.rb # Version info
42
+ ├── spec/
43
+ │ ├── train-k8s-container/ # Unit tests (mocked)
44
+ │ └── integration/ # Integration tests (real kubectl)
45
+ ├── test/
46
+ │ ├── scripts/ # Manual test scripts
47
+ │ ├── setup-kind.sh # Kind cluster setup
48
+ │ └── cleanup-kind.sh # Kind cluster teardown
49
+ └── .github/workflows/ # CI/CD pipelines
50
+ ```
51
+
52
+ ## Running Tests
53
+
54
+ ### Unit Tests
55
+
56
+ Unit tests mock all external dependencies and run quickly:
57
+
58
+ ```bash
59
+ # Run all unit tests
60
+ bundle exec rspec spec/train-k8s-container
61
+
62
+ # Run specific test file
63
+ bundle exec rspec spec/train-k8s-container/connection_spec.rb
64
+
65
+ # Run specific test by line number
66
+ bundle exec rspec spec/train-k8s-container/connection_spec.rb:42
67
+
68
+ # Run with verbose output
69
+ bundle exec rspec --format documentation
70
+ ```
71
+
72
+ ### Integration Tests
73
+
74
+ Integration tests require a real Kubernetes cluster:
75
+
76
+ ```bash
77
+ # Setup kind cluster with test pods
78
+ ./test/setup-kind.sh
79
+
80
+ # Run integration tests
81
+ bundle exec rspec spec/integration
82
+
83
+ # Cleanup when done
84
+ ./test/cleanup-kind.sh
85
+ ```
86
+
87
+ ### Full Test Suite
88
+
89
+ ```bash
90
+ # Run all tests (unit + integration)
91
+ bundle exec rspec
92
+
93
+ # With coverage report
94
+ bundle exec rspec
95
+ open coverage/index.html
96
+ ```
97
+
98
+ ## Setting Up Local Kind Cluster
99
+
100
+ ### Automated Setup
101
+
102
+ ```bash
103
+ # Creates cluster and deploys test pods
104
+ ./test/setup-kind.sh
105
+ ```
106
+
107
+ This script:
108
+ 1. Creates a kind cluster named `test-cluster`
109
+ 2. Deploys `test-ubuntu` pod (Ubuntu 22.04 with bash)
110
+ 3. Deploys `test-alpine` pod (Alpine 3.18 with ash/sh)
111
+ 4. Deploys `test-distroless` pod (no shell, for edge case testing)
112
+ 5. Waits for all pods to be ready
113
+
114
+ ### Manual Setup
115
+
116
+ ```bash
117
+ # Create kind cluster
118
+ kind create cluster --name test-cluster
119
+
120
+ # Deploy test pods
121
+ kubectl run test-ubuntu --image=ubuntu:22.04 --restart=Never -- sleep infinity
122
+ kubectl run test-alpine --image=alpine:3.18 --restart=Never -- sleep infinity
123
+
124
+ # Wait for pods
125
+ kubectl wait --for=condition=Ready pod/test-ubuntu --timeout=120s
126
+ kubectl wait --for=condition=Ready pod/test-alpine --timeout=120s
127
+
128
+ # Verify
129
+ kubectl get pods
130
+ kubectl exec test-ubuntu -- echo "ready"
131
+ ```
132
+
133
+ ### Cleanup
134
+
135
+ ```bash
136
+ # Delete cluster
137
+ kind delete cluster --name test-cluster
138
+
139
+ # Or use the cleanup script
140
+ ./test/cleanup-kind.sh
141
+ ```
142
+
143
+ ## Testing with InSpec/Cinc Auditor
144
+
145
+ ### Install Plugin Locally
146
+
147
+ ```bash
148
+ # Build gem
149
+ gem build train-k8s-container.gemspec
150
+
151
+ # Install in Cinc Auditor
152
+ cinc-auditor plugin install train-k8s-container-*.gem
153
+
154
+ # Verify installation
155
+ cinc-auditor plugin list
156
+ ```
157
+
158
+ ### Manual Testing
159
+
160
+ ```bash
161
+ # Detect platform
162
+ cinc-auditor detect -t k8s-container:///test-ubuntu/test-ubuntu
163
+
164
+ # Interactive shell
165
+ cinc-auditor shell -t k8s-container:///test-ubuntu/test-ubuntu
166
+
167
+ # Run a profile
168
+ cinc-auditor exec my-profile -t k8s-container:///test-ubuntu/test-ubuntu
169
+ ```
170
+
171
+ ### Using test_live.rb
172
+
173
+ ```bash
174
+ # Requires kind cluster with test pods
175
+ bundle exec ruby test/scripts/test_live.rb
176
+ ```
177
+
178
+ ## Code Quality
179
+
180
+ ### Linting
181
+
182
+ ```bash
183
+ # Run Cookstyle/RuboCop
184
+ bundle exec rake style
185
+
186
+ # Auto-fix issues
187
+ bundle exec rubocop -a
188
+ ```
189
+
190
+ ### Security Audit
191
+
192
+ ```bash
193
+ # Check for vulnerable dependencies
194
+ bundle audit check --update
195
+ ```
196
+
197
+ ### Full Quality Check
198
+
199
+ ```bash
200
+ # Runs style + tests + security
201
+ bundle exec rake quality
202
+ ```
203
+
204
+ ## Debugging
205
+
206
+ ### Enable Debug Logging
207
+
208
+ ```bash
209
+ # With InSpec/Cinc
210
+ cinc-auditor detect -t k8s-container:///pod/container -l debug
211
+
212
+ # In tests
213
+ TRAIN_K8S_DEBUG=1 bundle exec rspec
214
+ ```
215
+
216
+ ### Common Issues
217
+
218
+ #### "No such file or directory - kubectl"
219
+
220
+ kubectl is not in PATH. Install kubectl or specify the path:
221
+ ```bash
222
+ export PATH=$PATH:/usr/local/bin
223
+ ```
224
+
225
+ #### "error: unable to forward port"
226
+
227
+ The kind cluster may not be running:
228
+ ```bash
229
+ kind get clusters
230
+ kind create cluster --name test-cluster
231
+ ```
232
+
233
+ #### "container not found"
234
+
235
+ Pod or container name doesn't exist:
236
+ ```bash
237
+ kubectl get pods -A
238
+ kubectl describe pod <pod-name>
239
+ ```
240
+
241
+ ### Inspecting kubectl Commands
242
+
243
+ The plugin builds kubectl commands like:
244
+ ```bash
245
+ kubectl exec --stdin <pod> -n <namespace> -c <container> -- /bin/sh -c "<command>"
246
+ ```
247
+
248
+ To debug, run the command manually:
249
+ ```bash
250
+ kubectl exec --stdin test-ubuntu -n default -c test-ubuntu -- /bin/sh -c "whoami"
251
+ ```
252
+
253
+ ## Architecture Notes
254
+
255
+ ### Platform Detection (Detect + Context Pattern)
256
+
257
+ This plugin uses Train's built-in `Detect.scan(self)` to detect the actual OS inside containers, then adds Kubernetes context families:
258
+
259
+ ```ruby
260
+ # lib/train-k8s-container/platform.rb
261
+ @platform = Train::Platforms::Detect.scan(self)
262
+ add_k8s_families(@platform) # Adds 'kubernetes', 'container' families
263
+ ```
264
+
265
+ This allows InSpec resources to work correctly (`os.linux?` = true) while still providing transport context (`platform.kubernetes?` = true).
266
+
267
+ ### Connection Flow
268
+
269
+ 1. **URI Parsing**: `k8s-container://namespace/pod/container`
270
+ 2. **Validation**: Pod/container names validated against RFC 1123
271
+ 3. **Shell Detection**: Probes for available shells (bash, sh, ash, zsh)
272
+ 4. **Command Execution**: Routes through `KubectlExecClient`
273
+ 5. **Platform Detection**: Runs `Detect.scan()` on first access
274
+
275
+ ### Key Files
276
+
277
+ | File | Purpose |
278
+ |------|---------|
279
+ | `transport.rb` | Plugin registration with Train |
280
+ | `connection.rb` | Main connection class, URI parsing |
281
+ | `kubectl_exec_client.rb` | Builds and executes kubectl commands |
282
+ | `platform.rb` | Platform detection using Detect+Context |
283
+ | `retry_handler.rb` | Retry logic for transient failures |
284
+
285
+ ## CI/CD
286
+
287
+ GitHub Actions runs on every push/PR:
288
+
289
+ - **Unit tests**: Ruby 3.1, 3.2, 3.3
290
+ - **Integration tests**: Kubernetes 1.29, 1.30, 1.31
291
+ - **Security scans**: TruffleHog, bundler-audit, SBOM
292
+ - **Pod-to-pod tests**: InSpec running inside cluster
293
+
294
+ See `.github/workflows/ci.yml` for details.
295
+
296
+ ## Releasing
297
+
298
+ Releases are automated via GitHub Actions when a tag is pushed:
299
+
300
+ ```bash
301
+ # Update VERSION file
302
+ echo "2.1.0" > VERSION
303
+
304
+ # Commit and tag
305
+ git add VERSION CHANGELOG.md
306
+ git commit -m "Release v2.1.0"
307
+ git tag v2.1.0
308
+ git push origin main --tags
309
+ ```
310
+
311
+ The `release-tag.yml` workflow will:
312
+ 1. Run tests
313
+ 2. Build gem
314
+ 3. Publish to RubyGems.org
315
+ 4. Create GitHub release
data/Gemfile ADDED
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # train-core is needed for development/testing but NOT declared in gemspec
6
+ # Train plugins are loaded within InSpec's environment which provides train
7
+ gem 'train-core', ['>= 1.7.5', '< 4.0']
8
+
9
+ # Specify your gem's dependencies in train-k8s-container.gemspec
10
+ gemspec
11
+
12
+ group :development do
13
+ gem 'bundler-audit', '~> 0.9'
14
+ gem 'cookstyle', '~> 8.1'
15
+ gem 'rake', '~> 13.0', '>= 13.0.6'
16
+ gem 'rspec', '~> 3.11'
17
+ end
18
+
19
+ group :test do
20
+ gem 'byebug'
21
+ gem 'pry'
22
+ gem 'simplecov', require: false
23
+ end
data/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ Licensed under the Apache-2.0 license, except as noted below.
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
+
5
+ * Redistributions of source code must retain the above copyright/digital rights legend, this list of conditions and the following Notice.
6
+
7
+ * Redistributions in binary form must reproduce the above copyright/digital rights legend, this list of conditions and the following Notice in the documentation and/or other materials provided with the distribution.
8
+
9
+ * Neither the name of The MITRE Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
data/NOTICE.md ADDED
@@ -0,0 +1,9 @@
1
+ MITRE hereby grants express written permission to use, reproduce, distribute, modify, and otherwise leverage this software to the extent permitted by the licensed terms provided in the LICENSE.md file included with this project.
2
+
3
+ This software was produced for the U. S. Government under Contract Number HHSM-500-2012-00008I, and is subject to Federal Acquisition Regulation Clause 52.227-14, Rights in Data-General.
4
+
5
+ No other use other than that granted to the U. S. Government, or to those acting on behalf of the U. S. Government under that Clause is authorized without the express written permission of The MITRE Corporation.
6
+
7
+ For further information, please contact The MITRE Corporation, Contracts Management Office, 7515 Colshire Drive, McLean, VA 22102-7539, (703) 983-6000.
8
+
9
+ (c) 2025 The MITRE Corporation.
data/README.md ADDED
@@ -0,0 +1,237 @@
1
+ # train-k8s-container
2
+
3
+ A Train transport plugin that enables Chef InSpec and Cinc Auditor to execute compliance checks against containers running in Kubernetes clusters via kubectl exec.
4
+
5
+ [![CI](https://github.com/mitre/train-k8s-container/actions/workflows/ci.yml/badge.svg)](https://github.com/mitre/train-k8s-container/actions/workflows/ci.yml)
6
+ [![Security](https://github.com/mitre/train-k8s-container/actions/workflows/security.yml/badge.svg)](https://github.com/mitre/train-k8s-container/actions/workflows/security.yml)
7
+
8
+ ## Overview
9
+
10
+ This plugin allows InSpec/Cinc Auditor to scan containers running in Kubernetes clusters, enabling compliance-as-code for containerized workloads. It supports:
11
+
12
+ - **Pod-to-Pod Scanning**: Scanner pod connects to target containers in other pods
13
+ - **Same-Pod Scanning**: Scanner sidecar scans sibling containers within the same pod
14
+ - **External Scanning**: Run scans from outside the cluster using kubeconfig
15
+
16
+ ## Features
17
+
18
+ - **Train v2 Compliance** - Modern TrainPlugins namespace and structure
19
+ - **Multi-Platform Support** - Linux containers (Ubuntu, Alpine, RHEL, distroless)
20
+ - **Shell Detection** - Automatic detection of available shells (bash, sh, ash, zsh)
21
+ - **Platform Detection** - Uses Train's Detect+Context pattern for accurate OS detection
22
+ - **Security Hardening** - CVE-2021-25743 mitigation, RFC 1123 validation, command injection prevention
23
+ - **Comprehensive Testing** - 95%+ code coverage with unit and integration tests
24
+
25
+ ## Installation
26
+
27
+ ### From RubyGems (Recommended)
28
+
29
+ ```bash
30
+ # Using Cinc Auditor (recommended - open source, license-free)
31
+ cinc-auditor plugin install train-k8s-container
32
+
33
+ # Or using Chef InSpec
34
+ inspec plugin install train-k8s-container
35
+ ```
36
+
37
+ ### From Source
38
+
39
+ ```bash
40
+ git clone https://github.com/mitre/train-k8s-container.git
41
+ cd train-k8s-container
42
+ gem build train-k8s-container.gemspec
43
+ cinc-auditor plugin install train-k8s-container-*.gem
44
+ ```
45
+
46
+ ## Prerequisites
47
+
48
+ - **kubectl** installed and in PATH
49
+ - **kubeconfig** configured with cluster access (default: `~/.kube/config`)
50
+ - **RBAC permissions** to exec into target pods
51
+
52
+ ## Usage
53
+
54
+ ### URI Format
55
+
56
+ ```
57
+ k8s-container://<namespace>/<pod>/<container>
58
+ ```
59
+
60
+ - `namespace` - Kubernetes namespace (use empty for `default`)
61
+ - `pod` - Pod name
62
+ - `container` - Container name within the pod
63
+
64
+ ### Examples
65
+
66
+ ```bash
67
+ # Detect container platform
68
+ cinc-auditor detect -t k8s-container://production/web-app/nginx
69
+
70
+ # Using default namespace
71
+ cinc-auditor detect -t k8s-container:///my-pod/my-container
72
+
73
+ # Interactive shell
74
+ cinc-auditor shell -t k8s-container:///my-pod/my-container
75
+
76
+ # Run a compliance profile
77
+ cinc-auditor exec my-profile -t k8s-container://prod/app-pod/app
78
+
79
+ # Run STIG baseline
80
+ cinc-auditor exec https://github.com/mitre/canonical-ubuntu-22.04-lts-stig-baseline \
81
+ -t k8s-container:///target-pod/target-container
82
+ ```
83
+
84
+ ### Platform Detection Output
85
+
86
+ ```bash
87
+ $ cinc-auditor detect -t k8s-container:///test-ubuntu/test-ubuntu
88
+
89
+ Name: ubuntu
90
+ Families: debian, linux, unix, os, kubernetes, container
91
+ Release: 22.04
92
+ Arch: aarch64
93
+ ```
94
+
95
+ ### Running Compliance Checks
96
+
97
+ ```ruby
98
+ # Example InSpec control
99
+ control 'container-security-1' do
100
+ impact 1.0
101
+ title 'Verify container user'
102
+
103
+ describe user('root') do
104
+ it { should exist }
105
+ end
106
+
107
+ describe file('/etc/passwd') do
108
+ it { should exist }
109
+ its('owner') { should eq 'root' }
110
+ end
111
+ end
112
+ ```
113
+
114
+ ## Kubernetes RBAC Setup
115
+
116
+ For pod-to-pod scanning, the scanner pod needs exec permissions:
117
+
118
+ ```yaml
119
+ apiVersion: v1
120
+ kind: ServiceAccount
121
+ metadata:
122
+ name: inspec-scanner
123
+ namespace: default
124
+ ---
125
+ apiVersion: rbac.authorization.k8s.io/v1
126
+ kind: ClusterRole
127
+ metadata:
128
+ name: inspec-scanner-role
129
+ rules:
130
+ - apiGroups: [""]
131
+ resources: ["pods", "pods/exec"]
132
+ verbs: ["get", "list", "create"]
133
+ ---
134
+ apiVersion: rbac.authorization.k8s.io/v1
135
+ kind: ClusterRoleBinding
136
+ metadata:
137
+ name: inspec-scanner-binding
138
+ subjects:
139
+ - kind: ServiceAccount
140
+ name: inspec-scanner
141
+ namespace: default
142
+ roleRef:
143
+ kind: ClusterRole
144
+ name: inspec-scanner-role
145
+ apiGroup: rbac.authorization.k8s.io
146
+ ```
147
+
148
+ ## Supported Container Types
149
+
150
+ ### Linux Containers
151
+
152
+ | Distribution | Shell | Status |
153
+ |-------------|-------|--------|
154
+ | Ubuntu/Debian | bash | Full support |
155
+ | Alpine/BusyBox | ash/sh | Full support |
156
+ | RHEL/CentOS | bash | Full support |
157
+ | Distroless | N/A | Limited (direct binary only) |
158
+
159
+ ### Not Yet Supported
160
+
161
+ - Windows containers (planned)
162
+
163
+ ## Configuration
164
+
165
+ ### Environment Variables
166
+
167
+ | Variable | Description | Default |
168
+ |----------|-------------|---------|
169
+ | `KUBECONFIG` | Path to kubeconfig file | `~/.kube/config` |
170
+ | `TRAIN_K8S_DEBUG` | Enable debug logging | `false` |
171
+
172
+ ## Development
173
+
174
+ See [DEVELOPMENT.md](DEVELOPMENT.md) for local development setup and testing.
175
+
176
+ ### Quick Start
177
+
178
+ ```bash
179
+ # Install dependencies
180
+ bundle install
181
+
182
+ # Run unit tests
183
+ bundle exec rspec spec/train-k8s-container
184
+
185
+ # Run linting
186
+ bundle exec rake style
187
+
188
+ # Setup kind cluster for integration tests
189
+ ./test/setup-kind.sh
190
+
191
+ # Run integration tests
192
+ bundle exec rspec spec/integration
193
+ ```
194
+
195
+ ## Contributing
196
+
197
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
198
+
199
+ 1. Fork the repository
200
+ 2. Create a feature branch
201
+ 3. Make changes with tests
202
+ 4. Run `bundle exec rspec && bundle exec rake style`
203
+ 5. Submit a pull request
204
+
205
+ ## Security
206
+
207
+ See [SECURITY.md](SECURITY.md) for security policy and reporting vulnerabilities.
208
+
209
+ - Report vulnerabilities to [saf-security@mitre.org](mailto:saf-security@mitre.org)
210
+ - Do NOT open public issues for security vulnerabilities
211
+
212
+ ## License
213
+
214
+ Licensed under Apache-2.0. See [LICENSE.md](LICENSE.md) and [NOTICE.md](NOTICE.md).
215
+
216
+ ## Maintainers
217
+
218
+ This project is maintained by the MITRE SAF (Security Automation Framework) team.
219
+
220
+ - **Email**: [saf@mitre.org](mailto:saf@mitre.org)
221
+ - **Website**: [saf.mitre.org](https://saf.mitre.org)
222
+
223
+ ## Acknowledgments
224
+
225
+ This project is a fork of [inspec/train-k8s-container](https://github.com/inspec/train-k8s-container), significantly enhanced with:
226
+
227
+ - Train v2 plugin architecture
228
+ - Detect+Context platform detection pattern
229
+ - Comprehensive CI/CD with pod-to-pod testing
230
+ - Security hardening and SBOM generation
231
+ - MITRE SAF ecosystem integration
232
+
233
+ ---
234
+
235
+ NOTICE: This software was produced for the U.S. Government under Contract Number HHSM-500-2012-00008I, and is subject to Federal Acquisition Regulation Clause 52.227-14, Rights in Data-General.
236
+
237
+ (c) 2025 The MITRE Corporation.
data/Rakefile ADDED
@@ -0,0 +1,37 @@
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
+ begin
9
+ require 'cookstyle'
10
+ require 'rubocop/rake_task'
11
+ desc 'Run Cookstyle tests'
12
+ RuboCop::RakeTask.new(:style) do |task|
13
+ task.options += %w[--display-cop-names --no-color --parallel]
14
+ end
15
+ rescue LoadError
16
+ puts 'cookstyle gem is not installed. bundle install first to make sure all dependencies are installed.'
17
+ end
18
+
19
+ desc 'Run security scans (bundler-audit)'
20
+ task :security do
21
+ require 'bundler/audit/task'
22
+ Bundler::Audit::Task.new
23
+
24
+ puts '=== Running Security Scans ==='
25
+ puts '--- Bundler Audit (Dependency Vulnerabilities) ---'
26
+
27
+ Rake::Task['bundle:audit:update'].invoke
28
+ Rake::Task['bundle:audit'].invoke
29
+
30
+ puts
31
+ puts '✅ Security scans complete'
32
+ end
33
+
34
+ desc 'Run all quality checks (style + spec + security)'
35
+ task quality: %i[style spec security]
36
+
37
+ task default: :spec