Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial draft #2

Merged
merged 6 commits into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions auth/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#Template from https://docs.docker.com/registry/recipes/nginx/

events {
worker_connections 1024;
}

http {

upstream docker-registry {
server registry:5000;
}

## Set a variable to help us decide if we need to add the
## 'Docker-Distribution-Api-Version' header.
## The registry always sets this header.
## In the case of nginx performing auth, the header is unset
## since nginx is auth-ing before proxying.
map $upstream_http_docker_distribution_api_version $docker_distribution_api_version {
'' 'registry/2.0';
}

server {
listen 443 ssl;
server_name docker.cdot.systems;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use a variable here, in case we decide to move it somewhere else.

Suggested change
server_name docker.cdot.systems;
server_name ${DOMAIN};


# SSL
ssl_certificate /etc/nginx/conf.d/domain.crt;
ssl_certificate_key /etc/nginx/conf.d/domain.key;

# Recommendations from https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html
ssl_protocols TLSv1.1 TLSv1.2;
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;

# disable any limits to avoid HTTP 413 for large image uploads
client_max_body_size 0;

# required to avoid HTTP 411: see Issue #1486 (https://github.com/moby/moby/issues/1486)
chunked_transfer_encoding on;

location /v2/ {
Copy link
Contributor

@Kevan-Y Kevan-Y Feb 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make sure I understand. We will push our image to DOMAIN/v2 route?

# Do not allow connections from docker 1.5 and earlier
# docker pre-1.6.0 did not properly set the user agent on ping, catch "Go *" user agents
if ($http_user_agent ~ "^(docker\/1\.(3|4|5(?!\.[0-9]-dev))|Go ).*$" ) {
return 404;
}

# To add basic authentication to v2 use auth_basic setting.
auth_basic "Registry realm";
auth_basic_user_file /etc/nginx/conf.d/nginx.htpasswd;

## If $docker_distribution_api_version is empty, the header is not added.
## See the map directive above where this variable is defined.
add_header 'Docker-Distribution-Api-Version' $docker_distribution_api_version always;

proxy_pass http://docker-registry;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be docker.cdot.systems?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be http://registry:${PORT}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we probably don't need the upstream and can use the docker network.

proxy_set_header Host $http_host; # required for docker client's sake
proxy_set_header X-Real-IP $remote_addr; # pass on real client's IP
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 900;
}
}
}
Empty file added auth/nginx.htpasswd
Empty file.
39 changes: 39 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#https://docs.docker.com/registry/deploying/#deploy-your-registry-using-a-compose-file
services:
TDDR marked this conversation as resolved.
Show resolved Hide resolved
nginx:
image: "nginx:alpine"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use nginx:stable-alpine. Boring and safe vs cutting edge!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to use bcrypt?

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nginx:stable-alpine is still alpine, just a stable vs. development version of nginx

ports:
humphd marked this conversation as resolved.
Show resolved Hide resolved
- 5043:443
restart: unless-stopped
links:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this, since our registry is named registry already, and will be reachable by nginx.

- registry:registry
volumes:
- ./auth:/etc/nginx/conf.d
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@manekenpix where should we put our files in the host? It might make sense to have ./nginx but I don't think auth makes as much sense for these.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a config folder would be ok?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had thought the same thing originally, but after going back and looking at the documentation I saw this.
image
from here https://docs.docker.com/registry/recipes/nginx/#setting-things-up

So I decided to go with the current folder structure. I can create and move it back to a config folder though?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the easiest way to do this is to mimic the layout of what we'll pass in within our repo:

docker-compose.yml
config/ (or this could be called volume/)
  etc/
    nginx/
      conf.d

This way you can look at the overlays we have in our repo, and understand quickly where they end-up in the container.

volumes:
  - ./config/etc/nginx/conf.d:/etc/nginx/conf.d

- ./auth/nginx.conf:/etc/nginx/nginx.conf:ro

# SSL certificate management for nginx
certbot:
image: certbot/certbot
container_name: 'certbot'
volumes:
- ../../certbot/conf:/etc/letsencrypt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar question here, we need to determine our local path

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe somewhere in /etc, like /etc/letsencrypt?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, config/etc/letsencrypt would work similar to my comment above.

- ../../certbot/www:/var/www/certbot
restart: always
# This will check if your certificate is up for renewal every 12 hours as recommended by Let’s Encrypt
entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"
TDDR marked this conversation as resolved.
Show resolved Hide resolved

registry:
restart: always
image: registry:2
environment:
REGISTRY_HTTP_TLS_CERTIFICATE: /certs/domain.crt
REGISTRY_HTTP_TLS_KEY: /certs/domain.key
REGISTRY_AUTH: token
REGISTRY_AUTH_TOKEN_REALM: Registry Realm
REGISTRY_AUTH_TOKEN_SERVICE: Token services
REGISTRY_AUTH_TOKEN_ISSUER: Registry token issuer
REGISTRY_AUTH_TOKEN_ROOTCERTBUNDLE: /root/certs/bundle
volumes:
- /telescope/data:/var/lib/registry
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should figure out where in the host we're going to put our stuff.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think /usr/share/our_directory would make sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you say our_directory, would that mean this directory, /mnt/docker0storage/registry?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, so it would be:

volumes:
  - /mnt/docker0storage/registry:/var/lib/registry

Such that the container will overlay /mnt/docker0storage/registry onto /var/lib/registry within the container.

- /telescope/certs:/certs
- /telescope/auth:/auth
41 changes: 41 additions & 0 deletions registry-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# https://docs.docker.com/registry/configuration/

version: 0.1
log:
level: debug
fields:
service: registry
storage:
cache:
blobdescriptor: inmemory
filesystem:
rootdirectory: /mnt/docker0storage/registry
http:
addr: 443:5000 # https://docs.docker.com/registry/configuration/#letsencrypt
host: docker.cdot.systems
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we change it to ${DOMAIN} like what @manekenpix suggested in one of the other file?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do, we'll have to use envsubst or something to replace the values before we use this file.

tls:
certificate: /path/to/x509/public
key: /path/to/x509/private
letsencrypt:
cachefile: /path/to/cache-file
email: [email protected]
#hosts: [myregistryaddress.org]
headers:
X-Content-Type-Options: [nosniff]
auth:
token:
realm: token-realm
service: token-service
issuer: registry-token-issuer
rootcertbundle: /root/certs/bundle
# redis:
# addr: localhost:6379
# password: asecret
# db: 0
# dialtimeout: 10ms
# readtimeout: 10ms
# writetimeout: 10ms
# pool:
# maxidle: 16
# maxactive: 64
# idletimeout: 300s