-
Notifications
You must be signed in to change notification settings - Fork 63
fix/ota-2421/disallow downloading non-OSTree binaries #1282
fix/ota-2421/disallow downloading non-OSTree binaries #1282
Conversation
6e64eb4
to
c9e5607
Compare
Codecov Report
@@ Coverage Diff @@
## master #1282 +/- ##
==========================================
- Coverage 79.05% 79.02% -0.04%
==========================================
Files 178 178
Lines 10475 10482 +7
==========================================
+ Hits 8281 8283 +2
- Misses 2194 2199 +5
Continue to review full report at Codecov.
|
if (!target.IsOstree() && | ||
(config.pacman.type == PackageManager::kOstree || config.pacman.type == PackageManager::kOstreeDockerApp)) { | ||
LOG_ERROR << "Cannot install a non-OSTree package on an OSTree system"; | ||
sendEvent<event::InstallTargetComplete>(primary_ecu_serial, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO, I'd make this code more generic and extendable, i.e. instead of comparing a specific target type with specific package manager types do something like the following:
if (target.type != config.pacman.type)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO, I'd make this code more generic and extendable
I like the idea but currently we don't really have a good way to support that. The only type that we can recognize in the Target metadata is OSTree, so for now, that's the only one worth checking.
In other cases when
is_new = false
the eventevent::InstallTargetComplete
is not sent, I am just wondering if it's correct place to do it here.
I agree, instead of sending that event, we should just set last_exception
and return false. The log message is fine, though.
if (!target.IsOstree() && | ||
(config.pacman.type == PackageManager::kOstree || config.pacman.type == PackageManager::kOstreeDockerApp)) { | ||
LOG_ERROR << "Cannot install a non-OSTree package on an OSTree system"; | ||
sendEvent<event::InstallTargetComplete>(primary_ecu_serial, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In other cases when is_new = false
the event event::InstallTargetComplete
is not sent, I am just wondering if it's correct place to do it here.
The logic looks about right, but we need a test for this. It will need to use the OSTree package manager, but it won't need to actually use it since the update will already fail at the check for updates. |
487028c
to
4d52a04
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will need to use the OSTree package manager,
https://github.com/advancedtelematic/ostree-basic-pkg
This tool?
if (!target.IsOstree() && | ||
(config.pacman.type == PackageManager::kOstree || config.pacman.type == PackageManager::kOstreeDockerApp)) { | ||
LOG_ERROR << "Cannot install a non-OSTree package on an OSTree system"; | ||
last_exception = Uptane::InvalidMetadata(target.filename(), "", "Non-OSTree package"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is ‘InvalidMetadata’ the proper exception type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not a bad choice, but since it's usually used for problems in parsing the metadata, maybe we should find something else. Nothing else looks better, though, so how about making a new exception? InvalidTarget
perhaps?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure,I was considering making a new one too. Thanks!
I was referring to https://github.com/advancedtelematic/aktualizr/blob/master/src/libaktualizr/package_manager/ostreemanager.h. You may need to use this script to generate an OSTree sysroot for the test: https://github.com/advancedtelematic/aktualizr/blob/master/scripts/make_ostree_sysroot.sh. For an example of how to use that, see https://github.com/advancedtelematic/aktualizr/blob/master/src/libaktualizr/package_manager/CMakeLists.txt#L36 and https://github.com/advancedtelematic/aktualizr/blob/master/src/libaktualizr/package_manager/ostreemanager_test.cc. |
ff60411
to
8f1eed4
Compare
Totally raw! Maybe I should use json to make a fake target instead of using aktualizr tool to generate one? And the 'generate ostree sysroot' part also looks not good. |
Nah, using aktualizr-repo is perfect. That looks fine to me.
I also think that part is a bit overcomplicated. You don't actually need to mock the sysroot and all that, or at least I don't think so. It looks like you modeled that part off of the |
fe3430c
to
5a24aab
Compare
5e7dcca
to
4ad2074
Compare
If you rebase on latest master, you should be able to get the Travis timeout resolved. I ran your branch locally and noticed this in the output: |
Trapped in git chaos...I'll figure the way out tomorrow.
I might should start with this issue first. |
4c74ecf
to
9d1aa78
Compare
4b3da79
to
3db232a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few minor comments. As far as why the test is failing... perhaps my assumptions about how easy it would be to fake an ostree sysroot for this purpose was wrong. I'm not sure i understand why ostree is complaining, though. Have you been able to trace it with gdb?
|
||
#include <ostree.h> | ||
|
||
boost::filesystem::path aktualizr_repo_path; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable doesn't need to be global.
#include "storage/sqlstorage.h" | ||
#include "test_utils.h" | ||
|
||
#include <ostree.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this include shouldn't be necessary anymore.
#include <future> | ||
#include <iostream> | ||
#include <string> | ||
#include <thread> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are all of these includes necessary as well?
boost::trim_if(new_rev, boost::is_any_of(" \t\r\n")); | ||
LOG_INFO << "DEST: " << new_rev; | ||
|
||
Process akt_repo(aktualizr_repo_path.string()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not at all critical, but I recommend renaming the "aktualizr_repo" references here to "uptane_generator". (I also changed every "akt_repo" to just "gen".)
No, I was trying to use the whole mock the sysroot and unptane-generate part from aktuarlizr_fullostree_test. But aktuarlizr_fullostree_test will fail locally too. |
3db232a
to
702c9aa
Compare
6ae1ed9
to
ba061fa
Compare
The code looks good but can we change the commit messages before merging? |
96ddefb
to
784fd81
Compare
Added unit test Fixed bugs that failed the test Removed unnecessary ostree bits Signed-off-by: Zee314159 <252806294@qq.com>
784fd81
to
a2ae26d
Compare
Draft code, just some thoughts to address this issue.