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

Conversation

xliuxu
Copy link
Contributor

@xliuxu xliuxu commented Mar 4, 2024

Logrotate will run as the user openvswitch, but we start the OVS daemon as the root user. We can disable this behavior by specifying --without libcapng in RPM builds.

Fixes: #6046

@xliuxu xliuxu added the action/backport Indicates a PR that requires backports. label Mar 4, 2024
@tnqn tnqn added the action/release-note Indicates a PR that should be included in release notes. label Mar 4, 2024
@@ -32,7 +32,7 @@ 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 && \
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.

Comment on lines 36 to 37
# Antrea will run OVS and logrotate as the root user. Disabling libcapng helps
# to skip configuring the user and group for OVS and logrotate.
Copy link
Member

Choose a reason for hiding this comment

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

Before this change, OVS runs as openvswitch, which user logrotate uses?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without this change, OVS runs as root but logrorate will su to openvswitch when performing log rotation. We did not use the --ovs-user option to specify the OVS user.

Copy link
Member

Choose a reason for hiding this comment

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

Could you help me understand why the issue doesn't exist in ubuntu image, where I see OVS also runs as root?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For OVS deb packages the logrotate configuration does not switch users before rotation by default.
https://github.com/openvswitch/ovs/blob/v2.17.9/debian/openvswitch-switch.logrotate#L2
But the configuration of rpm packages will switch to non-root users if libcap is linked.
The line https://github.com/openvswitch/ovs/blob/v2.17.9/rhel/etc_logrotate.d_openvswitch#L9 will be changed in https://github.com/openvswitch/ovs/blob/v2.17.9/rhel/openvswitch-fedora.spec.in#L325

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the explanation. I feel we could rephrase it a little:

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated. Thanks!

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.

Fixes: antrea-io#6046

Signed-off-by: Xu Liu <xliu2@vmware.com>
Copy link
Member

@tnqn tnqn left a comment

Choose a reason for hiding this comment

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

LGTM, let's also check if the solution makes sense to @antoninbas

@antoninbas
Copy link
Contributor

/skip-all

@antoninbas antoninbas merged commit 23eda62 into antrea-io:main Mar 8, 2024
48 of 53 checks passed
@tnqn
Copy link
Member

tnqn commented Mar 11, 2024

@xliuxu could you backport it to 1.13-1.15?

xliuxu added a commit to xliuxu/antrea that referenced this pull request Mar 11, 2024
logrotate needs to run as the same user as OVS to get the proper
permissions for log files. As Antrea runs OVS as root, we disable
libcapng to make logrotate also run as root.

Fixes: antrea-io#6046

Signed-off-by: Xu Liu <xliu2@vmware.com>
xliuxu added a commit to xliuxu/antrea that referenced this pull request Mar 11, 2024
logrotate needs to run as the same user as OVS to get the proper
permissions for log files. As Antrea runs OVS as root, we disable
libcapng to make logrotate also run as root.

Fixes: antrea-io#6046

Signed-off-by: Xu Liu <xliu2@vmware.com>
xliuxu added a commit to xliuxu/antrea that referenced this pull request Mar 11, 2024
logrotate needs to run as the same user as OVS to get the proper
permissions for log files. As Antrea runs OVS as root, we disable
libcapng to make logrotate also run as root.

Fixes: antrea-io#6046

Signed-off-by: Xu Liu <xliu2@vmware.com>
@xliuxu
Copy link
Contributor Author

xliuxu commented Mar 11, 2024

@xliuxu could you backport it to 1.13-1.15?

Done. Thanks!

@xliuxu xliuxu deleted the xliu2/fix_ubi_logrotate branch March 11, 2024 03:42
tnqn pushed a commit that referenced this pull request Mar 11, 2024
logrotate needs to run as the same user as OVS to get the proper
permissions for log files. As Antrea runs OVS as root, we disable
libcapng to make logrotate also run as root.

Fixes: #6046

Signed-off-by: Xu Liu <xliu2@vmware.com>
tnqn pushed a commit that referenced this pull request Mar 11, 2024
logrotate needs to run as the same user as OVS to get the proper
permissions for log files. As Antrea runs OVS as root, we disable
libcapng to make logrotate also run as root.

Fixes: #6046

Signed-off-by: Xu Liu <xliu2@vmware.com>
tnqn pushed a commit that referenced this pull request Mar 11, 2024
logrotate needs to run as the same user as OVS to get the proper
permissions for log files. As Antrea runs OVS as root, we disable
libcapng to make logrotate also run as root.

Fixes: #6046

Signed-off-by: Xu Liu <xliu2@vmware.com>
xliuxu added a commit to xliuxu/antrea that referenced this pull request Mar 13, 2024
This change adds back the default RPMBUILD_OPT option to disable
unnecessary tests when building OVS rpm packages, which was
previously overwritten in antrea-io#6052.

Signed-off-by: Xu Liu <xu.liu@broadcom.com>
xliuxu added a commit to xliuxu/antrea that referenced this pull request Mar 13, 2024
This change adds back the default `RPMBUILD_OPT` to disable
unnecessary tests when building OVS rpm packages, which was
previously overwritten in antrea-io#6052.

Signed-off-by: Xu Liu <xu.liu@broadcom.com>
xliuxu added a commit to xliuxu/antrea that referenced this pull request Mar 13, 2024
This change adds back the default `RPMBUILD_OPT` to disable
unnecessary tests when building OVS rpm packages, which was
previously overwritten in antrea-io#6052.

Signed-off-by: Xu Liu <xu.liu@broadcom.com>
antoninbas pushed a commit that referenced this pull request Mar 14, 2024
This change adds back the default `RPMBUILD_OPT` to disable
unnecessary tests when building OVS rpm packages, which was
previously overwritten in #6052.

Signed-off-by: Xu Liu <xu.liu@broadcom.com>
luolanzone pushed a commit to luolanzone/antrea that referenced this pull request Mar 27, 2024
logrotate needs to run as the same user as OVS to get the proper
permissions for log files. As Antrea runs OVS as root, we disable
libcapng to make logrotate also run as root.

Fixes: antrea-io#6046

Signed-off-by: Xu Liu <xliu2@vmware.com>
luolanzone pushed a commit to luolanzone/antrea that referenced this pull request Jun 14, 2024
This change adds back the default `RPMBUILD_OPT` to disable
unnecessary tests when building OVS rpm packages, which was
previously overwritten in antrea-io#6052.

Signed-off-by: Xu Liu <xu.liu@broadcom.com>
luolanzone pushed a commit to luolanzone/antrea that referenced this pull request Jun 14, 2024
This change adds back the default `RPMBUILD_OPT` to disable
unnecessary tests when building OVS rpm packages, which was
previously overwritten in antrea-io#6052.

Signed-off-by: Xu Liu <xu.liu@broadcom.com>
tnqn pushed a commit that referenced this pull request Jun 14, 2024
This change adds back the default `RPMBUILD_OPT` to disable
unnecessary tests when building OVS rpm packages, which was
previously overwritten in #6052.

Signed-off-by: Xu Liu <xu.liu@broadcom.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action/backport Indicates a PR that requires backports. action/release-note Indicates a PR that should be included in release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Antrea ovs crashes everyday at 00:0x
3 participants