You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
3.0 KiB

  1. # Enable Authentication with Htpasswd for Kube-Registry
  2. Docker registry support a few authentication providers. Full list of supported provider can be found [here](https://docs.docker.com/registry/configuration/#auth). This document describes how to enable authentication with htpasswd for kube-registry.
  3. ### Prepare Htpasswd Secret
  4. Please generate your own htpasswd file. Assuming the file you generated is `htpasswd`.
  5. Creating secret to hold htpasswd...
  6. ```console
  7. $ kubectl --namespace=kube-system create secret generic registry-auth-secret --from-file=htpasswd=htpasswd
  8. ```
  9. ### Run Registry
  10. Please be noted that this sample rc is using emptyDir as storage backend for simplicity.
  11. <!-- BEGIN MUNGE: EXAMPLE registry-auth-rc.yaml -->
  12. ```yaml
  13. apiVersion: v1
  14. kind: ReplicationController
  15. metadata:
  16. name: kube-registry-v0
  17. namespace: kube-system
  18. labels:
  19. k8s-app: kube-registry
  20. version: v0
  21. # kubernetes.io/cluster-service: "true"
  22. spec:
  23. replicas: 1
  24. selector:
  25. k8s-app: kube-registry
  26. version: v0
  27. template:
  28. metadata:
  29. labels:
  30. k8s-app: kube-registry
  31. version: v0
  32. # kubernetes.io/cluster-service: "true"
  33. spec:
  34. containers:
  35. - name: registry
  36. image: registry:2
  37. resources:
  38. # keep request = limit to keep this container in guaranteed class
  39. limits:
  40. cpu: 100m
  41. memory: 100Mi
  42. requests:
  43. cpu: 100m
  44. memory: 100Mi
  45. env:
  46. - name: REGISTRY_HTTP_ADDR
  47. value: :5000
  48. - name: REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY
  49. value: /var/lib/registry
  50. - name: REGISTRY_AUTH_HTPASSWD_REALM
  51. value: basic_realm
  52. - name: REGISTRY_AUTH_HTPASSWD_PATH
  53. value: /auth/htpasswd
  54. volumeMounts:
  55. - name: image-store
  56. mountPath: /var/lib/registry
  57. - name: auth-dir
  58. mountPath: /auth
  59. ports:
  60. - containerPort: 5000
  61. name: registry
  62. protocol: TCP
  63. volumes:
  64. - name: image-store
  65. emptyDir: {}
  66. - name: auth-dir
  67. secret:
  68. secretName: registry-auth-secret
  69. ```
  70. <!-- END MUNGE: EXAMPLE registry-auth-rc.yaml -->
  71. No changes are needed for other components (kube-registry service and proxy).
  72. ### To Verify
  73. Setup proxy or port-forwarding to the kube-registry. Image push/pull should fail without authentication. Then use `docker login` to authenticate with kube-registry and see if it works.
  74. ### Configure Nodes to Authenticate with Kube-Registry
  75. By default, nodes assume no authentication is required by kube-registry. Without authentication, nodes cannot pull images from kube-registry. To solve this, more documentation can be found [Here](https://github.com/kubernetes/kubernetes.github.io/blob/master/docs/concepts/containers/images.md#configuring-nodes-to-authenticate-to-a-private-repository).
  76. [![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/cluster/addons/registry/auth/README.md?pixel)]()