Commit cb21560b authored by Dylan Griffith's avatar Dylan Griffith

Ensure CA + Tiller cert never expire and Helm client cert expires quickly

parent 039a8ebd
...@@ -31,8 +31,7 @@ module Clusters ...@@ -31,8 +31,7 @@ module Clusters
end end
def issue_cert def issue_cert
ca_cert_obj ca_cert_obj.issue
.issue
end end
def set_initial_status def set_initial_status
...@@ -42,7 +41,8 @@ module Clusters ...@@ -42,7 +41,8 @@ module Clusters
end end
def install_command def install_command
tiller_cert = issue_cert tiller_cert = ca_cert_obj.issue(expires_in: Gitlab::Kubernetes::Helm::Certificate::INFINITE_EXPIRY)
Gitlab::Kubernetes::Helm::InitCommand.new( Gitlab::Kubernetes::Helm::InitCommand.new(
name: name, name: name,
files: { files: {
......
...@@ -2,6 +2,9 @@ module Gitlab ...@@ -2,6 +2,9 @@ module Gitlab
module Kubernetes module Kubernetes
module Helm module Helm
class Certificate class Certificate
INFINITE_EXPIRY = 1000.years
SHORT_EXPIRY = 30.minutes
attr_reader :key, :cert attr_reader :key, :cert
def key_string def key_string
...@@ -27,7 +30,7 @@ module Gitlab ...@@ -27,7 +30,7 @@ module Gitlab
cert = OpenSSL::X509::Certificate.new cert = OpenSSL::X509::Certificate.new
cert.subject = cert.issuer = OpenSSL::X509::Name.parse(subject) cert.subject = cert.issuer = OpenSSL::X509::Name.parse(subject)
cert.not_before = Time.now cert.not_before = Time.now
cert.not_after = Time.now + 365 * 24 * 60 * 60 cert.not_after = INFINITE_EXPIRY.from_now
cert.public_key = public_key cert.public_key = public_key
cert.serial = 0x0 cert.serial = 0x0
cert.version = 2 cert.version = 2
...@@ -44,7 +47,7 @@ module Gitlab ...@@ -44,7 +47,7 @@ module Gitlab
new(key, cert) new(key, cert)
end end
def issue def issue(expires_in: SHORT_EXPIRY)
key = OpenSSL::PKey::RSA.new(4096) key = OpenSSL::PKey::RSA.new(4096)
public_key = key.public_key public_key = key.public_key
...@@ -54,7 +57,7 @@ module Gitlab ...@@ -54,7 +57,7 @@ module Gitlab
cert.subject = OpenSSL::X509::Name.parse(subject) cert.subject = OpenSSL::X509::Name.parse(subject)
cert.issuer = self.cert.subject cert.issuer = self.cert.subject
cert.not_before = Time.now cert.not_before = Time.now
cert.not_after = Time.now + 365 * 24 * 60 * 60 cert.not_after = expires_in.from_now
cert.public_key = public_key cert.public_key = public_key
cert.serial = 0x0 cert.serial = 0x0
cert.version = 2 cert.version = 2
......
require 'spec_helper'
describe Gitlab::Kubernetes::Helm::Certificate do
describe '.generate_root' do
subject { described_class.generate_root }
it 'should generate a root CA that expires a long way in the future' do
expect(subject.cert.not_after).to be > 999.years.from_now
end
end
describe '#issue' do
subject { described_class.generate_root.issue }
it 'should generate a cert that expires soon' do
expect(subject.cert.not_after).to be < 60.minutes.from_now
end
context 'passing in INFINITE_EXPIRY' do
subject { described_class.generate_root.issue(expires_in: described_class::INFINITE_EXPIRY) }
it 'should generate a cert that expires a long way in the future' do
expect(subject.cert.not_after).to be > 999.years.from_now
end
end
end
end
...@@ -43,6 +43,9 @@ describe Clusters::Applications::Helm do ...@@ -43,6 +43,9 @@ describe Clusters::Applications::Helm do
expect(subject.files[:'cert.pem']).to be_present expect(subject.files[:'cert.pem']).to be_present
expect(subject.files[:'key.pem']).to be_present expect(subject.files[:'key.pem']).to be_present
cert = OpenSSL::X509::Certificate.new(subject.files[:'cert.pem'])
expect(cert.not_after).to be > 999.years.from_now
end end
end end
end end
...@@ -108,6 +108,9 @@ describe Clusters::Applications::Ingress do ...@@ -108,6 +108,9 @@ describe Clusters::Applications::Ingress do
expect(subject[:'cert.pem']).to be_present expect(subject[:'cert.pem']).to be_present
expect(subject[:'key.pem']).to be_present expect(subject[:'key.pem']).to be_present
cert = OpenSSL::X509::Certificate.new(subject[:'cert.pem'])
expect(cert.not_after).to be < 60.minutes.from_now
end end
end end
end end
...@@ -53,6 +53,9 @@ describe Clusters::Applications::Jupyter do ...@@ -53,6 +53,9 @@ describe Clusters::Applications::Jupyter do
expect(subject[:'cert.pem']).to be_present expect(subject[:'cert.pem']).to be_present
expect(subject[:'key.pem']).to be_present expect(subject[:'key.pem']).to be_present
cert = OpenSSL::X509::Certificate.new(subject[:'cert.pem'])
expect(cert.not_after).to be < 60.minutes.from_now
end end
context 'when the helm application does not have a ca_cert' do context 'when the helm application does not have a ca_cert' do
......
...@@ -168,6 +168,9 @@ describe Clusters::Applications::Prometheus do ...@@ -168,6 +168,9 @@ describe Clusters::Applications::Prometheus do
expect(subject[:'cert.pem']).to be_present expect(subject[:'cert.pem']).to be_present
expect(subject[:'key.pem']).to be_present expect(subject[:'key.pem']).to be_present
cert = OpenSSL::X509::Certificate.new(subject[:'cert.pem'])
expect(cert.not_after).to be < 60.minutes.from_now
end end
context 'when the helm application does not have a ca_cert' do context 'when the helm application does not have a ca_cert' do
......
...@@ -49,6 +49,9 @@ describe Clusters::Applications::Runner do ...@@ -49,6 +49,9 @@ describe Clusters::Applications::Runner do
expect(subject[:'cert.pem']).to be_present expect(subject[:'cert.pem']).to be_present
expect(subject[:'key.pem']).to be_present expect(subject[:'key.pem']).to be_present
cert = OpenSSL::X509::Certificate.new(subject[:'cert.pem'])
expect(cert.not_after).to be < 60.minutes.from_now
end end
context 'when the helm application does not have a ca_cert' do context 'when the helm application does not have a ca_cert' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment