Skip to content

RFC: etcdmain, pkg: CN based auth for inter peer connection#8616

Merged
gyuho merged 3 commits into
etcd-io:masterfrom
mitake:peer-cn-auth
Oct 4, 2017
Merged

RFC: etcdmain, pkg: CN based auth for inter peer connection#8616
gyuho merged 3 commits into
etcd-io:masterfrom
mitake:peer-cn-auth

Conversation

@mitake

@mitake mitake commented Sep 27, 2017

Copy link
Copy Markdown
Contributor

This commit adds an authentication mechanism to inter peer connection
(rafthttp). If the cert based peer auth is enabled and a new option
--peer-require-cn is passed, an etcd process denies a peer
connection whose CN doesn't match.

/cc @luxas this is what we talked before, will it be useful for kubeadm?

@mitake mitake changed the title etcdmain, pkg: CN based auth for inter peer connection RFC: etcdmain, pkg: CN based auth for inter peer connection Sep 27, 2017
@mitake

mitake commented Sep 27, 2017

Copy link
Copy Markdown
Contributor Author

This PR is related to #8262 , so I'm ccing @ericchiang
If it is valuable for k8s and acceptable by etcd, I'll add tests and docs.

Comment thread pkg/transport/listener.go Outdated
if info.RequireCN != "" {
cfg.VerifyPeerCertificate = func(rawCerts [][]byte, verifiedChains [][]*x509.Certificate) error {
if len(verifiedChains) != 0 {
chains := verifiedChains[0]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Q. why verifiedChains[0]? Do we ever get more than 1 []*x509.Certificate?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I believe the first certificate is the leaf certificate.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@mitake Let's document that on the code, then.
Thanks!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

verifiedChains is documented as any verified chains that normal processing found. Wouldn't it be safest to verify them all (for _, chains := range verifiedChains { ...), just in-case there is more than one? I can't think of any down side.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry, you're right. The first cert of an individual chain is the leaf. Checking each chain sounds correct.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@gyuho @ericchiang @jpbetz ok, I'll change the mechanism of extracting CN later. Thanks for your comments.

@mitake

mitake commented Sep 29, 2017

Copy link
Copy Markdown
Contributor Author

@gyuho @ericchiang @jpbetz updated the way of looking CN based on the discussion. Also I renamed the command line flag to --peer-cert-allowed-cn as originally proposed in #8262. I'm adding an e2e test and doc.

@mitake

mitake commented Sep 29, 2017

Copy link
Copy Markdown
Contributor Author

@gyuho added the doc and test, could you take a look?

Comment thread pkg/transport/listener.go Outdated
for _, chain := range chains {
if info.AllowedCN == chain.Subject.CommonName {
return nil
} else {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

else is not needed?

Comment thread pkg/transport/listener.go Outdated
// should be left nil. In that case, tls.X509KeyPair will be used.
parseFunc func([]byte, []byte) (tls.Certificate, error)

// AllowedCN is a CN which must be provided by a client

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add period . at the end of comment?

Comment thread e2e/etcd_config_test.go Outdated
}

var args []string

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

remove this empty line?

@gyuho gyuho added this to the v3.3.0 milestone Sep 29, 2017
@mitake

mitake commented Sep 29, 2017

Copy link
Copy Markdown
Contributor Author

@gyuho updated for your comments, could you take a look?

Comment thread pkg/transport/listener.go Outdated
return nil
}

return fmt.Errorf("CommonName authentication failed (allowed: %s, client: %s)", info.AllowedCN, chains[0].Subject.CommonName)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just remove this return fmt.Errorf entirely because it's possible that one of the chain has different Subject.CommonName?

If we still need to keep this error, it should be only when chain.Subject.CommonName != "" and also s/chains[0].Subject.CommonName/chain.Subject.CommonName/.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK I'll change the behaviour for checking a leaf of every verified chain. Probably checking non-leaf certs should be avoided because they wouldn't be user supplied. If the parameter passed with --peer-cert-allowed-cn and CNs in the non leaf certs match accidentally, a node can be authenticated in a wrong manner.

I'm still not sure how the case of multiple verified chains can happen yet... I'm digging it.

mitake added 3 commits October 2, 2017 15:59
This commit adds an authentication mechanism to inter peer connection
(rafthttp). If the cert based peer auth is enabled and a new option
`--peer-cert-allowed-cn` is passed, an etcd process denies a peer
connection whose CN doesn't match.
@mitake

mitake commented Oct 2, 2017

Copy link
Copy Markdown
Contributor Author

@gyuho updated for the CN checking part, could you take a look?

@gyuho

gyuho commented Oct 2, 2017

Copy link
Copy Markdown
Contributor

lgtm. Thanks!
/cc @xiang90 @jpbetz

@gyuho gyuho merged commit 863dfd1 into etcd-io:master Oct 4, 2017
@mitake mitake deleted the peer-cn-auth branch October 5, 2017 01:32
@luxas

luxas commented Oct 28, 2017

Copy link
Copy Markdown
Contributor

Thank you @gyuho & @mitake!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

5 participants