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: refactor certStore and KMP to support multi-tenancy [multi-tenancy PR 10] #1423

Merged
merged 24 commits into from
May 3, 2024

Conversation

binbin-li
Copy link
Collaborator

@binbin-li binbin-li commented Apr 29, 2024

Description

What this PR does / why we need it:

This is the 10th PR for multi-tenancy support. Please review #1422 first. Check diff between PR 9 and PR 10 at: binbin-li#141

  1. Updated the implementation of pkg/customresources/certificatestores.go to support multi-tenancy and backward compatible. Moved prependNamespace logic to GetCertsFromStore method. Removed extra namespace mapping from ScopedCertStores, now the layout of certStore is similar to KMP.
  2. Updated pkg/keymanagementprovider/keymanagementprovider.go to support multi-tenancy.
  3. Removed getCertStoreNamespace from verifier_controller as we will not prepend namespace to certStore configs of Notation Verifiers.
  4. Removed prependNamespaceToKMPName from cosign/trustpolicy.go as we will not prepend namespace to store configs of Cosign Verifiers.
  5. Now the matching between namespace and resource(KMP/certStore) only exists in KMP or certStore implementation. Verifier will keep the original config from users since we'll have clustered and namespaced verifiers, no more assumption need to be made on the empty namespace. So notation verifier and cosign trustPolicy should not prepend namespace to the resource path but each resource should judge if the given scope has access to it.

User Bahavior

Since we don't have a cluster-wide CertStore CRD, default namespace will be reserved for cluster-wide CertStore usage.

Access level of verifier Resource type Resource name provided by user expected behavior
cluster certStore cert1 return certs from gatekeeper-system/cert1 if it exists
cluster certStore namespace1/cert1 return certs from namespace1/cert1 if it exists
cluster certStore default/cert1 return certs from default/cert1 if it exists (default stands for a cluster-wide namespace)
cluster kmp kmp1 return certs from clustered kmp1 if it exists
cluster kmp namespace1/kmp1 cannot access namespaced resource
namespace1 certStore cert1 cannot access gatekeeper-system/cert1
namespace1 certStore namespace1/cert1 return certs from namespace1/cert1 if it exists
namespace1 certStore default/cert1 return certs from default/cert1 if it exists
namespace1 kmp kmp1 return certs from clustered kmp1 if it exists
namespace1 kmp namespace1/kmp1 return certs from namespace1/kmp1 if it exists
namespace2 kmp namespace1/kmp1 cannot access different namespace

We can notice that behavior is different between certStore and kmp. Because KMP is following the multi-tenancy design but certStore keep the previous behavior to avoid breaking change.

Which issue(s) this PR fixes (optional, using fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when the PR gets merged):

Fixes #

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Helm Chart Change (any edit/addition/update that is necessary for changes merged to the main branch)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Please also list any relevant details for your test configuration

  • Test A
  • Test B

Checklist:

  • Does the affected code have corresponding tests?
  • Are the changes documented, not just with inline documentation, but also with conceptual documentation such as an overview of a new feature, or task-based documentation like a tutorial? Consider if this change should be announced on your project blog.
  • Does this introduce breaking changes that would require an announcement or bumping the major version?
  • Do all new files have appropriate license header?

Post Merge Requirements

  • MAINTAINERS: manually trigger the "Publish Package" workflow after merging any PR that indicates Helm Chart Change

@binbin-li binbin-li force-pushed the multi-tenancy-pr-10 branch from 9fbd0b1 to d5fdc08 Compare April 29, 2024 14:42
Copy link

codecov bot commented Apr 29, 2024

Codecov Report

Attention: Patch coverage is 78.46154% with 14 lines in your changes are missing coverage. Please review.

Project coverage is 66.31%. Comparing base (1bd347c) to head (d0042d4).
Report is 3 commits behind head on dev.

❗ Current head d0042d4 differs from pull request most recent head 2474502. Consider uploading reports for the commit 2474502 to get more accurate results

Files Patch % Lines
...omresources/certificatestores/certificatestores.go 88.00% 2 Missing and 1 partial ⚠️
...s/namespaceresource/certificatestore_controller.go 50.00% 2 Missing ⚠️
pkg/keymanagementprovider/keymanagementprovider.go 88.23% 1 Missing and 1 partial ⚠️
pkg/manager/manager.go 0.00% 2 Missing ⚠️
pkg/verifier/cosign/trustpolicy.go 71.42% 2 Missing ⚠️
pkg/verifier/notation/truststore.go 75.00% 1 Missing and 1 partial ⚠️
pkg/controllers/verifier_controller.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1423      +/-   ##
==========================================
- Coverage   66.76%   66.31%   -0.45%     
==========================================
  Files         116      117       +1     
  Lines        6030     6089      +59     
==========================================
+ Hits         4026     4038      +12     
- Misses       1620     1668      +48     
+ Partials      384      383       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@binbin-li binbin-li changed the title [WIP] feat: refactor certStore and KMP to support multi-tenancy [WIP] feat: refactor certStore and KMP to support multi-tenancy [multi-tenancy PR 10] Apr 29, 2024
@binbin-li binbin-li force-pushed the multi-tenancy-pr-10 branch 3 times, most recently from a6ed978 to e5fc08b Compare April 29, 2024 16:42
@binbin-li binbin-li changed the title [WIP] feat: refactor certStore and KMP to support multi-tenancy [multi-tenancy PR 10] feat: refactor certStore and KMP to support multi-tenancy [multi-tenancy PR 10] Apr 29, 2024
@binbin-li binbin-li force-pushed the multi-tenancy-pr-10 branch from e5fc08b to 1d6262a Compare April 30, 2024 04:40
@binbin-li binbin-li force-pushed the multi-tenancy-pr-10 branch from 1d6262a to 2a04be7 Compare April 30, 2024 06:23
@binbin-li binbin-li force-pushed the multi-tenancy-pr-10 branch from 90f835f to a95d858 Compare May 1, 2024 01:54
@binbin-li binbin-li force-pushed the multi-tenancy-pr-10 branch 4 times, most recently from 71df42a to 2f1d234 Compare May 2, 2024 11:19
// }
// Note: Scope is utilized for organizing and isolating cert stores. In a Kubernetes (K8s) environment, the scope can be either a namespace or an empty string ("") for cluster-wide cert stores.
ScopedCertStores map[string]map[string][]*x509.Certificate
// Note: The namespace "default" is reserved for cluster-wide scenario.
Copy link
Collaborator

@akashsinghal akashsinghal May 2, 2024

Choose a reason for hiding this comment

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

nit (not blocking): I think this is out of date? "default" is not reserved right? It's the EmptyNamespace instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

thanks for catching! I did update in my last batch but forgot to push it. Actually as we disuccsed last week, there should be no cluster-wide concept while users keep using certStore since certStore will always prefixed with the namespace (default if users don't provide it). And a cluster-wide verifier could always access certStores in all namespaces as v1.1 supports.

Copy link
Collaborator

@susanshi susanshi left a comment

Choose a reason for hiding this comment

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

left some clarification questions, thanks!

}

if err = verifierAddOrReplace(verifier.Spec, resource, namespace); err != nil {
if err := verifierAddOrReplace(verifier.Spec, resource, constants.EmptyNamespace); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we still need the namespace var, ? are we moving local from verifier to certStore?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We won't need the namespace var since now. In the future, verifier will just keep the original configurations from users, like the ref to certStore/KMP. For the logics matching reference to certStore/KMP, it's moved to certStore/KMP implementation so that we could have different behavior on them. And it would be easier to manage it than splitting namespace fetching, namespace prefix and matching into different places.

// Cluster-wide verifier could access all certStores.
// Note: the cluster-wide behavior is different from KMP as we need to keep the behavior backward compatible.
func hasAccessToStore(ctx context.Context, storeName string) bool {
namespace := ctxUtils.GetNamespace(ctx)
Copy link
Collaborator

Choose a reason for hiding this comment

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

clarification , doe ctxUtils.GetNamespace(ctx) get the namespace of the verification request or the verifier.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's fetching the namespace of the request, i.e. the namespace where image is deployed. I should update the comment to be more clear. Thanks for calling it out!

@binbin-li binbin-li force-pushed the multi-tenancy-pr-10 branch from 2f1d234 to d0042d4 Compare May 3, 2024 14:07
@binbin-li binbin-li force-pushed the multi-tenancy-pr-10 branch from d0042d4 to 2474502 Compare May 3, 2024 14:34
Copy link
Collaborator

@akashsinghal akashsinghal left a comment

Choose a reason for hiding this comment

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

lgtm

@akashsinghal akashsinghal merged commit 1742f2f into ratify-project:dev May 3, 2024
15 checks passed
akashsinghal pushed a commit to akashsinghal/ratify that referenced this pull request Sep 13, 2024
binbin-li added a commit to binbin-li/ratify that referenced this pull request Sep 14, 2024
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