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

feat: support secret as a target #193

Merged
merged 1 commit into from
Oct 18, 2023
Merged

Conversation

Jiawei0227
Copy link
Contributor

Support #10

Add a new API Secret under taget to allow creating secret format CA certificates.
This is compatible with existing ConfigMap and can co-exist or exist alone.

@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. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Oct 7, 2023
@jetstack-bot
Copy link
Contributor

Hi @Jiawei0227. 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 the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Oct 7, 2023
@Jiawei0227
Copy link
Contributor Author

/ok-to-test

/cc @SgtCoDFish @rudexi

@jetstack-bot
Copy link
Contributor

@Jiawei0227: GitHub didn't allow me to request PR reviews from the following users: rudexi.

Note that only cert-manager members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

/ok-to-test

/cc @SgtCoDFish @rudexi

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
Copy link
Contributor

@Jiawei0227: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/ok-to-test

/cc @SgtCoDFish @rudexi

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.

@rudexi
Copy link

rudexi commented Oct 7, 2023

/ok-to-test

@jetstack-bot
Copy link
Contributor

@rudexi: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/ok-to-test

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.

@inteon
Copy link
Member

inteon commented Oct 9, 2023

/ok-to-test

@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 Oct 9, 2023
@inteon
Copy link
Member

inteon commented Oct 9, 2023

Thanks @Jiawei0227 for rebasing this PR, could you dco signoff your commits & also add @rudexi as a co-author?

@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 Oct 9, 2023
@Jiawei0227
Copy link
Contributor Author

Thanks @Jiawei0227 for rebasing this PR, could you dco signoff your commits & also add @rudexi as a co-author?

Done. This CL is mostly a rewrite since the previous PR is completely un-rebaseable. But I am okay with co-authoring @rudexi since this PR is inspired by him

@Jiawei0227 Jiawei0227 force-pushed the secrets branch 3 times, most recently from 1710f91 to 00260c6 Compare October 9, 2023 23:58
@jetstack-bot jetstack-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 10, 2023
@jetstack-bot jetstack-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 10, 2023
@erikgb
Copy link
Contributor

erikgb commented Oct 10, 2023

/retest

Copy link
Member

@SgtCoDFish SgtCoDFish left a comment

Choose a reason for hiding this comment

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

Thanks for your work on this! I have a couple of suggestions - what do you think?

Comment on lines 104 to 106
# -- List of secrets trust-manager is allowed to read/write. Used when the secret target is set when creating
# a bundle. If the list is empty it means read/write access to all secrets.
authorizedSecrets: ["ca-bundle"]
Copy link
Member

@SgtCoDFish SgtCoDFish Oct 11, 2023

Choose a reason for hiding this comment

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

suggestion: I'm not sure if this is the safest way to do this.

I have a few concerns:

  • Having a default here feels wrong - since most clusters won't need to be able to read/write to secrets called ca-bundle. I'd rather the default be that there's nothing extra which we have access to, so that users have to explicitly expand trust-manager's permissions.
  • Having an empty list confer permissions to everything is really confusing to me (the intuitive reading would be that an empty list means there are no allowed secrets at all)
  • There doesn't seem to be an obvious way to allow no secrets, in the event that I don't want to use secrets at all.

I'd personally rather the default be "no secrets are authorized". How about something like the following?

secretTargets:
    # -- If set to true, enable writing trust bundles to Kubernetes Secrets as a target
    enabled: false

    # -- A list of secret names which trust-manager will be permitted to read and write across all namespaces. These will be the only allowable Secrets that can be used as targets. Must be a non-empty list  if secretTargets.enabled is true
    authorizedSecrets: []  # NOTE: I originally wrote [""] here but [] is better

Copy link
Member

Choose a reason for hiding this comment

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

What would be the difference between authorizedSecrets: [""] and authorizedSecrets: [] ?

Copy link
Member

Choose a reason for hiding this comment

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

Whoops, that was a typo, my bad! I think the default should be authorizedSecrets: [].

If enabled is set to true, we should check that authorizedSecrets is a list with at least one valid secret name. "" wouldn't be a valid secret name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For resourceNames, an empty set means that everything is allowed

I was thinking https://kubernetes.io/docs/reference/access-authn-authz/rbac/#referring-to-resources the resourceNames field in k8s and an empty list there infer permission to all.

However, I understand the concern here. But then the question is probably what option we will use to indicate "permission to all"? The problem is resourceNames does not allow wildcard matching (kubernetes/kubernetes#56582). I added an enabled field so that user have to explicitly enable it. wdyt?

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 we need a separate config to enable RBAC to any secret. It seems scary to rely on a Helm list value to express this desire.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay, I add another option authorizedSecretsAll to indicate permission to all. And now empty list of authorizedSecrets means access to nothing

pkg/bundle/sync.go Outdated Show resolved Hide resolved
@Jiawei0227
Copy link
Contributor Author

/retest

Copy link
Member

@SgtCoDFish SgtCoDFish left a comment

Choose a reason for hiding this comment

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

Few more comments - really appreciate the work you've put into this. We're nearly there 😁

deploy/charts/trust-manager/values.yaml Outdated Show resolved Hide resolved
deploy/charts/trust-manager/values.yaml Outdated Show resolved Hide resolved
deploy/charts/trust-manager/values.yaml Outdated Show resolved Hide resolved
pkg/apis/trust/v1alpha1/types_bundle.go Outdated Show resolved Hide resolved
test/env/data.go Show resolved Hide resolved
@@ -39,7 +39,7 @@ import (
)

const (
EventuallyTimeout = "30s"
EventuallyTimeout = "90s"
Copy link
Member

Choose a reason for hiding this comment

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

question: Why are we bumping this? 30s seems like it should be plenty for this use case to me, but I'd happily bump if you've been running into problems

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I run this locally, if its the first time I bring up KIND cluster it will timeout. It took around 40s etc to finish all the testing in my local.

Inspired by cert-manager#108

Signed-off-by: Jiawei Wang <[email protected]>,Guillaume Ludinard <[email protected]>
@Jiawei0227
Copy link
Contributor Author

/retest

Copy link
Member

@SgtCoDFish SgtCoDFish left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

I ran this locally and it worked great! Thank you so much for your efforts on this, really appreciate it!

@jetstack-bot jetstack-bot added the lgtm Indicates that a PR is ready to be merged. label Oct 18, 2023
@jetstack-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: SgtCoDFish

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

@jetstack-bot jetstack-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 18, 2023
@jetstack-bot jetstack-bot merged commit f5fadf2 into cert-manager:main Oct 18, 2023
- ""
resources:
- "secrets"
verbs: ["create", "list", "watch"]
Copy link
Member

Choose a reason for hiding this comment

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

@SgtCoDFish shouldn't this also be part of the .Values.secretTargets.enabled section?

Copy link
Member

Choose a reason for hiding this comment

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

We still by default grant trust-manager access to read ALL secret resources.

Copy link
Contributor

@erikgb erikgb Oct 23, 2023

Choose a reason for hiding this comment

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

I think we must conditionally watch secrets from the controller if we add a condition here. And that might be the reason behind this bug.

Copy link
Contributor

Choose a reason for hiding this comment

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

Here is a WIP PR to fix this: #207. My Tuesday (tomorrow) is filled with meetings, so feel free to pick it up. My gut feeling says that this new feature needs more work....

Copy link
Member

Choose a reason for hiding this comment

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

Yeah that's my bad... thought I checked the permissions and clearly wasn't thorough / careful enough in my efforts to move this forwards. Sorry.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for confirming that this was not the intended behavior @SgtCoDFish.

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. dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. lgtm Indicates that a PR is ready to be merged. ok-to-test size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants