Skip to content

Commit

Permalink
Merge branch 'branch/v16' into lisa/v16/kube-namespace-enforce
Browse files Browse the repository at this point in the history
  • Loading branch information
kimlisa authored Nov 5, 2024
2 parents 2c9c06d + be89454 commit e1a4b9f
Show file tree
Hide file tree
Showing 99 changed files with 3,823 additions and 1,133 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/kube-integration-tests-non-root.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
env:
TEST_KUBE: true
KUBECONFIG: /home/.kube/config
ALPINE_VERSION: 3.20.3

jobs:
changes:
Expand Down Expand Up @@ -89,6 +90,38 @@ jobs:
cp -r $HOME/.kube /home/
chown -R ci:ci /home/.kube
- name: Build Alpine image with webserver
run: |
export SHORT_VERSION=${ALPINE_VERSION%.*}
# download the alpine image
# store the files in the fixtures/alpine directory
# to avoid passing all the repository files to the docker build context.
cd ./fixtures/alpine
# download alpine minirootfs and signature
curl -fSsLO https://dl-cdn.alpinelinux.org/alpine/v$SHORT_VERSION/releases/x86_64/alpine-minirootfs-$ALPINE_VERSION-x86_64.tar.gz
curl -fSsLO https://dl-cdn.alpinelinux.org/alpine/v$SHORT_VERSION/releases/x86_64/alpine-minirootfs-$ALPINE_VERSION-x86_64.tar.gz.asc
curl -fSsLO https://dl-cdn.alpinelinux.org/alpine/v$SHORT_VERSION/releases/x86_64/alpine-minirootfs-$ALPINE_VERSION-x86_64.tar.gz.sha256
# verify the checksum
sha256sum -c alpine-minirootfs-$ALPINE_VERSION-x86_64.tar.gz.sha256
# verify the signature
gpg --import ./alpine-ncopa.at.alpinelinux.org.asc
gpg --verify ./alpine-minirootfs-$ALPINE_VERSION-x86_64.tar.gz.asc ./alpine-minirootfs-$ALPINE_VERSION-x86_64.tar.gz
# build the webserver
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./webserver ./webserver.go
docker build -t alpine-webserver:v1 --build-arg=ALPINE_VERSION=$ALPINE_VERSION -f ./Dockerfile .
# load the image into the kind cluster
kind load docker-image alpine-webserver:v1
cd -
- name: Run tests
timeout-minutes: 40
run: |
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ default.etcd

# usually release tarballs get in the way
*.gz
# ignore all tarballs except the alpine one
!fixtures/alpine/alpine-minirootfs-*.tar.gz
*.zip

# editors
Expand Down
18 changes: 11 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1474,7 +1474,7 @@ derive:
.PHONY: derive-up-to-date
derive-up-to-date: must-start-clean/host derive
@if ! git diff --quiet; then \
echo 'Please run make derive.'; \
./build.assets/please-run.sh "derived functions" "make derive"; \
exit 1; \
fi

Expand Down Expand Up @@ -1508,15 +1508,15 @@ endif
# Unlike protos-up-to-date, this target runs locally.
.PHONY: protos-up-to-date/host
protos-up-to-date/host: must-start-clean/host grpc/host
@if ! git diff --quiet; then \
echo 'Please run make grpc.'; \
./build.assets/please-run.sh "protos gRPC" "make grpc"; \
exit 1; \
fi

.PHONY: must-start-clean/host
must-start-clean/host:
@if ! git diff --quiet; then \
echo 'This must be run from a repo with no unstaged commits.'; \
@echo 'This must be run from a repo with no unstaged commits.'; \
git diff; \
exit 1; \
fi

Expand All @@ -1525,7 +1525,12 @@ must-start-clean/host:
crds-up-to-date: must-start-clean/host
$(MAKE) -C integrations/operator manifests
@if ! git diff --quiet; then \
echo 'Please run make -C integrations/operator manifests.'; \
./build.assets/please-run.sh "operator CRD manifests" "make -C integrations/operator crd"; \
exit 1; \
fi
$(MAKE) -C integrations/operator crd-docs
@if ! git diff --quiet; then \
./build.assets/please-run.sh "operator CRD docs" "make -C integrations/operator crd"; \
exit 1; \
fi
$(MAKE) -C integrations/operator crd-docs
Expand All @@ -1540,8 +1545,7 @@ crds-up-to-date: must-start-clean/host
terraform-resources-up-to-date: must-start-clean/host
$(MAKE) -C integrations/terraform docs
@if ! git diff --quiet; then \
echo 'Please run make -C integrations/terraform docs.'; \
git diff; \
./build.assets/please-run.sh "TF provider docs" "make -C integrations/terraform docs"; \
exit 1; \
fi

Expand Down
40 changes: 40 additions & 0 deletions build.assets/please-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/sh

# This script is a helper that tells developers what generated content is out of date
# and which command to run.
# When running on GitHub actions, the script will also create an error in the PR and
# collapse the diff to improve readability.

set -eu

# only echoes the string if we are in GitHub Actions
echo_gha() {
[ -n "${GITHUB_ACTIONS+x}" ] && echo "$@"
}

main() {
if [ $# -ne 2 ]; then
echo "Usage: $0 <kind> <generate command>" >&2
exit 1
fi

KIND="$1"
GENERATE_COMMAND="$2"

TITLE="$KIND are out-of-date"
MESSAGE="Please run the command \`$GENERATE_COMMAND\`"

# Create a GitHub error
echo_gha "::error file=Makefile,title=$TITLE::$MESSAGE"

echo "============="
echo "$TITLE"
echo "$MESSAGE"
echo "============="

echo_gha "::group::Diff output"
git diff || true
echo_gha "::endgroup::"
}

main "$@"
2 changes: 1 addition & 1 deletion docs/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@
},
{
"source": "/application-access/jwt/",
"destination": "/enroll-resources/application-access/jwt/",
"destination": "/enroll-resources/application-access/jwt/jwt/",
"permanent": true
},
{
Expand Down
2 changes: 2 additions & 0 deletions docs/pages/admin-guides/management/guides/guides.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ You can integrate Teleport with third-party tools in order to complete various
tasks in your cluster. These guides describe Teleport integrations that are not
documented elsewhere:

- [AWS OIDC Integration with Teleport](awsoidc-integration.mdx). How
to set up the AWS OIDC integration to allow Teleport to interact with AWS.
- [EC2 tags as Teleport agent labels](ec2-tags.mdx). How to set up
Teleport agent labels based on EC2 tags.
- [GCP tags and labels as Teleport agent labels](gcp-tags.mdx). How
Expand Down
2 changes: 1 addition & 1 deletion e
Submodule e updated from cc7fef to 533cf6
9 changes: 9 additions & 0 deletions fixtures/alpine/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM scratch

ARG ALPINE_VERSION

ADD alpine-minirootfs-$ALPINE_VERSION-x86_64.tar.gz /

COPY webserver /webserver

CMD [ "/webserver" ]
50 changes: 50 additions & 0 deletions fixtures/alpine/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# `alpine-webserver:v1` Build Process

## Source

The `alpine-webserver:v1` image is based on `alpine` `minirootfs`, but instead of relying on Docker Hub's official Alpine image, we source the original files directly from Alpine's CDN. This approach mitigates issues with Docker Hub and GitHub Action network failures, which have been a common cause of integration test failures.

The build process is specified in the `.github/workflows/kube-integration-tests-non-root.yaml` file.

## Download

To download the new `alpine-minirootfs` image, follow the instructions:

```bash
$ export ALPINE_VERSION=3.20.3
$ export SHORT_VERSION=${ALPINE_VERSION%.*}

# download alpine minirootfs and signature
$ curl -fSsLO https://dl-cdn.alpinelinux.org/alpine/v$SHORT_VERSION/releases/x86_64/alpine-minirootfs-$ALPINE_VERSION-x86_64.tar.gz
$ curl -fSsLO https://dl-cdn.alpinelinux.org/alpine/v$SHORT_VERSION/releases/x86_64/alpine-minirootfs-$ALPINE_VERSION-x86_64.tar.gz.asc
$ curl -fSsLO https://dl-cdn.alpinelinux.org/alpine/v$SHORT_VERSION/releases/x86_64/alpine-minirootfs-$ALPINE_VERSION-x86_64.tar.gz.sha256

```

## Source Validation

The build process in `.github/workflows/kube-integration-tests-non-root.yaml` validates both the SHA-256 checksum and the GPG signature. The signature verification uses `alpine-ncopa.at.alpinelinux.org.asc`, which is the official public key used by Alpine Linux to sign its assets. This public key is available on the [Alpine Linux Downloads page](https://www.alpinelinux.org/downloads/).

## Image Build Process

The image is constructed from a scratch filesystem and incorporates only the necessary components to run the web server. Here’s the basic Dockerfile configuration:

```Dockerfile
FROM scratch

ARG ALPINE_VERSION

ADD alpine-minirootfs-$ALPINE_VERSION-x86_64.tar.gz /

COPY webserver /webserver

CMD [ "/webserver" ]
```

This minimalist configuration ensures the image remains lightweight, secure, and tailored to only the required functionalities.

## Image distribution

After sucessfull build, the image is loaded into our `kind` cluster with the tag `alpine-webserver:v1`.

Note: `:latest` can't be used otherwise Kubernetes will try loading the image from dockerhub and fail.
52 changes: 52 additions & 0 deletions fixtures/alpine/alpine-ncopa.at.alpinelinux.org.asc
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v2

mQINBFSIEDwBEADbib88gv1dBgeEez1TIh6A5lAzRl02JrdtYkDoPr5lQGYv0qKP
lWpd3jgGe8n90krGmT9W2nooRdyZjZ6UPbhYSJ+tub6VuKcrtwROXP2gNNqJA5j3
vkXQ40725CVig7I3YCpzjsKRStwegZAelB8ZyC4zb15J7YvTVkd6qa/uuh8H21X2
h/7IZJz50CMxyz8vkdyP2niIGZ4fPi0cVtsg8l4phbNJ5PwFOLMYl0b5geKMviyR
MxxQ33iNa9X+RcWeR751IQfax6xNcbOrxNRzfzm77fY4KzBezcnqJFnrl/p8qgBq
GHKmrrcjv2MF7dCWHGAPm1/vdPPjUpOcEOH4uGvX7P4w2qQ0WLBTDDO47/BiuY9A
DIwEF1afNXiJke4fmjDYMKA+HrnhocvI48VIX5C5+C5aJOKwN2EOpdXSvmsysTSt
gIc4ffcaYugfAIEn7ZdgcYmTlbIphHmOmOgt89J+6Kf9X6mVRmumI3cZWetf2FEV
fS9v24C2c8NRw3LESoDT0iiWsCHcsixCYqqvjzJBJ0TSEIVCZepOOBp8lfMl4YEZ
BVMzOx558LzbF2eR/XEsr3AX7Ga1jDu2N5WzIOa0YvJl1xcQxc0RZumaMlZ81dV/
uu8G2+HTrJMZK933ov3pbxaZ38/CbCA90SBk5xqVqtTNAHpIkdGj90v2lwARAQAB
tCVOYXRhbmFlbCBDb3BhIDxuY29wYUBhbHBpbmVsaW51eC5vcmc+iQI2BBMBCAAg
BQJUiBA8AhsDBQsJCAcCBhUICQoLAgMWAgECHgECF4AACgkQKTrNCQfZSVrcNxAA
mEzX9PQaczzlPAlDe3m1AN0lP6E/1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c=
=FcYC
-----END PGP PUBLIC KEY BLOCK-----
26 changes: 26 additions & 0 deletions fixtures/alpine/webserver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Teleport
// Copyright (C) 2024 Gravitational, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

package main

import "net/http"

func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello, world!"))
})
http.ListenAndServe(":80", nil)
}
22 changes: 22 additions & 0 deletions integration/hostuser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,28 @@ func TestRootHostUsers(t *testing.T) {
require.NoError(t, err)
require.False(t, hasExpirations)
})

t.Run("Test migrate unmanaged user", func(t *testing.T) {
t.Cleanup(func() { cleanupUsersAndGroups([]string{testuser}, []string{types.TeleportKeepGroup}) })

users := srv.NewHostUsers(context.Background(), presence, "host_uuid")
_, err := host.UserAdd(testuser, nil, host.UserOpts{})
require.NoError(t, err)

closer, err := users.UpsertUser(testuser, services.HostUsersInfo{Mode: services.HostUserModeKeep, Groups: []string{types.TeleportKeepGroup}})
require.NoError(t, err)
require.Nil(t, closer)

u, err := user.Lookup(testuser)
require.NoError(t, err)

gids, err := u.GroupIds()
require.NoError(t, err)

keepGroup, err := user.LookupGroup(types.TeleportKeepGroup)
require.NoError(t, err)
require.Contains(t, gids, keepGroup.Gid)
})
}

type hostUsersBackendWithExp struct {
Expand Down
13 changes: 10 additions & 3 deletions integration/kube_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1473,7 +1473,7 @@ func testKubeEphemeralContainers(t *testing.T, suite *KubeSuite) {
sessCreatorTerm := NewTerminal(250)
group := &errgroup.Group{}
group.Go(func() error {
cmd := []string{"/bin/sh", "echo", "hello from an ephemeral container"}
cmd := []string{"/bin/sh", "-c", "echo hello from an ephemeral container"}
debugPod, _, err := generateDebugContainer(contName, cmd, pod)
if err != nil {
return trace.Wrap(err)
Expand Down Expand Up @@ -1578,7 +1578,7 @@ func generateDebugContainer(name string, cmd []string, pod *v1.Pod) (*v1.Pod, *v
ec := &v1.EphemeralContainer{
EphemeralContainerCommon: v1.EphemeralContainerCommon{
Name: name,
Image: "alpine:latest",
Image: localPodImage,
Command: cmd,
ImagePullPolicy: v1.PullIfNotPresent,
Stdin: true,
Expand Down Expand Up @@ -1933,6 +1933,13 @@ func newNamespace(name string) *v1.Namespace {
}
}

// localPodImage is a container image that is used for testing
// It's a docker image that runs a simple web server
// that listens on port 80 and returns "Hello, World!" on GET /
// This image is vendored in the Teleport repository in the
// fixtures/alpine directory. Check the Dockerfile there for details.
const localPodImage = "alpine-webserver:v1"

func newPod(ns, name string) *v1.Pod {
return &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -1942,7 +1949,7 @@ func newPod(ns, name string) *v1.Pod {
Spec: v1.PodSpec{
Containers: []v1.Container{{
Name: "nginx",
Image: "nginx:alpine",
Image: localPodImage,
}},
},
}
Expand Down
Loading

0 comments on commit e1a4b9f

Please sign in to comment.