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

Bug 1843856: Sanitize TLS config that has key bundled with cert #136

Conversation

Miciah
Copy link
Contributor

@Miciah Miciah commented Jun 5, 2020

Modify the extended validation logic to copy any private key found in the certificate field of a route's TLS configuration to its key field.

Extended validation validates a route's TLS configuration using any key that is specified in either the TLS configuration's certificate field or its key field. As a result, a route that specifies the certificate and key together in the certificate field may pass extended validation and be admitted. However, before this commit, the certificate manager only wrote the certificate out if the TLS configuration had a nonempty key field. As a result, a route with a valid certificate and key could be admitted but the certificate and key not written out, which would cause HAProxy to fail to load.

  • pkg/router/routeapihelpers/validation.go (splitCertKey): New function. Take sanitized PEM data and split it into public and private parts.
    (ExtendedValidateRoute): Use splitCertKey to parse out any private parts that are in the certificate field of the TLS configuration. Prepend any private parts found in the certificate data to the TLS configuration's key.
  • pkg/router/routeapihelpers/validation_test.go: Add test cases.

@openshift-ci-robot openshift-ci-robot added bugzilla/severity-high Referenced Bugzilla bug's severity is high for the branch this PR is targeting. bugzilla/invalid-bug Indicates that a referenced Bugzilla bug is invalid for the branch this PR is targeting. labels Jun 5, 2020
@openshift-ci-robot
Copy link
Contributor

@Miciah: This pull request references Bugzilla bug 1843856, which is invalid:

  • expected the bug to target the "4.6.0" release, but it targets "3.11.z" instead

Comment /bugzilla refresh to re-evaluate validity if changes to the Bugzilla bug are made, or edit the title of this pull request to link to a different bug.

In response to this:

Bug 1843856: Sanitize TLS config that has key bundled with cert

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 5, 2020
@Miciah
Copy link
Contributor Author

Miciah commented Jun 8, 2020

/bugzilla refresh

@openshift/openshift-team-network-edge, please review.

@openshift-ci-robot openshift-ci-robot added the bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. label Jun 8, 2020
@openshift-ci-robot
Copy link
Contributor

@Miciah: This pull request references Bugzilla bug 1843856, which is valid. The bug has been moved to the POST state. The bug has been updated to refer to the pull request using the external bug tracker.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target release (4.6.0) matches configured target release for branch (4.6.0)
  • bug is in the state ASSIGNED, which is one of the valid states (NEW, ASSIGNED, ON_DEV, POST, POST)

In response to this:

/bugzilla refresh

@openshift/openshift-team-network-edge, please review.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci-robot openshift-ci-robot removed the bugzilla/invalid-bug Indicates that a referenced Bugzilla bug is invalid for the branch this PR is targeting. label Jun 8, 2020
} else {
if len(tlsConfig.Key) > 0 {
if len(keyBytes) > 0 {
keyBytes = append(keyBytes, byte('\n'))

Choose a reason for hiding this comment

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

I noticed there isn't a unit test that covers this branch. I point this out because I am slightly confused as to what's going on here. If tlsConfig.Key is set and splitCertKey yields private keyBytes from tlsConfig.Certificate, then keyBytes will become a new-line delimited buffer of both of the keys? Could you elaborate a little bit so I can understand?

Copy link
Contributor Author

@Miciah Miciah Jul 8, 2020

Choose a reason for hiding this comment

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

Right, we'll move any private parts that were in tlsConfig.Certificate to tlsConfig.Key, preserving any existing private parts that were already in tlsConfig.Key. I'm not sure whether it would be better just to ignore keyBytes if tlsConfig.Key is already set, or override tlsConfig.Key with keyBytes if the latter is nonempty, but I think this is the safest approach, keeping in mind that we don't want to break existing routes that may be doing weird things in tlsConfig.

Choose a reason for hiding this comment

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

Understood. I agree this approach sounds like the way to go.

if err := pem.Encode(publicBuf, block); err != nil {
return nil, nil, err
}
case "EC PRIVATE KEY", "RSA PRIVATE KEY":

Choose a reason for hiding this comment

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

(im probably just out of the loop here, but...) Are EC and RSA the only acceptable types of private keys here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's right. More to the point, splitCertKey expects sanitized PEM data, meaning PEM data that came from sanitizePEM, and sanitizePEM (by way of knownBlockDecoders and privateKeyBlockVerifier) always uses either the block type "RSA PRIVATE KEY" or "EC PRIVATE KEY" for private keys.

@Miciah Miciah force-pushed the BZ1843856-sanitize-TLS-config-that-has-key-bundled-with-cert branch from 74185d8 to a5e9560 Compare July 9, 2020 13:36
Modify the extended validation logic to copy any private key found in the
certificate field of a route's TLS configuration to its key field.

Extended validation validates a route's TLS configuration using any key
that is specified in either the TLS configuration's certificate field or
its key field.  As a result, a route that specifies the certificate and key
together in the certificate field may pass extended validation and be
admitted.  However, the certificate manager only wrote the certificate out
if the TLS configuration had a nonempty key field.  As a result, a route
with a valid certificate and key could be admitted but the certificate and
key not written out, which would cause HAProxy to fail to load.

This commit fixes bug 1843856.

https://bugzilla.redhat.com/show_bug.cgi?id=1843856

* pkg/router/routeapihelpers/validation.go (splitCertKey): New function.
Take sanitized PEM data and split it into public and private parts.
(ExtendedValidateRoute): Use splitCertKey to parse out any private parts
that are in the certificate field of the TLS configuration.  Prepend any
private parts found in the certificate data to the TLS configuration's key.
* pkg/router/routeapihelpers/validation_test.go: Add test cases.
@Miciah Miciah force-pushed the BZ1843856-sanitize-TLS-config-that-has-key-bundled-with-cert branch from a5e9560 to 2dfa244 Compare July 9, 2020 13:37
@Miciah
Copy link
Contributor Author

Miciah commented Jul 9, 2020

I added some comments, removed a spurious newline that the new logic was inserting when both tls.Certificate and tls.Key had private key data, and added a test case.

@openshift-ci-robot
Copy link
Contributor

@Miciah: This pull request references Bugzilla bug 1843856, which is valid.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target release (4.6.0) matches configured target release for branch (4.6.0)
  • bug is in the state POST, which is one of the valid states (NEW, ASSIGNED, ON_DEV, POST, POST)

In response to this:

Bug 1843856: Sanitize TLS config that has key bundled with cert

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@sgreene570
Copy link

New changes look good! Thanks for adding the additional unit test.
/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 9, 2020
@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Miciah, sgreene570

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot merged commit 67c08c8 into openshift:master Jul 9, 2020
@openshift-ci-robot
Copy link
Contributor

@Miciah: All pull requests linked via external trackers have merged: openshift/router#136. Bugzilla bug 1843856 has been moved to the MODIFIED state.

In response to this:

Bug 1843856: Sanitize TLS config that has key bundled with cert

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@Miciah
Copy link
Contributor Author

Miciah commented Jul 15, 2020

/cherry-pick release-4.5
/cherry-pick release-4.4
/cherry-pick release-4.3

@openshift-cherrypick-robot

@Miciah: new pull request created: #150

In response to this:

/cherry-pick release-4.5
/cherry-pick release-4.4
/cherry-pick release-4.3

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@Miciah
Copy link
Contributor Author

Miciah commented Jul 15, 2020

/cherry-pick release-4.4

@Miciah
Copy link
Contributor Author

Miciah commented Jul 15, 2020

/cherry-pick release-4.3

@openshift-cherrypick-robot

@Miciah: new pull request created: #151

In response to this:

/cherry-pick release-4.4

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-cherrypick-robot

@Miciah: new pull request created: #152

In response to this:

/cherry-pick release-4.3

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@mrunalp mrunalp added the cherry-pick-approved Indicates a cherry-pick PR into a release branch has been approved by the release branch manager. label Aug 13, 2020
@openshift-cherrypick-robot

@Miciah: new pull request could not be created: status code 422 not one of [201], body: {"message":"Validation Failed","errors":[{"resource":"PullRequest","code":"custom","message":"No commits between openshift:release-4.5 and openshift-cherrypick-robot:cherry-pick-136-to-release-4.5"}],"documentation_url":"https://docs.github.com/rest/reference/pulls#create-a-pull-request"}

In response to this:

/cherry-pick release-4.5
/cherry-pick release-4.4
/cherry-pick release-4.3

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-cherrypick-robot

@Miciah: failed to push cherry-picked changes in GitHub: pushing failed, output: "To https://github.com/openshift-cherrypick-robot/router\n ! [rejected] cherry-pick-136-to-release-4.4 -> cherry-pick-136-to-release-4.4 (non-fast-forward)\nerror: failed to push some refs to 'https://openshift-cherrypick-robot:CENSORED@github.com/openshift-cherrypick-robot/router'\nhint: Updates were rejected because the tip of your current branch is behind\nhint: its remote counterpart. Integrate the remote changes (e.g.\nhint: 'git pull ...') before pushing again.\nhint: See the 'Note about fast-forwards' in 'git push --help' for details.\n", error: exit status 1

In response to this:

/cherry-pick release-4.4

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-cherrypick-robot

@Miciah: failed to push cherry-picked changes in GitHub: pushing failed, output: "To https://github.com/openshift-cherrypick-robot/router\n ! [rejected] cherry-pick-136-to-release-4.3 -> cherry-pick-136-to-release-4.3 (non-fast-forward)\nerror: failed to push some refs to 'https://openshift-cherrypick-robot:CENSORED@github.com/openshift-cherrypick-robot/router'\nhint: Updates were rejected because the tip of your current branch is behind\nhint: its remote counterpart. Integrate the remote changes (e.g.\nhint: 'git pull ...') before pushing again.\nhint: See the 'Note about fast-forwards' in 'git push --help' for details.\n", error: exit status 1

In response to this:

/cherry-pick release-4.3

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. bugzilla/severity-high Referenced Bugzilla bug's severity is high for the branch this PR is targeting. bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. cherry-pick-approved Indicates a cherry-pick PR into a release branch has been approved by the release branch manager. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants