Improve Caddyfile and use registry config file
Some checks are pending
CI/CD Pipeline (Fully Isolated DinD) / Run Tests (DinD) (push) Waiting to run
CI/CD Pipeline (Fully Isolated DinD) / Build and Push Docker Images (DinD) (push) Blocked by required conditions
CI/CD Pipeline (Fully Isolated DinD) / Deploy to Production (push) Blocked by required conditions
Some checks are pending
CI/CD Pipeline (Fully Isolated DinD) / Run Tests (DinD) (push) Waiting to run
CI/CD Pipeline (Fully Isolated DinD) / Build and Push Docker Images (DinD) (push) Blocked by required conditions
CI/CD Pipeline (Fully Isolated DinD) / Deploy to Production (push) Blocked by required conditions
This commit is contained in:
parent
03dac72b90
commit
a43f2003d0
4 changed files with 98 additions and 37 deletions
|
@ -692,7 +692,7 @@ sudo cp /opt/APP_NAME/registry/docker-compose.registry.yml docker-compose.yml
|
||||||
sudo cp /opt/APP_NAME/registry/Caddyfile Caddyfile
|
sudo cp /opt/APP_NAME/registry/Caddyfile Caddyfile
|
||||||
|
|
||||||
# Update Caddyfile with your actual IP address
|
# Update Caddyfile with your actual IP address
|
||||||
sudo sed -i "s/registry.example.com/YOUR_CI_CD_IP/g" Caddyfile
|
sudo sed -i "s/YOUR_CI_CD_IP/YOUR_ACTUAL_IP_ADDRESS/g" Caddyfile
|
||||||
|
|
||||||
# Create environment file for registry authentication
|
# Create environment file for registry authentication
|
||||||
# First, create a secure password hash
|
# First, create a secure password hash
|
||||||
|
@ -716,28 +716,11 @@ sudo chmod 600 .env
|
||||||
sudo mkdir -p /opt/registry/data
|
sudo mkdir -p /opt/registry/data
|
||||||
sudo chown registry:registry /opt/registry/data
|
sudo chown registry:registry /opt/registry/data
|
||||||
|
|
||||||
# Create registry configuration (no authentication needed - Caddy handles it)
|
# Copy registry configuration from repository
|
||||||
sudo tee /opt/registry/config.yml << 'EOF'
|
sudo cp /opt/APP_NAME/registry/config.yml /opt/registry/config.yml
|
||||||
version: 0.1
|
|
||||||
log:
|
# Update the baseurl with your actual IP address
|
||||||
level: debug
|
sudo sed -i "s/YOUR_CI_CD_IP/YOUR_ACTUAL_IP_ADDRESS/g" /opt/registry/config.yml
|
||||||
storage:
|
|
||||||
filesystem:
|
|
||||||
rootdirectory: /var/lib/registry
|
|
||||||
delete:
|
|
||||||
enabled: true
|
|
||||||
http:
|
|
||||||
addr: :5000
|
|
||||||
headers:
|
|
||||||
X-Content-Type-Options: [nosniff]
|
|
||||||
middleware:
|
|
||||||
repository:
|
|
||||||
- name: AwsEc2PublicBlock
|
|
||||||
storage:
|
|
||||||
- name: Redirect
|
|
||||||
options:
|
|
||||||
baseurl: https://YOUR_CI_CD_IP
|
|
||||||
EOF
|
|
||||||
|
|
||||||
# Set proper permissions
|
# Set proper permissions
|
||||||
sudo chown registry:registry /opt/registry/config.yml
|
sudo chown registry:registry /opt/registry/config.yml
|
||||||
|
@ -802,8 +785,8 @@ sudo journalctl -u docker-registry.service -f
|
||||||
The Docker Registry is now configured with the following access model:
|
The Docker Registry is now configured with the following access model:
|
||||||
|
|
||||||
**Authentication Model:**
|
**Authentication Model:**
|
||||||
- **Pulls**: Unauthenticated (public read access)
|
- **Pulls**: Unauthenticated (public read access) - `/v2/*/blobs/*`, `/v2/*/manifests/*`, `/v2/_catalog`, `/v2/*/tags/list`
|
||||||
- **Pushes**: Require authentication with `registry-user` credentials
|
- **Pushes**: Require authentication with `registry-user` credentials - `/v2/*/blobs/uploads/*`, `/v2/*/manifests/*` (PUT/POST/PATCH/DELETE)
|
||||||
|
|
||||||
**Registry Credentials:**
|
**Registry Credentials:**
|
||||||
- **Username**: `registry-user`
|
- **Username**: `registry-user`
|
||||||
|
@ -811,7 +794,13 @@ The Docker Registry is now configured with the following access model:
|
||||||
|
|
||||||
**Registry URL**: `https://YOUR_CI_CD_IP`
|
**Registry URL**: `https://YOUR_CI_CD_IP`
|
||||||
|
|
||||||
**Note**: The authentication is handled by Caddy using the environment variables in the `.env` file. The Docker Registry itself runs without authentication, but Caddy enforces authentication for push operations.
|
**Security Features:**
|
||||||
|
- **URL-based access control**: Different paths require different authentication levels
|
||||||
|
- **Method-based restrictions**: Push operations (PUT/POST/PATCH/DELETE) require authentication
|
||||||
|
- **Path validation**: Prevents method spoofing by validating both URL patterns and HTTP methods
|
||||||
|
- **Security headers**: X-Content-Type-Options, X-Frame-Options for additional protection
|
||||||
|
|
||||||
|
**Note**: The authentication is handled by Caddy using the environment variables in the `.env` file. The Docker Registry itself runs without authentication, but Caddy enforces authentication for push operations based on URL patterns and HTTP methods.
|
||||||
|
|
||||||
#### 5.8 Test Registry Setup
|
#### 5.8 Test Registry Setup
|
||||||
|
|
||||||
|
|
|
@ -1,25 +1,63 @@
|
||||||
|
|
||||||
(registry_auth) {
|
(registry_auth) {
|
||||||
basicauth {
|
basicauth {
|
||||||
{env.REGISTRY_USERNAME} {env.REGISTRY_PASSWORD_HASH}
|
{env.REGISTRY_USERNAME} {env.REGISTRY_PASSWORD_HASH}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
https://registry.example.com {
|
YOUR_CI_CD_IP {
|
||||||
import registry_auth
|
# Security headers
|
||||||
reverse_proxy registry:5000
|
|
||||||
header {
|
header {
|
||||||
X-Content-Type-Options nosniff
|
X-Content-Type-Options nosniff
|
||||||
|
X-Frame-Options DENY
|
||||||
}
|
}
|
||||||
|
|
||||||
@push method POST PUT PATCH DELETE
|
# Handle registry operations based on URL patterns
|
||||||
handle @push {
|
@push_operations {
|
||||||
|
path /v2/*/blobs/uploads/*
|
||||||
|
path /v2/*/manifests/*
|
||||||
|
method PUT POST PATCH DELETE
|
||||||
|
}
|
||||||
|
|
||||||
|
@pull_operations {
|
||||||
|
path /v2/*/blobs/*
|
||||||
|
path /v2/*/manifests/*
|
||||||
|
path /v2/_catalog
|
||||||
|
path /v2/*/tags/list
|
||||||
|
method GET HEAD OPTIONS
|
||||||
|
}
|
||||||
|
|
||||||
|
# Require authentication for push operations
|
||||||
|
handle @push_operations {
|
||||||
import registry_auth
|
import registry_auth
|
||||||
reverse_proxy registry:5000
|
reverse_proxy registry:5000 {
|
||||||
|
header_up Authorization {http.request.header.Authorization}
|
||||||
|
header_up X-Forwarded-For {remote_host}
|
||||||
|
header_up X-Forwarded-Proto {scheme}
|
||||||
|
header_up X-Forwarded-Host {host}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@pull method GET HEAD OPTIONS
|
# Allow unauthenticated pull operations
|
||||||
handle @pull {
|
handle @pull_operations {
|
||||||
reverse_proxy registry:5000
|
reverse_proxy registry:5000 {
|
||||||
|
header_up X-Forwarded-For {remote_host}
|
||||||
|
header_up X-Forwarded-Proto {scheme}
|
||||||
|
header_up X-Forwarded-Host {host}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Block all other requests
|
||||||
|
handle {
|
||||||
|
respond "Registry operation not allowed" 405
|
||||||
|
}
|
||||||
|
|
||||||
|
# Logging
|
||||||
|
log {
|
||||||
|
output file /var/log/caddy/registry.log
|
||||||
|
format json
|
||||||
|
level INFO
|
||||||
|
}
|
||||||
|
|
||||||
|
# Compression
|
||||||
|
encode zstd gzip
|
||||||
}
|
}
|
|
@ -6,6 +6,7 @@ This folder contains the configuration files for the Docker Registry setup used
|
||||||
|
|
||||||
- **`docker-compose.registry.yml`**: Docker Compose configuration for the registry and Caddy reverse proxy
|
- **`docker-compose.registry.yml`**: Docker Compose configuration for the registry and Caddy reverse proxy
|
||||||
- **`Caddyfile`**: Caddy configuration for HTTPS and authentication
|
- **`Caddyfile`**: Caddy configuration for HTTPS and authentication
|
||||||
|
- **`config.yml`**: Docker Registry configuration file
|
||||||
- **`README.md`**: This documentation file
|
- **`README.md`**: This documentation file
|
||||||
|
|
||||||
## Architecture
|
## Architecture
|
||||||
|
@ -18,7 +19,20 @@ The registry setup uses:
|
||||||
## Authentication Model
|
## Authentication Model
|
||||||
|
|
||||||
- **Pulls**: Unauthenticated (public read access)
|
- **Pulls**: Unauthenticated (public read access)
|
||||||
|
- `/v2/*/blobs/*` - Download image layers
|
||||||
|
- `/v2/*/manifests/*` - Download image manifests
|
||||||
|
- `/v2/_catalog` - List repositories
|
||||||
|
- `/v2/*/tags/list` - List image tags
|
||||||
- **Pushes**: Require authentication with `registry-user` credentials
|
- **Pushes**: Require authentication with `registry-user` credentials
|
||||||
|
- `/v2/*/blobs/uploads/*` - Upload image layers
|
||||||
|
- `/v2/*/manifests/*` (PUT/POST/PATCH/DELETE) - Upload/update manifests
|
||||||
|
|
||||||
|
## Security Features
|
||||||
|
|
||||||
|
- **URL-based access control**: Different paths require different authentication levels
|
||||||
|
- **Method-based restrictions**: Push operations require authentication
|
||||||
|
- **Path validation**: Prevents method spoofing by validating both URL patterns and HTTP methods
|
||||||
|
- **Security headers**: X-Content-Type-Options, X-Frame-Options for additional protection
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
|
@ -26,6 +40,7 @@ The setup is configured through:
|
||||||
1. **Environment Variables**: Stored in `.env` file (created during setup)
|
1. **Environment Variables**: Stored in `.env` file (created during setup)
|
||||||
2. **Caddyfile**: Handles HTTPS and authentication
|
2. **Caddyfile**: Handles HTTPS and authentication
|
||||||
3. **Docker Compose**: Orchestrates the registry and Caddy services
|
3. **Docker Compose**: Orchestrates the registry and Caddy services
|
||||||
|
4. **Registry Config**: `config.yml` contains the Docker Registry configuration
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
|
19
registry/config.yml
Normal file
19
registry/config.yml
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
version: 0.1
|
||||||
|
log:
|
||||||
|
level: debug
|
||||||
|
storage:
|
||||||
|
filesystem:
|
||||||
|
rootdirectory: /var/lib/registry
|
||||||
|
delete:
|
||||||
|
enabled: true
|
||||||
|
http:
|
||||||
|
addr: :5000
|
||||||
|
headers:
|
||||||
|
X-Content-Type-Options: [nosniff]
|
||||||
|
middleware:
|
||||||
|
repository:
|
||||||
|
- name: AwsEc2PublicBlock
|
||||||
|
storage:
|
||||||
|
- name: Redirect
|
||||||
|
options:
|
||||||
|
baseurl: https://YOUR_CI_CD_IP
|
Loading…
Add table
Reference in a new issue