| 
									
										
										
										
											2022-07-06 17:14:06 +08:00
										 |  |  | //go:build seccomp && linux
 | 
					
						
							| 
									
										
										
										
											2018-06-26 02:50:52 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | package buildah | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2022-07-06 17:14:06 +08:00
										 |  |  | 	"fmt" | 
					
						
							| 
									
										
										
										
											2022-11-15 00:22:45 +08:00
										 |  |  | 	"os" | 
					
						
							| 
									
										
										
										
											2018-06-26 02:50:52 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/opencontainers/runtime-spec/specs-go" | 
					
						
							| 
									
										
										
										
											2025-08-29 20:55:12 +08:00
										 |  |  | 	"go.podman.io/common/pkg/seccomp" | 
					
						
							| 
									
										
										
										
											2018-06-26 02:50:52 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func setupSeccomp(spec *specs.Spec, seccompProfilePath string) error { | 
					
						
							|  |  |  | 	switch seccompProfilePath { | 
					
						
							|  |  |  | 	case "unconfined": | 
					
						
							|  |  |  | 		spec.Linux.Seccomp = nil | 
					
						
							|  |  |  | 	case "": | 
					
						
							|  |  |  | 		seccompConfig, err := seccomp.GetDefaultProfile(spec) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2022-07-06 17:14:06 +08:00
										 |  |  | 			return fmt.Errorf("loading default seccomp profile failed: %w", err) | 
					
						
							| 
									
										
										
										
											2018-06-26 02:50:52 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		spec.Linux.Seccomp = seccompConfig | 
					
						
							|  |  |  | 	default: | 
					
						
							| 
									
										
										
										
											2022-11-15 00:22:45 +08:00
										 |  |  | 		seccompProfile, err := os.ReadFile(seccompProfilePath) | 
					
						
							| 
									
										
										
										
											2018-06-26 02:50:52 +08:00
										 |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2022-09-18 18:36:08 +08:00
										 |  |  | 			return fmt.Errorf("opening seccomp profile failed: %w", err) | 
					
						
							| 
									
										
										
										
											2018-06-26 02:50:52 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		seccompConfig, err := seccomp.LoadProfile(string(seccompProfile), spec) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2022-07-06 17:14:06 +08:00
										 |  |  | 			return fmt.Errorf("loading seccomp profile (%s) failed: %w", seccompProfilePath, err) | 
					
						
							| 
									
										
										
										
											2018-06-26 02:50:52 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		spec.Linux.Seccomp = seccompConfig | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return nil | 
					
						
							|  |  |  | } |