- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.1k
Add FreeBSD container support #7727
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
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            11 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      2f4bc00
              
                internal/config/device: add stub for DevicesFromAnnotation
              
              
                dfr 29a85ac
              
                internal/linklogs: add stub for freebsd
              
              
                dfr 68091fe
              
                internal/factory/container: make (*container).SelinuxLabel platform-s…
              
              
                dfr 7f104e5
              
                internal/factory/container: make SpecAddNamespaces platform-specific
              
              
                dfr 286e7e2
              
                internal/factory/container: add no-op stub for SpecAddDevices on FreeBSD
              
              
                dfr 5035c19
              
                server: factor out creating the security context
              
              
                dfr 20b17df
              
                server: add no-op stub for makeOCIConfigurationRootless
              
              
                dfr e533ab2
              
                server: factor out adding sysfs mounts
              
              
                dfr 7cdfc79
              
                server: factor out adding /dev/shm mount
              
              
                dfr 3c7337f
              
                server: move createSandboxContainer and related functions to containe…
              
              
                dfr 8287e41
              
                server: don't dereference Config.Linux if it is nil
              
              
                dfr File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,5 @@ | ||
| package container | ||
|  | ||
| func (c *container) SelinuxLabel(sboxLabel string) ([]string, error) { | ||
| return []string{}, nil | ||
| } | 
  
    
      This file contains hidden or 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,41 @@ | ||
| package container | ||
|  | ||
| import ( | ||
| "strings" | ||
|  | ||
| "github.com/opencontainers/selinux/go-selinux/label" | ||
|  | ||
| "github.com/cri-o/cri-o/utils" | ||
| ) | ||
|  | ||
| // SelinuxLabel returns the container's SelinuxLabel | ||
| // it takes the sandbox's label, which it falls back upon. | ||
| func (c *container) SelinuxLabel(sboxLabel string) ([]string, error) { | ||
| selinuxConfig := c.config.Linux.SecurityContext.SelinuxOptions | ||
|  | ||
| labels := map[string]string{} | ||
|  | ||
| labelOptions, err := label.DupSecOpt(sboxLabel) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|  | ||
| for _, r := range labelOptions { | ||
| k := strings.Split(r, ":")[0] | ||
| labels[k] = r | ||
| } | ||
|  | ||
| if selinuxConfig != nil { | ||
| for _, r := range utils.GetLabelOptions(selinuxConfig) { | ||
| k := strings.Split(r, ":")[0] | ||
| labels[k] = r | ||
| } | ||
| } | ||
|  | ||
| ret := []string{} | ||
| for _, v := range labels { | ||
| ret = append(ret, v) | ||
| } | ||
|  | ||
| return ret, nil | ||
| } | ||
  
    
      This file contains hidden or 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,9 @@ | ||
| package container | ||
|  | ||
| import ( | ||
| devicecfg "github.com/cri-o/cri-o/internal/config/device" | ||
| ) | ||
|  | ||
| func (c *container) SpecAddDevices(configuredDevices, annotationDevices []devicecfg.Device, privilegedWithoutHostDevices, enableDeviceOwnershipFromSecurityContext bool) error { | ||
| return nil | ||
| } | 
  
    
      This file contains hidden or 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 | 
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| //go:build !linux | ||
| //go:build !linux && !freebsd | ||
|  | ||
| package container | ||
|  | ||
|  | ||
  
    
      This file contains hidden or 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 | 
|---|---|---|
| @@ -1,106 +1,9 @@ | ||
| package container | ||
|  | ||
| import ( | ||
| "errors" | ||
| "fmt" | ||
|  | ||
| rspec "github.com/opencontainers/runtime-spec/specs-go" | ||
| "github.com/opencontainers/runtime-tools/generate" | ||
| types "k8s.io/cri-api/pkg/apis/runtime/v1" | ||
|  | ||
| "github.com/cri-o/cri-o/internal/config/nsmgr" | ||
| "github.com/cri-o/cri-o/internal/lib/namespace" | ||
| oci "github.com/cri-o/cri-o/internal/oci" | ||
| "github.com/cri-o/cri-o/pkg/config" | ||
| ) | ||
|  | ||
| func (c *container) SpecAddNamespaces(sb SandboxIFace, targetCtr *oci.Container, serverConfig *config.Config) error { | ||
| // Join the namespace paths for the pod sandbox container. | ||
| if err := ConfigureGeneratorGivenNamespacePaths(sb.NamespacePaths(), &c.spec); err != nil { | ||
| return fmt.Errorf("failed to configure namespaces in container create: %w", err) | ||
| } | ||
|  | ||
| sc := c.config.Linux.SecurityContext | ||
|  | ||
| if sc.NamespaceOptions.Network == types.NamespaceMode_NODE { | ||
| if err := c.spec.RemoveLinuxNamespace(string(rspec.NetworkNamespace)); err != nil { | ||
| return err | ||
| } | ||
| } | ||
|  | ||
| switch sc.NamespaceOptions.Pid { | ||
| case types.NamespaceMode_NODE: | ||
| // kubernetes PodSpec specify to use Host PID namespace | ||
| if err := c.spec.RemoveLinuxNamespace(string(rspec.PIDNamespace)); err != nil { | ||
| return err | ||
| } | ||
| case types.NamespaceMode_POD: | ||
| pidNsPath := sb.PidNsPath() | ||
| if pidNsPath == "" { | ||
| if sb.NamespaceOptions().Pid != types.NamespaceMode_POD { | ||
| return errors.New("pod level PID namespace requested for the container, but pod sandbox was not similarly configured, and does not have an infra container") | ||
| } | ||
|  | ||
| return errors.New("PID namespace requested, but sandbox infra container unexpectedly invalid") | ||
| } | ||
|  | ||
| if err := c.spec.AddOrReplaceLinuxNamespace(string(rspec.PIDNamespace), pidNsPath); err != nil { | ||
| return fmt.Errorf("updating container PID namespace to pod: %w", err) | ||
| } | ||
| case types.NamespaceMode_TARGET: | ||
| if targetCtr == nil { | ||
| return errors.New("target PID namespace specified with invalid target ID") | ||
| } | ||
|  | ||
| targetPID, err := targetCtr.Pid() | ||
| if err != nil { | ||
| return fmt.Errorf("target PID namespace find PID: %w", err) | ||
| } | ||
|  | ||
| ns, err := serverConfig.NamespaceManager().NamespaceFromProcEntry(targetPID, nsmgr.PIDNS) | ||
| if err != nil { | ||
| return fmt.Errorf("target PID namespace from proc: %w", err) | ||
| } | ||
|  | ||
| if err := c.spec.AddOrReplaceLinuxNamespace(string(rspec.PIDNamespace), ns.Path()); err != nil { | ||
| return fmt.Errorf("updating container PID namespace to target %s: %w", targetCtr.ID(), err) | ||
| } | ||
|  | ||
| c.pidns = ns | ||
| } | ||
|  | ||
| return nil | ||
| } | ||
|  | ||
| // ConfigureGeneratorGivenNamespacePaths takes a map of nsType -> nsPath. It configures the generator | ||
| // to add or replace the defaults to these paths. | ||
| func ConfigureGeneratorGivenNamespacePaths(managedNamespaces []*namespace.ManagedNamespace, g *generate.Generator) error { | ||
| typeToSpec := map[nsmgr.NSType]rspec.LinuxNamespaceType{ | ||
| nsmgr.IPCNS: rspec.IPCNamespace, | ||
| nsmgr.NETNS: rspec.NetworkNamespace, | ||
| nsmgr.UTSNS: rspec.UTSNamespace, | ||
| nsmgr.USERNS: rspec.UserNamespace, | ||
| } | ||
|  | ||
| for _, ns := range managedNamespaces { | ||
| // allow for empty paths, as this namespace just shouldn't be configured | ||
| if ns.Path() == "" { | ||
| continue | ||
| } | ||
|  | ||
| nsForSpec := typeToSpec[ns.Type()] | ||
| if nsForSpec == "" { | ||
| return fmt.Errorf("invalid namespace type %s", ns.Type()) | ||
| } | ||
|  | ||
| if err := g.AddOrReplaceLinuxNamespace(string(nsForSpec), ns.Path()); err != nil { | ||
| return err | ||
| } | ||
| } | ||
|  | ||
| return nil | ||
| } | ||
|  | ||
| func (c *container) PidNamespace() nsmgr.Namespace { | ||
| return c.pidns | ||
| } | 
  
    
      This file contains hidden or 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,20 @@ | ||
| package container | ||
|  | ||
| import ( | ||
| "github.com/cri-o/cri-o/internal/config/nsmgr" | ||
| oci "github.com/cri-o/cri-o/internal/oci" | ||
| "github.com/cri-o/cri-o/pkg/config" | ||
| ) | ||
|  | ||
| func (c *container) SpecAddNamespaces(sb SandboxIFace, targetCtr *oci.Container, serverConfig *config.Config) error { | ||
| // Join the namespace paths for the pod sandbox container. | ||
| managedNamespaces := sb.NamespacePaths() | ||
|  | ||
| for _, ns := range managedNamespaces { | ||
| if ns.Type() == nsmgr.NETNS { | ||
| c.Spec().AddAnnotation("org.freebsd.parentJail", ns.Path()) | ||
| } | ||
| } | ||
|  | ||
| return nil | ||
| } | 
  
    
      This file contains hidden or 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,102 @@ | ||
| package container | ||
|  | ||
| import ( | ||
| "errors" | ||
| "fmt" | ||
|  | ||
| rspec "github.com/opencontainers/runtime-spec/specs-go" | ||
| "github.com/opencontainers/runtime-tools/generate" | ||
| types "k8s.io/cri-api/pkg/apis/runtime/v1" | ||
|  | ||
| "github.com/cri-o/cri-o/internal/config/nsmgr" | ||
| "github.com/cri-o/cri-o/internal/lib/namespace" | ||
| oci "github.com/cri-o/cri-o/internal/oci" | ||
| "github.com/cri-o/cri-o/pkg/config" | ||
| ) | ||
|  | ||
| func (c *container) SpecAddNamespaces(sb SandboxIFace, targetCtr *oci.Container, serverConfig *config.Config) error { | ||
| // Join the namespace paths for the pod sandbox container. | ||
| if err := ConfigureGeneratorGivenNamespacePaths(sb.NamespacePaths(), &c.spec); err != nil { | ||
| return fmt.Errorf("failed to configure namespaces in container create: %w", err) | ||
| } | ||
|  | ||
| sc := c.config.Linux.SecurityContext | ||
|  | ||
| if sc.NamespaceOptions.Network == types.NamespaceMode_NODE { | ||
| if err := c.spec.RemoveLinuxNamespace(string(rspec.NetworkNamespace)); err != nil { | ||
| return err | ||
| } | ||
| } | ||
|  | ||
| switch sc.NamespaceOptions.Pid { | ||
| case types.NamespaceMode_NODE: | ||
| // kubernetes PodSpec specify to use Host PID namespace | ||
| if err := c.spec.RemoveLinuxNamespace(string(rspec.PIDNamespace)); err != nil { | ||
| return err | ||
| } | ||
| case types.NamespaceMode_POD: | ||
| pidNsPath := sb.PidNsPath() | ||
| if pidNsPath == "" { | ||
| if sb.NamespaceOptions().Pid != types.NamespaceMode_POD { | ||
| return errors.New("pod level PID namespace requested for the container, but pod sandbox was not similarly configured, and does not have an infra container") | ||
| } | ||
|  | ||
| return errors.New("PID namespace requested, but sandbox infra container unexpectedly invalid") | ||
| } | ||
|  | ||
| if err := c.spec.AddOrReplaceLinuxNamespace(string(rspec.PIDNamespace), pidNsPath); err != nil { | ||
| return fmt.Errorf("updating container PID namespace to pod: %w", err) | ||
| } | ||
| case types.NamespaceMode_TARGET: | ||
| if targetCtr == nil { | ||
| return errors.New("target PID namespace specified with invalid target ID") | ||
| } | ||
|  | ||
| targetPID, err := targetCtr.Pid() | ||
| if err != nil { | ||
| return fmt.Errorf("target PID namespace find PID: %w", err) | ||
| } | ||
|  | ||
| ns, err := serverConfig.NamespaceManager().NamespaceFromProcEntry(targetPID, nsmgr.PIDNS) | ||
| if err != nil { | ||
| return fmt.Errorf("target PID namespace from proc: %w", err) | ||
| } | ||
|  | ||
| if err := c.spec.AddOrReplaceLinuxNamespace(string(rspec.PIDNamespace), ns.Path()); err != nil { | ||
| return fmt.Errorf("updating container PID namespace to target %s: %w", targetCtr.ID(), err) | ||
| } | ||
|  | ||
| c.pidns = ns | ||
| } | ||
|  | ||
| return nil | ||
| } | ||
|  | ||
| // ConfigureGeneratorGivenNamespacePaths takes a map of nsType -> nsPath. It configures the generator | ||
| // to add or replace the defaults to these paths. | ||
| func ConfigureGeneratorGivenNamespacePaths(managedNamespaces []*namespace.ManagedNamespace, g *generate.Generator) error { | ||
| typeToSpec := map[nsmgr.NSType]rspec.LinuxNamespaceType{ | ||
| nsmgr.IPCNS: rspec.IPCNamespace, | ||
| nsmgr.NETNS: rspec.NetworkNamespace, | ||
| nsmgr.UTSNS: rspec.UTSNamespace, | ||
| nsmgr.USERNS: rspec.UserNamespace, | ||
| } | ||
|  | ||
| for _, ns := range managedNamespaces { | ||
| // allow for empty paths, as this namespace just shouldn't be configured | ||
| if ns.Path() == "" { | ||
| continue | ||
| } | ||
|  | ||
| nsForSpec := typeToSpec[ns.Type()] | ||
| if nsForSpec == "" { | ||
| return fmt.Errorf("invalid namespace type %s", ns.Type()) | ||
| } | ||
|  | ||
| if err := g.AddOrReplaceLinuxNamespace(string(nsForSpec), ns.Path()); err != nil { | ||
| return err | ||
| } | ||
| } | ||
|  | ||
| return nil | ||
| } | ||
  
    
      This file contains hidden or 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.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.