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

Add pkcs12 password feature #229

Closed
wants to merge 7 commits into from
Closed

Add pkcs12 password feature #229

wants to merge 7 commits into from

Conversation

arsenalzp
Copy link
Contributor

This PR is related to the issue #199
It add PKCS12 arbitrary password feature which allows to set a password for PKCS12 bundle as well as don't remove password-less PKCS12 feature.

@jetstack-bot jetstack-bot added the dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. label Nov 9, 2023
@jetstack-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign munnerz for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

@jetstack-bot
Copy link
Contributor

Hi @arsenalzp. Thanks for your PR.

I'm waiting for a cert-manager member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@jetstack-bot jetstack-bot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 9, 2023
Copy link
Contributor

@erikgb erikgb left a comment

Choose a reason for hiding this comment

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

@arsenalzp This looks like a good start! I have added some comments after my first review pass. Some of them are just suggestions - so feel free to disagree. But please explain why. 😉

/ok-to-test

deploy/charts/trust-manager/values.yaml Outdated Show resolved Hide resolved
pkg/bundle/sync.go Outdated Show resolved Hide resolved
pkg/bundle/sync.go Outdated Show resolved Hide resolved
pkg/bundle/sync.go Outdated Show resolved Hide resolved
pkg/bundle/sync.go Outdated Show resolved Hide resolved
@jetstack-bot jetstack-bot added ok-to-test and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 9, 2023
@arsenalzp
Copy link
Contributor Author

arsenalzp commented Nov 11, 2023

Hello,
Your remarks were fixed.
Could you please be so kind to review PR again?

@arsenalzp arsenalzp changed the title add pkcs12 password feature Add pkcs12 password feature Nov 11, 2023
// encodeJKS creates a binary JKS file from the given PEM-encoded trust bundle and password.
// Note that the password is not treated securely; JKS files generally seem to expect a password
// to exist and so we have the option for one.
func (e jksEncoder) encode(trustBundle string) ([]byte, error) {
cas, err := util.DecodeX509CertificateChainBytes([]byte(trustBundle))
func (e jksEncoder) encode() ([]byte, error) {
Copy link
Member

@inteon inteon Nov 13, 2023

Choose a reason for hiding this comment

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

Why are these function signatures being changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hello,
Thank you for a review.
jksEncoder and pkcs12Encoder structures bring all necessary information in corresponding properties:

type encoderData struct {
	storePasswd string
	bundleData  string
}

type pkcs12Encoder struct {
	encoderData
}

type jksEncoder struct {
	encoderData
}

In the future it might be reasonable to rewrite functions like populateAdditionalFormatData to either accept encoder interface and based on the casting result invoke corresponding encode() method or use generics, something like that.

Copy link
Contributor

Choose a reason for hiding this comment

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

I also don't think you need to change the signature of this function. That makes a struct instance locked to the bundle data. Why do you need to change it?

Copy link
Contributor Author

@arsenalzp arsenalzp Nov 13, 2023

Choose a reason for hiding this comment

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

I guess it makes code more clear and avoid of copying bundle data between function/method.
The bundle data is tightly coupled to its encoder; imagine you would like to add decode(), transform() methods in the future, then it leads that the bundle data should be returned from one encoder method and immediately consumed by another one.
Let's look at how is the bundle data was being used before: put to populate function just only to be put to corresponding encoder's method again.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's pretty common in decorators. When will you use function parameters with your view on this?

Copy link
Contributor Author

@arsenalzp arsenalzp Nov 13, 2023

Choose a reason for hiding this comment

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

I agree with you, but at this moment encoder structure consists of 2 fields: password one and data one, what if we need more parameters for encoder, more methods. Ephemeral example - push bundle data into some destination, then encode, so that data should be put as argument twice: to some push(data) as well as to encode(data) functions.
My proposal looks pretty good, we operate by encoder structure, it might be pushed anywhere, with all necessary parameters. populateAdditionalFormatData function accept encoder structure, then within that function we can work the structure we want by any way, everything what we need is already inside that structure.

Copy link
Contributor Author

@arsenalzp arsenalzp Nov 13, 2023

Choose a reason for hiding this comment

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

Dear colleagues, if you insist to use bundle data as argument to encode method, I will rewrite, of course.

Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>

add test for PKCS12 with arbitrary password

Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>

add PKCS12 arbitrary password tests

Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>

remove unnecessary labels from ConfigMap resource

Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>

update helm docs

Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>

fix some remarks from the PR

Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>

fix JKS tests

Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>

reflect PKCS12 and JKS encoders modification to integration test

Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>

update Helm docs

Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>

fix typo in the Values part

Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>

update Helm docs

Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>

update Helm values and doc files

Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>
@@ -31,6 +31,7 @@ Kubernetes: `>= 1.25.0-0`
| app.metrics.service.enabled | bool | `true` | Create a Service resource to expose metrics endpoint. |
| app.metrics.service.servicemonitor | object | `{"enabled":false,"interval":"10s","labels":{},"prometheusInstance":"default","scrapeTimeout":"5s"}` | ServiceMonitor resource for this Service. |
| app.metrics.service.type | string | `"ClusterIP"` | Service type to expose metrics. |
| app.pkcs12Password | string | `nil` | Password for JKS and PKCS12 stores protection |
Copy link
Contributor

Choose a reason for hiding this comment

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

I think these docs are a bit misleading. The default should be "" (empty string) creating a password-less PKC12 truststore.

Copy link
Contributor Author

@arsenalzp arsenalzp Nov 13, 2023

Choose a reason for hiding this comment

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

I agree, this line of code will be changed

// encodeJKS creates a binary JKS file from the given PEM-encoded trust bundle and password.
// Note that the password is not treated securely; JKS files generally seem to expect a password
// to exist and so we have the option for one.
func (e jksEncoder) encode(trustBundle string) ([]byte, error) {
cas, err := util.DecodeX509CertificateChainBytes([]byte(trustBundle))
func (e jksEncoder) encode() ([]byte, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I also don't think you need to change the signature of this function. That makes a struct instance locked to the bundle data. Why do you need to change it?

@arsenalzp
Copy link
Contributor Author

arsenalzp commented Nov 13, 2023

#229 (comment)

I guess it makes code more clear and avoid of copying bundle data between function/method.
The bundle data is tightly coupled to its encoder; imagine you would like to add decode(), transform() methods in the future, then it leads that the bundle data should be returned from one encoder method and immediately consumed by another one.

@arsenalzp
Copy link
Contributor Author

Hello colleagues,
Sorry that I'm disturbing you again.
Any decision regarding this PR? Should I change/fix something?

@erikgb
Copy link
Contributor

erikgb commented Nov 15, 2023

Should I change/fix something?

Fields or function params is not a blocker for me. I prefer function params, but. Maybe you can fix (and close) the other open discussions? So we are left with just that point to land?

@SgtCoDFish
Copy link
Member

This is a drive-by comment and I don't have time to fully review but I think I'm negative on adding this as a command-line flag.

This maps neatly to being added in the resource, which is where I'd expect to be able to set it:

{
  "apiVersion": "trust.cert-manager.io/v1alpha1",
  "kind": "Bundle",
  "metadata": {
    "name": "testing"
  },
  "spec": {
    "sources": [
      {
        "useDefaultCAs": true
      }
    ],
    "target": {
      "additionalFormats": {
        "jks": {
          "key": "my-bundle.jks",
          "password": "super_secret",
        }
      },
      "configMap": {
        "key": "mybundle.pem"
      }
    }
  }
}

Putting myself in the shoes of a user, I'd be familar with the concept that each JKS file can have a different password. I'd expect trust-manager to work the same way as that.

Obviously today we have one global setting for the password, but that's just because the JKS files need some password, not because the setting should be global to all bundles.

I can't really see a reason for this to be a CLI flag.

@arsenalzp
Copy link
Contributor Author

arsenalzp commented Nov 16, 2023

This is a drive-by comment and I don't have time to fully review but I think I'm negative on adding this as a command-line flag.

This maps neatly to being added in the resource, which is where I'd expect to be able to set it:

{
  "apiVersion": "trust.cert-manager.io/v1alpha1",
  "kind": "Bundle",
  "metadata": {
    "name": "testing"
  },
  "spec": {
    "sources": [
      {
        "useDefaultCAs": true
      }
    ],
    "target": {
      "additionalFormats": {
        "jks": {
          "key": "my-bundle.jks",
          "password": "super_secret",
        }
      },
      "configMap": {
        "key": "mybundle.pem"
      }
    }
  }
}

Putting myself in the shoes of a user, I'd be familar with the concept that each JKS file can have a different password. I'd expect trust-manager to work the same way as that.

Obviously today we have one global setting for the password, but that's just because the JKS files need some password, not because the setting should be global to all bundles.

I can't really see a reason for this to be a CLI flag.

Hello,
It was proposed to do it globally for entire cluster.
However, if someone has different point of view, let's discuss this topic; it is no so hard to rewrite this solution.
In case we accept your point of view, I would move password parameter upper in the Bundle resource, because pksc12 and jks are two formats of the same bundle, I don't expect customer wants to have different password for each format of the same bundle.

Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>

add test for PKCS12 with arbitrary password

Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>

add PKCS12 arbitrary password tests

Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>

remove unnecessary labels from ConfigMap resource

Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>

update helm docs

Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>

fix some remarks from the PR

Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>

fix JKS tests

Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>

reflect PKCS12 and JKS encoders modification to integration test

Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>

update Helm docs

Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>

fix typo in the Values part

Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>

update Helm docs

Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>

update Helm values and doc files

Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>

Add pkcs12 password feature in the Bundle resource

Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>

fix password issue in helm chart

Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>
@arsenalzp
Copy link
Contributor Author

Another PR #233 related to @SgtCoDFish was submitted.

@jetstack-bot jetstack-bot added dco-signoff: no Indicates that at least one commit in this pull request is missing the DCO sign-off message. and removed dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. labels Nov 16, 2023
Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>
Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>

add test for PKCS12 with arbitrary password

Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>

add PKCS12 arbitrary password tests

Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>

remove unnecessary labels from ConfigMap resource

Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>

update helm docs

Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>

fix some remarks from the PR

Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>

fix JKS tests

Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>

reflect PKCS12 and JKS encoders modification to integration test

Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>

update Helm docs

Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>

fix typo in the Values part

Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>

update Helm docs

Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>

update Helm values and doc files

Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>

tweak readme to encourage use

Signed-off-by: Ashley Davis <ashley.davis@venafi.com>

chore: generate applyconfigurations for custom resources

Signed-off-by: Erik Godding Boye <egboye@gmail.com>

Bump the all group with 3 updates

Bumps the all group with 3 updates: [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo), [github.com/onsi/gomega](https://github.com/onsi/gomega) and [sigs.k8s.io/structured-merge-diff/v4](https://github.com/kubernetes-sigs/structured-merge-diff).

Updates `github.com/onsi/ginkgo/v2` from 2.13.0 to 2.13.1
- [Release notes](https://github.com/onsi/ginkgo/releases)
- [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md)
- [Commits](onsi/ginkgo@v2.13.0...v2.13.1)

Updates `github.com/onsi/gomega` from 1.29.0 to 1.30.0
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](onsi/gomega@v1.29.0...v1.30.0)

Updates `sigs.k8s.io/structured-merge-diff/v4` from 4.2.3 to 4.4.1
- [Release notes](https://github.com/kubernetes-sigs/structured-merge-diff/releases)
- [Changelog](https://github.com/kubernetes-sigs/structured-merge-diff/blob/master/RELEASE.md)
- [Commits](kubernetes-sigs/structured-merge-diff@v4.2.3...v4.4.1)

---
updated-dependencies:
- dependency-name: github.com/onsi/ginkgo/v2
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all
- dependency-name: github.com/onsi/gomega
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: all
- dependency-name: sigs.k8s.io/structured-merge-diff/v4
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: all
...

Signed-off-by: dependabot[bot] <support@github.com>

chore!: remove .status.target field from Bundle API

Signed-off-by: Erik Godding Boye <egboye@gmail.com>
@jetstack-bot jetstack-bot added dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. and removed dco-signoff: no Indicates that at least one commit in this pull request is missing the DCO sign-off message. labels Nov 16, 2023
@jetstack-bot jetstack-bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 16, 2023
Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>
@jetstack-bot jetstack-bot added dco-signoff: no Indicates that at least one commit in this pull request is missing the DCO sign-off message. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Nov 16, 2023
Signed-off-by: Oleksandr Krutko <alexander.krutko@gmail.com>
@jetstack-bot
Copy link
Contributor

Thanks for your pull request. Before we can look at it, you'll need to add a 'DCO signoff' to your commits.

📝 Please follow instructions in the contributing guide to update your commits with the DCO

Full details of the Developer Certificate of Origin can be found at developercertificate.org.

The list of commits missing DCO signoff:

  • 74dd69a Merge branch 'cert-manager:main' into addPKCSPasswd

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. I understand the commands that are listed here.

@jetstack-bot
Copy link
Contributor

@arsenalzp: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-trust-manager-verify 2d4b1fa link true /test pull-trust-manager-verify
pull-trust-manager-smoke 2d4b1fa link true /test pull-trust-manager-smoke

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dco-signoff: no Indicates that at least one commit in this pull request is missing the DCO sign-off message. ok-to-test size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants