Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Fix RBAC and local image resolution for acorn copy (#1950)
Browse files Browse the repository at this point in the history
Signed-off-by: Grant Linville <grant@acorn.io>
  • Loading branch information
g-linville committed Jul 20, 2023
1 parent 2008864 commit e68fb04
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
34 changes: 32 additions & 2 deletions pkg/cli/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,25 @@ func (a *ImageCopy) Run(cmd *cobra.Command, args []string) error {
return err
}

if !a.AllTags {
// Check if the source argument matches the name of a local image, and use it if it does.
// If there is an error, ignore it and move on, treating the argument as a remote image name.
if _, err := c.ImageGet(cmd.Context(), args[0]); err == nil {
return a.copyLocalToRemote(cmd, c, args, creds)
}
}

source, err := name.ParseReference(args[0])
if err != nil {
return err
}

dest, err := name.ParseReference(args[1])
sourceAuth, _, err := creds.Get(cmd.Context(), source.Context().RegistryStr())
if err != nil {
return err
}

sourceAuth, _, err := creds.Get(cmd.Context(), source.Context().RegistryStr())
dest, err := name.ParseReference(args[1])
if err != nil {
return err
}
Expand All @@ -88,3 +96,25 @@ func (a *ImageCopy) Run(cmd *cobra.Command, args []string) error {

return progressbar.Print(progress)
}

func (a *ImageCopy) copyLocalToRemote(cmd *cobra.Command, c client.Client, args []string, creds *credentials.Store) error {
dest, err := name.ParseReference(args[1])
if err != nil {
return err
}

destAuth, _, err := creds.Get(cmd.Context(), dest.Context().RegistryStr())
if err != nil {
return err
}

progress, err := c.ImageCopy(cmd.Context(), args[0], args[1], &client.ImageCopyOptions{
Force: a.Force,
DestAuth: destAuth,
})
if err != nil {
return err
}

return progressbar.Print(progress)
}
1 change: 1 addition & 0 deletions pkg/roles/roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ var (
Resources: []string{
"images/push",
"images/pull",
"images/copy",
"containerreplicas/exec",
"secrets/reveal",
},
Expand Down

0 comments on commit e68fb04

Please sign in to comment.