Skip to content

Commit 3dbaae5

Browse files
authored
Merge pull request #13876 from bmcelvee/osdocs-623-dockerless-nodes
osdocs-123-devexp-138 Document dockerless nodes
2 parents 8bcf57d + 475840c commit 3dbaae5

9 files changed

+409
-0
lines changed

_topic_map.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,16 @@ Topics:
160160
File: managing-build-output
161161
- Name: Using build strategies
162162
File: build-strategies
163+
- Name: Adding a Docker socket to custom builds with Buildah
164+
File: custom-builds-buildah
163165
- Name: Performing basic builds
164166
File: basic-build-operations
165167
- Name: Triggering and modifying builds
166168
File: triggering-builds-build-hooks
167169
- Name: Performing advanced builds
168170
File: advanced-build-operations
171+
- Name: Securing builds by strategy
172+
File: securing-builds-by-strategy
169173
- Name: Troubleshooting builds
170174
File: troubleshooting-builds
171175
---

builds/custom-builds-buildah.adoc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[id='custom-builds-buildah']
2+
= Adding a Docker socket to custom builds with Buildah
3+
include::modules/common-attributes.adoc[]
4+
:context: custom-builds-buildah
5+
toc::[]
6+
7+
8+
With {product-title} 4.0, a Docker socket will not be present on the host
9+
nodes. This means the _mount docker socket_ option of a custom build is not
10+
guaranteed to provide an accessible Docker socket for use within a custom build
11+
image.
12+
13+
If you need this capability in order to build and push images, add the Buildah
14+
tool your custom build image and use it to build and push the image within your
15+
custom build logic. The following is an example of how to run custom builds with
16+
Buildah.
17+
18+
[NOTE]
19+
====
20+
Using the custom build strategy requires permissions that normal users do
21+
not have by default because it allows the user to execute arbitrary code inside
22+
a privileged container running on the cluster. This level of access can be used
23+
to compromise the cluster and therefore should be granted only to users who are
24+
trusted with administrative privileges on the cluster.
25+
====
26+
27+
.Prerequisites
28+
29+
* Review how to xref:../builds/securing-builds-by-strategy.adoc#securing-builds-by-strategy[grant custom build permissions].
30+
31+
32+
include::modules/builds-create-custom-build-artifacts.adoc[leveloffset=+1]
33+
include::modules/builds-build-custom-builder-image.adoc[leveloffset=+1]
34+
include::modules/builds-use-custom-builder-image.adoc[leveloffset=+1]
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
[id='securing-builds-by-strategy']
2+
= Securing builds by strategy
3+
include::modules/common-attributes.adoc[]
4+
:context: securing-builds-by-strategy
5+
toc::[]
6+
7+
Builds in {product-title} are run in privileged containers. Depending on the
8+
build strategy used, this allows a user who can run builds to escalate their
9+
permissions on the cluster and host nodes. As a security measure, limit who can
10+
run builds and the strategy that is used for those builds. Custom builds are
11+
inherently less safe than Source builds, because they can execute any code
12+
within a privileged container, and are disabled by default. Grant Docker build
13+
permissions with caution, because a vulnerability in the Dockerfile processing
14+
logic could result in a privileges being granted on the host node.
15+
16+
By default, all users that can create builds are granted permission to use the
17+
Docker and Source-to-Image (S2I) build strategies. Users with *cluster-admin*
18+
privileges can enable the Custom build strategy, as referenced in the
19+
restricting build strategies to a user globally section.
20+
21+
You can control who can build and which build strategies they can use by using
22+
an authorization policy. Each build strategy has a corresponding build
23+
subresource. A user must have permission to create a build _and_ permission to
24+
create on the build strategy subresource in order to create builds using that
25+
strategy. Default roles are provided which grant the *create* permission on the
26+
build strategy subresource.
27+
28+
.Build Strategy Subresources and Roles
29+
[options="header"]
30+
|===
31+
32+
|Strategy |Subresource |Role
33+
34+
|Docker
35+
|builds/docker
36+
|system:build-strategy-docker
37+
38+
|Source-to-Image
39+
|builds/source
40+
|system:build-strategy-source
41+
42+
|Custom
43+
|builds/custom
44+
|system:build-strategy-custom
45+
46+
|JenkinsPipeline
47+
|builds/jenkinspipeline
48+
|system:build-strategy-jenkinspipeline
49+
50+
|===
51+
52+
include::modules/builds-disabling-build-strategy-globally.adoc[leveloffset=+1]
53+
include::modules/builds-restricting-build-strategy-globally.adoc[leveloffset=+1]
54+
include::modules/builds-restricting-build-strategy-to-user.adoc[leveloffset=+1]
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * assembly/builds
4+
// * builds/custom-builds-buildah.adoc
5+
6+
7+
[id='builds-build-custom-builder-image-{context}']
8+
= Build custom builder image
9+
10+
You can use {product-title} to build and push custom builder images to use in
11+
a custom strategy.
12+
13+
.Prerequisites
14+
15+
* Define all the inputs that will go into creating your new custom builder image.
16+
17+
.Procedure
18+
19+
. Define a BuildConfig that will build your custom builder image:
20+
+
21+
----
22+
$ oc new-build --binary --strategy=docker --name custom-builder-image
23+
----
24+
25+
. From the directory in which you created your custom build image, run the build:
26+
+
27+
----
28+
$ oc start-build custom-builder-image --from-dir . -F
29+
----
30+
+
31+
After the build completes, your new custom builder image will be
32+
available in your project in an image stream tag named
33+
`custom-builder-image:latest`.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * assembly/builds
4+
// * builds/custom-builds-buildah.adoc
5+
6+
7+
[id='builds-create-custom-build-artifacts-{context}']
8+
= Creating custom build artifacts
9+
10+
You need to create the image you want to use as your custom build image.
11+
12+
.Procedure
13+
14+
. Starting with an empty directory, create a file named `Dockerfile` with the
15+
following content:
16+
+
17+
----
18+
FROM docker.io/centos:7
19+
RUN yum install -y buildah
20+
# For simplicity, /tmp/build contains the inputs we’ll be building when we
21+
# run this custom builder image. Normally the custom builder image would
22+
# fetch this content from some location at build time. (e.g. via git clone).
23+
ADD Dockerfile.sample /tmp/input/Dockerfile
24+
ADD build.sh /usr/bin
25+
RUN chmod a+x /usr/bin/build.sh
26+
# /usr/bin/build.sh contains the actual custom build logic that will be executed when
27+
# this custom builder image is executed.
28+
ENTRYPOINT ["/usr/bin/build.sh"]
29+
----
30+
31+
. In the same directory, create a file named `Dockerfile.sample`. This file will be
32+
included in the custom build image and defines the image that will be produced
33+
by the custom build:
34+
+
35+
----
36+
FROM docker.io/centos:7
37+
RUN touch /tmp/built
38+
----
39+
40+
. In the same directory, create a file named `build.sh`. This file contains the
41+
logic that will be executed when the custom build runs:
42+
+
43+
----
44+
#!/bin/sh
45+
# Note that in this case the build inputs are part of the custom builder image, but normally this
46+
# would be retrieved from an external source.
47+
cd /tmp/input
48+
# OUTPUT_REGISTRY and OUTPUT_IMAGE are env variables provided by the custom
49+
# build framework
50+
TAG="${OUTPUT_REGISTRY}/${OUTPUT_IMAGE}"
51+
52+
53+
# performs the build of the new image defined by Dockerfile.sample
54+
buildah --storage-driver vfs bud --isolation chroot -t ${TAG} .
55+
56+
57+
# buildah requires a slight modification to the push secret provided by the service
58+
# account in order to use it for pushing the image
59+
cp /var/run/secrets/openshift.io/push/.dockercfg /tmp
60+
(echo "{ \"auths\": " ; cat /var/run/secrets/openshift.io/push/.dockercfg ; echo "}") > /tmp/.dockercfg
61+
62+
63+
# push the new image to the target for the build
64+
buildah --storage-driver vfs push --tls-verify=false --authfile /tmp/.dockercfg ${TAG}
65+
----
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * assembly/builds
4+
// * builds/securing-builds-by-strategy.adoc
5+
6+
7+
[id='builds-disabling-build-strategy-globally-{context}']
8+
= Disabling access to a build strategy globally
9+
10+
To prevent access to a particular build strategy globally, log in as a user with
11+
*cluster-admin* privileges, remove the corresponding role from the
12+
*system:authenticated* group, and apply the annotation
13+
`rbac.authorization.kubernetes.io/autoupdate: "false"` to protect them from changes between
14+
the API restarts. The following example shows disabling the docker build
15+
strategy.
16+
17+
.Procedure
18+
19+
. Apply the `rbac.authorization.kubernetes.io/autoupdate` annotation:
20+
+
21+
----
22+
$ oc edit clusterrolebinding system:build-strategy-docker-binding
23+
24+
apiVersion: v1
25+
groupNames:
26+
- system:authenticated
27+
kind: ClusterRoleBinding
28+
metadata:
29+
annotations:
30+
rbac.authorization.kubernetes.io/autoupdate: "false" <1>
31+
creationTimestamp: 2018-08-10T01:24:14Z
32+
name: system:build-strategy-docker-binding
33+
resourceVersion: "225"
34+
selfLink: /oapi/v1/clusterrolebindings/system%3Abuild-strategy-docker-binding
35+
uid: 17b1f3d4-9c3c-11e8-be62-0800277d20bf
36+
roleRef:
37+
name: system:build-strategy-docker
38+
subjects:
39+
- kind: SystemGroup
40+
name: system:authenticated
41+
userNames:
42+
- system:serviceaccount:management-infra:management-admin
43+
----
44+
<1> Change the `rbac.authorization.kubernetes.io/autoupdate` annotation's value to `"false"`.
45+
. Remove the role:
46+
+
47+
----
48+
$ oc adm policy remove-cluster-role-from-group system:build-strategy-docker system:authenticated
49+
----
50+
51+
. Ensure the build strategy subresources are also removed from these roles:
52+
+
53+
----
54+
$ oc edit clusterrole admin
55+
$ oc edit clusterrole edit
56+
----
57+
58+
. For each role, remove the line that corresponds to the resource of the strategy
59+
to disable.
60+
.. Disable the Docker Build Strategy for *admin*:
61+
+
62+
[source, yaml]
63+
----
64+
kind: ClusterRole
65+
metadata:
66+
name: admin
67+
...
68+
rules:
69+
- resources:
70+
- builds/custom
71+
- builds/docker <1>
72+
- builds/source
73+
...
74+
...
75+
----
76+
<1> Delete this line to disable Docker builds globally for users with the *admin*
77+
role.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * assembly/builds
4+
// * builds/securing-builds-by-strategy.adoc
5+
6+
7+
[id='builds-restricting-build-strategy-globally-{context}']
8+
= Restricting build strategies to users globally
9+
10+
You can allow a set of specific users to create builds with a particular
11+
strategy.
12+
13+
.Prerequisites
14+
15+
* Disable global access to the build strategy.
16+
17+
.Procedure
18+
19+
* Assign the role that corresponds to the build strategy to a specific user. For
20+
example, to add the *system:build-strategy-docker* cluster role to the user
21+
*devuser*:
22+
+
23+
----
24+
$ oc adm policy add-cluster-role-to-user system:build-strategy-docker devuser
25+
----
26+
+
27+
[WARNING]
28+
====
29+
Granting a user access at the cluster level to the *builds/docker* subresource
30+
means that the user can create builds with the Docker strategy in
31+
any project in which they can create builds.
32+
====
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * assembly/builds
4+
// * builds/securing-builds-by-strategy.adoc
5+
6+
7+
[id='builds-restricting-build-strategy-to-user-{context}']
8+
= Restricting build strategies to a user within a project
9+
10+
Similar to granting the build strategy role to a user globally, you can allow
11+
only a set of specific users within a project to create builds with a particular
12+
strategy.
13+
14+
.Prerequisites
15+
16+
* Disable global access to the build strategy.
17+
18+
.Procedure
19+
20+
* Assign the role that corresponds to the build strategy to a specific user within a
21+
project. For example, to add the *system:build-strategy-docker* role within the
22+
project *devproject* to the user *devuser*:
23+
+
24+
----
25+
$ oc adm policy add-role-to-user system:build-strategy-docker devuser -n devproject
26+
----

0 commit comments

Comments
 (0)