Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Feat/ota 2666/garage tools mutual tls #1243

Merged
merged 9 commits into from
Jul 29, 2019

Conversation

pattivacek
Copy link
Collaborator

@pattivacek pattivacek commented Jun 25, 2019

Short version: it works! Well, it works as far as the unit tests are concerned. The certs were generated by the Makefile that @simao provided and @koshelev, @jochenschneider, and @zabbal consulted with.

Long version: This still hasn't been tested with any real server implementation. Also, this PR currently violates my preference to keep binaries out of git. I was able to add some scripts to generate the zip files based on the p12, but that could be taken further to start from just the certs, or we could go even further and basically incorporate Simao's Makefile. That would be cool, actually. Also, it's annoying that in the current branch, I delete the old zips, add new ones, delete them, and add p12s. It should probably be refactored/rebased to just delete the old zips and add the p12s directly. I'm not fixing it right now in case there are other changes based on code review or testing with a real server.

Also: there should be more unit tests for various the combinations of client_auth.p12, api_gateway.url, and treehub.json. We should test that we prefer the p12 and URL if available.

@codecov-io
Copy link

codecov-io commented Jun 26, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@383dfc3). Click here to learn what that means.
The diff coverage is 93.87%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #1243   +/-   ##
=========================================
  Coverage          ?   79.33%           
=========================================
  Files             ?      171           
  Lines             ?    10160           
  Branches          ?        0           
=========================================
  Hits              ?     8060           
  Misses            ?     2100           
  Partials          ?        0
Impacted Files Coverage Δ
src/sota_tools/treehub_server.h 100% <ø> (ø)
src/sota_tools/treehub_server.cc 100% <100%> (ø)
src/libaktualizr/bootstrap/bootstrap.cc 57.77% <100%> (ø)
src/sota_tools/authenticate.cc 73.07% <100%> (ø)
src/libaktualizr/bootstrap/bootstrap.h 100% <100%> (ø)
src/sota_tools/server_credentials.h 76.47% <100%> (ø)
src/sota_tools/server_credentials.cc 94.04% <90%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 383dfc3...85deb96. Read the comment docs.

@lbonn
Copy link
Contributor

lbonn commented Jun 26, 2019

Pushed a trivial fix for the debian testing ci


/* Authenticate with nothing (no auth).
* Parse authentication information from treehub.json.
* Parse images repository URL from a provided archive. */
TEST(authenticate, good_cert_noauth_zip) {
// Authenticates with ssl_noauth_server on port 2443.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a minor nitpicking: would be better to use "tls" instead of "ssl" everywhere to be consistent with kTls and such.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

/* Authenticate with OAuth2.
* Parse authentication information from treehub.json. */
TEST(authenticate, good_zip) {
// Authenticates with the ATS portal to the SaaS instance.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is "the ATS portal", is it connect.ota.here.com ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, that's the normal portal. https://app.atsgarage.com/ is the old portal that surprisingly still works but basically serves the same content.

TreehubServer treehub;
int r = authenticate("", creds, treehub);
int r = authenticate("tests/fake_http_server/server.crt", creds, treehub);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, makes sense to pass "tests/fake_http_server/server.crt" as the test parameter ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, where should it get passed from?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From corrsponding CMakeLists.txt

add_aktualizr_test(NAME SOURCES <> ARGS )

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but, it's really not important, not sure if it's worth bothering

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like that's just moving the hardcoded value to a more obscure place. I'm not sure I see the benefit right now. That said, I'm interested in redoing this logic so that we can generate all the certs and such dynamically, and once that is done, something like what you are suggesting will probably be necessary.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, + for the dynamic certs generation, also using TEST_F/test fixtures/base class is an ideal for sharing the same context across multiple tests.


/* Authenticate with nothing (no auth).
* Parse authentication information from treehub.json.
* Parse images repository URL from a provided archive. */
TEST(authenticate, good_cert_noauth_zip) {
// Authenticates with ssl_noauth_server on port 2443.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this port number 2443 actually hard-coded value or it's a parameter or a configuration variable ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's hardcoded. It probably shouldn't be anymore. I'll look into that.

boost::filesystem::path filepath = "tests/sota_tools/auth_test_noauth_good.zip";
ServerCredentials creds(filepath);
EXPECT_EQ(creds.GetMethod(), AuthMethod::kNone);
TreehubServer treehub;
int r = authenticate("tests/fake_http_server/client.crt", creds, treehub);
int r = authenticate("tests/fake_http_server/server.crt", creds, treehub);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe, makes sense to pass "tests/fake_http_server/server.crt" as the test parameter ?

TreehubServer treehub;
int r = authenticate("", ServerCredentials(filepath), treehub);
int r = authenticate("", creds, treehub);
EXPECT_EQ(0, r);
CurlEasyWrapper curl_handle;
curlEasySetoptWrapper(curl_handle.get(), CURLOPT_VERBOSE, 1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to continue the test control flow if the authentication fails, if not then ASSERT_EQ should serve better here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The EXPECT_EQ shouldn't hurt and it's not like we'll save a huge amount of test time if we fail earlier. We normally use EXPECT for everything unless there's a good reason not to. If there is consensus around changing that norm, I'm open to revising it, though.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, I don't think that there is much practical benefits in it.

method_ = AuthMethod::kTls;
} else if (strcmp(filename, "api_gateway.url") == 0) {
use_api_gateway = true;
ostree_server_ = readArchiveFile(a)->str();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read this like ostree_server and api_gateway are the same entity.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, for backwards compatibility, we have to support the case where there is no API gateway for some period. Going forward, there should always be such a gateway, but if we don't have the URL in the credentials.zip (or there wasn't such a gateway deployed), we still need to be able to talk to treehub directly.

try {
ptree pt;
if (use_api_gateway) {
repo_url_ = ostree_server_;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now, ostree_server becomes repo_url :)

Copy link
Collaborator

@mike-sul mike-sul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would be the most efficient way to figure out design behind this different schema to authentication ?
How can I authenticate at and use the treehub server from a command line by utilizing ostree utility ?

@pattivacek
Copy link
Collaborator Author

What would be the most efficient way to figure out design behind this different schema to authentication ?

Some of the answers can be gleaned from https://github.com/advancedtelematic/aktualizr/blob/master/docs/provisioning-methods-and-credentialszip.adoc. What exactly are you looking for, though? Do you want a sequence diagram or a better explanation of the options?

How can I authenticate at and use the treehub server from a command line by utilizing ostree utility ?

You mean you want to use the ostree commandline tool? If so, I don't think you can. We are operating on OSTree objects directly and parsing them with glib ourselves to walk the object trees. (We do that to avoid a dependency on libostree.) Or is there something else you want to do?

@pattivacek pattivacek force-pushed the feat/OTA-2666/garage-tools-mutual-tls branch from f1705ad to 3f9e8a6 Compare July 12, 2019 08:19
@mike-sul
Copy link
Collaborator

What would be the most efficient way to figure out design behind this different schema to authentication ?

Some of the answers can be gleaned from https://github.com/advancedtelematic/aktualizr/blob/master/docs/provisioning-methods-and-credentialszip.adoc. What exactly are you looking for, though? Do you want a sequence diagram or a better explanation of the options?

How can I authenticate at and use the treehub server from a command line by utilizing ostree utility ?

You mean you want to use the ostree commandline tool? If so, I don't think you can. We are operating on OSTree objects directly and parsing them with glib ourselves to walk the object trees. (We do that to avoid a dependency on libostree.) Or is there something else you want to do?

I've already figured out what I wanted by debugging through the code. Thanks.

@mike-sul mike-sul closed this Jul 12, 2019
@pattivacek pattivacek reopened this Jul 12, 2019
@pattivacek pattivacek force-pushed the feat/OTA-2666/garage-tools-mutual-tls branch from 3f9e8a6 to 870db0a Compare July 15, 2019 10:20
pattivacek and others added 9 commits July 19, 2019 14:46
Signed-off-by: Patrick Vacek <patrickvacek@gmail.com>
The old method required seperate client cert, key, and root CA in the
credentials archive. It has been unused as far as I can tell for at
least a year, if not two or more. The one test for it has been broken
for a long time.

That method has been replaced with mutual TLS support, which is what the
backend is transitioning to. OAuth2 support will eventually get dropped
on the server, but in the meantime we still need to support it for some
transitional period.

Signed-off-by: Patrick Vacek <patrickvacek@gmail.com>
Signed-off-by: Patrick Vacek <patrickvacek@gmail.com>
Added new server certs to get this to work correctly.

Signed-off-by: Patrick Vacek <patrickvacek@gmail.com>
Signed-off-by: Patrick Vacek <patrickvacek@gmail.com>
Verify that it actually uses TLS but fails.

Signed-off-by: Patrick Vacek <patrickvacek@gmail.com>
This means they don't have to be hardcoded binary objects anymore.

Even better would be to actually generate the p12 based on the certs as
I'd originally planned but ran out of time for.

Signed-off-by: Patrick Vacek <patrickvacek@gmail.com>
Used by tests/sota_tools/cert_generation/generate-zips.sh

Signed-off-by: Laurent Bonnans <laurent.bonnans@here.com>
Signed-off-by: Patrick Vacek <patrickvacek@gmail.com>
@pattivacek pattivacek force-pushed the feat/OTA-2666/garage-tools-mutual-tls branch from 870db0a to 85deb96 Compare July 19, 2019 12:47
@pattivacek
Copy link
Collaborator Author

pattivacek commented Jul 23, 2019

Should we merge this or wait until we can test with a "real" server? I had also considered doing some more work to make the test data more dynamically generated, but I didn't want to do it before I knew for sure that it worked with the final server implementation. I particularly wanted to get rid of the binary p12 files that I had to had to this PR in its current state.

@lbonn
Copy link
Contributor

lbonn commented Jul 29, 2019

If it doesn't break something that's already working (which I think it's the case), we can probably merge it.

@pattivacek
Copy link
Collaborator Author

If it doesn't break something that's already working (which I think it's the case), we can probably merge it.

Yeah, fair enough. I don't want to have to keep rebasing this, and I'm pretty sure this is on the right track for the eventual integration with the real server implementation. There's still some improvements that could be made here, especially in the automation of the tests, but I think it's a good start.

@pattivacek pattivacek merged commit f5668ae into master Jul 29, 2019
@pattivacek pattivacek deleted the feat/OTA-2666/garage-tools-mutual-tls branch July 29, 2019 07:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants