|
| 1 | +## Deploying and Running Nebari from a Private Container Repository |
| 2 | + |
| 3 | +Nebari deploys and runs FOSS components as containers running in Kubernetes. |
| 4 | +By default, Nebari sources each container from the container's respective public repository, typically `docker.io` or `quay.io`. |
| 5 | +This introduces supply-chain concerns for security-focused customers. |
| 6 | + |
| 7 | +One solution to these supply-chain concerns is to deploy Nebari from private locally-mirrored containers: |
| 8 | + |
| 9 | +- Create a controlled private container repository (e.g. ECR) |
| 10 | +- Mirror all containers used by Nebari into this private container repository |
| 11 | +- Use the `pre_bootstrap_command` mechanism in `nebari-config.yaml` to specify the mirrored container repo |
| 12 | + |
| 13 | +Deploying Nebari in this fashion eliminates significant supply chain surface-area, but requires identifying all containers used by Nebari. |
| 14 | + |
| 15 | +The following configurations demonstrate how to specify a private repo denoted by the string `[PRIVATE_REPO]`. |
| 16 | + |
| 17 | +**Note:** Authorization tokens are used in the examples below. It is important for administrators to understand the expiration policy of these tokens, because the Nebari k8s cluster may in some cases need to **use these tokens to pull container images at any time during run-time operation**. |
| 18 | + |
| 19 | +### Set ECR as default container registry mirror |
| 20 | + |
| 21 | +``` |
| 22 | +amazon_web_services: |
| 23 | + node_groups: |
| 24 | + general: |
| 25 | + instance: m5.2xlarge |
| 26 | + launch_template: |
| 27 | + pre_bootstrap_command: | |
| 28 | + #!/bin/bash |
| 29 | + # Verify that IP forwarding is enabled for worker nodes, as is required for containerd |
| 30 | + if [[ $(sysctl net.ipv4.ip_forward | grep "net.ipv4.ip_forward = 1") ]]; then echo "net.ipv4.ip_forward is on"; else sysctl -w net.ipv4.ip_forward=1; fi |
| 31 | + # Set ECR as default container registry mirror |
| 32 | + mkdir -p /etc/containerd/certs.d/_default |
| 33 | + ECR_TOKEN="$(aws ecr get-login-password --region us-east-1)" |
| 34 | + BASIC_AUTH="$(echo -n "AWS:$ECR_TOKEN" | base64 -w 0)" |
| 35 | + cat <<-EOT > /etc/containerd/certs.d/_default/hosts.toml |
| 36 | + [host."https://[PRIVATE_REPO].dkr.ecr.us-east-1.amazonaws.com"] |
| 37 | + capabilities = ["pull", "resolve"] |
| 38 | + [host."https://[PRIVATE_REPO].dkr.ecr.us-east-1.amazonaws.com".header] |
| 39 | + authorization = "Basic $BASIC_AUTH" |
| 40 | + EOT |
| 41 | +
|
| 42 | +``` |
| 43 | + |
| 44 | +### Set GitLab CR as default container registry mirror |
| 45 | + |
| 46 | +``` |
| 47 | +# Set GitLab CR as default container registry mirror in hosts.toml; |
| 48 | +# must have override_path set if project/group names don't match upstream container |
| 49 | +amazon_web_services: |
| 50 | + node_groups: |
| 51 | + general: |
| 52 | + instance: m5.2xlarge |
| 53 | + launch_template: |
| 54 | + pre_bootstrap_command: | |
| 55 | + #!/bin/bash |
| 56 | + # Verify that IP forwarding is enabled for worker nodes, as is required for containerd |
| 57 | + if [[ $(sysctl net.ipv4.ip_forward | grep "net.ipv4.ip_forward = 1") ]]; then echo "net.ipv4.ip_forward is on"; else sysctl -w net.ipv4.ip_forward=1; fi |
| 58 | + # Set default container registry mirror in hosts.toml; must have override_path set if project/group names don't match upstream container |
| 59 | + CONTAINER_REGISTRY_URL="[PRIVATE_REPO]" |
| 60 | + CONTAINER_REGISTRY_USERNAME="[username]" |
| 61 | + CONTAINER_REGISTRY_TOKEN="[token]" |
| 62 | + CONTAINER_REGISTRY_GROUP=as-nebari |
| 63 | + CONTAINER_REGISTRY_PROJECT=nebari-test |
| 64 | + mkdir -p /etc/containerd/certs.d/_default |
| 65 | + cat <<-EOT > /etc/containerd/certs.d/_default/hosts.toml |
| 66 | + [host."https://$CONTAINER_REGISTRY_URL/v2/$CONTAINER_REGISTRY_GROUP/$CONTAINER_REGISTRY_PROJECT"] |
| 67 | + override_path = true |
| 68 | + capabilities = ["pull", "resolve"] |
| 69 | + EOT |
| 70 | +
|
| 71 | + # Set containerd registry config auth in config.d .toml import dir |
| 72 | + mkdir -p /etc/containerd/config.d |
| 73 | + cat <<EOT | sudo tee /etc/containerd/config.d/config-import.toml |
| 74 | + version = 2 |
| 75 | + [plugins."io.containerd.grpc.v1.cri".registry] |
| 76 | + config_path = "/etc/containerd/certs.d:/etc/docker/certs.d" |
| 77 | + [plugins."io.containerd.grpc.v1.cri".registry.auths] |
| 78 | + [plugins."io.containerd.grpc.v1.cri".registry.configs] |
| 79 | + [plugins."io.containerd.grpc.v1.cri".registry.configs."$CONTAINER_REGISTRY_URL".auth] |
| 80 | + username = "$CONTAINER_REGISTRY_USERNAME" |
| 81 | + password = "$CONTAINER_REGISTRY_TOKEN" |
| 82 | + EOT |
| 83 | +``` |
| 84 | + |
| 85 | +### Set GitLab CR as default container registry mirror, with custom Client SSL/TLS Certs |
| 86 | + |
| 87 | +``` |
| 88 | +# must have override_path set if project/group names don't match upstream container |
| 89 | +# Also add/set GitLab Client SSL/TLS Certificate for Containerd |
| 90 | +amazon_web_services: |
| 91 | + node_groups: |
| 92 | + general: |
| 93 | + instance: m5.2xlarge |
| 94 | + launch_template: |
| 95 | + pre_bootstrap_command: | |
| 96 | + #!/bin/bash |
| 97 | + # Verify that IP forwarding is enabled for worker nodes, as is required for containerd |
| 98 | + if [[ $(sysctl net.ipv4.ip_forward | grep "net.ipv4.ip_forward = 1") ]]; then echo "net.ipv4.ip_forward is on"; else sysctl -w net.ipv4.ip_forward=1; fi |
| 99 | + # Set default container registry mirror in hosts.toml; must have override_path set if project/group names don't match upstream container |
| 100 | + CONTAINER_REGISTRY_URL="[PRIVATE_REPO]" |
| 101 | + CONTAINER_REGISTRY_USERNAME="[username]" |
| 102 | + CONTAINER_REGISTRY_TOKEN="[token]" |
| 103 | + CONTAINER_REGISTRY_GROUP=as-nebari |
| 104 | + CONTAINER_REGISTRY_PROJECT=nebari-test |
| 105 | + mkdir -p /etc/containerd/certs.d/_default |
| 106 | + cat <<-EOT > /etc/containerd/certs.d/_default/hosts.toml |
| 107 | + [host."https://$CONTAINER_REGISTRY_URL/v2/$CONTAINER_REGISTRY_GROUP/$CONTAINER_REGISTRY_PROJECT"] |
| 108 | + override_path = true |
| 109 | + capabilities = ["pull", "resolve"] |
| 110 | + client = ["/etc/containerd/certs.d/$CONTAINER_REGISTRY_URL/client.pem"] |
| 111 | + EOT |
| 112 | +
|
| 113 | + # Set containerd registry config auth in config.d .toml import dir |
| 114 | + mkdir -p /etc/containerd/config.d |
| 115 | + cat <<EOT | sudo tee /etc/containerd/config.d/config-import.toml |
| 116 | + version = 2 |
| 117 | + [plugins."io.containerd.grpc.v1.cri".registry] |
| 118 | + config_path = "/etc/containerd/certs.d:/etc/docker/certs.d" |
| 119 | + [plugins."io.containerd.grpc.v1.cri".registry.auths] |
| 120 | + [plugins."io.containerd.grpc.v1.cri".registry.configs] |
| 121 | + [plugins."io.containerd.grpc.v1.cri".registry.configs."$CONTAINER_REGISTRY_URL".auth] |
| 122 | + username = "$CONTAINER_REGISTRY_USERNAME" |
| 123 | + password = "$CONTAINER_REGISTRY_TOKEN" |
| 124 | + EOT |
| 125 | +
|
| 126 | + # Add client key/cert to containerd |
| 127 | + mkdir -p /etc/containerd/certs.d/$CONTAINER_REGISTRY_URL |
| 128 | + cat <<-EOT >> /etc/containerd/certs.d/$CONTAINER_REGISTRY_URL/client.pem |
| 129 | + -----BEGIN CERTIFICATE----- |
| 130 | + XzxzxzxzxxzxzxzxzxzxzxzxxzxzxzxzxzxzxzxxzxzxzxzxzxzxzxzxzxxzxzZx |
| 131 | + ZxyzxzxzxxzxzxzxzxzxzxzxxzxzxzxzxzxzxzxxzxzxzxzxzxzxzxzxzxxzxzXz |
| 132 | + -----END CERTIFICATE----- |
| 133 | + -----BEGIN PRIVATE KEY----- |
| 134 | + XzxzxzxzxxzxzxzxzxzxzxzxxzxzxzxzxzxzxzxxzxzxzxzxzxzxzxzxzxxzxzZx |
| 135 | + ZxyzxzxzxxzxzxzxzxzxzxzxxzxzxzxzxzxzxzxxzxzxzxzxzxzxzxzxzxxzxzXz |
| 136 | + -----END PRIVATE KEY----- |
| 137 | + EOT |
| 138 | +``` |
0 commit comments