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

Add read-only and read-write user auth to Nginx recipe #14321

Closed
wants to merge 2 commits into from
Closed
Changes from all 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
20 changes: 16 additions & 4 deletions registry/recipes/nginx.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,18 @@ Review the [requirements](index.md#requirements), then follow these steps.
}

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

# Use separate users for read-only requests
# This allows you to create users with read-only access
if ($request_method ~ "GET|HEAD") {
set $auth_basic "Registry realm ro";
set $auth_basic_user_file /etc/nginx/conf.d/nginx-ro.htpasswd;
}

auth_basic $auth_basic;
auth_basic_user_file $auth_basic_user_file;

## If $docker_distribution_api_version is empty, the header is not added.
## See the map directive above where this variable is defined.
Expand All @@ -152,10 +162,12 @@ Review the [requirements](index.md#requirements), then follow these steps.
}
```

3. Create a password file `auth/nginx.htpasswd` for "testuser" and "testpassword".
3. Create password file `auth/nginx-ro.htpasswd` for read-only users and `auth/nginx-rw.htpasswd` for read-write users.

The following command creates both for "testuser" with password "testpassword".

```console
$ docker run --rm --entrypoint htpasswd registry:2 -Bbn testuser testpassword > auth/nginx.htpasswd
$ docker run --rm --entrypoint htpasswd httpd:2.4-alpine -Bbn testuser testpassword | tee -a auth/nginx-ro.htpasswd auth/nginx-rw.htpasswd > /dev/null
```

> **Note**: If you do not want to use `bcrypt`, you can omit the `-B` parameter.
Expand Down