-
Notifications
You must be signed in to change notification settings - Fork 562
(psa) allow legacy Catalogsources to run in non-restrcted namespaces #2845
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -182,11 +182,7 @@ func Pod(source *operatorsv1alpha1.CatalogSource, name string, image string, saN | |
}, | ||
}, | ||
SecurityContext: &corev1.SecurityContext{ | ||
ReadOnlyRootFilesystem: pointer.Bool(false), | ||
AllowPrivilegeEscalation: pointer.Bool(false), | ||
Capabilities: &corev1.Capabilities{ | ||
Drop: []corev1.Capability{"ALL"}, | ||
}, | ||
bparees marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ReadOnlyRootFilesystem: pointer.Bool(false), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to read the SQL Index DB which is the root file system so that needs to be true (ihmo) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
this needs to be false if we need to write to it (which i think we do, because i think the legacy catalogs write to the It does not mean "set this to true if you need to read from the filesystem", you set it to true when you explicitly want to ensure nothing
bparees marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
ImagePullPolicy: pullPolicy, | ||
TerminationMessagePolicy: corev1.TerminationMessageFallbackToLogsOnError, | ||
|
@@ -195,19 +191,18 @@ func Pod(source *operatorsv1alpha1.CatalogSource, name string, image string, saN | |
NodeSelector: map[string]string{ | ||
"kubernetes.io/os": "linux", | ||
}, | ||
SecurityContext: &corev1.PodSecurityContext{ | ||
SeccompProfile: &corev1.SeccompProfile{ | ||
Type: corev1.SeccompProfileTypeRuntimeDefault, | ||
}, | ||
}, | ||
ServiceAccountName: saName, | ||
}, | ||
} | ||
|
||
if runAsUser > 0 { | ||
pod.Spec.SecurityContext.RunAsUser = &runAsUser | ||
pod.Spec.SecurityContext.RunAsNonRoot = pointer.Bool(true) | ||
if source.Spec.GrpcPodConfig != nil { | ||
if source.Spec.GrpcPodConfig.SecurityContextConfig == operatorsv1alpha1.Restricted { | ||
addSecurityContext(pod, runAsUser) | ||
} | ||
} else { | ||
addSecurityContext(pod, runAsUser) | ||
} | ||
|
||
// Override scheduling options if specified | ||
if source.Spec.GrpcPodConfig != nil { | ||
grpcPodConfig := source.Spec.GrpcPodConfig | ||
|
@@ -256,3 +251,19 @@ func hashPodSpec(spec corev1.PodSpec) string { | |
hashutil.DeepHashObject(hasher, &spec) | ||
return rand.SafeEncodeString(fmt.Sprint(hasher.Sum32())) | ||
} | ||
|
||
func addSecurityContext(pod *corev1.Pod, runAsUser int64) { | ||
pod.Spec.Containers[0].SecurityContext.AllowPrivilegeEscalation = pointer.Bool(false) | ||
pod.Spec.Containers[0].SecurityContext.Capabilities = &corev1.Capabilities{ | ||
Drop: []corev1.Capability{"ALL"}, | ||
} | ||
pod.Spec.SecurityContext = &corev1.PodSecurityContext{ | ||
SeccompProfile: &corev1.SeccompProfile{ | ||
Type: corev1.SeccompProfileTypeRuntimeDefault, | ||
}, | ||
} | ||
if runAsUser > 0 { | ||
pod.Spec.SecurityContext.RunAsUser = &runAsUser | ||
pod.Spec.SecurityContext.RunAsNonRoot = pointer.Bool(true) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, because we need to read root file system, they away to grant permissions to that is setting true to AllowPrivilegeEscalation
And RunAsUser=0 is not required ( we need an user that have permissions to do what needs to be done as before, and if the bt setting true there the user will be part of the root group and have the same permissions.
Btw, RunAsUser=0 might not work on OCP (it will depends of the namespace and it probably will raise the error invalid value in the range)
c/c @perdasilva
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does "AllowPrivilegeEscalation" have to do w/ reading the root filesystem?
allow privilege escalation means you can run a setuid binary or otherwise allow a process to "become root", does the opm registry binary do so?
I would simply expect the index.db to be readable (by any uid), or in general we should be ensuring that the container is run w/ the appropriate uid and fsgroup to allow us to read (and write, if necessary) to the appropriate directories. None of that should require privilege escalation.
https://kubernetes.io/docs/tasks/configure-pod-container/security-context/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That'd mean we don't need to specify
AllowPrivilegeEscalation
at all then, since opm doesn't require to be root to read or write to the sqllite db, and also in 4.10 we didn't specifyAllowPrivilegeEscalation
either (and opm not requiring to be root hasn't changed since 4.10, and is unlikely to change either).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fyi was updating the tests to use image hosted in the quay.io/olmtest registry instead of my personal registry, so took that opportunity to remove
AllowPrivilegeEscalation:true
too. cc: @perdasilva now I'm happy with the PR going in :)