Auto Discovery Pull Secret Extractor Docker Image
auto-discovery-secret-extraction容器作为initContainer,用于帮助Trivy等扫描工具访问私有Docker仓库镜像,通过自动发现并创建带ownerReference的临时密钥实现认证,扫描完成后临时密钥自动删除。
Usage
The auto-discovery-secret-extraction container should be used as an initContainer to enable Trivy (or other container scan tools) to scan images from private docker registries. The container expects the imageID for which it should find the corresponding secret and the name of the temporary secret as commandline arguments. The initContainer will then read secrets mounted as a volume under /secrets and check which secret belongs to the domain of the provided imageID. After the correct secret is identified it will create a temporary secret which will contain the credentials of the private registry of the provided imageID. The temporary secret will have an ownerReference to the pod in which this container is running in. This means that the temporary secret will be automatically removed when the scan of the pod is finished.
Running a local docker registry
The easiest way to test the initContainer locally is to deploy a local registry using docker outside of the k8s cluster to be able to delete the cluster without recreating the registry every time.
Creating a local registry with authentication
- Create basic auth secrets
bashmkdir auth docker run \ --entrypoint htpasswd \ httpd:2 -Bbn testuser testpassword > auth/htpasswd
- Start registry container (Commands adapted from https://docs.docker.com/registry/deploying/)
bashdocker run -d \ -p "127.0.0.1:5000:5000" \ --name registry \ --restart=always \ -v "$(pwd)"/auth:/auth \ -e "REGISTRY_AUTH=htpasswd" \ -e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \ -e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \ registry:2
- Login into newly created docker registry
bashdocker login localhost:5000 -u testuser -p testpassword
- Create kind cluster with the local registry configured (Commands adapted from https://kind.sigs.k8s.io/docs/user/local-registry/)
bashcat <<EOF | kind create cluster --config=- kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 nodes: - role: control-plane containerdConfigPatches: - |- [plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:5000"] endpoint = ["http://registry:5000"] [plugins."io.containerd.grpc.v1.cri".registry.configs."registry:5000".tls] insecure_skip_verify = true EOF docker network connect "kind" "registry" cat <<EOF | kubectl apply -f - apiVersion: v1 kind: ConfigMap metadata: name: local-registry-hosting namespace: kube-public data: localRegistryHosting.v1: | host: "localhost:5000" help: "https://kind.sigs.k8s.io/docs/user/local-registry/" EOF
- Push an image to the local registry
bashdocker pull ubuntu docker tag ubuntu localhost:5000/ubuntu docker push localhost:5000/ubuntu
- Create a pod running an image from the local registry
bashcat <<EOF | kubectl apply -f - apiVersion: v1 kind: Secret metadata: name: regcred namespace: default data: .dockerconfigjson: ewoJImF1dGhzIjogewoJCSJsb2NhbGhvc3Q6NTAwMCI6IHsKCQkJImF1dGgiOiAiZEdWemRIVnpaWEk2ZEdWemRIQmhjM04zYjNKayIKCQl9Cgl9Cn0= type: kubernetes.io/dockerconfigjson --- apiVersion: v1 kind: Pod metadata: name: private-reg namespace: default spec: containers: - name: private-reg-container image: localhost:5000/ubuntu command: ["sleep"] args: ["999999"] imagePullSecrets: - name: regcred EOF
securecodebox 命名空间的其他可用镜像:
securecodebox/parser-test-scan
securecodebox/scanner-typo3scan
securecodebox/parser-kube-hunter
securecodebox/old-wordpress
securecodebox/scanner-whatweb
securecodebox/parser-trivy
镜像拉取方式
您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。
轩辕镜像加速拉取命令点我查看更多 auto-discovery-pull-secret-extractor 镜像标签
DockerHub 原生拉取命令
用户好评
来自真实用户的反馈,见证轩辕镜像的优质服务