Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Centralizes images into agnhost (part 4) #81170

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 0 additions & 3 deletions test/images/BUILD
Expand Up @@ -15,15 +15,12 @@ filegroup(
"//test/images/apparmor-loader:all-srcs",
"//test/images/echoserver:all-srcs",
"//test/images/metadata-concealment:all-srcs",
"//test/images/mounttest:all-srcs",
"//test/images/nonewprivs:all-srcs",
"//test/images/pets/peer-finder:all-srcs",
"//test/images/regression-issue-74839:all-srcs",
"//test/images/resource-consumer:all-srcs",
"//test/images/resource-consumer-controller:all-srcs",
"//test/images/sample-apiserver:all-srcs",
"//test/images/sample-device-plugin:all-srcs",
"//test/images/test-webserver:all-srcs",
],
tags = ["automanaged"],
)
6 changes: 6 additions & 0 deletions test/images/agnhost/BUILD
Expand Up @@ -26,6 +26,7 @@ go_library(
"//test/images/agnhost/inclusterclient:go_default_library",
"//test/images/agnhost/liveness:go_default_library",
"//test/images/agnhost/logs-generator:go_default_library",
"//test/images/agnhost/mounttest:go_default_library",
"//test/images/agnhost/net:go_default_library",
"//test/images/agnhost/netexec:go_default_library",
"//test/images/agnhost/nettest:go_default_library",
Expand All @@ -34,7 +35,9 @@ go_library(
"//test/images/agnhost/pause:go_default_library",
"//test/images/agnhost/port-forward-tester:go_default_library",
"//test/images/agnhost/porter:go_default_library",
"//test/images/agnhost/resource-consumer-controller:go_default_library",
"//test/images/agnhost/serve-hostname:go_default_library",
"//test/images/agnhost/test-webserver:go_default_library",
"//test/images/agnhost/webhook:go_default_library",
"//vendor/github.com/spf13/cobra:go_default_library",
"//vendor/k8s.io/klog:go_default_library",
Expand Down Expand Up @@ -62,6 +65,7 @@ filegroup(
"//test/images/agnhost/inclusterclient:all-srcs",
"//test/images/agnhost/liveness:all-srcs",
"//test/images/agnhost/logs-generator:all-srcs",
"//test/images/agnhost/mounttest:all-srcs",
"//test/images/agnhost/net:all-srcs",
"//test/images/agnhost/netexec:all-srcs",
"//test/images/agnhost/nettest:all-srcs",
Expand All @@ -70,7 +74,9 @@ filegroup(
"//test/images/agnhost/pause:all-srcs",
"//test/images/agnhost/port-forward-tester:all-srcs",
"//test/images/agnhost/porter:all-srcs",
"//test/images/agnhost/resource-consumer-controller:all-srcs",
"//test/images/agnhost/serve-hostname:all-srcs",
"//test/images/agnhost/test-webserver:all-srcs",
"//test/images/agnhost/webhook:all-srcs",
],
tags = ["automanaged"],
Expand Down
12 changes: 10 additions & 2 deletions test/images/agnhost/Dockerfile
Expand Up @@ -16,6 +16,10 @@ FROM BASEIMAGE

CROSS_BUILD_COPY qemu-QEMUARCH-static /usr/bin/

# from dnsutils image
# install necessary packages:
# - bind-tools: contains dig, which can used in DNS tests.
# - CoreDNS: used in some DNS tests.
# from hostexec image
# install necessary packages:
# - curl, nc: used by a lot of e2e tests
Expand All @@ -26,10 +30,14 @@ RUN apk --update add bind-tools curl netcat-openbsd iproute2 iperf bash && rm -r
&& ln -s /usr/bin/iperf /usr/local/bin/iperf \
&& ls -altrh /usr/local/bin/iperf

# PORT 8080 needed by: netexec, nettest
ADD https://github.com/coredns/coredns/releases/download/v1.6.2/coredns_1.6.2_linux_BASEARCH.tgz /coredns.tgz
RUN tar -xzvf /coredns.tgz && rm -f /coredns.tgz

# PORT 80 needed by: test-webserver
# PORT 8080 needed by: netexec, nettest, resource-consumer, resource-consumer-controller
# PORT 8081 needed by: netexec
# PORT 9376 needed by: serve-hostname
EXPOSE 8080 8081 9376
EXPOSE 80 8080 8081 9376

# from netexec
RUN mkdir /uploads
Expand Down
79 changes: 72 additions & 7 deletions test/images/agnhost/README.md
Expand Up @@ -40,7 +40,7 @@ For example, let's consider the following `pod.yaml` file:
containers:
- args:
- dns-suffix
image: gcr.io/kubernetes-e2e-test-images/agnhost:2.8
image: gcr.io/kubernetes-e2e-test-images/agnhost:2.9
name: agnhost
dnsConfig:
nameservers:
Expand Down Expand Up @@ -290,21 +290,52 @@ Examples:

```console
docker run -i \
gcr.io/kubernetes-e2e-test-images/agnhost:2.8 \
gcr.io/kubernetes-e2e-test-images/agnhost:2.9 \
logs-generator --log-lines-total 10 --run-duration 1s
```

```console
kubectl run logs-generator \
--generator=run-pod/v1 \
--image=gcr.io/kubernetes-e2e-test-images/agnhost:2.8 \
--image=gcr.io/kubernetes-e2e-test-images/agnhost:2.9 \
--restart=Never \
-- logs-generator -t 10 -d 1s
```

[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/test/images/logs-generator/README.md?pixel)]()


### mounttest

The `mounttest` subcommand can be used to create files with various permissions, read files,
and output file system type, mode, owner, and permissions for any given file.

The subcommand can accept the following flags:

- `fs_type`: Path to print the FS type for.
- `file_mode`: Path to print the mode bits of.
- `file_perm`: Path to print the perms of.
- `file_owner`: Path to print the owning UID and GID of.
- `new_file_0644`: Path to write to and read from with perm 0644.
- `new_file_0666`: Path to write to and read from with perm 0666.
- `new_file_0660`: Path to write to and read from with perm 0660.
- `new_file_0777`: Path to write to and read from with perm 0777.
- `file_content`: Path to read the file content from.
- `file_content_in_loop`: Path to read the file content in loop from.
- `retry_time` (default: 180): Retry time during the loop.
- `break_on_expected_content` (default: true): Break out of loop on expected content (use with `--file_content_in_loop` flag only).

Usage:

```console
kubectl exec test-agnhost -- /agnhost mounttest \
[--fs_type <path>] [--file_mode <path>] [--file_perm <path>] [--file_owner <path>] \
[--new_file_0644 <path>] [--new_file_0666 <path>] [--new_file_0660 <path>] [--new_file_0777 <path>] \
[--file_content <path>] [--file_content_in_loop <path>] \
[--retry_time <seconds>] [--break_on_expected_content <true_or_false>]
```


### net

The goal of this Go project is to consolidate all low-level
Expand Down Expand Up @@ -424,7 +455,7 @@ Usage:
```console
kubectl run test-agnhost \
--generator=run-pod/v1 \
--image=gcr.io/kubernetes-e2e-test-images/agnhost:2.8 \
--image=gcr.io/kubernetes-e2e-test-images/agnhost:2.9 \
--restart=Never \
--env "POD_IP=<POD_IP>" \
--env "NODE_IP=<NODE_IP>" \
Expand Down Expand Up @@ -479,7 +510,7 @@ Usage:
```console
kubectl run test-agnhost \
--generator=run-pod/v1 \
--image=gcr.io/kubernetes-e2e-test-images/agnhost:2.8 \
--image=gcr.io/kubernetes-e2e-test-images/agnhost:2.9 \
--restart=Never \
--env "BIND_ADDRESS=localhost" \
--env "BIND_PORT=8080" \
Expand Down Expand Up @@ -517,6 +548,25 @@ Usage:
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/test/images/porter/README.md?pixel)]()


### resource-consumer-controller

This subcommand starts an HTTP server that spreads requests around resource consumers. The HTTP server has the same endpoints and usage as the one spawned by the ``resource-consumer`` subcommand.

The subcommand can accept the following flags:

- `port` (default: 8080): The port number to listen to.
- `consumer-port` (default: 8080): Port number of consumers.
- `consumer-service-name` (default: `resource-consumer`): Name of service containing resource consumers.
- `consumer-service-namespace` (default: `default`): Namespace of service containing resource consumers.

Usage:

```console
kubectl exec test-agnhost -- /agnhost resource-consumer-controller \
[--port <port>] [--consumer-port <port>] [--consumer-service-name <service-name>] [--consumer-service-namespace <namespace>]
```


### serve-hostname

This is a small util app to serve your hostname on TCP and/or UDP. Useful for testing.
Expand All @@ -542,6 +592,21 @@ Usage:
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/test/images/serve_hostname/README.md?pixel)]()


### test-webserver

Starts a simple HTTP fileserver which serves any file specified in the URL path, if it exists.

The subcommand can accept the following flags:

- `port` (default: `80`): The port number to listen to.

Usage:

```console
kubectl exec test-agnhost -- /agnhost test-webserver [--port <port>]
```


### webhook (Kubernetes External Admission Webhook)

The subcommand tests MutatingAdmissionWebhook and ValidatingAdmissionWebhook. After deploying
Expand All @@ -561,11 +626,11 @@ Usage:

## Other tools

The image contains `iperf`.
The image contains `iperf`, `curl`, `dns-tools` (including `dig`), CoreDNS.


## Image

The image can be found at `gcr.io/kubernetes-e2e-test-images/agnhost:2.8` for Linux
The image can be found at `gcr.io/kubernetes-e2e-test-images/agnhost:2.9` for Linux
containers, and `e2eteam/agnhost:2.8` for Windows containers. In the future, the same
repository can be used for both OSes.
2 changes: 1 addition & 1 deletion test/images/agnhost/VERSION
@@ -1 +1 @@
2.8
2.9
8 changes: 7 additions & 1 deletion test/images/agnhost/agnhost.go
Expand Up @@ -32,6 +32,7 @@ import (
"k8s.io/kubernetes/test/images/agnhost/inclusterclient"
"k8s.io/kubernetes/test/images/agnhost/liveness"
"k8s.io/kubernetes/test/images/agnhost/logs-generator"
"k8s.io/kubernetes/test/images/agnhost/mounttest"
"k8s.io/kubernetes/test/images/agnhost/net"
"k8s.io/kubernetes/test/images/agnhost/netexec"
"k8s.io/kubernetes/test/images/agnhost/nettest"
Expand All @@ -40,12 +41,14 @@ import (
"k8s.io/kubernetes/test/images/agnhost/pause"
"k8s.io/kubernetes/test/images/agnhost/port-forward-tester"
"k8s.io/kubernetes/test/images/agnhost/porter"
"k8s.io/kubernetes/test/images/agnhost/resource-consumer-controller"
"k8s.io/kubernetes/test/images/agnhost/serve-hostname"
"k8s.io/kubernetes/test/images/agnhost/test-webserver"
"k8s.io/kubernetes/test/images/agnhost/webhook"
)

func main() {
rootCmd := &cobra.Command{Use: "app", Version: "2.8"}
rootCmd := &cobra.Command{Use: "app", Version: "2.9"}

rootCmd.AddCommand(auditproxy.CmdAuditProxy)
rootCmd.AddCommand(connect.CmdConnect)
Expand All @@ -59,6 +62,7 @@ func main() {
rootCmd.AddCommand(inclusterclient.CmdInClusterClient)
rootCmd.AddCommand(liveness.CmdLiveness)
rootCmd.AddCommand(logsgen.CmdLogsGenerator)
rootCmd.AddCommand(mounttest.CmdMounttest)
rootCmd.AddCommand(net.CmdNet)
rootCmd.AddCommand(netexec.CmdNetexec)
rootCmd.AddCommand(nettest.CmdNettest)
Expand All @@ -67,7 +71,9 @@ func main() {
rootCmd.AddCommand(pause.CmdPause)
rootCmd.AddCommand(porter.CmdPorter)
rootCmd.AddCommand(portforwardtester.CmdPortForwardTester)
rootCmd.AddCommand(resconsumerctrl.CmdResourceConsumerController)
rootCmd.AddCommand(servehostname.CmdServeHostname)
rootCmd.AddCommand(testwebserver.CmdTestWebserver)
rootCmd.AddCommand(webhook.CmdWebhook)

// NOTE(claudiub): Some tests are passing logging related flags, so we need to be able to
Expand Down
Expand Up @@ -2,14 +2,18 @@ package(default_visibility = ["//visibility:public"])

load(
"@io_bazel_rules_go//go:def.bzl",
"go_binary",
"go_library",
)

go_library(
name = "go_default_library",
srcs = ["mt.go"],
importpath = "k8s.io/kubernetes/test/images/mounttest",
srcs = [
"mt.go",
"mt_utils.go",
"mt_utils_windows.go",
],
importpath = "k8s.io/kubernetes/test/images/agnhost/mounttest",
deps = ["//vendor/github.com/spf13/cobra:go_default_library"],
)

filegroup(
Expand All @@ -24,8 +28,3 @@ filegroup(
srcs = [":package-srcs"],
tags = ["automanaged"],
)

go_binary(
name = "mounttest",
embed = [":go_default_library"],
)
97 changes: 97 additions & 0 deletions test/images/agnhost/mounttest/filePermissions.ps1
@@ -0,0 +1,97 @@
# Copyright 2019 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

Param(
[string]$FileName = $(throw "-FileName is required.")
)


# read = read data | read attributes
$READ_PERMISSIONS = 0x0001 -bor 0x0080

# write = write data | append data | write attributes | write EA
$WRITE_PERMISSIONS = 0x0002 -bor 0x0004 -bor 0x0100 -bor 0x0010

# execute = read data | file execute
$EXECUTE_PERMISSIONS = 0x0001 -bor 0x0020


function GetFilePermissions($path) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I lack sufficient windows expertise to really review this; can we get someone else to take a look at this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, it's what it has been used in tests like should be consumable from pods in volume with mappings since about 1 year. You can see it here: https://testgrid.k8s.io/sig-windows#aks-engine-azure-windows-master

$objPath = "Win32_LogicalFileSecuritySetting='$path'"
$output = Invoke-WmiMethod -Namespace root/cimv2 -Path $objPath -Name GetSecurityDescriptor

if ($output.ReturnValue -ne 0) {
$retVal = $output.ReturnValue
Write-Error "GetSecurityDescriptor invocation failed with code: $retVal"
exit 1
}

$fileSD = $output.Descriptor
$fileOwnerGroup = $fileSD.Group
$fileOwner = $fileSD.Owner

if ($fileOwnerGroup.Name -eq $null -and $fileOwnerGroup.Domain -eq $null) {
# the file owner's group is not recognized. Check if the Owner itself is
# a group, and if so, default the group to it.
net user $fileOwner.Name > $null 2> $null
if (-not $?) {
$fileOwnerGroup = $fileOwner
}

}

$userMask = 0
$groupMask = 0
$otherMask = 0

foreach ($ace in $fileSD.DACL) {
$mask = 0
if ($ace.AceType -ne 0) {
# not an Allow ACE, skip.
continue
}

# convert mask.
if ( ($ace.AccessMask -band $READ_PERMISSIONS) -eq $READ_PERMISSIONS ) {
$mask = $mask -bor 4
}
if ( ($ace.AccessMask -band $WRITE_PERMISSIONS) -eq $WRITE_PERMISSIONS ) {
$mask = $mask -bor 2
}
if ( ($ace.AccessMask -band $EXECUTE_PERMISSIONS) -eq $EXECUTE_PERMISSIONS ) {
$mask = $mask -bor 1
}

# detect mask type.
if ($ace.Trustee.Equals($fileOwner)) {
$userMask = $mask
}
if ($ace.Trustee.Equals($fileOwnerGroup)) {
$groupMask = $mask
}
if ($ace.Trustee.Name.ToLower() -eq "users") {
$otherMask = $mask
}
}

return "$userMask$groupMask$otherMask"
}

$mask = GetFilePermissions($FileName)
if (-not $?) {
exit 1
}

# print the permission mask Linux-style.
echo "0$mask"