Blueprint `auth.basic-auth` from Docker labels sometimes leaves two header-auth rows after a container is recreated
Describe the Bug
A public HTTP resource is defined by container labels (Newt Docker label provider), including:
pangolin.proxy-resources.<name>.auth.sso-enabled: 'true'
pangolin.proxy-resources.<name>.auth.basic-auth.user: <user>
pangolin.proxy-resources.<name>.auth.basic-auth.password: <password>When the container is recreated, the resource's default policy sometimes ends up with two rows in resourcePolicyHeaderAuth instead of one. Both rows are new (the previous rows are removed, and the two new ones have consecutive ids), with the same credentials and different salts.
What we observed on 1.23.0, four re-applies in a row:
- right after the upgrade: 1 row;
- two redeploys of the whole compose project (
docker compose up -d --wait, only this service's image changed): 2 new rows each time; - recreating only this service (
docker compose up -d --no-deps --wait <service>, one label value changed): 1 new row.
On 1.22.0, a recreation also added a second row next to the first one.
Basic auth keeps working (either row matches), so the impact is only a duplicate row. Since the old rows are deleted, the table does not seem to grow without bound on 1.23.0.
More data from the blueprints table (1.23.0):
- Newt's blueprint is applied very often: several hundred times a day here (we assume on Docker events; the same host runs CI jobs that start and stop many containers).
- Two applications often land in the same second: over the last 24 hours, 308 of the 724 seconds that had an application had two or more.
- Each stored blueprint declares the resource once and its
basic-authonce. - No header auth is configured from the dashboard: the resource has a single (default) policy, and
resourceHeaderAuthis empty.
So the most likely cause is a race between two applications running at the same time, each one deleting the existing header-auth rows and inserting its own. A possible spot, from reading the main branch (not verified at runtime): in server/lib/blueprints/resourcePolicies.ts, the header-auth delete and the following insert are separated by await hashPassword(...) (argon2), which leaves time for a second application to run its own delete in between.
Environment
- OS Type & Version: Debian 13 (trixie), Docker 29.7.2 (Pangolin, Gerbil and Traefik host); Debian 13 (trixie), Docker 29.6.2 (Newt host)
- Pangolin Version: 1.23.0 (
fosrl/pangolin:ee-1.23.0), SQLite; also seen on 1.22.0 - Edition (Community or Enterprise): Enterprise
- Gerbil Version: 1.5.1
- Traefik Version: v3.7.12
- Newt Version: 1.18.0, Docker label provider (
DOCKER_SOCKET); also seen on 1.17.0 - Client Version: none (no client involved)
To Reproduce
- Label a container with a public resource using
auth.basic-auth.userandauth.basic-auth.password, and let Newt create the resource. - Recreate the container without changing its labels (
docker compose up -d --force-recreate <service>). SELECT count(*) FROM resourcePolicyHeaderAuth WHERE resourcePolicyId = <policy of the resource>;returns 2 in about half of our attempts (1 otherwise).
AI Disclosure
This issue was written by an AI assistant (Claude, by Anthropic) on behalf of the reporter, and posted at the reporter's request. The observations come from the reporter's own deployment: row counts and timestamps from read-only queries on the SQLite database, versions from the running containers. The conclusion about a race is the assistant's and has not been checked in the code.
Expected Behavior
After any re-apply of a blueprint with the same basic-auth, the policy has exactly one header-auth row.
Source: fosrl/pangolin