-
Notifications
You must be signed in to change notification settings - Fork 505
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
Adding setcap image so that capabilities can be applied to #1684
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright 2021 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. | ||
|
||
ARG BASEIMAGE | ||
|
||
FROM ${BASEIMAGE} | ||
|
||
RUN apt-get update && apt-get -y --no-install-recommends install libcap2-bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# Copyright 2021 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. | ||
|
||
.PHONY: build push all all-build all-push-images all-push push-manifest | ||
|
||
REGISTRY?="gcr.io/k8s-staging-build-image" | ||
IMAGE=$(REGISTRY)/setcap | ||
|
||
TAG ?= $(shell git describe --tags --always --dirty) | ||
IMAGE_VERSION ?= buster-v1.4.0 | ||
CONFIG ?= buster | ||
DEBIAN_BASE_VERSION ?= buster-v1.4.0 | ||
|
||
ARCH?=amd64 | ||
ALL_ARCH = amd64 arm arm64 ppc64le s390x | ||
|
||
BASE_REGISTRY?=k8s.gcr.io/build-image | ||
BASEIMAGE?=$(BASE_REGISTRY)/debian-base-$(ARCH):$(DEBIAN_BASE_VERSION) | ||
|
||
# Build args | ||
QEMUVERSION=5.2.0-2 | ||
|
||
# This option is for running docker manifest command | ||
export DOCKER_CLI_EXPERIMENTAL := enabled | ||
|
||
build: | ||
ifneq ($(ARCH),amd64) | ||
# Register /usr/bin/qemu-ARCH-static as the handler for non-x86 binaries in the kernel | ||
docker run --rm --privileged multiarch/qemu-user-static:$(QEMUVERSION) --reset -p yes | ||
docker buildx version | ||
BUILDER=$(shell docker buildx create --use) | ||
endif | ||
docker buildx build \ | ||
--pull \ | ||
--load \ | ||
--platform linux/$(ARCH) \ | ||
-t $(IMAGE)-$(ARCH):$(IMAGE_VERSION) \ | ||
-t $(IMAGE)-$(ARCH):$(TAG)-$(CONFIG) \ | ||
-t $(IMAGE)-$(ARCH):latest-$(CONFIG) \ | ||
--build-arg=BASEIMAGE=$(BASEIMAGE) \ | ||
. | ||
ifneq ($(ARCH),amd64) | ||
docker buildx rm $$BUILDER | ||
endif | ||
|
||
push: build | ||
docker push $(IMAGE)-$(ARCH):$(IMAGE_VERSION) | ||
docker push $(IMAGE)-$(ARCH):$(TAG)-$(CONFIG) | ||
docker push $(IMAGE)-$(ARCH):latest-$(CONFIG) | ||
|
||
sub-build-%: | ||
$(MAKE) ARCH=$* build | ||
|
||
all-build: $(addprefix sub-build-,$(ALL_ARCH)) | ||
|
||
sub-push-image-%: | ||
$(MAKE) ARCH=$* push | ||
|
||
all-push-images: $(addprefix sub-push-image-,$(ALL_ARCH)) | ||
|
||
all-push: all-push-images push-manifest | ||
|
||
push-manifest: | ||
docker manifest create --amend $(IMAGE):$(IMAGE_VERSION) $(shell echo $(ALL_ARCH) | sed -e "s~[^ ]*~$(IMAGE)\-&:$(IMAGE_VERSION)~g") | ||
@for arch in $(ALL_ARCH); do docker manifest annotate --arch $${arch} ${IMAGE}:${IMAGE_VERSION} ${IMAGE}-$${arch}:${IMAGE_VERSION}; done | ||
docker manifest push --purge ${IMAGE}:${IMAGE_VERSION} | ||
|
||
all: all-push | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
setcap | ||
This image is based on debian-base and installs the libcap2-bin package. The | ||
main use of this image is to apply `CAP_NET_BIND_SERVICE` to the kube-apiserver | ||
binary so that it can a bind to ports less than 1024 and still be run as non | ||
root. | ||
|
||
This image is compiled for multiple architectures. | ||
|
||
How to release | ||
If you're editing the Dockerfile or some other thing, please bump the TAG in the Makefile. | ||
|
||
Build and push images for all the architectures | ||
$ make all-push | ||
# ---> staging-k8s.gcr.io/setcap-amd64:TAG | ||
# ---> staging-k8s.gcr.io/setcap-arm:TAG | ||
# ---> staging-k8s.gcr.io/setcap-arm64:TAG | ||
# ---> staging-k8s.gcr.io/setcap-ppc64le:TAG | ||
# ---> staging-k8s.gcr.io/setcap-s390x:TAG | ||
If you don't want to push the images, run `make sub-build-{target_arch}` or `make all-build` instead |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# See https://cloud.google.com/cloud-build/docs/build-config | ||
timeout: 1200s | ||
options: | ||
substitution_option: ALLOW_LOOSE | ||
machineType: 'N1_HIGHCPU_8' | ||
steps: | ||
- name: 'gcr.io/k8s-testimages/gcb-docker-gcloud:v20201130-750d12f' | ||
entrypoint: bash | ||
dir: ./images/build/setcap | ||
env: | ||
- DOCKER_CLI_EXPERIMENTAL=enabled | ||
- REGISTRY=gcr.io/$PROJECT_ID | ||
- IMAGE=gcr.io/$PROJECT_ID/setcap | ||
- TAG=$_GIT_TAG | ||
- PULL_BASE_REF=$_PULL_BASE_REF | ||
- IMAGE_VERSION=$_IMAGE_VERSION | ||
- CONFIG=$_CONFIG | ||
- DEBIAN_BASE_VERSION=$_DEBIAN_BASE_VERSION | ||
- HOME=/root # for docker buildx | ||
args: | ||
- -c | ||
- | | ||
gcloud auth configure-docker && \ | ||
make all-push | ||
substitutions: | ||
# _GIT_TAG will be filled with a git-based tag for the image, of the form vYYYYMMDD-hash, and | ||
# can be used as a substitution | ||
_GIT_TAG: '12345' | ||
_PULL_BASE_REF: 'dev' | ||
_IMAGE_VERSION: 'v0.0.0' | ||
_CONFIG: 'codename' | ||
_DEBIAN_BASE_VERSION: 'v0.0.0' | ||
|
||
tags: | ||
- 'setcap' | ||
- ${_GIT_TAG} | ||
- ${_PULL_BASE_REF} | ||
- ${_IMAGE_VERSION} | ||
- ${_CONFIG} | ||
- ${_DEBIAN_BASE_VERSION} | ||
|
||
images: | ||
- 'gcr.io/$PROJECT_ID/setcap-amd64:$_IMAGE_VERSION' | ||
- 'gcr.io/$PROJECT_ID/setcap-amd64:$_GIT_TAG-$_CONFIG' | ||
- 'gcr.io/$PROJECT_ID/setcap-amd64:latest-$_CONFIG' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
variants: | ||
buster: | ||
CONFIG: 'buster' | ||
IMAGE_VERSION: 'buster-v1.4.0' | ||
DEBIAN_BASE_VERSION: 'buster-v1.4.0' |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's do not silently assume that we're running on amd64.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we build these images on another arch?
NOTE: this is from multiple other makefiles in this repo:
release/images/build/debian-iptables/Makefile
Line 45 in aab9759
release/images/build/debian-hyperkube-base/Makefile
Line 75 in aab9759
release/images/build/debian-base/Makefile
Line 115 in aab9759
IMO if we consider this a problem this needs a cleanup orthogonal to this PR and the discussion around what way to use setcap
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not in the CI, but when developing those images locally different machines using different architectures would result in different outputs.
Right now I'm working on cleaning up the debian-base image in #1909. Sure, I'm happy to follow-up on that later on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fair enough! thanks :-)