agnhost: Check symlink target's permissions for Windows

We're not interested in checking the file permissions of the
symlink itself, but it's target's permissions.
This commit is contained in:
Claudiu Belu 2021-08-27 16:00:47 -07:00
parent ab4aa182a5
commit 14708f23b5
3 changed files with 21 additions and 9 deletions

View File

@ -32,7 +32,7 @@ For example, let's consider the following `pod.yaml` file:
containers: containers:
- args: - args:
- dns-suffix - dns-suffix
image: registry.k8s.io/e2e-test-images/agnhost:2.14 image: registry.k8s.io/e2e-test-images/agnhost:2.40
name: agnhost name: agnhost
dnsConfig: dnsConfig:
nameservers: nameservers:
@ -201,7 +201,7 @@ Usage:
```console ```console
guestbook="test/e2e/testing-manifests/guestbook" guestbook="test/e2e/testing-manifests/guestbook"
sed_expr="s|{{.AgnhostImage}}|registry.k8s.io/e2e-test-images/agnhost:2.14|" sed_expr="s|{{.AgnhostImage}}|registry.k8s.io/e2e-test-images/agnhost:2.40|"
# create the services. # create the services.
kubectl create -f ${guestbook}/frontend-service.yaml kubectl create -f ${guestbook}/frontend-service.yaml
@ -306,14 +306,14 @@ Examples:
```console ```console
docker run -i \ docker run -i \
registry.k8s.io/e2e-test-images/agnhost:2.29 \ registry.k8s.io/e2e-test-images/agnhost:2.40 \
logs-generator --log-lines-total 10 --run-duration 1s logs-generator --log-lines-total 10 --run-duration 1s
``` ```
```console ```console
kubectl run logs-generator \ kubectl run logs-generator \
--generator=run-pod/v1 \ --generator=run-pod/v1 \
--image=registry.k8s.io/e2e-test-images/agnhost:2.29 \ --image=registry.k8s.io/e2e-test-images/agnhost:2.40 \
--restart=Never \ --restart=Never \
-- logs-generator -t 10 -d 1s -- logs-generator -t 10 -d 1s
``` ```
@ -492,7 +492,7 @@ Usage:
```console ```console
kubectl run test-agnhost \ kubectl run test-agnhost \
--generator=run-pod/v1 \ --generator=run-pod/v1 \
--image=registry.k8s.io/e2e-test-images/agnhost:2.14 \ --image=registry.k8s.io/e2e-test-images/agnhost:2.40 \
--restart=Never \ --restart=Never \
--env "POD_IP=<POD_IP>" \ --env "POD_IP=<POD_IP>" \
--env "NODE_IP=<NODE_IP>" \ --env "NODE_IP=<NODE_IP>" \
@ -547,7 +547,7 @@ Usage:
```console ```console
kubectl run test-agnhost \ kubectl run test-agnhost \
--generator=run-pod/v1 \ --generator=run-pod/v1 \
--image=registry.k8s.io/e2e-test-images/agnhost:2.21 \ --image=registry.k8s.io/e2e-test-images/agnhost:2.40 \
--restart=Never \ --restart=Never \
--env "BIND_ADDRESS=localhost" \ --env "BIND_ADDRESS=localhost" \
--env "BIND_PORT=8080" \ --env "BIND_PORT=8080" \
@ -667,6 +667,6 @@ The Windows `agnhost` image includes a `nc` binary that is 100% compliant with i
## Image ## Image
The image can be found at `registry.k8s.io/e2e-test-images/agnhost:2.35` for both Linux and The image can be found at `registry.k8s.io/e2e-test-images/agnhost:2.40` for both Linux and
Windows containers (based on `mcr.microsoft.com/windows/nanoserver:1809`, `mcr.microsoft.com/windows/nanoserver:20H2`, and Windows containers (based on `mcr.microsoft.com/windows/nanoserver:1809`, `mcr.microsoft.com/windows/nanoserver:20H2`, and
`mcr.microsoft.com/windows/nanoserver:ltsc2022`). `mcr.microsoft.com/windows/nanoserver:ltsc2022`).

View File

@ -1 +1 @@
2.39 2.40

View File

@ -24,6 +24,7 @@ import (
"fmt" "fmt"
"os" "os"
"os/exec" "os/exec"
"path/filepath"
"strconv" "strconv"
"strings" "strings"
) )
@ -73,11 +74,22 @@ func getFilePerm(path string) (os.FileMode, error) {
errOut bytes.Buffer errOut bytes.Buffer
) )
// NOTE(claudiub): Symlinks have different permissions which might not match the target's.
// We want to evaluate the permissions of the target's not the symlink's.
info, err := os.Lstat(path)
if err == nil && info.Mode()&os.ModeSymlink != 0 {
evaluated, err := filepath.EvalSymlinks(path)
if err != nil {
return 0, err
}
path = evaluated
}
cmd := exec.Command("powershell.exe", "-NonInteractive", "./filePermissions.ps1", cmd := exec.Command("powershell.exe", "-NonInteractive", "./filePermissions.ps1",
"-FileName", path) "-FileName", path)
cmd.Stdout = &out cmd.Stdout = &out
cmd.Stderr = &errOut cmd.Stderr = &errOut
err := cmd.Run() err = cmd.Run()
if err != nil { if err != nil {
fmt.Printf("error from PowerShell Script: %v, %v\n", err, errOut.String()) fmt.Printf("error from PowerShell Script: %v, %v\n", err, errOut.String())