Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
slapos.toolbox
Commits
62978dd3
Commit
62978dd3
authored
Mar 02, 2023
by
Łukasz Nowak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
check_certificate: Support certificate only configuration
parent
de8c7232
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
19 deletions
+80
-19
slapos/promise/plugin/check_certificate.py
slapos/promise/plugin/check_certificate.py
+24
-19
slapos/test/promise/plugin/test_check_certificate.py
slapos/test/promise/plugin/test_check_certificate.py
+56
-0
No files found.
slapos/promise/plugin/check_certificate.py
View file @
62978dd3
...
@@ -16,7 +16,7 @@ class RunPromise(GenericPromise):
...
@@ -16,7 +16,7 @@ class RunPromise(GenericPromise):
"""
"""
certificate_file
=
self
.
getConfig
(
'certificate'
)
certificate_file
=
self
.
getConfig
(
'certificate'
)
key_file
=
self
.
getConfig
(
'key'
)
key_file
=
self
.
getConfig
(
'key'
,
None
)
try
:
try
:
certificate_expiration_days
=
int
(
certificate_expiration_days
=
int
(
...
@@ -36,6 +36,14 @@ class RunPromise(GenericPromise):
...
@@ -36,6 +36,14 @@ class RunPromise(GenericPromise):
certificate_file
,
e
))
certificate_file
,
e
))
return
return
if
certificate
.
not_valid_after
-
datetime
.
timedelta
(
days
=
certificate_expiration_days
)
<
datetime
.
datetime
.
utcnow
():
self
.
logger
.
error
(
'ERROR Certificate %r will expire in less than %s days'
%
(
certificate_file
,
certificate_expiration_days
))
return
if
key_file
is
not
None
:
try
:
try
:
with
open
(
key_file
,
'r'
)
as
fh
:
with
open
(
key_file
,
'r'
)
as
fh
:
key
=
serialization
.
load_pem_private_key
(
key
=
serialization
.
load_pem_private_key
(
...
@@ -52,12 +60,9 @@ class RunPromise(GenericPromise):
...
@@ -52,12 +60,9 @@ class RunPromise(GenericPromise):
certificate_file
,
key_file
))
certificate_file
,
key_file
))
return
return
if
certificate
.
not_valid_after
-
datetime
.
timedelta
(
if
key_file
:
days
=
certificate_expiration_days
)
<
datetime
.
datetime
.
utcnow
():
self
.
logger
.
error
(
'ERROR Certificate %r will expire in less than %s days'
%
(
certificate_file
,
certificate_expiration_days
))
return
self
.
logger
.
info
(
self
.
logger
.
info
(
'OK Certificate %r and key %r are ok'
%
(
certificate_file
,
key_file
))
'OK Certificate %r and key %r are ok'
%
(
certificate_file
,
key_file
))
else
:
self
.
logger
.
info
(
'OK Certificate %r is ok, no key provided'
%
(
certificate_file
,))
slapos/test/promise/plugin/test_check_certificate.py
View file @
62978dd3
...
@@ -146,6 +146,19 @@ class TestCheckCertificate(TestPromisePluginMixin):
...
@@ -146,6 +146,19 @@ class TestCheckCertificate(TestPromisePluginMixin):
self
.
certificate_path
,
self
.
key_path
)
self
.
certificate_path
,
self
.
key_path
)
)
)
def
test_no_key_provided
(
self
):
self
.
createKeyCertificate
()
self
.
writePromise
({
'certificate'
:
self
.
certificate_path
,
})
self
.
configureLauncher
()
self
.
launcher
.
run
()
self
.
assertPassedMessage
(
self
.
getPromiseResult
(
self
.
promise_name
),
"OK Certificate '%s' is ok, no key provided"
%
(
self
.
certificate_path
,)
)
def
test_no_key
(
self
):
def
test_no_key
(
self
):
self
.
createKeyCertificate
()
self
.
createKeyCertificate
()
nokey_path
=
os
.
path
.
join
(
self
.
tempdir
,
'nokey.pem'
)
nokey_path
=
os
.
path
.
join
(
self
.
tempdir
,
'nokey.pem'
)
...
@@ -206,6 +219,20 @@ class TestCheckCertificate(TestPromisePluginMixin):
...
@@ -206,6 +219,20 @@ class TestCheckCertificate(TestPromisePluginMixin):
self
.
certificate_path
,)
self
.
certificate_path
,)
)
)
def
test_expires_no_key
(
self
):
self
.
createKeyCertificate
(
days
=
5
)
self
.
writePromise
({
'certificate'
:
self
.
certificate_path
,
})
self
.
configureLauncher
()
with
self
.
assertRaises
(
PromiseError
):
self
.
launcher
.
run
()
self
.
assertFailedMessage
(
self
.
getPromiseResult
(
self
.
promise_name
),
"ERROR Certificate '%s' will expire in less than 15 days"
%
(
self
.
certificate_path
,)
)
def
test_expires_custom
(
self
):
def
test_expires_custom
(
self
):
self
.
createKeyCertificate
(
days
=
19
)
self
.
createKeyCertificate
(
days
=
19
)
self
.
writePromise
({
self
.
writePromise
({
...
@@ -222,6 +249,21 @@ class TestCheckCertificate(TestPromisePluginMixin):
...
@@ -222,6 +249,21 @@ class TestCheckCertificate(TestPromisePluginMixin):
self
.
certificate_path
,)
self
.
certificate_path
,)
)
)
def
test_expires_custom_no_key
(
self
):
self
.
createKeyCertificate
(
days
=
19
)
self
.
writePromise
({
'certificate'
:
self
.
certificate_path
,
'certificate-expiration-days'
:
'20'
})
self
.
configureLauncher
()
with
self
.
assertRaises
(
PromiseError
):
self
.
launcher
.
run
()
self
.
assertFailedMessage
(
self
.
getPromiseResult
(
self
.
promise_name
),
"ERROR Certificate '%s' will expire in less than 20 days"
%
(
self
.
certificate_path
,)
)
def
test_expires_bad_value
(
self
):
def
test_expires_bad_value
(
self
):
self
.
createKeyCertificate
(
days
=
14
)
self
.
createKeyCertificate
(
days
=
14
)
self
.
writePromise
({
self
.
writePromise
({
...
@@ -237,6 +279,20 @@ class TestCheckCertificate(TestPromisePluginMixin):
...
@@ -237,6 +279,20 @@ class TestCheckCertificate(TestPromisePluginMixin):
"ERROR certificate-expiration-days is wrong: 'bad'"
"ERROR certificate-expiration-days is wrong: 'bad'"
)
)
def
test_expires_bad_value_no_key
(
self
):
self
.
createKeyCertificate
(
days
=
14
)
self
.
writePromise
({
'certificate'
:
self
.
certificate_path
,
'certificate-expiration-days'
:
'bad'
})
self
.
configureLauncher
()
with
self
.
assertRaises
(
PromiseError
):
self
.
launcher
.
run
()
self
.
assertFailedMessage
(
self
.
getPromiseResult
(
self
.
promise_name
),
"ERROR certificate-expiration-days is wrong: 'bad'"
)
class
TestCheckCertificateSameFile
(
TestCheckCertificate
):
class
TestCheckCertificateSameFile
(
TestCheckCertificate
):
same_file
=
True
same_file
=
True
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment