Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FABG-948] Add support for extra hosts at enrollment #46

Merged
merged 9 commits into from
Mar 2, 2020

Conversation

vieirin
Copy link
Contributor

@vieirin vieirin commented Feb 5, 2020

Provide WithHosts option and add hosts to CSR info at enrollment request
This allows us to pass extra hosts for certificate enrollment, so it can be valid to
those hosts as well for its CN

Signed-off-by: Manoel [email protected]

Provide WithHosts option and add hosts to CSR info at enrollment request
This allows us to pass extra hosts for certificate enrollment, so it can be valid to
those hosts as well for its CN

Signed-off-by: Manoel <[email protected]>
@vieirin vieirin requested a review from a team as a code owner February 5, 2020 20:37
@codecov
Copy link

codecov bot commented Feb 5, 2020

Codecov Report

❗ No coverage uploaded for pull request base (master@070ee52). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master      #46   +/-   ##
=========================================
  Coverage          ?   74.54%           
=========================================
  Files             ?      176           
  Lines             ?    12605           
  Branches          ?        0           
=========================================
  Hits              ?     9396           
  Misses            ?     2289           
  Partials          ?      920

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 070ee52...de91daf. Read the comment docs.

Copy link
Contributor

@alikic alikic left a comment

Choose a reason for hiding this comment

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

EnrollmentRequest should follow

. Adding just host is not a good idea as it is conceivable one might want to add more from CSRInfo in the future. So the whole CSRInfo should be added to EnrollmentRequest instead of just host.

@vieirin vieirin force-pushed the master branch 5 times, most recently from 5eed268 to 91aeb64 Compare February 7, 2020 17:47
@vieirin
Copy link
Contributor Author

vieirin commented Feb 10, 2020

@alikic any other changes?

@@ -6,6 +6,8 @@ SPDX-License-Identifier: Apache-2.0

package msp

import "github.com/cloudflare/cfssl/csr"
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't include third party structures in our high level API. This import shouldn't be here.

Names []csr.Name
Hosts []string
KeyRequest *BasicKeyRequest
CA *csr.CAConfig
Copy link
Contributor

@alikic alikic Feb 14, 2020

Choose a reason for hiding this comment

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

This API shouldn't have dependencies on "github.com/cloudflare/cfssl/csr". CAConfig should be added to our API, and any mapping between this API and third party should be hidden. While we have a freedom to design our API structures independently from the third party, it is useful to keep them close as we keep extending support for Fabric CA features.

Copy link
Contributor Author

@vieirin vieirin Feb 14, 2020

Choose a reason for hiding this comment

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

I strongly disagree, to create a new struct and re-map it as done in CSR struct seems a bad thing to me, caapi depends on cloudflare structure, this dependency is already packaged with sdk code, btw.
I don't see how creating same structs and "convert this type to that type" functions, where those types have the exact same fields but are different definitions is beneficial

what do you think

Copy link
Contributor

@alikic alikic Feb 14, 2020

Choose a reason for hiding this comment

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

Neither fabric-ca nor cloudflare/cfssl are used directly in the exposed API, all uses are internal. I see that we do use cloudflare/cfssl in a couple of tests, perhaps we shouldn't, we can easily change that. Usage of cloudflare/cfssl internally is an implementation detail, shouldn't be in public API.

You wanted to add only hosts to the API call, and my thinking was, if we keep adding the missing pieces of Fabric CA support, we will likely end up with structures similar to what the CA is using. This is why I thought we should introduce CSRInfo, to group hosts and future (currently missing) elements together in a way it makes sense. CSRInfo could initially have only hosts, and whatever you currently need. Ideally, all additions should have proper integration tests.

@chanioxaris
Copy link

Any updates on this issue?

@alikic
Copy link
Contributor

alikic commented Feb 26, 2020

Here is where we stand - the feature is useful, but the implementation has two issues. It introduces a third party dependency in the public API, and it is missing an integration test which would verify that the resulting certificate has desired properties. It makes sense to group all parameters relevant to the creation of a CSR into a structure (perhaps initially having only hosts in the structure), which could be called CSRInfo, but no third party structures are allowed in the public API.

@vieirin
Copy link
Contributor Author

vieirin commented Feb 28, 2020

I'm going back to this issue, @alikic this test should be written in integration tests too, right?
On unit tests return for hosts entry is always empty on returned certificate.

@vieirin vieirin force-pushed the master branch 2 times, most recently from b15e9ac to aeb3136 Compare February 28, 2020 17:19
@vieirin
Copy link
Contributor Author

vieirin commented Feb 28, 2020

Integration tests are broken again
updating with last master hope it fix

@vieirin
Copy link
Contributor Author

vieirin commented Feb 28, 2020

Done :)

t.Fatalf("Registration failed: %s", err)
}

extraHosts := []string{"localhost"}
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to test with more values in extraHosts, it should add all of them to the cert....

Copy link
Contributor Author

@vieirin vieirin Feb 28, 2020

Choose a reason for hiding this comment

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

Can this comparison be O(n²) in test or should it be optimized with a map-based search?
I mean can I compare all requested hosts with all received hosts or may I convert requested hosts to a map first to compare? Does it makes difference? Just to write it right from start haha

Copy link
Contributor

Choose a reason for hiding this comment

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

Haha, you can implement comparison any way you want, I am just looking for having at least two values there, just to have a little more confidence that the mapping works correctly through the layers all the way to the CA itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. Understood.

t.Fatalf("GetSigningIdentity failed: %s", err)
}

has, err := hasHost(si, extraHosts[0])
Copy link
Contributor

Choose a reason for hiding this comment

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

.... and then verify that all the requested hosts are in the cert.

t.Fatalf("GetSigningIdentity failed: %s", err)
}

has, err = hasHost(si, extraHosts[0])
Copy link
Contributor

Choose a reason for hiding this comment

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

.... and then verify that all the requested hosts are in the cert.

Copy link
Contributor

Choose a reason for hiding this comment

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

otherwise looks good

@alikic alikic merged commit ab4de7e into hyperledger:master Mar 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants