-
Notifications
You must be signed in to change notification settings - Fork 169
Description
This issue tracks the different things that can be done to improve the code quality. If you want to fix some one of the issues please comment on this issue, so I can update it.
pylint
We currently have a large list of warnings that we ignore. Those have to be reviewed and removed where possible.
Current warnings:
- W1509: Initial round of pylint fixes #932
- C0103
- C0115:
- C0116:
- C0201: Initial round of pylint fixes #932
- C0209: Initial round of pylint fixes #932
- C0301
- C0302
- C0111
- W0102: pylint: Fix issues related to W0102 dangerous-default-value #939
- W0511
- W0602: pylint: Fix issues related to W0602 global-variable-not-assigned #946
- W0603
- W0703
- W1201: Use lazy string formatting when logging (#535) #914, Initial round of pylint fixes #932
- W1203: Initial round of pylint fixes #932
- E1120: Initial round of pylint fixes #932
- R0801
- R0902
- R0903
- R0904
- R0912
- R0913
- R0914
- R0915
- R0201: pylint: Fix issues related to R0201 #938
- R0911
- R1729: Initial round of pylint fixes #932
- R1732: pylint: Fix R1732 consider-using-with #937
See: https://github.com/keylime/keylime/blob/master/pylintrc
flake8 integration
Flake8 does catches some errors that pylint does not and vice versa. We should integrate it into our style checks.
List of potential useful plugins:
- flake8-bugbear
- flake8-comprehensions
- flake8-simplify
- flake8-builtins
MyPy
We currently not enforce types. This makes it harder to reason about some functions and allows for subtile errors.
A strict mypy configuration currently returns about 2000 warnings that can probably removed by going through Keylime and adding type annotations.
Configuration used:
[mypy]
plugins = sqlmypy
strict = True
follow_imports = silent
ignore_missing_imports = True
DONE
pyright
Static code analysis reports several typing issues in most Python files. Investigate if we should integrate it.
DONE
LGTM, semgrep and Bandit
There are multiple tools for analyzing the AST of the Python code and finding common security and code quality issues.
We should at least integrate one of them into our CI.
Fuzzing methods that take user controlled input with something like https://github.com/google/atheris can also be useful (mentioned by @kkaarreell).
TODOs
- Integrate LGTM/GraphQL into the CI: ci: add CodeQL analysis #975
- have a look at the found issues: https://lgtm.com/projects/g/keylime/keylime/alerts/?mode=list
- Look what Bandit can do for us
- Look at fuzzing
Converting dicts to classes
For the agent event loop we use a dict to store all the necessary state of an agent. This is not ideal because it is hard to reason about what is actually in this dict. We should convert this dict to a class that holds all the required state. For this class we can then also provide conversion functions from and to the ORM class.
WIP partly by #1523
Unit tests
Most of the older code in Keylime is only covered by the restful test or the e2e tests. We should add unit tests for this code and refactor it to make it more testable where necessary.
New code should be ideally only added with unit tests.
Automatic code formatting
The current code has no clear style guidelines. We should try to enforce a style with automated tooling.
TODOs:
- Reformat code with black and add it to the CI pipeline
- Add isort to CI
- Add pre-commit hooks to make it easier to use
Add pre-commit hook to enforce code style with isort and black #982
Removal of config.REQUIRE_ROOT
With #900 merged this flag should be fully removed.
Removal of vTPM code
Originally Keylime supported vTPMs a feature from Xen. This is no longer the case and the deep quote feature is not implemented in swtpm. Most of the code is already removed but there is still some broken skeleton code in there which should be removed.
I think we can move the issue on how to trust the underlying hypervisor out of Keylime and into the platform that manages the hypervisor (e.g. OpenStack).
DONE
Removal of STUB TPM logic
There are some parts of Keylime that have code for canned values. There seems to be no documentation on how to use that code and newer parts of Keylime do not implement it. I think this code can be removed.
DONE
Removing dependency of the TPM abstraction for the registrar and verifier
Both components initialize an abstract TPM without actually using a TPM. The registrar uses a software implementation of TPM_MakeCredential
and the verifier uses tpm2_checkquote
and tpm2_eventlog
. keylime/enhancements#59 already proposes to move the quote verification code into a separate module which is more flexible and easier to test.
Once the rust agent is the official one, the entire TPM abstraction code could then be removed.
DONE with the exception of tpm2_eventlog, python only parser is being worked on