Class: Terrafying::Components::SelfSignedCA
- Inherits:
-
Terrafying::Context
- Object
- Terrafying::Context
- Terrafying::Components::SelfSignedCA
- Includes:
- CA
- Defined in:
- lib/terrafying/components/selfsignedca.rb
Instance Attribute Summary collapse
-
#ca_key ⇒ Object
readonly
Returns the value of attribute ca_key.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Class Method Summary collapse
Instance Method Summary collapse
- #create(name, bucket, options = {}) ⇒ Object
- #create_keypair_in(ctx, name, options = {}) ⇒ Object
-
#initialize ⇒ SelfSignedCA
constructor
A new instance of SelfSignedCA.
- #keypair ⇒ Object
Methods included from CA
#<=>, #create_keypair, #reference_keypair
Constructor Details
#initialize ⇒ SelfSignedCA
Returns a new instance of SelfSignedCA.
19 20 21 |
# File 'lib/terrafying/components/selfsignedca.rb', line 19 def initialize() super end |
Instance Attribute Details
#ca_key ⇒ Object (readonly)
Returns the value of attribute ca_key.
11 12 13 |
# File 'lib/terrafying/components/selfsignedca.rb', line 11 def ca_key @ca_key end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/terrafying/components/selfsignedca.rb', line 11 def name @name end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
11 12 13 |
# File 'lib/terrafying/components/selfsignedca.rb', line 11 def source @source end |
Class Method Details
.create(name, bucket, options = {}) ⇒ Object
15 16 17 |
# File 'lib/terrafying/components/selfsignedca.rb', line 15 def self.create(name, bucket, ={}) SelfSignedCA.new.create name, bucket, end |
Instance Method Details
#create(name, bucket, options = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/terrafying/components/selfsignedca.rb', line 23 def create(name, bucket, ={}) = { prefix: "", common_name: name, organization: "uSwitch Limited", public_certificate: false, }.merge() @name = name @bucket = bucket @prefix = [:prefix] @ident = "#{name}-ca" provider :tls, {} resource :tls_private_key, @ident, { algorithm: "ECDSA", ecdsa_curve: "P384", } resource :tls_self_signed_cert, @ident, { key_algorithm: "ECDSA", private_key_pem: output_of(:tls_private_key, @ident, :private_key_pem), subject: { common_name: [:common_name], organization: [:organization], }, is_ca_certificate: true, validity_period_hours: 24 * 365, allowed_uses: [ "certSigning", "digitalSignature", ], } @source = File.join("s3://", @bucket, @prefix, @name, "ca.cert") @ca_key = output_of(:tls_private_key, @ident, :private_key_pem) @ca_cert = output_of(:tls_self_signed_cert, @ident, :cert_pem) if [:public_certificate] cert_acl = "public-read" else cert_acl = "private" end resource :aws_s3_bucket_object, "#{@name}-cert", { bucket: @bucket, key: File.join(@prefix, @name, "ca.cert"), content: @ca_cert, acl: cert_acl, } self end |
#create_keypair_in(ctx, name, options = {}) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/terrafying/components/selfsignedca.rb', line 115 def create_keypair_in(ctx, name, ={}) = { common_name: name, organization: "uSwitch Limited", validity_in_hours: 24 * 365, allowed_uses: [ "nonRepudiation", "digitalSignature", "keyEncipherment" ], dns_names: [], ip_addresses: [], }.merge() key_ident = "#{@name}-#{tf_safe(name)}" ctx.resource :tls_private_key, key_ident, { algorithm: "ECDSA", ecdsa_curve: "P384", } ctx.resource :tls_cert_request, key_ident, { key_algorithm: "ECDSA", private_key_pem: output_of(:tls_private_key, key_ident, :private_key_pem), subject: { common_name: [:common_name], organization: [:organization], }, dns_names: [:dns_names], ip_addresses: [:ip_addresses], } ctx.resource :tls_locally_signed_cert, key_ident, { cert_request_pem: output_of(:tls_cert_request, key_ident, :cert_request_pem), ca_key_algorithm: "ECDSA", ca_private_key_pem: @ca_key, ca_cert_pem: @ca_cert, validity_period_hours: [:validity_in_hours], allowed_uses: [:allowed_uses], } ctx.resource :aws_s3_bucket_object, "#{key_ident}-key", { bucket: @bucket, key: File.join(@prefix, @name, name, "key"), content: output_of(:tls_private_key, key_ident, :private_key_pem), } ctx.resource :aws_s3_bucket_object, "#{key_ident}-cert", { bucket: @bucket, key: File.join(@prefix, @name, name, "cert"), content: output_of(:tls_locally_signed_cert, key_ident, :cert_pem), } reference_keypair(ctx, name) end |
#keypair ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/terrafying/components/selfsignedca.rb', line 80 def keypair resource :aws_s3_bucket_object, "#{@name}-key", { bucket: @bucket, key: File.join(@prefix, @name, "ca.key"), content: @ca_key, } { ca: self, path: { cert: File.join("/etc/ssl", @name, "ca.cert"), key: File.join("/etc/ssl", @name, "ca.key"), }, source: { cert: File.join("s3://", @bucket, @prefix, @name, "ca.cert"), key: File.join("s3://", @bucket, @prefix, @name, "ca.key"), }, resources: [ "aws_s3_bucket_object.#{@name}-key", "aws_s3_bucket_object.#{@name}-cert" ], iam_statement: { Effect: "Allow", Action: [ "s3:GetObjectAcl", "s3:GetObject", ], Resource: [ "arn:aws:s3:::#{File.join(@bucket, @prefix, @name, "ca.cert")}", "arn:aws:s3:::#{File.join(@bucket, @prefix, @name, "ca.key")}", ] } } end |