赞
踩
《OpenShift 4.x HOL教程汇总》
说明:本文已经在OpenShift 4.8环境中验证
$ git clone https://github.com/liuxiaoyu-git/image-scanning-signing-service.git
$ cd image-scanning-signing-service
$ WORKER="$(oc get nodes -l node-role.kubernetes.io/worker --no-headers -o custom-columns=":metadata.name" | head -1)"
$ echo ${WORKER}
$ oc label node ${WORKER} type=builder
$ oc get machineconfigpool -w
NAME CONFIG UPDATED UPDATING DEGRADED MACHINECOUNT READYMACHINECOUNT UPDATEDMACHINECOUNT DEGRADEDMACHINECOUNT AGE
master rendered-master-268f75295029d9dbe6755043c42427b3 True False False 3 3 3 0 9d
worker rendered-worker-8dac6881264caab39329d54ab649abbd True False False 2 2 2 0 9d
oc new-project image-management
oc apply -f deploy/crds/imagesigningrequests.cop.redhat.com_imagesigningrequests_crd.yaml
oc apply -f deploy/service_account.yaml
oc apply -f deploy/role.yaml
oc apply -f deploy/role_binding.yaml
oc apply -f deploy/scc.yaml
oc apply -f deploy/secret.yaml
oc apply -f deploy/lab_extras/operator.yaml
oc apply -f deploy/lab_extras/sigstore.yaml
$ oc get pod -n image-management
NAME READY STATUS RESTARTS AGE
image-security-6b9bb96765-4hlp5 1/1 Running 0 21s
sigstore-1-deploy 0/1 Completed 0 18s
sigstore-1-wh7sj 1/1 Running 0 16s
$ ROUTE=http://$(oc get route sigstore -o jsonpath='{..spec.host}' -n image-management)
$ base64 deploy/lab_extras/registry-conf.yaml -w 0
ZG9ja2VyOgogICAgIGRvY2tlci5pbzoKICAgICAgICAgc2lnc3RvcmU6IGh0dHA6Ly9zaWdzdG9yZS1pbWFnZS1tYW5hZ2VtZW50LmFwcHMuY2x1c3Rlci04ZDM1LjhkMzUuc2FuZGJveDE0MjAub3BlbnRsYy5jb20gCg==
$ oc apply -f deploy/lab_extras/trust-machineconifg.yaml
$ oc get machineconfigpool worker -w
NAME CONFIG UPDATED UPDATING DEGRADED MACHINECOUNT READYMACHINECOUNT UPDATEDMACHINECOUNT DEGRADEDMACHINECOUNT AGE
worker rendered-worker-8dac6881264caab39329d54ab649abbd False True False 2 0 0 0 9d
worker rendered-worker-8dac6881264caab39329d54ab649abbd False True False 2 1 1 0 9d
worker rendered-worker-8dac6881264caab39329d54ab649abbd False True False 2 1 1 0 9d
worker rendered-worker-d977c1330ccf9a645aca738a56abe8af True False False 2 2 2 0 9d
$ WORKER="$(oc get nodes -l node-role.kubernetes.io/worker --no-headers -o custom-columns=":metadata.name" | head -1)"
$ oc debug node/${WORKER}
Starting pod/ip-10-0-156-171us-east-2computeinternal-debug ...
To use host binaries, run `chroot /host`
Pod IP: 10.0.156.171
If you don't see a command prompt, try pressing enter.
sh-4.4# chroot /host
sh-4.4# cat /etc/containers/policy.json { "default": [ { "type": "insecureAcceptAnything" } ], "transports": { "docker": { "docker.io": [ { "type": "signedBy", "keyType": "GPGKeys", "keyPath": "/root/pubkey.gpg" } ] }, "docker-daemon": { "": [ { "type": "insecureAcceptAnything" } ] } } } sh-4.4# cat /etc/containers/registries.d/docker.io.yaml docker: docker.io: sigstore: http://sigstore-image-management.apps.cluster-8d35.8d35.sandbox1420.opentlc.com
sh-4.4# podman pull docker.io/library/mysql
Trying to pull docker.io/library/mysql:latest...
Error: Source image rejected: A signature was required, but no signature exists
sh-4.4# exit
$ oc new-project nginx-test
$ oc import-image nginx --from="docker.io/nginxinc/nginx-unprivileged" --confirm -n nginx-test
$ oc new-app nginx -n nginx-test
$ oc get pod -n nginx-test
NAME READY STATUS RESTARTS AGE
nginx-9dd546c49-wp682 0/1 ImagePullBackOff 0 25s
$ oc describe pod nginx-9dd546c49-wp682 -n nginx-test
。。。。
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 109s default-scheduler Successfully assigned nginx-test/nginx-9dd546c49-wp682 to ip-10-0-170-27.us-east-2.compute.internal
Normal AddedInterface 108s multus Add eth0 [10.131.0.18/23] from openshift-sdn
Warning Failed 30s (x6 over 107s) kubelet Error: ImagePullBackOff
Normal Pulling 15s (x4 over 108s) kubelet Pulling image "docker.io/nginxinc/nginx-unprivileged@sha256:ed41d4160dd6bf386f5e611a44f6d5467c83e26bb131b459a34459fc5a42e052"
Warning Failed 15s (x4 over 108s) kubelet Failed to pull image "docker.io/nginxinc/nginx-unprivileged@sha256:ed41d4160dd6bf386f5e611a44f6d5467c83e26bb131b459a34459fc5a42e052": rpc error: code = Unknown desc = Source image rejected: A signature was required, but no signature exists
Warning Failed 15s (x4 over 108s) kubelet Error: ErrImagePull
Normal BackOff 1s (x7 over 107s) kubelet Back-off pulling image "docker.io/nginxinc/nginx-unprivileged@sha256:ed41d4160dd6bf386f5e611a44f6d5467c83e26bb131b459a34459fc5a42e052"
$ more deploy/lab_extras/signing-request.yaml
apiVersion: imagesigningrequests.cop.redhat.com/v1alpha1
kind: ImageSigningRequest
metadata:
name: nginx-1
spec:
containerImage:
kind: ImageStreamTag
name: nginx:latest
$ oc apply -f deploy/lab_extras/signing-request.yaml -n nginx-test
$ oc get pod -n image-management NAME READY STATUS RESTARTS AGE c3b5f7ff-d047-4f62-a0eb-c57a469cbfab 0/1 Completed 0 57s image-security-6b9bb96765-hvnvr 1/1 Running 0 9m26s sigstore-1-m2cq7 1/1 Running 0 13m $ oc logs -f c3b5f7ff-d047-4f62-a0eb-c57a469cbfab -n image-management time="2021-11-12T14:28:15Z" level=error msg="unable to write system event: \"write unixgram @00016->/run/systemd/journal/socket: sendmsg: no such file or directory\"" Trying to pull docker.io/nginxinc/nginx-unprivileged@sha256:ed41d4160dd6bf386f5e611a44f6d5467c83e26bb131b459a34459fc5a42e052... Getting image source signatures Copying blob sha256:54247d3512a9e6bc95687e0b652e10044079c9bbf7af9d69fa1d428e41bff84f Copying blob sha256:0f7e43c994f13c51289d21fc1a72d13fed47631a99ce7b524dfe8d1a45958477 Copying blob sha256:052722e881c1465eb58c9ac2bafc164a254188c9f06bd0933d99757ec992fc00 Copying blob sha256:a330b6cecb98cd2425fd25fce36669073f593b3176b4ee14731e48c05d678cdd Copying blob sha256:96bc90d52cf2f2f47520455d64faad604a264bcaa579617419087d59b9f84461 Copying blob sha256:3aeee11385fd3301401d6e72c873fcbb9e7dc1a486e793d76d62b0034a27ac3a Copying blob sha256:5885822443274cc7a636331e79ae9909810cfbe9344c1b93abfc8a78b9e35a3a Copying config sha256:9f271e225e01a0a3868f080ae7cfaf36a957a79f8141c96c5604352e9629729e Writing manifest to image destination Storing signatures 9f271e225e01a0a3868f080ae7cfaf36a957a79f8141c96c5604352e9629729e Untagged: docker.io/nginxinc/nginx-unprivileged@sha256:ed41d4160dd6bf386f5e611a44f6d5467c83e26bb131b459a34459fc5a42e052 Deleted: 9f271e225e01a0a3868f080ae7cfaf36a957a79f8141c96c5604352e9629729e
$ oc get imagesigningrequests nginx-1 -o yaml -n nginx-test 。。。 status: conditions: - lastTransitionTime: 2021-11-12 14:27:51.956766002 +0000 UTC m=+487.950431898 message: Signing Pod Launched 'image-management/c3b5f7ff-d047-4f62-a0eb-c57a469cbfab' status: "True" type: Initialization - lastTransitionTime: 2021-11-12 14:28:41.161360642 +0000 UTC m=+537.155026498 message: Image Signed status: "True" type: Finished endTime: 2021-11-12 14:28:41.161360642 +0000 UTC m=+537.155026498 phase: Completed signedImage: sha256:ed41d4160dd6bf386f5e611a44f6d5467c83e26bb131b459a34459fc5a42e052 startTime: 2021-11-12 14:27:51.956766002 +0000 UTC m=+487.950431898 unsignedImage: sha256:ed41d4160dd6bf386f5e611a44f6d5467c83e26bb131b459a34459fc5a42e052
$ oc get pod -n nginx-test
NAME READY STATUS RESTARTS AGE
nginx-9dd546c49-wp682 1/1 Running 0 9m28s
$ oc rollout restart deployment/nginx
deployment.apps/nginx restarted
https://github.com/RedHatDemos/SecurityDemos/blob/master/2021Labs/OpenShiftSecurity/documentation/lab5.adoc
https://github.com/redhat-cop/image-scanning-signing-service.git
https://access.redhat.com/verify-images-ocp4
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。