- htadmin provides a simple API interface to manage the
.htpasswdfile. - The
.htpasswdfile can be configured to restrict access with HTTP basic authentication for Nginx web servers. Refer: https://docs.nginx.com/nginx/admin-guide/security-controls/configuring-http-basic-authentication/ - The credentials are automatically loaded, no need to reload the Nginx web server.
- The
.htpasswdfile will be generated in the same directory as the htadmin executable is running.
env CGO_ENABLED=0 go build -a -gcflags=all="-l -B" -ldflags "-s -w" .- htadmin reads the credentials file
creds.yamlfrom the same directory where the binary is executed from. - modify the
creds.yamlfile as per the requirement
users:
pulse: changeme
admin: changemeNOTE: Replace the changeme with your actual password.
./htadminFor example, if your username is pulse and the password is changeme, you have to encode the string pulse:changeme into base64, which is cHVsc2U6Y2hhbmdlbWU= .
curl -i -X POST http://localhost:19978/uac/create \
-H 'authorization: Basic cHVsc2U6Y2hhbmdlbWU=' \
-H "Accept: application/json" -H "Content-type: application/json" \
-d '{ "name": "acme" }'Output:
HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8
Date: Tue, 22 Nov 2022 11:55:32 GMT
Content-Length: 40
Success
5L0XC7ARAo4qStt18v91rkUsydrBwW6scurl -i -X POST http://localhost:19978/uac/delete \
-H 'authorization: Basic cHVsc2U6Y2hhbmdlbWU=' \
-H "Accept: application/json" -H "Content-type: application/json" \
-d '{ "name": "acme" }'Output:
HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8
Date: Tue, 22 Nov 2022 11:57:12 GMT
Content-Length: 34
User "acme" deleted successfully