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

Fix logrotate user in UBI images #6052

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion build/images/ovs/Dockerfile.ubi
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ RUN cd /tmp/openvswitch* && \
sed -e "s/@VERSION@/$OVS_VERSION/" rhel/openvswitch-fedora.spec.in > /tmp/ovs.spec && \
yum-builddep -y /tmp/ovs.spec && ./boot.sh && \
./configure --prefix=/usr --localstatedir=/var --sysconfdir=/etc && \
make rpm-fedora && mkdir -p /tmp/ovs-rpms && \
# logrotate needs to run as the same user as OVS to get the proper permissions of log files.
# As Antrea runs OVS as root, we disable libcapng to make logrotate also run as root.
# See https://github.com/openvswitch/ovs/blob/v2.17.7/rhel/openvswitch-fedora.spec.in#L26-L27.
RPMBUILD_OPT="--without libcapng" make rpm-fedora && mkdir -p /tmp/ovs-rpms && \
Copy link
Member

Choose a reason for hiding this comment

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

Is there a public reference that documents how it fixes the issue? And better to add a comment as it can't be easily seen from the code itself.
Ideally the comment should also the other impacts of disabling libcapng if there are any.

Copy link
Contributor Author

@xliuxu xliuxu Mar 4, 2024

Choose a reason for hiding this comment

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

It is described in https://github.com/openvswitch/ovs/blob/v2.17.9/rhel/openvswitch-fedora.spec.in#L26.

If libcap-ng isn't available and there is no need for running OVS as regular user, specify the '--without libcapng'

There should be no side effects as this option only skips adding user/group and changing folder owners for openvswitch.

Not linking with libcapng will cause the OVS daemon to fail when using the --user option, as explained in openvswitch/ovs@2ff63ae. If this is not ideal, we might need to sed the logrotate config afterwards to use the root user.

Copy link
Member

Choose a reason for hiding this comment

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

We don't set --user option when running OVS, right? If so, I think we could just set --without libcapng. We should add comment for reference in the future, including the link, the purpose, and the side effect.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We did not use --user option ( --ovs-user option of ovs-ctl in start_ovs) in Antrea.
I will add a comment for this change.

mv /tmp/openvswitch-$OVS_VERSION/rpm/rpmbuild/RPMS/*/*.rpm /tmp/ovs-rpms && \
rm -rf /tmp/openvswitch*

Expand Down
12 changes: 12 additions & 0 deletions test/e2e/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func TestBasic(t *testing.T) {
t.Run("testDeletePreviousRoundFlowsOnStartup", func(t *testing.T) { testDeletePreviousRoundFlowsOnStartup(t, data) })
t.Run("testGratuitousARP", func(t *testing.T) { testGratuitousARP(t, data, data.testNamespace) })
t.Run("testClusterIdentity", func(t *testing.T) { testClusterIdentity(t, data) })
t.Run("testLogRotate", func(t *testing.T) { testLogRotate(t, data) })
}

// testPodAssignIP verifies that Antrea allocates IP addresses properly to new Pods. It does this by
Expand Down Expand Up @@ -892,3 +893,14 @@ func testClusterIdentity(t *testing.T, data *TestData) {
assert.NoError(t, err, "Failed to retrieve cluster identity information within %v", timeout)
assert.NotEqual(t, uuid.Nil, clusterUUID)
}

func testLogRotate(t *testing.T, data *TestData) {
nodeName := nodeName(0)
podName := getAntreaPodName(t, data, nodeName)
cmd := []string{"logrotate", "-vf", "/etc/logrotate.d/openvswitch-switch"}
stdout, stderr, err := data.RunCommandFromPod(antreaNamespace, podName, ovsContainerName, cmd)
if err != nil {
t.Fatalf("Error when running logrotate command in Pod '%s': %v, stdout: %s, stderr: %s", podName, err, stdout, stderr)
}
t.Logf("Successfully ran logrotate command in Pod '%s': stdout: %s, stderr: %s", podName, stdout, stderr)
}
Loading