NginxProxyManager / nginx-proxy-manager

Docker container for managing Nginx proxy hosts with a simple, powerful interface
https://nginxproxymanager.com
MIT License
21.36k stars 2.46k forks source link

Adding Access List through the API returns 413 code #3568

Open diegocade1 opened 5 months ago

diegocade1 commented 5 months ago

Checklist

Describe the bug

When trying to add an Access List through the api (the list has aprx 1512 entries of IPs)

Nginx Proxy Manager Version

To Reproduce Steps to reproduce the behavior:

  1. Py script with the following:

def add_access_list(name: str, token: str, existing_rule_id: str, *clients: Access_Rule_Client) -> int: payload = { "name" : name, "satisfy_any" : True, "pass_auth" : False, "items": [], "clients": [{'address': rule.address, 'directive': rule.directive} for rule in clients] } headers = { 'Authorization' : f'Bearer {token}' } if existing_rule_id is None: url = f"http://{BASE_URL}:{BASE_PORT}/api/nginx/access-lists" response = requests.post(url, json=payload, headers=headers)

time.sleep(60)

else:
    print(f"adding to ruleid : {existing_rule_id}")
    url = f"http://{BASE_URL}:{BASE_PORT}/api/nginx/access-lists/{existing_rule_id}"
    response = requests.put(url, json=payload, headers=headers)
    #time.sleep(60)
if response.status_code in [200, 201]:
    response_json = response.json()
    id = response_json["id"]
    print(f'Successfully {"updated" if existing_rule_id else "created"} rule (id: {id})')
    return id
else:
    print(f"Error adding access list. ({response.status_code})")
    return -1

After executing the script

Adding access list adding to ruleid : 11 Error adding access list. (413) (Code 413 Request Entity Too Large)

Expected behavior

That the records are inserted correctly.

Screenshots

Operating System

The script is being executed Ubuntu 22.04.4 LTS

Additional context

gadget78 commented 4 months ago

so is this because the API is "unfinished", or just has a bug in this type of configuration ? been trying to find more info on NPM's API, but there doesn't actually seem to be any official Docs on it ? ..

i found this, https://documenter.getpostman.com/view/4475423/2s93mBvyLZ#be0769e8-9cd7-4a74-a075-d56c23fd3351 does seem to have most of the API commands, listed, but not all ..

and also found this, https://github.com/NginxProxyManager/nginx-proxy-manager/issues/1808 showing you can use address npm-admin-ui:81/api/schema to get a list but this too doesn't actually seem like a full working list ? ...

but it seems this post maybe the best ? .. https://github.com/NginxProxyManager/nginx-proxy-manager/issues/1790 which links to this https://github.com/NginxProxyManager/nginx-proxy-manager/tree/develop/backend/routes/api

so going by this, im going to presume the API feature is still being formed, would be perfect if it did have just a few more bugs fixed, and features fully formed, like the Access List control for one !..

TL;DR; looking at your code you supplied, you have "items": [], within the "payload" which i believe is not needed/understood, so its given that odd error....

gadget78 commented 4 months ago

thought i would follow this up, i also posted within this "discussion" post here .. https://github.com/NginxProxyManager/nginx-proxy-manager/discussions/3195

as i DID NEARLY get this working, but it will only "re-create" the list, and will not "add" to to the existing list. did you get any further with your setup ?

curl -X PUT -H "Content-Type: application/json; charset=UTF-8" -H "Authorization: Bearer eyJhbGciOi...." -d '{ "name": "AccessListName", "satisfy_any": 0, "pass_auth": 0, "clients": [ { "address": "192.168.178.96", "directive": "allow" } ] }' http://192.168.1.5:81/api/nginx/access-lists/2

this works, but it SHOUD add to the existing list, but it re-creates it instead :( i found the reason why, and explained here https://github.com/NginxProxyManager/nginx-proxy-manager/discussions/3195#discussioncomment-8972116 just in case this comes up on someones search .,..