caddy-security icon indicating copy to clipboard operation
caddy-security copied to clipboard

question: Noob question, my example does not work, what am I doing wrong?

Open rbasche opened this issue 3 months ago • 2 comments

Caution: Noob here:

I am trying to build my own caddy image. Did with help of chatgpt, who also wrote the Caddyfile (with a lot of hassle, as it tends to invent uundocumented solutions...)

The build works fine, but when trying a simple example it says the security directive is not know, please advice

  • what is wrong
  • where is my misunderstanding
  • where to look to make a correct simple example

Dockerfile is:

cat Dockerfile

Builder-Image mit xcaddy

FROM caddy:builder AS builder

RUN xcaddy build
--with github.com/greenpau/caddy-security

FROM caddy:latest

COPY --from=builder /usr/bin/caddy /usr/bin/caddy

Caddyfile is:

cat conf/Caddyfile {

log {
    output file /var/log/caddy/test.log {
        roll_disabled
    }
}

}

localhost:8080 { route { security { local { # Pfad zur JSON-Datei mit Benutzern users_file /data/users.json } authentication { portal { cookie_domain "localhost" } } }

    respond "Login erfolgreich!" 200
}

}

Users file is: cat data/users.json { "users": [ { "username": "testuser", "password": "$2a$12$KIXvXqM8u4r0qS0w3p2jOuR7N6lE4gMvzjSgNqPyE.CdMnI7Oq0lS", "roles": ["admin"] } ] }

Starting caddy with:

docker run --rm -p 18080:8080 -v /opt/caddy-build/conf:/etc/caddy -v /opt/caddy-build/log:/var/log/caddy -v /opt/caddy-build/data:/data caddy-security

{"level":"info","ts":1759338745.032251,"msg":"maxprocs: Leaving GOMAXPROCS=4: CPU quota undefined"} {"level":"info","ts":1759338745.032576,"msg":"GOMEMLIMIT is updated","package":"github.com/KimMachineGun/automemlimit/memlimit","GOMEMLIMIT":7500006604,"previous":9223372036854775807} {"level":"info","ts":1759338745.0326245,"msg":"using config from file","file":"/etc/caddy/Caddyfile"} {"level":"info","ts":1759338745.0329864,"msg":"maxprocs: No GOMAXPROCS change to reset"} Error: adapting config using caddyfile: parsing caddyfile tokens for 'route': unrecognized directive: security - are you sure your Caddyfile structure (nesting and braces) is correct?, at /etc/caddy/Caddyfile:25

rbasche avatar Oct 01 '25 17:10 rbasche

@rbasche , please the following file for reference https://github.com/authcrunch/authcrunch/blob/main/Dockerfile

greenpau avatar Oct 01 '25 19:10 greenpau

Sample Caddyfile is here https://github.com/authcrunch/authcrunch/blob/main/Caddyfile

greenpau avatar Oct 01 '25 19:10 greenpau