Skip to content

Commit

Permalink
Validate sandbox and container metadata
Browse files Browse the repository at this point in the history
We pre-validate the container metadata before creation the
sandbox/container.

Fixes kubernetes-sigs#1273

Signed-off-by: Sascha Grunert <[email protected]>
  • Loading branch information
saschagrunert committed Oct 9, 2023
1 parent 05719b3 commit d96416a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cmd/crictl/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ func loadContainerConfig(path string) (*pb.ContainerConfig, error) {
if err := utilyaml.NewYAMLOrJSONDecoder(f, 4096).Decode(&config); err != nil {
return nil, err
}

if config.Metadata == nil {
return nil, errors.New("metadata is not set")
} else if config.Metadata.Name == "" {
return nil, fmt.Errorf("name is not in metadata %q", config.Metadata)
}

return &config, nil
}

Expand All @@ -166,6 +173,13 @@ func loadPodSandboxConfig(path string) (*pb.PodSandboxConfig, error) {
if err := utilyaml.NewYAMLOrJSONDecoder(f, 4096).Decode(&config); err != nil {
return nil, err
}

if config.Metadata == nil {
return nil, errors.New("metadata is not set")
} else if config.Metadata.Name == "" || config.Metadata.Namespace == "" || config.Metadata.Uid == "" {
return nil, fmt.Errorf("name, namespace or uid is not in metadata %q", config.Metadata)
}

return &config, nil
}

Expand Down

0 comments on commit d96416a

Please sign in to comment.