google-ssl-cert 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +3 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +6 -0
- data/Guardfile +19 -0
- data/LICENSE.txt +1 -0
- data/README.md +153 -0
- data/Rakefile +14 -0
- data/docs/google-secrets-cheatsheet.md +6 -0
- data/exe/google-ssl-cert +14 -0
- data/google-ssl-cert.gemspec +43 -0
- data/lib/google-ssl-cert.rb +1 -0
- data/lib/google_ssl_cert/autoloader.rb +22 -0
- data/lib/google_ssl_cert/base.rb +14 -0
- data/lib/google_ssl_cert/cert.rb +85 -0
- data/lib/google_ssl_cert/cli/base.rb +12 -0
- data/lib/google_ssl_cert/cli/create.rb +67 -0
- data/lib/google_ssl_cert/cli/help/completion.md +20 -0
- data/lib/google_ssl_cert/cli/help/completion_script.md +3 -0
- data/lib/google_ssl_cert/cli/help/create.md +31 -0
- data/lib/google_ssl_cert/cli/help/prune.md +30 -0
- data/lib/google_ssl_cert/cli/help/secret/get.md +4 -0
- data/lib/google_ssl_cert/cli/help/secret/save.md +4 -0
- data/lib/google_ssl_cert/cli/help.rb +11 -0
- data/lib/google_ssl_cert/cli/prune.rb +88 -0
- data/lib/google_ssl_cert/cli/secret.rb +15 -0
- data/lib/google_ssl_cert/cli.rb +62 -0
- data/lib/google_ssl_cert/command.rb +89 -0
- data/lib/google_ssl_cert/completer/script.rb +8 -0
- data/lib/google_ssl_cert/completer/script.sh +10 -0
- data/lib/google_ssl_cert/completer.rb +159 -0
- data/lib/google_ssl_cert/global.rb +12 -0
- data/lib/google_ssl_cert/google_services.rb +30 -0
- data/lib/google_ssl_cert/helpers/global.rb +7 -0
- data/lib/google_ssl_cert/helpers/project_number.rb +15 -0
- data/lib/google_ssl_cert/logger.rb +28 -0
- data/lib/google_ssl_cert/logging.rb +9 -0
- data/lib/google_ssl_cert/name.rb +19 -0
- data/lib/google_ssl_cert/secret.rb +86 -0
- data/lib/google_ssl_cert/version.rb +3 -0
- data/lib/google_ssl_cert.rb +13 -0
- data/spec/cli_spec.rb +26 -0
- data/spec/spec_helper.rb +29 -0
- metadata +272 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2b8d9e0628aac83d0eb66c15b5e2c711949e50ba2716f370151227c39065010e
|
4
|
+
data.tar.gz: 4dd9a50a62e9a658c537306f5530cdeefb96253fd64cdd47bfd574cf995bb6d8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3e081cf7944e0e37e2b58e2e4985c1374b58206ce50a54737bdec410c83f69d42c0a4049e7e0604cf8429c59962d11c2d09e1d8c4ddd0b5b6ca7202a83ff3005
|
7
|
+
data.tar.gz: bf7c86b74c5eb758d319f817fc6a5b5c79a9297d6db77d78c79c3cc169c2e8fad8f0d52171b2c4bb013e4d65907b5a94fd04a72840bd7da3f5ada8f604cbe48e
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
guard "bundler", cmd: "bundle" do
|
2
|
+
watch("Gemfile")
|
3
|
+
watch(/^.+\.gemspec/)
|
4
|
+
end
|
5
|
+
|
6
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
7
|
+
require "guard/rspec/dsl"
|
8
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
9
|
+
|
10
|
+
# RSpec files
|
11
|
+
rspec = dsl.rspec
|
12
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
13
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
14
|
+
watch(rspec.spec_files)
|
15
|
+
|
16
|
+
# Ruby files
|
17
|
+
ruby = dsl.ruby
|
18
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
19
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Proprietary, All rights reserved. For licensing and terms, please refer to https://www.boltops.com/terms
|
data/README.md
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
# Google Ssl Cert Rotation Tool
|
2
|
+
|
3
|
+
[![BoltOps Badge](https://img.boltops.com/boltops/badges/boltops-badge.png)](https://www.boltops.com)
|
4
|
+
|
5
|
+
A Google SSL Cert rotation automation tool.
|
6
|
+
|
7
|
+
## How Does It Work?
|
8
|
+
|
9
|
+
You should run this tool in the folder with your cert files. The cert files can be inferred conventionally or explicitly specified. Tool can be used in conjuction with [Kubes](https://kubes.guru/) and the [google_secret](https://kubes.guru/docs/helpers/google/secrets/) helper. It can be used to automate the SSL cert rotation process.
|
10
|
+
|
11
|
+
This is done by generating a new SSL cert and storing that name to Google secrets. All the user needs to do is be in the folder with the cert private key and signed cert. These files are typically named: `private.key` and `certificate.crt`. The key is that the Google Secret name itself does not change, only it's value.
|
12
|
+
|
13
|
+
### Kubes Kuberbetes YAML
|
14
|
+
|
15
|
+
Your Kuberbetes YAML files can be built with [Kubes](https://kubes.guru/) with the `google_secret` helper which references the cert name.
|
16
|
+
|
17
|
+
Example `ingress.yaml` with an L7 external load balancer and global cert.
|
18
|
+
|
19
|
+
.kubes/resources/web/ingress.yaml:
|
20
|
+
|
21
|
+
```yaml
|
22
|
+
apiVersion: networking.k8s.io/v1
|
23
|
+
kind: Ingress
|
24
|
+
metadata:
|
25
|
+
name: web
|
26
|
+
annotations:
|
27
|
+
ingress.gcp.kubernetes.io/pre-shared-cert: '<%= google_secret("cert_demo", base64: false) %>'
|
28
|
+
spec:
|
29
|
+
defaultBackend:
|
30
|
+
service:
|
31
|
+
name: web
|
32
|
+
port:
|
33
|
+
number: 80
|
34
|
+
```
|
35
|
+
|
36
|
+
The `.kubes/resources/web/ingress.yaml` code remains the same, but the generated/compiled ``.kubes/output/web/ingress.yaml`` will have the new Google SSL Cert name. This triggers Kuberbetes to do a rolling deploy properly.
|
37
|
+
|
38
|
+
## Summary of Steps
|
39
|
+
|
40
|
+
1. Use the `google-ssl-cert create` command to create new SSL cert and save the name to Google Secrets. The value in the Google Secret can be later referenced.
|
41
|
+
2. Deploying your application to Kuberbetes and using the Kubes `google_secret` helper that references the new cert name.
|
42
|
+
3. Pruning the old cert names with the `google-ssl-cert prune` command.
|
43
|
+
|
44
|
+
## Usage: Quick Start
|
45
|
+
|
46
|
+
Make sure you have the cert files in your current folder:
|
47
|
+
|
48
|
+
$ ls
|
49
|
+
private.key certificate.crt
|
50
|
+
|
51
|
+
When no cert name is provided, one will be generated for you:
|
52
|
+
|
53
|
+
$ google-ssl-cert create --secret-name cert_demo
|
54
|
+
Global cert created: google-ssl-cert-global-20211021155725
|
55
|
+
Secret saved: name: cert_demo value: google-ssl-cert-global-20211021155725
|
56
|
+
|
57
|
+
Check that cert and secret was created on google cloud:
|
58
|
+
|
59
|
+
% gcloud compute ssl-certificates list
|
60
|
+
NAME TYPE CREATION_TIMESTAMP EXPIRE_TIME MANAGED_STATUS
|
61
|
+
google-ssl-cert-global-20211021155725 SELF_MANAGED 2021-10-21T08:57:26.005-07:00 2022-01-12T15:59:59.000-08:00
|
62
|
+
~/environment/cert-files git:master aws:tung:us-west-2 gke:default
|
63
|
+
%
|
64
|
+
$ gcloud secrets versions access latest --secret cert_demo
|
65
|
+
google-ssl-cert-global-20211021155725
|
66
|
+
|
67
|
+
## Usage: Region Cert
|
68
|
+
|
69
|
+
If you need to create a region cert instead, IE: for internal load balancers, specify the `--no-global` flag. Example:
|
70
|
+
|
71
|
+
$ google-ssl-cert create --secret-name cert_demo --no-global
|
72
|
+
Region cert created: google-ssl-cert-us-central1-20211021155852 in region: us-central1
|
73
|
+
Secret saved: name: cert_demo value: google-ssl-cert-us-central1-20211021155852
|
74
|
+
|
75
|
+
Check that cert and secret was created on google cloud:
|
76
|
+
|
77
|
+
$ gcloud compute ssl-certificates list
|
78
|
+
NAME TYPE CREATION_TIMESTAMP EXPIRE_TIME MANAGED_STATUS
|
79
|
+
google-ssl-cert-us-central1-20211021155852 SELF_MANAGED 2021-10-21T08:58:53.514-07:00 2022-01-12T15:59:59.000-08:00
|
80
|
+
|
81
|
+
## Usage: Specifying the Cert Name
|
82
|
+
|
83
|
+
You can also specify the cert name:
|
84
|
+
|
85
|
+
$ google-ssl-cert create --cert-name google-ssl-cert-v1 --no-timestamp --secret-name cert_demo
|
86
|
+
Global cert created: google-ssl-cert-v1
|
87
|
+
Secret saved: name: cert_demo value: google-ssl-cert-v1
|
88
|
+
|
89
|
+
Check that cert was created on google cloud:
|
90
|
+
|
91
|
+
$ gcloud compute ssl-certificates list
|
92
|
+
NAME TYPE CREATION_TIMESTAMP EXPIRE_TIME MANAGED_STATUS
|
93
|
+
google-ssl-cert-v1 SELF_MANAGED 2021-10-21T09:00:43.975-07:00 2022-01-12T15:59:59.000-08:00
|
94
|
+
|
95
|
+
## Required Env Vars
|
96
|
+
|
97
|
+
These env vars should be set:
|
98
|
+
|
99
|
+
Name | Description
|
100
|
+
--- | ---
|
101
|
+
GOOGLE\_APPLICATION_CREDENTIALS | A service account as must be set up with `GOOGLE_APPLICATION_CREDENTIALS`. IE: `export GOOGLE_APPLICATION_CREDENTIALS=~/.gcp/credentials.json`
|
102
|
+
GOOGLE_PROJECT | The env var `GOOGLE_PROJECT` and must be set.
|
103
|
+
GOOGLE_REGION | The env var `GOOGLE_REGION` and must be set when creating a region-based google ssl cert. So when using the `--no-global` flag
|
104
|
+
|
105
|
+
To check that `GOOGLE_APPLICATION_CREDENTIALS` is valid and is working you can use the [boltops-tools/google_check](https://github.com/boltops-tools/google_check) test script to check. Here are the summarized commands:
|
106
|
+
|
107
|
+
git clone https://github.com/boltops-tools/google_check
|
108
|
+
cd google_check
|
109
|
+
bundle
|
110
|
+
bundle exec ruby google_check.rb
|
111
|
+
|
112
|
+
## Cert Files Conventions
|
113
|
+
|
114
|
+
The tool will look in your current folder for these private keys in the following order:
|
115
|
+
|
116
|
+
private.key
|
117
|
+
server.key
|
118
|
+
key.pem
|
119
|
+
|
120
|
+
And look for these certs:
|
121
|
+
|
122
|
+
certificate.crt
|
123
|
+
server.crt
|
124
|
+
cert.pem
|
125
|
+
|
126
|
+
So, for example, if you name your cert files in your current folder conventionally like so:
|
127
|
+
|
128
|
+
private.key # private key
|
129
|
+
certificate.crt # signed cert
|
130
|
+
|
131
|
+
The tool is able to detect it and automatically use those files to create the cert.
|
132
|
+
|
133
|
+
You can also specify the path to the certificate and private key explicitly:
|
134
|
+
|
135
|
+
google-ssl-cert create --private-key server.key --certificate server.crt
|
136
|
+
|
137
|
+
## Prune
|
138
|
+
|
139
|
+
To prune or delete old google ssl certs after rotating:
|
140
|
+
|
141
|
+
google-ssl-cert prune
|
142
|
+
|
143
|
+
## Installation
|
144
|
+
|
145
|
+
gem install google-ssl-cert
|
146
|
+
|
147
|
+
## Contributing
|
148
|
+
|
149
|
+
1. Fork it
|
150
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
151
|
+
3. Commit your changes (`git commit -am "Add some feature"`)
|
152
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
153
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
|
4
|
+
task default: :spec
|
5
|
+
|
6
|
+
RSpec::Core::RakeTask.new
|
7
|
+
|
8
|
+
require_relative "lib/google-ssl-cert"
|
9
|
+
require "cli_markdown"
|
10
|
+
desc "Generates cli reference docs as markdown"
|
11
|
+
task :docs do
|
12
|
+
mkdir_p "docs/_includes"
|
13
|
+
CliMarkdown::Creator.create_all(cli_class: GoogleSslCert::CLI, cli_name: "google-ssl-cert")
|
14
|
+
end
|
data/exe/google-ssl-cert
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Trap ^C
|
4
|
+
Signal.trap("INT") {
|
5
|
+
puts "\nCtrl-C detected. Exiting..."
|
6
|
+
sleep 0.1
|
7
|
+
exit
|
8
|
+
}
|
9
|
+
|
10
|
+
$:.unshift(File.expand_path("../../lib", __FILE__))
|
11
|
+
require "google-ssl-cert"
|
12
|
+
require "google_ssl_cert/cli"
|
13
|
+
|
14
|
+
GoogleSslCert::CLI.start(ARGV)
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "google_ssl_cert/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "google-ssl-cert"
|
8
|
+
spec.version = GoogleSslCert::VERSION
|
9
|
+
spec.authors = ["Tung Nguyen"]
|
10
|
+
spec.email = ["tongueroo@gmail.com"]
|
11
|
+
spec.summary = "Google SSL Cert Tool"
|
12
|
+
spec.homepage = "https://github.com/boltopspro/google-ssl-cert"
|
13
|
+
spec.license = "Apache-2.0"
|
14
|
+
|
15
|
+
spec.files = File.directory?('.git') ? `git ls-files`.split($/) : Dir.glob("**/*")
|
16
|
+
spec.bindir = "exe"
|
17
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "activesupport"
|
22
|
+
spec.add_dependency "google-cloud-compute-v1"
|
23
|
+
spec.add_dependency "google-cloud-resource_manager"
|
24
|
+
spec.add_dependency "google-cloud-secret_manager"
|
25
|
+
spec.add_dependency "memoist"
|
26
|
+
spec.add_dependency "rainbow"
|
27
|
+
spec.add_dependency "thor"
|
28
|
+
spec.add_dependency "zeitwerk"
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler"
|
31
|
+
spec.add_development_dependency "byebug"
|
32
|
+
spec.add_development_dependency "cli_markdown"
|
33
|
+
spec.add_development_dependency "rake"
|
34
|
+
spec.add_development_dependency "rspec"
|
35
|
+
|
36
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
37
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
38
|
+
if spec.respond_to?(:metadata)
|
39
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
40
|
+
else
|
41
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require_relative "google_ssl_cert"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "zeitwerk"
|
2
|
+
|
3
|
+
module GoogleSslCert
|
4
|
+
class Autoloader
|
5
|
+
class Inflector < Zeitwerk::Inflector
|
6
|
+
def camelize(basename, _abspath)
|
7
|
+
map = { cli: "CLI", version: "VERSION" }
|
8
|
+
map[basename.to_sym] || super
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def setup
|
14
|
+
loader = Zeitwerk::Loader.new
|
15
|
+
loader.inflector = Inflector.new
|
16
|
+
loader.push_dir(File.dirname(__dir__)) # lib
|
17
|
+
loader.ignore("#{File.dirname(__dir__)}/google-ssl-cert.rb")
|
18
|
+
loader.setup
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module GoogleSslCert
|
2
|
+
class Cert < Base
|
3
|
+
extend Memoist
|
4
|
+
|
5
|
+
def initialize(*)
|
6
|
+
super
|
7
|
+
@cert_name = @options[:cert_name]
|
8
|
+
@private_key = private_key
|
9
|
+
@certificate = certificate
|
10
|
+
end
|
11
|
+
|
12
|
+
def create
|
13
|
+
validate!
|
14
|
+
region = ENV['GOOGLE_REGION']
|
15
|
+
ssl_certificate_resource = {
|
16
|
+
name: @cert_name,
|
17
|
+
private_key: IO.read(@private_key),
|
18
|
+
certificate: IO.read(@certificate),
|
19
|
+
}
|
20
|
+
|
21
|
+
if global?
|
22
|
+
ssl_certificates.insert(
|
23
|
+
project: ENV['GOOGLE_PROJECT'],
|
24
|
+
ssl_certificate_resource: ssl_certificate_resource,
|
25
|
+
)
|
26
|
+
logger.info "Global cert created: #{@cert_name}"
|
27
|
+
else
|
28
|
+
region_ssl_certificates.insert(
|
29
|
+
project: ENV['GOOGLE_PROJECT'],
|
30
|
+
region: region,
|
31
|
+
ssl_certificate_resource: ssl_certificate_resource,
|
32
|
+
)
|
33
|
+
logger.info "Region cert created: #{@cert_name} in region: #{region}"
|
34
|
+
end
|
35
|
+
rescue Google::Cloud::AlreadyExistsError => e
|
36
|
+
logger.error "#{e.class}: #{e.message}"
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
def private_key
|
41
|
+
find_file(private_keys)
|
42
|
+
end
|
43
|
+
|
44
|
+
def private_keys
|
45
|
+
[@options[:private_key], "private.key", "server.key", "key.pem"].compact
|
46
|
+
end
|
47
|
+
|
48
|
+
# signed cert
|
49
|
+
def certificate
|
50
|
+
find_file(certificates)
|
51
|
+
end
|
52
|
+
|
53
|
+
def certificates
|
54
|
+
[@options[:certificate], "certificate.crt", "server.crt", "cert.pem"].compact
|
55
|
+
end
|
56
|
+
|
57
|
+
def find_file(*paths)
|
58
|
+
paths.flatten.find do |path|
|
59
|
+
File.exist?(path)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def validate!
|
64
|
+
errors = []
|
65
|
+
unless @private_key
|
66
|
+
errors << "ERROR: None of the private keys could be found: #{private_keys.join(' ')}"
|
67
|
+
end
|
68
|
+
unless @certificate
|
69
|
+
errors << "ERROR: None of the certificates could be found: #{certificates.join(' ')}"
|
70
|
+
end
|
71
|
+
unless errors.empty?
|
72
|
+
logger.error errors.join("\n")
|
73
|
+
logger.error <<~EOL
|
74
|
+
|
75
|
+
Are you sure that:
|
76
|
+
|
77
|
+
* You're in the right directory with the cert files?
|
78
|
+
* Or can specify the path to the cert files with options:
|
79
|
+
* --certificate and --private-key
|
80
|
+
EOL
|
81
|
+
exit 1
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
class GoogleSslCert::CLI
|
2
|
+
class Create < Base
|
3
|
+
def initialize(options={})
|
4
|
+
super
|
5
|
+
@cert_name = GoogleSslCert::Name.new(@options).generate
|
6
|
+
end
|
7
|
+
|
8
|
+
def run
|
9
|
+
validate!
|
10
|
+
create_cert
|
11
|
+
save_secret if @options[:save_secret]
|
12
|
+
end
|
13
|
+
|
14
|
+
# Google API Docs:
|
15
|
+
# https://cloud.google.com/compute/docs/reference/rest/v1/sslCertificates/insert
|
16
|
+
def create_cert
|
17
|
+
GoogleSslCert::Cert.new(@options.merge(cert_name: @cert_name)).create
|
18
|
+
end
|
19
|
+
|
20
|
+
# The secret name is expected to be static/predictable
|
21
|
+
# The secret value is the changed/updated google ssl cert
|
22
|
+
#
|
23
|
+
# Example:
|
24
|
+
# secret_name = demo_ssl-cert-name
|
25
|
+
# secret_value = google-ssl-cert-20211013231005
|
26
|
+
#
|
27
|
+
# gcloud compute ssl-certificates list
|
28
|
+
# NAME TYPE CREATION_TIMESTAMP EXPIRE_TIME MANAGED_STATUS
|
29
|
+
# google-ssl-cert-20211013231005 SELF_MANAGED 2021-10-13T16:10:05.795-07:00 2022-10-12T17:22:01.000-07:00
|
30
|
+
# gcloud secrets list
|
31
|
+
# NAME CREATED REPLICATION_POLICY LOCATIONS
|
32
|
+
# demo_ssl-cert-name 2021-10-13T23:10:06 automatic
|
33
|
+
#
|
34
|
+
def save_secret
|
35
|
+
secret_name = @options[:secret_name]
|
36
|
+
secret_value = @cert_name # @cert_name the value because it will be referenced. the @cert_name or 'key' will be the same
|
37
|
+
secret.save(secret_name, secret_value)
|
38
|
+
end
|
39
|
+
|
40
|
+
def secret
|
41
|
+
GoogleSslCert::Secret.new(@options)
|
42
|
+
end
|
43
|
+
memoize :secret
|
44
|
+
|
45
|
+
private
|
46
|
+
def validate!
|
47
|
+
errors = []
|
48
|
+
unless ENV['GOOGLE_APPLICATION_CREDENTIALS']
|
49
|
+
errors << "ERROR: The GOOGLE_APPLICATION_CREDENTIALS env var must be set."
|
50
|
+
end
|
51
|
+
unless ENV['GOOGLE_PROJECT']
|
52
|
+
errors << "ERROR: The GOOGLE_PROJECT env var must be set."
|
53
|
+
end
|
54
|
+
if !ENV['GOOGLE_REGION'] and !global?
|
55
|
+
errors << "ERROR: The GOOGLE_REGION env var must be when creating a region cert."
|
56
|
+
end
|
57
|
+
unless errors.empty?
|
58
|
+
logger.error errors.join("\n")
|
59
|
+
exit 1
|
60
|
+
end
|
61
|
+
|
62
|
+
# Call here so validation happens at the beginning with the rest of validation
|
63
|
+
# want command to exit early and not even create a google ssl cert
|
64
|
+
secret.validate!
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
## Examples
|
2
|
+
|
3
|
+
google-ssl-cert completion
|
4
|
+
|
5
|
+
Prints words for TAB auto-completion.
|
6
|
+
|
7
|
+
google-ssl-cert completion
|
8
|
+
google-ssl-cert completion hello
|
9
|
+
google-ssl-cert completion hello name
|
10
|
+
|
11
|
+
To enable, TAB auto-completion add the following to your profile:
|
12
|
+
|
13
|
+
eval $(google-ssl-cert completion_script)
|
14
|
+
|
15
|
+
Auto-completion example usage:
|
16
|
+
|
17
|
+
google-ssl-cert [TAB]
|
18
|
+
google-ssl-cert hello [TAB]
|
19
|
+
google-ssl-cert hello name [TAB]
|
20
|
+
google-ssl-cert hello name --[TAB]
|
@@ -0,0 +1,31 @@
|
|
1
|
+
## Examples
|
2
|
+
|
3
|
+
When no cert name is provided, one will be generated for you:
|
4
|
+
|
5
|
+
$ google-ssl-cert create
|
6
|
+
Google SSL Cert Created: google-ssl-cert-20211013203211
|
7
|
+
|
8
|
+
Check that cert was created on google cloud:
|
9
|
+
|
10
|
+
$ gcloud compute ssl-certificates list
|
11
|
+
NAME TYPE CREATION_TIMESTAMP EXPIRE_TIME MANAGED_STATUS
|
12
|
+
google-ssl-cert-20211013203211 SELF_MANAGED 2021-10-13T13:16:28.304-07:00 2022-10-12T17:22:01.000-07:00
|
13
|
+
|
14
|
+
You can also specify the cert name:
|
15
|
+
|
16
|
+
$ google-ssl-cert create --cert-name google-ssl-cert-1 --no-timestamp
|
17
|
+
Google SSL Cert Created: google-ssl-cert-1
|
18
|
+
|
19
|
+
Check that cert was created on google cloud:
|
20
|
+
|
21
|
+
$ gcloud compute ssl-certificates list
|
22
|
+
NAME TYPE CREATION_TIMESTAMP EXPIRE_TIME MANAGED_STATUS
|
23
|
+
google-ssl-cert-1 SELF_MANAGED 2021-10-13T13:17:04.192-07:00 2022-10-12T17:22:01.000-07:00
|
24
|
+
|
25
|
+
## More Examples
|
26
|
+
|
27
|
+
google-ssl-cert create
|
28
|
+
google-ssl-cert create --private-key /path/to/key/server.key
|
29
|
+
google-ssl-cert create --certificate /path/to/certificate/server.crt
|
30
|
+
google-ssl-cert create --no-save-secret
|
31
|
+
google-ssl-cert create --secret-name secret-name
|
@@ -0,0 +1,30 @@
|
|
1
|
+
Prune only deletes google ssl cert resources if the cert name has a timestamp at the end with 14 digits as the format. Example:
|
2
|
+
|
3
|
+
google-ssl-cert-20211014221403
|
4
|
+
|
5
|
+
## Examples
|
6
|
+
|
7
|
+
Lets say there are 3 certs:
|
8
|
+
|
9
|
+
$ gcloud compute ssl-certificates list
|
10
|
+
NAME TYPE CREATION_TIMESTAMP EXPIRE_TIME MANAGED_STATUS
|
11
|
+
google-ssl-cert-20211014221406 SELF_MANAGED 2021-10-14T15:14:06.592-07:00 2022-01-12T15:59:59.000-08:00
|
12
|
+
google-ssl-cert-20211014221546 SELF_MANAGED 2021-10-14T15:15:46.400-07:00 2022-01-12T15:59:59.000-08:00
|
13
|
+
google-ssl-cert-20211014221549 SELF_MANAGED 2021-10-14T15:15:49.624-07:00 2022-01-12T15:59:59.000-08:00
|
14
|
+
|
15
|
+
Running prune will delete the 2 oldest certs.
|
16
|
+
|
17
|
+
$ google-ssl-cert prune
|
18
|
+
Will delete the following global certs:
|
19
|
+
google-ssl-cert-20211014221406
|
20
|
+
google-ssl-cert-20211014221546
|
21
|
+
Are you sure? (y/N) y
|
22
|
+
Deleted global cert: google-ssl-cert-20211014221406
|
23
|
+
Deleted global cert: google-ssl-cert-20211014221546
|
24
|
+
|
25
|
+
Confirm that only 1 cert is kept.
|
26
|
+
|
27
|
+
$ gcloud compute ssl-certificates list
|
28
|
+
NAME TYPE CREATION_TIMESTAMP EXPIRE_TIME MANAGED_STATUS
|
29
|
+
google-ssl-cert-20211014221549 SELF_MANAGED 2021-10-14T15:15:49.624-07:00 2022-01-12T15:59:59.000-08:00
|
30
|
+
$
|