-
Notifications
You must be signed in to change notification settings - Fork 50
Add collect keyless params task & related keyless improvements #3171
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
Open
simonbaird
wants to merge
5
commits into
conforma:main
Choose a base branch
from
simonbaird:collect-keyless-params-task
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,276
−165
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d2541d2
Support running nginx TUF inside test cluster
simonbaird 9de6ed6
Support creating ConfigMaps in acceptance tests
simonbaird 62613e8
Reduce policy repetition in feature file
simonbaird 9dde861
Improvements for task keyless signing support
simonbaird 142a144
Add new task to collect keyless signing params
simonbaird File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,14 +32,18 @@ import ( | |
| pipeline "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" | ||
| tekton "github.com/tektoncd/pipeline/pkg/client/clientset/versioned/typed/pipeline/v1" | ||
| v1 "k8s.io/api/core/v1" | ||
| rbacv1 "k8s.io/api/rbac/v1" | ||
| apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
| "k8s.io/apimachinery/pkg/runtime" | ||
|
|
||
| "github.com/conforma/cli/acceptance/crypto" | ||
| "github.com/conforma/cli/acceptance/kubernetes/types" | ||
| "github.com/conforma/cli/acceptance/kustomize" | ||
| "github.com/conforma/cli/acceptance/rekor" | ||
| "github.com/conforma/cli/acceptance/testenv" | ||
| "github.com/conforma/cli/acceptance/wiremock" | ||
| ) | ||
|
|
||
| // createPolicyObject creates the EnterpriseContractPolicy object with the given | ||
|
|
@@ -189,6 +193,137 @@ func (k *kindCluster) CreateNamedSnapshot(ctx context.Context, name string, spec | |
| return k.createSnapshot(ctx, snapshot) | ||
| } | ||
|
|
||
| // CreateConfigMap creates a ConfigMap with the given name and namespace with the provided content | ||
| // Also creates necessary RBAC permissions for cross-namespace access | ||
| func (k *kindCluster) CreateConfigMap(ctx context.Context, name, namespace, content string) error { | ||
| var data map[string]string | ||
|
|
||
| // Parse JSON content and extract individual fields as ConfigMap data keys | ||
| if strings.HasPrefix(strings.TrimSpace(content), "{") { | ||
| // Parse JSON content | ||
| var jsonData map[string]interface{} | ||
| if err := json.Unmarshal([]byte(content), &jsonData); err != nil { | ||
| return fmt.Errorf("failed to parse JSON content: %w", err) | ||
| } | ||
|
|
||
| // Convert to string map for ConfigMap data | ||
| data = make(map[string]string) | ||
| for key, value := range jsonData { | ||
| if value != nil { | ||
| data[key] = fmt.Sprintf("%v", value) | ||
| } | ||
| } | ||
| } else { | ||
| // For non-JSON content, store as-is under a single key | ||
| data = map[string]string{ | ||
| "content": content, | ||
| } | ||
| } | ||
|
|
||
| configMap := &v1.ConfigMap{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: name, | ||
| Namespace: namespace, | ||
| }, | ||
| Data: data, | ||
| } | ||
|
|
||
| // Create the ConfigMap (or update if it already exists) | ||
| if _, err := k.client.CoreV1().ConfigMaps(namespace).Create(ctx, configMap, metav1.CreateOptions{}); err != nil { | ||
| if apierrors.IsAlreadyExists(err) { | ||
| // ConfigMap exists, so get the existing one to retrieve its ResourceVersion | ||
| existing, err := k.client.CoreV1().ConfigMaps(namespace).Get(ctx, name, metav1.GetOptions{}) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to get existing ConfigMap: %w", err) | ||
| } | ||
| // Set the ResourceVersion from the existing ConfigMap | ||
| configMap.ResourceVersion = existing.ResourceVersion | ||
| // Now update with the proper ResourceVersion | ||
| if _, err := k.client.CoreV1().ConfigMaps(namespace).Update(ctx, configMap, metav1.UpdateOptions{}); err != nil { | ||
| return fmt.Errorf("failed to update existing ConfigMap: %w", err) | ||
| } | ||
| } else { | ||
| return err | ||
| } | ||
| } | ||
|
|
||
| // Create RBAC permissions for cross-namespace ConfigMap access | ||
| // This allows any service account to read ConfigMaps from any namespace | ||
| if err := k.ensureConfigMapRBAC(ctx); err != nil { | ||
| return fmt.Errorf("failed to create RBAC permissions: %w", err) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // ensureConfigMapRBAC creates necessary RBAC permissions for ConfigMap access across namespaces | ||
| func (k *kindCluster) ensureConfigMapRBAC(ctx context.Context) error { | ||
| // Create ClusterRole for ConfigMap reading (idempotent) | ||
| clusterRole := &rbacv1.ClusterRole{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: "acceptance-configmap-reader", | ||
| }, | ||
| Rules: []rbacv1.PolicyRule{ | ||
| { | ||
| APIGroups: []string{""}, | ||
| Resources: []string{"configmaps"}, | ||
| Verbs: []string{"get", "list"}, | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| if _, err := k.client.RbacV1().ClusterRoles().Create(ctx, clusterRole, metav1.CreateOptions{}); err != nil { | ||
| // Ignore error if ClusterRole already exists | ||
| if !strings.Contains(err.Error(), "already exists") { | ||
| return fmt.Errorf("failed to create ClusterRole: %w", err) | ||
| } | ||
| } | ||
|
|
||
| // Create ClusterRoleBinding for all service accounts (idempotent) | ||
| clusterRoleBinding := &rbacv1.ClusterRoleBinding{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: "acceptance-configmap-reader-binding", | ||
| }, | ||
| RoleRef: rbacv1.RoleRef{ | ||
| APIGroup: "rbac.authorization.k8s.io", | ||
| Kind: "ClusterRole", | ||
| Name: "acceptance-configmap-reader", | ||
| }, | ||
| Subjects: []rbacv1.Subject{ | ||
| { | ||
| Kind: "Group", | ||
| Name: "system:serviceaccounts", | ||
| APIGroup: "rbac.authorization.k8s.io", | ||
| }, | ||
| }, | ||
| } | ||
|
Comment on lines
+282
to
+299
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. RBAC binding is too broad ( Line 295 binds ConfigMap read access to all service accounts in the cluster. For acceptance tests this should be scoped to the specific task service account/namespace only. 🔒 Scope RBAC to the test service account instead of all SAs-func (k *kindCluster) ensureConfigMapRBAC(ctx context.Context) error {
+func (k *kindCluster) ensureConfigMapRBAC(ctx context.Context, configMapNamespace string) error {
+ t := testenv.FetchState[testState](ctx)
@@
- clusterRoleBinding := &rbacv1.ClusterRoleBinding{
+ roleBinding := &rbacv1.RoleBinding{
ObjectMeta: metav1.ObjectMeta{
- Name: "acceptance-configmap-reader-binding",
+ Name: fmt.Sprintf("acceptance-configmap-reader-%s", t.namespace),
+ Namespace: configMapNamespace,
},
RoleRef: rbacv1.RoleRef{
APIGroup: "rbac.authorization.k8s.io",
Kind: "ClusterRole",
Name: "acceptance-configmap-reader",
},
Subjects: []rbacv1.Subject{
{
- Kind: "Group",
- Name: "system:serviceaccounts",
- APIGroup: "rbac.authorization.k8s.io",
+ Kind: "ServiceAccount",
+ Name: "default",
+ Namespace: t.namespace,
},
},
}
- if _, err := k.client.RbacV1().ClusterRoleBindings().Create(ctx, clusterRoleBinding, metav1.CreateOptions{}); err != nil {
+ if _, err := k.client.RbacV1().RoleBindings(configMapNamespace).Create(ctx, roleBinding, metav1.CreateOptions{}); err != nil {
...
}🤖 Prompt for AI Agents |
||
|
|
||
| if _, err := k.client.RbacV1().ClusterRoleBindings().Create(ctx, clusterRoleBinding, metav1.CreateOptions{}); err != nil { | ||
| // Ignore error if ClusterRoleBinding already exists | ||
| if !strings.Contains(err.Error(), "already exists") { | ||
| return fmt.Errorf("failed to create ClusterRoleBinding: %w", err) | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // CreateNamedNamespace creates a namespace with the specified name | ||
| func (k *kindCluster) CreateNamedNamespace(ctx context.Context, name string) error { | ||
| _, err := k.client.CoreV1().Namespaces().Create(ctx, &v1.Namespace{ | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: name, | ||
| }, | ||
| }, metav1.CreateOptions{}) | ||
|
|
||
| // Ignore error if namespace already exists | ||
| if err != nil && strings.Contains(err.Error(), "already exists") { | ||
| return nil | ||
| } | ||
|
|
||
| return err | ||
| } | ||
|
|
||
| // CreateNamespace creates a randomly-named namespace for the test to execute in | ||
| // and stores it in the test context | ||
| func (k *kindCluster) CreateNamespace(ctx context.Context) (context.Context, error) { | ||
|
|
@@ -254,6 +389,19 @@ func stringParam(ctx context.Context, name, value string, t *testState) pipeline | |
| vars["BUILD_SNAPSHOT_DIGEST"] = t.snapshotDigest | ||
| } | ||
|
|
||
| // Add TUF and certificate variables for keyless verification | ||
| // For Tekton tasks, always use the cluster-internal TUF service | ||
| vars["TUF"] = "http://tuf.tuf-service.svc.cluster.local:8080" | ||
| vars["CERT_IDENTITY"] = "https://kubernetes.io/namespaces/default/serviceaccounts/default" | ||
| vars["CERT_ISSUER"] = "https://kubernetes.default.svc.cluster.local" | ||
|
|
||
| // Only set REKOR variable if stub rekord was started | ||
| if wiremock.IsRunning(ctx) { | ||
| if rekorURL, err := rekor.StubRekor(ctx); err == nil { | ||
| vars["REKOR"] = rekorURL | ||
| } | ||
| } | ||
|
|
||
| publicKeys := crypto.PublicKeysFrom(ctx) | ||
| for name, key := range publicKeys { | ||
| vars[fmt.Sprintf("%s_PUBLIC_KEY", name)] = key | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.