-
Notifications
You must be signed in to change notification settings - Fork 4.8k
WIP OCPNODE-4561: Migrate OCP-59552 enable image signature verification for RHEL registries #31243
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
BhargaviGudi
wants to merge
1
commit into
openshift:main
Choose a base branch
from
BhargaviGudi:migrate-ocp-59552
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.
+202
−2
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| package node | ||
|
|
||
| import ( | ||
| "context" | ||
| "path/filepath" | ||
| "strings" | ||
| "time" | ||
|
|
||
| g "github.com/onsi/ginkgo/v2" | ||
| o "github.com/onsi/gomega" | ||
| ote "github.com/openshift-eng/openshift-tests-extension/pkg/ginkgo" | ||
|
|
||
| "k8s.io/apimachinery/pkg/util/wait" | ||
| e2e "k8s.io/kubernetes/test/e2e/framework" | ||
|
|
||
| nodeutils "github.com/openshift/origin/test/extended/node" | ||
| exutil "github.com/openshift/origin/test/extended/util" | ||
| ) | ||
|
|
||
| var _ = g.Describe("[Suite:openshift/disruptive-longrunning][sig-node][Disruptive][Serial] Image signature verification", func() { | ||
| var ( | ||
| oc = exutil.NewCLIWithoutNamespace("image-sig") | ||
| nodeE2EBaseDir = exutil.FixturePath("testdata", "node", "node_e2e") | ||
| imgSignatureYAML = filepath.Join(nodeE2EBaseDir, "machineconfig-image-signature.yaml") | ||
| ) | ||
|
|
||
| g.BeforeEach(func() { | ||
| isMicroShift, err := exutil.IsMicroShiftCluster(oc.AdminKubeClient()) | ||
| o.Expect(err).NotTo(o.HaveOccurred()) | ||
| if isMicroShift { | ||
| g.Skip("Skipping test on MicroShift cluster") | ||
| } | ||
| }) | ||
|
|
||
| //author: bgudi@redhat.com | ||
| g.It("[OTP] Enable image signature verification for Red Hat Container Registries [OCP-59552]", ote.Informing(), func() { | ||
| ctx := context.Background() | ||
|
|
||
| g.By("Check if mcp worker exists in current cluster") | ||
| machineCount, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("mcp", "worker", "-o=jsonpath={.status.machineCount}").Output() | ||
| if err != nil || machineCount == "0" { | ||
| g.Skip("Skipping test: mcp worker does not exist in this cluster") | ||
| } | ||
| e2e.Logf("Worker MCP machine count: %s", machineCount) | ||
|
|
||
| g.By("Apply a machine config to set image signature policy for worker nodes") | ||
| err = oc.AsAdmin().WithoutNamespace().Run("create").Args("-f", imgSignatureYAML).Execute() | ||
| o.Expect(err).NotTo(o.HaveOccurred(), "failed to create MachineConfig") | ||
|
|
||
| g.DeferCleanup(func(ctx context.Context) { | ||
| g.By("Delete the MachineConfig") | ||
| oc.AsAdmin().WithoutNamespace().Run("delete").Args("-f", imgSignatureYAML, "--ignore-not-found").Execute() | ||
|
|
||
| g.By("Wait for MCP to finish rolling back") | ||
| err := waitForMCPUpdate(ctx, oc, "worker", 30*time.Minute) | ||
| if err != nil { | ||
| e2e.Logf("Warning: MCP did not finish rolling back: %v", err) | ||
| } | ||
| }, ctx) | ||
|
|
||
| g.By("Wait for MCP to finish updating") | ||
| err = waitForMCPUpdate(ctx, oc, "worker", 30*time.Minute) | ||
| o.Expect(err).NotTo(o.HaveOccurred(), "MCP worker did not finish updating") | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| g.By("Verify the signature configuration in /etc/containers/policy.json") | ||
| err = checkImageSignature(oc) | ||
| o.Expect(err).NotTo(o.HaveOccurred(), "image signature configuration verification failed") | ||
| }) | ||
| }) | ||
|
|
||
| // waitForMCPUpdate waits for the MachineConfigPool to finish updating. | ||
| // It checks the Updated condition to become True (which means update is complete). | ||
| // Returns nil when the MCP is updated, or an error if it times out. | ||
| // This is a helper function and does not contain assertions. | ||
| func waitForMCPUpdate(ctx context.Context, oc *exutil.CLI, mcpName string, timeout time.Duration) error { | ||
| g.GinkgoHelper() | ||
| return wait.PollUntilContextTimeout(ctx, 30*time.Second, timeout, false, func(ctx context.Context) (bool, error) { | ||
| // Check the Updated condition instead of Updating | ||
| // Updated=True means the MCP has finished updating | ||
| updatedStatus, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("mcp", mcpName, "-o=jsonpath={.status.conditions[?(@.type=='Updated')].status}").Output() | ||
| if err != nil { | ||
| e2e.Logf("Error getting MCP Updated status: %v", err) | ||
| return false, nil | ||
| } | ||
|
|
||
| // Check that machine counts match (all machines have the desired config) | ||
| machineCount, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("mcp", mcpName, "-o=jsonpath={.status.machineCount}").Output() | ||
| if err != nil { | ||
| e2e.Logf("Error getting machine count: %v", err) | ||
| return false, nil | ||
| } | ||
| updatedMachineCount, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("mcp", mcpName, "-o=jsonpath={.status.updatedMachineCount}").Output() | ||
| if err != nil { | ||
| e2e.Logf("Error getting updated machine count: %v", err) | ||
| return false, nil | ||
| } | ||
|
|
||
| e2e.Logf("MCP %s: Updated=%s, machines=%s, updatedMachines=%s", mcpName, updatedStatus, machineCount, updatedMachineCount) | ||
|
|
||
| if strings.Contains(updatedStatus, "True") && machineCount == updatedMachineCount { | ||
| e2e.Logf("MCP %s updated successfully", mcpName) | ||
| return true, nil | ||
| } | ||
| e2e.Logf("MCP %s is still updating", mcpName) | ||
| return false, nil | ||
| }) | ||
| } | ||
|
|
||
| // checkImageSignature verifies that the image signature policy is correctly configured on worker nodes. | ||
| // It checks for required entries in /etc/containers/policy.json for Red Hat registries. | ||
| // This is a helper function and does not contain assertions. | ||
| func checkImageSignature(oc *exutil.CLI) error { | ||
| g.GinkgoHelper() | ||
| return wait.PollUntilContextTimeout(context.Background(), 10*time.Second, 30*time.Second, true, func(ctx context.Context) (bool, error) { | ||
| workerNode := nodeutils.GetFirstReadyWorkerNode(oc) | ||
| policyJSON, err := nodeutils.ExecOnNodeWithChroot(oc, workerNode, "cat", "/etc/containers/policy.json") | ||
| if err != nil { | ||
| e2e.Logf("Error reading policy.json: %v", err) | ||
| return false, nil | ||
| } | ||
|
|
||
| e2e.Logf("Checking policy.json content from node %s", workerNode) | ||
|
|
||
| // Check for required entries in the policy.json | ||
| requiredEntries := []string{ | ||
| "registry.access.redhat.com", | ||
| "signedBy", | ||
| "GPGKeys", | ||
| "/etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release", | ||
| "registry.redhat.io", | ||
| } | ||
|
|
||
| for _, entry := range requiredEntries { | ||
| if !strings.Contains(policyJSON, entry) { | ||
| e2e.Logf("Missing required entry in policy.json: %s", entry) | ||
| return false, nil | ||
| } | ||
| } | ||
|
|
||
| e2e.Logf("Image signature policy verified successfully") | ||
| return true, nil | ||
| }) | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
test/extended/testdata/node/node_e2e/machineconfig-image-signature.yaml
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 |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Generated by Butane; do not edit | ||
| apiVersion: machineconfiguration.openshift.io/v1 | ||
| kind: MachineConfig | ||
| metadata: | ||
| labels: | ||
| machineconfiguration.openshift.io/role: worker | ||
| name: 51-worker-rh-registry-trust | ||
| spec: | ||
| config: | ||
| ignition: | ||
| version: 3.2.0 | ||
| storage: | ||
| files: | ||
| - contents: | ||
| source: data:;base64,ewogICJkZWZhdWx0IjogWwogICAgewogICAgICAidHlwZSI6ICJpbnNlY3VyZUFjY2VwdEFueXRoaW5nIgogICAgfQogIF0sCiAgInRyYW5zcG9ydHMiOiB7CiAgICAiZG9ja2VyIjogewogICAgICAicmVnaXN0cnkuYWNjZXNzLnJlZGhhdC5jb20iOiBbCiAgICAgICAgewogICAgICAgICAgInR5cGUiOiAic2lnbmVkQnkiLAogICAgICAgICAgImtleVR5cGUiOiAiR1BHS2V5cyIsCiAgICAgICAgICAia2V5UGF0aCI6ICIvZXRjL3BraS9ycG0tZ3BnL1JQTS1HUEctS0VZLXJlZGhhdC1yZWxlYXNlIgogICAgICAgIH0KICAgICAgXSwKICAgICAgInJlZ2lzdHJ5LnJlZGhhdC5pbyI6IFsKICAgICAgICB7CiAgICAgICAgICAidHlwZSI6ICJzaWduZWRCeSIsCiAgICAgICAgICAia2V5VHlwZSI6ICJHUEdLZXlzIiwKICAgICAgICAgICJrZXlQYXRoIjogIi9ldGMvcGtpL3JwbS1ncGcvUlBNLUdQRy1LRVktcmVkaGF0LXJlbGVhc2UiCiAgICAgICAgfQogICAgICBdCiAgICB9LAogICAgImRvY2tlci1kYWVtb24iOiB7CiAgICAgICIiOiBbCiAgICAgICAgewogICAgICAgICAgInR5cGUiOiAiaW5zZWN1cmVBY2NlcHRBbnl0aGluZyIKICAgICAgICB9CiAgICAgIF0KICAgIH0KICB9Cn0K | ||
| mode: 420 | ||
| overwrite: true | ||
| path: /etc/containers/policy.json |
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.