Skip to content

Commit 592bc92

Browse files
Merge pull request #4554 from QiWang19/policy-nosigstoresigned
OCPBUGS-38809: Update machine-config-daemon-pull.service to use custom policy for Podman < 4.4.1
2 parents b08fa0e + 969f3ff commit 592bc92

File tree

5 files changed

+98
-2
lines changed

5 files changed

+98
-2
lines changed

pkg/daemon/update.go

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ import (
1414
goruntime "runtime"
1515
"strconv"
1616
"strings"
17+
"sync"
1718
"syscall"
1819
"time"
1920

2021
"github.com/clarketm/json"
22+
"github.com/coreos/go-semver/semver"
2123
ign3types "github.com/coreos/ignition/v2/config/v3_4/types"
2224
corev1 "k8s.io/api/core/v1"
2325
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -2548,7 +2550,11 @@ func (dn *Daemon) InplaceUpdateViaNewContainer(target string) error {
25482550

25492551
systemdPodmanArgs := []string{"--unit", "machine-config-daemon-update-rpmostree-via-container", "-p", "EnvironmentFile=-/etc/mco/proxy.env", "--collect", "--wait", "--", "podman"}
25502552
pullArgs := append([]string{}, systemdPodmanArgs...)
2551-
pullArgs = append(pullArgs, "pull", "--authfile", "/var/lib/kubelet/config.json", target)
2553+
pullArgs = append(pullArgs, "pull", "--authfile", "/var/lib/kubelet/config.json")
2554+
if !podmanSupportsSigstore() {
2555+
pullArgs = append(pullArgs, "--signature-policy", "/etc/machine-config-daemon/policy-for-old-podman.json")
2556+
}
2557+
pullArgs = append(pullArgs, target)
25522558
err = runCmdSync("systemd-run", pullArgs...)
25532559
if err != nil {
25542560
return err
@@ -2684,6 +2690,35 @@ func runCmdSync(cmdName string, args ...string) error {
26842690
return nil
26852691
}
26862692

2693+
var (
2694+
podmanSigstoreSupported sync.Once
2695+
podmanSigstoreSupportedValue bool
2696+
)
2697+
2698+
func podmanSupportsSigstore() bool {
2699+
podmanSigstoreSupported.Do(func() {
2700+
// https://issues.redhat.com/browse/OCPBUGS-38809 failed for base image 4.11 or older, OCP 4.12 is with podman 4.4.1
2701+
// returns false if podman version is less than 4.4.1
2702+
cmd := exec.Command("podman", "version", "-f", "{{.APIVersion}}")
2703+
out, err := cmd.CombinedOutput()
2704+
if err != nil {
2705+
klog.Errorf("failed to run podman version: %v", err)
2706+
podmanSigstoreSupportedValue = false
2707+
return
2708+
}
2709+
sigstorePodman := "4.4.1"
2710+
// Example version format: 5.3.0-rc1
2711+
imgPodmanVersion, err := semver.NewVersion(strings.TrimSpace(string(out)))
2712+
if err != nil {
2713+
klog.Errorf("failed to parse podman version: %v", err)
2714+
podmanSigstoreSupportedValue = false
2715+
return
2716+
}
2717+
podmanSigstoreSupportedValue = imgPodmanVersion.Compare(*semver.New(sigstorePodman)) >= 0
2718+
})
2719+
return podmanSigstoreSupportedValue
2720+
}
2721+
26872722
// Log a message to the systemd journal as well as our stdout
26882723
func logSystem(format string, a ...interface{}) {
26892724
message := fmt.Sprintf(format, a...)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
mode: 0755
2+
path: "/etc/machine-config-daemon/generate_podman_policy_args.sh"
3+
contents:
4+
inline: |
5+
#!/bin/bash
6+
7+
# Extract Podman version and determine the signature policy
8+
/usr/bin/podman -v | /bin/awk '{
9+
split($3, version, "-");
10+
clean_version = version[1];
11+
12+
split(clean_version, current, /\./);
13+
split("4.4.1", target, /\./);
14+
15+
for (i = 1; i <= 3; i++) {
16+
if ((current[i] + 0) < (target[i] + 0)) {
17+
print "--signature-policy /etc/machine-config-daemon/policy-for-old-podman.json";
18+
exit;
19+
} else if ((current[i] + 0) > (target[i] + 0)) {
20+
exit;
21+
}
22+
}
23+
}' > /tmp/podman_policy_args

templates/common/_base/units/machine-config-daemon-pull.service.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ contents: |
1515
[Service]
1616
Type=oneshot
1717
RemainAfterExit=yes
18-
ExecStart=/bin/sh -c "while ! /usr/bin/podman pull --authfile=/var/lib/kubelet/config.json '{{ .Images.machineConfigOperator }}'; do sleep 1; done"
18+
ExecStartPre=/etc/machine-config-daemon/generate_podman_policy_args.sh
19+
ExecStart=/bin/sh -c "while ! /usr/bin/podman pull $(cat /tmp/podman_policy_args) --authfile=/var/lib/kubelet/config.json '{{ .Images.machineConfigOperator }}'; do sleep 1; done"
20+
1921
{{if .Proxy -}}
2022
EnvironmentFile=/etc/mco/proxy.env
2123
{{end -}}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
mode: 0644
2+
path: "/etc/machine-config-daemon/policy-for-old-podman.json"
3+
contents:
4+
inline: |
5+
{
6+
"default": [
7+
{
8+
"type": "insecureAcceptAnything"
9+
}
10+
],
11+
"transports":
12+
{
13+
"docker-daemon":
14+
{
15+
"": [{"type":"insecureAcceptAnything"}]
16+
}
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
mode: 0644
2+
path: "/etc/machine-config-daemon/policy-for-old-podman.json"
3+
contents:
4+
inline: |
5+
{
6+
"default": [
7+
{
8+
"type": "insecureAcceptAnything"
9+
}
10+
],
11+
"transports":
12+
{
13+
"docker-daemon":
14+
{
15+
"": [{"type":"insecureAcceptAnything"}]
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)