prevent ctr from creating tags with forbidden characters
check if the target tag that is to be created using ctr image tag is valid and does not contain any forbidden characters. Signed-off-by: Akhil Mohan <makhil@vmware.com>
This commit is contained in:
parent
5c37d3827b
commit
6ec0d4a3ad
@ -24,6 +24,7 @@ import (
|
|||||||
"github.com/containerd/containerd/cmd/ctr/commands"
|
"github.com/containerd/containerd/cmd/ctr/commands"
|
||||||
"github.com/containerd/containerd/errdefs"
|
"github.com/containerd/containerd/errdefs"
|
||||||
"github.com/containerd/containerd/pkg/transfer/image"
|
"github.com/containerd/containerd/pkg/transfer/image"
|
||||||
|
"github.com/containerd/containerd/reference/docker"
|
||||||
)
|
)
|
||||||
|
|
||||||
var tagCommand = cli.Command{
|
var tagCommand = cli.Command{
|
||||||
@ -60,6 +61,9 @@ var tagCommand = cli.Command{
|
|||||||
|
|
||||||
if !context.BoolT("local") {
|
if !context.BoolT("local") {
|
||||||
for _, targetRef := range context.Args()[1:] {
|
for _, targetRef := range context.Args()[1:] {
|
||||||
|
if _, err := docker.ParseAnyReference(targetRef); err != nil {
|
||||||
|
return fmt.Errorf("error parsing reference: %q is not a valid repository/tag %v", targetRef, err)
|
||||||
|
}
|
||||||
err = client.Transfer(ctx, image.NewStore(ref), image.NewStore(targetRef))
|
err = client.Transfer(ctx, image.NewStore(ref), image.NewStore(targetRef))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -82,6 +86,9 @@ var tagCommand = cli.Command{
|
|||||||
}
|
}
|
||||||
// Support multiple references for one command run
|
// Support multiple references for one command run
|
||||||
for _, targetRef := range context.Args()[1:] {
|
for _, targetRef := range context.Args()[1:] {
|
||||||
|
if _, err := docker.ParseAnyReference(targetRef); err != nil {
|
||||||
|
return fmt.Errorf("error parsing reference: %q is not a valid repository/tag %v", targetRef, err)
|
||||||
|
}
|
||||||
image.Name = targetRef
|
image.Name = targetRef
|
||||||
// Attempt to create the image first
|
// Attempt to create the image first
|
||||||
if _, err = imageService.Create(ctx, image); err != nil {
|
if _, err = imageService.Create(ctx, image); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user