-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add set-security-context-read-only-root-filesystem as a feature flag
Prior to this change it was not possible to set readOnlyRootFilesystem for tekton pipeline containers. This change allows users to set readOnlyRootFilesystem in container securityContext for all containers. Aligns tekton with industry best practices for kuberenetes security, such as Azure Kubernetes Services deployment safeguards.
- Loading branch information
1 parent
8c3d09f
commit acd8516
Showing
15 changed files
with
306 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
Copyright 2024 The Tekton Authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package pod | ||
|
||
import ( | ||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
var ( | ||
// Used in security context of pod init containers | ||
allowPrivilegeEscalation = false | ||
runAsNonRoot = true | ||
readOnlyRootFilesystem = true | ||
|
||
// LinuxSecurityContext allow init containers to run in namespaces | ||
// with "restricted" pod security admission | ||
// See https://kubernetes.io/docs/concepts/security/pod-security-standards/#restricted | ||
LinuxSecurityContext = &corev1.SecurityContext{ | ||
AllowPrivilegeEscalation: &allowPrivilegeEscalation, | ||
Capabilities: &corev1.Capabilities{ | ||
Drop: []corev1.Capability{"ALL"}, | ||
}, | ||
RunAsNonRoot: &runAsNonRoot, | ||
SeccompProfile: &corev1.SeccompProfile{ | ||
Type: corev1.SeccompProfileTypeRuntimeDefault, | ||
}, | ||
} | ||
WindowsSecurityContext = &corev1.SecurityContext{ | ||
RunAsNonRoot: &runAsNonRoot, | ||
} | ||
) | ||
|
||
// SecurityContext defines AffinityAssistant container configuration | ||
type SecurityContext struct { | ||
SetSecurityContext bool | ||
SetReadOnlyRootFilesystem bool | ||
} | ||
|
||
func (c SecurityContext) GetSecurityContext(isWindows bool) *corev1.SecurityContext { | ||
if isWindows { | ||
return WindowsSecurityContext | ||
} | ||
|
||
if !c.SetReadOnlyRootFilesystem { | ||
return LinuxSecurityContext | ||
} | ||
|
||
securityContext := LinuxSecurityContext.DeepCopy() | ||
securityContext.ReadOnlyRootFilesystem = &readOnlyRootFilesystem | ||
return securityContext | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.