Skip to content

Commit

Permalink
Merge pull request #63 from phillipsj/feature/windows-changes
Browse files Browse the repository at this point in the history
Fixes various Windows specific bugs discovered during test.
  • Loading branch information
phillipsj authored Nov 5, 2021
2 parents 18e623a + 4db110c commit 7922dcc
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 23 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ require (
github.com/google/go-containerregistry v0.5.0
github.com/mattn/go-colorable v0.1.8
github.com/rancher/lasso v0.0.0-20210408231703-9ddd9378d08d
github.com/rancher/wharfie v0.3.2
github.com/rancher/wharfie v0.4.3
github.com/rancher/wrangler v0.8.0
github.com/sirupsen/logrus v1.8.1
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a
Expand Down
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,8 @@ github.com/rancher/client-go v0.21.0-rancher.1 h1:WVy7jpVmdjIRVkgXpBRlNx4jnGkLCF
github.com/rancher/client-go v0.21.0-rancher.1/go.mod h1:nNBytTF9qPFDEhoqgEPaarobC8QPae13bElIVHzIglA=
github.com/rancher/lasso v0.0.0-20210408231703-9ddd9378d08d h1:vfjPEF6M7Jf1/zK1xF7z2drLfniooKcgDQdoXO5+U7w=
github.com/rancher/lasso v0.0.0-20210408231703-9ddd9378d08d/go.mod h1:OhBBBO1pBwYp0hacWdnvSGOj+XE9yMLOLnaypIlic18=
github.com/rancher/wharfie v0.3.2 h1:HWXMow09V8jjZ20uxOOnt2SvavWHpIgPF7nL8pYqdSs=
github.com/rancher/wharfie v0.3.2/go.mod h1:cb8mSczpmw7ItbPF3K1W7crWuJLVdyV49sZZuaY4BS8=
github.com/rancher/wharfie v0.4.3 h1:Ezn78XQLvfFb02NYG7IlsnCNsQo1upLYoIxAidQJans=
github.com/rancher/wharfie v0.4.3/go.mod h1:cb8mSczpmw7ItbPF3K1W7crWuJLVdyV49sZZuaY4BS8=
github.com/rancher/wrangler v0.8.0 h1:jGWr7ES0KwZU/8zB6lte0z4QB7hFcspaXPTvGmrvHok=
github.com/rancher/wrangler v0.8.0/go.mod h1:zSV5oh3+YZboilwcJmFHO3J6FZba82BTQft1b6ijx2I=
github.com/remyoudompheng/bigfft v0.0.0-20170806203942-52369c62f446/go.mod h1:uYEyJGbgTkfkS4+E/PavXkNJcbFIpEtjt2B0KDQ5+9M=
Expand Down Expand Up @@ -694,7 +694,6 @@ golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzB
golang.org/x/mod v0.1.1-0.20191209134235-331c550502dd/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.1-0.20200828183125-ce943fd02449 h1:xUIPaMhvROX9dhPvRCenIJtU78+lbEenGbgqB5hfHCQ=
golang.org/x/mod v0.3.1-0.20200828183125-ce943fd02449/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20180112015858-5ccada7d0a7b/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down Expand Up @@ -884,7 +883,6 @@ golang.org/x/tools v0.0.0-20200505023115-26f46d2f7ef8/go.mod h1:EkVYQZoAsY45+roY
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20200916195026-c9a70fc28ce3/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.0 h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY=
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down Expand Up @@ -1018,7 +1016,6 @@ k8s.io/apiserver v0.21.0/go.mod h1:w2YSn4/WIwYuxG5zJmcqtRdtqgW/J2JRgFAqps3bBpg=
k8s.io/cli-runtime v0.21.0/go.mod h1:XoaHP93mGPF37MkLbjGVYqg3S1MnsFdKtiA/RZzzxOo=
k8s.io/cloud-provider v0.21.0/go.mod h1:z17TQgu3JgUFjcgby8sj5X86YdVK5Pbt+jm/eYMZU9M=
k8s.io/cluster-bootstrap v0.21.0/go.mod h1:rs7i1JpBCa56YNmnYxFJuoUghIwpMzDidY8ZmqiRnrQ=
k8s.io/code-generator v0.21.0 h1:LGWJOvkbBNpuRBqBRXUjzfvymUh7F/iR2KDpwLnqCM4=
k8s.io/code-generator v0.21.0/go.mod h1:hUlps5+9QaTrKx+jiM4rmq7YmH8wPOIko64uZCHDh6Q=
k8s.io/component-base v0.21.0 h1:tLLGp4BBjQaCpS/KiuWh7m2xqvAdsxLm4ATxHSe5Zpg=
k8s.io/component-base v0.21.0/go.mod h1:qvtjz6X0USWXbgmbfXR+Agik4RZ3jv2Bgr5QnZzdPYw=
Expand All @@ -1029,7 +1026,6 @@ k8s.io/csi-translation-lib v0.21.0/go.mod h1:edq+UMpgqEx3roTuGF/03uIuSOsI986jtu6
k8s.io/gengo v0.0.0-20200114144118-36b2048a9120/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
k8s.io/gengo v0.0.0-20201113003025-83324d819ded/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E=
k8s.io/gengo v0.0.0-20201214224949-b6c5ce23f027 h1:Uusb3oh8XcdzDF/ndlI4ToKTYVlkCSJP39SRY2mfRAw=
k8s.io/gengo v0.0.0-20201214224949-b6c5ce23f027/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E=
k8s.io/heapster v1.2.0-beta.1/go.mod h1:h1uhptVXMwC8xtZBYsPXKVi8fpdlYkTs6k949KozGrM=
k8s.io/klog v0.3.0/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=
Expand Down
11 changes: 0 additions & 11 deletions pkg/applyinator/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,3 @@ func parsePerm(perm string) (os.FileMode, error) {
}
return os.FileMode(parsedPerm), nil
}

func reconcileFilePermissions(path string, uid int, gid int, perm os.FileMode) error {
logrus.Debugf("reconciling file permissions for %s to %d:%d %d", path, uid, gid, perm)
if err := os.Chmod(path, perm); err != nil {
return err
}
if err := os.Chown(path, uid, gid); err != nil {
return err
}
return nil
}
19 changes: 19 additions & 0 deletions pkg/applyinator/file_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//go:build !windows
// +build !windows

package applyinator

import (
"os"

"github.com/sirupsen/logrus"
)

// reconcileFilePermissions abstracts out the file permissions checks that only works on Linux.
func reconcileFilePermissions(path string, uid int, gid int, perm os.FileMode) error {
logrus.Debugf("reconciling file permissions for %s to %d:%d %d", path, uid, gid, perm)
if err := os.Chmod(path, perm); err != nil {
return err
}
return os.Chown(path, uid, gid)
}
16 changes: 16 additions & 0 deletions pkg/applyinator/file_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//go:build windows
// +build windows

package applyinator

import (
"os"

"github.com/sirupsen/logrus"
)

// reconcileFilePermissions abstracts out the file permissions checks and are a no op on Windows
func reconcileFilePermissions(path string, uid int, gid int, perm os.FileMode) error {
logrus.Debugf("windows file permissions for %s will not be reconciled to %d:%d %d", path, uid, gid, perm)
return nil
}
4 changes: 2 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ func Parse(path string, result interface{}) error {
return fmt.Errorf("error gathering file information for file %s: %w", path, err)
}

if fi.Mode().Perm() != 0600 {
return fmt.Errorf("file %s had permission %#o which was not expected 0600", path, fi.Mode().Perm())
if err := permissionsCheck(fi, path); err != nil {
return err
}

if err := pathOwnedByRoot(fi, path); err != nil {
Expand Down
10 changes: 10 additions & 0 deletions pkg/config/config_unix.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !windows
// +build !windows

package config
Expand All @@ -9,6 +10,7 @@ import (
"syscall"
)

// pathOwnedByRoot is abstracted out for Linux as root is a Linux only concept.
func pathOwnedByRoot(fi os.FileInfo, path string) error {
stat, ok := fi.Sys().(*syscall.Stat_t)
if !ok {
Expand All @@ -19,3 +21,11 @@ func pathOwnedByRoot(fi os.FileInfo, path string) error {
}
return nil
}

// permissionsCheck is abstracted out for Linux as root is a Linux only concept.
func permissionsCheck(fi os.FileInfo, path string) error {
if fi.Mode().Perm() != 0600 {
return fmt.Errorf("file %s had permission %#o which was not expected 0600", path, fi.Mode().Perm())
}
return nil
}
7 changes: 7 additions & 0 deletions pkg/config/config_windows.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build windows
// +build windows

package config
Expand All @@ -6,6 +7,12 @@ import (
"os"
)

// pathOwnedByRoot is abstracted out with Windows being a no op.
func pathOwnedByRoot(fi os.FileInfo, path string) error {
return nil
}

// permissionsCheck is abstracted out with Windows being a no op.
func permissionsCheck(fi os.FileInfo, path string) error {
return nil
}
13 changes: 10 additions & 3 deletions pkg/image/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import (
"fmt"
"os"
"path/filepath"
"runtime"

"github.com/google/go-containerregistry/pkg/authn"
"github.com/google/go-containerregistry/pkg/name"
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/rancher/wharfie/pkg/credentialprovider/plugin"
"github.com/rancher/wharfie/pkg/extract"
"github.com/rancher/wharfie/pkg/registries"
"github.com/rancher/wharfie/pkg/tarfile"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -110,13 +110,20 @@ func (u *Utility) Stage(destDir string, imgString string) error {

multiKeychain := authn.NewMultiKeychain(kcs...)
logrus.Infof("Pulling image %s", image.Name())
img, err = remote.Image(registry.Rewrite(image), remote.WithAuthFromKeychain(multiKeychain), remote.WithTransport(registry))
img, err = remote.Image(registry.Rewrite(image),
remote.WithAuthFromKeychain(multiKeychain),
remote.WithTransport(registry),
remote.WithPlatform(v1.Platform{
Architecture: runtime.GOARCH,
OS: runtime.GOOS,
}),
)
if err != nil {
return fmt.Errorf("%v: failed to get image %s", err, image.Name())
}
}

return extract.Extract(img, destDir)
return extractFiles(img, destDir)
}

func (u *Utility) findRegistriesYaml() string {
Expand Down
14 changes: 14 additions & 0 deletions pkg/image/util_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//go:build !windows
// +build !windows

package image

import (
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/rancher/wharfie/pkg/extract"
)

// extractFiles was extracted as method to assist with differences in Windows.
func extractFiles(img v1.Image, dir string) error {
return extract.Extract(img, dir)
}
18 changes: 18 additions & 0 deletions pkg/image/util_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//go:build windows
// +build windows

package image

import (
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/rancher/wharfie/pkg/extract"
)

// extractFiles was abstracted because Windows containers don't have a concept of a scratch container.
// So files need to be placed in a subdirectory.
func extractFiles(img v1.Image, dir string) error {
extractPaths := map[string]string{
"/Files/bin": dir,
}
return extract.ExtractDirs(img, extractPaths)
}

0 comments on commit 7922dcc

Please sign in to comment.