stack_master 1.1.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a51b4fe56605619be180809d3e8b936beba108c0
4
- data.tar.gz: 479573ec4534231f8cc2dad7a1d7396f240c3ed6
2
+ SHA256:
3
+ metadata.gz: 77c6c6c758e05af556c50439bfdf5dce99720a8deb44f485f0e17bcbd82890a6
4
+ data.tar.gz: 8f467f0f94b7e963afac93400d4f2c4152a3cbc6e12dc0949ed8fcfc857f5d9d
5
5
  SHA512:
6
- metadata.gz: 9c7784db458ab74af7d4b7d1b18c4603c1227d73574d1624d013fded5bb6af8ec2f74239b7d30b50085fb6c5b781f62a46905b89f883fe00a77bc469621cdb8e
7
- data.tar.gz: e5244c0803bd55d3462fb02f79d239a6b240fd3ca7dd88649021097bc0b20c9ac97fa5e9070667ef5a5d7e3bcc6f3a94cb2ec733a02329692f3fea66719da605
6
+ metadata.gz: f32beb39936cbe533bf08949f2a9657f69dc353dda6bf12f9d98d4736a00060d3745baec090d02fb02288d7abf739a923c0d21af6f7d77f27d2540b67971535d
7
+ data.tar.gz: 467c51b8edc25e774f20ab3a804b8d44f3559bbde1e9c7817f67935d8a1a4a577d7d4f3181650c48bfa708b11a314213c1ae40e44a546dd03ba882ef225608a1
data/README.md CHANGED
@@ -240,6 +240,21 @@ db_password:
240
240
  secret: db_password
241
241
  ```
242
242
 
243
+ ### Parameter Store
244
+ An alternative to the secrets store, uses the AWS SSM Parameter store to protect
245
+ secrets. Expects a parameter of either `String` or `SecureString` type to be present in the
246
+ same region as the stack. You can store the parameter using a command like this
247
+
248
+ `aws ssm put-parameter --region <region> --name <parameter name> --value <secret> --type (String|SecureString)`
249
+
250
+ When doing so make sure you don't accidentally store the secret in your `.bash_history` and
251
+ you will likely want to set the parameter to NoEcho in your template.
252
+
253
+ ```yaml
254
+ db_password:
255
+ parameter_store: ssm_parameter_name
256
+ ```
257
+
243
258
  ### Security Group
244
259
 
245
260
  Looks up a security group by name and returns the ARN.
@@ -0,0 +1,47 @@
1
+ Feature: Apply command with parameter_store parameter
2
+
3
+ Background:
4
+ Given a file named "stack_master.yml" with:
5
+ """
6
+ stacks:
7
+ us-east-2:
8
+ vpc:
9
+ template: vpc.rb
10
+ """
11
+ And a directory named "parameters"
12
+ And a file named "parameters/vpc.yml" with:
13
+ """
14
+ vpc_cidr:
15
+ parameter_store: "/cucumber-test-vpc-cidr"
16
+ """
17
+ And a SSM parameter named "/cucumber-test-vpc-cidr" with value "10.0.0.0/16" in region "us-east-2"
18
+ And a directory named "templates"
19
+ And a file named "templates/vpc.rb" with:
20
+ """
21
+ SparkleFormation.new(:vpc) do
22
+
23
+ parameters.vpc_cidr do
24
+ type 'String'
25
+ end
26
+
27
+ resources.vpc do
28
+ type 'AWS::EC2::VPC'
29
+ properties do
30
+ cidr_block ref!(:vpc_cidr)
31
+ end
32
+ end
33
+
34
+ end
35
+ """
36
+
37
+ Scenario: Run apply and create a new stack
38
+ Given I stub the following stack events:
39
+ | stack_id | event_id | stack_name | logical_resource_id | resource_status | resource_type | timestamp |
40
+ | 1 | 1 | vpc | Vpc | CREATE_COMPLETE | AWS::EC2::VPC | 2020-10-29 00:00:00 |
41
+ | 1 | 1 | vpc | vpc | CREATE_COMPLETE | AWS::CloudFormation::Stack | 2020-10-29 00:00:00 |
42
+ When I run `stack_master apply us-east-2 vpc --trace`
43
+ And the output should contain all of these lines:
44
+ | +--- |
45
+ | +VpcCidr: 10.0.0.0/16 |
46
+ And the output should match /2020-10-29 00:00:00 (\+|\-)[0-9]{4} vpc AWS::CloudFormation::Stack CREATE_COMPLETE/
47
+ Then the exit status should be 0
@@ -0,0 +1,14 @@
1
+ Given(/^(?:a|the) SSM parameter(?: named)? "([^"]*)" with value "([^"]*)" in region "([^"]*)"$/) do |parameter_name, parameter_value, parameter_region|
2
+ Aws.config[:ssm] = {
3
+ stub_responses: {
4
+ get_parameter: {
5
+ parameter: {
6
+ name: parameter_name,
7
+ value: parameter_value,
8
+ type: "SecureString",
9
+ version: 1
10
+ }
11
+ }
12
+ }
13
+ }
14
+ end
@@ -61,6 +61,7 @@ module StackMaster
61
61
  autoload :LatestAmiByTags, 'stack_master/parameter_resolvers/latest_ami_by_tags'
62
62
  autoload :LatestAmi, 'stack_master/parameter_resolvers/latest_ami'
63
63
  autoload :Env, 'stack_master/parameter_resolvers/env'
64
+ autoload :ParameterStore, 'stack_master/parameter_resolvers/parameter_store'
64
65
  end
65
66
 
66
67
  module AwsDriver
@@ -0,0 +1,31 @@
1
+ module StackMaster
2
+ module ParameterResolvers
3
+ class ParameterStore < Resolver
4
+
5
+ ParameterNotFound = Class.new(StandardError)
6
+
7
+ def initialize(config, stack_definition)
8
+ @config = config
9
+ @stack_definition = stack_definition
10
+ end
11
+
12
+ def resolve(value)
13
+ begin
14
+ resp = ssm.get_parameter(
15
+ name: value,
16
+ with_decryption: true
17
+ )
18
+ rescue Aws::SSM::Errors::ParameterNotFound
19
+ raise ParameterNotFound, "Unable to find #{value} in Parameter Store"
20
+ end
21
+ resp.parameter.value
22
+ end
23
+
24
+ private
25
+
26
+ def ssm
27
+ @ssm ||= Aws::SSM::Client.new(region: @stack_definition.region)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,3 +1,3 @@
1
1
  module StackMaster
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.1"
3
3
  end
@@ -0,0 +1,50 @@
1
+ RSpec.describe StackMaster::ParameterResolvers::ParameterStore do
2
+
3
+ describe '#resolve' do
4
+
5
+ let(:config) { double(base_dir: '/base') }
6
+ let(:stack_definition) { double(stack_name: 'mystack', region: 'us-east-1') }
7
+ subject(:resolver) { described_class.new(config, stack_definition) }
8
+ let(:parameter_name) { 'TEST' }
9
+ let(:parameter_value) { 'TEST' }
10
+ let(:unknown_parameter_name) { 'NOTEST' }
11
+ let(:unencryptable_parameter_name) { 'SECRETTEST' }
12
+
13
+
14
+ context 'the parameter is defined' do
15
+ before do
16
+ Aws.config[:ssm] = {
17
+ stub_responses: {
18
+ get_parameter: {
19
+ parameter: {
20
+ name: parameter_name,
21
+ value: parameter_value,
22
+ type: "SecureString",
23
+ version: 1
24
+ }
25
+ }
26
+ }
27
+ }
28
+ end
29
+
30
+ it 'should return the parameter value' do
31
+ expect(resolver.resolve(parameter_name)).to eq parameter_value
32
+ end
33
+ end
34
+
35
+ context 'the parameter is undefined' do
36
+ before do
37
+ Aws.config[:ssm] = {
38
+ stub_responses: {
39
+ get_parameter:
40
+ Aws::SSM::Errors::ParameterNotFound.new(unknown_parameter_name, "Parameter #{unknown_parameter_name} not found")
41
+ }
42
+ }
43
+ end
44
+ it 'should raise and error' do
45
+ expect { resolver.resolve(unknown_parameter_name) }
46
+ .to raise_error(StackMaster::ParameterResolvers::ParameterStore::ParameterNotFound, "Unable to find #{unknown_parameter_name} in Parameter Store")
47
+ end
48
+ end
49
+ end
50
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stack_master
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Hodgkiss
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-02-21 00:00:00.000000000 Z
12
+ date: 2018-02-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -304,6 +304,7 @@ files:
304
304
  - features/apply.feature
305
305
  - features/apply_with_compile_time_parameters.feature
306
306
  - features/apply_with_env_parameters.feature
307
+ - features/apply_with_parameter_store_parameters.feature
307
308
  - features/apply_with_s3.feature
308
309
  - features/delete.feature
309
310
  - features/diff.feature
@@ -314,6 +315,7 @@ files:
314
315
  - features/resources.feature
315
316
  - features/stack_defaults.feature
316
317
  - features/status.feature
318
+ - features/step_definitions/parameter_store_steps.rb
317
319
  - features/step_definitions/stack_steps.rb
318
320
  - features/support/env.rb
319
321
  - features/validate.feature
@@ -343,6 +345,7 @@ files:
343
345
  - lib/stack_master/parameter_resolvers/env.rb
344
346
  - lib/stack_master/parameter_resolvers/latest_ami.rb
345
347
  - lib/stack_master/parameter_resolvers/latest_ami_by_tags.rb
348
+ - lib/stack_master/parameter_resolvers/parameter_store.rb
346
349
  - lib/stack_master/parameter_resolvers/secret.rb
347
350
  - lib/stack_master/parameter_resolvers/security_group.rb
348
351
  - lib/stack_master/parameter_resolvers/sns_topic_name.rb
@@ -417,6 +420,7 @@ files:
417
420
  - spec/stack_master/parameter_resolvers/env_spec.rb
418
421
  - spec/stack_master/parameter_resolvers/latest_ami_by_tags_spec.rb
419
422
  - spec/stack_master/parameter_resolvers/latest_ami_spec.rb
423
+ - spec/stack_master/parameter_resolvers/parameter_store_spec.rb
420
424
  - spec/stack_master/parameter_resolvers/secret_spec.rb
421
425
  - spec/stack_master/parameter_resolvers/security_group_spec.rb
422
426
  - spec/stack_master/parameter_resolvers/security_groups_spec.rb
@@ -485,7 +489,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
485
489
  version: '0'
486
490
  requirements: []
487
491
  rubyforge_project:
488
- rubygems_version: 2.6.11
492
+ rubygems_version: 2.7.6
489
493
  signing_key:
490
494
  specification_version: 4
491
495
  summary: StackMaster is a sure-footed way of creating, updating and keeping track
@@ -494,6 +498,7 @@ test_files:
494
498
  - features/apply.feature
495
499
  - features/apply_with_compile_time_parameters.feature
496
500
  - features/apply_with_env_parameters.feature
501
+ - features/apply_with_parameter_store_parameters.feature
497
502
  - features/apply_with_s3.feature
498
503
  - features/delete.feature
499
504
  - features/diff.feature
@@ -504,6 +509,7 @@ test_files:
504
509
  - features/resources.feature
505
510
  - features/stack_defaults.feature
506
511
  - features/status.feature
512
+ - features/step_definitions/parameter_store_steps.rb
507
513
  - features/step_definitions/stack_steps.rb
508
514
  - features/support/env.rb
509
515
  - features/validate.feature
@@ -533,6 +539,7 @@ test_files:
533
539
  - spec/stack_master/parameter_resolvers/env_spec.rb
534
540
  - spec/stack_master/parameter_resolvers/latest_ami_by_tags_spec.rb
535
541
  - spec/stack_master/parameter_resolvers/latest_ami_spec.rb
542
+ - spec/stack_master/parameter_resolvers/parameter_store_spec.rb
536
543
  - spec/stack_master/parameter_resolvers/secret_spec.rb
537
544
  - spec/stack_master/parameter_resolvers/security_group_spec.rb
538
545
  - spec/stack_master/parameter_resolvers/security_groups_spec.rb