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

Copy SecurityContext from Containers[0] if present for PVR #8712

Merged

Conversation

sseago
Copy link
Collaborator

@sseago sseago commented Feb 20, 2025

Thank you for contributing to Velero!

Please add a summary of your change

Velero 1.15.1 added a change to set a default SecurityContext on the fs-backup InitContainer to fix a bug related to pod security standards enforcement. In an OpenShift environment, when the pod was created by a non-admin user, using this default SecurityContext with runAsUser set based on the current (velero) user breaks because this forces the openshift.io/scc annotation to the default privileged level of the velero SA.

The fix is to use the SecurityContext from the first pod container if that container has a SecurityContext set, using the default otherwise.

Does your change fix a particular issue?

Fixes #8711

Please indicate you've done the following:

Copy link

codecov bot commented Feb 20, 2025

Codecov Report

Attention: Patch coverage is 69.23077% with 4 lines in your changes missing coverage. Please review.

Project coverage is 59.46%. Comparing base (e64806a) to head (21db5f8).
Report is 18 commits behind head on main.

Files with missing lines Patch % Lines
pkg/restore/actions/pod_volume_restore_action.go 69.23% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8712      +/-   ##
==========================================
- Coverage   59.48%   59.46%   -0.03%     
==========================================
  Files         371      371              
  Lines       40191    40199       +8     
==========================================
- Hits        23909    23905       -4     
- Misses      14789    14799      +10     
- Partials     1493     1495       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

kaovilai
kaovilai previously approved these changes Feb 20, 2025
@Lyndon-Li Lyndon-Li requested a review from reasonerjt February 21, 2025 02:49
}
}
// if first container in pod has a SecurityContext set, then copy this security context
Copy link
Contributor

Choose a reason for hiding this comment

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

The log message printed in line 165 could be misleading, maybe just remove "Using default securityContext values" in the sentence?

@reasonerjt
Copy link
Contributor

@sseago This change makes sense to me, is it convenient to add a UT?

@sseago sseago dismissed stale reviews from kaovilai and shubham-pampattiwar via 21db5f8 February 24, 2025 20:25
@sseago sseago force-pushed the pod-initcontainer-securitycontext branch from 6c01dfb to 21db5f8 Compare February 24, 2025 20:25
@sseago
Copy link
Collaborator Author

sseago commented Feb 24, 2025

@reasonerjt unit test added

@blackpiglet blackpiglet merged commit ad08c7a into vmware-tanzu:main Feb 25, 2025
41 of 42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fs-backup restore on OpenShift results in wrong SCC annotation
5 participants